From eb131467632a2ca6633aadc536f9c321e879b498 Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 11 Sep 2025 15:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/StockOrders.php | 4 +- .../utils/pdf/template/stockOrder copy.stub | 319 ++++++++++++++++++ app/common/utils/pdf/template/stockOrder.stub | 16 +- app/crm/controller/StockOrdersController.php | 27 +- app/crm/service/StockOrdersService.php | 191 +++++++---- 5 files changed, 475 insertions(+), 82 deletions(-) create mode 100644 app/common/utils/pdf/template/stockOrder copy.stub diff --git a/app/common/model/StockOrders.php b/app/common/model/StockOrders.php index a5dc48d..0b97fe4 100644 --- a/app/common/model/StockOrders.php +++ b/app/common/model/StockOrders.php @@ -50,7 +50,7 @@ class StockOrders extends Model 'trade_term_id', 'trade_term_snapshot', 'clearance_port_id', 'clearance_port_snapshot', 'latest_arrival_date', 'contract_exchange_rate', 'settlement_currency', 'status', 'remark', 'created_at', 'updated_at', 'deleted_at', - 'object_id', 'contract', 'is_use', 'is_final', 'approval_status', 'file_url', 'pick_up_date', 'collect_all_date' + 'object_id', 'contract', 'is_use', 'is_final', 'approval_status', 'file_url', 'pick_up_date', 'collect_all_date', 'profit_total' ]; /** @@ -87,7 +87,7 @@ class StockOrders extends Model */ public function moneyValues() { - return $this->hasOne(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders'); + return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders'); } diff --git a/app/common/utils/pdf/template/stockOrder copy.stub b/app/common/utils/pdf/template/stockOrder copy.stub new file mode 100644 index 0000000..8a2dbf5 --- /dev/null +++ b/app/common/utils/pdf/template/stockOrder copy.stub @@ -0,0 +1,319 @@ + + + + + 合塑实业-汽车事业部-备货单(客户下定) + + + +
+ +
+

合塑实业-汽车事业部-备货单(客户下定)

