Finish mzl_dev
This commit is contained in:
@@ -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'
|
||||
'object_id', 'contract', 'is_use', 'is_final', 'approval_status', 'file_url', 'pick_up_date', 'collect_all_date'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,23 +140,27 @@
|
||||
<th>颜色/外</th>
|
||||
<th>内饰</th>
|
||||
<th>改装</th>
|
||||
<th class="nowrap">官方指导价/二手挂牌价</th>
|
||||
<th class="nowrap">优惠</th>
|
||||
<th class="nowrap">单价</th>
|
||||
<th class="nowrap">总价</th>
|
||||
<th class="nowrap">官方指导价/二手挂牌价</th>
|
||||
<th class="nowrap">优惠/二手减价</th>
|
||||
<th class="nowrap">利润</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach (($data['veh_list'] ?? []) as $vehicle): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($vehicle['index'] ?? ' - '); ?></td>
|
||||
<td><?php echo htmlspecialchars($vehicle['model_snapshot'] ?? ' - '); ?></td>
|
||||
<td>
|
||||
<?php echo htmlspecialchars($vehicle['model_snapshot'] ?? ' - '); ?>
|
||||
<?php if ($vehicle['mileage'] > 0): ?>
|
||||
<span class="nowrap">(<?php echo htmlspecialchars($vehicle['mileage']).'km'; ?>)</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($vehicle['num'] ?? ' - '); ?></td>
|
||||
<td><?php echo htmlspecialchars($vehicle['color_exterior_snapshot'] ?? ' - '); ?></td>
|
||||
<td><?php echo htmlspecialchars($vehicle['color_interior_snapshot'] ?? ' - '); ?></td>
|
||||
<td><?php echo htmlspecialchars($vehicle['modify'] ?? ' - '); ?></td>
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['unit_price_text'] ?? ' - '); ?></td>
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['total_price_text'] ?? ' - '); ?></td>
|
||||
|
||||
<?php if ($vehicle['mileage'] > 0): ?>
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['listing_price'] ?? ' - '); ?></td>
|
||||
@@ -166,6 +170,9 @@
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['discount_price'] ?? ' - '); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['unit_price_text'] ?? ' - '); ?></td>
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['total_price_text'] ?? ' - '); ?></td>
|
||||
<td class="nowrap"><?php echo htmlspecialchars($vehicle['profit_text'] ?? ' - '); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -173,7 +180,7 @@
|
||||
<td colspan="6" style="text-align:left;">
|
||||
<span class="info-label">合同汇率:</span> <span class="info-value"><?php echo htmlspecialchars($data['contract_exchange_rate'] ?? ' - '); ?></span>
|
||||
</td>
|
||||
<td colspan="4" style="text-align:left;">
|
||||
<td colspan="5" style="text-align:left;">
|
||||
<span class="info-label">合计到岸价:</span> <span class="info-value"><?php echo htmlspecialchars($data['cif_total_amount'] ?? ' - '); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -193,11 +200,23 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><span class="info-label">清关人:</span> <span class="info-value"><?php echo htmlspecialchars($data['declarant_name'] ?? ' - '); ?></span></td>
|
||||
<td><span class="info-label">预计发运日期:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['eta_ship_date'] ?? ' - '); ?></span></td>
|
||||
|
||||
<?php if ($data['is_final'] == 1): ?>
|
||||
<td><span class="info-label">全款收齐日:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['collect_all_date'] ?? ' - '); ?></span></td>
|
||||
<?php else: ?>
|
||||
<td><span class="info-label">预计发运日期:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['eta_ship_date'] ?? ' - '); ?></span></td>
|
||||
<?php endif; ?>
|
||||
|
||||
<td><span class="info-label">出运方式:</span> <span class="info-value"><?php echo htmlspecialchars($data['shipping_method_snapshot'] ?? ' - '); ?></span></td>
|
||||
<td><span class="info-label">国内收货港:</span> <span class="info-value"><?php echo htmlspecialchars($data['domestic_port_snapshot'] ?? ' - '); ?></span></td>
|
||||
<td><span class="info-label">贸易条款/清关目的港:</span> <span class="info-value"><?php echo htmlspecialchars($data['trade_term_snapshot'] ?? ' - '); ?>/<?php echo htmlspecialchars($data['clearance_port_snapshot'] ?? ' - '); ?></span></td>
|
||||
<td><span class="info-label">最迟到港时间:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['latest_arrival_date'] ?? ' - '); ?></span></td>
|
||||
|
||||
<?php if ($data['is_final'] == 1): ?>
|
||||
<td><span class="info-label">提车日期:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['pick_up_date'] ?? ' - '); ?></span></td>
|
||||
<?php else: ?>
|
||||
<td><span class="info-label">最迟到港时间:</span> <span class="info-value nowrap"><?php echo htmlspecialchars($data['latest_arrival_date'] ?? ' - '); ?></span></td>
|
||||
<?php endif; ?>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -241,7 +260,6 @@
|
||||
</table>
|
||||
|
||||
<!-- PDF 底部签名区 -->
|
||||
<!-- PDF 底部签名区(无表格版本) -->
|
||||
<div style="margin-top: 6mm; font-size: 12px;">
|
||||
<!-- 左侧:业务员签字 / 备发货负责人签字 -->
|
||||
<div style="width: 50%; float: left; text-align: left;">
|
||||
|
||||
@@ -96,7 +96,7 @@ class IndexController
|
||||
}
|
||||
|
||||
|
||||
public function test()
|
||||
public function test(Request $request)
|
||||
{
|
||||
|
||||
|
||||
@@ -127,8 +127,15 @@ class IndexController
|
||||
// $up = new UploadService();
|
||||
// $res = $up->uploadLocalFile($param);
|
||||
// var_dump($res);
|
||||
|
||||
$service = new \app\common\service\StockOrdersService();
|
||||
$service->createdPdfFile(60);
|
||||
$param = $request->all();
|
||||
try {
|
||||
$service = new \app\crm\service\StockOrdersService();
|
||||
$result = $service->createdPdfFile($param['id']);
|
||||
return json($result);
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
var_dump($th->getMessage().$th->getLine().$th->getFile());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,8 @@ class StockOrdersController extends BaseController
|
||||
if (isset($data['eta_ship_date'])) $data['eta_ship_date'] = date('Y-m-d', $data['eta_ship_date']);
|
||||
if (isset($data['biz_date'])) $data['biz_date'] = date('Y-m-d', $data['biz_date']);
|
||||
if (isset($data['latest_arrival_date'])) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']);
|
||||
if (isset($data['pick_up_date'])) $data['pick_up_date'] = date('Y-m-d', $data['pick_up_date']);
|
||||
if (isset($data['collect_all_date'])) $data['collect_all_date'] = date('Y-m-d', $data['collect_all_date']);
|
||||
|
||||
if (!empty($data['contract'])) {
|
||||
$data['contract_url'] = (new \app\common\service\OssService)->generatePrivateUrl($data['contract']);
|
||||
@@ -127,7 +129,9 @@ class StockOrdersController extends BaseController
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取打印数据
|
||||
*/
|
||||
public function print(Request $request)
|
||||
{
|
||||
try {
|
||||
@@ -141,7 +145,21 @@ class StockOrdersController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动审批
|
||||
*/
|
||||
public function approval(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceApproval($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'approvalFormat')
|
||||
? [$this, 'approvalFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function desc(Request $request)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,444 @@
|
||||
<?php
|
||||
|
||||
namespace app\crm\service;
|
||||
|
||||
use app\common\model\StockOrderAccounts;
|
||||
use app\common\model\StockOrderItemOptions;
|
||||
use app\common\model\StockOrderItems;
|
||||
use app\common\validate\StockOrdersValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\StockOrders;
|
||||
use app\common\model\SysCurrency;
|
||||
use support\Request;
|
||||
use app\common\model\User;
|
||||
use support\exception\BusinessException;
|
||||
use support\Db;
|
||||
|
||||
class StockOrdersService_bak
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = StockOrders::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = StockOrdersValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 业务id
|
||||
if (isset($p['salesperson_id']) && $p['salesperson_id']) {
|
||||
$config['where']['salesperson_id'] = $p['salesperson_id'];
|
||||
}
|
||||
// 初、终版
|
||||
$config['where']['is_final'] = $p['is_final'] ?? 0;
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['pi_no', 'order_no', 'customer_snapshot'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
$config['where']['salesperson_id'] = $request->user->uid;
|
||||
break;
|
||||
case 'print':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
|
||||
$config['with'][] = 'items';
|
||||
$config['with'][] = 'items.options';
|
||||
$config['with'][] = 'items.moneyValues';
|
||||
$config['with'][] = 'accounts';
|
||||
$config['with'][] = 'moneyValues';
|
||||
$config['with'][] = 'salesperson';
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function serviceStore(Request $request, array $data = [])
|
||||
{
|
||||
// 关联表较多,增加事务处理
|
||||
return Db::transaction(function () use ($request, $data) {
|
||||
$data = $this->preProcess('Store', $data, $request);
|
||||
$dl = $this->getDataLimitFromRequest($request);
|
||||
$created = $this->logicCreate($data, $dl); // 表1
|
||||
|
||||
// 车辆
|
||||
$cifTotalAmount = 0;
|
||||
$cifTotalAmountRate = 0;
|
||||
$cifTotalAmountCurrency = 'CNY';
|
||||
// $profit = 0;
|
||||
foreach ($data['veh_list'] as $veh) {
|
||||
$veh['order_id'] = $created->id;
|
||||
|
||||
// 唯一标识
|
||||
$uniqueIdStr = "";
|
||||
$uniqueIdStr .= $veh['sku_id'];
|
||||
$uniqueIdStr .= $veh['model_snapshot'];
|
||||
$uniqueIdStr .= $veh['color_interior_code'];
|
||||
$uniqueIdStr .= $veh['color_exterior_code'];
|
||||
$uniqueIdStr .= $veh['mileage'];
|
||||
$uniqueIdStr .= json($veh['modify_list']);
|
||||
$veh['unique_id'] = md5($uniqueIdStr);
|
||||
$item = StockOrderItems::create($veh); // 表2
|
||||
|
||||
// 金额 // 表3
|
||||
// $item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
// $item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
if ($veh['unit_price']['amount']) {
|
||||
$item->addMoney('unit_price', $veh['unit_price']['currency'], $veh['unit_price']['amount'], $veh['unit_price']['rate'], '单价');
|
||||
}
|
||||
if ($veh['total_price']['amount']) {
|
||||
$item->addMoney('total_price', $veh['total_price']['currency'], $veh['total_price']['amount'], $veh['total_price']['rate'], '总价');
|
||||
}
|
||||
if ($veh['handling_fee']['amount']) {
|
||||
$item->addMoney('handling_fee', $veh['handling_fee']['currency'], $veh['handling_fee']['amount'], $veh['handling_fee']['rate'], '手续费');
|
||||
}
|
||||
if ($veh['fob_transport_fee']['amount']) {
|
||||
$item->addMoney('fob_transport_fee', $veh['fob_transport_fee']['currency'], $veh['fob_transport_fee']['amount'], $veh['fob_transport_fee']['rate'], 'FOB运输费');
|
||||
}
|
||||
if ($veh['port_misc_fee']['amount']) {
|
||||
$item->addMoney('port_misc_fee', $veh['port_misc_fee']['currency'], $veh['port_misc_fee']['amount'], $veh['port_misc_fee']['rate'], '港杂');
|
||||
}
|
||||
if ($veh['retrofit_fee']['amount']) {
|
||||
$item->addMoney('retrofit_fee', $veh['retrofit_fee']['currency'], $veh['retrofit_fee']['amount'], $veh['retrofit_fee']['rate'], '改装费');
|
||||
}
|
||||
if ($veh['ocean_freight']['amount']) {
|
||||
$item->addMoney('ocean_freight', $veh['ocean_freight']['currency'], $veh['ocean_freight']['amount'], $veh['ocean_freight']['rate'], '海运费');
|
||||
}
|
||||
|
||||
// 二手车 or 新车
|
||||
if ($veh['mileage'] > 0) {
|
||||
if ($veh['listing_price']['amount']) {
|
||||
$item->addMoney('listing_price', $veh['listing_price']['currency'], $veh['listing_price']['amount'], $veh['listing_price']['rate'], '二手挂牌价');
|
||||
}
|
||||
if ($veh['reduction_price']['amount']) {
|
||||
$item->addMoney('reduction_price', $veh['reduction_price']['currency'], $veh['reduction_price']['amount'], $veh['reduction_price']['rate'], '二手减价');
|
||||
}
|
||||
|
||||
$ttPrice = ($veh['listing_price']['amount'] / $created->contract_exchange_rate);
|
||||
$ddPrice = $veh['reduction_price']['amount'];
|
||||
} else {
|
||||
if ($veh['official_price']['amount']) {
|
||||
$item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
}
|
||||
if ($veh['discount_price']['amount'] ) {
|
||||
$item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
}
|
||||
|
||||
$ttPrice = ($veh['official_price']['amount'] / $created->contract_exchange_rate);
|
||||
$ddPrice = $veh['discount_price']['amount'];
|
||||
}
|
||||
|
||||
// 利润
|
||||
$profit = (float)$veh['unit_price']['amount']
|
||||
- (float)$ttPrice
|
||||
- (float)$ddPrice
|
||||
- (float)$veh['handling_fee']['amount']
|
||||
- (float)$veh['fob_transport_fee']['amount']
|
||||
- (float)$veh['port_misc_fee']['amount']
|
||||
- (float)$veh['retrofit_fee']['amount']
|
||||
- (float)$veh['ocean_freight']['amount'];
|
||||
$item->addMoney('profit', $veh['unit_price']['currency'], $profit, $veh['unit_price']['rate'], '利润');
|
||||
|
||||
// cif_total_amount
|
||||
$cifTotalAmount += $veh['total_price']['amount'];
|
||||
$cifTotalAmountRate = $veh['retrofit_fee']['rate'];
|
||||
$cifTotalAmountCurrency = $veh['retrofit_fee']['currency'];
|
||||
|
||||
// 改装
|
||||
if (count($veh['modify_list']) > 0) {
|
||||
foreach ($veh['modify_list'] as $modify) {
|
||||
$modify['order_item_id'] = $item->id;
|
||||
StockOrderItemOptions::create($modify); // 表4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算&&插入 表1
|
||||
$created->addMoney('cif_total_amount', $cifTotalAmountCurrency, $cifTotalAmount, $cifTotalAmountRate, '合计到岸价');
|
||||
|
||||
// 账户
|
||||
if (count($data['account_list']) > 0) {
|
||||
foreach ($data['account_list'] as $account) {
|
||||
$account['order_id'] = $created->id;
|
||||
$account['remit_date'] = strtotime($account['remit_date']);
|
||||
StockOrderAccounts::create($account); // 表5
|
||||
}
|
||||
}
|
||||
|
||||
return $this->postProcess('Store', $created);
|
||||
});
|
||||
}
|
||||
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$userId = $request->user->uid;
|
||||
|
||||
$data['order_no'] = generateStockNo();
|
||||
$data['biz_date'] = strtotime($data['biz_date']);
|
||||
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
||||
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
||||
$data['salesperson_id'] = $userId;
|
||||
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterServiceStore($res)
|
||||
{
|
||||
// 处理原单
|
||||
if ($res->is_final == 1 && $res->object_id > 0) {
|
||||
$order = StockOrders::find($res->object_id);
|
||||
$order->is_use = 1;
|
||||
$order->object_id = $res->id;
|
||||
if (!$order->save()) {
|
||||
flg('备货单【'.$order->order_no.'】创建终版成功,但更新原单失败');
|
||||
}
|
||||
}
|
||||
// 启动审批
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
$result = $appro->start('stock_order_flow', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id);
|
||||
var_dump($result);
|
||||
|
||||
// 异步生成pdf文件
|
||||
\Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$res->id]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
public function createdPdfFile($id)
|
||||
{
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
$config['where']['id'] = $id;
|
||||
$config['with'][] = 'items';
|
||||
$config['with'][] = 'items.options';
|
||||
$config['with'][] = 'items.moneyValues';
|
||||
$config['with'][] = 'accounts';
|
||||
$config['with'][] = 'moneyValues';
|
||||
$config['with'][] = 'salesperson';
|
||||
$item = $this->logicShow($config);
|
||||
$pdfData = $this->pdfData($item);
|
||||
|
||||
// 渲染模板为最终HTML
|
||||
$tplPath = app_path('common/utils/pdf/template/stockOrder.stub');
|
||||
$html = \app\common\utils\pdf\service\PdfHelper::render($tplPath, ['data' => $pdfData]);
|
||||
|
||||
// 生成PDF
|
||||
$driver = new \app\common\utils\pdf\service\MpdfDriver();
|
||||
$pdfBin = $driver->htmlToPdf($html);
|
||||
|
||||
// 存储
|
||||
$dir = public_path('pdf').'/';
|
||||
$fileName = ($pdfData['order_no'] ?? date('YmdHis')) . '.pdf';
|
||||
|
||||
// 本地保存
|
||||
\app\common\utils\pdf\service\PdfStorage::saveBinary(
|
||||
$pdfBin,
|
||||
$dir,
|
||||
$fileName
|
||||
);
|
||||
|
||||
// // 在线预览
|
||||
// return new \support\Response(200, [
|
||||
// 'Content-Type' => 'application/pdf',
|
||||
// 'Content-Disposition' => 'inline; filename="stock-order.pdf"',
|
||||
// ], $pdfBin);
|
||||
|
||||
// $url = [
|
||||
// 'file_name' => $fileName,
|
||||
// 'file_url' => getenv('MAIN_DOMAIN').'/pdf/'.$fileName
|
||||
// ];
|
||||
|
||||
// 上传云端
|
||||
$param = [
|
||||
'path' => $dir . $fileName,
|
||||
'scene' => 'stock_orders',
|
||||
'category' => 'pdf',
|
||||
'original_name' => $fileName
|
||||
];
|
||||
$up = new \app\common\service\UploadService();
|
||||
$res = $up->uploadLocalFile($param);
|
||||
|
||||
@unlink($dir . $fileName);
|
||||
|
||||
// 更新文件地址
|
||||
$item->file_url = $res['file_name'];
|
||||
$item->save();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function servicePrint(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'show');
|
||||
$item = $this->logicShow($config);
|
||||
return $this->postProcess('Print', $item);
|
||||
}
|
||||
|
||||
|
||||
public function pdfData($item)
|
||||
{
|
||||
$vehList = [];
|
||||
$index = 0;
|
||||
foreach ($item->items as $k => $v) {
|
||||
// 存在则数量加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, '.', ',');
|
||||
continue;
|
||||
}
|
||||
$index += 1;
|
||||
// 处理金额
|
||||
$mv = [];
|
||||
foreach ($v->moneyValues as $money) {
|
||||
$mv[$money->field] = [
|
||||
'currency' => $money->currency,
|
||||
'amount' => $money->amount,
|
||||
'rate' => $money->exchange_rate,
|
||||
'currency_symbol' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'),
|
||||
];
|
||||
}
|
||||
// 处理改装
|
||||
$mfy = '';
|
||||
foreach ($v->options as $my) {
|
||||
$mfy .= $my->option_name_snapshot.' ';
|
||||
}
|
||||
|
||||
// 处理结果集
|
||||
$vehList[$v->unique_id] = [
|
||||
'index' => $index,
|
||||
'model_snapshot' => $v->model_snapshot,
|
||||
'color_interior_snapshot' => $v->color_interior_snapshot,
|
||||
'color_exterior_snapshot' => $v->color_exterior_snapshot,
|
||||
'num' => 1,
|
||||
'modify' => $mfy,
|
||||
'mileage' => $v->mileage,
|
||||
'unit_price' => $mv['unit_price']['amount'],
|
||||
'total_price' => $mv['total_price']['amount'],
|
||||
'unit_price_symbol' => $mv['unit_price']['currency_symbol'],
|
||||
'total_price_symbol' => $mv['total_price']['currency_symbol'],
|
||||
'unit_price_text' => $mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ','),
|
||||
'total_price_text' => $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',')
|
||||
];
|
||||
|
||||
// 根据里程处理 新车or二手车
|
||||
if ($v->mileage > 0) {
|
||||
if (isset($mv['reduction_price'])) {
|
||||
$vehList[$v->unique_id]['reduction_price'] = $mv['reduction_price']['amount'];
|
||||
$vehList[$v->unique_id]['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
$vehList[$v->unique_id]['listing_price'] = $mv['listing_price']['amount'];
|
||||
$vehList[$v->unique_id]['listing_price_symbol'] = $mv['listing_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ',');
|
||||
} else {
|
||||
if (isset($mv['discount_price'])) {
|
||||
$vehList[$v->unique_id]['discount_price'] = $mv['discount_price']['amount'];
|
||||
$vehList[$v->unique_id]['discount_price_symbol'] = $mv['discount_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
$vehList[$v->unique_id]['official_price'] = $mv['official_price']['amount'];
|
||||
$vehList[$v->unique_id]['official_price_symbol'] = $mv['official_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
}
|
||||
|
||||
$accList = [];
|
||||
$accIndex = 1;
|
||||
foreach ($item->accounts as $k => $v) {
|
||||
$accList[] = [
|
||||
'index' => '收款'.$k + 1,
|
||||
'remit_country_name_snapshot' => $v->remit_country_name_snapshot,
|
||||
'remit_date' => date('Y-m-d', $v->remit_date),
|
||||
'currency_name_snapshot' => $v->currency_name_snapshot,
|
||||
'account_name_snapshot' => $v->account_name_snapshot,
|
||||
'remitter_name' => $v->remitter_name,
|
||||
'amount' => $v->amount,
|
||||
];
|
||||
$accIndex += 1;
|
||||
}
|
||||
|
||||
$cifTotalAmount = 0.00;
|
||||
if ($item->moneyValues) {
|
||||
$cifTotalAmountSysboml = SysCurrency::where('currency_code', $item->moneyValues->currency)->value('currency_symbol');
|
||||
$cifTotalAmount = $cifTotalAmountSysboml.sprintf("%.2f", $item->moneyValues->amount, $item->moneyValues->exchange_rate);
|
||||
}
|
||||
|
||||
$veh = [
|
||||
'order_no' => $item->order_no,
|
||||
'salesperson_snapshot' => $item->salesperson_snapshot,
|
||||
// 'sign_img' => $item->salesperson->sign_img,
|
||||
'sign_img_url' => (!empty($item->salesperson->sign_img))?(new \app\common\service\OssService)->generatePrivateUrl($item->salesperson->sign_img):'',
|
||||
'created_at' => date('Y-m-d', strtotime($item->created_at)),
|
||||
|
||||
'pi_no' => $item->pi_no,
|
||||
'biz_date' => date('Y-m-d', $item->biz_date),
|
||||
'clearance_country_snapshot' => $item->clearance_country_snapshot,
|
||||
'customer_source_snapshot' => $item->customer_source_snapshot,
|
||||
'customer_snapshot' => $item->customer_snapshot,
|
||||
'customer_country_snapshot' => $item->customer_country_snapshot,
|
||||
|
||||
// 订单项
|
||||
'veh_list' => $vehList,
|
||||
|
||||
'contract_exchange_rate' => $item->contract_exchange_rate,
|
||||
'cif_total_amount' => $item->cif_total_amount,
|
||||
|
||||
'declarant_name' => $item->declarant_name,
|
||||
'eta_ship_date' => date('Y-m-d', $item->eta_ship_date),
|
||||
'shipping_method_snapshot' => $item->shipping_method_snapshot,
|
||||
'domestic_port_snapshot' => $item->domestic_port_snapshot,
|
||||
'trade_term_snapshot' => $item->trade_term_snapshot,
|
||||
'clearance_port_snapshot' => $item->clearance_port_snapshot,
|
||||
'latest_arrival_date' => date('Y-m-d', $item->latest_arrival_date),
|
||||
|
||||
// 账户
|
||||
'account_list' => $accList,
|
||||
'acc_index' => $accIndex,
|
||||
'cif_total_amount' => $cifTotalAmount
|
||||
];
|
||||
|
||||
return $veh;
|
||||
}
|
||||
}
|
||||
@@ -382,7 +382,9 @@ Route::group('/crm', function () {
|
||||
Route::any('/list', [app\crm\controller\StockOrdersController::class, 'index']);
|
||||
Route::any('/show', [app\crm\controller\StockOrdersController::class, 'show']);
|
||||
Route::any('/store', [app\crm\controller\StockOrdersController::class, 'store']);
|
||||
Route::any('/update', [app\crm\controller\StockOrdersController::class, 'update']);
|
||||
Route::any('/print', [app\crm\controller\StockOrdersController::class, 'print']);
|
||||
Route::any('/approval', [app\crm\controller\StockOrdersController::class, 'approval']);
|
||||
});
|
||||
|
||||
// 审批记录
|
||||
|
||||
Reference in New Issue
Block a user