user_money = bcsub($user->user_money, $order['actual'], 2); $user->save(); //用户支出流水 $record[] = [ 'financial_record_sn' => time(), 'order_id' => $order['id'], 'number_sn' => $order['number'], 'user_id' => $order['customer'], 'financial_type' => OrderEnum::USER_ORDER_PAY, 'financial_pm' => OrderEnum::EXPENDITURE, 'number' => $order['actual'], 'status' => 1, 'type' => OrderEnum::USER, 'mer_id' => $order['merchant'], ]; //商户获得流水 $record[] = [ 'financial_record_sn' => time(), 'order_id' => $order['id'], 'number_sn' => $order['number'], 'user_id' => $order['customer'], 'financial_type' => OrderEnum::MERCHANT_ORDER_OBTAINS, 'financial_pm' => OrderEnum::INCOME, 'number' => $order['actual'], 'status' => 0, 'type' => OrderEnum::MERCHANT, 'mer_id' => $order['merchant'], ]; (new FinancialRecord())->saveAll($record); Db::commit(); return true; } catch (Exception $e) { Db::rollback(); Log::error('余额支付失败' . $e->getMessage() . '。line:' . $e->getLine() . '。file:' . $e->getFile()); self::setError('余额支付失败' . $e->getMessage()); return false; } } /** * @notes 订单支付成功 * @param $order 订单 * @param $CallbackData 回调数据 * @date 2021/7/8 00:40 */ static function paySuccess($order, $CallbackData = []) { Db::startTrans(); try { $order->money = $CallbackData['money']; $order->paid = 1; $order->save(); if($order['cart_id']){ if(!is_array($order['cart_id'])){ $cart_arr=explode(',',$order['cart_id']); Cart::whereIn('cart_id',$cart_arr)->update(['is_pay'=>1]); }else{ Cart::whereIn('cart_id',$order['cart_id'])->update(['is_pay'=>1]); } } Log::info('支付成功'); // 提交事务 Db::commit(); return true; } catch (\Exception $e) { // 回滚事务 Db::rollback(); Log::error('支付失败'.$e->getMessage().'。like:'.$e->getLine()); self::setError('支付失败'.$e->getMessage()); return false; } } }