user = $this->auth->getUser(); $this->service = new OrderService(); } private function check_option_services($option_services) { $option_services = json_decode(str_ireplace(""", "\"", $option_services), true); if (null === $option_services || !is_array($option_services)) $this->error("选择的服务数据传输格式错误!"); if (0 === count($option_services)) $this->error("请选择服务!"); $s_ids = []; $fmt_services = []; foreach ($option_services as $item) { $item_id = (int)$item['service_id']; $s_ids[] = $item_id; $fmt_services[$item_id] = [ "service_id" => $item_id, "quantity" => (int)$item['quantity'] ]; } return ['s_ids' => $s_ids, "fmt_services" => $fmt_services]; } public function fetchOrder($status = null, $page = 1, $size = 10) { $array = $status ? explode(",", $status) : []; foreach ($array as $item) { if (!in_array($item, array_merge(ALL_ORDER_STATUS, ["*"]))) $this->error("状态错误!"); } $r = $this->service->fetchOrder($this->user->id, in_array("*", $array) ? ALL_ORDER_STATUS : $array, $page, $size); $this->success($r); } /** * 获取订单详情 */ public function getOrder() { $params = (new BaseApiValidate(["order_id" => "require|number"]))->checkBody(); $r = $this->service->getOrder($params["order_id"]); if (null === $r) $this->error("订单不存在!"); $this->success($r); } /** * @throws \think\exception\DbException */ public function create() { $params = (new OrderValidate())->checkBody(); $store_id = isset($params['store_id']) && $params['store_id'] > 0 ? $params['store_id'] : null; $massager_id = isset($params['massager_id']) && $params['massager_id'] > 0 ? $params['massager_id'] : null; if ($store_id == null && $massager_id == null) $this->error("下单主体错误!"); $option_services = $this->check_option_services($params['option_services']); $r = $this->service->create($this->user, $option_services['s_ids'], $option_services['fmt_services'], $massager_id, $store_id, $massager_id > 0); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } public function reorder() { $params = (new BaseApiValidate(["order_id" => "require|number"]))->checkBody(); $r = $this->service->reorder($params["order_id"]); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * 变更服务项 * @throws \think\exception\DbException */ public function changeOrderService() { $params = (new BaseApiValidate([ "order_id" => "require|number", "option_services" => "require" ]))->checkBody(); $option_services = $this->check_option_services($params['option_services']); $r = $this->service->changeOrderService($params["order_id"], $option_services['s_ids'], $option_services['fmt_services']); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * 选择用户地址 */ public function bindUserArea() { $params = (new BaseApiValidate([ "order_id" => "require|number", "user_area_id" => "require|number" ]))->checkBody(); $r = $this->service->bindUserArea($this->user->id, $params['order_id'], $params['user_area_id']); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * 选择优惠券 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function bindVoucher() { $params = (new BaseApiValidate([ "order_id" => "require|number", "user_voucher_id" => "require|number" ]))->checkBody(); $r = $this->service->bindVoucher($this->user->id, $params['order_id'], $params['user_voucher_id']); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * @throws \think\exception\DbException */ public function modifyOrder() { $params = (new BaseApiValidate([ "order_id" => "require|number", ]))->checkBody(); $description = isset($params['description']) && strlen($params['description']) > 0 ? $params['description'] : null; $trip_type = null; $service_start_date = null; if (isset($params["trip_type"]) && in_array($params["trip_type"], [\E_TRIP_TYPE::Taxi, \E_TRIP_TYPE::Bus])) $trip_type = $params['trip_type']; if (isset($params["service_start_date"]) && strtotime($params["service_start_date"]) > 0) $service_start_date = $params['service_start_date']; $r = $this->service->modifyOrder( $this->user->id, $params['order_id'], $description, $trip_type, $service_start_date, isset($params["balance_deduction"]) && $params["balance_deduction"] >= 0 ? $params["balance_deduction"] : null ); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } public function updateOrderOpenMembership() { $params = (new BaseApiValidate([ "order_id" => "require|number", "open_membership" => "require|number", ]))->checkBody(); $r = $this->service->updateOrderOpenMembership($this->user->id, $params["order_id"], 1 == $params["open_membership"]); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * @throws \think\exception\DbException */ public function calculateTripAmount() { $params = (new BaseApiValidate([ "order_id" => "require|number", ]))->checkBody(); $r = $this->service->calculateTripAmount($this->user->id, $params['order_id']); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } /** * @throws \think\exception\DbException */ public function payment() { $params = (new BaseApiValidate([ "order_id" => "require|number", "payment_type" => "require", "platform" => "require", ]))->checkBody(); if (!in_array($params['payment_type'], ALL_ORDER_PAY_TYPE)) $this->error("支付方式错误!"); if (!in_array($params['platform'], ["web", "applet"])) $this->error("平台错误!"); $r = $this->service->payment($this->user->id, $params['order_id'], $params['payment_type'], $params["platform"], $params["description"]); $r->code() == 1 ? $this->success($r->data()) : $this->error($r->msg(), null, $r->code()); } /** * @throws \think\exception\DbException */ public function cancel() { $params = (new BaseApiValidate([ "order_id" => "require|number", "reason" => "require" ]))->checkBody(); $r = $this->service->cancel($params["order_id"], $params["reason"]); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } public function comment() { $params = (new BaseApiValidate([ "order_id" => "require|number", "is_anonymity" => "require|between:0,1", "star" => "between:0,5", "content" => "length:1,1000", "negative" => "between:0,1" ]))->checkBody(); if (!isset($params["content"])) { $params["content"] = "服务好素质高"; } $r = $this->service->comment($params["order_id"], $params); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } public function appeal() { $params = (new BaseApiValidate([ "order_id" => "require|number", "appeal_reason" => "require", ]))->checkBody(); $r = $this->service->appeal($this->user->id, $params["order_id"], $params["appeal_reason"]); $r->code() ? $this->success($r->data()) : $this->error($r->msg()); } public function virtualMobile() { $params = (new BaseApiValidate([ "order_id" => "require|number", "type" => "require", ]))->checkBody(); $this->success("15574920253"); } }