Kirin 3 éve
szülő
commit
0d584843a8

+ 24 - 1
app/admin/controller/finance/UserExtract.php

@@ -9,12 +9,13 @@
 namespace app\admin\controller\finance;
 
 use app\admin\controller\AuthController;
+use app\admin\model\wechat\WechatUser;
 use app\models\system\SystemStoreMember;
 use app\models\user\UserBill;
 use think\facade\Route as Url;
 use crmeb\services\JsonService;
 use app\admin\model\user\UserExtract as UserExtractModel;
-use crmeb\services\{UtilService as Util, FormBuilder as Form};
+use crmeb\services\{UtilService as Util, FormBuilder as Form, WechatService};
 
 /**
  * 用户提现管理
@@ -157,6 +158,28 @@ class UserExtract extends AuthController
             $res = $res && UserBill::income('提现转换(股份)', $extract['uid'], 'gf', 'extract_get_gf', $extract['commission_gf'], $extract['id'], \app\admin\model\user\User::where('uid', $extract['uid'])->value('gf') + $extract['commission_gf'], '提现申请通过,其中部分佣金转换为股份' . $extract['commission_gf']);
             $res = $res && \app\admin\model\user\User::where('uid', $extract['uid'])->inc('gf', $extract['commission_gf'])->update();
         }
+
+        $real_get = $extract['extract_price'] - $extract['commission_gf'] - $extract['commission_consumer'] - $extract['commission_yue'] - $extract['commission'];
+
+        if ($real_get > 0) {
+            $open_id = WechatUser::where('uid', $extract['uid'])->find();
+            if ($open_id['openid']) {
+                try {
+                    WechatService::paymentService()->batches('ex' . date('YmdHis') . $extract['id'], sys_config('site_name') . '-' . '用户提现到账',
+                        '提现申请通过,实际到账' . $real_get . '元', $real_get * 100, 1, [
+                            [
+                                'out_detail_no' => 'ex' . date('YmdHis') . $extract['id'] . '-1',
+                                'transfer_amount' => $real_get * 100,
+                                'transfer_remark' => '提现申请通过,实际到账' . $real_get . '元',
+                                'openid' => $open_id['openid'],
+                            ]
+                        ]);
+                } catch (\Exception $e) {
+                    UserExtractModel::rollbackTrans();
+                    return JsonService::fail($e->getMessage());
+                }
+            }
+        }
 //        if ($extract['commission_gf'] > 0 && SystemStoreMember::be(['uid' => $extract['uid']])) {
 //            $res = $res && SystemStoreMember::where('uid', $extract['uid'])->inc('consume_rights', $extract['commission_gf'])->update();
 //        }

+ 21 - 0
vendor/overtrue/wechat/src/Payment/API.php

@@ -74,6 +74,7 @@ class API extends AbstractAPI
     const API_QUERY_REFUND = '/pay/refundquery';
     const API_DOWNLOAD_BILL = '/pay/downloadbill';
     const API_REPORT = '/payitil/report';
+    const api_batches = '/v3/transfer/batches';
 
     const API_URL_SHORTEN = 'https://api.mch.weixin.qq.com/tools/shorturl';
     const API_AUTH_CODE_TO_OPENID = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid';
@@ -561,4 +562,24 @@ class API extends AbstractAPI
     {
         return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir());
     }
+
+    public function batches(
+        $out_batch_no,
+        $batch_name,
+        $batch_remark,
+        $total_amount,
+        $total_num,
+        $transfer_detail_list
+    ) {
+        $params = [
+            'out_batch_no' => $out_batch_no,
+            'batch_name' => $batch_name,
+            'batch_remark' => $batch_remark,
+            'total_amount' => $total_amount,
+            'total_num' => $total_num,
+            'transfer_detail_list' => $transfer_detail_list,
+        ];
+
+        return $this->safeRequest($this->wrapApi(self::api_batches), $params);
+    }
 }