userId == '123456789') { throw new ApiException( '网络繁忙' ); } } /** * @OA\Get(path="/api/Order/index", * tags={"订单管理"}, * summary="订单列表", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")), * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")), * @OA\Parameter(name="orderStatus", in="query", description="订单状态 1未支付 2已支付 ", @OA\Schema(type="integer")), * @OA\Parameter(name="writeOffStatus", in="query", description="核销状态 1未核销 2已核销 ", @OA\Schema(type="integer")), * @OA\Parameter(name="discussStatus", in="query", description="评价状态 1未评价 2已评价 ", @OA\Schema(type="integer")), * @OA\Parameter(name="orderSn", in="query", description="订单号", @OA\Schema(type="string")), * @OA\Parameter(name="mobile", in="query", description="手机号", @OA\Schema(type="string")), * @OA\Parameter(name="storeId", in="query", description="门店id", @OA\Schema(type="integer")), * @OA\Parameter(name="appointmentTime", in="query", description="预约时间", @OA\Schema(type="2020-01-02,2021-12-30")), * @OA\Parameter(name="createTcreateTimeime", in="query", description="订单时间", @OA\Schema(type="2020-01-02,2021-12-30")), * @OA\Parameter(name="orderType", in="query", description="订单类型 1小程序下单 2后台增加 3点餐", @OA\Schema(type="string")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function index() { $input = Until::getInput(); $model = new OrderModel(); $model->setPage($input['page'] ?? 1); $model->setPageSize($input['pageSize'] ?? 10); $where = []; $model::where([['status', '=', 1], ['order_type', '<>', 2], ['create_time', '<', date('Y-m-d H:i:s', strtotime('-15minutes'))]]) ->update(['status' => OrderModel::IS_CLOSE]); if (!empty($input['orderSn'])) { $where[] = ['o.order_sn', 'like', "%{$input['orderSn']}%"]; } if (!empty($input['mobile'])) { $where[] = ['o.mobile', 'like', "%{$input['mobile']}%"]; } if (!empty($input['writeOffStatus'])) { if (empty($input['foodOrder'])) { $where[] = ['wo.write_off_status', '=', (int)$input['writeOffStatus']]; } else if ($input['foodOrder'] == 2) { $model->setOp('write_off_status', 'left'); } } if (!empty($input['orderStatus'])) { $where[] = ['o.status', '=', (int)$input['orderStatus']]; } if (!empty($input['discussStatus'])) { $where[] = ['discussOrder.id', '=', null]; } if (!empty($input['storeId'])) { $where[] = ['store.id', '=', $input['storeId']]; } if (!empty($input['appointmentTime'])) { $data = explode(',', $input['appointmentTime']); $where[] = ['o.appointment_time', 'between', [$data[0], $data[1] . ' 23:59:59']]; } if (!empty($input['createTime'])) { $data = explode(',', $input['createTime']); $where[] = ['o.create_time', 'between', [$data[0], $data[1] . ' 23:59:59']]; } if (!empty($input['orderType'])) { $type = explode(',', $input['orderType']); $where[] = ['o.order_type', 'in', $type]; } if (!$this->isAdmin()) { $where[] = ['o.user_id', '=', $this->userId]; // if (empty($input['orderStatus'])) { // $where[] = ['o.status', '<>', OrderModel::IS_DELETE]; // } } $model->setWhere($where); $data = $model->getOrderList(); $orderIds = array_column($data['list'], 'id'); $productList = (new OrderProductModel())::where([['order_id', 'in', $orderIds]])->select(); $productList = Until::modelToArray($productList); $product = []; foreach ($productList as &$v) { unset($v['product_snap']); $product[$v['order_id']][] = $v; } $statusFilter = [1 => '未支付', 2 => '已支付', 3 => '已关闭', 4 => '已删除', 5 => '已完成']; foreach ($data['list'] as $k => &$one) { if ($one['status'] == OrderModel::IS_PAY) { if ($one['allocateStatus'] == 1 && ($one['write_off_status'] == 2 || $one['order_type'] == 2) && !empty($one['roomId'])) { $one['allocateOrderStatus'] = 2; // 可开始服务 } elseif ($one['allocateStatus'] == 2) { $one['allocateOrderStatus'] = 3; //服务中 可结束服务 } else { $one['allocateOrderStatus'] = 999; //未核销 或者未分配房间 } } else { $one['allocateOrderStatus'] = 1; //未支付 } if ($one['allocateStatus'] == 3) { $one['allocateOrderStatus'] = 4; //服务结束 } // var_dump($one['allocateOrderStatus']); $one['productList'] = $product[$one['id']] ?? []; $one['statusText'] = $statusFilter[$one['status']]; if ($one['status'] === OrderModel::IS_PAY) { if ($one['write_off_status'] == 2) { // $one['statusText'] = '待消费'; } else { $one['statusText'] = '已支付'; if ($one['allocateStatus'] == 3 && empty($one['discuss_id']) && !empty($input['discussStatus'])) { $one['statusText'] = '未评价'; } } } } Until::output($data); } public function save() { $input = Until::getInput(); $rule = [ 'name|品牌名称' => 'require', 'groupId|集团id' => 'require', ]; Until::check($rule, $input); $model = new BrandModel(); if (!empty($input['id'])) { $id = (int)$input['id']; $model::where(['id' => $id])->update([ 'brand_name' => $input['name'], 'group_id' => $input['groupId'] ]); } else { $id = $model->insertGetId([ 'brand_name' => $input['name'], 'group_id' => $input['groupId'] ]); } $info = $model::get($id); Until::output(['info' => Until::modelToArray($info)]); } /** * @OA\GET(path="/api/Order/read", * tags={"订单管理"}, * summary="查看订单信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="query", description="订单id", @OA\Schema(type="ineger",default="1")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function read($id) { $model = new OrderModel(); $where[] = ['o.id', '=', (int)$id]; $model->setWhere($where); $info = $model->getOrderInfo(); $productList = (new OrderProductModel())::where([['order_id', '=', $info['id']]])->select(); $productList = Until::modelToArray($productList); foreach ($productList as &$v) { unset($v['product_snap']); } $info['productList'] = $productList; Until::output(['info' => $info]); } /** * @OA\GET(path="/api/Order/delete", * tags={"订单管理"}, * summary="删除品牌信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="query", description="品牌id", @OA\Schema(type="ineger",default="1")), * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function delete($id, $status) { $model = new BrandModel(); $where[] = ['id', '=', (int)$id]; $data = ['status' => (int)$status]; $isSuccess = $model::where($where)->update($data); Until::output(['isSuccess' => $isSuccess]); } /** * @OA\Post(path="/api/Order/createOrder", * tags={"订单管理"}, * summary="创建订单信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="商品id", property="productId", type="integer", default="1"), * @OA\Property(description="门店id", property="storeId", type="integer", default="1"), * @OA\Property(description="职员id", property="staffId", type="integer", default="1"), * @OA\Property(description="预约时间", property="appointmentTime", type="string", default="2020-12-12 16:30"), * @OA\Property(description="预约结束时间", property="endTime", type="string", default="2020-12-12 16:30"), * @OA\Property(description="商品数量", property="num", type="integer", default="1"), * @OA\Property(description="手机号", property="mobile", type="string", default="15623655623"), * @OA\Property(description="姓名", property="name", type="string", default="夏铭"), * @OA\Property(description="支付方式", property="payType", type="string", default="1微信 2支付宝 3银行卡 4现金 "), * required={"productId","storeId","appointmentTime","num","mobile"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function createOrder() { $input = Until::getInput(); $rule = [ 'productId|商品id' => 'require', 'storeId|门店id' => 'require', 'appointmentTime|预约时间' => 'require', 'num|数量' => 'require', 'mobile|手机号' => 'require', 'staffId|技师' => 'require' ]; Until::check($rule, $input); if (empty($input['endTime'])) { $input['endTime'] = date('Y-m-d H:i', strtotime($input['appointmentTime']) + 1800); } if (strtotime($input['appointmentTime']) >= strtotime($input['endTime'])) { throw new ApiException('结束时间必须大于开始时间'); } $input['productId'] = (int)$input['productId']; if ($input['num'] < 1) { throw new ApiException('数量必须大于1'); } if ($this->isAdmin() && !empty($input['name'])) { $model = new UserModel(); $rs = $model::where(['mobile' => $input['mobile']])->find(); if (empty($rs)) { $id = $model->insertGetId([ 'name' => '', 'real_name' => $input['name'], 'avatar' => '', 'mobile' => $input['mobile'], 'join_type' => 2, ]); $input['userId'] = $id; } else { $model::where(['id' => $rs['id']])->update(['real_name' => $input['name']]); $input['userId'] = $rs['id']; } } $data = (new OrderService())->payOrder($input); Until::output($data); } /** * @OA\Post(path="/api/Order/createFoodOrder", * tags={"订单管理"}, * summary="创建订单信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="购物车id", property="cartId", type="integer", default="1"), * @OA\Property(description="台桌id", property="tableId", type="integer", default="1"), * required={"cartId","tableId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function createFoodOrder() { $input = Until::getInput(); $rule = [ 'cartId|商品id和数量' => 'require', 'tableId|桌台id' => 'require', ]; Until::check($rule, $input); $data = (new OrderService())->payFoodOrder($input); Until::output($data); } /** * @OA\Post(path="/api/Order/assignStaff", * tags={"订单管理"}, * summary="分配职员", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * @OA\Property(description="职员id", property="staffId", type="integer", default="1"), * @OA\Property(description="是否轮班", property="isTurn", type="integer", default="1"), * required={"orderId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function assignStaff() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', // 'staffId|职员id' => 'require', ]; Until::check($rule, $input); $model = new OrderModel(); $orderInfo = $model::where(['id' => (int)$input['orderId']])->find(); $allocateModel = new AllocateModel(); $rs = $allocateModel::where(['order_id' => (int)$input['orderId']])->find(); if (empty($rs)) { $allocateModel->insertGetId([ 'order_id' => (int)$input['orderId'], 'staff_id' => $input['staffId'], 'assign_admin_id' => $this->adminId ]); } else { if ($rs['status'] == 2) { throw new ApiException('服务已开始,无法分配职员'); } elseif ($rs['status'] == 3) { throw new ApiException('服务已结束,无法分配职员'); } if (empty($input['staffId'])) { $where[] = ['s.status', '=', 1]; $where[] = ['sto.id', '=', $orderInfo['store_id']]; $turnInfo = (new StaffModel())->getTurnInfo(); $input['staffId'] = $turnInfo['staffId']; } $allocateModel::where(['id' => $rs['id']])->update(['staff_id' => $input['staffId'], 'assign_admin_id' => $this->adminId]); } $model::where(['id' => (int)$input['orderId']])->update(['staff_id' => (int)$input['staffId']]); (new StaffModel())::where(['id' => $input['staffId']])->update(['server_status' => 2]); Until::output(); } /** * @OA\Post(path="/api/Order/serverStart", * tags={"订单管理"}, * summary="服务开始", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * required={"orderId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function serverStart() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', ]; Until::check($rule, $input); $ser = new ServerService(); $ser->startService($input['orderId']); Until::output(); } /** * @OA\Post(path="/api/Order/clockStart", * tags={"订单管理"}, * summary="上钟", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="上钟器卡号(房间卡号)", property="clockCode", type="string", default="1"), * @OA\Property(description="工牌卡号", property="braceletCode", type="string", default="1"), * required={"clockCode","braceletCode"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function clockStart() { $input = Until::getInput(); $rule = [ 'clockCode|上钟器卡号' => 'require', 'braceletCode|手环卡号' => 'require', ]; Until::check($rule, $input); $staffInfo = ServerService::getStaffByCode($input['braceletCode']); $roomInfo = ServerService::getRoomByCode($input['clockCode']); $allocateModel = new AllocateModel(); $info = $allocateModel::where(['staff_id' => $staffInfo['id'], 'store_id' => $roomInfo['store_id']])->order('id', 'desc')->find(); if (empty($info) || empty($info['order_id'])) { throw new ApiException('无此服务'); } $ser = new ServerService(); $ser->startService($info['order_id']); Until::output(); } /** * @OA\Post(path="/api/Order/serverComplete", * tags={"订单管理"}, * summary="服务完成", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * required={"orderId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function serverComplete() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', ]; Until::check($rule, $input); $model = new OrderModel(); $allocateModel = new AllocateModel(); $rs = $allocateModel::where(['order_id' => (int)$input['orderId']])->find(); if (empty($rs)) { throw new ApiException('该服务还没分配职员'); } else { if ($rs['status'] == 3) { throw new ApiException('该服务已完成'); } } if (!empty($this->adminId)) { $opId = $this->adminId; $opType = 'admin'; } else { $opId = $this->userId; $opType = 'xcx'; } $allocateModel::where(['id' => $rs['id']])->update(['status' => 3, 'server_end_time' => date('Y-m-d H:i:s'), 'end_id' => $opId, 'op_type' => $opType]); $model::where(['id' => $input['orderId']])->update(['status' => 5]); $orderRoomRs = (new OrderRoomModel())::where(['order_id' => $input['orderId']])->find(); (new RoomModel())::where(['id' => $orderRoomRs['room_id']])->update(['room_server_status' => 3]); (new StaffModel())::where(['id' => $rs['staff_id']])->update(['server_status' => 1]); Until::output(); } /** * @OA\Post(path="/api/Order/payOrder", * tags={"订单管理"}, * summary="手动支付", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * @OA\Property(description="支付方式", property="payType", type="string", default="1微信 2支付宝 3银行卡 4现金 "), * @OA\Property(description="备注", property="remark", type="integer", default="1"), * required={"orderId","payType"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function payOrder() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', 'payType|支付方式' => 'require', ]; Until::check($rule, $input); $model = new OrderModel(); $orderInfo = $model::where(['id' => (int)$input['orderId']])->find(); if ($orderInfo === null) { throw new ApiException('无此订单'); } if ($orderInfo['status'] === OrderModel::IS_PAY) { throw new ApiException('该订单已支付'); } if ($orderInfo['order_type'] !== 2) { throw new ApiException('该订单已不是pad端下单'); } $model::where(['id' => (int)$input['orderId']])->update([ 'status' => OrderModel::IS_PAY, 'pay_type' => $input['payType'], 'remark' => $input['remark'], 'pay_time' => date('Y-m-d H:i:s') ]); Db::table('pay_record')->insertGetId(['order_id' => $input['orderId'], 'admin_id' => $this->adminId]); $code = random_int(10000, 99999); $wModel = new WriteOffModel(); $wModel::where(['order_id' => $input['orderId']])->update([ 'write_off_code' => $code, ]); Until::output([]); } public function notifyOrder() { $input = Until::getInput(); $rule = [ 'OrderNumber|订单号' => 'require', ]; Until::check($rule, $input); if (md5('ef17f532-4661-b07c-5346-65dfa304c0d8' . $input['OrderNumber']) === $this->request->header('serchkey')) { (new OrderService())->notify($input['OrderNumber']); Until::output([]); } (new OrderService())->notify($input['OrderNumber']); Until::output(['decode' => md5('ef17f532-4661-b07c-5346-65dfa304c0d8' . $input['OrderNumber']), 'encode' => $this->request->header('serchkey')]); } public function changeCode() { $input = Until::getInput(); $rule = [ 'orderId|订单号' => 'require', ]; Until::check($rule, $input); $ser = new OrderService(); $code = $ser->changeCode(); $wModel = new WriteOffModel(); $wModel::where(['order_id' => $input['orderId'], 'write_off_status' => 1])->update([ 'write_off_code' => $code, 'over_time' => date('Y-m-d H:i:s', time() + 2 * 60), ]); Until::output(['code' => $code]); } /** * @OA\Post(path="/api/Order/writeOffOrder", * tags={"订单管理"}, * summary="核销订单", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * @OA\Property(description="核销code", property="code", type="string", default="1"), * required={"orderId","code"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function writeOffOrder() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', 'code|核销码' => 'require' ]; Until::check($rule, $input); $rs = (new OrderModel())::where(['id' => $input['orderId']])->find(); if ($rs['status'] != OrderModel::IS_PAY) { throw new ApiException('该订单未付款,不可核销'); } $model = new WriteOffModel(); $where = ['order_id' => $input['orderId'], 'write_off_code' => $input['code']]; $writeOff = $model::where($where)->find(); if ($writeOff === null) { throw new ApiException('核销码错误'); } if ($writeOff['write_off_status'] == 2) { throw new ApiException('该订单已经核销了'); } $userModel = new UserModel(); $userModel::where([['id', '=', $rs['user_id']], ['first_store_id', '=', 0]])->update(['first_store_id' => $rs['store_id']]); $model::where($where) ->update([ 'write_off_status' => 2, 'write_off_time' => date('Y-m-d H:i:s'), 'admin_id' => $this->adminId ]); Until::output(); } /** * @OA\Post(path="/api/Order/closeOrder", * tags={"订单管理"}, * summary="订单关闭", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="orderId", in="query", description="订单id", @OA\Schema(type="ineger",default="1")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function closeOrder() { $input = Until::getInput(); $model = new OrderModel(); $model::where([ 'user_id' => $this->userId, 'id' => (int)$input['orderId'] ])->update(['status' => OrderModel::IS_CLOSE]); Until::output([]); } /** * @OA\Post(path="/api/Order/deleteOrder", * tags={"订单管理"}, * summary="订单删除", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="orderId", in="query", description="订单id", @OA\Schema(type="ineger",default="1")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function deleteOrder() { $input = Until::getInput(); $model = new OrderModel(); $model::where([ 'user_id' => $this->userId, 'id' => (int)$input['orderId'] ])->update(['status' => OrderModel::IS_DELETE]); Until::output([]); } public function payOrderAgain() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', ]; Until::check($rule, $input); $data = (new OrderService())->payAgain((int)$input['orderId']); Until::output($data); } /** * @OA\Post(path="/api/Order/updateCart", * tags={"订单管理"}, * summary="加入购物车", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="商品id", property="productId", type="integer", default="1"), * @OA\Property(description="商品数量", property="num", type="integer", default="1"), * @OA\Property(description="购物车id", property="cartId", type="integer", default="1"), * @OA\Property(description="类型1增加 2减少", property="type", type="integer", default="1"), * required={"productId","num","cartId","type"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function updateCart() { $input = Until::getInput(); $rule = [ 'productId|订单id' => 'require', 'num|数量' => 'require', 'cartId|购物车id' => 'require', ]; Until::check($rule, $input); $cartModel = new CartModel(); $cartInfo = $cartModel::where([ 'id' => $input['cartId'] ])->find(); if (empty($cartInfo)) { throw new ApiException('不存在的购物车id'); } $cartProductModel = new CartProductModel(); $rs = $cartProductModel::where(['product_id' => $input['productId'], 'cart_id' => $input['cartId']])->find(); if (empty($rs)) { $cartProductModel->insertGetId([ 'product_id' => $input['productId'], 'cart_id' => $input['cartId'], 'num' => $input['num'] ?? 1 ]); } else { if ($input['type'] == 1) { $cartProductModel::where(['id' => $rs['id']])->inc('num', 1)->update(); } if ($input['type'] == 2) { if ($rs['num'] == 1) { $cartProductModel::where(['id' => $rs['id']])->delete(); } $cartProductModel::where(['id' => $rs['id']])->dec('num', 1)->update(); } } $cartInfo = Until::modelToArray($cartInfo); $cartModel->setFields('c.*,cp.product_id,cp.num,p.product_name,p.current_price,p.product_img'); $rs = $cartModel->getCartList(); $cartInfo['totalNum'] = 0; $cartInfo['totalPrice'] = 0; foreach ($rs as $v) { $cartInfo['totalNum'] += $v['num']; $cartInfo['totalPrice'] += $v['num'] * $v['current_price']; } $cartInfo['id'] = $v['id']; $cartInfo['table_id'] = $v['table_id']; $cartInfo['store_id'] = $v['store_id']; $cartInfo['user_id'] = $v['user_id']; $cartInfo['create_time'] = $v['create_time']; $cartInfo['list'] = $cartInfo['totalNum'] == 0 ? [] : $rs; Until::output($cartInfo); } /** * @OA\Post(path="/api/Order/getCart", * tags={"订单管理"}, * summary="获取购物车", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="门店id", property="storeId", type="integer", default="1"), * @OA\Property(description="桌台id", property="tableId", type="integer", default="1"), * required={"storeId","tableId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function getCart() { $input = Until::getInput(); $rule = [ 'storeId|门店id' => 'require', 'tableId|桌台id' => 'require' ]; Until::check($rule, $input); $model = new CartModel(); try { $model->startTrans(); $whereData = [ 'table_id' => (int)$input['tableId'], 'store_id' => (int)$input['storeId'], 'user_id' => $this->userId, 'status' => CartModel::NORMAL ]; $cartInfo = $model::where($whereData)->find(); $cartInfo = Until::modelToArray($cartInfo); if (empty($cartInfo)) { $id = $model->insertGetId($whereData); } $model->setWhere([ 'c.status' => CartModel::NORMAL, 'c.user_id' => $this->userId, 'c.table_id' => (int)$input['tableId'], 'c.store_id' => (int)$input['storeId'] ]); $model->setFields('c.*,cp.product_id,cp.num,p.product_name,p.current_price,p.product_img'); $rs = $model->getCartList(); $model->commit(); } catch (\Exception $e) { $model->rollback(); throw new ApiException($e->getMessage()); } $cartInfo['totalPrice'] = 0; $cartInfo['totalNum'] = 0; foreach ($rs as $v) { $cartInfo['totalNum'] += $v['num']; $cartInfo['totalPrice'] += $v['num'] * $v['current_price']; } $cartInfo['id'] = $v['id']; $cartInfo['table_id'] = $v['table_id']; $cartInfo['store_id'] = $v['store_id']; $cartInfo['user_id'] = $v['user_id']; $cartInfo['create_time'] = $v['create_time']; $cartInfo['totalPrice'] = number_format($cartInfo['totalPrice'], 2); $cartInfo['list'] = $cartInfo['totalNum'] == 0 ? [] : $rs; Until::output($cartInfo); } /** * @OA\Post(path="/api/Order/clearCart", * tags={"订单管理"}, * summary="清空购物车", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="购物车id", property="cartId", type="integer", default="1"), * required={"cartId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function clearCart() { $input = Until::getInput(); $rule = [ 'cartId|购物车id' => 'require', ]; Until::check($rule, $input); $model = new CartModel(); $model::where(['id' => $input['cartId']])->update(['status' => 0]); Until::output(); } /** * @OA\Post(path="/api/Order/editOrder", * tags={"订单管理"}, * summary="修改订单信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="订单id", property="orderId", type="integer", default="1"), * @OA\Property(description="订单金额", property="orderMoney", type="string", default="13.26"), * @OA\Property(description="技师", property="staffId", type="string", default="13.26"), * @OA\Property(description="旧服务项目id", property="oldProductId", type="string", default="13.26"), * @OA\Property(description="新服务项目id", property="newProductId", type="string", default="13.26"), * required={"orderId"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function editOrder() { $input = Until::getInput(); $rule = [ 'orderId|订单id' => 'require', ]; Until::check($rule, $input); if (empty($input['orderMoney']) || empty($input['staffId']) || empty($input['oldProductId']) || empty($input['newProductId'])) { throw new ApiException('修改信息不能为空'); } $log = new OrderChangeModel(); $orderModel = new OrderModel(); if (!empty($input['orderMoney'])) { try { $log->startTrans(); $rs = $orderModel::where(['id' => $input['orderId']])->find(); $log->insertGetId([ 'order_id' => $input['orderId'], 'change' => 'orderMoney', 'remark' => "订单金额由{$rs['order_money']}修改为{$input['orderMoney']}", 'admin_id' => Until::$adminId, 'order_snap' => json_encode($rs) ]); $orderModel::where(['id' => $input['orderId']])->update(['order_money' => $input['orderMoney']]); $log->commit(); }catch (\Exception $e) { $log->rollback(); throw new ApiException($e->getMessage()); } } if (!empty($input['staffId'])) { try { $log->startTrans(); $rs = $orderModel::where(['id' => $input['orderId']])->find(); $log->insertGetId([ 'order_id' => $input['orderId'], 'change' => 'orderMoney', 'remark' => "订单由职员:{$rs['staffId']}修改为职员:{$input['staffId']}", 'admin_id' => Until::$adminId, 'order_snap' => json_encode($rs) ]); $orderModel::where(['id' => $input['orderId']])->update(['staff_id' => $input['staffId']]); (new AllocateModel())::where(['order_id' => $input['orderId']])->update(['staff_id' => $input['staffId']]); $log->commit(); }catch (\Exception $e) { $log->rollback(); throw new ApiException($e->getMessage()); } } $data = (new OrderService())->payFoodOrder($input); Until::output($data); } }