小程序分类修改表存储逻辑相关

This commit is contained in:
liu 2024-06-27 15:26:34 +08:00
parent eff3a9a2c6
commit b95964cbaf
2 changed files with 52 additions and 35 deletions

View File

@ -6,6 +6,7 @@ namespace app\api\lists\cate;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\Request;
use think\facade\Db;
@ -27,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['name', 'data', 'store_id', 'sort', 'pid'],
'=' => ['name', 'data', 'store_id', 'sort'],
];
}
@ -44,10 +45,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
$level = Request()->get('level', 1);
$this->searchWhere[] = ['level', '=', $level];
$this->searchWhere[] = ['count', '>', 0];
$this->searchWhere[] = ['delete_time', '=', null];
$cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id');
$pid = $this->request->get('pid',0);
$this->searchWhere[] = ['stock', '>', 0];
$this->searchWhere[] = ['status', '=', 1];
if($pid == 0 && $level ==1){
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('top_cate_id');
}
if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('two_cate_id');
}
if($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('cate_id');
}
$lists = [];
if ($cate_arr) {
return Cate::where('id', 'in', $cate_arr)
@ -56,18 +71,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->toArray();
}
// ->each(function ($item) {
// $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $item['children'] = $a;
// foreach ($a as $k => &$v) {
// $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $v['children'] = $b;
// }
// })->toArray();
return $lists;
// return linear_to_tree($lists, 'children');
}
@ -80,8 +84,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
$level = Request()->get('level', 1);
$pid = $this->request->get('pid',0);
if($pid == 0 && $level ==1){
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('top_cate_id');
}
return Db::name('store_product_cate')->where($this->searchWhere)
->count();
if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('two_cate_id');
}
if($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
->column('cate_id');
}
return Cate::where('id', 'in', $cate_arr)->count();
}
}

View File

@ -33,13 +33,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
public function setSearch(): array
{
return [
'=' => ['store_id', 'cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
return [
'=' => ['store_id', 'cate_id'],
'=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
}
/**
* @notes 设置支持排序字段
@ -74,17 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function lists(): array
{
$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');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} else {
$this->searchWhere[] = ['cate_id', '=', $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');
// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
// } else {
// $this->searchWhere[] = ['cate_id', '=', $class_all];
// }
// }
$order = $this->request->get('order','');
$field = $this->request->get('field','');
if(empty($order)||empty($field)){
@ -92,7 +89,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
}else{
$order = [$field => $order];
}
$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';
$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';
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];