seven 1 week ago
parent
commit
4c4102837a

+ 5 - 3
app/Http/Controllers/admin/Wallet.php

@@ -20,6 +20,7 @@ use App\Services\GameplayRuleService;
 use App\Models\Config;
 use App\Services\ConfigService;
 use App\Services\Payment\SanJinService;
+use App\Services\PaymentOrderService;
 
 class Wallet extends Controller
 {
@@ -281,10 +282,11 @@ class Wallet extends Controller
         // $awards = IssueService::award([7,7,7]);
         // $result = BetService::betSettled2('3356003',$awards);
         // $result = IssueService::sendLotteryImage($memberId, 3356000);
-        $order_no = SanJinService::createOrderNo();
-        echo $order_no;
+        // $order_no = SanJinService::createOrderNo();
+        // echo $order_no;
         // $result = SanJinService::pay(100,$order_no);
-        $result = SanJinService::payout(100,$order_no,'厦门银行','张三',1245679451259741541,SanJinService::ALIPAY_TO_ALIPAY);
+        // $result = SanJinService::payout(100,$order_no,'厦门银行','张三',1245679451259741541,SanJinService::ALIPAY_TO_ALIPAY);
+        $result = PaymentOrderService::createPayout($memberId,100,SanJinService::ALIPAY_TO_ALIPAY,'支付宝','张三','1756201451');
         echo "<pre>";
         var_dump($result);
     }

+ 31 - 0
app/Models/PaymentOrder.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Foundation\Auth\User as Authenticatable;
+use Illuminate\Notifications\Notifiable;
+use Laravel\Sanctum\HasApiTokens;
+
+/**
+ * Admin
+ * @mixin Builder
+ * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
+ */
+class PaymentOrder extends Authenticatable
+{
+    use HasApiTokens, Notifiable;
+    protected $table = 'payment_orders';
+    // protected $hidden = ['created_at', 'updated_at'];
+    protected $fillable = ['type', 'order_no', 'member_id', 'amount' ,'channel' ,'bank_name' ,'account' ,'card_no' ,'status' ,'callback_url' ,'callback_data'];
+
+    protected function getCreatedAtAttribute($value)
+    {
+        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
+    }
+
+    protected function getUpdatedAtAttribute($value)
+    {
+        return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
+    }
+}

+ 159 - 0
app/Services/PaymentOrderService.php

