Browse Source

feat:订单管理->创建订单

刘学玺 4 months ago
parent
commit
abdfaca8f2

+ 61 - 0
app/Admin/Controllers/AgentProjectConfigController.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Services\AgentProjectConfigService;
+use Slowlyo\OwlAdmin\Controllers\AdminController;
+
+/**
+ * 代理商项目设置
+ *
+ * @property AgentProjectConfigService $service
+ */
+class AgentProjectConfigController extends AdminController
+{
+	protected string $serviceName = AgentProjectConfigService::class;
+
+	public function list()
+	{
+		$crud = $this->baseCRUD()
+			->filterTogglable(false)
+			->headerToolbar([
+				$this->createButton('dialog'),
+				...$this->baseHeaderToolBar()
+			])
+			->columns([
+				amis()->TableColumn('id', 'ID')->sortable(),
+				amis()->TableColumn('agent_id', '代理商编号'),
+				amis()->TableColumn('base_price', '服务的起步价'),
+				amis()->TableColumn('per_kilometer_fee', '每公里的费用'),
+				amis()->TableColumn('state', '状态'),
+				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
+				amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
+				$this->rowActions('dialog')
+			]);
+
+		return $this->baseList($crud);
+	}
+
+	public function form($isEdit = false)
+	{
+		return $this->baseForm()->body([
+			amis()->TextControl('agent_id', '代理商编号'),
+			amis()->TextControl('base_price', '服务的起步价'),
+			amis()->TextControl('per_kilometer_fee', '每公里的费用'),
+			amis()->TextControl('state', '状态'),
+		]);
+	}
+
+	public function detail()
+	{
+		return $this->baseDetail()->body([
+			amis()->TextControl('id', 'ID')->static(),
+			amis()->TextControl('agent_id', '代理商编号')->static(),
+			amis()->TextControl('base_price', '服务的起步价')->static(),
+			amis()->TextControl('per_kilometer_fee', '每公里的费用')->static(),
+			amis()->TextControl('state', '状态')->static(),
+			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
+			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
+		]);
+	}
+}

+ 192 - 348
app/Http/Controllers/Client/OrderController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Client;
 use App\Http\Controllers\Controller;
 use App\Services\Client\OrderService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
 
 class OrderController extends Controller
 {
@@ -16,53 +17,129 @@ class OrderController extends Controller
     }
 
     /**
-     * 订单初始化
+     * [订单管理] 订单初始化
+     *
+     * @description 初始化订单
+     *
+     * @bodyParam coach_id int required 技师ID Example: 1
+     * @bodyParam area_code string required 区划代码 Example: 370602
+     * @bodyParam project_id int required 项目ID Example: 1
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @return \Illuminate\Http\JsonResponse
      */
     public function initialize(Request $request)
     {
-        $userId = Auth::id();
-        $coachId = $request->input('coach_id');
-        $areaCode = $request->input('area_code');
-        $projectId = $request->input('project_id');
-        
-        return $this->service->initialize($userId, $coachId, $areaCode, $projectId);
+        $data = $request->only(['coach_id', 'area_code', 'project_id']);
+
+        return $this->service->initialize(Auth::user()->id, $data);
     }
 
     /**
-     * 结束订单
+     * [订单管理] 创建订单
+     *
+     * @description 创建订单
+     *
+     * @bodyParam project_id int required 项目ID Example: 1
+     * @bodyParam address_id int required 地址ID Example: 1
+     * @bodyParam coach_id int required 技师ID Example: 1
+     * @bodyParam use_balance int 使用余额 Example: 0
+     * @bodyParam service_time datetime required 服务时间 Example: 2024-01-01 10:00:00
+     * @bodyParam order_id int 订单ID Example:
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     */
+    public function create(Request $request)
+    {
+        $data = $request->only(['project_id', 'address_id', 'coach_id', 'use_balance', 'order_id', 'service_time']);
+
+        return $this->service->createOrder(Auth::user()->id, $data);
+    }
+
+    /**
+     * [订单管理] 结束订单
+     *
+     * @description 结束订单
+     *
+     * @bodyParam order_id int required 订单ID Example: 123
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @return \Illuminate\Http\JsonResponse
      */
     public function finish(Request $request)
     {
-        $userId = Auth::id();
+        $userId = Auth::user()->id;
         $orderId = $request->input('order_id');
-        
+
         return $this->service->finishOrder($userId, $orderId);
     }
 
     /**
-     * 确认技师离开
+     * [订单管理] 确认技师离开
+     *
+     * @description 确认技师离开
+     *
+     * @bodyParam order_id int required 订单ID Example: 123
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @return \Illuminate\Http\JsonResponse
      */
