diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 1dbb0f96..23295ae4 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -8,6 +8,7 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists; use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; 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_cart_info\BeforehandOrderCartInfo; use app\common\model\store_order\StoreOrder; @@ -83,7 +84,11 @@ class BeforehandOrderController extends BaseAdminController 'regional_manager' => $params['regional_manager'] ?? '', ]; $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); } /** diff --git a/app/admin/lists/AccountsReceivableLists.php b/app/admin/lists/AccountsReceivableLists.php index 16a6b70f..6634da2f 100644 --- a/app/admin/lists/AccountsReceivableLists.php +++ b/app/admin/lists/AccountsReceivableLists.php @@ -5,6 +5,9 @@ namespace app\admin\lists; use app\common\lists\ListsSearchInterface; use app\common\model\beforehand_order\BeforehandOrder; 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 @@ -35,12 +38,21 @@ class AccountsReceivableLists extends BaseAdminDataLists implements ListsSearchI $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); $query->whereIn('order_id', $orderIds); } - return $query - ->with('info') + $list = $query->with('info') ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->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; } /** diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 44d94db5..1a06454e 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -488,4 +488,73 @@ class PurchaseProductOfferLogic extends BaseLogic } 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()); + } + } + }