feat(purchase): 一键添加往期采购商品功能
- 新增 AddPurchasesOneClick 方法实现一键添加往期采购商品 - 更新采购订单逻辑,支持往期补单采购 - 修改仓库产品逻辑,优化订单类型判断条件 - 调整订单列表显示,区分往期补单出库和入库
This commit is contained in:
parent
92de8b8ead
commit
4c918cca71
@ -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 编辑采购商品
|
||||
|
@ -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');
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -60,7 +60,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
if ($mark == '') {
|
||||
$mark = BeforehandOrderCartInfo::where('bhoid', $params['order_id'])->where('product_id', $params['product_id'])->value('mark');
|
||||
}
|
||||
$find=StoreProduct::where('id',$params['product_id'])->find();
|
||||
$find = StoreProduct::where('id', $params['product_id'])->find();
|
||||
$purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find();
|
||||
if ($purchaseProductOffer) {
|
||||
$purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num'];
|
||||
@ -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 编辑采购商品
|
||||
@ -182,53 +236,53 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
]);
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
$unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name');
|
||||
$unit_name = StoreProductUnit::where('id', $offer['unit'])->value('name');
|
||||
$order = BeforehandOrder::where('id', $params['bhoid'])->find();
|
||||
$order->pay_price = PurchaseProductOffer::where('order_id', $order['id'])->sum('total_price');
|
||||
$order->total_price = $order->pay_price;
|
||||
$order->save();
|
||||
self::setProductGroupPrice($params, $product);
|
||||
// $data = [];
|
||||
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
// $data['bhoid'] = $offer['order_id'];
|
||||
// $data['offer_id'] = $params['id'];
|
||||
// $data['product_id'] = $offer['product_id'];
|
||||
// $data['purchase_price'] = $params['purchase'];
|
||||
// $data['status'] = 0;
|
||||
// if ($dict_data) {
|
||||
// foreach ($dict_data as $k => $v) {
|
||||
// if ($v['name'] == 'purchase') {
|
||||
// $data['purchase_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'cost') {
|
||||
// $data['cost_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'price') {
|
||||
// $data['price_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ($find) {
|
||||
// $find->save($data);
|
||||
// } else {
|
||||
// StoreProductPrice::create($data);
|
||||
// }
|
||||
// $data = [];
|
||||
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
// $data['bhoid'] = $offer['order_id'];
|
||||
// $data['offer_id'] = $params['id'];
|
||||
// $data['product_id'] = $offer['product_id'];
|
||||
// $data['purchase_price'] = $params['purchase'];
|
||||
// $data['status'] = 0;
|
||||
// if ($dict_data) {
|
||||
// foreach ($dict_data as $k => $v) {
|
||||
// if ($v['name'] == 'purchase') {
|
||||
// $data['purchase_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'cost') {
|
||||
// $data['cost_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'price') {
|
||||
// $data['price_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ($find) {
|
||||
// $find->save($data);
|
||||
// } else {
|
||||
// StoreProductPrice::create($data);
|
||||
// }
|
||||
Db::commit();
|
||||
$offer['store_name']=$product['store_name'];
|
||||
$offer['unit_name']=$unit_name;
|
||||
$offer['buyer_name']=DeliveryService::where('uid',$offer['buyer_id'])->value('nickname');
|
||||
if($offer['pay_type']==1){
|
||||
$offer['pay_type_name']='赊账';
|
||||
}elseif($offer['pay_type']==2){
|
||||
$offer['pay_type_name']='现金';
|
||||
}else{
|
||||
$offer['pay_type_name']='没设置';
|
||||
$offer['store_name'] = $product['store_name'];
|
||||
$offer['unit_name'] = $unit_name;
|
||||
$offer['buyer_name'] = DeliveryService::where('uid', $offer['buyer_id'])->value('nickname');
|
||||
if ($offer['pay_type'] == 1) {
|
||||
$offer['pay_type_name'] = '赊账';
|
||||
} elseif ($offer['pay_type'] == 2) {
|
||||
$offer['pay_type_name'] = '现金';
|
||||
} else {
|
||||
$offer['pay_type_name'] = '没设置';
|
||||
}
|
||||
ProductOffer::push($offer);
|
||||
return true;
|
||||
@ -283,19 +337,19 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
PurchaseProductOffer::where('id', $params['id'])->update(['is_accept' => 1]);
|
||||
$find=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->find();
|
||||
$data=[
|
||||
$find = BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->find();
|
||||
$data = [
|
||||
'gross_weight' => $params['gross_weight'] ?? 0,
|
||||
'net_weight' => $params['net_weight'] ?? 0,
|
||||
'accept_num' => $params['accept_num'] ?? 0,
|
||||
];
|
||||
if($params['accept_num']!=$find['cart_num']){
|
||||
$pay_price=bcmul($params['accept_num'], $find['price'], 2);
|
||||
$data['pay_price']=$pay_price;
|
||||
if ($params['accept_num'] != $find['cart_num']) {
|
||||
$pay_price = bcmul($params['accept_num'], $find['price'], 2);
|
||||
$data['pay_price'] = $pay_price;
|
||||
}
|
||||
$find->save($data);
|
||||
if($params['accept_num']!=$find['cart_num']){
|
||||
$pay_price=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price');
|
||||
if ($params['accept_num'] != $find['cart_num']) {
|
||||
$pay_price = BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price');
|
||||
BeforehandOrder::where('id', $params['bhoid'])->update(['pay_price' => $pay_price]);
|
||||
}
|
||||
Db::commit();
|
||||
@ -368,13 +422,13 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
if (!empty($productCatePriceRate)) {
|
||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||
$purchase=0;
|
||||
$purchase = 0;
|
||||
foreach ($productCatePriceRate as $k => $v) {
|
||||
if ($v['id'] == 100001 || $v['id'] == 21) {
|
||||
//供货
|
||||
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
|
||||
$purchase=$data['purchase'];
|
||||
$purchase = $data['purchase'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -383,12 +437,12 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
if (empty($v['rate'])) {
|
||||
continue;
|
||||
}
|
||||
if ($v['id'] == 4 &&$purchase>0) {
|
||||
if ($v['id'] == 4 && $purchase > 0) {
|
||||
//商户
|
||||
$data['cost_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['cost'] = bcmul($purchase, bcadd($data['cost_lv'], 1, 2), 2);
|
||||
continue;
|
||||
}elseif (($v['id'] == 100002 || $v['id'] == 22) &&$purchase>0) {
|
||||
} elseif (($v['id'] == 100002 || $v['id'] == 22) && $purchase > 0) {
|
||||
//零售
|
||||
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['price'] = bcmul($purchase, bcadd($data['price_lv'], 1, 2), 1);
|
||||
@ -405,7 +459,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
continue;
|
||||
}
|
||||
$baseRate = ($v['id'] == 100001 || $v['id'] == 21) ? 100 : 100 + $v['rate'];
|
||||
if($purchase>0){
|
||||
if ($purchase > 0) {
|
||||
$item = [
|
||||
'product_id' => $product['id'],
|
||||
'group_id' => $v['id'],
|
||||
@ -461,5 +515,4 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user