Merge pull request 'dev' (#267) from dev into main

Reviewed-on: #267
This commit is contained in:
mkm 2024-10-14 21:59:09 +08:00
commit 803c76f7c0
3 changed files with 56 additions and 30 deletions

View File

@ -17,9 +17,10 @@ use app\common\model\store_product_unit\StoreProductUnit;
* Class BeforehandOrderCartInfoLists * Class BeforehandOrderCartInfoLists
* @package app\admin\listsbeforehand_order_cart_info * @package app\admin\listsbeforehand_order_cart_info
*/ */
class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{ {
public $list;
/** /**
* @notes 设置搜索条件 * @notes 设置搜索条件
@ -46,28 +47,38 @@ 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')){
->field(['id', 'bhoid', 'uid', 'is_buyer','buyer_uid','product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num','mark']) $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) ->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'];
if($item->bhoid){ $item['top_cate_id'] = $find['top_cate_id'];
$status=PurchaseProductOffer::where('order_id',$item->bhoid)->where('product_id',$item->product_id)->value('status'); if ($item->bhoid) {
if($status==1){ $status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status');
$item->status_name='已完成'; if ($status == 1) {
}else{ $item->status_name = '已完成';
$item->status_name='采购中'; } else {
$item->status_name = '采购中';
} }
} }
return $item; return $item;
}) })
->toArray(); ->toArray();
$this->list = $list;
return $list;
} }
@ -82,7 +93,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
return BeforehandOrderCartInfo::where($this->searchWhere)->count(); return BeforehandOrderCartInfo::where($this->searchWhere)->count();
} }
/** /**
* @notes 导出文件名 * @notes 导出文件名
* @return string * @return string
* @author 乔峰 * @author 乔峰
@ -102,7 +113,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
*/ */
public function setExcelFields(): array public function setExcelFields(): array
{ {
$data=[ $data = [
'store_name' => '商品名称', 'store_name' => '商品名称',
'warehouse_stock' => '仓库数量', 'warehouse_stock' => '仓库数量',
'cart_num' => '需求数量', '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\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;
@ -42,8 +43,8 @@ class BeforehandOrderLogic extends BaseLogic
public static function add(array $params): bool public static function add(array $params): bool
{ {
$order_type=$params['order_type'] ?? 0; $order_type = $params['order_type'] ?? 0;
if($order_type==4){ if ($order_type == 4) {
throw new BusinessException('不能添加线上订单,线上订单只能转换'); throw new BusinessException('不能添加线上订单,线上订单只能转换');
} }
Db::startTrans(); Db::startTrans();
@ -99,7 +100,7 @@ class BeforehandOrderLogic extends BaseLogic
public static function generateOrder(array $params): bool public static function generateOrder(array $params): bool
{ {
$order = BeforehandOrder::where('id', $params['id'])->find(); $order = BeforehandOrder::where('id', $params['id'])->find();
if ($order['order_type']==4) { if ($order['order_type'] == 4) {
throw new BusinessException('该订单类型不能生成支付订单'); throw new BusinessException('该订单类型不能生成支付订单');
} }
Db::startTrans(); 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(); $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']]); 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(); Db::commit();
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
@ -353,8 +354,8 @@ class BeforehandOrderLogic extends BaseLogic
$datas = []; $datas = [];
$order = StoreOrder::where('id', $params['id'])->find(); $order = StoreOrder::where('id', $params['id'])->find();
$find=BeforehandOrder::where('order_sn',$order['order_id'])->find(); $find = BeforehandOrder::where('order_sn', $order['order_id'])->find();
if($find){ if ($find) {
throw new BusinessException('该订单已转成预定单,请勿重新转'); throw new BusinessException('该订单已转成预定单,请勿重新转');
} }
$info = StoreOrderCartInfo::where('oid', $params['id'])->select(); $info = StoreOrderCartInfo::where('oid', $params['id'])->select();
@ -406,10 +407,10 @@ class BeforehandOrderLogic extends BaseLogic
*/ */
public static function delete(array $params): bool public static function delete(array $params): bool
{ {
$res= BeforehandOrder::destroy($params['id']); $res = BeforehandOrder::destroy($params['id']);
if($res){ if ($res) {
BeforehandOrderCartInfo::where('bhoid',$params['id'])->update(['delete_time'=>time()]); BeforehandOrderCartInfo::where('bhoid', $params['id'])->update(['delete_time' => time()]);
PurchaseProductOffer::where('order_id',$params['id'])->update(['delete_time'=>time()]); PurchaseProductOffer::where('order_id', $params['id'])->update(['delete_time' => time()]);
} }
return $res; return $res;
} }
@ -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;
} }
} }

View File

@ -5,6 +5,7 @@ namespace app\admin\logic\purchase_product_offer;
use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use support\exception\BusinessException; use support\exception\BusinessException;
use think\facade\Db; use think\facade\Db;
@ -30,13 +31,17 @@ class PurchaseProductOfferLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$mark=$params['mark'] ?? '';
if($mark==''){
$mark=BeforehandOrderCartInfo::where('bhoid',$params['order_id'])->where('product_id',$params['product_id'])->value('mark');
}
PurchaseProductOffer::create([ PurchaseProductOffer::create([
'order_id' => $params['order_id'], 'order_id' => $params['order_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'unit' => $params['unit'], 'unit' => $params['unit'],
'is_buyer' => $params['is_buyer'], 'is_buyer' => $params['is_buyer'],
'need_num' => $params['need_num'], 'need_num' => $params['need_num'],
'mark' => $params['mark'] ?? '', 'mark' => $mark,
'buyer_id' => $params['buyer_id'], 'buyer_id' => $params['buyer_id'],
'status' => 0, 'status' => 0,