From 6856f5c2cc0592b1481fd5c08944143616bd495b Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 26 Jan 2024 18:14:47 +0800 Subject: [PATCH] 1 --- app/api/controller/Server.php | 143 ++++++++++++++++++++++++ app/api/model/Server.php | 21 ++++ app/api/model/Server/ServerCategory.php | 51 +++++++++ app/api/model/Server/ServerOrder.php | 70 ++++++++++++ app/api/service/User.php | 128 ++++++++++++++++++++- app/common/enum/OrderType.php | 22 ++++ app/common/enum/ServerEnum.php | 10 +- app/common/enum/user/UserTypeEnum.php | 56 ++++++++++ app/common/model/server/Server.php | 6 +- app/common/service/server/Order.php | 2 +- 10 files changed, 499 insertions(+), 10 deletions(-) create mode 100644 app/api/controller/Server.php create mode 100644 app/api/model/Server.php create mode 100644 app/api/model/Server/ServerCategory.php create mode 100644 app/api/model/Server/ServerOrder.php create mode 100644 app/common/enum/user/UserTypeEnum.php diff --git a/app/api/controller/Server.php b/app/api/controller/Server.php new file mode 100644 index 00000000..b0354358 --- /dev/null +++ b/app/api/controller/Server.php @@ -0,0 +1,143 @@ +list(); + if (!empty($list)) { + foreach ($list as $key => $value) { + unset($list[$key]['image']); + } + } + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:服务列表页 + * @throws DbException + * @author: wanghousheng + */ + public function list(): Json + { + $server_name = $this->request->post('server_name'); + $category_id = intval($this->request->post('category_id')); + $where = []; + if ($server_name) { + $where[] = ['server.server_name', 'like', "%$server_name%"]; + } + if ($category_id) { + $where[] = ['server.category_id', '=', $category_id]; + } + $model = new \app\api\model\Server($where); + $list = $model->getList(); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + if (!$list->isEmpty()) { + foreach ($data['list'] as $key => $value) { + unset($data['list'][$key]['image']); + unset($data['list'][$key]['category']); + } + } + return $this->renderSuccess($data); + } + + /** + * @notes:订单状态 + * @return Json + * @author: wanghousheng + */ + public function orderStatus(): Json + { + $list = array_values(ServerEnum::data()); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:用户订单列表 + * @throws DbException + * @throws BaseException + * @author: wanghousheng + */ + public function userOrderList(): Json + { + $order_no = $this->request->post('order_no'); + $order_status = intval($this->request->post('order_status')); + $where = []; + if (!empty($order_no)) { + $where['order_no'] = $order_no; + } + if ($order_status) { + $where['order_status'] = $order_status; + } + $model = new ServerOrder($where); + $list = $model->userOrders($where); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + if (!$list->isEmpty()) { + if (!$list->isEmpty()) { + foreach ($data['list'] as $key => $value) { + unset($data['list'][$key]['image']); + unset($data['list'][$key]['dealer']); + } + } + } + return $this->renderSuccess($data); + } + + /** + * @notes: + * @return Json + * @throws BaseException + * @throws DbException + * @author: wanghousheng + */ + public function dealerOrderList(): Json + { + $order_no = $this->request->post('order_no'); + $order_status = intval($this->request->post('order_status')); + $where = []; + if (!empty($order_no)) { + $where['order_no'] = $order_no; + } + if ($order_status) { + $where['order_status'] = $order_status; + } + $model = new ServerOrder($where); + $list = $model->dealerOrders($where); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + if (!$list->isEmpty()) { + if (!$list->isEmpty()) { + foreach ($data['list'] as $key => $value) { + unset($data['list'][$key]['image']); + unset($data['list'][$key]['dealer']); + } + } + } + return $this->renderSuccess($data); + } +} \ No newline at end of file diff --git a/app/api/model/Server.php b/app/api/model/Server.php new file mode 100644 index 00000000..1dcfb594 --- /dev/null +++ b/app/api/model/Server.php @@ -0,0 +1,21 @@ +hasOne(UploadFile::class, 'file_id', 'image_id') + ->bind(['image_url' => 'preview_url']); + } + + /** + * @notes:获取全部记录 + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function list(): array + { + return $this->with(['image']) + ->order(['sort', 'create_time']) + ->select() + ->toArray(); + } +} \ No newline at end of file diff --git a/app/api/model/Server/ServerOrder.php b/app/api/model/Server/ServerOrder.php new file mode 100644 index 00000000..547ea119 --- /dev/null +++ b/app/api/model/Server/ServerOrder.php @@ -0,0 +1,70 @@ +with(['image', 'dealer']) + ->where($where) + ->where('user_id', '=', $userId) + ->where('is_delete', '=', 0) + ->order(['create_time' => 'desc']) + ->paginate($listRows); + } + + /** + * @notes:分销员订单列表 + * @param $where + * @param int $listRows + * @return Paginator + * @throws BaseException + * @throws DbException + * @author: wanghousheng + */ + public function dealerOrders($where, int $listRows = 15): Paginator + { + // 当前用户ID + $userId = UserService::getCurrentLoginUserId(); + // 查询列表数据 + return $this->with(['image', 'user']) + ->where($where) + ->where('dealer_id', '=', $userId) + ->where('is_delete', '=', 0) + ->order(['create_time' => 'desc']) + ->paginate($listRows); + } +} \ No newline at end of file diff --git a/app/api/service/User.php b/app/api/service/User.php index e088ce86..7fbe2615 100644 --- a/app/api/service/User.php +++ b/app/api/service/User.php @@ -12,12 +12,14 @@ declare (strict_types=1); namespace app\api\service; -use think\facade\Cache; use app\api\model\User as UserModel; use app\api\model\UserOauth as UserOauthModel; +use app\common\enum\Client as ClientEnum; +use app\common\enum\dealer\DealerUserEnum; +use app\common\enum\user\UserTypeEnum; use app\common\service\User as UserService; use cores\exception\BaseException; -use app\common\enum\Client as ClientEnum; +use think\facade\Cache; /** * 用户服务类 @@ -63,6 +65,128 @@ class User extends UserService return $userInfo ? $userInfo['user_id'] : false; } + /** + * @notes:是否PLUS会员 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public static function isPlusMember(): bool + { + $userType = static::getCurrentLoginUserType(); + if ($userType && $userType == UserTypeEnum::MEMBER && self::checkEffectiveTime()) { + return true; + } + return false; + } + + /** + * @notes:是否分销商 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function isDealerMember(): bool + { + $userType = static::getCurrentLoginUserType(); + if ($userType && $userType == UserTypeEnum::DEALER) { + $userId = self::getCurrentLoginUserId(); + //分销表里有没有 + $dealerInfo = \app\api\model\dealer\User::detail($userId, []); + if (!$dealerInfo->isEmpty() && self::checkEffectiveTime()) { + return true; + } + } + return false; + } + + /** + * @notes:是否分销商-工程师 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function isDealerEngineer(): bool + { + $userType = static::getCurrentLoginUserType(); + if ($userType && $userType == UserTypeEnum::DEALER) { + $userId = self::getCurrentLoginUserId(); + //分销表里有没有 + $dealerInfo = \app\api\model\dealer\User::detail($userId, []); + if (!$dealerInfo->isEmpty() && self::checkEffectiveTime() && $dealerInfo['type'] == DealerUserEnum::ENGINEER) { + return true; + } + } + return false; + } + + /** + * @notes:是否店主 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function isStore(): bool + { + $userType = static::getCurrentLoginUserType(); + if ($userType && $userType == UserTypeEnum::STORE) { + $userId = self::getCurrentLoginUserId(); + //商家表里有没有 + $model = new \app\api\model\Store(); + $store_id = $model->where(['user_id' => $userId])->value('store_id'); + if ($store_id && $store_id == $this->getStoreId()) { + return $userId; + } + } + return false; + } + + /** + * @notes:是否普通会员 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function isNormalMember(): bool + { + $userType = static::getCurrentLoginUserType(); + if ($userType && $userType == UserTypeEnum::NORMAL) { + return true; + } + return false; + } + + /** + * @notes:检测plus会员 分销商是否到期 + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + private function checkEffectiveTime(): bool + { + $userInfo = static::getCurrentLoginUser(); + if (!empty($userInfo) && !empty($userInfo['effective_time'])) { + $effective_time = strtotime($userInfo['effective_time'] . ' 23:59:59'); + if (time() < $effective_time) { + return true; + } + } + return false; + } + + /** + * 获取当前登录的用户身份 + * getCurrentLoginUser方法的二次封装 + * @param bool $isForce 是否强制验证登录, 如果未登录将抛错 + * @return int|false + * @throws BaseException + */ + public static function getCurrentLoginUserType(bool $isForce = true) + { + $userInfo = static::getCurrentLoginUser($isForce); + return $userInfo ? $userInfo['user_type'] : 10; + } + /** * 获取第三方用户信息 * @param int $userId 用户ID diff --git a/app/common/enum/OrderType.php b/app/common/enum/OrderType.php index de885ccd..e90c9e3d 100644 --- a/app/common/enum/OrderType.php +++ b/app/common/enum/OrderType.php @@ -22,9 +22,19 @@ class OrderType extends EnumBasics // 商城订单 const ORDER = 10; + // 服务订单 + const SERVER = 20; + + // 开通会员订单 + const MEMBER = 30; + + // 开通分销订单 + const DEALER = 40; + // 余额充值订单 const RECHARGE = 100; + /** * 获取订单类型值 * @return array @@ -39,6 +49,18 @@ class OrderType extends EnumBasics self::RECHARGE => [ 'name' => '余额充值订单', 'value' => self::RECHARGE, + ], + self::SERVER => [ + 'name' => '服务订单', + 'value' => self::SERVER, + ], + self::MEMBER => [ + 'name' => '开通会员订单', + 'value' => self::MEMBER, + ], + self::DEALER => [ + 'name' => '开通分销订单', + 'value' => self::DEALER, ] ]; } diff --git a/app/common/enum/ServerEnum.php b/app/common/enum/ServerEnum.php index 2ef1f635..dc94e799 100644 --- a/app/common/enum/ServerEnum.php +++ b/app/common/enum/ServerEnum.php @@ -26,10 +26,6 @@ class ServerEnum extends EnumBasics 'name' => '待付款', 'value' => self::APPLYPAY, ], - self::CANCELLED => [ - 'name' => '已取消', - 'value' => self::CANCELLED, - ], self::APPLYDISPATCH => [ 'name' => '待派单', 'value' => self::APPLYDISPATCH, @@ -41,7 +37,11 @@ class ServerEnum extends EnumBasics self::COMPLETED => [ 'name' => '已完成', 'value' => self::COMPLETED, - ] + ], + self::CANCELLED => [ + 'name' => '已取消', + 'value' => self::CANCELLED, + ], ]; } } \ No newline at end of file diff --git a/app/common/enum/user/UserTypeEnum.php b/app/common/enum/user/UserTypeEnum.php new file mode 100644 index 00000000..3808b188 --- /dev/null +++ b/app/common/enum/user/UserTypeEnum.php @@ -0,0 +1,56 @@ + [ + 'name' => '普通会员', + 'value' => self::NORMAL, + ], + self::MEMBER => [ + 'name' => 'PLUS会员', + 'value' => self::MEMBER, + ], + self::DEALER => [ + 'name' => '分销商', + 'value' => self::DEALER, + ], + self::STORE => [ + 'name' => '店长', + 'value' => self::STORE, + ] + ]; + } + + /** + * 根据值获取名称 + * @param string $value + * @return string + */ + public static function getName(string $value): string + { + return self::data()[$value]['name']; + } +} \ No newline at end of file diff --git a/app/common/model/server/Server.php b/app/common/model/server/Server.php index e2fe711f..2dd74252 100644 --- a/app/common/model/server/Server.php +++ b/app/common/model/server/Server.php @@ -30,12 +30,14 @@ class Server extends BaseModel */ public function image(): HasOne { - return $this->hasOne(UploadFile::class, 'file_id', 'image_id'); + return $this->hasOne(UploadFile::class, 'file_id', 'image_id') + ->bind(['server_image' => 'preview_url']); } public function category(): HasOne { - return $this->hasOne(ServerCategory::class, 'category_id', 'category_id'); + return $this->hasOne(ServerCategory::class, 'category_id', 'category_id') + ->bind(['server_category' => 'name']); } /** diff --git a/app/common/service/server/Order.php b/app/common/service/server/Order.php index 569b9157..e30fbac5 100644 --- a/app/common/service/server/Order.php +++ b/app/common/service/server/Order.php @@ -23,7 +23,7 @@ class Order extends BaseService */ public static function createOrderNo(): string { - return date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13)))), 0, 8); + return 'SE' . date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13)))), 0, 8); } /**