Ken 5 dní pred
rodič
commit
bc527f2648

+ 15 - 1
app/Http/Controllers/admin/PaymentOrder.php

@@ -15,9 +15,12 @@ class PaymentOrder extends Controller
 
     public function audit()
     {
+        DB::beginTransaction();
         try {
             $validate = [
-                'id' => ['required', 'integer', 'min:1'],
+//                'id' => ['required', 'integer', 'min:1'],
+                'ids' => ['required', 'array', 'min:1','max:20'],
+                'ids.*' => ['required', 'integer', 'min:1'],
                 'status' => ['required', 'integer', 'in:1,3'],
             ];
             $status = request()->input('status', null);
@@ -26,16 +29,27 @@ class PaymentOrder extends Controller
             }
             $params = request()->validate($validate);
             $remark = request()->input('remark', '');
+
+            $count = 0;
             if ($params['status'] == 1) {
                 $ret = PaymentOrderService::createPayout($params['id']);
+                if ($ret['code'] === 0)$count++;
                 if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
             } else {
                 $ret = PaymentOrderService::withdrawalFailed($params['id'], $remark);
+                if ($ret['code'] === 0)$count++;
                 if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
             }
+
+            if ($count < 1) {
+                throw new Exception('操作失败', HttpStatus::CUSTOM_ERROR);
+            }
+            DB::commit();
         } catch (ValidationException $e) {
+            DB::rollBack();
             return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
         } catch (Exception $e) {
+            DB::rollBack();
             return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
         }
         return $this->success();

+ 1 - 6
app/Services/PaymentOrderService.php

@@ -324,7 +324,6 @@ class PaymentOrderService extends BaseService
      */
     public static function withdrawalFailed($orderId, $remark): array
     {
-        DB::beginTransaction();
         try {
             $order = PaymentOrder::where('id', $orderId)
                 ->where('type', 2)
@@ -347,9 +346,7 @@ class PaymentOrderService extends BaseService
             }
             // 记录退款日志
             BalanceLogService::addLog($order->member_id, $order->amount, $beforeBalance, $availableBalance, '三方提现', $order->id, '提现失败退款');
-            DB::commit();
         } catch (Exception $e) {
-            DB::rollBack();
             return ['code' => HttpStatus::CUSTOM_ERROR, 'msg' => $e->getMessage()];
         }
         return ['code' => 0, 'msg' => 'ok'];
@@ -361,7 +358,7 @@ class PaymentOrderService extends BaseService
      */
     public static function createPayout(int $orderId): array
     {
-        DB::beginTransaction();
+
         try {
             $order = PaymentOrder::where('id', $orderId)
                 ->where('type', 2)
@@ -375,9 +372,7 @@ class PaymentOrderService extends BaseService
             if ($ret['code'] != 200) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
             $order->status = self::STATUS_PROCESS;
             $order->save();
-            DB::commit();
         } catch (Exception $e) {
-            DB::rollBack();
             return ['code' => HttpStatus::CUSTOM_ERROR, 'msg' => $e->getMessage()];
         }
         return ['code' => 0, 'msg' => 'ok'];