feature/main20240421
guojia 7 months ago
parent ec56168ce9
commit 833d38f0f3
  1. 16
      app/api/controller/Controller.php
  2. 17
      app/api/controller/Merchant.php
  3. 4
      app/common/model/Category.php
  4. 4
      app/common/model/Merchant.php
  5. 4
      app/store/controller/Category.php
  6. 2
      app/store/controller/Goods.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

@ -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);
}

@ -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)

@ -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;
}

@ -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() ?: '添加失败');

@ -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'));
}

Loading…
Cancel
Save