-    public function confirmLeave(Request $request) 
+    public function confirmLeave(Request $request)
     {
-        $userId = Auth::id();
+        $userId = Auth::user()->id;
         $orderId = $request->input('order_id');
-        
+
         return $this->service->confirmLeave($userId, $orderId);
     }
 
     /**
-     * 取消订单
+     * [订单管理] 取消订单
+     *
+     * @description 取消订单
+     *
+     * @bodyParam order_id int required 订单ID Example: 123
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @return \Illuminate\Http\JsonResponse
      */
     public function cancel(Request $request)
     {
-        $userId = Auth::id();
+        $userId = Auth::user()->id;
         $orderId = $request->input('order_id');
-        
+
         return $this->service->cancelOrder($userId, $orderId);
     }
 
     /**
-     * 获取订单列表
+     * [订单管理] 获取订单列表
+     *
+     * @description 获取订单列表
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": []
+     * }
+     *
+     * @return \Illuminate\Http\JsonResponse
      */
     public function list()
     {
@@ -70,7 +147,19 @@ class OrderController extends Controller
     }
 
     /**
-     * 获取订单详情
+     * [订单管理] 获取订单详情
+     *
+     * @description 获取订单详情
+     *
+     * @urlParam id required 订单ID Example: 123
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\JsonResponse
      */
     public function detail($id)
     {
@@ -78,7 +167,17 @@ class OrderController extends Controller
     }
 
     /**
-     * 订单退款
+     * [订单管理] 订单退款
+     *
+     * @description 订单退款
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\JsonResponse
      */
     public function refund($id)
     {
@@ -86,25 +185,54 @@ class OrderController extends Controller
     }
 
     /**
-     * 获取代理商配置
+     * [订单管理] 获取代理商配置
+     *
+     * @description 获取代理商配置
+     *
+     * @response {
+     *   "min_distance": 0,
+     *   "min_fee": 0,
+     *   "per_km_fee": 0
+     * }
+     *
+     * @return array
      */
     public function getAgentConfig(Request $request)
     {
         $agentId = $request->input('agent_id');
+
         return $this->service->getAgentConfig($agentId);
     }
 
     /**
-     * 获取技师配置
+     * [订单管理] 获取技师配置
+     *
+     * @description 获取技师配置
+     *
+     * @response {
+     *   "delivery_fee_type": "round_trip",
+     *   "charge_delivery_fee": true
+     * }
+     *
+     * @return array
      */
     public function getCoachConfig(Request $request)
     {
         $coachId = $request->input('coach_id');
+
         return $this->service->getCoachConfig($coachId);
     }
 
     /**
-     * 计算路费金额
+     * [订单管理] 计算路费金额
+     *
+     * @description 计算路费金额
+     *
+     * @response {
+     *   "fee": 0
+     * }
+     *
+     * @return float
      */
     public function calculateDeliveryFee(Request $request)
     {
@@ -117,12 +245,26 @@ class OrderController extends Controller
         if ($agentId) {
             return $this->service->calculateDeliveryFee($coachId, $agentId, $distance);
         } else {
-            return $this->service->calculateDeliveryFeeByLocation($coachId, $latitude, $longitude, $distance);
+            // return $this->service->calculateDeliveryFeeByLocation($coachId, $latitude, $longitude, $distance);
         }
     }
 
     /**
-     * 计算订单金额
+     * [订单管理] 计算订单金额
+     *
+     * @description 计算订单金额
+     *
+     * @response {
+     *   "total_amount": 0,
+     *   "balance_amount": 0,
+     *   "pay_amount": 0,
+     *   "coupon_amount": 0,
+     *   "tip_amount": 0,
+     *   "project_amount": 0,
+     *   "delivery_fee": 0
+     * }
+     *
+     * @return array
      */
     public function calculateOrderAmount(Request $request)
     {
@@ -137,341 +279,43 @@ class OrderController extends Controller
     }
 
     /**
-     * 创建订单
-     */
-    public function create(Request $request)
-    {
-        $userId = Auth::id();
-        $projectId = $request->input('project_id');
-        $addressId = $request->input('address_id');
-        $coachId = $request->input('coach_id');
-        $useBalance = $request->input('use_balance', 0);
-        $orderId = $request->input('order_id');
-
-        return $this->service->createOrder($userId, $projectId, $addressId, $coachId, $useBalance, $orderId);
-    }
-
-    /**
-     * 加钟
+     * [订单管理] 加钟
+     *
+     * @description 加钟
+     *
+     * @urlParam order_id required 订单ID Example: 123
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
      */
     public function addTime(Request $request, $orderId)
     {
         $userId = Auth::id();
+
         return $this->service->addTime($userId, $orderId);
     }
 
     /**
-     * 指定技师
+     * [订单管理] 指定技师
+     *
+     * @description 指定技师
+     *
+     * @urlParam order_id required 订单ID Example: 123
+     *
+     * @bodyParam coach_id int required 技师ID Example: 1
+     *
+     * @response {
+     *   "status": "success",
+     *   "data": {}
+     * }
      */
     public function assignCoach(Request $request, $orderId)
     {
         $userId = Auth::id();
         $coachId = $request->input('coach_id');
-        return $this->service->assignCoach($userId, $orderId, $coachId);
-    }
-
-    /**
-     * 获取代理商配置
-     */
-    public function getAgentConfig($agentId)
-    {
-        $agent = AgentInfo::where('id', $agentId)
-            ->where('state', 'enable')
-            ->firstOrFail();
-
-        $config = AgentConfig::where('agent_id', $agentId)->firstOrFail();
-
-        return [
-            'min_distance' => $config->min_distance,
-            'min_fee' => $config->min_fee,
-            'per_km_fee' => $config->per_km_fee
-        ];
-    }
-
-    /**
-     * 获取技师配置
-     */
-    public function getCoachConfig($coachId)
-    {
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->firstOrFail();
-
-        $config = CoachConfig::where('coach_id', $coachId)->firstOrFail();
-
-        return [
-            'delivery_fee_type' => $config->delivery_fee_type,
-            'charge_delivery_fee' => $config->charge_delivery_fee
-        ];
-    }
-
-    /**
-     * 计算路费金额
-     */
-    public function calculateDeliveryFee($coachId, $agentId, $distance)
-    {
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->firstOrFail();
-
-        $coachConfig = CoachConfig::where('coach_id', $coachId)->firstOrFail();
-
-        if (!$coachConfig->charge_delivery_fee) {
-            return 0;
-        }
-
-        $agentConfig = AgentConfig::where('agent_id', $agentId)->firstOrFail();
 
-        $fee = 0;
-        if ($distance <= $agentConfig->min_distance) {
-            $fee = $agentConfig->min_fee;
-        } else {
-            $extraDistance = $distance - $agentConfig->min_distance;
-            $fee = $agentConfig->min_fee + ($extraDistance * $agentConfig->per_km_fee);
-        }
-
-        return $coachConfig->delivery_fee_type == 'round_trip' ? $fee * 2 : $fee;
-    }
-
-    /**
-     * 计算订单金额
-     */
-    public function calculateOrderAmount($userId, $addressId, $coachId, $projectId, $agentId, $useBalance)
-    {
-        // 参数校验
-        $user = User::where('id', $userId)
-            ->where('status', 1)
-            ->firstOrFail();
-
-        $address = UserAddress::where('id', $addressId)
-            ->where('user_id', $userId)
-            ->firstOrFail();
-
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->firstOrFail();
-
-        $project = Project::where('id', $projectId)
-            ->where('state', 'enable')
-            ->firstOrFail();
-
-        // 计算金额
-        $projectAmount = $project->price;
-        $deliveryFee = $this->calculateDeliveryFee($coachId, $agentId, $address->distance);
-        $tipAmount = request()->has('order_id') ? Order::find(request()->input('order_id'))->tip_amount : 0;
-        
-        $couponAmount = 0;
-        if (request()->has('coupon_id')) {
-            $coupon = Coupon::where('id', request()->input('coupon_id'))
-                ->where('state', 'enable')
-                ->firstOrFail();
-            $couponAmount = $coupon->amount;
-        }
-
-        $totalAmount = $projectAmount + $deliveryFee + $tipAmount - $couponAmount;
-
-        $balanceAmount = 0;
-        $payAmount = $totalAmount;
-
-        if ($useBalance) {
-            $wallet = UserWallet::where('user_id', $userId)->first();
-            if ($wallet && $wallet->balance >= $totalAmount) {
-                $balanceAmount = $totalAmount;
-                $payAmount = 0;
-            } else if ($wallet) {
-                $balanceAmount = $wallet->balance;
-                $payAmount = $totalAmount - $balanceAmount;
-            }
-        }
-
-        return [
-            'total_amount' => $totalAmount,
-            'balance_amount' => $balanceAmount,
-            'pay_amount' => $payAmount,
-            'coupon_amount' => $couponAmount,
-            'tip_amount' => $tipAmount,
-            'project_amount' => $projectAmount,
-            'delivery_fee' => $deliveryFee
-        ];
-    }
-
-    /**
-     * 创建订单
-     */
-    public function createOrder($userId, $projectId, $addressId, $coachId, $useBalance, $orderId = null)
-    {
-        return DB::transaction(function() use ($userId, $projectId, $addressId, $coachId, $useBalance, $orderId) {
-            // 参数校验
-            $user = User::where('id', $userId)
-                ->where('status', 1)
-                ->firstOrFail();
-
-            $address = UserAddress::where('id', $addressId)
-                ->where('user_id', $userId)
-                ->firstOrFail();
-
-            if (!$orderId) {
-                $coach = CoachUser::where('id', $coachId)
-                    ->where('state', 'enable')
-                    ->where('auth_state', 'passed')
-                    ->firstOrFail();
-            }
-
-            $project = Project::where('id', $projectId)
-                ->where('state', 'enable')
-                ->firstOrFail();
-
-            // 创建订单
-            $orderType = $orderId ? 'add_time' : 'normal';
-            $amounts = $this->calculateOrderAmount($userId, $addressId, $coachId, $projectId, $project->agent_id, $useBalance);
-
-            $order = new Order();
-            $order->user_id = $userId;
-            $order->project_id = $projectId;
-            $order->address_id = $addressId;
-            $order->coach_id = $coachId;
-            $order->order_type = $orderType == 'normal' ? 0 : 1;
-            $order->status = 0;
-            $order->total_amount = $amounts['total_amount'];
-            $order->balance_amount = $amounts['balance_amount'];
-            $order->pay_amount = $amounts['pay_amount'];
-            $order->coupon_amount = $amounts['coupon_amount'];
-            $order->tip_amount = $amounts['tip_amount'];
-            $order->project_amount = $amounts['project_amount'];
-            $order->delivery_fee = $orderType == 'add_time' ? 0 : $amounts['delivery_fee'];
-            $order->payment_type = $useBalance && $amounts['pay_amount'] == 0 ? 0 : 1;
-            $order->save();
-
-            // 创建订单历史
-            if ($orderType == 'add_time') {
-                OrderHistory::create([
-                    'order_id' => $order->id,
-                    'type' => 'add_time',
-                    'user_id' => $userId
-                ]);
-            } else {
-                OrderHistory::create([
-                    'order_id' => $order->id,
-                    'type' => 'create',
-                    'user_id' => $userId
-                ]);
-            }
-
-            // 余额支付处理
-            if ($order->payment_type == 0) {
-                $order->status = 1;
-                $order->save();
-
-                OrderHistory::create([
-                    'order_id' => $order->id,
-                    'type' => 'pay',
-                    'user_id' => $userId
-                ]);
-
-                CoachSchedule::create([
-                    'coach_id' => $coachId,
-                    'date' => date('Y-m-d'),
-                    'status' => 'busy'
-                ]);
-
-                return $order->id;
-            }
-
-            // 微信支付处理
-            // TODO: 调用支付接口
-
-            return $order->id;
-        });
-    }
-
-    /**
-     * 加钟
-     */
-    public function addTime($userId, $orderId)
-    {
-        $order = Order::where('id', $orderId)
-            ->where('user_id', $userId)
-            ->firstOrFail();
-
-        return $this->createOrder($userId, $order->project_id, $order->address_id, $order->coach_id, 0, $orderId);
-    }
-
-    /**
-     * 指定技师
-     */
-    public function assignCoach($userId, $orderId, $coachId)
-    {
-        return DB::transaction(function() use ($userId, $orderId, $coachId) {
-            // 参数校验
-            $user = User::where('id', $userId)
-                ->where('status', 1)
-                ->firstOrFail();
-
-            $order = Order::where('id', $orderId)
-                ->where('user_id', $userId)
-                ->whereIn('status', [0, 1, 6])
-                ->firstOrFail();
-
-            $coach = CoachUser::where('id', $coachId)
-                ->where('state', 'enable')
-                ->where('auth_state', 'passed')
-                ->firstOrFail();
-
-            $schedule = CoachSchedule::where('coach_id', $coachId)
-                ->where('date', date('Y-m-d'))
-                ->where('status', 'free')
-                ->firstOrFail();
-
-            // 修改订单
-            $order->coach_id = $coachId;
-            if ($order->status == 0) {
-                $amounts = $this->calculateOrderAmount($userId, $order->address_id, $coachId, $order->project_id, $order->agent_id, $order->payment_type == 0);
-                
-                $order->total_amount = $amounts['total_amount'];
-                $order->balance_amount = $amounts['balance_amount'];
-                $order->pay_amount = $amounts['pay_amount'];
-                $order->coupon_amount = $amounts['coupon_amount'];
-                $order->tip_amount = $amounts['tip_amount'];
-                $order->project_amount = $amounts['project_amount'];
-                $order->delivery_fee = $amounts['delivery_fee'];
-
-                if ($order->payment_type == 0) {
-                    $order->status = 1;
-                }
-            }
-            if ($order->status == 1) {
-                $order->status = 2;
-            }
-            $order->save();
-
-            // 创建订单历史
-            OrderHistory::create([
-                'order_id' => $order->id,
-                'type' => 'assign_coach',
-                'user_id' => $userId,
-                'coach_id' => $coachId
-            ]);
-
-            OrderHistory::create([
-                'order_id' => $order->id,
-                'type' => 'accept',
-                'user_id' => $userId,
-                'coach_id' => $coachId,
-                'remark' => '抢单成功'
-            ]);
-
-            // 更新抢单池
-            GrabOrder::where('order_id', $orderId)
-                ->update(['status' => 2, 'coach_id' => $coachId]);
-
-            // 更新排班
-            $schedule->status = 'busy';
-            $schedule->save();
-
-            return true;
-        });
+        return $this->service->assignCoach($userId, $orderId, $coachId);
     }
