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/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 d06c307f..357ea6cf 100644 --- a/app/common/model/MaintenanceCategory.php +++ b/app/common/model/MaintenanceCategory.php @@ -36,7 +36,6 @@ class MaintenanceCategory extends BaseModel return static::get($categoryId); } - /** * 获取列表 * @param array $where @@ -48,7 +47,12 @@ class MaintenanceCategory extends BaseModel public function getList(array $where = []): \think\Collection { return $this->where($where) + ->with(['maintenances.catImg']) ->order(['sort', $this->getPk()]) ->select(); } + + public function maintenances() { + return $this->hasMany(Maintenance::class,'category_id', 'id'); + } } diff --git a/app/store/model/Maintenance.php b/app/store/model/Maintenance.php index 7f09e2fe..0dd57317 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); @@ -69,8 +70,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 +89,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;