feat(purchase): 一键添加往期采购商品功能

- 新增 AddPurchasesOneClick 方法实现一键添加往期采购商品
- 更新采购订单逻辑,支持往期补单采购
- 修改仓库产品逻辑,优化订单类型判断条件
- 调整订单列表显示,区分往期补单出库和入库
This commit is contained in:
mkm 2025-01-18 16:34:30 +08:00
parent 92de8b8ead
commit 4c918cca71
6 changed files with 141 additions and 69 deletions

View File

@ -42,9 +42,21 @@ class PurchaseProductOfferController extends BaseAdminController
$params['admin_id'] = $this->adminId;
$result = PurchaseProductOfferLogic::add($params);
return $this->success('设置成功', [], 1, 1);
}
/**
* @notes 一键添加往期采购商品
* @return \think\response\Json
* @author admin
* @date 2024/08/14 15:06
*/
public function add_purchases_one_click()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = PurchaseProductOfferLogic::AddPurchasesOneClick($params);
return $this->success('设置成功', [], 1, 1);
}
/**
* @notes 编辑采购商品

View File

@ -114,11 +114,13 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
$item->order_type_name = '仓库补货';
$item->outbound = '无须出库';
} elseif ($item->order_type == 6) {
$item->order_type_name = '往期补单';
$item->order_type_name = '往期补单-出库';
} elseif ($item->order_type == 7) {
$item->order_type_name = '采购订单';
} elseif ($item->order_type == 8) {
$item->order_type_name = '其他订单';
}elseif ($item->order_type == 9) {
$item->order_type_name = '往期补单-入库';
}
$item->msg = '';
$count1 = PurchaseProductOffer::where('order_id', $item->id)->where('buyer_confirm', 0)->count('id');

View File

@ -330,12 +330,16 @@ class BeforehandOrderLogic extends BaseLogic
try {
$find = BeforehandOrder::where('id', $params['id'])->find();
$other_data = $params['other_data'];
$find->save([
$data=[
'other_data' => json_encode($other_data, true),
'file' => $params['file'],
'store_id' => $params['store_id'],
'mark' => $params['mark']
]);
];
if(!empty($params['order_type']) && $params['order_type']>0){
$data['order_type'] = $params['order_type'];
}
$find->save($data);
Db::commit();
return true;
} catch (\Throwable $e) {

View File

@ -205,6 +205,7 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
$arr = [
'warehouse_id' => $params['warehouse_id'],
'supplier_id' => 0,
'order_type' => $beforehandOrder['order_type']??0,
'oid' => $beforehandOrder['id'],
'admin_id' => $params['admin_id'],
'financial_pm' => 1,
@ -217,16 +218,16 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
];
$res = WarehouseOrder::create($arr);
foreach ($offer_list as $k => $v) {
if (!empty($v['source_order_info'])) {
// 采购单来源于往期补单,需要减少对应订单的入库数量
$sourceOrderInfo = reset_index($v['source_order_info'], 'source_order_id');
$orders = BeforehandOrder::field('id,order_type')->whereIn('id', array_keys($sourceOrderInfo))->select()->toArray();
foreach ($orders as $order) {
if ($order['order_type'] == 6) {
$v['buyer_nums'] = $v['buyer_nums'] - $sourceOrderInfo[$order['id']]['need_num'];
}
}
}
// if (!empty($v['source_order_info'])) {
// // 采购单来源于往期补单,需要减少对应订单的入库数量
// $sourceOrderInfo = reset_index($v['source_order_info'], 'source_order_id');
// $orders = BeforehandOrder::field('id,order_type')->whereIn('id', array_keys($sourceOrderInfo))->select()->toArray();
// foreach ($orders as $order) {
// if ($order['order_type'] == 6) {
// $v['buyer_nums'] = $v['buyer_nums'] - $sourceOrderInfo[$order['id']]['need_num'];
// }
// }
// }
$data['admin_id'] = $params['admin_id'];
$data['order_type'] = $beforehandOrder['order_type'];
$data['store_id'] = 0;

View File

@ -107,7 +107,61 @@ class PurchaseProductOfferLogic extends BaseLogic
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 一键添加往期采购商品
* @param array $params
* @return bool
* @author admin
* @date 2024/08/14 15:06
*/
public static function AddPurchasesOneClick(array $params): bool
{
Db::startTrans();
try {
$arr=BeforehandOrderCartInfo::where('bhoid',$params['order_id'])->select();
$data_arr=[];
$procurementOrder = new BeforehandOrder();
$procurementOrder->order_id = getNewOrderId('CG');
$procurementOrder->buyer_id = $params['buyer_id'];
$procurementOrder->admin_id = $params['admin_id'];
$procurementOrder->order_type = 9;
$procurementOrder->total_price = 0;
$procurementOrder->pay_price = 0;
$procurementOrder->save();
foreach ($arr as $k=>$v){
$data_arr[]=[
'order_id' => $procurementOrder['id'],
'product_id' => $v['product_id'],
'unit' => $v['unit'],
'is_buyer' => $v['is_buyer'],
'need_num' => $v['cart_num'],
'buyer_id' => $params['buyer_id'],
'mark' => '往期补单采购',
'package' => '',
'store_info' => '',
'marques' => '',
'after_sales' => '',
'status' => 0,
'source_order_info' => [
[
'source_order_id' => $params['order_id'],
'product_id' => $v['product_id'],
'need_num' => $v['cart_num'],
'mark' => '往期补单采购',
]
]
];
}
(new PurchaseProductOffer())->saveAll($data_arr);
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id']])->update(['is_buyer' => 1, 'procurement_order_id' => $procurementOrder['id']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑采购商品
@ -461,5 +515,4 @@ class PurchaseProductOfferLogic extends BaseLogic
}
return $res;
}
}

View File

@ -38,7 +38,7 @@ class WarehouseProductLogic extends BaseLogic
// Db::startTrans();
try {
$after_nums = 0;
if ($params['order_type'] != 6) {
if (!in_array($params['order_type'],[6,7,9])) {
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
$after_nums = $storege['nums'] + $params['nums'];