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(){
return $this->dataLists(new ProductLists(),1);
return $this->dataLists(new ProductLists());
}
/**

View File

@ -18,7 +18,7 @@ use think\facade\Db;
* Class 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
{
$name=$this->request->get('store_name','');
$name = $this->request->get('store_name', '');
// $where['%pipe_like%'] =['name'=>'store_name|bar_code'];
if($name){
if(preg_match('/[\x{4e00}-\x{9fff}]+/u', $name)==1){
$where['%like%']=['store_name'=>'store_name'];
}else{
$where['=']=['bar_code','cate_id'];
if ($name) {
if (preg_match('/[\x{4e00}-\x{9fff}]+/u', $name) == 1) {
$where['%like%'] = ['store_name' => 'store_name'];
} else {
$where['='] = ['bar_code', 'cate_id'];
}
}else{
$where['=']=['store_id','bar_code','cate_id'];
} else {
$where['='] = ['store_id', 'bar_code', 'cate_id'];
}
return $where;
@ -63,7 +63,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
*/
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;
if($this->searchWhere){
if ($this->searchWhere) {
foreach ($this->searchWhere as $subArray) {
if (in_array('store_id', $subArray)) {
$found = true;
@ -87,50 +87,29 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
}
}
}
if(!$found){
$store_id = DictType::where('type','store')->value('remark')??5;
$this->searchWhere[]=['store_id','=',$store_id];
if (!$found) {
$store_id = DictType::where('type', 'store')->value('remark') ?? 5;
$this->searchWhere[] = ['store_id', '=', $store_id];
}
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$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[]=['stock','>',0];
$M_store_id=$this->request->__get('store_id');
if($M_store_id){
$where[]=['store_id','=',$M_store_id];
$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();
}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();
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];
$data = StoreBranchProduct::where($this->searchWhere)
->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){
// if(isset($check) && $check['status'] == 1){
// // $value['price'] = StoreProduct::where('id',$value['product_id'])->value('ot_price');
@ -143,7 +122,6 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
// }
// }
return $data;
}
@ -156,7 +134,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
public function count(): int
{
$found = false;
if($this->searchWhere){
if ($this->searchWhere) {
foreach ($this->searchWhere as $subArray) {
if (in_array('store_id', $subArray)) {
$found = true;
@ -164,37 +142,34 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface,Li
}
}
}
if(!$found){
$store_id = DictType::where('type','store')->value('remark')??5;
$this->searchWhere[]=['store_id','=',$store_id];
if (!$found) {
$store_id = DictType::where('type', 'store')->value('remark') ?? 5;
$this->searchWhere[] = ['store_id', '=', $store_id];
}
$class_all=$this->request->get('class_all');
$where=[];
if($class_all){
$arr=Cate::where('pid',$class_all)->column('id');
if($arr){
$arr2=Cate::where('pid','in',$arr)->column('id');
$where[]=['cate_id','in',array_merge($arr,$arr2)];
$class_all = $this->request->get('class_all');
$where = [];
if ($class_all) {
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$where[] = ['cate_id', 'in', array_merge($arr, $arr2)];
}
}
if(empty($where)&& $class_all){
if (empty($where) && $class_all) {
//2或者1
$where[]=['cate_id','=',$class_all];
$where[] = ['cate_id', '=', $class_all];
}
$M_store_id=$this->request->__get('store_id');
$this->searchWhere[]=['status','=',1];
$this->searchWhere[]=['stock','>',0];
if($M_store_id){
$where[]=['store_id','=',$M_store_id];
$M_store_id = $this->request->__get('store_id');
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];
if ($M_store_id) {
$where[] = ['store_id', '=', $M_store_id];
$data = StoreBranchProduct::where($this->searchWhere)->where($where)
->count();
}else{
$data =StoreBranchProduct::where($this->searchWhere)->where($where)
} else {
$data = StoreBranchProduct::where($this->searchWhere)->where($where)
->count();
}
return $data;
}
}
}