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] 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); + } }