feat(ProductController, ProductLists): updated logic for product lists, added access control, fixed bugs, improved code quality

This commit is contained in:
mkm 2024-09-17 10:00:39 +08:00
parent c47825e2a2
commit c1a107886d
2 changed files with 28 additions and 14 deletions

View File

@ -1,20 +1,24 @@
<?php <?php
namespace app\api\controller\product; namespace app\api\controller\product;
use app\api\controller\BaseApiController; use app\api\controller\BaseApiController;
use app\api\lists\product\ProductLists; use app\api\lists\product\ProductLists;
use app\api\lists\product\ProductWholesaleLists; use app\api\lists\product\ProductWholesaleLists;
use app\api\lists\product\StoreProductLists; use app\api\lists\product\StoreProductLists;
use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User;
class ProductController extends BaseApiController
{
class ProductController extends BaseApiController{
public $notNeedLogin = ['lists']; public $notNeedLogin = ['lists'];
/** /**
* 商品列表 * 商品列表
*/ */
public function lists(){ public function lists()
{
return $this->dataLists(new ProductLists()); return $this->dataLists(new ProductLists());
} }
@ -22,29 +26,38 @@ class ProductController extends BaseApiController{
/** /**
* 批发商品列表 * 批发商品列表
*/ */
public function wholesale_lists(){ public function wholesale_lists()
{
if ($this->userId) {
$label_id = User::where('id', $this->userId)->value('label_id');
if ($label_id != 99) {
return $this->fail('您没有权限访问该列表');
}
} else {
return $this->fail('请登陆后访问');
}
return $this->dataLists(new ProductWholesaleLists()); return $this->dataLists(new ProductWholesaleLists());
} }
/** /**
* 商品列表 * 商品列表
*/ */
public function mer_list(){ public function mer_list()
$this->request->__set('store_id',$this->request->userInfo['store_id']??0); {
$this->request->__set('store_id', $this->request->userInfo['store_id'] ?? 0);
return $this->dataLists(new ProductLists()); return $this->dataLists(new ProductLists());
} }
/** /**
* 商品列表 * 商品列表
*/ */
public function store_lists(){ public function store_lists()
{
$store_id=SystemStoreStaff::where('uid',$this->userId)->where('is_admin',1)->value('store_id'); $store_id = SystemStoreStaff::where('uid', $this->userId)->where('is_admin', 1)->value('store_id');
if($store_id>0){ if ($store_id > 0) {
$this->request->__set('store_id',$store_id); $this->request->__set('store_id', $store_id);
return $this->dataLists(new StoreProductLists()); return $this->dataLists(new StoreProductLists());
}else{ } else {
return $this->data(['lists'=>[]]); return $this->data(['lists' => []]);
} }
} }
} }

View File

@ -109,6 +109,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
} }
$this->off_activity = $off_activity; $this->off_activity = $off_activity;
$this->searchWhere[] = ['is_show', '=', 1]; $this->searchWhere[] = ['is_show', '=', 1];
$this->searchWhere[] = ['product_type', 'in', [0,4]];
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
return StoreProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field($fields) ->field($fields)