From b89c162045919e8b0c1fce6edf5f920fe949b303 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 25 Jan 2024 15:57:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=9B=9E=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/enum/ServerEnum.php | 47 ++++++++++ app/common/enum/dealer/DealerUserEnum.php | 31 +++++++ app/common/model/dealer/User.php | 23 ++++- app/common/model/server/Order.php | 103 ++++++++++++++++++++++ app/common/service/server/Order.php | 91 +++++++++++++++++++ app/store/controller/Server.php | 83 +++++++++++++++++ app/store/controller/dealer/User.php | 29 ++++-- app/store/model/server/Server.php | 10 +-- 8 files changed, 402 insertions(+), 15 deletions(-) create mode 100644 app/common/enum/ServerEnum.php create mode 100644 app/common/enum/dealer/DealerUserEnum.php create mode 100644 app/common/model/server/Order.php create mode 100644 app/common/service/server/Order.php diff --git a/app/common/enum/ServerEnum.php b/app/common/enum/ServerEnum.php new file mode 100644 index 00000000..2ef1f635 --- /dev/null +++ b/app/common/enum/ServerEnum.php @@ -0,0 +1,47 @@ + [ + 'name' => '待付款', + 'value' => self::APPLYPAY, + ], + self::CANCELLED => [ + 'name' => '已取消', + 'value' => self::CANCELLED, + ], + self::APPLYDISPATCH => [ + 'name' => '待派单', + 'value' => self::APPLYDISPATCH, + ], + self::APPLYSERVER => [ + 'name' => '待服务', + 'value' => self::APPLYSERVER, + ], + self::COMPLETED => [ + 'name' => '已完成', + 'value' => self::COMPLETED, + ] + ]; + } +} \ No newline at end of file diff --git a/app/common/enum/dealer/DealerUserEnum.php b/app/common/enum/dealer/DealerUserEnum.php new file mode 100644 index 00000000..4e45cbbc --- /dev/null +++ b/app/common/enum/dealer/DealerUserEnum.php @@ -0,0 +1,31 @@ + [ + 'name' => '工程师', + 'value' => self::ENGINEER, + ], + self::NORMAL => [ + 'name' => '普通', + 'value' => self::NORMAL, + ], + ]; + } +} \ No newline at end of file diff --git a/app/common/model/dealer/User.php b/app/common/model/dealer/User.php index bbd06c79..11886a2f 100644 --- a/app/common/model/dealer/User.php +++ b/app/common/model/dealer/User.php @@ -12,8 +12,13 @@ declare (strict_types=1); namespace app\common\model\dealer; -use cores\BaseModel; +use app\common\enum\dealer\DealerUserEnum; use app\common\library\helper; +use cores\BaseModel; +use think\Collection; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; use think\model\relation\BelongsTo; /** @@ -167,4 +172,20 @@ class User extends BaseModel ]); return true; } + + /** + * @notes:获取工程师分销商 + * @return array|Collection|User[] + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public static function getEngineer() + { + return (new static()) + ->where(['type' => DealerUserEnum::ENGINEER]) + ->order(['create_time']) + ->select(); + } } \ No newline at end of file diff --git a/app/common/model/server/Order.php b/app/common/model/server/Order.php new file mode 100644 index 00000000..6b2f6144 --- /dev/null +++ b/app/common/model/server/Order.php @@ -0,0 +1,103 @@ +belongsTo(Server::class, 'id', 'server_id'); + } + + /** + * 获取器:订单状态文字描述 + * @return string + */ + public function getOrderStatusTextAttr($value, $data): string + { + // 订单状态 + return ServerEnum::data()[$data['order_status']]['name']; + } + + /** + * 图片 + * @return HasOne + */ + public function image(): HasOne + { + return $this->hasOne(UploadFile::class, 'file_id', 'server_image_id') + ->bind(['server_image' => 'preview_url']); + } + + /** + * 关联用户表 + * @return BelongsTo + */ + public function user(): BelongsTo + { + $module = self::getCalledModule(); + return $this->belongsTo("app\\$module\\model\\User") + ->bind(['user_name' => 'nick_name', 'user_mobile' => 'mobile']); + } + + public function dealer(): BelongsTo + { + $module = self::getCalledModule(); + return $this->belongsTo("app\\$module\\model\\User", 'dealer_id', 'user_id') + ->bind(['dealer_name' => 'nick_name', 'dealer_mobile' => 'mobile']); + } + + /** + * @notes:服务订单列表 + * @param array $where + * @param int $listRows + * @return Paginator + * @author: wanghousheng + */ + public function getList(array $where, int $listRows = 15): Paginator + { + $where = $this->setQueryDefaultValue($where); + return $this->with(['image', 'dealer']) + ->alias('a') + ->join('user b', 'b.user_id = a.user_id') + ->where($where) + ->order(['create_time']) + ->field('a.*,b.mobile as user_mobile,b.nick_name as user_nick_name') + ->paginate($listRows); + } + + /** + * @notes:订单详情 + * @param $where + * @param array $with + * @return Order|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } +} \ No newline at end of file diff --git a/app/common/service/server/Order.php b/app/common/service/server/Order.php new file mode 100644 index 00000000..569b9157 --- /dev/null +++ b/app/common/service/server/Order.php @@ -0,0 +1,91 @@ + 0 && UserCouponModel::setIsUse($order['coupon_id'], false); + } + //判断是否已支付 + if ($order['pay_status'] == PayStatus::SUCCESS) { + if (!(new RefundService)->handle($order)) { + try { + throwError('执行订单退款失败'); + } catch (BaseException $e) { + return false; + } + } + } + //更新订单状态 + $model = new \app\common\model\server\Order; + $model->where(['order_id' => $order['order_id']])->save(['order_status' => ServerEnum::CANCELLED]); + return true; + } + return false; + } + + /** + * @notes:派单 + * @param array $order + * @param int $dealerId + * @return bool + * @author: wanghousheng + */ + public static function dispatchOrders(array $order, int $dealerId): bool + { + //判断该订单是否可以指派 + if (!empty($order) && $order['order_status'] == ServerEnum::APPLYDISPATCH) { + //判断指派人员是否是分销工程师 + $dealerInfo = DealerUserModel::detail($dealerId, []); + if (!empty($dealerInfo)) { + $dealerInfo = $dealerInfo->toArray(); + if ($dealerInfo['type'] == DealerUserEnum::ENGINEER) { + $model = new \app\common\model\server\Order; + $up['dealer_id'] = $dealerId; + $up['order_status'] = ServerEnum::APPLYSERVER; + $model->where(['order_id' => $order['order_id']])->save($up); + return true; + } + } + } + return false; + } +} \ No newline at end of file diff --git a/app/store/controller/Server.php b/app/store/controller/Server.php index 757befe9..1d347dcc 100644 --- a/app/store/controller/Server.php +++ b/app/store/controller/Server.php @@ -1,9 +1,11 @@ renderSuccess('操作成功'); } + + /** + * @notes:服务订单列表 + * @return Json + * @author: wanghousheng + */ + public function orderList(): Json + { + $model = new \app\common\model\server\Order; + $server_name = $this->request->post('server_name'); + $order_no = $this->request->post('order_no'); + $order_status = intval($this->request->post('order_status')); + $where = []; + if (!empty($server_name)) { + $where[] = ['a.server_name', 'like', `%$server_name%`]; + } + if (!empty($order_no)) { + $where[] = ['a.order_no', '=', $order_no]; + } + if ($order_status) { + $where[] = ['a.order_status', '=', $order_status]; + } + $user_mobile = $this->request->post('user_mobile'); + if ($user_mobile) { + $where[] = ['b.mobile', '=', $user_mobile]; + } + $user_nickname = $this->request->post('user_nickname'); + if ($user_nickname) { + $where[] = ['b.nick_name', 'like', "%$server_name%"]; + } + $list = $model->getList($where); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:取消服务订单 + * @param int $orderId + * @return Json + * @author: wanghousheng + */ + public function cancelOrder(int $orderId): Json + { + $order = \app\common\model\server\Order::detail($orderId); + if (empty($order)) { + return $this->renderError('订单信息不存在'); + } + try { + $result = \app\common\service\server\Order::cancelOrder($order->toArray()); + if ($result) { + return $this->renderSuccess('操作成功'); + } + } catch (BaseException|DataNotFoundException|ModelNotFoundException|DbException $e) { + return $this->renderError($e->getMessage() ?: '取消失败'); + } + return $this->renderError('取消失败'); + } + + /** + * @notes:派单 + * @return Json + * @author: wanghousheng + */ + public function dispatchOrders(): Json + { + $data = $this->postForm(); + if (empty($data['dealer_id'])) { + return $this->renderError('指派人员不能为空'); + } + if (empty($data['order_id'])) { + return $this->renderError('缺少必要参数'); + } + $order = \app\common\model\server\Order::detail($data['order_id']); + if (empty($order)) { + return $this->renderError('订单信息不存在'); + } + $result = \app\common\service\server\Order::dispatchOrders($order->toArray(), $data['dealer_id']); + if ($result) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError('操作失败'); + } } diff --git a/app/store/controller/dealer/User.php b/app/store/controller/dealer/User.php index 06a46d3a..acb8441e 100644 --- a/app/store/controller/dealer/User.php +++ b/app/store/controller/dealer/User.php @@ -12,12 +12,15 @@ declare (strict_types=1); namespace app\store\controller\dealer; -use think\response\Json; +use app\common\service\qrcode\Poster; use app\store\controller\Controller; -use app\store\model\dealer\User as UserModel; use app\store\model\dealer\Referee as RefereeModel; -use app\common\service\qrcode\Poster; +use app\store\model\dealer\User as UserModel; use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\response\Json; /** * 分销商管理 @@ -84,9 +87,9 @@ class User extends Controller * @param string $channel 渠道 * @return Json * @throws BaseException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public function poster(int $dealerId, string $channel = 'H5'): Json { @@ -94,4 +97,18 @@ class User extends Controller $Qrcode = new Poster($model, $channel); return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]); } + + /** + * @notes:工程师分销商 + * @return Json + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function getEngineer(): Json + { + $list = UserModel::getEngineer(); + return $this->renderSuccess(compact('list')); + } } \ No newline at end of file diff --git a/app/store/model/server/Server.php b/app/store/model/server/Server.php index 451f073e..ef844260 100644 --- a/app/store/model/server/Server.php +++ b/app/store/model/server/Server.php @@ -1,11 +1,9 @@ select()->delete(); - } catch (DataNotFoundException|ModelNotFoundException|DbException $e) { - return false; - } + return static::whereIn('server_id', $serverId)->delete(); } /**