Sfoglia il codice sorgente

refactor(admin): 重构用户提现状态切换逻辑

- 移除提现额度扣减相关代码注释
- 添加提现拒绝时佣金和提现额度退回功能
- 优化代码格式和空格规范
- 完善拒绝提现时的数据回滚处理
shichen 3 mesi fa
parent
commit
6d7e40bf6c
1 ha cambiato i file con 63 aggiunte e 41 eliminazioni
  1. 63 41
      app/controller/admin/user/UserExtract.php

+ 63 - 41
app/controller/admin/user/UserExtract.php

@@ -200,48 +200,48 @@ class UserExtract extends BaseController
200 200
      */
201 201
     public function switchStatus($id)
202 202
     {
203
-        $data = $this->request->params(['status','fail_msg','mark']);
204
-        if($data['status'] == '-1' && empty($data['fail_msg']))
203
+        $data = $this->request->params(['status', 'fail_msg', 'mark']);
204
+        if ($data['status'] == '-1' && empty($data['fail_msg']))
205 205
             return app('json')->fail('请填写拒绝原因');
206
-        if(!$this->repository->getWhereCount($id))
206
+        if (!$this->repository->getWhereCount($id))
207 207
             return app('json')->fail('数据不存在或状态错误');
208 208
         $data['admin_id'] = $this->request->adminId();
209
-        $data['status_time'] = date('Y-m-d H:i:s',time());
210
-        $extract_data=Db::name('user_extract')->where('extract_id',$id)->find();
211
-        if($data['status']!='-1'){
212
-
213
-            /** @var UserRepository $userRepository */
214
-            $userRepository = app()->make(UserRepository::class);
215
-            $userEntity = $userRepository->getUserEntityByUid($extract_data['uid']);
216
-            if ($userEntity->getWithdrawalLimit() < $extract_data['extract_price']) {
217
-                return app('json')->fail('提现额度不足');
218
-            } else {
219
-                try {
220
-                    /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
221
-                    $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
222
-                    // 添加扣减记录
223
-                    $userWithdrawalLimitRecordEntity = $userWithdrawalLimitRecordRepository->addUserWithdrawalLimitRecord(
224
-                        (int)$userEntity->getUid(),
225
-                        UserWithdrawalLimitRecordEnum::PM['EXPEND']['code'],
226
-                        (float)$extract_data['extract_price'],
227
-                        -1,
228
-                        '',
229
-                        '提现扣减提现额度'
230
-                    );
231
-                    // 结算扣减记录
232
-                    $userWithdrawalLimitRecordRepository->executeByIdList([$userWithdrawalLimitRecordEntity->getId()]);
233
-                } catch (\Throwable $exception) {
234
-                    return app('json')->fail($exception->getMessage());
235
-                }
236
-            }
237
-
238
-            if($extract_data['extract_type']==1){
239
-                $res=$this->repository->WechatTransfers($id);
240
-                if($res['code']==201){
209
+        $data['status_time'] = date('Y-m-d H:i:s', time());
210
+        $extract_data = Db::name('user_extract')->where('extract_id', $id)->find();
211
+        if ($data['status'] != '-1') {
212
+
213
+            // /** @var UserRepository $userRepository */
214
+            // $userRepository = app()->make(UserRepository::class);
215
+            // $userEntity = $userRepository->getUserEntityByUid($extract_data['uid']);
216
+            // if ($userEntity->getWithdrawalLimit() < $extract_data['extract_price']) {
217
+            //     return app('json')->fail('提现额度不足');
218
+            // } else {
219
+            //     try {
220
+            //         /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
221
+            //         $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
222
+            //         // 添加扣减记录
223
+            //         $userWithdrawalLimitRecordEntity = $userWithdrawalLimitRecordRepository->addUserWithdrawalLimitRecord(
224
+            //             (int)$userEntity->getUid(),
225
+            //             UserWithdrawalLimitRecordEnum::PM['EXPEND']['code'],
226
+            //             (float)$extract_data['extract_price'],
227
+            //             -1,
228
+            //             '',
229
+            //             '提现扣减提现额度'
230
+            //         );
231
+            //         // 结算扣减记录
232
+            //         $userWithdrawalLimitRecordRepository->executeByIdList([$userWithdrawalLimitRecordEntity->getId()]);
233
+            //     } catch (\Throwable $exception) {
234
+            //         return app('json')->fail($exception->getMessage());
235
+            //     }
236
+            // }
237
+
238
+            if ($extract_data['extract_type'] == 1) {
239
+                $res = $this->repository->WechatTransfers($id);
240
+                if ($res['code'] == 201) {
241 241
                     return app('json')->success('微信处理中,请稍后');
242 242
                 }
243
-            }elseif ($extract_data['extract_type']==2){
244
-                $res=$this->repository->AliTransfers($id);
243
+            } elseif ($extract_data['extract_type'] == 2) {
244
+                $res = $this->repository->AliTransfers($id);
245 245
             }
246 246
 //            if($res['code']!=200 && $extract_data['types']==1){
247 247
 //                Db::name('user_rich')->where('uid',$extract_data['uid'])->inc('red', $extract_data['extract_price'])->update();
@@ -255,15 +255,37 @@ class UserExtract extends BaseController
255 255
 //                ]);
256 256
 //                return app('json')->fail(isset($res['msg'])?$res['msg']:'提现失败',$res);
257 257
 //            }
258
-        }else{
259
-            if($extract_data['withdrawal_type']==2) {
258
+        } else {
259
+            if ($extract_data['withdrawal_type'] == 2) {
260 260
                 Db::name('entropy_barter_bill')->where('order_no', $extract_data['order_sn'])->where('pm', 2)->update(['status' => 3, 'remarks' => '审核已拒绝']);
261 261
                 $eb_bill = Db::name('entropy_barter_bill')->where('order_no', $extract_data['order_sn'])->where('pm', 2)->find();
262 262
                 Db::name('entropy_barter_user_' . $extract_data['mer_id'])->where('eb_id', $eb_bill['to_id'])->inc('wallet', $extract_data['extract_price'])->update();
263 263
             }
264
+
265
+            // 拒绝提现要退回佣金和提现额度
266
+            if ($extract_data['withdrawal_type'] == 3) {
267
+                // 佣金
268
+                Db::name('user')->where('uid',$extract_data['uid'])->inc('brokerage_price',$extract_data['extract_price']);
269
+                // 提现额度
270
+                Db::name('user')->where('uid',$extract_data['uid'])->inc('withdrawal_limit',$extract_data['extract_price']);
271
+                // 提现额度记录
272
+                /** @var UserRepository $userRepository */
273
+                $userRepository = app()->make(UserRepository::class);
274
+                $userEntity = $userRepository->getUserEntityByUid($extract_data['uid']);
275
+                $recordData = [
276
+                    'user_id' => $extract_data['uid'],
277
+                    'pm' => UserWithdrawalLimitRecordEnum::PM['INCOME']['code'],
278
+                    'number' => $data['extract_price'],
279
+                    'balance' => $userEntity->withdrawalLimit + $extract_data['extract_price'],
280
+                    'type_shop' => -1,
281
+                    'order_sn' => '',
282
+                    'remark' => '提现拒绝增加提现额度'
283
+                ];
284
+                Db::name('user_withdrawal_limit_records')->insert($recordData);
285
+            }
264 286
         }
265
-        $this->repository->switchStatus($id,$data);
266
-        Db::name('user_extract')->where('extract_id',$id)->update($data);
287
+        $this->repository->switchStatus($id, $data);
288
+        Db::name('user_extract')->where('extract_id', $id)->update($data);
267 289
         return app('json')->success('审核成功');
268 290
     }
269 291