From 3f2e3b3f10b318fd29790e2b5d557dd140613c46 Mon Sep 17 00:00:00 2001 From: limu Date: Wed, 31 Jan 2024 11:38:15 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=85=A5=E9=A9=BB=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Store.php | 16 ++++++++++++++++ app/admin/model/Store.php | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 9e491023..f3a2568b 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -139,4 +139,20 @@ class Store extends Controller } return $this->renderSuccess('操作成功'); } + + /** + * 审核商城 + * @param int $storeId + * @return Json + */ + public function audit(int $storeId): Json + { + // 商城详情 + $model = StoreModel::detail($storeId); + if (!$model->auditStore($this->request->param())) { + return $this->renderError($model->getError() ?: '操作失败'); + } + return $this->renderSuccess('操作成功'); + } + } diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index 3292c9b9..10eb5b52 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -88,4 +88,10 @@ class Store extends StoreModel return $this->save(['is_delete' => 1]); }); } + + public function auditStore(array $data) + { + $storeInfo = $this->toArray(); + print_r($storeInfo);exit; + } } From cfe9dd03a25e1cd2bdbfda4c022a0834532bcd76 Mon Sep 17 00:00:00 2001 From: limu Date: Wed, 31 Jan 2024 11:58:27 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/model/Store.php | 26 +++++++++++++++++++++++++- app/api/model/Article.php | 2 +- app/api/model/article/Category.php | 1 + app/common/model/article/Category.php | 11 +++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index 10eb5b52..ec5bf440 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\admin\model; use app\admin\model\Page as PageModel; +use app\admin\model\store\User; use app\common\model\Store as StoreModel; use app\admin\model\store\User as StoreUserModel; @@ -92,6 +93,29 @@ class Store extends StoreModel public function auditStore(array $data) { $storeInfo = $this->toArray(); - print_r($storeInfo);exit; + if($storeInfo['status'] != 0){ + $this->error = '状态异常,请勿重复操作'; + return false; + } + $user = User::where(['user_id' => $storeInfo['user_id']])->find(); + if (StoreUserModel::checkExist($user['mobile'])) { + $this->error = '商家用户名已存在'; + return false; + } + if($data['status'] == 1){ + return $this->transaction(function () use ($data) { + // 添加小程序记录 + $data['is_recycle'] = 0; + if ($status = $this->save($data)) { + // 新增商家用户信息 + (new StoreUserModel)->add((int)$this['store_id'], $data); + // 新增默认首页数据 + (new PageModel)->insertDefault((int)$this['store_id']); + } + return $status; + }); + }else{ + + } } } diff --git a/app/api/model/Article.php b/app/api/model/Article.php index 58daf544..22197d5b 100644 --- a/app/api/model/Article.php +++ b/app/api/model/Article.php @@ -98,7 +98,7 @@ class Article extends ArticleModel public function helpCenter() { - $cat = CategoryModel::where(['status' => 1])->order('sort desc')->select()->toArray(); + $cat = CategoryModel::where(['status' => 1])->with(['catImg'])->order('sort desc')->select()->toArray(); foreach ($cat as $k => $v) { $cat[$k]['child'] = $this->where('status', '=', 1) ->where('is_delete', '=', 0) diff --git a/app/api/model/article/Category.php b/app/api/model/article/Category.php index 78910e92..373e6db0 100644 --- a/app/api/model/article/Category.php +++ b/app/api/model/article/Category.php @@ -43,4 +43,5 @@ class Category extends CategoryModel { return $this->getList(['status' => 1]); } + } diff --git a/app/common/model/article/Category.php b/app/common/model/article/Category.php index 95f1cffe..0894158d 100644 --- a/app/common/model/article/Category.php +++ b/app/common/model/article/Category.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\common\model\article; use cores\BaseModel; +use think\model\relation\HasOne; /** * 文章分类模型 @@ -37,6 +38,16 @@ class Category extends BaseModel return static::get($categoryId); } + /** + * 关联用户头像表 + * @return HasOne + */ + public function catImg(): HasOne + { + return $this->hasOne('UploadFile', 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } + /** * 获取列表 * @param array $where From b5dd413388ec0ca0cf0d9c7b48261d26de18be7c Mon Sep 17 00:00:00 2001 From: limu Date: Wed, 31 Jan 2024 12:03:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/article/Category.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/model/article/Category.php b/app/common/model/article/Category.php index 0894158d..98af9c8b 100644 --- a/app/common/model/article/Category.php +++ b/app/common/model/article/Category.php @@ -44,7 +44,8 @@ class Category extends BaseModel */ public function catImg(): HasOne { - return $this->hasOne('UploadFile', 'file_id', 'img_id') + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') ->bind(['img_url' => 'preview_url']); } From 278b68f1b9112753c3b975545205f1febe8437e7 Mon Sep 17 00:00:00 2001 From: limu Date: Wed, 31 Jan 2024 12:26:26 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/model/Store.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index ec5bf440..cba14037 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -16,6 +16,7 @@ use app\admin\model\Page as PageModel; use app\admin\model\store\User; use app\common\model\Store as StoreModel; use app\admin\model\store\User as StoreUserModel; +use app\common\model\User as UserModel; /** * 商家记录表模型 @@ -93,29 +94,42 @@ class Store extends StoreModel public function auditStore(array $data) { $storeInfo = $this->toArray(); - if($storeInfo['status'] != 0){ + if ($storeInfo['status'] != 0) { $this->error = '状态异常,请勿重复操作'; return false; } - $user = User::where(['user_id' => $storeInfo['user_id']])->find(); - if (StoreUserModel::checkExist($user['mobile'])) { + $user = UserModel::where(['user_id' => $storeInfo['user_id']])->find(); + if (empty($user) || empty($user->mobile)) { + $this->error = '用户不存在,或未绑定手机'; + return false; + } + if (StoreUserModel::checkExist($user->mobile)) { $this->error = '商家用户名已存在'; return false; } - if($data['status'] == 1){ + if ($data['status'] == 1) { + $data['user_id'] = $storeInfo['user_id']; + $data['mobile'] = $user->mobile; return $this->transaction(function () use ($data) { // 添加小程序记录 - $data['is_recycle'] = 0; - if ($status = $this->save($data)) { + $update['is_recycle'] = 0; + $update['status'] = 1; + if ($status = $this->save($update)) { // 新增商家用户信息 - (new StoreUserModel)->add((int)$this['store_id'], $data); + $storeUser = [ + 'user_name' => $data['mobile'], + 'password' => $data['mobile'], + ]; + (new StoreUserModel)->add((int)$this['store_id'], $storeUser); // 新增默认首页数据 (new PageModel)->insertDefault((int)$this['store_id']); + //指定用户类型更改为商家 + (new UserModel)->where(['user_id' => $data['user_id']])->update(['user_type' => 40]); } return $status; }); - }else{ - + } else { + return $this->save(['status' => 2]); } } } From adceb8e41fba044af82469820a919644da1b2e5a Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 31 Jan 2024 13:32:40 +0800 Subject: [PATCH 5/5] 1 --- app/api/controller/Recovery.php | 18 +- app/api/model/RecoveryImage.php | 8 +- app/api/model/RecoveryOrder.php | 22 +-- app/api/model/Server/ServerCategory.php | 1 + app/common/model/RecoveryImage.php | 6 +- app/common/model/RecoveryOrder.php | 6 +- app/common/model/server/RecoveryCategory.php | 61 ++++++ app/common/model/server/ServerRecovery.php | 76 +++++++ app/store/controller/Recovery.php | 198 +++++++++++++++++++ app/store/model/server/RecoveryCategory.php | 48 +++++ app/store/model/server/ServerRecovery.php | 62 ++++++ 11 files changed, 476 insertions(+), 30 deletions(-) create mode 100644 app/common/model/server/RecoveryCategory.php create mode 100644 app/common/model/server/ServerRecovery.php create mode 100644 app/store/controller/Recovery.php create mode 100644 app/store/model/server/RecoveryCategory.php create mode 100644 app/store/model/server/ServerRecovery.php diff --git a/app/api/controller/Recovery.php b/app/api/controller/Recovery.php index 08897916..fec56b97 100644 --- a/app/api/controller/Recovery.php +++ b/app/api/controller/Recovery.php @@ -61,12 +61,12 @@ class Recovery extends Controller */ public function detail(): Json { - $recoveryId = intval($this->request->post('recovery_id')); - if (!$recoveryId) { + $orderId = intval($this->request->post('order_id')); + if (!$orderId) { return $this->renderError('缺少必要参数'); } $model = new RecoveryOrder(); - $info = $model->getDetails($recoveryId); + $info = $model->getDetails($orderId); if ($info && !empty($info['images'])) { $info['is_cancel'] = 0; if ($info['order_status'] == RecoveryStatusEnum::ACCEPTED) { @@ -91,12 +91,12 @@ class Recovery extends Controller */ public function cancel(): Json { - $recoveryId = intval($this->request->post('recovery_id')); - if (!$recoveryId) { + $orderId = intval($this->request->post('order_id')); + if (!$orderId) { return $this->renderError('缺少必要参数'); } $model = new RecoveryOrder(); - if ($model->cancel($recoveryId)) { + if ($model->cancel($orderId)) { return $this->renderSuccess('操作成功'); } return $this->renderError('操作失败'); @@ -200,8 +200,8 @@ class Recovery extends Controller */ public function update(): Json { - $recovery_id = intval($this->request->post('recovery_id')); - if (!$recovery_id) { + $order_id = intval($this->request->post('order_id')); + if (!$order_id) { return $this->renderError('缺少必要参数'); } $imageIds = $this->request->post('image_ids'); @@ -276,7 +276,7 @@ class Recovery extends Controller 'shop_id' => $shop_id, ]; $model = new RecoveryOrder(); - if ($model->edit($data, $recovery_id, $imageIds)) { + if ($model->edit($data, $order_id, $imageIds)) { return $this->renderSuccess('操作成功'); } return $this->renderError('操作失败'); diff --git a/app/api/model/RecoveryImage.php b/app/api/model/RecoveryImage.php index 069a28ea..8583382e 100644 --- a/app/api/model/RecoveryImage.php +++ b/app/api/model/RecoveryImage.php @@ -18,15 +18,15 @@ class RecoveryImage extends BaseRecoveryImage /** * 更新关系记录 - * @param int $recoveryId + * @param int $orderId * @param array $imageIds 新的图片集 * @return array|false */ - public static function updates(int $recoveryId, array $imageIds) + public static function updates(int $orderId, array $imageIds) { // 删除所有的sku记录 - static::deleteAll(['recovery_id' => $recoveryId]); + static::deleteAll(['order_id' => $orderId]); // 批量写入商品图片记录 - return static::increased($recoveryId, $imageIds); + return static::increased($orderId, $imageIds); } } \ No newline at end of file diff --git a/app/api/model/RecoveryOrder.php b/app/api/model/RecoveryOrder.php index 83f6714d..07e33610 100644 --- a/app/api/model/RecoveryOrder.php +++ b/app/api/model/RecoveryOrder.php @@ -46,14 +46,14 @@ class RecoveryOrder extends BaseRecoveryOrder /** * @notes:订单详情 - * @param int $recoveryId + * @param int $orderId * @return BaseRecoveryOrder|array|null * @throws BaseException * @author: wanghousheng */ - public function getDetails(int $recoveryId) + public function getDetails(int $orderId) { - $where['recovery_id'] = $recoveryId; + $where['order_id'] = $orderId; $where['user_id'] = UserService::getCurrentLoginUserId(); return static::detail($where, ['images.file']); } @@ -86,16 +86,16 @@ class RecoveryOrder extends BaseRecoveryOrder /** * @notes:更新 * @param array $data - * @param int $recoveryId + * @param int $orderId * @param array $imageIds * @return bool * @author: wanghousheng */ - public function edit(array $data, int $recoveryId, array $imageIds = []): bool + public function edit(array $data, int $orderId, array $imageIds = []): bool { - if ($this->where(['recovery_id' => $recoveryId])->save($data)) { + if ($this->where(['order_id' => $orderId])->save($data)) { if ($imageIds) { - RecoveryImage::updates($recoveryId, $imageIds); + RecoveryImage::updates($orderId, $imageIds); } return true; } @@ -104,14 +104,14 @@ class RecoveryOrder extends BaseRecoveryOrder /** * @notes:取消 - * @param int $recoveryId + * @param int $orderId * @return bool * @throws BaseException * @author: wanghousheng */ - public function cancel(int $recoveryId): bool + public function cancel(int $orderId): bool { - $where['recovery_id'] = $recoveryId; + $where['order_id'] = $orderId; // 当前用户ID $userId = UserService::getCurrentLoginUserId(); if (!UserService::isStore()) { @@ -119,7 +119,7 @@ class RecoveryOrder extends BaseRecoveryOrder } $info = static::detail($where); if (!$info->isEmpty() && $info['order_status'] == RecoveryStatusEnum::ACCEPTED) { - $this->where(['recovery_id' => $recoveryId])->save(['order_status' => RecoveryStatusEnum::CANCEL]); + $this->where(['order_id' => $orderId])->save(['order_status' => RecoveryStatusEnum::CANCEL]); return true; } return false; diff --git a/app/api/model/Server/ServerCategory.php b/app/api/model/Server/ServerCategory.php index d87abd0d..6d1ae23b 100644 --- a/app/api/model/Server/ServerCategory.php +++ b/app/api/model/Server/ServerCategory.php @@ -44,6 +44,7 @@ class ServerCategory extends BaseServerCategory public function list(): array { return $this->with(['image']) + ->where(['status' => 1]) ->order(['sort', 'create_time']) ->select() ->toArray(); diff --git a/app/common/model/RecoveryImage.php b/app/common/model/RecoveryImage.php index 3bef1370..8bfb97fa 100644 --- a/app/common/model/RecoveryImage.php +++ b/app/common/model/RecoveryImage.php @@ -28,18 +28,18 @@ class RecoveryImage extends BaseModel /** * @notes:批量插入回收图片记录 - * @param int $recoveryId 回收ID + * @param int $orderId 回收ID * @param array $imageIds 图片ID集 * @return array|false * @author: wanghousheng */ - public static function increased(int $recoveryId, array $imageIds) + public static function increased(int $orderId, array $imageIds) { $dataset = []; foreach ($imageIds as $imageId) { $dataset[] = [ 'image_id' => $imageId, - 'recovery_id' => $recoveryId, + 'order_id' => $orderId, 'store_id' => self::$storeId ]; } diff --git a/app/common/model/RecoveryOrder.php b/app/common/model/RecoveryOrder.php index 3ba62b77..7082596f 100644 --- a/app/common/model/RecoveryOrder.php +++ b/app/common/model/RecoveryOrder.php @@ -11,10 +11,10 @@ use think\model\relation\HasMany; class RecoveryOrder extends BaseModel { // 定义表名 - protected $name = 'server_recovery'; + protected $name = 'server_recovery_order'; // 定义主键 - protected $pk = 'recovery_id'; + protected $pk = 'order_id'; /** * 追加字段 * @var array @@ -30,7 +30,7 @@ class RecoveryOrder extends BaseModel */ public function images(): HasMany { - return $this->hasMany(RecoveryImage::class, 'recovery_id', 'recovery_id')->order(['id']); + return $this->hasMany(RecoveryImage::class, 'order_id', 'order_id')->order(['id']); } public function getOrderStatusTextAttr($value, $data) diff --git a/app/common/model/server/RecoveryCategory.php b/app/common/model/server/RecoveryCategory.php new file mode 100644 index 00000000..caf993df --- /dev/null +++ b/app/common/model/server/RecoveryCategory.php @@ -0,0 +1,61 @@ +hasOne(UploadFile::class, 'file_id', 'image_id'); + } + + /** + * @notes:分类详情 + * @param $where + * @param array $with + * @return static|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } + + /** + * @notes:获取全部记录 + * @param array $where + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function getList(array $where = []): array + { + $where = $this->setQueryDefaultValue($where); + return $this->with(['image']) + ->where($where) + ->order(['sort', 'create_time']) + ->select() + ->toArray(); + } +} \ No newline at end of file diff --git a/app/common/model/server/ServerRecovery.php b/app/common/model/server/ServerRecovery.php new file mode 100644 index 00000000..3f0e57f0 --- /dev/null +++ b/app/common/model/server/ServerRecovery.php @@ -0,0 +1,76 @@ +hasOne(UploadFile::class, 'file_id', 'image_id') + ->bind(['recovery_image' => 'preview_url']); + } + + public function category(): HasOne + { + return $this->hasOne(RecoveryCategory::class, 'category_id', 'category_id') + ->bind(['recovery_category' => 'name']); + } + + /** + * @notes:回收详情 + * @param $where + * @param array $with + * @return static|array|null + * @author: wanghousheng + */ + public static function detail($where, array $with = []) + { + return static::get($where, $with); + } + + /** + * @notes:获取全部记录 + * @param array $where + * @param int $listRows + * @param string $sort + * @param string $sort_type + * @return Paginator + * @throws DbException + * @author: wanghousheng + */ + public function getList(array $where = [], int $listRows = 15, string $sort = '', string $sort_type = 'desc'): Paginator + { + $where = $this->setQueryDefaultValue($where); + $sort_arr = ['sort' => $sort_type, 'create_time' => $sort_type]; + if ($sort) { + $sort_arr = [$sort => $sort_type, 'create_time' => $sort_type]; + } + return $this->with(['image'])->withJoin(['category' => ['category_id', 'name']]) + ->where($where) + ->order($sort_arr) + ->paginate($listRows); + } +} \ No newline at end of file diff --git a/app/store/controller/Recovery.php b/app/store/controller/Recovery.php new file mode 100644 index 00000000..893eadc7 --- /dev/null +++ b/app/store/controller/Recovery.php @@ -0,0 +1,198 @@ +request->post('name'); + $where = []; + if (!empty($name)) { + $where[] = ['name', 'like', `%$name%`]; + } + $model = new RecoveryCategory(); + try { + $list = $model->getList($where); + } catch (DataNotFoundException|ModelNotFoundException|DbException $e) { + return $this->renderError($e->getMessage() ?: '接口异常'); + } + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:添加分类 + * @return Json + * @author: wanghousheng + */ + public function addCategory(): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = new RecoveryCategory(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @notes:编辑分类 + * @param int $categoryId + * @return Json + * @author: wanghousheng + */ + public function editCategory(int $categoryId): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = RecoveryCategory::detail($categoryId); + if ($model->edit($data)) { + return $this->renderSuccess('编辑成功'); + } + return $this->renderError($model->getError() ?: '编辑失败'); + } + + public function deleteCategory(int $categoryId): Json + { + $model = RecoveryCategory::detail($categoryId); + if ($model->remove()) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError('删除失败'); + } + + /** + * @notes:回收列表 + * @return Json + * @author: wanghousheng + */ + public function recoveryList(): Json + { + // 获取列表记录 + $model = new ServerRecovery(); + $recovery_name = $this->request->post('recovery_name'); + $category_id = intval($this->request->post('category_id')); + $status = intval($this->request->post('status')); + $where = []; + if ($recovery_name) { + $where[] = ['recovery.server_name', 'like', "%$recovery_name%"]; + } + if ($category_id) { + $where[] = ['recovery.category_id', '=', $category_id]; + } + if ($status) { + $where[] = ['recovery.status', '=', $status]; + } + try { + $list = $model->getList($where); + } catch (DbException $e) { + return $this->renderError($e->getMessage()); + } + return $this->renderSuccess(compact('list')); + } + + public function recoveryDetail(int $recoveryId): Json + { + // 获取商品详情 + $model = new ServerRecovery; + $info = $model->getDetail($recoveryId); + return $this->renderSuccess(compact('info')); + } + + /** + * @notes:添加回收 + * @return Json + * @author: wanghousheng + */ + public function addRecovery(): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = new ServerRecovery(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @notes:编辑回收 + * @param int $recoveryId + * @return Json + * @author: wanghousheng + */ + public function editRecovery(int $recoveryId): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = ServerRecovery::detail($recoveryId); + if ($model->edit($data)) { + return $this->renderSuccess('编辑成功'); + } + return $this->renderError($model->getError() ?: '编辑失败'); + } + + /** + * @notes:订单状态 + * @return Json + * @author: wanghousheng + */ + public function orderStatus(): Json + { + $list = array_values(RecoveryStatusEnum::data()); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:删除回收 + * @param array $recoveryId + * @return Json + * @author: wanghousheng + */ + public function deleteRecovery(array $recoveryId): Json + { + $model = new ServerRecovery; + if ($model->remove($recoveryId)) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError('删除失败'); + } + + /** + * 修改回收状态(上下架) + * @param array $recoveryIds id集 + * @param bool $state 为true表示上架 + * @return Json + */ + public function recoveryStatus(array $recoveryIds, bool $state): Json + { + $model = new ServerRecovery; + if (!$model->setStatus($recoveryIds, $state)) { + return $this->renderError($model->getError() ?: '操作失败'); + } + return $this->renderSuccess('操作成功'); + } +} \ No newline at end of file diff --git a/app/store/model/server/RecoveryCategory.php b/app/store/model/server/RecoveryCategory.php new file mode 100644 index 00000000..6220ba71 --- /dev/null +++ b/app/store/model/server/RecoveryCategory.php @@ -0,0 +1,48 @@ +save($data); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + * @author: wanghousheng + */ + public function edit($data): bool + { + // 是否删除图片 + !isset($data['image_id']) && $data['image_id'] = 0; + return $this->save($data) !== false; + } + + /** + * @notes:删除 + * @return bool + * @author: wanghousheng + */ + public function remove(): bool + { + if (!static::detail(['category_id' => $this['category_id']])) { + $this->error = '记录不存在'; + return false; + } + return $this->delete(); + } +} \ No newline at end of file diff --git a/app/store/model/server/ServerRecovery.php b/app/store/model/server/ServerRecovery.php new file mode 100644 index 00000000..29e16d3a --- /dev/null +++ b/app/store/model/server/ServerRecovery.php @@ -0,0 +1,62 @@ +save($data); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + * @author: wanghousheng + */ + public function edit($data): bool + { + // 是否删除图片 + !isset($data['image_id']) && $data['image_id'] = 0; + return $this->save($data) !== false; + } + + /** + * @notes:删除 + * @param array $recoveryId + * @return bool + * @author: wanghousheng + */ + public function remove(array $recoveryId): bool + { + return static::whereIn('server_id', $recoveryId)->delete(); + } + + /** + * 修改回收状态 + * @param array $recoveryIds 商品id集 + * @param bool $state 为true表示上架 + * @return bool|false + */ + public function setStatus(array $recoveryIds, bool $state): bool + { + // 批量更新记录 + return static::updateBase(['status' => $state ? 1 : 2], [['recovery_id', 'in', $recoveryIds]]); + } + + public function getDetail(int $recoveryId) + { + return static::detail($recoveryId, ['image', 'category']); + } +} \ No newline at end of file