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

- 在前置订单购物车信息列表中添加商品分类筛选功能
- 实现通过顶级分类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

@ -17,9 +17,10 @@ use app\common\model\store_product_unit\StoreProductUnit;
* Class BeforehandOrderCartInfoLists
* @package app\admin\listsbeforehand_order_cart_info
*/
class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{
public $list;
/**
* @notes 设置搜索条件
@ -46,28 +47,38 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
*/
public function lists(): array
{
return 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'])
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'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,unit')->withTrashed()->find();
$item->unit_name=StoreProductUnit::where('id',$find->unit)->value('name');
$item['warehouse_stock']=WarehouseProductStorege::where('product_id',$item['product_id'])->value('nums')??0;
$item['store_name']=$find['store_name'];
$item['image']=$find['image'];
$item['unit']=$find['unit'];
if($item->bhoid){
$status=PurchaseProductOffer::where('order_id',$item->bhoid)->where('product_id',$item->product_id)->value('status');
if($status==1){
$item->status_name='已完成';
}else{
$item->status_name='采购中';
->select()->each(function ($item) {
$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['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->value('nums') ?? 0;
$item['store_name'] = $find['store_name'];
$item['image'] = $find['image'];
$item['unit'] = $find['unit'];
$item['top_cate_id'] = $find['top_cate_id'];
if ($item->bhoid) {
$status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status');
if ($status == 1) {
$item->status_name = '已完成';
} else {
$item->status_name = '采购中';
}
}
return $item;
})
->toArray();
$this->list = $list;
return $list;
}
@ -82,7 +93,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
return BeforehandOrderCartInfo::where($this->searchWhere)->count();
}
/**
/**
* @notes 导出文件名
* @return string
* @author 乔峰
@ -102,7 +113,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
*/
public function setExcelFields(): array
{
$data=[
$data = [
'store_name' => '商品名称',
'warehouse_stock' => '仓库数量',
'cart_num' => '需求数量',

View File

@ -11,6 +11,7 @@ use app\common\logic\BaseLogic;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
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_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
@ -42,8 +43,8 @@ class BeforehandOrderLogic extends BaseLogic
public static function add(array $params): bool
{
$order_type=$params['order_type'] ?? 0;
if($order_type==4){
$order_type = $params['order_type'] ?? 0;
if ($order_type == 4) {
throw new BusinessException('不能添加线上订单,线上订单只能转换');
}
Db::startTrans();
@ -99,7 +100,7 @@ class BeforehandOrderLogic extends BaseLogic
public static function generateOrder(array $params): bool
{
$order = BeforehandOrder::where('id', $params['id'])->find();
if ($order['order_type']==4) {
if ($order['order_type'] == 4) {
throw new BusinessException('该订单类型不能生成支付订单');
}
Db::startTrans();
@ -331,7 +332,7 @@ class BeforehandOrderLogic extends BaseLogic
}
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
$order->save(['outbound_id' => $res['id'],'is_outbound'=>1]);
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1]);
Db::commit();
return true;
} catch (\Throwable $e) {
@ -353,8 +354,8 @@ class BeforehandOrderLogic extends BaseLogic
$datas = [];
$order = StoreOrder::where('id', $params['id'])->find();
$find=BeforehandOrder::where('order_sn',$order['order_id'])->find();
if($find){
$find = BeforehandOrder::where('order_sn', $order['order_id'])->find();
if ($find) {
throw new BusinessException('该订单已转成预定单,请勿重新转');
}
$info = StoreOrderCartInfo::where('oid', $params['id'])->select();
@ -406,10 +407,10 @@ class BeforehandOrderLogic extends BaseLogic
*/
public static function delete(array $params): bool
{
$res= BeforehandOrder::destroy($params['id']);
if($res){
BeforehandOrderCartInfo::where('bhoid',$params['id'])->update(['delete_time'=>time()]);
PurchaseProductOffer::where('order_id',$params['id'])->update(['delete_time'=>time()]);
$res = BeforehandOrder::destroy($params['id']);
if ($res) {
BeforehandOrderCartInfo::where('bhoid', $params['id'])->update(['delete_time' => time()]);
PurchaseProductOffer::where('order_id', $params['id'])->update(['delete_time' => time()]);
}
return $res;
}
@ -424,6 +425,15 @@ class BeforehandOrderLogic extends BaseLogic
*/
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;
}
}