|
@@ -2441,9 +2441,9 @@ readonly class OrderService
|
|
|
* }
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
- public function assignCoach(int $userId, int $orderId, int $coachId, int $payment_type): array|bool
|
|
|
+ public function assignCoach(int $userId, int $orderId, int $coachId, int $payment_type, ?float $distance = null): array|bool
|
|
|
{
|
|
|
- return DB::transaction(function () use ($userId, $orderId, $coachId, $payment_type) {
|
|
|
+ return DB::transaction(function () use ($userId, $orderId, $coachId, $payment_type, $distance) {
|
|
|
try {
|
|
|
// 1. 验证参数
|
|
|
$order = $this->validateAssignOrder($userId, $orderId);
|
|
@@ -2462,6 +2462,26 @@ readonly class OrderService
|
|
|
|
|
|
if (! is_null($payment_type)) {
|
|
|
$order->payment_type = $payment_type;
|
|
|
+
|
|
|
+ // 2. 计算订单金额
|
|
|
+ $amounts = $this->calculateOrderAmount(
|
|
|
+ userId: $userId,
|
|
|
+ addressId: $order->address_id ?? null,
|
|
|
+ coachId: $coachId ?? null,
|
|
|
+ projectId: $order->project_id,
|
|
|
+ agentId: $order->agent_id ?? null,
|
|
|
+ useBalance: $order->payment_type === PaymentMethod::BALANCE->value ? true : false,
|
|
|
+ distance: $distance ?? 0
|
|
|
+ );
|
|
|
+
|
|
|
+ $order->fill([
|
|
|
+ 'total_amount' => $amounts['total_amount'],
|
|
|
+ 'balance_amount' => $amounts['balance_amount'],
|
|
|
+ 'pay_amount' => $amounts['pay_amount'],
|
|
|
+ 'discount_amount' => $amounts['coupon_amount'],
|
|
|
+ 'project_amount' => $amounts['project_amount'],
|
|
|
+ 'traffic_amount' => $amounts['delivery_fee'],
|
|
|
+ ]);
|
|
|
$order->save();
|
|
|
}
|
|
|
|