From f88ad8e281bdd38f844b46d6f91e0c9dd27cb481 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Sun, 18 Feb 2024 16:44:22 +0800 Subject: [PATCH] update --- app/api/controller/User.php | 56 ++++----- app/common/model/Maintenance.php | 39 +++++++ app/common/model/MaintenanceCategory.php | 54 +++++++++ app/store/controller/content/Maintenance.php | 82 ++++++++++++++ .../content/MaintenanceCategory.php | 83 ++++++++++++++ app/store/model/Maintenance.php | 107 ++++++++++++++++++ app/store/model/MaintenanceCategory.php | 68 +++++++++++ 7 files changed, 455 insertions(+), 34 deletions(-) create mode 100644 app/common/model/Maintenance.php create mode 100644 app/common/model/MaintenanceCategory.php create mode 100644 app/store/controller/content/Maintenance.php create mode 100644 app/store/controller/content/MaintenanceCategory.php create mode 100644 app/store/model/Maintenance.php create mode 100644 app/store/model/MaintenanceCategory.php diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 9e8d9f38..d5989b3c 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -33,6 +33,7 @@ use think\response\Json; use think\Db; use app\common\model\dealer\Order as DealerOrderModel; use app\common\model\Order as OrderModel; + /** * 用户管理 * Class User @@ -319,6 +320,7 @@ class User extends Controller $Qrcode = new InviteUser($userInfo, 'MP-WEIXIN'); return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]); } + /** * 用户列表 * @return Json @@ -346,11 +348,12 @@ class User extends Controller } elseif ($value['user_type'] == 30) { $value['order_num'] = DealerOrderModel::where('first_user_id|second_user_id|third_user_id', '=', $value['user_id'])->count(); } - + } - + return $this->renderSuccess(compact('list')); } + public function updateUser(): Json { $params = $this->request->param(); @@ -359,12 +362,14 @@ class User extends Controller UserModel::where('user_id', $user_id)->update($params); return $this->renderSuccess('ok'); } + /** * 生成会员码 * [getMembershipInviteQrcode description] * @return [type] [description] */ - public function getMembershipInviteQrcode(){ + public function getMembershipInviteQrcode() + { $user_id = $userInfo = UserService::getCurrentLoginUserId(true); $obj = new \app\common\service\qrcode\BaseQRcode(); // 小程序码参数 @@ -373,56 +378,39 @@ class User extends Controller // 下载小程序码 $page = 'pages/login/index'; $qrcode = $obj->getQrcode((int)$storeId, $scene, $page, 'MP-WEIXIN'); - return $this->renderSuccess(str_replace(root_path()."public/", base_url(), $qrcode)); + return $this->renderSuccess(str_replace(root_path() . "public/", base_url(), $qrcode)); } + /** * 生成分销商码 * [getDealerInviteQrcode description] * @return [type] [description] */ - public function getDealerInviteQrcode(){ + public function getDealerInviteQrcode() + { $storeId = request()->header()['storeid']; $user_id = $userInfo = UserService::getCurrentLoginUserId(true); $obj = new \app\common\service\qrcode\BaseQRcode(); $scene = 'uid:' . $user_id; $qrcode = $obj->getQrcode((int)$storeId, $scene, null, 'MP-WEIXIN'); - return $this->renderSuccess(str_replace(root_path()."public/", base_url(), $qrcode)); + return $this->renderSuccess(str_replace(root_path() . "public/", base_url(), $qrcode)); } - public function maintenance() + public function maintenance() { - $storeId = request()->header()['storeid']; - $list = Db::table('yoshop_maintenance') - ->where(['store_id' => $storeId, 'status' => 1, 'parent_id' => 0]) - ->field('id','name') - ->select() - ->toArray(); - foreach ($list as &$item) { - $item['tags'] = Db::table('yoshop_maintenance') - ->field('name,id,url') - ->where(['parent_id' => $item['id']]) + $storeId = request()->header()['storeid']; + $list = Db::table('yoshop_maintenance_category') + ->where(['store_id' => $storeId, 'status' => 1,]) ->select() ->toArray(); + foreach ($list as &$item) { + $item['tags'] = Db::table('yoshop_maintenance') + ->where(['category_id' => $item['id'], 'is_delete' => 0]) + ->select() + ->toArray(); } return $this->renderSuccess($list); } - - - - - - - - - - - - - - - - - } diff --git a/app/common/model/Maintenance.php b/app/common/model/Maintenance.php new file mode 100644 index 00000000..9597d4a3 --- /dev/null +++ b/app/common/model/Maintenance.php @@ -0,0 +1,39 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\BelongsTo; + +/** + * 文件库分组模型 + * Class UploadGroup + * @package app\common\model + */ +class Maintenance extends BaseModel +{ + // 定义表名 + protected $name = 'maintenance'; + + + public static function detail(int $articleId, array $with = []) + { + return self::get($articleId, $with); + } + + public function category(): BelongsTo + { + $module = self::getCalledModule(); + return $this->BelongsTo("app\\{$module}\\model\\MaintenanceCategory", 'category_id'); + } +} diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php new file mode 100644 index 00000000..d06c307f --- /dev/null +++ b/app/common/model/MaintenanceCategory.php @@ -0,0 +1,54 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\HasOne; + +/** + * 文章分类模型 + * Class Category + * @package app\common\model + */ +class MaintenanceCategory extends BaseModel +{ + // 定义表名 + protected $name = 'maintenance_category'; + + + /** + * 分类详情 + * @param int $categoryId + * @return static|array|null + */ + public static function detail(int $categoryId) + { + return static::get($categoryId); + } + + + /** + * 获取列表 + * @param array $where + * @return \think\Collection + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $where = []): \think\Collection + { + return $this->where($where) + ->order(['sort', $this->getPk()]) + ->select(); + } +} diff --git a/app/store/controller/content/Maintenance.php b/app/store/controller/content/Maintenance.php new file mode 100644 index 00000000..63c0f49e --- /dev/null +++ b/app/store/controller/content/Maintenance.php @@ -0,0 +1,82 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller\content; + +use think\response\Json; +use app\store\controller\Controller; +use app\store\model\Maintenance as MaintenanceModel; + +/** + * 文章管理控制器 + * Class article + * @package app\store\controller\content + */ +class Maintenance extends Controller +{ + /** + * 文章列表 + * @return Json + * @throws \think\db\exception\DbException + */ + public function list(): Json + { + $model = new MaintenanceModel; + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + + + + /** + * @return Json + */ + public function add(): Json + { + // 新增记录 + $model = new MaintenanceModel; + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @param int $articleId + * @return Json + */ + public function edit(int $articleId): Json + { + // 文章详情 + $model = MaintenanceModel::detail($articleId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除文章 + * @param int $articleId + * @return Json + */ + public function delete(int $articleId): Json + { + // 文章详情 + $model = MaintenanceModel::detail($articleId); + if (!$model->setDelete()) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } +} diff --git a/app/store/controller/content/MaintenanceCategory.php b/app/store/controller/content/MaintenanceCategory.php new file mode 100644 index 00000000..2a0c7567 --- /dev/null +++ b/app/store/controller/content/MaintenanceCategory.php @@ -0,0 +1,83 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller\content; + +use think\response\Json; +use app\store\controller\Controller; +use app\store\model\MaintenanceCategory as MaintenanceCategoryModel; + +/** + * 文章分类 + * Class Category + * @package app\store\controller\content\article + */ +class MaintenanceCategory extends Controller +{ + /** + * 文章分类列表 + * @return Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function list(): Json + { + $model = new MaintenanceCategoryModel; + $list = $model->getList(); + return $this->renderSuccess(compact('list')); + } + + /** + * 添加文章分类 + * @return Json + */ + public function add(): Json + { + // 新增记录 + $model = new MaintenanceCategoryModel; + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 编辑文章分类 + * @param int $categoryId + * @return Json + */ + public function edit(int $categoryId): Json + { + // 分类详情 + $model = MaintenanceCategoryModel::detail($categoryId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除文章分类 + * @param int $categoryId + * @return Json + */ + public function delete(int $categoryId): Json + { + $model = MaintenanceCategoryModel::detail($categoryId); + if (!$model->remove($categoryId)) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } +} diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php new file mode 100644 index 00000000..25655add --- /dev/null +++ b/app/store/model/Maintenance.php @@ -0,0 +1,107 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\Maintenance as MaintenanceModel; + +/** + * 文章模型 + * Class Article + * @package app\store\model + */ +class Maintenance extends MaintenanceModel +{ + /** + * 获取列表 + * @param array $param + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public function getList(array $param = []): \think\Paginator + { + // 查询参数 + $params = $this->setQueryDefaultValue($param, [ + 'name' => '', + 'categoryId' => 0, + 'status' => -1, + ]); + // 检索查询条件 + $filter = []; + !empty($params['name']) && $filter[] = ['name', 'like', "%{$params['title']}%"]; + $params['status'] > -1 && $filter[] = ['status', '=', $params['status']]; + $params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']]; + // 查询列表数据 + $data = $this->where($filter) + ->where('is_delete', '=', 0) + ->order(['sort' => 'asc', 'create_time' => 'desc']) + ->paginate(15); + + return self::preload($data, ['category']); + } + + /** + * 新增记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + + if (empty($data['name'])) { + $this->error = '请输入保修名称'; + return false; + } + + if (($data['parent_id']) != 0) { + if (empty($data['url'])) { + $this->error = '请输地址'; + return false; + } + + } + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * 更新记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + if (empty($data['name'])) { + $this->error = '请输入保修名称'; + return false; + } + if (empty($data['url'])) { + $this->error = '请输入地址'; + return false; + } + return $this->save($data) !== false; + } + + /** + * 软删除 + * @return bool + */ + public function setDelete(): bool + { + return $this->save(['is_delete' => 1]); + } + + public static function getTotal(array $where = []): int + { + return (new static)->where($where)->where('is_delete', '=', 0)->count(); + } +} diff --git a/app/store/model/MaintenanceCategory.php b/app/store/model/MaintenanceCategory.php new file mode 100644 index 00000000..42e88738 --- /dev/null +++ b/app/store/model/MaintenanceCategory.php @@ -0,0 +1,68 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\store\model\Maintenance as MaintenanceModel; +use app\common\model\MaintenanceCategory as MaintenanceCategoryModel; + +/** + * 文章分类模型 + * Class Category + * @package app\store\model\article + */ +class MaintenanceCategory extends MaintenanceCategoryModel +{ + /** + * 添加新记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + // 保存记录 + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * 编辑记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + // 保存记录 + return $this->save($data); + } + + /** + * 删除商品分类 + * @param int $categoryId + * @return bool + */ + public function remove(int $categoryId): bool + { + // 判断是否存在文章 + $articleCount = MaintenanceModel::getTotal(['category_id' => $categoryId]); + if ($articleCount > 0) { + $this->error = '该分类下存在' . $articleCount . '个报修,不允许删除'; + return false; + } + // 删除记录 + return $this->delete(); + } + + +} + +