From 89f6717abd5ba64c4babd5adabacbb740bedddc3 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 1 Feb 2024 11:49:17 +0800 Subject: [PATCH] 1 --- app/api/controller/Server.php | 47 ++++++++++++++++++- app/api/model/Server/ServerOrder.php | 67 ++++++++++++++++++++++++++++ app/common/service/server/Order.php | 4 ++ 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/app/api/controller/Server.php b/app/api/controller/Server.php index 0de06efc..69ed3ccc 100644 --- a/app/api/controller/Server.php +++ b/app/api/controller/Server.php @@ -112,7 +112,7 @@ class Server extends Controller $end_time = strtotime($end_time) + 86400; $where[] = ['create_time', '<', $end_time]; } - $model = new ServerOrder($where); + $model = new ServerOrder(); $list = $model->orderList($where); $data['list'] = $list->items(); $data['total'] = $list->total(); @@ -134,6 +134,51 @@ class Server extends Controller return $this->renderSuccess($data); } + /** + * @notes:订单详情 + * @return Json + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function orderDetails(): Json + { + $orderId = intval($this->request->post('order_id')); + if (!$orderId) { + return $this->renderError('非法请求'); + } + $model = new ServerOrder(); + $info = $model->info(['order_id' => $orderId]); + if (!empty($info)) { + $info['is_cancel'] = ServerServiceOrder::checkCancel($info); + $info['is_dispatch'] = ServerServiceOrder::checkDispatch($info); + $info['is_pay'] = ServerServiceOrder::checkPay($info); + $info['is_success'] = ServerServiceOrder::checkSuccess($info); + } + return $this->renderSuccess(['info' => $info]); + } + + /** + * @notes:确认完成 + * @return Json + * @throws BaseException + * @author: wanghousheng + */ + public function confirmSuccess(): Json + { + $orderId = intval($this->request->post('order_id')); + if (!$orderId) { + return $this->renderError('非法请求'); + } + $model = new ServerOrder(); + if ($model->confirmSuccess(['order_id' => $orderId])) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError('操作失败'); + } + /** * @notes:确认订单 * @return Json diff --git a/app/api/model/Server/ServerOrder.php b/app/api/model/Server/ServerOrder.php index 3a555e22..f7dd4c69 100644 --- a/app/api/model/Server/ServerOrder.php +++ b/app/api/model/Server/ServerOrder.php @@ -11,6 +11,7 @@ use cores\exception\BaseException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\Model; use think\Paginator; class ServerOrder extends Order @@ -68,6 +69,72 @@ class ServerOrder extends Order } + /** + * @notes: + * @param $where + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function confirmSuccess($where): bool + { + // 当前用户ID + $userId = UserService::getCurrentLoginUserId(); + if (!UserService::isDealerEngineer() || !UserService::isStore()) { + return false; + } + if (UserService::isDealerEngineer()) { + $where = array_merge($where, ['dealer_id' => $userId]); + } + //分销商工程师 + $order_id = $this->where($where) + ->where(['order_status' => ServerEnum::APPLYSERVER]) + ->where('is_delete', '=', 0) + ->value('order_id'); + if (!empty($order_id)) { + $this->where(['id' => $order_id])->save(['order_status' => ServerEnum::COMPLETED]); + return true; + } + return false; + } + + /** + * @notes:订单详情 + * @param $where + * @return ServerOrder|array|mixed|Model|null + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function info($where) + { + // 当前用户ID + $userId = UserService::getCurrentLoginUserId(); + //判断当前用户身份 + if (UserService::isDealerEngineer()) { + //分销商工程师 + return $this->with(['image', 'user']) + ->where($where) + ->where('dealer_id', '=', $userId) + ->where('is_delete', '=', 0) + ->find(); + } elseif (UserService::isStore()) { + // 店主 + return $this->with(['image', 'user', 'dealer']) + ->where($where) + ->where('is_delete', '=', 0) + ->find(); + } else { + return $this->with(['image', 'dealer']) + ->where($where) + ->where('user_id', '=', $userId) + ->where('is_delete', '=', 0) + ->find(); + } + } + /** * 获取用户订单详情(仅订单记录) * @param int $orderId diff --git a/app/common/service/server/Order.php b/app/common/service/server/Order.php index 552d1e0b..e4a1985e 100644 --- a/app/common/service/server/Order.php +++ b/app/common/service/server/Order.php @@ -120,10 +120,14 @@ class Order extends BaseService * @notes:是否可以完成 * @param $order * @return bool + * @throws BaseException * @author: wanghousheng */ public static function checkSuccess($order): bool { + if (!UserService::isDealerEngineer() || !UserService::isStore()) { + return false; + } if (!empty($order) && $order['order_status'] == ServerEnum::APPLYSERVER) { return true; }