diff --git a/app/api/controller/Controller.php b/app/api/controller/Controller.php index 67127e6a..62f06486 100644 --- a/app/api/controller/Controller.php +++ b/app/api/controller/Controller.php @@ -32,6 +32,9 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; + // 当前商户ID + protected int $merchantId = 0; + /** * API基类初始化 * @throws BaseException @@ -53,7 +56,7 @@ class Controller extends BaseController // throwError('很抱歉,您没有权限进入系统'); // } // } - + $this->getMerchantId(); } /** @@ -67,6 +70,17 @@ class Controller extends BaseController } } + /** + * 获取当前登录的商城ID + */ + protected function getMerchantId() + { + $user = UserService::getCurrentLoginUser(true); + if (!empty($user)) { + $this->merchantId = $user['user_name']; + } + } + /** * 验证当前商城状态 * @return void diff --git a/app/api/controller/Merchant.php b/app/api/controller/Merchant.php index 066b5fbe..4eeee8b0 100644 --- a/app/api/controller/Merchant.php +++ b/app/api/controller/Merchant.php @@ -12,6 +12,7 @@ declare (strict_types=1); namespace app\api\controller; +use app\api\model\Goods as GoodsModel; use app\common\model\store\StoreSettle; use app\common\model\UploadFile; use think\response\Json; @@ -81,6 +82,15 @@ class Merchant extends Controller { // 获取商品详情 $detail = MerchantModel::detail($id); + if ($detail['license_img_id']) { + $img_ids = explode(",", $detail['license_img_id']); + $files = UploadFile::getFileList($img_ids); + $detail['licenseImg'] = $files ?: null; + } + if ($detail['logo_image_id']) { + $files = UploadFile::getFileList($detail['logo_image_id']); + $detail['logoImage'] = $files ?: null; + } return $this->renderSuccess(compact('detail')); } @@ -120,6 +130,7 @@ class Merchant extends Controller public function list(): Json { $model = new MerchantModel; $list = $model->getList($this->request->param())->toArray(); + foreach ($list['data'] as $kr => $r) { $res[$kr]['licenseImg'] = []; if ($r['license_img_id']) { @@ -127,6 +138,12 @@ class Merchant extends Controller $files = UploadFile::getFileList($img_ids); $list['data'][$kr]['licenseImg'] = $files ?: null; } + + $modelgoods = new GoodsModel; + $param = $this->request->param(); + $params['merchantId'] = $r['id']; + $listgoods = $modelgoods->getList($param, 3); + $list['data'][$kr]['goodsInfo'] = $listgoods; } return $this->renderSuccess($list); } diff --git a/app/common/model/Category.php b/app/common/model/Category.php index f0ef3646..1fe8d322 100644 --- a/app/common/model/Category.php +++ b/app/common/model/Category.php @@ -114,6 +114,10 @@ class Category extends BaseModel $filter[] = ['parent_id', '=', $params['category_id']]; } + if (isset($param['merchantId']) && $param['merchantId'] != "") { + $filter[] = ['merchant_id', '=', $params['merchantId']]; + } + // 查询列表数据 return $this->with(['image','rankimage']) ->where($filter) diff --git a/app/common/model/Merchant.php b/app/common/model/Merchant.php index 2b73349d..c81cd519 100644 --- a/app/common/model/Merchant.php +++ b/app/common/model/Merchant.php @@ -84,13 +84,13 @@ class Merchant extends BaseModel * @return \think\Paginator * @throws \think\db\exception\DbException */ - public function getList(array $param = []): \think\Paginator + public function getList(array $param = [], int $pageSize = 15): \think\Paginator { $res = $this->with(['logoImage']) ->where($this->getFilter($param)) ->where('is_delete', '=', 0) ->order(['sort' => 'asc', $this->getPk()]) - ->paginate(15); + ->paginate($pageSize); return $res; } diff --git a/app/store/controller/Category.php b/app/store/controller/Category.php index f7c3c5c2..d3df33b2 100644 --- a/app/store/controller/Category.php +++ b/app/store/controller/Category.php @@ -59,7 +59,9 @@ class Category extends Controller { // 新增记录 $model = new CategoryModel; - if ($model->add($this->postForm())) { + $postform = $this->postForm(); + $postform['merchant_id'] = $this->merchantId; + if ($model->add($postform)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index f0faeba5..e02ee5ed 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -35,7 +35,7 @@ class Goods extends Controller $model = new GoodsModel; $params = $this->request->param(); $params['channel'] = 'zy'; - $params['merchant_id'] = $this->merchantId; + $params['merchantId'] = $this->merchantId; $list= $model->getList($params, (int)$this->request->param('pageSize', 15)); return $this->renderSuccess(compact('list')); }