新增前置订单商品分类筛选功能

- 在前置订单购物车信息列表中添加商品分类筛选功能
- 实现通过顶级分类ID筛选商品的逻辑
- 优化订单生成和删除操作的处理
- 在订单详情中添加商品分类信息
This commit is contained in:
mkm 2024-10-14 21:58:33 +08:00
parent f16a694b72
commit d838e01c43
2 changed files with 50 additions and 29 deletions

View File

@ -20,6 +20,7 @@ use app\common\model\store_product_unit\StoreProductUnit;
class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{ {
public $list;
/** /**
* @notes 设置搜索条件 * @notes 设置搜索条件
@ -46,17 +47,25 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
*/ */
public function lists(): array public function lists(): array
{ {
return BeforehandOrderCartInfo::where($this->searchWhere) if($this->request->get('top_cate')){
$product_id=BeforehandOrderCartInfo::where($this->searchWhere)->column('product_id');
$ids=StoreProduct::where('id', 'in', $product_id)->where('top_cate_id',$this->request->get('top_cate'))->column('id');
if($ids){
$this->searchWhere[] = ['product_id','in',$ids];
}
}
$list = BeforehandOrderCartInfo::where($this->searchWhere)
->field(['id', 'bhoid', 'uid', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num', 'mark']) ->field(['id', 'bhoid', 'uid', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num', 'mark'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,unit')->withTrashed()->find(); $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,image,unit')->withTrashed()->find();
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name'); $item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
$item['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->value('nums') ?? 0; $item['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->value('nums') ?? 0;
$item['store_name'] = $find['store_name']; $item['store_name'] = $find['store_name'];
$item['image'] = $find['image']; $item['image'] = $find['image'];
$item['unit'] = $find['unit']; $item['unit'] = $find['unit'];
$item['top_cate_id'] = $find['top_cate_id'];
if ($item->bhoid) { if ($item->bhoid) {
$status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status'); $status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status');
if ($status == 1) { if ($status == 1) {
@ -68,6 +77,8 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
return $item; return $item;
}) })
->toArray(); ->toArray();
$this->list = $list;
return $list;
} }

View File

@ -11,6 +11,7 @@ use app\common\logic\BaseLogic;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
@ -424,6 +425,15 @@ class BeforehandOrderLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
return BeforehandOrder::findOrEmpty($params['id'])->toArray(); $res = BeforehandOrder::findOrEmpty($params['id'])->toArray();
$ids = BeforehandOrderCartInfo::where('bhoid', $params['id'])->column('product_id');
$top_cate_ids = StoreProduct::where('id', 'in', $ids)->column('top_cate_id');
if ($top_cate_ids) {
$top_cate_list = array_unique($top_cate_ids);
$arr = StoreCategory::where('id', 'in', $top_cate_list)->field('name,id')->select();
$res['top_cate'] = $arr?->toArray();
}
return $res;
} }
} }