添加创建采购单

This commit is contained in:
lewis 2025-02-05 17:44:31 +08:00
parent b0f38e5bcd
commit 405eebb642
3 changed files with 89 additions and 3 deletions

View File

@ -8,6 +8,7 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists;
use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; use app\admin\lists\beforehand_order\BeforehandOrderTwoLists;
use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; use app\admin\lists\beforehand_order\BeforehandOrderThreeLists;
use app\admin\logic\beforehand_order\BeforehandOrderLogic; use app\admin\logic\beforehand_order\BeforehandOrderLogic;
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
use app\common\model\beforehand_order\BeforehandOrder; 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 app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
@ -83,7 +84,11 @@ class BeforehandOrderController extends BaseAdminController
'regional_manager' => $params['regional_manager'] ?? '', 'regional_manager' => $params['regional_manager'] ?? '',
]; ];
$params['other_data'] = $other_data; $params['other_data'] = $other_data;
$result = BeforehandOrderLogic::add($params); if ($params['order_type'] == 7) {
PurchaseProductOfferLogic::batchCreate($params);
} else {
BeforehandOrderLogic::add($params);
}
return $this->success('添加成功', [], 1, 1); return $this->success('添加成功', [], 1, 1);
} }
/** /**

View File

@ -5,6 +5,9 @@ namespace app\admin\lists;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\finance\AccountsReceivable; use app\common\model\finance\AccountsReceivable;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use Illuminate\Contracts\Cache\Store;
/** /**
* AccountsReceivableLists * AccountsReceivableLists
@ -35,12 +38,21 @@ class AccountsReceivableLists extends BaseAdminDataLists implements ListsSearchI
$orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id');
$query->whereIn('order_id', $orderIds); $query->whereIn('order_id', $orderIds);
} }
return $query $list = $query->with('info')
->with('info')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->toArray(); ->toArray();
$stores = SystemStore::field('id,name')->whereIn('id', array_column($list, 'store_id'))->select()->toArray();
$stores = reset_index($stores, 'id');
$orderInfo = BeforehandOrder::field('id,order_id')->whereIn('id', array_column($list, 'order_id'))->select()->toArray();
$orderInfo = reset_index($orderInfo, 'id');
$orderInfo = reset_index($orderInfo, 'id');
foreach ($list as &$item) {
$item['store_name'] = $stores[$item['store_id']]['name'];
$item['order_sn'] = $orderInfo[$item['order_id']]['order_id'];
}
return $list;
} }
/** /**

View File

@ -488,4 +488,73 @@ class PurchaseProductOfferLogic extends BaseLogic
} }
return $res; return $res;
} }
public static function batchCreate($params)
{
if (empty($params['buyer_id'])) {
throw new BusinessException('请选择采购员');
}
Db::startTrans();
try {
$procurementOrder = new BeforehandOrder();
$procurementOrder->order_id = getNewOrderId('CG');
$procurementOrder->buyer_id = $params['buyer_id'];
$procurementOrder->admin_id = $params['admin_id'];
$procurementOrder->order_type = 7;
$procurementOrder->total_price = 0;
$procurementOrder->pay_price = 0;
$procurementOrder->save();
$purchaseOffer = [];
$cartInfo = [];
foreach ($params['product_arr'] as $product) {
if ($product['product_id'] <= 0) {
continue;
}
$cartInfo[] = [
'bhoid' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'unit' => $product['unit'],
'cart_num' => $product['nums'],
'accept_num' => $product['nums'],
'mark' => $product['mark'],
'is_buyer' => 1,
'procurement_order_id' => $procurementOrder['id'],
'total_price' => bcmul($product['price'], $product['nums'], 2),
'pay_price' => bcmul($product['price'], $product['nums'], 2),
'purchase' => $product['purchase'],
'uid' => $params['uid'],
'price' => $product['price'],
'package' => $product['package'],
'create_time' => time(),
'update_time' => time(),
];
$purchaseOffer[] = [
'order_id' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'unit' => $product['unit'],
'is_buyer' => 1,
'need_num' => $product['nums'],
'mark' => $product['mark'],
'buyer_id' => $params['buyer_id'],
'status' => 0,
'source_order_info' => [
[
'source_order_id' => $procurementOrder['id'],
'product_id' => $product['product_id'],
'need_num' => $product['nums'],
'mark' => $product['mark'],
]
]
];
}
PurchaseProductOffer::insertAll($purchaseOffer);
BeforehandOrderCartInfo::insertAll($cartInfo);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
} }