From 91546d26d1981aad5d91f213cf1a88f06bf70d4a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 10 Nov 2024 15:59:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor(admin):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=89=8D=E7=BD=AE=E8=AE=A2=E5=8D=95=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderLists 中添加 file 字段 - 在 BeforehandOrderLogic 中: - 优化订单创建逻辑,添加审批记录 - 调整订单更新逻辑,仅更新必要的字段 - 重构订单详情获取方法 - 添加时间判断逻辑,计算存储和配送时间 - 在 WarehouseProductReturnLogic 中关联前置订单 ID - 在 OrderAllocation 中更新订单时间相关逻辑 - 在 functions.php 中注释掉未使用的 getNewOrderSn 函数 --- .../beforehand_order/BeforehandOrderLists.php | 2 +- .../beforehand_order/BeforehandOrderLogic.php | 58 ++++++++++--------- .../WarehouseProductReturnLogic.php | 3 + app/common/service/xlsx/OrderAllocation.php | 12 ++-- app/functions.php | 15 +++++ 5 files changed, 54 insertions(+), 36 deletions(-) diff --git a/app/admin/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index ca59aa15d..4b5db2cb1 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -47,7 +47,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte public function lists(): array { return BeforehandOrder::where($this->searchWhere) - ->field(['id','order_id','store_id','order_type','total_num','total_price','outbound_id','admin_id','create_time', 'status', 'mark','warehousing_id']) + ->field(['id','order_id','store_id','order_type','total_num','total_price','outbound_id','admin_id','create_time', 'status', 'mark','warehousing_id','file']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item){ diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 0cc2cfe7b..df87e37d2 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -27,6 +27,7 @@ use app\common\service\xlsx\OrderAllocation; use app\common\service\xlsx\OrderInfo; use app\common\service\xlsx\OrderList; use app\common\service\xlsx\OrderOutbound; +use DateTime; use support\exception\BusinessException; use think\facade\Db; @@ -102,12 +103,11 @@ class BeforehandOrderLogic extends BaseLogic 'phone' => $params['phone'] ?? '', 'address' => $params['address'] ?? '', 'mark' => $params['mark'] ?? '', - 'arrival_time' => strtotime($params['arrival_time']), 'order_type' => $order_type, 'other_data' => json_encode($params['other_data'], true) ]); /** 添加审批记录 */ - BeforehandOrderRecord::create(['oid'=>$order['id'],'step_id'=>1]); + BeforehandOrderRecord::create(['oid' => $order['id'], 'step_id' => 1]); $product_arr = []; foreach ($datas as $k => $v) { $datas[$k]['bhoid'] = $order['id']; @@ -308,23 +308,14 @@ class BeforehandOrderLogic extends BaseLogic { Db::startTrans(); try { - BeforehandOrder::where('id', $params['id'])->update([ - 'store_id' => $params['store_id'], - 'order_id' => $params['order_id'], - 'uid' => $params['uid'], - 'cart_id' => $params['cart_id'], - 'total_num' => $params['total_num'], - 'total_price' => $params['total_price'], - 'pay_price' => $params['pay_price'], - 'deduction_price' => $params['deduction_price'], - 'paid' => $params['paid'], - 'pay_time' => $params['pay_time'], - 'pay_type' => $params['pay_type'], - 'source' => $params['source'], - 'status' => $params['status'], + $find=BeforehandOrder::where('id', $params['id'])->find(); + $other_data=$find['other_data']; + $other_data['arrival_time']=strtotime($params['arrival_time']); + $find->update([ + 'other_data'=>json_encode($other_data, true), + 'image' => $params['image'], 'mark' => $params['mark'] ]); - Db::commit(); return true; } catch (\Throwable $e) { @@ -508,8 +499,7 @@ class BeforehandOrderLogic extends BaseLogic */ public static function detail($params): array { - $res = BeforehandOrder::findOrEmpty($params['id'])->toArray(); - + $res = BeforehandOrder::where('id',$params['id'])->find()->toArray(); $ids = BeforehandOrderCartInfo::where('bhoid', $params['id'])->column('product_id'); $top_cate_ids = StoreProduct::where('id', 'in', $ids)->column('top_cate_id'); if ($top_cate_ids) { @@ -519,14 +509,13 @@ class BeforehandOrderLogic extends BaseLogic } $res['system_store'] = SystemStore::where('id', $res['store_id'])->value('name'); $res['admin_name'] = Admin::where('id', $res['admin_id'])->value('name'); - $record=BeforehandOrderRecord::where('oid',$params['id'])->order('id','desc')->find(); - $res['step_id']=1; - if($record){ - $res['step_id']=$record['step_id']; - if($record['check_user_id']>0){ - $res['examine_name']=Admin::where('id',$record['check_user_id'])->value('name'); + $record = BeforehandOrderRecord::where('oid', $params['id'])->order('id', 'desc')->find(); + $res['step_id'] = 1; + if ($record) { + $res['step_id'] = $record['step_id']; + if ($record['check_user_id'] > 0) { + $res['examine_name'] = Admin::where('id', $record['check_user_id'])->value('name'); } - } return $res; } @@ -568,6 +557,19 @@ class BeforehandOrderLogic extends BaseLogic }); $other_data = $order['other_data']; unset($order['other_data']); + $dateTime = new DateTime($order['create_time']); + $hour = (int) $dateTime->format('H'); + // 判断时间是否小于18点 + if ($hour < 18) { + // 时间小于18点的逻辑 + $data['storage_time'] = $dateTime->modify('+60 minutes')->format('Y-m-d H:i:s'); + $data['delivery_time'] = $dateTime->modify('+90 minutes')->format('Y-m-d H:i:s'); + } else { + // 时间大于或等于18点的逻辑 + $data['storage_time'] = $dateTime->modify('+150 minutes')->format('Y-m-d H:i:s'); + $data['delivery_time'] = $dateTime->modify('+205 minutes')->format('Y-m-d H:i:s'); + } + $data['split_time'] = $dateTime->modify('+10 minutes')->format('Y-m-d H:i:s'); $file_path = $order_allocation->export($data, $order, $other_data); return $file_path; } @@ -595,7 +597,7 @@ class BeforehandOrderLogic extends BaseLogic return $file_path; } - /** + /** * 导出出库 */ public static function OrderOutbound($params) @@ -609,7 +611,7 @@ class BeforehandOrderLogic extends BaseLogic $item['store_name'] = $find['store_name']; return $item; }); - $order['system_store_name']=SystemStore::where('id', $order['store_id'])->value('name'); + $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); $other_data = $order['other_data']; unset($order['other_data']); $file_path = $order_info->export($data, $order, $other_data); diff --git a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php index 086d239f5..e16e5e766 100644 --- a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php +++ b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php @@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse_product_return; use app\common\model\warehouse_product_return\WarehouseProductReturn; use app\common\logic\BaseLogic; +use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; use support\exception\BusinessException; @@ -33,8 +34,10 @@ class WarehouseProductReturnLogic extends BaseLogic try { $find=WarehouseProduct::where('id',$params['id'])->find(); if($find){ + $id=BeforehandOrder::where('id',$find['oid'])->value('id'); WarehouseProductReturn::create([ 'source_id'=>$params['id'], + 'bhoid'=>$id??0, 'warehouse_id'=>$find['warehouse_id'], 'supplier_id'=>$find['supplier_id'], 'store_id'=>$find['store_id'], diff --git a/app/common/service/xlsx/OrderAllocation.php b/app/common/service/xlsx/OrderAllocation.php index f149d4262..b94eab94b 100644 --- a/app/common/service/xlsx/OrderAllocation.php +++ b/app/common/service/xlsx/OrderAllocation.php @@ -128,19 +128,17 @@ class OrderAllocation $sheet->setCellValue('N' . ($count + 8),$other_data->regional_manager??''); $sheet->setCellValue('A' . ($count + 9),'接单时间'); - $sheet->setCellValue('B' . ($count + 9),''); + $sheet->setCellValue('B' . ($count + 9),$order['create_time']??''); $sheet->setCellValue('C' . ($count + 9),'分单时间'); - $sheet->setCellValue('D' . ($count + 9),''); + $sheet->setCellValue('D' . ($count + 9),$order['split_time']??''); $sheet->setCellValue('E' . ($count + 9),'入库时间'); - $sheet->setCellValue('F' . ($count + 9),''); - $sheet->setCellValue('G' . ($count + 9),' 出库时间'); - $sheet->setCellValue('H' . ($count + 9),''); + $sheet->setCellValue('F' . ($count + 9),$order['storage_time']??''); + $sheet->setCellValue('G' . ($count + 9),' 分拣时间'); + $sheet->setCellValue('H' . ($count + 9),$order['delivery_time']??''); $sheet->setCellValue('I' . ($count + 9),' 到门店时间'); $sheet->setCellValue('J' . ($count + 9),''); $sheet->setCellValue('K' . ($count + 9),' 下单到货时间'); $sheet->setCellValue('L' . ($count + 9),''); - $sheet->setCellValue('M' . ($count + 9),' 实际到货时间'); - $sheet->setCellValue('N' . ($count + 9),''); // 设置单元格的样式 $styleArray = [ 'font' => [ diff --git a/app/functions.php b/app/functions.php index 2f3150285..2548a2290 100644 --- a/app/functions.php +++ b/app/functions.php @@ -546,3 +546,18 @@ function channelLog($data, $type, $title = '更新前') $log = Log::channel($type); $log->info($title, $data); } + +// if (!function_exists('getNewOrderSn')) { + +// /** +// * @notes 获取订单号 +// * @param $type +// * @return string +// */ +// function getNewOrderSn($type) +// { +// list($msec, $sec) = explode(' ', microtime()); +// $orderId = $type . date('YmdHis', time()); +// return $orderId; +// } +// } \ No newline at end of file From 4199943282bdab168ac326ee09f18fe0b3f00729 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 11 Nov 2024 11:16:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E5=A4=8D=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=80=BB=E4=BB=B7=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderLogic 中添加总价计算逻辑 - 修正 StoreProductLogic 中商品分类数组的生成逻辑 - 修改 IndexController 中的查询条件和字段 - 调整 OrderAllocation 中的表格列标题和数据填充 --- app/admin/logic/beforehand_order/BeforehandOrderLogic.php | 7 ++++--- app/admin/logic/store_product/StoreProductLogic.php | 7 +++++++ app/api/controller/IndexController.php | 2 +- app/common/service/xlsx/OrderAllocation.php | 8 ++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index df87e37d2..c849b3d27 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -66,6 +66,7 @@ class BeforehandOrderLogic extends BaseLogic unset($params['product_arr'][$k]); continue; } + $total_prices=bcmul($v['price'],$v['nums'],2); $datas[$k]['purchase'] = $v['purchase']; $datas[$k]['mark'] = $v['mark'] ?? ''; $datas[$k]['product_id'] = $v['product_id']; @@ -81,12 +82,12 @@ class BeforehandOrderLogic extends BaseLogic $datas[$k]['accept_num'] = $v['nums']; $datas[$k]['price'] = $v['price']; $datas[$k]['package'] = $v['package'] ?? ''; - $datas[$k]['total_price'] = $v['total_price']; - $datas[$k]['pay_price'] = $v['total_price']; + $datas[$k]['total_price'] =$total_prices; + $datas[$k]['pay_price'] = $total_prices; $datas[$k]['create_time'] = time(); $datas[$k]['update_time'] = time(); $total_num += $v['nums']; - $total_price += $v['total_price']; + $total_price += $total_prices; } $order = BeforehandOrder::create([ 'order_id' => getNewOrderId('YG'), diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index c109eaee2..06eb1d96b 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -292,6 +292,13 @@ class StoreProductLogic extends BaseLogic if(empty($data)){ throw new BusinessException('商品不存在'); } + $data['cate_arr']=[$data['top_cate_id']]; + if($data['two_cate_id'] == $data['top_cate_id']){ + $data['cate_arr'][]=$data['cate_id']; + }else{ + $data['cate_arr'][]=$data['two_cate_id']; + $data['cate_arr'][]=$data['cate_id']; + } $data['unit_name']=StoreProductUnit::where('id', $data['unit'])->value('name'); return $data; } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index fbe6fec60..905cbc2dd 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -55,7 +55,7 @@ class IndexController extends BaseApiController { d(1); - $arr=StoreOrder::where('store_id',8)->where('paid',1)->field('id,pay_price')->select()->toArray(); + $arr=StoreOrder::where('store_id',3)->where('paid',1)->field('id,pay_price,deduction_price,refund_price')->select()->toArray(); $data=[]; foreach ($arr as $k => $v) { $total_price=StoreOrderCartInfo::where('oid', $v['id'])->sum('total_price'); diff --git a/app/common/service/xlsx/OrderAllocation.php b/app/common/service/xlsx/OrderAllocation.php index b94eab94b..94e4f83cf 100644 --- a/app/common/service/xlsx/OrderAllocation.php +++ b/app/common/service/xlsx/OrderAllocation.php @@ -50,13 +50,13 @@ class OrderAllocation $sheet->setCellValue('A4', '编号'); $sheet->setCellValue('B4', '品名'); - $sheet->setCellValue('C4', '型号'); + $sheet->setCellValue('C4', '数量'); $sheet->setCellValue('D4', '包装'); $sheet->setCellValue('E4', '毛重'); $sheet->setCellValue('F4', '净重(约)'); $sheet->setCellValue('G4', '单位'); $sheet->setCellValue('H4', '销售单价'); - $sheet->setCellValue('I4', '下单数量'); + $sheet->setCellValue('I4', '型号'); $sheet->setCellValue('J4', '下单金额'); $sheet->setCellValue('K4', '发货量'); $sheet->setCellValue('L4', '实发量'); @@ -79,13 +79,13 @@ class OrderAllocation foreach ($data as $k => $v) { $sheet->setCellValue('A' . ($k + 5), $v['product_id']); $sheet->setCellValue('B' . ($k + 5), $v['store_name']); - $sheet->setCellValue('C' . ($k + 5), $v['marques']); + $sheet->setCellValue('C' . ($k + 5), $v['cart_num']); $sheet->setCellValue('D' . ($k + 5), $v['package']); $sheet->setCellValue('E' . ($k + 5), $v['gross_weight']); $sheet->setCellValue('F' . ($k + 5), $v['net_weight']); $sheet->setCellValue('G' . ($k + 5), $v['unit_name']); $sheet->setCellValue('H' . ($k + 5), $v['price']); - $sheet->setCellValue('I' . ($k + 5), $v['cart_num']); + $sheet->setCellValue('I' . ($k + 5), $v['marques']); $sheet->setCellValue('J' . ($k + 5), $v['total_price']); $sheet->setCellValue('K' . ($k + 5), $v['accept_num']); $sheet->setCellValue('L' . ($k + 5),$v['accept_num']); From 520cb5875b7f6f80390e1ff72dde14cd03a66f60 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 11 Nov 2024 11:26:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E6=AD=A3=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将存储时间、配送时间和分割时间的计算逻辑从 $data 数组修改为 $order 数组 - 优化了时间判断和计算的代码结构,提高了代码可读性和维护性 --- .../logic/beforehand_order/BeforehandOrderLogic.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index c849b3d27..31de88987 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -563,14 +563,14 @@ class BeforehandOrderLogic extends BaseLogic // 判断时间是否小于18点 if ($hour < 18) { // 时间小于18点的逻辑 - $data['storage_time'] = $dateTime->modify('+60 minutes')->format('Y-m-d H:i:s'); - $data['delivery_time'] = $dateTime->modify('+90 minutes')->format('Y-m-d H:i:s'); + $order['storage_time'] = $dateTime->modify('+60 minutes')->format('Y-m-d H:i:s'); + $order['delivery_time'] = $dateTime->modify('+90 minutes')->format('Y-m-d H:i:s'); } else { // 时间大于或等于18点的逻辑 - $data['storage_time'] = $dateTime->modify('+150 minutes')->format('Y-m-d H:i:s'); - $data['delivery_time'] = $dateTime->modify('+205 minutes')->format('Y-m-d H:i:s'); + $order['storage_time'] = $dateTime->modify('+150 minutes')->format('Y-m-d H:i:s'); + $order['delivery_time'] = $dateTime->modify('+205 minutes')->format('Y-m-d H:i:s'); } - $data['split_time'] = $dateTime->modify('+10 minutes')->format('Y-m-d H:i:s'); + $order['split_time'] = $dateTime->modify('+10 minutes')->format('Y-m-d H:i:s'); $file_path = $order_allocation->export($data, $order, $other_data); return $file_path; }