-} 
+}

+ 16 - 0
app/Models/AgentProjectConfig.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Slowlyo\OwlAdmin\Models\BaseModel as Model;
+
+/**
+ * 代理商项目设置
+ */
+class AgentProjectConfig extends Model
+{
+	use SoftDeletes;
+
+	protected $table = 'agent_project_config';
+}

+ 8 - 0
app/Models/MemberUser.php

@@ -11,6 +11,14 @@ class MemberUser extends Model
 {
     use HasApiTokens, SoftDeletes;
 
+    /**
+     * 获取用户的默认地址
+     */
+    public function address()
+    {
+        return $this->hasOne(MemberAddress::class, 'user_id', 'id')->where('is_default', 1);
+    }
+
     /**
      * 获取用户的所有地址
      */

+ 6 - 3
app/Models/OrderRecord.php

@@ -10,16 +10,19 @@ use Slowlyo\OwlAdmin\Models\BaseModel as Model;
  */
 class OrderRecord extends Model
 {
-	use SoftDeletes;
+    use SoftDeletes;
 
-	protected $table = 'order_records';
+    protected $table = 'order_records';
+
+    protected $guarded = [];
 
     /**
      * @Author FelixYin
+     *
      * @description 记录所属订单
      */
     public function order()
     {
         return $this->belongsTo('App\Models\OrderInfo', 'order_id');
     }
-}
+}

