feat: 商品列表API添加店铺商品功能
This commit is contained in:
parent
f3e83cda79
commit
2601a18a6b
@ -3,7 +3,8 @@
|
||||
namespace app\api\controller\product;
|
||||
use app\api\controller\BaseApiController;
|
||||
use app\api\lists\product\ProductLists;
|
||||
|
||||
use app\api\lists\product\StoreProductLists;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
|
||||
class ProductController extends BaseApiController{
|
||||
public $notNeedLogin = ['lists'];
|
||||
@ -22,5 +23,18 @@ class ProductController extends BaseApiController{
|
||||
$this->request->__set('store_id',$this->request->userInfo['store_id']??0);
|
||||
return $this->dataLists(new ProductLists());
|
||||
}
|
||||
/**
|
||||
* 商品列表
|
||||
*/
|
||||
public function store_lists(){
|
||||
|
||||
$store_id=SystemStoreStaff::where('uid',$this->userId)->where('is_admin',1)->value('store_id');
|
||||
if($store_id>0){
|
||||
$this->request->__set('store_id',$store_id);
|
||||
return $this->dataLists(new StoreProductLists());
|
||||
}else{
|
||||
return $this->dataLists();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -81,6 +81,11 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
}
|
||||
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
|
||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||
if($off_activity==1){
|
||||
$tag='赠10%品牌礼品券';
|
||||
}else{
|
||||
$tag='';
|
||||
}
|
||||
$uid=0;
|
||||
if($this->request->get('uid',0)>0){
|
||||
$uid=$this->request->get('uid',0);
|
||||
@ -102,8 +107,8 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order($order)
|
||||
// ->page($this->limitOffset +1,$this->limitLength)
|
||||
->select()->each(function ($item) {
|
||||
$item['tag']=' 赠10%品牌礼品券 ';
|
||||
->select()->each(function ($item) use($tag){
|
||||
$item['tag']=$tag;
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
|
111
app/api/lists/product/StoreProductLists.php
Normal file
111
app/api/lists/product/StoreProductLists.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\lists\product;
|
||||
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSortInterface;
|
||||
use app\common\model\dict\DictType;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\cate\Cate;
|
||||
use app\common\model\Config;
|
||||
use app\common\model\user\User;
|
||||
//use app\common\model\goods\GoodsLabel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 商品列表列表
|
||||
* Class goods
|
||||
* @package app\api\goods
|
||||
*/
|
||||
class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface, ListsSortInterface
|
||||
{
|
||||
protected $off_activity = 0;
|
||||
protected $user_ship = 0;
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/04/23 11:28
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
// '=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'],
|
||||
'%like%' => ['store_name' => 'store_name'],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @notes 设置支持排序字段
|
||||
* @return string[]
|
||||
* @date 2021/12/29 10:07
|
||||
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
|
||||
*/
|
||||
public function setSortFields(): array
|
||||
{
|
||||
return ['sell' => 'price', 'sales' => 'sales',];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置默认排序
|
||||
* @return string[]
|
||||
* @date 2021/12/29 10:06
|
||||
*/
|
||||
public function setDefaultOrder(): array
|
||||
{
|
||||
return ['price' => 'asc', 'id' => 'desc'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取商品列表列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/04/23 11:28
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$store_id= $this->request->__get('store_id');
|
||||
if($store_id){
|
||||
$this->searchWhere[] = ['store_id', '=', $store_id];
|
||||
}
|
||||
|
||||
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
|
||||
$type=$this->request->get('type',0);
|
||||
if($type==1){
|
||||
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
|
||||
}elseif($type==2){
|
||||
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,vip_price price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
|
||||
}
|
||||
$this->searchWhere[] = ['status', '=', 1];
|
||||
|
||||
// $this->searchWhere[] = ['stock', '>', 0];
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
->field($fields)
|
||||
->with(['className', 'unitName'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order('id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品列表数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/04/23 11:28
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
->count();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user