db->beginTransaction(); try { $user_id = $payment_refund->user_id; $money = $payment_refund->amount; $mall_id = $payment_refund->mall_id; // $order_id = $order->id; //使用该方法余额退款,退款金额需传入payment_trade表的pay_fee字段,而不是直接传订单支付金额,避免使用卡券抵扣产生重复退款问题 if (MallAddons::isInstall($mall_id, AddonsEnum::ADDONS_NAME_CARD_COUPONS)) { $payment = PaymentTrade::findOne(['out_trade_no'=>$payment_refund->out_trade_no]); $card_refund_price = CardCouponsScoreGive::setOrderRefundAll([ 'trade_id' => $payment->id ?? 0, 'refund_id' => $payment_refund->id, ]); // if($card_refund_price) $money -= $card_refund_price; // if($money < 0) $money = 0; } $insert_wallet [] = ['mall_id' => $mall_id, 'user_id' => $user_id, 'is_frozen' => false, 'wallet_type' => UserWalletService::WALLET_TYPE_BALANCE, 'money' => $money, 'desc' => $desc, 'source_table' => $source_table, 'source_table_id' => $source_table_id, 'from_type' => $from_type, 'capital_type' => $capital_type, ]; $res = UserWalletService::batchHandleByQueue($insert_wallet); if ($res == false) throw new \Exception(UserWalletService::getStaticError()); $payment_refund->is_pay = 1; $res = $payment_refund->save(); if ($res == false) throw new \Exception('生成余额退款记录失败'); $t->commit(); return true; } catch (\Exception $e) { $t->rollBack(); self::setStaticError($e->getMessage()); return false; } } }