From 61cf9835dcbf45116f90b2d1478da3fa6f63885a Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:09:21 +0800 Subject: [PATCH 1/7] update --- app/common/model/MaintenanceCategory.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index d06c307f..9e42ffe1 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -36,6 +36,14 @@ class MaintenanceCategory extends BaseModel return static::get($categoryId); } + public function catImg(): HasOne + { + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } + + /** * 获取列表 @@ -47,7 +55,7 @@ class MaintenanceCategory extends BaseModel */ public function getList(array $where = []): \think\Collection { - return $this->where($where) + return $this->where($where)->with(['catImg']) ->order(['sort', $this->getPk()]) ->select(); } From 001d4c9b214e82736951b41576b18a7b6a655e0c Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:12:05 +0800 Subject: [PATCH 2/7] update --- app/store/model/Maintenance.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index 7f09e2fe..a3011868 100644 --- a/app/store/model/Maintenance.php +++ b/app/store/model/Maintenance.php @@ -69,8 +69,8 @@ class Maintenance extends MaintenanceModel } } */ - if (empty($data['url'])) { - $this->error = '请输地址'; + if (empty($data['img_id'])) { + $this->error = '请上传维修图片'; return false; } $data['store_id'] = self::$storeId; @@ -88,8 +88,8 @@ class Maintenance extends MaintenanceModel $this->error = '请输入保修名称'; return false; } - if (empty($data['url'])) { - $this->error = '请输入地址'; + if (empty($data['img_id'])) { + $this->error = '请上传维修图片'; return false; } return $this->save($data) !== false; From 1679fc7964ce5133770bebca59e36ceab21bd623 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:16:10 +0800 Subject: [PATCH 3/7] update --- app/common/model/MaintenanceCategory.php | 11 +---------- app/store/model/Maintenance.php | 10 +++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index 9e42ffe1..6f6dc629 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -36,15 +36,6 @@ class MaintenanceCategory extends BaseModel return static::get($categoryId); } - public function catImg(): HasOne - { - $module = self::getCalledModule(); - return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') - ->bind(['img_url' => 'preview_url']); - } - - - /** * 获取列表 * @param array $where @@ -55,7 +46,7 @@ class MaintenanceCategory extends BaseModel */ public function getList(array $where = []): \think\Collection { - return $this->where($where)->with(['catImg']) + return $this->where($where) ->order(['sort', $this->getPk()]) ->select(); } diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index a3011868..a94dc005 100644 --- a/app/store/model/Maintenance.php +++ b/app/store/model/Maintenance.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\store\model; use app\common\model\Maintenance as MaintenanceModel; +use think\model\relation\HasOne; /** * 文章模型 @@ -41,7 +42,7 @@ class Maintenance extends MaintenanceModel $params['status'] > -1 && $filter[] = ['status', '=', $params['status']]; $params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']]; // 查询列表数据 - $data = $this->where($filter) + $data = $this->where($filter)->with(['catImg']) ->where('is_delete', '=', 0) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->paginate(15); @@ -108,4 +109,11 @@ class Maintenance extends MaintenanceModel { return (new static)->where($where)->where('is_delete', '=', 0)->count(); } + + public function catImg(): HasOne + { + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } } From 60016ea5d5643e1fb66a36cafe358f7327775714 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:25:16 +0800 Subject: [PATCH 4/7] update --- app/api/controller/User.php | 26 ++++++++---------------- app/common/model/MaintenanceCategory.php | 5 +++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/api/controller/User.php b/app/api/controller/User.php index ac3cb45b..2e7cae02 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.php @@ -16,6 +16,7 @@ use app\api\model\Agreement as AgreementModel; use app\api\model\User as UserModel; use app\api\model\Invite\InviteLog; use app\common\service\qrcode\BaseQRcode; +use app\store\model\MaintenanceCategory as MaintenanceCategoryModel; use app\store\model\User as StoreUserModel; use app\api\model\user\BalanceLog; use app\api\model\user\GoodSource as GoodsSourceModel; @@ -397,26 +398,17 @@ class User extends Controller return $this->renderSuccess(str_replace(root_path() . "public/", base_url(), $qrcode)); } + /** + * @throws ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + */ public function maintenance() { - $qrObj = new BaseQRcode(); $storeId = request()->header()['storeid']; - $list = Db::table('yoshop_maintenance_category') - ->where(['store_id' => $storeId, 'status' => 1,]) - ->select() - ->toArray(); - foreach ($list as &$item) { - $tags = []; - $data = Db::table('yoshop_maintenance') - ->where(['category_id' => $item['id'], 'is_delete' => 0]) - ->select() - ->toArray(); - foreach ($data as &$v) { - $v['url_path'] = $v['url'] ? str_replace(root_path() . "public/", base_url(), $qrObj->getOtherQrcode((int)$storeId, $v['url'])) : ''; - $tags[] = $v; - } - $item['tags'] = $tags; - } + $model = new MaintenanceCategoryModel; + $list = $model->getList(['store_id' => $storeId])->toArray(); + return $this->renderSuccess($list); } diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index 6f6dc629..41f31c54 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -47,7 +47,12 @@ class MaintenanceCategory extends BaseModel public function getList(array $where = []): \think\Collection { return $this->where($where) + ->with(['maintenances']) ->order(['sort', $this->getPk()]) ->select(); } + + public function maintenances() { + return $this->hasMany(MaintenanceCategory::class); + } } From bc69cf51d2a95417efd7461b1416631fd9237585 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:29:32 +0800 Subject: [PATCH 5/7] update --- app/common/model/MaintenanceCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index 41f31c54..fab5b990 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -53,6 +53,6 @@ class MaintenanceCategory extends BaseModel } public function maintenances() { - return $this->hasMany(MaintenanceCategory::class); + return $this->hasMany(MaintenanceCategory::class,'category_id', 'id'); } } From 4847408e585e6e39651ab3567486e17b71364d4f Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:32:08 +0800 Subject: [PATCH 6/7] update --- app/common/model/MaintenanceCategory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index fab5b990..a8d750cf 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -53,6 +53,6 @@ class MaintenanceCategory extends BaseModel } public function maintenances() { - return $this->hasMany(MaintenanceCategory::class,'category_id', 'id'); + return $this->hasMany(Maintenance::class,'category_id', 'id'); } } From 6a40626fe8fd28942cbc13c7b61ec66f952c1319 Mon Sep 17 00:00:00 2001 From: bruce <1272542526@qq.com> Date: Thu, 21 Mar 2024 10:34:41 +0800 Subject: [PATCH 7/7] update --- app/common/model/Maintenance.php | 8 ++++++++ app/common/model/MaintenanceCategory.php | 2 +- app/store/model/Maintenance.php | 7 ------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/common/model/Maintenance.php b/app/common/model/Maintenance.php index 9597d4a3..b3de56d4 100644 --- a/app/common/model/Maintenance.php +++ b/app/common/model/Maintenance.php @@ -14,6 +14,7 @@ namespace app\common\model; use cores\BaseModel; use think\model\relation\BelongsTo; +use think\model\relation\HasOne; /** * 文件库分组模型 @@ -36,4 +37,11 @@ class Maintenance extends BaseModel $module = self::getCalledModule(); return $this->BelongsTo("app\\{$module}\\model\\MaintenanceCategory", 'category_id'); } + + public function catImg(): HasOne + { + $module = self::getCalledModule(); + return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') + ->bind(['img_url' => 'preview_url']); + } } diff --git a/app/common/model/MaintenanceCategory.php b/app/common/model/MaintenanceCategory.php index a8d750cf..357ea6cf 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -47,7 +47,7 @@ class MaintenanceCategory extends BaseModel public function getList(array $where = []): \think\Collection { return $this->where($where) - ->with(['maintenances']) + ->with(['maintenances.catImg']) ->order(['sort', $this->getPk()]) ->select(); } diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index a94dc005..0dd57317 100644 --- a/app/store/model/Maintenance.php +++ b/app/store/model/Maintenance.php @@ -109,11 +109,4 @@ class Maintenance extends MaintenanceModel { return (new static)->where($where)->where('is_delete', '=', 0)->count(); } - - public function catImg(): HasOne - { - $module = self::getCalledModule(); - return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'img_id') - ->bind(['img_url' => 'preview_url']); - } }