@@ -0,0 +1,159 @@
+<?php
+
+
+namespace App\Services;
+
+use App\Services\BaseService;
+use App\Models\PaymentOrder;
+use App\Models\Config;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
+
+use App\Services\Payment\SanJinService;
+
+/**
+ * 投注
+*/
+class PaymentOrderService extends BaseService 
+{
+    const TYPE_PAY = 1; // 代收
+    const TYPE_PAYOUT = 1; // 代付
+
+    /**
+     * @description: 模型
+     * @return {string}
+     */    
+    public static function model() :string
+    {
+        return PaymentOrder::class;
+    }
+
+    /**
+     * @description: 枚举
+     * @return {*}
+     */    
+    public static function enum() :string
+    {
+        return '';
+    }
+
+    /**
+     * @description: 获取查询条件
+     * @param {array} $search 查询内容
+     * @return {array}
+     */    
+    public static function getWhere(array $search = []) :array
+    {
+        $where = [];
+        if(isset($search['member_id']) && !empty($search['member_id'])){
+            $where[] = ['member_id', '=', $search['member_id']];
+        }
+        if(isset($search['type']) && !empty($search['type'])){
+            $where[] = ['type', '=', $search['type']];
+        }
+        if(isset($search['channel']) && !empty($search['channel'])){
+            $where[] = ['channel', '=', $search['channel']];
+        }
+        if(isset($search['id']) && !empty($search['id'])){
+            $where[] = ['id', '=', $search['id']];
+        }
+        if(isset($search['status']) && !empty($search['status'])){
+            $where[] = ['status', '=', $search['status']];
+        }
+        return $where;
+    }
+
+     /**
+     * @description: 查询单条数据
+     * @param array $search
+     * @return \App\Models\Coin|null
+     */
+    public static function findOne(array $search): ?PaymentOrder
+    {
+        return self::model()::where(self::getWhere($search))->first();
+    }
+
+    /**
+     * @description: 查询所有数据
+     * @param array $search
+     * @return \Illuminate\Database\Eloquent\Collection
+     */
+    public static function findAll(array $search = [])
+    {
+        return self::model()::where(self::getWhere($search))->get();
+    }
+
+    /**
+     * @description: 分页查询
+     * @param array $search
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     */
+    public static function paginate(array $search = [])
+    {
+        $limit = isset($search['limit'])?$search['limit']:15;
+        $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
+        return ['total' => $paginator->total(), 'data' => $paginator->items()];
+    }
+
+    /**
+     * @description: 
+     * @param {*} $params
+     * @return {*}
+     */    
+    public static function submit($params = [])
+    {
+        $result = false;
+        $msg['code'] = self::NOT;
+        $msg['msg'] = '';
+        
+        // 2. 判断是否是更新
+        if (!empty($params['id'])) {
+            // 更新
+            $info = self::findOne(['id'=>$params['id']] );
+            if (!$info) {
+                $msg['msg'] = '数据不存在!';
+            }else{
+                $result = $info->update($params);
+                $id = $params['id'];
+            }
+        } else {
+            // 创建
+            $result = $info = self::model()::create($params);
+            $id = $result->id;
+        }
+        
+       
+        if($result){
+           $msg['code'] = self::YES;
+           $msg['msg'] = '设置成功';
+           $msg['key'] = $id;
+        }else{
+            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
+        }
+
+        return $msg;
+    }
+
+    public static function createPayout($memberId ,$amount ,$channel ,$bank_name ,$account ,$card_no)
+    {
+        $data = [];
+        $data['type'] = self::TYPE_PAYOUT;
+        $order_no = self::createOrderNo('sj'.$data['type'].'_',$memberId);
+        $data['order_no'] = $order_no;
+        $data['member_id'] = $memberId;
+        $amount = number_format($amount, 2, '.', '');
+        $data['amount'] = $amount;
+        $data['channel'] = $channel;
+        $data['bank_name'] = $bank_name;
+        $data['account'] = $account;
+        $data['card_no'] = $card_no;
+        $data['callback_url'] = SanJinService::getNotifyUrl();
+
+        $ret = SanJinService::payout($amount,$order_no,$bank_name,$account,$card_no);
+
+        return $ret;
+    }
+
+}

+ 48 - 0
database/migrations/2025_11_10_160558_create_payment_orders_table.php

@@ -0,0 +1,48 @@
+<?php
+
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('payment_orders', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->tinyInteger('type')->default(1)->comment('类型:1=代收,2=代付');
+            $table->string('order_no', 64)->unique()->comment('订单号');
+            $table->string('member_id', 64)->comment('会员ID');
+            $table->decimal('amount', 18, 2)->comment('金额');
+            $table->string('channel', 50)->nullable()->comment('渠道');
+            // 代付字段(可选)
+            $table->string('bank_name', 100)->nullable()->comment('银行名称(代付时使用)');
+            $table->string('account', 100)->nullable()->comment('收款人姓名(代付时使用)');
+            $table->string('card_no', 100)->nullable()->comment('收款银行卡号(代付时使用)');
+
+            $table->tinyInteger('status')->default(0)->comment('状态:0待处理 1处理中 2成功 3失败');
+            $table->string('callback_url', 255)->nullable()->comment('回调地址');
+            $table->json('callback_data')->nullable()->comment('第三方回调返回的数据');
+
+            $table->timestamps();
+            $table->index(['type', 'status']);
+            $table->index(['channel']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('payment_orders');
+    }
+};