0, 'lng' => 0, 'area_id' => 0]; // 优惠卷 // $coupon_record_model = new CouponRecord(); // 渠道 // $channel_model = new UserChannel(); // 用户渠道 // $input['channel_id'] = $channel_model->getChannelId($this->_user['id']); // 订单号 $order_id = !empty($params['order_id']) ? $params['order_id'] : 0; // 使用余额 $use_balance = $params['use_balance'] ?? 0; // 出行方式 $car_type = $params['car_type'] ?? 0; // 技师 $coach_id = $params['coach_id'] ?? 0; $coach_model = new User(); $coach_info = $coach_model->info($coach_id); !empty($coach_info) && $coach_info['is_work'] == 0 && self::error('该技师未上班'); !empty($coach_info) && ($coach_info['auth_status'] !== 2 || $coach_info['status'] !== 1) && self::error('该技师已下架'); // 优惠卷ID $coupon_id = !empty($params['coupon_id']) ? $params['coupon_id'] : 0; // 加钟订单 if ($order_id) { } else { // $address = $address_model->info($params['address_id']); // if(empty($address)){ // $this->errorMsg('请添加地址'); // } } $orderModel = new Order(); $orderPayInfo = $orderModel->buildPayInfo($params['user_id'], $params['project_id'], $address['area_id'], $address['lat'], $address['lng'], $use_balance, $coach_id, $car_type, $coupon_id, $order_id); //默认微信 $payType = $params['pay_type'] ?? 1; $use_balance && !$orderPayInfo['pay_price'] && ($payType = 0); $orderData = [ 'order_sn' => $this->buildOrderSN(), 'user_id' => $params['user_id'], 'pay_type' => $payType, ...$orderPayInfo, //备注 // 'text' => $params['text'] ?: '', // 'car_type' => $car_type, // 'channel_id' => $params['channel_id'] ?: 0, //目的地地址 //加钟 // 'add_pid' => $order_id, // 'is_add' => $order_id ? 1 : 0, ]; // 创建订单 return $orderModel->newQuery()->create($orderData)->id; } public function getOrderPage(array $data) { $user_id = Auth::id(); $status = intval($data['status'] ?? 0); $where = ['user_id' => $user_id, 'user_del' => 0]; $statusRange = match ($status) { 1 => [0, 1, 2, 3], 2 => [4, 5], 3 => [5], 4 => [6, 7], default => [0, 1, 2, 3, 4, 5, 6, 7] }; // $select = ['id', 'project_name', 'project_icon', 'duration', 'paid_type', 'price', 'real_address', 'status', 'created_at', 'refunded_at']; $select = ['id', 'project_name', 'project_icon', 'time_long', 'pay_type', 'pay_price', 'real_address', 'status', 'created_at']; $orderPage = Order::query()->where($where)->whereIn('status', $statusRange)->select($select)->latest()->paginate(); return ['list' => $orderPage->items(), 'total' => $orderPage->total()]; } public function getOrder(int $order_id) { $user_id = Auth::id(); return Order::query()->where('user_id', $user_id)->select($this->baseColumn)->find($order_id); } /** * @throws ApiException */ public function updateOrder(array $data, int $order_id): void { $order = Order::query()->find($order_id); $status = $data['status']; switch ($status) { // 结束订单 case 6: $order->status !== 5 && self::error('订单状态有误'); // 查询是否存在加钟订单 // 判断加钟服务是否完成 $order->user_end = 1; $order->end_time = time(); break; case 9: !in_array($order->status, [0, 1, 2, 3]) && self::error('订单状态有误'); break; } $order->status = $status; $order->save(); } public function delOrder(int $order_id): void { $order = Order::query()->find($order_id); $order->user_del = 1; $order->save(); } }