Browse Source

会员升级

Kirin 1 year ago
parent
commit
32ccf72dac
1 changed files with 77 additions and 75 deletions
  1. 77 75
      app/services/user/UserExtractServices.php

+ 77 - 75
app/services/user/UserExtractServices.php

@@ -161,87 +161,89 @@ class UserExtractServices extends BaseServices
     {
         $extractNumber = $userExtract['extract_price'];
         $this->transaction(function () use ($id, $userExtract, $extractNumber) {
-            if (!$this->dao->update($id, ['status' => 1])) {
-                throw new AdminException('修改失败');
-            }
-            //配置开启自动到零钱
-            if (sys_config('brokerage_type', 0)) {
-                /** @var WechatUserServices $wechatServices */
-                $wechatServices = app()->make(WechatUserServices::class);
-                $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'wechat');
-                if ($openid) {//公众号用户
-                    $type = Payment::WEB;
-                } else {//小程序用户
-                    $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'routine');
-                    $type = Payment::MINI;
-                }
-                //app微信用户
-                if (!$openid) {
-                    $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'app');
-                    $type = Payment::APP;
+            if ($userExtract['extract_type'] != 'bank') {
+                if (!$this->dao->update($id, ['status' => 1])) {
+                    throw new AdminException('修改失败');
                 }
-                if ($openid) {
-                    /** @var StoreOrderCreateServices $services */
-                    $services = app()->make(StoreOrderCreateServices::class);
-                    $wechat_order_id = $services->getNewOrderId();
-                    $res = Payment::merchantPay($openid, $wechat_order_id, $extractNumber, '提现佣金到零钱', $type);
-                    if (!$res) {
-                        throw new ValidateException('企业付款到零钱失败,请稍后再试');
+                //配置开启自动到零钱
+                if (sys_config('brokerage_type', 0)) {
+                    /** @var WechatUserServices $wechatServices */
+                    $wechatServices = app()->make(WechatUserServices::class);
+                    $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'wechat');
+                    if ($openid) {//公众号用户
+                        $type = Payment::WEB;
+                    } else {//小程序用户
+                        $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'routine');
+                        $type = Payment::MINI;
                     }
-                } else {
-                    throw new ValidateException('该用户暂不支持企业付款到零钱,请手动转账');
-                }
-            } else {
-                if ($userExtract['extract_type'] == 'bank') {
-                    $userServices = app()->make(UserServices::class);
-                    $userInfo = $userServices->get($userExtract['uid']);
-                    if (!$userInfo['professional_id']) {
-                        throw new ValidateException('用户未认证签约');
+                    //app微信用户
+                    if (!$openid) {
+                        $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'app');
+                        $type = Payment::APP;
                     }
-                    $bankInfo = WithdrawService::init()::contractInfo($userInfo['enterprise_professional_facilitator_id']);
-                    if (!$bankInfo['sign_img']) throw new ValidateException('用户未签约');
-                    $res = WithdrawService::init()::fastIssuing(
-                        $userInfo['professional_id'],
-                        $userExtract['id'],
-                        $bankInfo['name'],
-                        $bankInfo['cer_code'],
-                        $bankInfo['mobile'],
-                        $bankInfo['bank_code'],
-                        $extractNumber,
-                        '佣金提现'
-                    );
-                    if ($res) {
-                        $this->dao->update($id, ['trade_number' => $res['trade_number']]);
+                    if ($openid) {
+                        /** @var StoreOrderCreateServices $services */
+                        $services = app()->make(StoreOrderCreateServices::class);
+                        $wechat_order_id = $services->getNewOrderId();
+                        $res = Payment::merchantPay($openid, $wechat_order_id, $extractNumber, '提现佣金到零钱', $type);
+                        if (!$res) {
+                            throw new ValidateException('企业付款到零钱失败,请稍后再试');
+                        }
+                    } else {
+                        throw new ValidateException('该用户暂不支持企业付款到零钱,请手动转账');
                     }
                 }
-            }
-        });
-
-        /** @var UserServices $userServices */
-        $userServices = app()->make(UserServices::class);
-        $userType = $userServices->value(['uid' => $userExtract['uid']], 'user_type');
-        $nickname = $userServices->value(['uid' => $userExtract['uid']], 'nickname');
-        $phone = $userServices->value(['uid' => $userExtract['uid']], 'phone');
+                /** @var UserServices $userServices */
+                $userServices = app()->make(UserServices::class);
+                $userType = $userServices->value(['uid' => $userExtract['uid']], 'user_type');
+                $nickname = $userServices->value(['uid' => $userExtract['uid']], 'nickname');
+                $phone = $userServices->value(['uid' => $userExtract['uid']], 'phone');
 
-        switch ($userExtract['extract_type']) {
-            case 'bank':
-                $order_id = $userExtract['bank_code'];
-                break;
-            case 'weixin':
-                $order_id = $userExtract['wechat'];
-                break;
-            case 'alipay':
-                $order_id = $userExtract['alipay_code'];
-                break;
-            default:
-                $order_id = '';
-                break;
-        }
-        //记录资金流水队列
-        CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $userExtract['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $extractNumber, 'pay_type' => $userExtract['extract_type']], 'extract']);
+                switch ($userExtract['extract_type']) {
+                    case 'bank':
+                        $order_id = $userExtract['bank_code'];
+                        break;
+                    case 'weixin':
+                        $order_id = $userExtract['wechat'];
+                        break;
+                    case 'alipay':
+                        $order_id = $userExtract['alipay_code'];
+                        break;
+                    default:
+                        $order_id = '';
+                        break;
+                }
+                //记录资金流水队列
+                CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $userExtract['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $extractNumber, 'pay_type' => $userExtract['extract_type']], 'extract']);
 
-        //消息推送
-        event('notice.notice', [['uid' => $userExtract['uid'], 'userType' => strtolower($userType), 'extractNumber' => $extractNumber, 'nickname' => $nickname], 'user_extract']);
+                //消息推送
+                event('notice.notice', [['uid' => $userExtract['uid'], 'userType' => strtolower($userType), 'extractNumber' => $extractNumber, 'nickname' => $nickname], 'user_extract']);
+            } else {
+                if (!$this->dao->update($id, ['status' => 2])) {
+                    throw new AdminException('修改失败');
+                }
+                $userServices = app()->make(UserServices::class);
+                $userInfo = $userServices->get($userExtract['uid']);
+                if (!$userInfo['professional_id']) {
+                    throw new ValidateException('用户未认证签约');
+                }
+                $bankInfo = WithdrawService::init()::contractInfo($userInfo['enterprise_professional_facilitator_id']);
+                if (!$bankInfo['sign_img']) throw new ValidateException('用户未签约');
+                $res = WithdrawService::init()::fastIssuing(
+                    $userInfo['professional_id'],
+                    $userExtract['id'],
+                    $bankInfo['name'],
+                    $bankInfo['cer_code'],
+                    $bankInfo['mobile'],
+                    $bankInfo['bank_code'],
+                    $extractNumber,
+                    '佣金提现'
+                );
+                if ($res) {
+                    $this->dao->update($id, ['trade_number' => $res['trade_number']]);
+                }
+            }
+        });
         return true;
     }
 
@@ -342,7 +344,7 @@ class UserExtractServices extends BaseServices
         if (!$extract) {
             throw new AdminException('操作记录不存!');
         }
-        if ($extract->status == 1) {
+        if ($extract->status == 1 || $extract->status == 2) {
             throw new AdminException('您已提现,请勿重复提现!');
         }
         if ($extract->status == -1) {