diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 25cdf8eca..41e0ecc69 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -183,4 +183,12 @@ class BeforehandOrderCartInfoController extends BaseAdminController return $this->success('操作成功', [], 1, 1); } + public function putInStorage() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + BeforehandOrderCartInfoLogic::putInStorage($params); + return $this->success('操作成功', [], 1, 1); + } + } \ No newline at end of file diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php index d08c2a69e..128a9dc9e 100644 --- a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -345,4 +345,92 @@ class BeforehandOrderCartInfoLogic extends BaseLogic BeforehandOrderCartInfo::where('id', $params['id'])->update($update); } + public static function putInStorage($params) + { + if ($params['warehouse_id'] <= 0 || $params['warehouse_id'] == '') { + throw new BusinessException('请选择入库仓库'); + } + $purchaseProductOffer = PurchaseProductOffer::where('id', $params['id'])->find(); + if (empty($purchaseProductOffer) || $params['buyer_nums'] == 0) { + throw new BusinessException('请先设置采购信息再入库'); + } + if ($purchaseProductOffer['is_storage'] == 1) { + throw new BusinessException('商品已入库'); + } + $beforehandOrder = BeforehandOrder::where('id', $params['bhoid'])->field('id,order_type,warehousing_id')->find(); + + $completed_amount = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'pay_type' => 1, 'is_storage' => 1])->sum('total_price'); + $outstanding_amount = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'pay_type' => 2, 'is_storage' => 1])->sum('total_price'); + if ($purchaseProductOffer['pay_type'] == 1) { + $completed_amount = bcadd($completed_amount, $purchaseProductOffer['total_price'], 2); + } else { + $outstanding_amount = bcadd($outstanding_amount, $purchaseProductOffer['total_price'], 2); + } + Db::startTrans(); + try { + $warehouseOrder = WarehouseOrder::where('oid', $purchaseProductOffer['order_id'])->where('financial_pm', 1)->find(); + if (empty($warehouseOrder)) { + $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, + 'batch' => 0, + 'code' => getNewOrderId('RK'), + 'mark' => $params['remark'] ?? '', + 'total_price' => $purchaseProductOffer['total_price'], + 'completed_amount' => $completed_amount, + 'outstanding_amount' => $outstanding_amount, + ]; + $warehouseOrder = WarehouseOrder::create($arr); + } else { + $warehouseOrder->total_price = bcadd($warehouseOrder->total_price, $purchaseProductOffer['total_price'], 2); + $warehouseOrder->save(); + } + $purchaseProductOffer['price'] = bcdiv($purchaseProductOffer['total_price'], $params['buyer_nums'], 2); + $data['admin_id'] = $params['admin_id']; + $data['order_type'] = $beforehandOrder['order_type']; + $data['store_id'] = 0; + $data['pay_type'] = $purchaseProductOffer['pay_type']; + $data['oid'] = $warehouseOrder['id']; + $data['supplier_id'] = $purchaseProductOffer['supplier_id']; + $data['warehouse_id'] = $params['warehouse_id']; + $data['code'] = $warehouseOrder['code']; + $data['product_id'] = $purchaseProductOffer['product_id']; + $data['nums'] = $params['buyer_nums']; + $data['purchase'] = $purchaseProductOffer['price']; + $data['total_price'] = $purchaseProductOffer['total_price']; + $data['financial_pm'] = 1; + $data['manufacture'] = $purchaseProductOffer['manufacture'] > 0 ? date('Y-m-d H:i:s', $purchaseProductOffer['manufacture']) : ''; + $data['expiration_date'] = $purchaseProductOffer['expiration_date'] > 0 ? date('Y-m-d H:i:s', $purchaseProductOffer['expiration_date']) : ''; + if ($data['nums'] > 0) { + WarehouseProductLogic::add($data, 1, $params['admin_id']); + } + $offerUpdate = ['price' => $purchaseProductOffer['price'], 'status' => 1, 'is_storage' => 1, 'buyer_nums' => $params['buyer_nums']]; + $offerResult = PurchaseProductOffer::where('id', $purchaseProductOffer['id'])->where('is_storage', 0)->update($offerUpdate); + if (!$offerResult) { + throw new BusinessException('入库失败,采购信息更新出错'); + } + $putInCount = PurchaseProductOffer::where('order_id', $purchaseProductOffer['order_id'])->where('is_storage', 1)->count(); + $offerCount = PurchaseProductOffer::where('order_id', $purchaseProductOffer['order_id'])->count(); + if ($putInCount == $offerCount) { + $attrs = ['warehousing_id' => $warehouseOrder['id'], 'is_warehousing' => 1]; + if ($beforehandOrder['order_type'] == 7) { + $attrs['is_buying'] = 1; + } + $result = BeforehandOrder::where('id', $params['bhoid'])->where('warehousing_id', 0)->where('is_warehousing', 0)->update($attrs); + if (!$result) { + throw new BusinessException('入库失败,预订单更新出错'); + } + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + } diff --git a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php index 02b6416c8..d23c4631a 100644 --- a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -53,7 +53,7 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI $cateIds = []; $list = PurchaseProductOffer::where($this->searchWhere) ->with('product') - ->field(['id', 'order_id', 'product_id', 'price', 'total_price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', 'mark','update_time', 'supplier_id', 'package', 'store_info', 'marques', 'after_sales', 'pay_type']) + ->field(['id', 'order_id', 'product_id', 'price', 'total_price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', 'mark','update_time', 'supplier_id', 'package', 'store_info', 'marques', 'after_sales', 'pay_type', 'source_order_info']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($item) use(&$cateIds, &$supplierIds, &$unitIds) {