小程序分类修改表存储逻辑相关
This commit is contained in:
parent
eff3a9a2c6
commit
b95964cbaf
@ -6,6 +6,7 @@ namespace app\api\lists\cate;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\cate\Cate;
|
use app\common\model\cate\Cate;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
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
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$level = Request()->get('level', 1);
|
$level = Request()->get('level', 1);
|
||||||
$this->searchWhere[] = ['level', '=', $level];
|
$pid = $this->request->get('pid',0);
|
||||||
$this->searchWhere[] = ['count', '>', 0];
|
$this->searchWhere[] = ['stock', '>', 0];
|
||||||
$this->searchWhere[] = ['delete_time', '=', null];
|
$this->searchWhere[] = ['status', '=', 1];
|
||||||
$cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id');
|
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 = [];
|
$lists = [];
|
||||||
if ($cate_arr) {
|
if ($cate_arr) {
|
||||||
return Cate::where('id', 'in', $cate_arr)
|
return Cate::where('id', 'in', $cate_arr)
|
||||||
@ -56,18 +71,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||||
->select()->toArray();
|
->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 $lists;
|
||||||
// return linear_to_tree($lists, 'children');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +84,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
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)
|
if($pid && $level ==2){
|
||||||
->count();
|
$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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['store_id', 'cate_id'],
|
'=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'],
|
||||||
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
|
|
||||||
];
|
|
||||||
return [
|
|
||||||
'=' => ['store_id', 'cate_id'],
|
|
||||||
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
|
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @notes 设置支持排序字段
|
* @notes 设置支持排序字段
|
||||||
@ -74,17 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$class_all = $this->request->get('class_all');
|
// $class_all = $this->request->get('class_all');
|
||||||
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');
|
||||||
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
|
// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
|
||||||
} else {
|
// } else {
|
||||||
$this->searchWhere[] = ['cate_id', '=', $class_all];
|
// $this->searchWhere[] = ['cate_id', '=', $class_all];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
$order = $this->request->get('order','');
|
$order = $this->request->get('order','');
|
||||||
$field = $this->request->get('field','');
|
$field = $this->request->get('field','');
|
||||||
if(empty($order)||empty($field)){
|
if(empty($order)||empty($field)){
|
||||||
@ -92,7 +89,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
|
|||||||
}else{
|
}else{
|
||||||
$order = [$field => $order];
|
$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[] = ['status', '=', 1];
|
||||||
$this->searchWhere[] = ['stock', '>', 0];
|
$this->searchWhere[] = ['stock', '>', 0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user