wesmiler 2 months ago
parent
commit
d4a1128e83

+ 1 - 1
app/Http/Controllers/Admin/WithdrawController.php

@@ -72,6 +72,6 @@ class WithdrawController extends Backend
      * @return mixed
      */
     public function auth(){
-        return $this->service->audit();
+        return $this->service->auth();
     }
 }

+ 105 - 0
app/Services/Common/BalanceLogService.php

@@ -335,4 +335,109 @@ class BalanceLogService extends BaseService
 
         return $data;
     }
+
+    /**
+     * 审核
+     * @return array
+     */
+    public function auth()
+    {
+        $params = request()->post();
+        $id = isset($params['id'])? $params['id'] : 0;
+        $paStatus = isset($params['pay_status'])? $params['pay_status'] : 10;
+        $cacheKey = "caches:members:withdraw:auth_lock_{$id}";
+        if(RedisService::get($cacheKey)){
+            return message('请不要频繁操作',false);
+        }
+
+        $data = [
+            'id'=> $id,
+            'actual_money'=> isset($params['actual_money'])? floatval($params['actual_money']) : 0,
+            'audit_remark'=> isset($params['audit_remark'])? trim($params['audit_remark']) : '',
+            'status'=> isset($params['status'])? $params['status'] : 0,
+            'update_time'=> time(),
+        ];
+
+        if($data['actual_money']<=0){
+            $data['actual_money'] = isset($params['money'])? floatval($params['money']) : 0;
+        }
+
+        $info = $this->model->with(['member'])->where(['id'=> $id,'mark'=>1])->first();
+        if($id<=0 || empty($info)){
+            return message('提现记录不存在',false);
+        }
+
+        $status = isset($info['status'])? $info['status'] : 0;
+        if($status != 1){
+            return message('当前状态不可操作',false);
+        }
+
+        $data['pay_status'] = $paStatus;
+
+        // 处理
+        RedisService::set($cacheKey, $info, rand(2,3));
+        DB::beginTransaction();
+        $result = parent::edit($data);
+        $success = isset($result['success'])? $result['success'] : '';
+        if($success != true){
+            DB::rollBack();
+            RedisService::clear($cacheKey);
+            return message('审核失败',false);
+        }
+
+        if($data['status'] == 2){
+            // 统计
+            $updateData = [
+                'withdraw_total'=> DB::raw("withdraw_total + {$info['money']}"),
+                'update_time'=> time(),
+            ];
+            if(!MemberModel::where(['id'=> $info['user_id'],'mark'=>1],)->update($updateData)){
+                DB::rollBack();
+                RedisService::clear($cacheKey);
+                return message('提现审核处理失败',false);
+            }
+        }
+        // 审核失败
+        else if ($data['status'] == 3){
+            // 退钱给用户
+            $userInfo = isset($info['member'])?$info['member']:[];
+            $balance = isset($userInfo['balance'])?$userInfo['balance']: 0;
+            $updateData = [
+                'balance'=> DB::raw("balance + {$info['money']}"),
+                'update_time'=> time(),
+            ];
+            if(!MemberModel::where(['id'=> $info['user_id'],'mark'=>1],)->update($updateData)){
+                DB::rollBack();
+                RedisService::clear($cacheKey);
+                return message('提现审核处理失败',false);
+            }
+
+            // 明细
+            $log = [
+                'user_id' => $info['user_id'],
+                'source_order_no' => isset($info['order_no'])? $info['order_no'] :'',
+                'type' => 5, // 提现退还
+                'money' => $info['money'],
+                'after_money' => moneyFormat($balance +$info['money'],2),
+                'create_time' => time(),
+                'update_time' => time(),
+                'remark' => '提现失败退还',
+                'status' => 1,
+                'mark' => 1,
+            ];
+
+            if (!AccountLogModel::insertGetId($log)) {
+                DB::rollBack();
+                RedisService::clear($cacheKey);
+                return message('提现审核账户处理失败',false);
+            }
+        }
+
+        // 设置日志标题
+        ActionLogModel::setTitle("提现审核");
+        ActionLogModel::record();
+
+        DB::commit();
+        return $result;
+    }
 }