+ 17 - 0
app/Services/AgentProjectConfigService.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Services;
+
+use App\Models\AgentProjectConfig;
+use Slowlyo\OwlAdmin\Services\AdminService;
+
+/**
+ * 代理商项目设置
+ *
+ * @method AgentProjectConfig getModel()
+ * @method AgentProjectConfig|\Illuminate\Database\Query\Builder query()
+ */
+class AgentProjectConfigService extends AdminService
+{
+	protected string $modelName = AgentProjectConfig::class;
+}

+ 320 - 189
app/Services/Client/OrderService.php

@@ -2,33 +2,32 @@
 
 namespace App\Services\Client;
 
-use App\Models\Order;
-use App\Models\OrderRecord;
-use App\Models\WalletRefundRecord;
-
-use App\Models\User;
-use App\Models\MemberAddress;
-use App\Models\CoachUser;
-use App\Models\Project;
-use App\Models\AgentInfo;
 use App\Models\AgentConfig;
+use App\Models\AgentInfo;
 use App\Models\CoachConfig;
-use App\Models\Wallet;
-use App\Models\Coupon;
 use App\Models\CoachSchedule;
+use App\Models\CoachUser;
+use App\Models\Coupon;
 use App\Models\MemberUser;
-use App\Models\OrderHistory;
+use App\Models\Order;
 use App\Models\OrderGrabRecord;
