Merge pull request 'dev' (#3) from dev into main

Reviewed-on: #3
This commit is contained in:
mkm 2024-06-19 17:41:06 +08:00
commit 5a27841a02
2 changed files with 51 additions and 76 deletions

View File

@ -12,7 +12,7 @@ class ProductController extends BaseApiController{
*/ */
public function lists(){ public function lists(){
return $this->dataLists(new ProductLists(),1); return $this->dataLists(new ProductLists());
} }
/** /**

View File

@ -18,7 +18,7 @@ use think\facade\Db;
* Class goods * Class goods
* @package app\api\goods * @package app\api\goods
*/ */
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,ListsSortInterface class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
{ {
@ -30,16 +30,16 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
*/ */
public function setSearch(): array public function setSearch(): array
{ {
$name=$this->request->get('store_name',''); $name = $this->request->get('store_name', '');
// $where['%pipe_like%'] =['name'=>'store_name|bar_code']; // $where['%pipe_like%'] =['name'=>'store_name|bar_code'];
if($name){ if ($name) {
if(preg_match('/[\x{4e00}-\x{9fff}]+/u', $name)==1){ if (preg_match('/[\x{4e00}-\x{9fff}]+/u', $name) == 1) {
$where['%like%']=['store_name'=>'store_name']; $where['%like%'] = ['store_name' => 'store_name'];
}else{ } else {
$where['=']=['bar_code','cate_id']; $where['='] = ['bar_code', 'cate_id'];
} }
}else{ } else {
$where['=']=['store_id','bar_code','cate_id']; $where['='] = ['store_id', 'bar_code', 'cate_id'];
} }
return $where; return $where;
@ -63,7 +63,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
*/ */
public function setDefaultOrder(): array public function setDefaultOrder(): array
{ {
return ['sales' => 'desc','price' => 'asc']; return ['sales' => 'desc', 'price' => 'asc'];
} }
/** /**
@ -79,7 +79,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
{ {
$found = false; $found = false;
if($this->searchWhere){ if ($this->searchWhere) {
foreach ($this->searchWhere as $subArray) { foreach ($this->searchWhere as $subArray) {
if (in_array('store_id', $subArray)) { if (in_array('store_id', $subArray)) {
$found = true; $found = true;
@ -87,50 +87,29 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
} }
} }
} }
if(!$found){ if (!$found) {
$store_id = DictType::where('type','store')->value('remark')??5; $store_id = DictType::where('type', 'store')->value('remark') ?? 5;
$this->searchWhere[]=['store_id','=',$store_id]; $this->searchWhere[] = ['store_id', '=', $store_id];
} }
$class_all=$this->request->get('class_all'); $class_all = $this->request->get('class_all');
$where=[]; if ($class_all) {
if($class_all){
//查3级别的 //查3级别的
$arr=Cate::where('pid',$class_all)->column('id'); $arr = Cate::where('pid', $class_all)->column('id');
if($arr){ if ($arr) {
$arr2=Cate::where('pid','in',$arr)->column('id'); $arr2 = Cate::where('pid', 'in', $arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)]; $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} }
} }
if(empty($where) && $class_all){
//2或者1
$where[]=['cate_id','=',$class_all];
}
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[]=['status','=',1]; $this->searchWhere[] = ['stock', '>', 0];
$this->searchWhere[]=['stock','>',0]; $data = StoreBranchProduct::where($this->searchWhere)
$M_store_id=$this->request->__get('store_id'); ->field(['id', 'product_id', 'cate_id', 'store_name', 'cost', 'store_id', 'price', 'bar_code', 'image', 'sales', 'store_info', 'delete_time', 'unit', 'batch'])
if($M_store_id){ ->limit($this->limitOffset, $this->limitLength)
$where[]=['store_id','=',$M_store_id]; ->with(['className', 'unitName'])
$data = StoreBranchProduct::where($this->searchWhere)->where($where) ->order($this->sortOrder)
->field(['id', 'product_id','cate_id','store_name', 'cost','store_id','price', 'bar_code','image','sales','store_info','delete_time','unit','batch']) ->select()?->toArray();
->limit($this->limitOffset, $this->limitLength) // $check = DictType::where('type','activities')->find();
->with(['className','unitName'])
->order($this->sortOrder)
->select()
->toArray();
}else{
$data = StoreBranchProduct::where($this->searchWhere)->where($where)
->field(['id', 'product_id','cate_id','store_name','cost', 'store_id','price', 'bar_code','image','sales','store_info','delete_time','unit','batch'])
->limit($this->limitOffset, $this->limitLength)
->with(['className','unitName'])
->order($this->sortOrder)
->select()
->toArray();
}
// $check = DictType::where('type','activities')->find();
// foreach ($data as &$value){ // foreach ($data as &$value){
// if(isset($check) && $check['status'] == 1){ // if(isset($check) && $check['status'] == 1){
// // $value['price'] = StoreProduct::where('id',$value['product_id'])->value('ot_price'); // // $value['price'] = StoreProduct::where('id',$value['product_id'])->value('ot_price');
@ -143,7 +122,6 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
// } // }
// } // }
return $data; return $data;
} }
@ -156,7 +134,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
public function count(): int public function count(): int
{ {
$found = false; $found = false;
if($this->searchWhere){ if ($this->searchWhere) {
foreach ($this->searchWhere as $subArray) { foreach ($this->searchWhere as $subArray) {
if (in_array('store_id', $subArray)) { if (in_array('store_id', $subArray)) {
$found = true; $found = true;
@ -164,37 +142,34 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
} }
} }
} }
if(!$found){ if (!$found) {
$store_id = DictType::where('type','store')->value('remark')??5; $store_id = DictType::where('type', 'store')->value('remark') ?? 5;
$this->searchWhere[]=['store_id','=',$store_id]; $this->searchWhere[] = ['store_id', '=', $store_id];
} }
$class_all=$this->request->get('class_all'); $class_all = $this->request->get('class_all');
$where=[]; $where = [];
if($class_all){ if ($class_all) {
$arr=Cate::where('pid',$class_all)->column('id'); $arr = Cate::where('pid', $class_all)->column('id');
if($arr){ if ($arr) {
$arr2=Cate::where('pid','in',$arr)->column('id'); $arr2 = Cate::where('pid', 'in', $arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)]; $where[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} }
} }
if(empty($where)&& $class_all){ if (empty($where) && $class_all) {
//2或者1 //2或者1
$where[]=['cate_id','=',$class_all]; $where[] = ['cate_id', '=', $class_all];
} }
$M_store_id=$this->request->__get('store_id'); $M_store_id = $this->request->__get('store_id');
$this->searchWhere[]=['status','=',1]; $this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[]=['stock','>',0]; $this->searchWhere[] = ['stock', '>', 0];
if($M_store_id){ if ($M_store_id) {
$where[]=['store_id','=',$M_store_id]; $where[] = ['store_id', '=', $M_store_id];
$data = StoreBranchProduct::where($this->searchWhere)->where($where) $data = StoreBranchProduct::where($this->searchWhere)->where($where)
->count(); ->count();
} else {
}else{ $data = StoreBranchProduct::where($this->searchWhere)->where($where)
$data =StoreBranchProduct::where($this->searchWhere)->where($where)
->count(); ->count();
} }
return $data; return $data;
} }
}
}