Jelajahi Sumber

会员升级

Kirin 1 tahun lalu
induk
melakukan
cf469cadd6

+ 70 - 1
app/controller/api/v1/WithdrawController.php

@@ -10,7 +10,10 @@
 // +----------------------------------------------------------------------
 namespace app\controller\api\v1;
 
+use app\jobs\system\CapitalFlowJob;
 use app\Request;
+use app\services\user\UserExtractServices;
+use app\services\user\UserServices;
 use crmeb\basic\BaseController;
 use crmeb\services\WithdrawService;
 
@@ -31,12 +34,78 @@ class WithdrawController extends BaseController
         }
         $sign = $data['sign'];
         unset($data['sign']);
+        /** @var UserExtractServices $extract_service */
+        $extract_service = app()->make(UserExtractServices::class);
         if (WithdrawService::init()::checkSign($data, $sign)) {
             switch ($data['type']) {
                 case 'create_batch_order':
                     if ($data['return_code'] == 'SUCCESS') {
                         $info = WithdrawService::init()::decode($data['resoult']);
-                        @file_put_contents('notify.txt', json_encode($info) . PHP_EOL, FILE_APPEND);
+                        @file_put_contents('notify.txt', $data['type'] . json_encode($info) . PHP_EOL, FILE_APPEND);
+                        $list = $extract_service->getList(['trade_number' => $info['trade_number'], 'status' => 2]);
+                        if ($info['data']['result_code'] != 'SUCCESS') {
+                            foreach ($list as $v) {
+                                $extract_service->update($v['id'], ['status' => 0, 'mark' => '业务处理失败']);
+                            }
+                        } else {
+                            foreach ($list as $v) {
+                                $extract_service->update($v['id'], ['enterprise_order_id' => $info['data']['enterprise_order_id']]);
+                            }
+                        }
+                    }
+                    break;
+                case 'refuse_order':
+                    if ($data['return_code'] == 'SUCCESS') {
+                        $info = WithdrawService::init()::decode($data['resoult']);
+                        @file_put_contents('notify.txt', $data['type'] . json_encode($info) . PHP_EOL, FILE_APPEND);
+                        $list = $extract_service->getList(['enterprise_order_id' => $info['enterprise_order_id'], 'status' => 2]);
+                        foreach ($list as $v) {
+                            $extract_service->refuse($v['id'], $info['remarks']);
+                        }
+                    }
+                    break;
+                case 'payment_resout':
+                    if ($data['return_code'] == 'SUCCESS') {
+                        $info = WithdrawService::init()::decode($data['resoult']);
+                        @file_put_contents('notify.txt', $data['type'] . json_encode($info) . PHP_EOL, FILE_APPEND);
+                        $id = explode('_', $info['request_no'])[1] ?? 0;
+                        if ($id) {
+                            $list = $extract_service->getList(['id' => $id, 'status' => 2]);
+                            foreach ($list as $v) {
+                                if ($info['payment_status'] == 2) {
+                                    $extract_service->update($v['id'], ['status' => 0, 'mark' => '失败']);
+                                }
+                                if ($info['payment_status'] == 4) {
+                                    $extract_service->update($v['id'], ['status' => 1, 'mark' => '成功']);
+
+                                    /** @var UserServices $userServices */
+                                    $userServices = app()->make(UserServices::class);
+                                    $userType = $userServices->value(['uid' => $v['uid']], 'user_type');
+                                    $nickname = $userServices->value(['uid' => $v['uid']], 'nickname');
+                                    $phone = $userServices->value(['uid' => $v['uid']], 'phone');
+
+                                    switch ($v['extract_type']) {
+                                        case 'bank':
+                                            $order_id = $v['bank_code'];
+                                            break;
+                                        case 'weixin':
+                                            $order_id = $v['wechat'];
+                                            break;
+                                        case 'alipay':
+                                            $order_id = $v['alipay_code'];
+                                            break;
+                                        default:
+                                            $order_id = '';
+                                            break;
+                                    }
+                                    //记录资金流水队列
+                                    CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $v['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $v['extract_price'], 'pay_type' => $v['extract_type']], 'extract']);
+
+                                    //消息推送
+                                    event('notice.notice', [['uid' => $v['uid'], 'userType' => strtolower($userType), 'extractNumber' => $v['extract_price'], 'nickname' => $nickname], 'user_extract']);
+                                }
+                            }
+                        }
                     }
                     break;
                 default:

+ 21 - 0
app/model/user/UserExtract.php

@@ -84,6 +84,27 @@ class UserExtract extends BaseModel
         if ($value != '') $query->where('extract_type', $value);
     }
 
+
+    /**
+     * 提现方式
+     * @param Model $query
+     * @param $value
+     */
+    public function searchTradeNumberAttr($query, $value)
+    {
+        if ($value != '') $query->where('trade_number', $value);
+    }
+
+    /**
+     * 提现方式
+     * @param Model $query
+     * @param $value
+     */
+    public function searchEnterpriseOrderIdAttr($query, $value)
+    {
+        if ($value != '') $query->where('enterprise_order_id', $value);
+    }
+
     /**
      * 审核状态
      * @param Model $query

+ 1 - 1
crmeb/services/WithdrawService.php

@@ -232,7 +232,7 @@ class WithdrawService
      * @param $businessBodyString
      * @return mixed
      */
-    public static function decode($businessBodyString, $msg)
+    public static function decode($businessBodyString, $msg = '')
     {
         //进行Aes解密
         include_once 'phpseclib/Crypt/AES.php';