+
+ 备货单号: + 业务员: +
+
+ + + + + + + + + + + + + + + + + + + + + +
阿里订单号/PI号: 日期: 关目的国: 客户来源: 客户名称: 客户所在国:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0): ?> + + + + + + + + + + + + + + + + + + +
编号车型数量/台颜色/外内饰改装官方指导价/二手挂牌价优惠单价总价利润
+ + 0): ?> + () + +
+ 合同汇率: + + 合计到岸价: +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
清关人: 全款收齐日: 预计发运日期: 出运方式: 国内收货港: 贸易条款/清关目的港: /提车日期: 最迟到港时间:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
计划收款信息序号汇款国日期币种账户汇款人金额
+ + +
+ +
+ +
+ 业务员签字: + + + + + +
+ +
+ 备发货负责人签字: + + + + + +
+
+ + +
+
+ 组长签字: + + + + + +
+ +
+ 日期: + +
+
+ +
+
+ + +
+ + \ No newline at end of file diff --git a/app/common/utils/pdf/template/stockOrder.stub b/app/common/utils/pdf/template/stockOrder.stub index 2c051c1..7553946 100644 --- a/app/common/utils/pdf/template/stockOrder.stub +++ b/app/common/utils/pdf/template/stockOrder.stub @@ -163,16 +163,16 @@ 0): ?> - - + + - - + + - - - + + + @@ -181,7 +181,7 @@ 合同汇率: - 合计到岸价: + 合计到岸价: diff --git a/app/crm/controller/StockOrdersController.php b/app/crm/controller/StockOrdersController.php index b967d76..8efa6be 100644 --- a/app/crm/controller/StockOrdersController.php +++ b/app/crm/controller/StockOrdersController.php @@ -66,12 +66,14 @@ class StockOrdersController extends BaseController } if (count($data['moneyValues']) > 0) { - $data['cif_total_amount'] = [ - 'exchange_rate' => $data['moneyValues']['exchange_rate'], - 'amount' => $data['moneyValues']['amount'], - 'currency' => $data['moneyValues']['currency'], - 'id' => $data['moneyValues']['id'] - ]; + foreach ($data['moneyValues'] as $mvs) { + $data[$mvs['field']] = [ + 'exchange_rate' => $mvs['exchange_rate'], + 'amount' => $mvs['amount'], + 'currency' => $mvs['currency'], + 'id' => $mvs['id'] + ]; + } } foreach ($data['items'] as &$item) { @@ -144,6 +146,19 @@ class StockOrdersController extends BaseController return $this->error($e->getMessage()); } } + + public function detail(Request $request) + { + try { + $raw = $this->service->serviceDetail($request); + $data = $this->transformData($raw, method_exists($this, 'printFormat') + ? [$this, 'printFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } /** * 启动审批 diff --git a/app/crm/service/StockOrdersService.php b/app/crm/service/StockOrdersService.php index a8c4732..b29213f 100644 --- a/app/crm/service/StockOrdersService.php +++ b/app/crm/service/StockOrdersService.php @@ -71,6 +71,7 @@ class StockOrdersService case 'approval': $config['where']['id'] = $p['id']; break; + case 'detail': case 'show': $config['where']['id'] = $p['id']; @@ -223,10 +224,10 @@ class StockOrdersService $data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? ''; $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - if ($data['is_final'] == 1) { + // if ($data['is_final'] == 1) { $data['pick_up_date'] = strtotime($data['pick_up_date']); $data['collect_all_date'] = strtotime($data['collect_all_date']); - } + // } return $data; } @@ -452,18 +453,45 @@ class StockOrdersService $vehList = []; $index = 0; $totalProfit = 0; // 总利润 + + // $priceFields = [ + // 'official_price', // '官方指导价', + // 'discount_price', // '优惠', + // 'listing_price', // '二手挂牌价价', + // 'reduction_price', // '优惠', + + // 'handling_fee', // '手续费', + // 'retrofit_fee', // '改装费', + // 'fob_transport_fee', // 'FOB运输费', + // 'port_misc_fee', // '港杂', + // 'ocean_freight', // '海运费', + + // 'unit_price', // '单价', + // 'total_price', // '总价', + // // 'profit', // '利润' + // ]; foreach ($item->items as $k => $v) { + $currencyInfo = SysCurrency::where('currency_code', $item->settlement_currency)->first(['currency_symbol', 'currency_name'])->toArray(); + // 存在则数量加1 if (count($vehList) > 0 && isset($vehList[$v->unique_id])) { $vehList[$v->unique_id]['num'] += 1; - $vehList[$v->unique_id]['total_price'] += $vehList[$v->unique_id]['unit_price']; - $vehList[$v->unique_id]['total_price_text'] = $vehList[$v->unique_id]['total_price_symbol'].number_format($vehList[$v->unique_id]['total_price'], 2, '.', ','); + $vehList[$v->unique_id]['total_price']['currency_info'] = $currencyInfo['currency_symbol'].number_format($vehList[$v->unique_id]['total_price']['amount']*$vehList[$v->unique_id]['num'], 2, '.', ','); + $vehList[$v->unique_id]['profit']['currency_info'] = $currencyInfo['currency_symbol'].number_format($vehList[$v->unique_id]['profit']['amount']*$vehList[$v->unique_id]['num'], 2, '.', ','); continue; } $index += 1; + // 合计到岸价 + // $cifTotalAmount = 0.00; + // $cifTotalAmountSymbol = ''; + // if ($item->moneyValues) { + // $cifTotalInfo = SysCurrency::where('currency_code', $item->moneyValues->currency)->select('currency_symbol', 'currency_name')->get()->toArray(); + // $cifTotalAmount = $currencyInfo['currency_symbol'].sprintf("%.2f", $item->moneyValues->amount); + // } + // 处理金额 (每次循环重新初始化) $mv = []; foreach ($v->moneyValues as $money) { @@ -471,7 +499,8 @@ class StockOrdersService 'currency' => $money->currency, 'amount' => $money->amount, 'rate' => $money->exchange_rate, - 'currency_symbol' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'), + 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol').number_format($money->amount, 2, '.', ','), + // 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'), ]; } @@ -494,52 +523,72 @@ class StockOrdersService 'num' => 1, 'modify' => $mfy, 'mileage' => $v->mileage, - 'unit_price' => $mv['unit_price']['amount'] ?? 0, - 'total_price' => $mv['total_price']['amount'] ?? 0, - 'profit' => $itemProfit, // 单项利润 - 'profit_symbol' => $mv['unit_price']['currency_symbol'] ?? '', - 'profit_text' => isset($mv['unit_price']['currency_symbol']) ? - $mv['unit_price']['currency_symbol'].number_format($itemProfit, 2, '.', ',') : '0.00', - 'unit_price_symbol' => $mv['unit_price']['currency_symbol'] ?? '', - 'total_price_symbol' => $mv['total_price']['currency_symbol'] ?? '', - 'unit_price_text' => isset($mv['unit_price']['currency_symbol']) ? - $mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ',') : '0.00', - 'total_price_text' => isset($mv['total_price']['currency_symbol']) ? - $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',') : '0.00' + + + // 'unit_price' => $mv['unit_price']['amount'] ?? 0, + // 'unit_price_symbol' => $mv['unit_price']['currency_symbol'] ?? '', + // 'unit_price_text' => isset($mv['unit_price']['currency_symbol']) ? + // $mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ',') : '0.00', + + // 'total_price' => $mv['total_price']['amount'] ?? 0, + // 'total_price_symbol' => $mv['total_price']['currency_symbol'] ?? '', + // 'total_price_text' => isset($mv['total_price']['currency_symbol']) ? + // $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',') : '0.00', + + + // 'handling_fee' => $mv['handling_fee']['amount'] ?? 0, + // 'handling_fee_symbol' => $mv['handling_fee']['currency_symbol'] ?? '', + + + // 单项利润 + // 'profit' => $itemProfit, + // 'profit_symbol' => $cifTotalInfo['currency_symbol'], + // 'profit_text' => isset($mv['unit_price']['currency_symbol']) ? $cifTotalInfo['currency_symbol'].number_format($itemProfit, 2, '.', ',') : '0.00', ]; // 根据里程处理 新车or二手车 - if ($v->mileage > 0) { - // 二手车 - if (isset($mv['reduction_price'])) { - $vehListItem['reduction_price'] = $mv['reduction_price']['amount']; - $vehListItem['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol']; - $vehListItem['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ','); - } + // if ($v->mileage > 0) { + // // 二手车 + // if (isset($mv['reduction_price'])) { + // $vehListItem['reduction_price'] = $mv['reduction_price']['amount']; + // $vehListItem['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol']; + // $vehListItem['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ','); + // } - if (isset($mv['listing_price'])) { - $vehListItem['listing_price'] = $mv['listing_price']['amount']; - $vehListItem['listing_price_symbol'] = $mv['listing_price']['currency_symbol']; - $vehListItem['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ','); - } - } else { - // 新车 - if (isset($mv['discount_price'])) { - $vehListItem['discount_price'] = $mv['discount_price']['amount']; - $vehListItem['discount_price_symbol'] = $mv['discount_price']['currency_symbol']; - $vehListItem['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ','); - } + // if (isset($mv['listing_price'])) { + // $vehListItem['listing_price'] = $mv['listing_price']['amount']; + // $vehListItem['listing_price_symbol'] = $mv['listing_price']['currency_symbol']; + // $vehListItem['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ','); + // } + // } else { + // // 新车 + // if (isset($mv['discount_price'])) { + // $vehListItem['discount_price'] = $mv['discount_price']['amount']; + // $vehListItem['discount_price_symbol'] = $mv['discount_price']['currency_symbol']; + // $vehListItem['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ','); + // } - if (isset($mv['official_price'])) { - $vehListItem['official_price'] = $mv['official_price']['amount']; - $vehListItem['official_price_symbol'] = $mv['official_price']['currency_symbol']; - $vehListItem['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ','); - } - } + // if (isset($mv['official_price'])) { + // $vehListItem['official_price'] = $mv['official_price']['amount']; + // $vehListItem['official_price_symbol'] = $mv['official_price']['currency_symbol']; + // $vehListItem['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ','); + // } + // } - $vehList[$v->unique_id] = $vehListItem; + $vehList[$v->unique_id] = $vehListItem + $mv; } - +// var_dump($item->moneyValues); + $mvs = []; + foreach ($item->moneyValues as $moneys) { + $mvs[$moneys->field] = [ + 'currency' => $moneys->currency, + 'amount' => $moneys->amount, + 'rate' => $moneys->exchange_rate, + 'currency_info' => SysCurrency::where('currency_code', $moneys->currency)->value('currency_symbol').number_format($moneys->amount, 2, '.', ','), + // 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'), + ]; + } + // var_dump($mvs); $accList = []; foreach ($item->accounts as $k => $v) { $accList[] = [ @@ -553,12 +602,7 @@ class StockOrdersService ]; } - $cifTotalAmount = 0.00; - $cifTotalAmountSymbol = ''; - if ($item->moneyValues) { - $cifTotalAmountSymbol = SysCurrency::where('currency_code', $item->moneyValues->currency)->value('currency_symbol'); - $cifTotalAmount = $cifTotalAmountSymbol.sprintf("%.2f", $item->moneyValues->amount); - } + $veh = [ 'order_no' => $item->order_no, @@ -578,7 +622,8 @@ class StockOrdersService 'veh_list' => array_values($vehList), // 重新索引数组 'contract_exchange_rate' => $item->contract_exchange_rate, - 'cif_total_amount' => $item->cif_total_amount, + 'cif_total_amount' => $mvs['cif_total_amount'], + 'profit_total' => $mvs['profit_total'], 'declarant_name' => $item->declarant_name, 'eta_ship_date' => date('Y-m-d', $item->eta_ship_date), @@ -594,11 +639,12 @@ class StockOrdersService // 账户 'account_list' => $accList, 'acc_index' => count($accList)+1, - 'cif_total_amount' => $cifTotalAmount, - 'cif_total_amount_symbol' => $cifTotalAmountSymbol, - 'profit' => number_format($totalProfit, 2, '.', ''), - 'profit_symbol' => $cifTotalAmountSymbol // 假设利润使用相同货币 + // 'cif_total_amount' => $cifTotalAmount, + // 'cif_total_amount_symbol' => $cifTotalAmountSymbol, + // 'profit' => number_format($totalProfit, 2, '.', ''), + 'currency_symbol' => $item->settlement_currency // 假设利润使用相同货币 ]; + // var_dump($veh); return $veh; } @@ -613,6 +659,14 @@ class StockOrdersService return $this->postProcess('Print', $item); } + public function serviceDetail(Request $request) + { + $config = $this->buildQueryConfig($request, 'detail'); + $item = $this->logicShow($config); + $pdfData = $this->pdfData($item); + return $this->postProcess('Detail', $pdfData); + } + /** * 审批 */ @@ -783,10 +837,11 @@ class StockOrdersService */ private function processVehicleItems($order, array $vehList): void { - $cifTotalAmount = 0; - $cifTotalAmountRate = 0; - $cifTotalAmountCurrency = 'CNY'; + $cifTotalAmount = 0.00; + // $cifTotalAmountRate = 0; + // $cifTotalAmountCurrency = 'CNY'; + $profitTotalAmount = 0.00; foreach ($vehList as $veh) { $veh['order_id'] = $order->id; $veh['unique_id'] = $this->generateVehicleUniqueId($veh); @@ -798,23 +853,27 @@ class StockOrdersService // 计算利润 $profit = $this->calculateProfit($veh, $order); - $item->addMoney('profit', $veh['unit_price']['currency'], $profit, $veh['unit_price']['rate'], '利润'); + $item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润'); // 累计到岸价 $cifTotalAmount += $veh['total_price']['amount'] ?? 0; - if (isset($veh['retrofit_fee']['rate'])) { - $cifTotalAmountRate = $veh['retrofit_fee']['rate']; - } - if (isset($veh['retrofit_fee']['currency'])) { - $cifTotalAmountCurrency = $veh['retrofit_fee']['currency']; - } + $profitTotalAmount += $profit; + + // if (isset($veh['retrofit_fee']['rate'])) { + // $cifTotalAmountRate = $veh['retrofit_fee']['rate']; + // } + // if (isset($veh['retrofit_fee']['currency'])) { + // $cifTotalAmountCurrency = $veh['retrofit_fee']['currency']; + // } // 处理改装项 $this->processModificationItems($item->id, $veh['modify_list'] ?? []); } // 保存合计到岸价 - $order->addMoney('cif_total_amount', $cifTotalAmountCurrency, $cifTotalAmount, $cifTotalAmountRate, '合计到岸价'); + $order->addMoney('cif_total_amount', $order->settlement_currency, $cifTotalAmount, $order->contract_exchange_rate, '合计到岸价'); + // 利润 + $order->addMoney('profit_total', $order->settlement_currency, $profitTotalAmount, $order->contract_exchange_rate, '总利润'); } /**