Explorar el Código

修改提现处理

邹景立 hace 4 años
padre
commit
a590d540eb

+ 6 - 6
SQL01-数据表结构.sql

@@ -11,7 +11,7 @@
  Target Server Version : 50562
  File Encoding         : 65001
 
- Date: 22/03/2021 15:05:49
+ Date: 23/03/2021 14:35:38
 */
 
 SET NAMES utf8mb4;
@@ -300,8 +300,8 @@ CREATE TABLE `data_user_transfer`  (
   `type` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '提现方式',
   `date` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '提现日期',
   `code` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '提现单号',
-  `openid1` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '公众号OPENID1',
-  `openid2` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '公众号OPENID2',
+  `appid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '公众号APPID',
+  `openid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '公众号OPENID',
   `charge_rate` decimal(20, 4) NULL DEFAULT 0.0000 COMMENT '提现手续费比例',
   `charge_amount` decimal(20, 2) NULL DEFAULT 0.00 COMMENT '提现手续费金额',
   `amount` decimal(20, 2) NULL DEFAULT 0.00 COMMENT '提现转账金额',
@@ -329,8 +329,8 @@ CREATE TABLE `data_user_transfer`  (
   INDEX `idx_data_user_transfer_type`(`type`) USING BTREE,
   INDEX `idx_data_user_transfer_code`(`code`) USING BTREE,
   INDEX `idx_data_user_transfer_status`(`status`) USING BTREE,
-  INDEX `idx_data_user_transfer_openid1`(`openid1`) USING BTREE,
-  INDEX `idx_data_user_transfer_openid2`(`openid2`) USING BTREE,
+  INDEX `idx_data_user_transfer_appid`(`appid`) USING BTREE,
+  INDEX `idx_data_user_transfer_openid`(`openid`) USING BTREE,
   INDEX `idx_data_user_transfer_audit_status`(`audit_status`) USING BTREE
 ) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '数据-用户-提现' ROW_FORMAT = Compact;
 
@@ -813,7 +813,7 @@ CREATE TABLE `system_oplog`  (
   `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '操作人用户名',
   `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 90 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统-日志' ROW_FORMAT = COMPACT;
+) ENGINE = InnoDB AUTO_INCREMENT = 94 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '系统-日志' ROW_FORMAT = COMPACT;
 
 -- ----------------------------
 -- Table structure for system_queue

+ 53 - 42
app/data/command/UserTransfer.php

@@ -41,13 +41,15 @@ class UserTransfer extends Command
             if ($vo['status'] === 3) {
                 $this->queue->message($total, $count, "尝试处理订单 {$vo['code']} 打款", 1);
                 if ($vo['type'] === 'wechat_banks') {
-                    $result = $this->createTransferBank($vo);
+                    [$config, $result] = $this->createTransferBank($vo);
                 } else {
-                    $result = $this->createTransferWallet($vo);
+                    [$config, $result] = $this->createTransferWallet($vo);
                 }
                 if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
                     $this->app->db->name('DataUserTransfer')->where(['code' => $vo['code']])->update([
                         'status'      => 4,
+                        'appid'       => $config['appid'],
+                        'openid'      => $config['openid'],
                         'trade_no'    => $result['partner_trade_no'],
                         'trade_time'  => $result['payment_time'] ?? date('Y-m-d H:i:s'),
                         'change_time' => date('Y-m-d H:i:s'),
@@ -79,7 +81,7 @@ class UserTransfer extends Command
     /**
      * 尝试提现转账到银行卡
      * @param array $item
-     * @return array
+     * @return array [config, result]
      * @throws Exception
      * @throws \WeChat\Exceptions\InvalidDecryptException
      * @throws \WeChat\Exceptions\InvalidResponseException
@@ -90,20 +92,21 @@ class UserTransfer extends Command
      */
     private function createTransferBank(array $item): array
     {
-        return TransfersBank::instance($this->getConfig($item['uid']))->create([
+        $config = $this->getConfig($item['uid']);
+        return [$config, TransfersBank::instance($config)->create([
             'partner_trade_no' => $item['code'],
             'enc_bank_no'      => $item['bank_code'],
             'enc_true_name'    => $item['bank_user'],
             'bank_code'        => $item['bank_wseq'],
             'amount'           => intval($item['amount'] - $item['charge_amount']) * 100,
             'desc'             => '微信银行卡提现',
-        ]);
+        ])];
     }
 
     /**
      * 尝试提现转账到微信钱包
      * @param array $item
-     * @return array
+     * @return array [config, result]
      * @throws Exception
      * @throws \WeChat\Exceptions\InvalidResponseException
      * @throws \WeChat\Exceptions\LocalCacheException
@@ -114,14 +117,14 @@ class UserTransfer extends Command
     private function createTransferWallet(array $item): array
     {
         $config = $this->getConfig($item['uid']);
-        return Transfers::instance($config)->create([
+        return [$config, Transfers::instance($config)->create([
             'openid'           => $config['openid'],
             'amount'           => intval($item['amount'] - $item['charge_amount']) * 100,
             'partner_trade_no' => $item['code'],
             'spbill_create_ip' => '127.0.0.1',
             'check_name'       => 'NO_CHECK',
             'desc'             => '微信余额提现',
-        ]);
+        ])];
     }
 
     /**
@@ -136,10 +139,14 @@ class UserTransfer extends Command
      */
     private function queryTransferWallet(array $item)
     {
-        $result = Transfers::instance($this->getConfig($item['uid']))->query($item['partner_trade_no']);
+        $config = $this->getConfig($item['uid']);
+        [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']];
+        $result = Transfers::instance($config)->query($item['partner_trade_no']);
         if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
             $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([
                 'status'      => 5,
+                'appid'       => $config['appid'],
+                'openid'      => $config['openid'],
                 'trade_time'  => $result['payment_time'],
                 'change_time' => date('Y-m-d H:i:s'),
                 'change_desc' => '微信提现打款成功',
@@ -159,11 +166,15 @@ class UserTransfer extends Command
      */
     private function queryTransferBank(array $item)
     {
-        $result = TransfersBank::instance($this->getConfig($item['uid']))->query($item['partner_trade_no']);
+        $config = $this->getConfig($item['uid']);
+        [$config['appid'], $config['openid']] = [$item['appid'], $item['openid']];
+        $result = TransfersBank::instance($config)->query($item['partner_trade_no']);
         if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
             if ($result['status'] === 'SUCCESS') {
                 $this->app->db->name('DataUserTransfer')->where(['code' => $item['code']])->update([
                     'status'      => 5,
+                    'appid'       => $config['appid'],
+                    'openid'      => $config['openid'],
                     'trade_time'  => $result['pay_succ_time'] ?: date('Y-m-d H:i:s'),
                     'change_time' => date('Y-m-d H:i:s'),
                     'change_desc' => '微信提现打款成功',
@@ -182,38 +193,6 @@ class UserTransfer extends Command
     }
 
     /**
-     * 根据配置获取用户OPENID
-     * @param int $uid
-     * @param string $type
-     * @return mixed|null
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     */
-    private function getWechatInfo(int $uid, string $type): ?array
-    {
-        $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find();
-        if (empty($user)) return null;
-        $appid1 = sysdata('data.wxapp_appid');
-        if (strtolower(sysconf('wechat.type')) === 'api') {
-            $appid2 = sysconf('wechat.appid');
-        } else {
-            $appid2 = sysconf('wechat.thr_appid');
-        }
-        if ($type === 'normal') {
-            if (!empty($user['openid1'])) return [$appid1, $user['openid1']];
-            if (!empty($user['openid2'])) return [$appid2, $user['openid2']];
-        }
-        if ($type === 'wxapp' && !empty($user['openid1'])) {
-            return [$appid1, $user['openid1']];
-        }
-        if ($type === 'wechat' && !empty($user['openid2'])) {
-            return [$appid2, $user['openid2']];
-        }
-        return null;
-    }
-
-    /**
      * 获取微信提现参数
      * @param int $uid
      * @return array
@@ -247,4 +226,36 @@ class UserTransfer extends Command
             'cache_path' => $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . 'wechat',
         ];
     }
+
+    /**
+     * 根据配置获取用户OPENID
+     * @param int $uid
+     * @param string $type
+     * @return mixed|null
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    private function getWechatInfo(int $uid, string $type): ?array
+    {
+        $user = $this->app->db->name('DataUser')->where(['id' => $uid])->find();
+        if (empty($user)) return null;
+        $appid1 = sysdata('data.wxapp_appid');
+        if (strtolower(sysconf('wechat.type')) === 'api') {
+            $appid2 = sysconf('wechat.appid');
+        } else {
+            $appid2 = sysconf('wechat.thr_appid');
+        }
+        if ($type === 'normal') {
+            if (!empty($user['openid1'])) return [$appid1, $user['openid1']];
+            if (!empty($user['openid2'])) return [$appid2, $user['openid2']];
+        }
+        if ($type === 'wxapp' && !empty($user['openid1'])) {
+            return [$appid1, $user['openid1']];
+        }
+        if ($type === 'wechat' && !empty($user['openid2'])) {
+            return [$appid2, $user['openid2']];
+        }
+        return null;
+    }
 }

+ 0 - 2
app/data/controller/api/auth/Transfer.php

@@ -41,8 +41,6 @@ class Transfer extends Auth
         $data['uid'] = $this->uuid;
         $data['date'] = date('Y-m-d');
         $data['code'] = CodeExtend::uniqidDate(20, 'T');
-        $data['openid1'] = $this->user['openid1'];
-        $data['openid2'] = $this->user['openid2'];
         // 提现状态处理
         if (empty($transfers[$data['type']]['state']['audit'])) {
             $data['status'] = 1;