refactor(admin): 优化商品列表搜索和展示逻辑
- 调整搜索条件数组格式 - 修复商品类型切换后的活动价显示问题 - 优化商品列表的数据处理逻辑 - 美化代码格式,统一代码风格
This commit is contained in:
parent
6b44bc45ed
commit
07fb90ca8b
@ -35,7 +35,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['cate_id', 'is_show', 'bar_code','id'],
|
||||
'=' => ['cate_id', 'is_show', 'bar_code', 'id'],
|
||||
'in' => ['product_type'],
|
||||
'<=' => ['stock'],
|
||||
'%like%' => ['store_name'],
|
||||
@ -65,8 +65,8 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$this->searchWhere[] = ['cate_id', '=', $class_all];
|
||||
}
|
||||
}
|
||||
$is_warehouse=$this->request->get('is_warehouse',0);
|
||||
$order_type=$this->request->get('order_type',0);
|
||||
$is_warehouse = $this->request->get('is_warehouse', 0);
|
||||
$order_type = $this->request->get('order_type', 0);
|
||||
$userShip = 0;
|
||||
if (!empty($this->params['user_id'])) {
|
||||
$userShip = User::where('id', $this->params['user_id'])->value('user_ship');
|
||||
@ -86,9 +86,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id');
|
||||
$query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds);
|
||||
}
|
||||
$storeId = $this->params['store_id'] ?? 0;
|
||||
$is_true = true;
|
||||
if ($storeId > 0) {
|
||||
$is_true = SystemStore::isSelfOperate($storeId);
|
||||
}
|
||||
$list = $query->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) use($is_warehouse, $userShip,$order_type) {
|
||||
->select()->each(function ($item) use ($is_warehouse, $userShip, $order_type, $is_true) {
|
||||
$item['product_id'] = $item['id'];
|
||||
$item['bar_code_two'] = '';
|
||||
if (in_array($item['unit'], [2, 21])) {
|
||||
@ -106,7 +111,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$item['bar_code'] = '';
|
||||
}
|
||||
}
|
||||
switch($item['product_type']){
|
||||
switch ($item['product_type']) {
|
||||
case 2:
|
||||
$item['product_type_name'] = '兑换产品';
|
||||
break;
|
||||
@ -119,7 +124,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
case 5:
|
||||
$item['product_type_name'] = '批发产品';
|
||||
break;
|
||||
case 6:
|
||||
case 6:
|
||||
$item['product_type_name'] = '零采商品';
|
||||
break;
|
||||
default:
|
||||
@ -127,36 +132,36 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
}
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
||||
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
|
||||
$category = StoreCategory::where('id','in',[$item['top_cate_id'],$item['two_cate_id'],$item['cate_id']])->column('name');
|
||||
$item['cate_name'] =implode('/', $category);
|
||||
if($is_warehouse==1){
|
||||
$category = StoreCategory::where('id', 'in', [$item['top_cate_id'], $item['two_cate_id'], $item['cate_id']])->column('name');
|
||||
$item['cate_name'] = implode('/', $category);
|
||||
if ($is_warehouse == 1) {
|
||||
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
}else{
|
||||
} else {
|
||||
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
$item['stock'] = bcadd($nums, $stock);
|
||||
}
|
||||
if ($userShip == 4) {
|
||||
$item['price'] = $item['cost'];
|
||||
}
|
||||
if($item['is_show']==1){
|
||||
$item['status_msg']='上架|常用';
|
||||
}else{
|
||||
$item['status_msg']='下架|不常用|是否有替换';
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['status_msg'] = '上架|常用';
|
||||
} else {
|
||||
$item['status_msg'] = '下架|不常用|是否有替换';
|
||||
}
|
||||
if ($order_type == 2) {
|
||||
$price=StoreProductGroupPrice::where('group_id', 42)->where('product_id', $item['product_id'])->value('price');
|
||||
if($price>0){
|
||||
if ($order_type == 2 && $is_true == false) {
|
||||
$price = StoreProductGroupPrice::where('group_id', 42)->where('product_id', $item['product_id'])->value('price');
|
||||
if ($price > 0) {
|
||||
$item['price'] = $price;
|
||||
$item['store_name'] = $item['store_name'].'|活动价';
|
||||
$item['store_name'] = $item['store_name'] . '|活动价';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $item;
|
||||
})?->toArray();
|
||||
if ($userShip > 0 && $userShip != 4) {
|
||||
$list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
|
||||
}
|
||||
// if ($userShip > 0 && $userShip != 4) {
|
||||
// $list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
|
||||
// }
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user