-
+use App\Models\OrderRecord;
+use App\Models\Project;
+use App\Models\SysConfig;
+use App\Models\User;
+use App\Models\Wallet;
+use App\Models\WalletRefundRecord;
+use Exception;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
-use Exception;
+use Illuminate\Support\Facades\Log;
 
 class OrderService
 {
     protected AgentService $agentService;
+
     protected ProjectService $projectService;
-    
+
     public function __construct(
         AgentService $agentService,
         ProjectService $projectService
@@ -37,28 +36,46 @@ class OrderService
         $this->projectService = $projectService;
     }
 
-     /**
+    /**
      * 订单初始化
      */
-    public function initialize($userId, $coachId, $areaCode, $projectId)
+    public function initialize($userId, $data)
     {
+        $user = MemberUser::find($userId);
+
+        if (! $user) {
+            throw new Exception('用户不存在');
+        }
+
+        if ($user->state != 'enable') {
+            throw new Exception('用户状态异常');
+        }
+
         // 查询用户钱包
-        $wallet = Wallet::where('user_id', $userId)->first();
+        $wallet = $user->wallet;
 
         // 查询默认地址
-        $address = MemberAddress::where('user_id', $userId)
-            ->where('is_default', 1)
-            ->first();
+        $address = $user->address;
 
-        if ($address) {
-            $areaCode = $address->area_code;
-        }
+        $areaCode = $address ? $address->area_code : $data['area_code'];
 
         // 查询技师数据
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->first();
+        $coach = CoachUser::where('state', 'enable')
+            ->whereHas('info', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('real', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('qual', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->with(['info:id,nickname,avatar,gender'])
+            ->find($data['coach_id']);
+
+        if (! $coach) {
+            throw new Exception('技师不存在');
+        }
 
         // 查询技师排班
         // $schedule = CoachSchedule::where('coach_id', $coachId)
@@ -71,14 +88,11 @@ class OrderService
         //     ->where('expire_time', '>', now())
         //     ->get();
 
-        // 获取代理商
-        $agent = $this->agentService->getAgent($areaCode);
-
         // 获取项目详情
-        $project = $this->projectService->getProjectDetail($projectId, $agent->id);
+        $project = $this->projectService->getProjectDetail($data['project_id'], $areaCode);
 
         // 计算订单金额
-        $amounts = $this->calculateOrderAmount($userId, $address->id, $coachId, $projectId, $agent->id);
+        $amounts = $this->calculateOrderAmount($userId, $address?->id, $data['coach_id'], $data['project_id'], $project?->agent_id);
 
         return [
             'wallet' => $wallet,
@@ -91,17 +105,135 @@ class OrderService
         ];
     }
 
+    /**
+     * 创建订单
+     */
+    public function createOrder($userId, array $data)
+    {
+        try {
+            return DB::transaction(function () use ($userId, $data) {
+                // 1. 参数校验
+                $user = MemberUser::where('id', $userId)
+                    ->where('state', 'enable')
+                    ->firstOrFail();
+
+                $address = $user->addresses()
+                    ->where('id', $data['address_id'])
+                    ->firstOrFail();
+
+                // 查询技师及其认证状态
+                $coach = CoachUser::where('id', $data['coach_id'])
+                    ->where('state', 'enable')
+                    ->whereHas('info', function ($query) {
+                        $query->where('state', 'approved');
+                    })
+                    ->whereHas('qual', function ($query) {
+                        $query->where('state', 'approved');
+                    })
+                    ->whereHas('real', function ($query) {
+                        $query->where('state', 'approved');
+                    })
+                    ->firstOrFail();
+
+                $project = Project::where('id', $data['project_id'])
+                    ->where('state', 'enable')
+                    ->firstOrFail();
+
+                // 2. 创建订单
+                $orderType = isset($data['order_id']) ? 'add_time' : 'normal';
+
+                // 计算订单金额
+                $amounts = $this->calculateOrderAmount(
+                    $userId,
+                    $data['address_id'],
+                    $data['coach_id'],
+                    $data['project_id'],
+                    $project->agent_id,
+                    $data['use_balance'] ?? false
+                );
+
+                $order = new Order;
+                $order->user_id = $userId;
+                $order->project_id = $data['project_id'];
+                $order->coach_id = $data['coach_id'];
+                $order->type = $orderType;
+                $order->state = 'wait_pay';
+                $order->source = 'platform';
+                $order->total_amount = $amounts['total_amount'];
+                $order->balance_amount = $amounts['balance_amount'];
+                $order->pay_amount = $amounts['pay_amount'];
+                $order->project_amount = $amounts['project_amount'];
+                $order->traffic_amount = $orderType == 'add_time' ? 0 : $amounts['delivery_fee'];
+                $order->payment_type = ($data['use_balance'] && $amounts['pay_amount'] == 0) ? 'balance' : null;
+                $order->service_time = $data['service_time'];
+
+                // 从用户地址获取位置信息
+                $order->longitude = $address->longitude; // 经度
+                $order->latitude = $address->latitude;   // 纬度
+                $order->location = $address->location;   // 定位地址
+                $order->address = $address->address;     // 详细地址
+                $order->area_code = $address->area_code; // 行政区划代码
+
+                $order->save();
+
+                // 3. 创建订单记录
+                OrderRecord::create([
+                    'order_id' => $order->id,
+                    'object_id' => $userId,
+                    'object_type' => MemberUser::class,
+                    'state' => $orderType == 'add_time' ? 'add_time' : 'create',
+                    'remark' => $orderType == 'add_time' ? '加钟订单' : '创建订单',
+                ]);
+
+                // 4. 余额支付处理
+                if ($order->payment_type == 'balance') {
+                    $order->state = 'wait_receive';
+                    $order->save();
+
+                    OrderRecord::create([
+                        'order_id' => $order->id,
+                        'object_id' => $userId,
+                        'object_type' => MemberUser::class,
+                        'state' => 'pay',
+                        'remark' => '余额支付',
+                    ]);
+
+                    // 创建技师排班
+                    // CoachSchedule::create([
+                    //     'coach_id' => $data['coach_id'],
+                    //     'date' => date('Y-m-d'),
+                    //     'state' => 'busy',
+                    // ]);
+
+                    // TODO: 发送抢单通知
+                }
+
+                return [
+                    'order_id' => $order->id,
+                    'payment_type' => $order->payment_type,
+                ];
+            });
+        } catch (Exception $e) {
+            Log::error('创建订单失败:', [
+                'message' => $e->getMessage(),
+                'user_id' => $userId,
+                'data' => $data,
+            ]);
+            throw $e;
+        }
+    }
+
     /**
      * 结束订单
      */
     public function finishOrder($userId, $orderId)
     {
-        return DB::transaction(function() use ($userId, $orderId) {
+        return DB::transaction(function () use ($userId, $orderId) {
             $order = Order::where('user_id', $userId)
                 ->where('id', $orderId)
                 ->first();
 
-            if (!$order) {
+            if (! $order) {
                 throw new Exception('订单不存在');
             }
 
@@ -110,11 +242,11 @@ class OrderService
                 'order_id' => $orderId,
                 'user_id' => $userId,
                 'state' => 'finish',
-                'remark' => '服务完成'
+                'remark' => '服务完成',
             ]);
 
             // 修改订单状态
-            $order->status = 'finished';
+            $order->state = 'finished';
             $order->save();
 
             return ['message' => '订单已完成'];
@@ -126,12 +258,12 @@ class OrderService
      */
     public function confirmLeave($userId, $orderId)
     {
-        return DB::transaction(function() use ($userId, $orderId) {
+        return DB::transaction(function () use ($userId, $orderId) {
             $order = Order::where('user_id', $userId)
                 ->where('id', $orderId)
                 ->first();
 
-            if (!$order) {
+            if (! $order) {
                 throw new Exception('订单不存在');
             }
 
@@ -140,11 +272,11 @@ class OrderService
                 'order_id' => $orderId,
                 'user_id' => $userId,
                 'state' => 'leave',
-                'remark' => '技师已离开'
+                'remark' => '技师已离开',
             ]);
 
             // 修改订单状态
-            $order->status = 'allow_leave';
+            $order->state = 'allow_leave';
             $order->save();
 
             return ['message' => '已确认技师离开'];
@@ -156,12 +288,12 @@ class OrderService
      */
     public function cancelOrder($userId, $orderId)
     {
-        return DB::transaction(function() use ($userId, $orderId) {
+        return DB::transaction(function () use ($userId, $orderId) {
             $order = Order::where('user_id', $userId)
                 ->where('id', $orderId)
                 ->first();
 
-            if (!$order) {
+            if (! $order) {
                 throw new Exception('订单不存在');
             }
 
@@ -170,11 +302,11 @@ class OrderService
                 'order_id' => $orderId,
                 'user_id' => $userId,
                 'state' => 'cancel',
-                'remark' => '用户取消订单'
+                'remark' => '用户取消订单',
             ]);
 
             // 修改订单状态
-            $order->status = 'cancelled';
+            $order->state = 'cancelled';
             $order->save();
 
             return ['message' => '订单已取消'];
@@ -187,13 +319,13 @@ class OrderService
     public function getOrderList()
     {
         $userId = Auth::id();
-        
+
         return Order::where('user_id', $userId)
             ->with([
                 'project:id,title,cover,price',
                 'coach:id,name,avatar',
                 'agent:id,company_name',
-                'address:id,address'
+                'address:id,address',
             ])
             ->orderBy('created_at', 'desc')
             ->paginate(10);
@@ -213,9 +345,9 @@ class OrderService
                 'coach:id,name,avatar,mobile',
                 'agent:id,company_name',
                 'address:id,address,latitude,longitude',
-                'records' => function($query) {
+                'records' => function ($query) {
                     $query->orderBy('created_at', 'asc');
-                }
+                },
             ])
             ->firstOrFail();
     }
@@ -227,7 +359,7 @@ class OrderService
     {
         $userId = Auth::id();
 
-        return DB::transaction(function() use ($orderId, $userId) {
+        return DB::transaction(function () use ($orderId, $userId) {
             // 查询并锁定订单
             $order = Order::where('id', $orderId)
                 ->where('user_id', $userId)
@@ -245,7 +377,7 @@ class OrderService
                 'object_id' => $userId,
                 'object_type' => 'user',
                 'state' => 'refund',
-                'remark' => '订单退款'
+                'remark' => '订单退款',
             ]);
 
             // 创建退款记录
@@ -253,14 +385,14 @@ class OrderService
                 'order_id' => $orderId,
                 'user_id' => $userId,
                 'amount' => $order->total_amount,
-                'state' => 'success'
+                'state' => 'success',
             ]);
 
             return ['message' => '退款成功'];
         });
     }
 
-     /**
+    /**
      * 获取代理商配置
      */
     public function getAgentConfig($agentId)
@@ -299,30 +431,68 @@ class OrderService
     /**
      * 计算路费金额
      */
-    public function calculateDeliveryFee($coachId, $agentId, $distance)
+    public function calculateDeliveryFee($coachId, $projectId, $agentId, $distance)
     {
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->firstOrFail();
 
-        $coachConfig = CoachConfig::where('coach_id', $coachId)->firstOrFail();
+        // 查询技师数据
+        $coach = CoachUser::where('state', 'enable')
+            ->whereHas('info', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('real', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('qual', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->find($coachId);
+
+        if (! $coach) {
+            throw new Exception('技师不存在');
+        }
 
-        if (!$coachConfig->charge_delivery_fee) {
+        // 查询技师项目
+        $coachProject = $coach->projects()
+            ->where('state', 'enable')
+            ->where('project_id', $projectId)
+            ->first();
+        if (! $coachProject) {
+            throw new Exception('项目不存在');
+        }
+
+        // 技师免收路费
+        if ($coachProject->traffic_fee_type == 'free') {
             return 0;
         }
 
-        $agentConfig = AgentConfig::where('agent_id', $agentId)->firstOrFail();
+        // 查询代理商
+        $agent = AgentInfo::where('state', 'enable')->find($agentId);
+        if ($agent) {
+            $agentProject = $agent->projects()
+                ->where('state', 'enable')
+                ->where('project_id', $projectId)
+                ->first();
+
+            if (! $agentProject) {
+                throw new Exception('代理商项目不存在');
+            }
+            $config = $agent->projectConfig;
+
+        } else {
+            // 系统配置
+            $config = SysConfig::where('key', 'delivery_fee')->firstOrFail();
+            dd('暂停处理');
+        }
 
         $fee = 0;
-        if ($distance <= $agentConfig->min_distance) {
-            $fee = $agentConfig->min_fee;
+        if ($distance <= $config->min_distance) {
+            $fee = $config->min_fee;
         } else {
-            $extraDistance = $distance - $agentConfig->min_distance;
-            $fee = $agentConfig->min_fee + ($extraDistance * $agentConfig->per_km_fee);
+            $extraDistance = $distance - $config->min_distance;
+            $fee = $config->min_fee + ($extraDistance * $config->per_km_fee);
         }
 
-        return $coachConfig->delivery_fee_type == 'round_trip' ? $fee * 2 : $fee;
+        return $coachProject->delivery_fee_type == 'round_trip' ? $fee * 2 : $fee;
     }
 
     /**
@@ -331,28 +501,78 @@ class OrderService
     public function calculateOrderAmount($userId, $addressId, $coachId, $projectId, $agentId, $useBalance = false)
     {
         // 参数校验
-        $user = MemberUser::where('id', $userId)
-            ->where('status', 1)
-            ->firstOrFail();
+        $user = MemberUser::find($userId);
+        if (! $user) {
+            throw new Exception('用户不存在');
+        }
 
-        $address = MemberAddress::where('id', $addressId)
-            ->where('user_id', $userId)
-            ->firstOrFail();
+        if ($user->state != 'enable') {
+            throw new Exception('用户状态异常');
+        }
 
-        $coach = CoachUser::where('id', $coachId)
-            ->where('state', 'enable')
-            ->where('auth_state', 'passed')
-            ->firstOrFail();
+        // 查询地址
+        $address = $user->address()->find($addressId);
+
+        // 查询技师数据
+        $coach = CoachUser::where('state', 'enable')
+            ->whereHas('info', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('real', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->whereHas('qual', function ($query) {
+                $query->where('state', 'approved');
+            })
+            ->with(['info:id,nickname,avatar,gender'])
+            ->find($coachId);
+
+        if (! $coach) {
+            throw new Exception('技师不存在');
+        }
 
-        $project = Project::where('id', $projectId)
+        // 查询技师项目
+        $coachProject = $coach->projects()
             ->where('state', 'enable')
-            ->firstOrFail();
+            ->where('project_id', $projectId)
+            ->first();
+        if (! $coachProject) {
+            throw new Exception('项目不存在');
+        }
+
+        // 查询项目
+        $project = $coachProject->basicInfo;
+
+        if (! $project) {
+            throw new Exception('项目不存在');
+        }
+
+        if ($project->state != 'enable') {
+            throw new Exception('项目状态异常');
+        }
+
+        // 查询代理商
+        $agent = AgentInfo::where('state', 'enable')->find($agentId);
+        if ($agent) {
+            $agentProject = $agent->projects()
+                ->where('state', 'enable')
+                ->where('project_id', $projectId)
+                ->first();
+
+            if (! $agentProject) {
+                throw new Exception('代理商项目不存在');
+            }
+
+            $project->price = $agentProject->price;
+            $project->duration = $agentProject->duration;
+            $project->distance = $address->distance;
+        }
 
         // 计算金额
         $projectAmount = $project->price;
-        $deliveryFee = $this->calculateDeliveryFee($coachId, $agentId, $address->distance);
-        $tipAmount = request()->has('order_id') ? Order::find(request()->input('order_id'))->tip_amount : 0;
-        
+        $deliveryFee = $this->calculateDeliveryFee($coachId, $projectId, $agentId, $address?->distance);
+        // $tipAmount = request()->has('order_id') ? Order::find(request()->input('order_id'))->tip_amount : 0;
+
         $couponAmount = 0;
         if (request()->has('coupon_id')) {
             // $coupon = Coupon::where('id', request()->input('coupon_id'))
@@ -361,7 +581,7 @@ class OrderService
             // $couponAmount = $coupon->amount;
         }
 
-        $totalAmount = $projectAmount + $deliveryFee + $tipAmount - $couponAmount;
+        $totalAmount = $projectAmount + $deliveryFee - $couponAmount;
 
         $balanceAmount = 0;
         $payAmount = $totalAmount;
@@ -371,7 +591,7 @@ class OrderService
             if ($wallet && $wallet->balance >= $totalAmount) {
                 $balanceAmount = $totalAmount;
                 $payAmount = 0;
-            } else if ($wallet) {
+            } elseif ($wallet) {
                 $balanceAmount = $wallet->balance;
                 $payAmount = $totalAmount - $balanceAmount;
             }
@@ -382,101 +602,12 @@ class OrderService
             'balance_amount' => $balanceAmount,
             'pay_amount' => $payAmount,
             'coupon_amount' => $couponAmount,
-            'tip_amount' => $tipAmount,
+            // 'tip_amount' => $tipAmount,
             'project_amount' => $projectAmount,
-            'delivery_fee' => $deliveryFee
+            'delivery_fee' => $deliveryFee,
         ];
     }
 
-    /**
-     * 创建订单
-     */
-    public function createOrder($userId, $projectId, $addressId, $coachId, $useBalance, $orderId = null)
-    {
-        return DB::transaction(function() use ($userId, $projectId, $addressId, $coachId, $useBalance, $orderId) {
-            // 参数校验
-            $user = MemberUser::where('id', $userId)
-                ->where('status', 1)
-                ->firstOrFail();
-
-            $address = MemberAddress::where('id', $addressId)
-                ->where('user_id', $userId)
-                ->firstOrFail();
-
-            if (!$orderId) {
-                $coach = CoachUser::where('id', $coachId)
-                    ->where('state', 'enable')
-                    ->where('auth_state', 'passed')
-                    ->firstOrFail();
-            }
-
-            $project = Project::where('id', $projectId)
-                ->where('state', 'enable')
-                ->firstOrFail();
-
-            // 创建订单
-            $orderType = $orderId ? 'add_time' : 'normal';
-            $amounts = $this->calculateOrderAmount($userId, $addressId, $coachId, $projectId, $project->agent_id, $useBalance);
-
-            $order = new Order();
-            $order->user_id = $userId;
-            $order->project_id = $projectId;
-            $order->address_id = $addressId;
-            $order->coach_id = $coachId;
-            $order->order_type = $orderType == 'normal' ? 0 : 1;
-            $order->status = 0;
-            $order->total_amount = $amounts['total_amount'];
-            $order->balance_amount = $amounts['balance_amount'];
-            $order->pay_amount = $amounts['pay_amount'];
-            $order->coupon_amount = $amounts['coupon_amount'];
-            $order->tip_amount = $amounts['tip_amount'];
-            $order->project_amount = $amounts['project_amount'];
-            $order->delivery_fee = $orderType == 'add_time' ? 0 : $amounts['delivery_fee'];
-            $order->payment_type = $useBalance && $amounts['pay_amount'] == 0 ? 0 : 1;
-            $order->save();
-
-            // 创建订单历史
-            if ($orderType == 'add_time') {
-                OrderRecord::create([
-                    'order_id' => $order->id,
-                    'type' => 'add_time',
-                    'user_id' => $userId
-                ]);
-            } else {
-                OrderRecord::create([
-                    'order_id' => $order->id,
-                    'type' => 'create',
-                    'user_id' => $userId
-                ]);
-            }
-
-            // 余额支付处理
-            if ($order->payment_type == 'balance') {
-                $order->status = 'paid';
-                $order->save();
-
-                OrderRecord::create([
-                    'order_id' => $order->id,
-                    'type' => 'pay',
-                    'user_id' => $userId
-                ]);
-
-                // CoachSchedule::create([
-                //     'coach_id' => $coachId,
-                //     'date' => date('Y-m-d'),
-                //     'status' => 'busy'
-                // ]);
-
-                return $order->id;
-            }
-
-            // 微信支付处理
-            // TODO: 调用支付接口
-
-            return $order->id;
-        });
-    }
-
     /**
      * 加钟
      */
@@ -494,15 +625,15 @@ class OrderService
      */
     public function assignCoach($userId, $orderId, $coachId)
     {
-        return DB::transaction(function() use ($userId, $orderId, $coachId) {
+        return DB::transaction(function () use ($userId, $orderId, $coachId) {
             // 参数校验
             $user = MemberUser::where('id', $userId)
-                ->where('status', 'enable')
+                ->where('state', 'enable')
                 ->firstOrFail();
 
             $order = Order::where('id', $orderId)
                 ->where('user_id', $userId)
-                ->whereIn('status', [0, 1, 6])
+                ->whereIn('state', [0, 1, 6])
                 ->firstOrFail();
 
             $coach = CoachUser::where('id', $coachId)
@@ -512,28 +643,28 @@ class OrderService
 
             // $schedule = CoachSchedule::where('coach_id', $coachId)
             //     ->where('date', date('Y-m-d'))
-            //     ->where('status', 'free')
+            //     ->where('state', 'free')
             //     ->firstOrFail();
 
             // 修改订单
             $order->coach_id = $coachId;
-            if ($order->status == 'created') {
+            if ($order->state == 'created') {
                 $amounts = $this->calculateOrderAmount($userId, $order->address_id, $coachId, $order->project_id, $order->agent_id, $order->payment_type == 'balance');
-                
+
                 $order->total_amount = $amounts['total_amount'];
                 $order->balance_amount = $amounts['balance_amount'];
                 $order->pay_amount = $amounts['pay_amount'];
                 $order->coupon_amount = $amounts['coupon_amount'];
-                $order->tip_amount = $amounts['tip_amount'];
+                // $order->tip_amount = $amounts['tip_amount'];
                 $order->project_amount = $amounts['project_amount'];
                 $order->delivery_fee = $amounts['delivery_fee'];
 
                 if ($order->payment_type == 'balance') {
-                    $order->status = 'paid';
+                    $order->state = 'paid';
                 }
             }
-            if ($order->status == 'paid') {
-                $order->status = 'assigned';
+            if ($order->state == 'paid') {
+                $order->state = 'assigned';
             }
             $order->save();
 
@@ -542,7 +673,7 @@ class OrderService
                 'order_id' => $order->id,
                 'type' => 'assigned',
                 'user_id' => $userId,
-                'coach_id' => $coachId
+                'coach_id' => $coachId,
             ]);
 
             OrderRecord::create([
@@ -550,18 +681,18 @@ class OrderService
                 'type' => 'accepted',
                 'user_id' => $userId,
                 'coach_id' => $coachId,
-                'remark' => '抢单成功'
+                'remark' => '抢单成功',
             ]);
 
             // 更新抢单池
             OrderGrabRecord::where('order_id', $orderId)
-                ->update(['status' => 'success', 'coach_id' => $coachId]);
+                ->update(['state' => 'success', 'coach_id' => $coachId]);
 
             // 更新排班
-            // $schedule->status = 'busy';
+            // $schedule->state = 'busy';
             // $schedule->save();
 
             return true;
         });
     }
-} 
+}

+ 1 - 0
app/Services/Client/ProjectService.php

@@ -49,6 +49,7 @@ class ProjectService
         if ($agent) {
             // 查询代理商项目
             $project = $agent->projects()->where('project_id', $projectId)->first();
+            $project->agent_id = $agent->id;
         }
 
         return $project;

+ 37 - 0
database/migrations/2024_11_21_144232_create_agent_project_config_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('agent_project_config', function (Blueprint $table) {
+            $table->comment('代理商项目设置');
+            $table->increments('id');
+            $table->unsignedBigInteger('agent_id')->nullable()->comment('代理商编号');
+            $table->decimal('base_price')->comment('服务的起步价');
+            $table->decimal('per_kilometer_fee')->comment('每公里的费用');
+            $table->string('state')->default('')->comment('状态');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('agent_project_config');
+    }
+};

+ 1 - 0
database/migrations/2024_xx_xx_add_foreign_key_to_orders_table.php

@@ -0,0 +1 @@
+ 

+ 1 - 0
database/migrations/2024_xx_xx_insert_delivery_fee_config.php

@@ -0,0 +1 @@
+ 

+ 2 - 0
routes/admin.php

@@ -87,5 +87,7 @@ Route::group([
     $router->resource('coach_real_auth_records', \App\Admin\Controllers\CoachRealAuthRecordController::class);
     // 技师开通服务项目
     $router->resource('coach_project', \App\Admin\Controllers\CoachProjectController::class);
+    // 代理商项目设置
+    $router->resource('agent_project_config', \App\Admin\Controllers\AgentProjectConfigController::class);
 
 });

+ 17 - 0
routes/api.php

@@ -3,6 +3,7 @@
 use App\Http\Controllers\Client\AccountController;
 use App\Http\Controllers\Client\CoachController;
 use App\Http\Controllers\Client\CoachLocationController;
+use App\Http\Controllers\Client\OrderController;
 use App\Http\Controllers\Client\ProjectController;
 use App\Http\Controllers\Client\UserAddressController;
 use App\Http\Controllers\Client\UserController;
@@ -76,4 +77,20 @@ Route::middleware('auth:sanctum')->group(function () {
         Route::put('/{id}/default', [UserAddressController::class, 'setDefault']);
     });
 
+    Route::prefix('orders')->group(function () {
+        Route::post('initialize', [OrderController::class, 'initialize']);
+        Route::post('create', [OrderController::class, 'create']);
+        Route::post('finish', [OrderController::class, 'finish']);
+        Route::post('confirm-leave', [OrderController::class, 'confirmLeave']);
+        Route::post('cancel', [OrderController::class, 'cancel']);
+        Route::get('list', [OrderController::class, 'list']);
+        Route::get('detail/{id}', [OrderController::class, 'detail']);
+        Route::post('refund/{id}', [OrderController::class, 'refund']);
+        Route::post('get-agent-config', [OrderController::class, 'getAgentConfig']);
+        Route::post('get-coach-config', [OrderController::class, 'getCoachConfig']);
+        Route::post('calculate-delivery-fee', [OrderController::class, 'calculateDeliveryFee']);
+        Route::post('calculate-order-amount', [OrderController::class, 'calculateOrderAmount']);
+        Route::post('add-time/{orderId}', [OrderController::class, 'addTime']);
+    });
+
 });