From c0caac17f9d5f53d58d6a50badea3efc71a1cef6 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 28 Feb 2025 16:05:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=B1=BB=E5=9E=8B=E5=90=8D=E7=A7=B0=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B9=B6=E9=85=8D=E7=BD=AE=20PSI=20=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 app/functions.php 中添加 getOrderTypeName 函数,用于获取订单类型名称 - 在 config/middleware.php 中添加 psi 中间件配置,包括跨域中间件、初始化中间件、登录验证中间件、权限认证中间件和操作日志记录中间件 --- .../supplier/SupplierController.php | 95 +++++ app/admin/lists/supplier/SupplierLists.php | 69 ++++ app/admin/logic/supplier/SupplierLogic.php | 103 ++++++ app/common/enum/OrderEnum.php | 244 +++++++++++++ app/common/model/psi/psi_order/PsiOrder.php | 23 ++ .../model/psi/psi_product/PsiProduct.php | 48 +++ app/common/model/psi/warehouse/Warehouse.php | 23 ++ .../warehouse_storege/WarehouseStorege.php | 23 ++ app/common/model/supplier/Supplier.php | 23 ++ app/common/model/system_store/SystemStore.php | 23 ++ app/functions.php | 19 +- .../psi_order/PsiOrderController.php | 329 ++++++++++++++++++ app/psi/lists/psi_order/PsiOrderLists.php | 152 ++++++++ app/psi/logic/psi_order/PsiOrderLogic.php | 190 ++++++++++ config/middleware.php | 12 + 15 files changed, 1375 insertions(+), 1 deletion(-) create mode 100644 app/admin/controller/supplier/SupplierController.php create mode 100644 app/admin/lists/supplier/SupplierLists.php create mode 100644 app/admin/logic/supplier/SupplierLogic.php create mode 100644 app/common/enum/OrderEnum.php create mode 100644 app/common/model/psi/psi_order/PsiOrder.php create mode 100644 app/common/model/psi/psi_product/PsiProduct.php create mode 100644 app/common/model/psi/warehouse/Warehouse.php create mode 100644 app/common/model/psi/warehouse_storege/WarehouseStorege.php create mode 100644 app/common/model/supplier/Supplier.php create mode 100644 app/common/model/system_store/SystemStore.php create mode 100644 app/psi/controller/psi_order/PsiOrderController.php create mode 100644 app/psi/lists/psi_order/PsiOrderLists.php create mode 100644 app/psi/logic/psi_order/PsiOrderLogic.php diff --git a/app/admin/controller/supplier/SupplierController.php b/app/admin/controller/supplier/SupplierController.php new file mode 100644 index 0000000..b88dbd3 --- /dev/null +++ b/app/admin/controller/supplier/SupplierController.php @@ -0,0 +1,95 @@ +dataLists(new SupplierLists()); + } + + + /** + * @notes 添加供应链 + * @return \think\response\Json + * @author admin + * @date 2024/08/15 14:10 + */ + public function add() + { + $params = (new SupplierValidate())->post()->goCheck('add'); + $result = SupplierLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SupplierLogic::getError()); + } + + + /** + * @notes 编辑供应链 + * @return \think\response\Json + * @author admin + * @date 2024/08/15 14:10 + */ + public function edit() + { + $params = (new SupplierValidate())->post()->goCheck('edit'); + $result = SupplierLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SupplierLogic::getError()); + } + + + /** + * @notes 删除供应链 + * @return \think\response\Json + * @author admin + * @date 2024/08/15 14:10 + */ + public function delete() + { + $params = (new SupplierValidate())->post()->goCheck('delete'); + SupplierLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取供应链详情 + * @return \think\response\Json + * @author admin + * @date 2024/08/15 14:10 + */ + public function detail() + { + $params = (new SupplierValidate())->goCheck('detail'); + $result = SupplierLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/supplier/SupplierLists.php b/app/admin/lists/supplier/SupplierLists.php new file mode 100644 index 0000000..9d82998 --- /dev/null +++ b/app/admin/lists/supplier/SupplierLists.php @@ -0,0 +1,69 @@ + ['phone'], + '%like%'=>['mer_name'] + ]; + } + + + /** + * @notes 获取供应链列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/15 14:10 + */ + public function lists(): array + { + return Supplier::where($this->searchWhere) + ->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) + ->limit($this->limitOffset, 100) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price'); + $item->total_outstanding_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',0)->sum('total_price'); + }) + ->toArray(); + } + + + /** + * @notes 获取供应链数量 + * @return int + * @author admin + * @date 2024/08/15 14:10 + */ + public function count(): int + { + return Supplier::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/supplier/SupplierLogic.php b/app/admin/logic/supplier/SupplierLogic.php new file mode 100644 index 0000000..907b352 --- /dev/null +++ b/app/admin/logic/supplier/SupplierLogic.php @@ -0,0 +1,103 @@ + $params['mer_name'], + 'phone' => $params['phone'], + 'settle_cycle' => $params['settle_cycle'], + 'address' => $params['address'], + 'mark' => $params['mark'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑供应链 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/15 14:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Supplier::where('id', $params['id'])->update([ + 'mer_name' => $params['mer_name'], + 'phone' => $params['phone'], + 'settle_cycle' => $params['settle_cycle'], + 'address' => $params['address'], + 'mark' => $params['mark'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除供应链 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/15 14:10 + */ + public static function delete(array $params): bool + { + return Supplier::destroy($params['id']); + } + + + /** + * @notes 获取供应链详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/15 14:10 + */ + public static function detail($params): array + { + return Supplier::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php new file mode 100644 index 0000000..9e6f605 --- /dev/null +++ b/app/common/enum/OrderEnum.php @@ -0,0 +1,244 @@ + '订单支付', + self::MERCHANT_ORDER_PAY => '商户订单支付', + self::PLATFORM_ORDER_PAY => '平台订单支付', + self::MERCHANT_ORDER_OBTAINS => '商户', + self::ORDER_HANDLING_FEES => '手续费', + self::PLATFORM_ORDER_OBTAINS => '平台', + self::SUPPLIER_ORDER_OBTAINS => '成本', + self::SYSTEM_SET => '平台设置', + self::VILLAGE_ORDER_OBTAINS => '村长', + self::BRIGADE_ORDER_OBTAINS=>'队长', + self::ORDER_MARGIN=>'保证金', + self::VIP_ORDER_OBTAINS=>'会员', + self::OTHER_ORDER_OBTAINS=>'其他', + self::USER_ORDER_REFUND=>'订单返还' + + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } + + /** + * @notes 获取订单状态类型 + */ + public static function getOrderType($value = true) + { + $data = [ + self::RECEIVED_GOODS => '已完成', + self::WAIT_EVALUATION => '待评价', + self::WAIT_DELIVERY => '待发货', + self::WAIT_RECEIVING => '待核销', + self::RETURN_SUCCESS => '退货成功', + self::ALREADY_REFUND => '已退款', + self::RECEIVED_BACK => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } + + /** + * @notes 获取订单状态类型 + */ + public static function refundStatus($value = true) + { + $data = [ + self::REFUND_STATUS_NO => '未退款', + self::REFUND_STATUS_YES => '退款中', + self::REFUND_STATUS_FINISH => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } + + /** + * @notes 获取订单状态类型 + */ + public static function refundType($value = true) + { + $data = [ + 1 => '仅退款', + 2 => '退款退货', + 3 => '拒绝退款', + 4 => '商品待退货', + 5 => '退货待收货', + 6 => '已退款', + ]; + if ($value === true) { + return $data; + } + return $data[$value] ?? ''; + } +} diff --git a/app/common/model/psi/psi_order/PsiOrder.php b/app/common/model/psi/psi_order/PsiOrder.php new file mode 100644 index 0000000..310b0ff --- /dev/null +++ b/app/common/model/psi/psi_order/PsiOrder.php @@ -0,0 +1,23 @@ + '铺货订单', + 2 => '商贩订单', + 3 => '一条龙订单', + 4 => '线上订单', + 5 => '仓库补货', + 6 => '往期补单-出库', + 7 => '采购订单', + 8 => '其他订单', + 9 => '往期补单-入库', + ]; + return $typeMap[$type] ?? ''; + } +} diff --git a/app/psi/controller/psi_order/PsiOrderController.php b/app/psi/controller/psi_order/PsiOrderController.php new file mode 100644 index 0000000..acb616f --- /dev/null +++ b/app/psi/controller/psi_order/PsiOrderController.php @@ -0,0 +1,329 @@ +dataLists(new PsiOrderLists()); + } + + + /** + * @notes 添加入库单 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function add() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $result = WarehouseOrderLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + } + /** + * @notes 添加出库单 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function outbound() + { + $product_arr = $this->request->post('product_arr'); + $warehouse_id = $this->request->post('warehouse_id'); + $delivery_time = $this->request->post('delivery_time'); + $mark = $this->request->post('mark'); + $type = $this->request->post('order_type', 1); + Db::startTrans(); + try { + if($type==1){ + $code=getNewOrderId('TGY'); + }else{ + $code=getNewOrderId('BS'); + } + $arr = [ + 'warehouse_id' => $warehouse_id, + 'store_id' => 0, + 'supplier_id' => 0, + 'code' => $code, + 'admin_id' => $this->adminId, + 'financial_pm' => 0, + 'batch' => 0, + 'mark' => $mark ?? "", + ]; + $arr['delivery_time'] = strtotime($delivery_time); + $res = WarehouseOrder::create($arr); + foreach ($product_arr as $key => $arr) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['id'], + 'store_id' => 0, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['stock'], + 'status' => 1, + 'admin_id' => $this->adminId, + 'type' => $type, + 'order_type' => 0, + ]; + $storeProduct = StoreProduct::where('id', $arr['id'])->find(); + $data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2); + $data['purchase'] = $storeProduct['purchase']; + $data['oid'] = $res['id']; + $data['financial_pm'] = 0; + $data['price'] = $storeProduct['price']; + WarehouseProductLogic::setOutbound($data,1,$this->adminId); + $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + return $this->success('出库成功', [], 1, 1); + } + + + /** + * @notes 编辑仓储商品单 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function edit() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $result = WarehouseOrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + } + + /** + * @notes 编辑仓储商品单 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function update_edit() + { + $params = $this->request->post(); + $result = WarehouseOrderLogic::update_edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail('编辑失败'); + } + + /** + * @notes 删除仓储商品单 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function delete() + { + $params = (new WarehouseOrderValidate())->post()->goCheck('delete'); + WarehouseOrderLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取仓储商品单详情 + * @return \think\response\Json + * @author admin + * @date 2024/08/20 10:50 + */ + public function detail() + { + $params = (new WarehouseOrderValidate())->goCheck('detail'); + $result = WarehouseOrderLogic::detail($params); + return $this->data($result); + } + /** + * 入库表格 + */ + public function rentry_export() + { + $id = $this->request->post('id'); + $xlsx = new WarehouseOrdeRentry(); + $order = WarehouseOrder::where('id', $id)->findOrEmpty(); + $data = WarehouseProduct::where('oid', $id)->select(); + $order['total_num'] = 0; + $credit_pay = 0; + $cash_pay = 0; + foreach ($data as $key => &$value) { + $find = StoreProduct::where('id', $value->product_id)->withTrashed()->find(); + $value->store_name = $find['store_name'] ?? ''; + $value->store_info = $find['store_info'] ?? ''; + if (!empty($find['unit'])) { + $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + } else { + $value->unit_name = ''; + } + $order['total_num'] += $value->nums; + $value->supplier_name = Supplier::where('id', $value->supplier_id)->value('mer_name'); + if ($value->pay_type == 1) { + $credit_pay += $value->total_price; + $value->pay_type_name = '赊账'; + } elseif ($value->pay_type == 2) { + $cash_pay += $value->total_price; + $value->pay_type_name = '现款'; + } else { + $value->pay_type_name = '未设置'; + } + } + $order['credit_pay'] = $credit_pay; + $order['cash_pay'] = $cash_pay; + $file_path = $xlsx->export($data, $order); + + return $this->success('导出成功', ['url' => $file_path]); + } + + /** + * 出库表格 + */ + public function export() + { + $id = $this->request->post('id'); + $type = $this->request->post('type'); + if (in_array($type, [2, 3])) { + return $this->fail('暂不支持此操作'); + } + $xlsx = new OrderDetail(); + $order = WarehouseOrder::where('id', $id)->findOrEmpty(); + $system_store = SystemStore::where('id', $order['store_id'])->value('name'); + $data = WarehouseProduct::where('oid', $id)->select(); + $order['total_num'] = 0; + $total_price = 0; + foreach ($data as $key => &$value) { + if (in_array($order['store_id'], [17, 18])) { + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->withTrashed()->find(); + } else { + $find = StoreProduct::where('id', $value->product_id)->withTrashed()->find(); + } + $value->store_name = $find['store_name'] ?? ''; + $value->store_info = $find['store_info'] ?? ''; + // if($type==2){ + // $value->price = $value['purchase']; + // $value->total_price=bcmul($value['purchase'],$value['nums'],2); + // $total_price+=$value->total_price; + // }elseif($type==3){ + // $value->price = $find['cost']; + // $value->total_price=bcmul($find['cost'],$value['nums'],2); + // $total_price+=$value->total_price; + // }elseif($type==4){ + // $value->price = $find['price']; + // $value->total_price=bcmul($find['price'],$value['nums'],2); + // $total_price+=$value->total_price; + // }else{ + if ($type == 1) { + $value->price = $value['purchase']; + $value->total_price = bcmul($value['purchase'], $value['nums'], 2); + $total_price += $value->total_price; + } + + + // } + $value->cart_num = $value['nums']; + if (!empty($find['unit'])) { + $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + } else { + $value->unit_name = ''; + } + $order['total_num'] += $value->nums; + } + if ($type == 2) { + $order['total_price'] = $total_price; + } + $order['delivery_time'] = date('Y-m-d H:i:s', $order['delivery_time']); + $order['pay_time'] = $order['create_time']; + $order['order_id'] = $order['code']; + + if ($order['oid'] > 0) { + $orders = StoreOrder::where('id', $order['oid'])->findOrEmpty(); + $order['real_name'] = $orders['real_name']; + $order['user_phone'] = $orders['user_phone']; + $order['user_address'] = $orders['user_address']; + } + $file_path = $xlsx->export($data, $system_store, $order); + + return $this->success('导出成功', ['url' => $file_path]); + } + + /** + * 导出标签 + */ + public function export_tags() + { + $id = $this->request->post('id'); + $warehouseOrder = WarehouseOrder::where('id', $id)->field('oid,store_id,delivery_time')->find(); + $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction'); + $data = WarehouseProduct::where('oid', $id)->where('financial_pm', 0)->field('oid,product_id,nums')->select() + ->each(function ($item) use ($system_store, $warehouseOrder) { + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->withTrashed()->find(); + $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['system_store'] = $system_store; + $item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name; + $item['store_name'] = $find['store_name']; + if ($warehouseOrder['oid']) { + $find = StoreOrder::where('id', $warehouseOrder['oid'])->field('real_name,user_address')->find(); + if ($find) { + $item['address'] = $find['real_name'] . ' ' . $find['user_address']; + } else { + $item['address'] = '无地址'; + } + } else { + $item['address'] = '无地址'; + } + }) + ->toArray(); + $file_path = (new Beforehand())->export($data, $system_store); + return $this->success('导出成功', ['url' => $file_path]); + } +} diff --git a/app/psi/lists/psi_order/PsiOrderLists.php b/app/psi/lists/psi_order/PsiOrderLists.php new file mode 100644 index 0000000..e210f4d --- /dev/null +++ b/app/psi/lists/psi_order/PsiOrderLists.php @@ -0,0 +1,152 @@ + ['financial_pm', 'supplier_id', 'warehouse_id', 'store_id','id'], + '%like'=>['code'], + 'between_time' => 'create_time' + ]; + } + + + /** + * @notes 获取仓储商品单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/20 10:50 + */ + public function lists(): array + { + return PsiOrder::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time','oid', 'order_type']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + if ($item->financial_pm == 0) { + $item->financial_pm_name = '出库'; + } else { + $item->financial_pm_name = '入库'; + } + if ($item->financial_pm == 0) { + if ($item->store_id) { + $item->system_store = SystemStore::where('id', $item->store_id)->value('name'); + } else { + $item->system_store = ''; + } + } + if ($item->admin_id) { + $item->admin_name = Admin::where('id', $item->admin_id)->value('name'); + } else { + $item->admin_name = ''; + } + if ($item->warehouse_id) { + $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); + } else { + $item->warehouse_name = ''; + } + if ($item->supplier_id) { + $item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name'); + }else{ + $item->supplier_name = ''; + } + if (!empty($item['order_type'])) { + $item->order_type_name = getOrderTypeName($item->order_type); + } + }) + ->toArray(); + } + + + /** + * @notes 获取仓储商品单数量 + * @return int + * @author admin + * @date 2024/08/20 10:50 + */ + public function count(): int + { + return PsiOrder::where($this->searchWhere)->count(); + } + /** + * @notes 导出文件名 + * @return string + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 0) { + return '出库单列表'; + } else { + return '入库单列表'; + } + } + + + /** + * @notes 导出字段 + * @return string[] + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 1) { + $data = [ + 'create_time' => '操作时间', + 'warehouse_name' => '仓库', + 'supplier_name' => '供应商', + 'code' => '单号', + 'financial_pm_name' => '状态', + 'admin_name' => '填写人员', + 'completed_amount' => '已结金额', + 'outstanding_amount' => '未结金额', + 'total_price' => '总金额', + 'mark' => '备注', + ]; + } else { + $data = [ + 'create_time' => '操作时间', + 'warehouse_name' => '仓库', + 'supplier_name' => '供应商', + 'code' => '单号', + 'financial_pm_name' => '状态', + 'admin_name' => '填写人员', + 'total_price' => '总金额', + 'mark' => '备注', + ]; + } + return $data; + } +} diff --git a/app/psi/logic/psi_order/PsiOrderLogic.php b/app/psi/logic/psi_order/PsiOrderLogic.php new file mode 100644 index 0000000..a2aa5b2 --- /dev/null +++ b/app/psi/logic/psi_order/PsiOrderLogic.php @@ -0,0 +1,190 @@ + $params['warehouse_id'], + 'supplier_id' => $params['supplier_id'], + 'code' => $params['code'], + 'admin_id' => $params['admin_id'], + 'financial_pm' => 1, + 'batch' => 0, + 'mark' => $params['remark'], + 'total_price' => $params['remark'], + 'completed_amount' => $params['completed_amount']??0, + 'outstanding_amount' => $params['outstanding_amount']??0, + ]; + + $total_price = 0; + foreach ($params['product_arr'] as $k => $v) { + $total_price += $v['total_price']; + } + $arr['total_price'] = $total_price; + $res = WarehouseOrder::create($arr); + foreach ($params['product_arr'] as $k => $v) { + $data['admin_id'] = $params['admin_id']; + $data['store_id'] = 0; + $data['oid'] = $res['id']; + $data['supplier_id'] = $params['supplier_id']; + $data['warehouse_id'] = $params['warehouse_id']; + $data['code'] = $params['code']; + $data['product_id'] = $v['product_id']; + $data['nums'] = $v['nums']; + $data['purchase'] = $v['purchase']; + $data['total_price'] = $v['total_price']; + $data['financial_pm'] = 1; + if (!empty($v['manufacture'])) { + $data['manufacture'] = $v['manufacture']; + } + if (!empty($v['expiration_date'])) { + $data['expiration_date'] = $v['expiration_date']; + } + WarehouseProductLogic::add($data,1,$params['admin_id']); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑仓储商品单 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/20 10:50 + */ + public static function edit(array $params): bool + { + $find = WarehouseOrder::where('id', $params['id'])->find(); + if (!$find) { + throw new BusinessException('订单不存在'); + } + $order_type=BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('order_type')??0; + Db::startTrans(); + try { + foreach ($params['product_arr'] as $k => $v) { + $data['order_type'] = $order_type; + $data['supplier_id'] = $v['supplier_id']??0; + $data['pay_type'] = $v['pay_type']??0; + $data['admin_id'] = $params['admin_id']; + $data['store_id'] = $find['store_id']; + $data['oid'] = $find['id']; + $data['warehouse_id'] = $find['warehouse_id']; + $data['code'] = $find['code']; + $data['product_id'] = $v['id']; + $data['nums'] = $v['nums']; + $data['purchase'] = $v['purchase']; + $data['total_price'] = $v['total_price']; + $data['financial_pm'] = $find['financial_pm']; + if (!empty($v['manufacture'])) { + $data['manufacture'] = $v['manufacture']; + } + if (!empty($v['expiration_date'])) { + $data['expiration_date'] = $v['expiration_date']; + } + if($find['financial_pm']==0){ + $data['purchase'] = $v['prices']; + $data['total_price'] = bcmul($v['prices'], $v['nums'], 2); + } + WarehouseProductLogic::add($data,1,$params['admin_id']); + } + $find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + if ($find) { + WarehouseOrder::where('id', $params['id'])->update([ + 'nums' => $find['nums'], + 'total_price' => $find['total_price'] + ]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除仓储商品单 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/20 10:50 + */ + public static function delete(array $params): bool + { + $count = WarehouseProduct::where('oid', $params['id'])->count(); + if ($count >= 1) { + throw new BusinessException('该订单下还有商品没有删除,请先删除商品'); + } + WarehouseOrder::destroy($params['id']); + $find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + if ($find) { + WarehouseOrder::where('id', $params['id'])->update([ + 'nums' => $find['nums'], + 'total_price' => $find['total_price'] + ]); + } + return true; + } + + /** + * @notes 编辑仓储商品单 + * @param $data + * @return bool + * @author admin + * @date 2024/08/20 10:50 + */ + public static function update_edit($data){ + $res=WarehouseOrder::update($data); + if($res){ + return true; + }else{ + return false; + } + } + + /** + * @notes 获取仓储商品单详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/20 10:50 + */ + public static function detail($params): array + { + return WarehouseOrder::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/config/middleware.php b/config/middleware.php index 8c5ae07..ab6482e 100644 --- a/config/middleware.php +++ b/config/middleware.php @@ -47,4 +47,16 @@ return [ // 操作日志记录 app\admin\middleware\OperationLogMiddleware::class, ], + 'psi' => [ + // 跨域中间件 + app\common\http\middleware\AdminAllowMiddleware::class, + // 初始化 + app\admin\middleware\InitMiddleware::class, + // 登录验证 + app\admin\middleware\LoginMiddleware::class, + // 权限认证 + app\admin\middleware\AuthMiddleware::class, + // 操作日志记录 + app\admin\middleware\OperationLogMiddleware::class, + ], ];