diff --git a/app/common/controller/PurchaseOrdersController.php b/app/common/controller/PurchaseOrdersController.php
index 57ce0e0..5c87198 100644
--- a/app/common/controller/PurchaseOrdersController.php
+++ b/app/common/controller/PurchaseOrdersController.php
@@ -27,14 +27,21 @@ class PurchaseOrdersController extends BaseController
{
if (isset($data['records']) && count($data['records']) > 0) {
foreach ($data['records'] as &$record) {
+ $contractFile = $record['contract_file'] ? explode(',', $record['contract_file']) : [];
+ $contractFileUrl = [];
+ if (count($contractFile) > 0) {
+ foreach ($contractFile as $file) {
+ $contractFileUrl[] = (new \app\common\service\OssService)->generatePrivateUrl($file);
+ }
+ }
$result = [
'id' => $record['id'],
'po_no' => $record['po_no'],
'pi_no' => $record['pi_no'],
'buyer_id' => $record['buyer_id'],
'buyer_name' => $record['buyer_name'],
- 'contract_file' => $record['contract_file'],
- 'contract_file_url' => $record['contract_file'] ? (new \app\common\service\OssService)->generatePrivateUrl($data['contract_file']) : '',
+ 'contract_file' => $contractFile,
+ 'contract_file_url' => $contractFileUrl,
'status' => $record['status'],
'remark' => $record['remark'],
'created_at' => date('Y-m-d H:i:s', strtotime($record['created_at'])),
@@ -55,14 +62,21 @@ class PurchaseOrdersController extends BaseController
*/
protected function showFormat($data)
{
+ $contractFile = $data['contract_file'] ? explode(',', $data['contract_file']) : [];
+ $contractFileUrl = [];
+ if (count($contractFile) > 0) {
+ foreach ($contractFile as $file) {
+ $contractFileUrl[] = (new \app\common\service\OssService)->generatePrivateUrl($file);
+ }
+ }
$result = [
'id' => $data['id'],
'po_no' => $data['po_no'],
'pi_no' => $data['pi_no'],
'buyer_id' => $data['buyer_id'],
'buyer_name' => $data['buyer_name'],
- 'contract_file' => $data['contract_file'],
- 'contract_file_url' => $data['contract_file'] ? (new \app\common\service\OssService)->generatePrivateUrl($data['contract_file']) : '',
+ 'contract_file' => $contractFile,
+ 'contract_file_url' => $contractFileUrl,
'status' => $data['status'],
'remark' => $data['remark']
];
diff --git a/app/common/service/PurchaseOrdersService.php b/app/common/service/PurchaseOrdersService.php
index 40155f8..fe624e4 100644
--- a/app/common/service/PurchaseOrdersService.php
+++ b/app/common/service/PurchaseOrdersService.php
@@ -163,7 +163,6 @@ class PurchaseOrdersService
switch ($scene) {
case 'index':
- // $config['where']['status'] = 1;
$config['order']['id'] = 'desc';
break;
case 'update':
@@ -193,29 +192,18 @@ class PurchaseOrdersService
// 构建查询条件
$config = $this->buildQueryConfig($request, 'update');
- // 删除采购单明细
+ // 软删除采购单明细
$order = $this->logicShow($config);
if ($order && $order->items) {
- PurchaseOrderItems::where('purchase_order_id', $order->id)->delete();
+ foreach ($order->items as $item) {
+ $item->delete();
+ }
}
- // 删除采购单主表
- $deleted = $this->logicDeleteBy($config);
+ // 软删除采购单主表
+ $order->delete();
- return $this->postProcess('Destroy', $deleted);
+ return $this->postProcess('Destroy', $order);
});
}
-
-
-// protected function afterServiceShow($item)
-// {
-
-// $item['items'] = $item->items->map(function ($item) {
-// $item['stock_order'] = $item->stockOrderItems;
-// return $item;
-// });
-// var_dump($item->toArray());
-// return $item;
-
-// }
}
\ No newline at end of file
diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php
index 6880b6d..ee34158 100644
--- a/app/common/service/StockOrdersService.php
+++ b/app/common/service/StockOrdersService.php
@@ -710,7 +710,7 @@ class StockOrdersService
$purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0);
$taxRefund = (float)($veh['tax_refund']['amount'] ?? 0);
- // 退税额 tax_refund 是增加利润的,所以用加法
+ // 退税额 是增加利润
return $unitPrice - $ttPrice - $ddPrice - $handlingFee - $fobTransportFee - $portMiscFee - $retrofitFee - $oceanFreight - $commission - $purchaseTax + $taxRefund;
}
@@ -819,6 +819,14 @@ class StockOrdersService
// 如果已存在相同车辆,增加数量
if (isset($vehList[$v->unique_id])) {
$this->incrementVehicleCount($vehList[$v->unique_id], $currencyInfo);
+ // 拼接 remark 值
+ if (!empty($v->remark)) {
+ if (!empty($vehList[$v->unique_id]['remark'])) {
+ $vehList[$v->unique_id]['remark'] .= "; " . $v->remark;
+ } else {
+ $vehList[$v->unique_id]['remark'] = $v->remark;
+ }
+ }
continue;
}
@@ -840,7 +848,8 @@ class StockOrdersService
'color_exterior_snapshot' => $v->color_exterior_snapshot,
'num' => 1,
'modify' => $modificationText,
- 'mileage' => $v->mileage
+ 'mileage' => $v->mileage,
+ 'remark' => $v->remark,
] + $moneyValues;
// 添加利润信息
diff --git a/app/common/utils/pdf/template/stockOrder.stub b/app/common/utils/pdf/template/stockOrder.stub
index a11bfa1..e559157 100644
--- a/app/common/utils/pdf/template/stockOrder.stub
+++ b/app/common/utils/pdf/template/stockOrder.stub
@@ -110,7 +110,7 @@
| 阿里订单号/PI号: |
日期: |
- 关目的国: |
+ 清关目的国: |
客户来源: |
客户名称: |
客户所在国: |
@@ -174,6 +174,11 @@
|
|
+
+ |
+ 备注:
+ |
+
diff --git a/app/common/validate/StockOrdersValidate.php b/app/common/validate/StockOrdersValidate.php
index 78fccf3..884f3ae 100644
--- a/app/common/validate/StockOrdersValidate.php
+++ b/app/common/validate/StockOrdersValidate.php
@@ -6,24 +6,204 @@ use think\Validate;
class StockOrdersValidate extends Validate
{
- // 规则
+ /**
+ * 验证规则
+ */
protected $rule = [
-
+ 'id' => 'number|egt:0',
+ 'order_no' => 'require|max:40|unique:stock_orders',
+ 'pi_no' => 'require|max:64',
+ 'biz_date' => 'require',
+ 'salesperson_id' => 'number|egt:0',
+ 'salesperson_snapshot' => 'max:64',
+ 'clearance_country_id' => 'require|number|egt:0',
+ 'clearance_country_snapshot' => 'require|max:64',
+ 'customer_source_id' => 'require|number|egt:0',
+ 'customer_source_snapshot' => 'require|max:64',
+ 'customer_id' => 'require|number|egt:0',
+ 'customer_snapshot' => 'require|max:128',
+ 'customer_country_id' => 'require|number|egt:0',
+ 'customer_country_snapshot' => 'require|max:64',
+ 'declarant_name' => 'require|max:64',
+ 'eta_ship_date' => 'number|egt:0',
+ 'shipping_method_id' => 'require|number',
+ 'shipping_method_snapshot' => 'require|max:32',
+ 'cif_total_amount' => 'require|float|egt:0',
+ 'domestic_port_id' => 'require|number|egt:0',
+ 'domestic_port_snapshot' => 'require|max:64',
+ 'trade_term_id' => 'require|number|egt:0',
+ 'trade_term_snapshot' => 'require|max:64',
+ 'clearance_port_id' => 'require|number|egt:0',
+ 'clearance_port_snapshot' => 'require|max:64',
+ 'latest_arrival_date' => 'number|egt:0',
+ 'contract_exchange_rate' => 'require|float|egt:0',
+ 'settlement_currency' => 'require|length:3|alpha',
+ 'remark' => 'max:255',
+ 'contract' => 'max:255',
+ 'is_use' => 'in:0,1',
+ 'object_id' => 'number|egt:0',
+ 'is_final' => 'in:0,1',
+ 'approval_status' => 'in:0,1,2,3',
+ 'status' => 'in:0,1',
+ 'file_url' => 'max:255',
+ 'pick_up_date' => 'number|egt:0',
+ 'collect_all_date' => 'number|egt:0',
+ 'created_at' => 'number|egt:0',
+ 'updated_at' => 'number|egt:0',
+ 'deleted_at' => 'number|egt:0',
];
- // 提示
+ /**
+ * 错误提示信息
+ */
protected $message = [
-
+ 'order_no.require' => '备货单编号不能为空',
+ 'order_no.max' => '备货单编号长度不能超过40个字符',
+ 'order_no.unique' => '备货单编号已存在',
+ 'pi_no.require' => 'PI号不能为空',
+ 'pi_no.max' => 'PI号长度不能超过64个字符',
+ 'biz_date.require' => '单据日期不能为空',
+ 'clearance_country_id.require' => '清关目的国ID不能为空',
+ 'clearance_country_snapshot.require' => '清关目的国名称不能为空',
+ 'customer_source_id.require' => '客户来源ID不能为空',
+ 'customer_source_snapshot.require' => '客户来源名称不能为空',
+ 'customer_id.require' => '客户ID不能为空',
+ 'customer_snapshot.require' => '客户名称不能为空',
+ 'customer_country_id.require' => '客户所在国ID不能为空',
+ 'customer_country_snapshot.require' => '客户所在国名称不能为空',
+ 'declarant_name.require' => '清关人不能为空',
+ 'shipping_method_id.require' => '出运方式ID不能为空',
+ 'shipping_method_snapshot.require' => '出运方式不能为空',
+ 'cif_total_amount.require' => '合计到岸价不能为空',
+ 'cif_total_amount.float' => '合计到岸价必须为数字',
+ 'cif_total_amount.egt' => '合计到岸价不能为负数',
+ 'domestic_port_id.require' => '国内收货港ID不能为空',
+ 'domestic_port_snapshot.require' => '国内收货港名称不能为空',
+ 'trade_term_id.require' => '贸易条款ID不能为空',
+ 'trade_term_snapshot.require' => '贸易条款名称不能为空',
+ 'clearance_port_id.require' => '清关目的港ID不能为空',
+ 'clearance_port_snapshot.require' => '清关目的港名称不能为空',
+ 'contract_exchange_rate.require' => '合同汇率不能为空',
+ 'contract_exchange_rate.float' => '合同汇率必须为数字',
+ 'contract_exchange_rate.egt' => '合同汇率不能为负数',
+ 'settlement_currency.require' => '结算币种不能为空',
+ 'settlement_currency.length' => '结算币种必须为3个字符',
+ 'settlement_currency.alpha' => '结算币种必须为字母',
+ 'approval_status.in' => '审批状态值不正确',
+ 'status.in' => '状态值不正确',
+ 'is_final.in' => '是否终版值不正确',
+ 'is_use.in' => '是否开过终版值不正确',
];
- // 场景
+ /**
+ * 验证场景
+ */
protected $scene = [
+ // 创建场景
'store' => [
-
+ 'pi_no', 'biz_date',
+ 'clearance_country_id', 'clearance_country_snapshot', 'customer_source_id',
+ 'customer_source_snapshot', 'customer_id', 'customer_snapshot',
+ 'customer_country_id', 'customer_country_snapshot', 'declarant_name',
+ 'shipping_method_id', 'shipping_method_snapshot',
+ 'domestic_port_id', 'domestic_port_snapshot',
+ 'trade_term_id', 'trade_term_snapshot', 'clearance_port_id',
+ 'clearance_port_snapshot', 'contract_exchange_rate',
+ 'settlement_currency'
],
-
+
+ // 更新场景
'update' => [
-
+ 'pi_no', 'biz_date',
+ 'clearance_country_id', 'clearance_country_snapshot', 'customer_source_id',
+ 'customer_source_snapshot', 'customer_id', 'customer_snapshot',
+ 'customer_country_id', 'customer_country_snapshot', 'declarant_name',
+ 'shipping_method_id', 'shipping_method_snapshot',
+ 'domestic_port_id', 'domestic_port_snapshot',
+ 'trade_term_id', 'trade_term_snapshot', 'clearance_port_id',
+ 'clearance_port_snapshot', 'contract_exchange_rate',
+ 'settlement_currency'
+ ],
+
+ // 提交审批场景
+ 'submit' => [
+ 'id' => 'require|number|egt:1',
+ 'status' => 'require|in:1'
+ ],
+
+ // 审批场景
+ 'approve' => [
+ 'id' => 'require|number|egt:1',
+ 'approval_status' => 'require|in:1,2,3'
+ ],
+
+ // 状态更新场景
+ 'status' => [
+ 'id' => 'require|number|egt:1',
+ 'status' => 'require|in:0,1'
+ ],
+
+ // 简略验证场景(用于快速验证)
+ 'simple' => [
+ 'order_no', 'biz_date', 'cif_total_amount', 'settlement_currency'
]
];
+
+ /**
+ * 自定义验证规则 - 验证时间戳是否合理
+ */
+ protected function checkTimestamp($value, $rule, $data = [])
+ {
+ if ($value === 0 || $value === '0') {
+ return true;
+ }
+
+ // 时间戳应该在1970年到现在+1年的范围内
+ $minTimestamp = 0;
+ $maxTimestamp = time() + (365 * 24 * 60 * 60);
+
+ return $value >= $minTimestamp && $value <= $maxTimestamp;
+ }
+
+ /**
+ * 自定义验证规则 - 验证金额格式
+ */
+ protected function checkMoney($value, $rule, $data = [])
+ {
+ if (!is_numeric($value)) {
+ return false;
+ }
+
+ // 验证小数点位数不超过2位
+ if (strpos($value, '.') !== false) {
+ $decimalPart = explode('.', $value)[1];
+ if (strlen($decimalPart) > 2) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * 场景验证前回调 - 添加自定义规则
+ */
+ // protected function sceneBefore($scene)
+ // {
+ // // 为时间戳字段添加自定义验证
+ // $timestampFields = ['biz_date', 'eta_ship_date', 'latest_arrival_date', 'pick_up_date', 'collect_all_date', 'created_at', 'updated_at', 'deleted_at'];
+ // foreach ($timestampFields as $field) {
+ // if (isset($this->scene[$scene][$field])) {
+ // $this->rule[$field] .= '|checkTimestamp';
+ // }
+ // }
+
+ // // 为金额字段添加自定义验证
+ // $moneyFields = ['cif_total_amount', 'contract_exchange_rate'];
+ // foreach ($moneyFields as $field) {
+ // if (isset($this->scene[$scene][$field])) {
+ // $this->rule[$field] .= '|checkMoney';
+ // }
+ // }
+ // }
}
\ No newline at end of file
diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php
index cd5e64f..8dd01f6 100644
--- a/app/controller/IndexController.php
+++ b/app/controller/IndexController.php
@@ -9,6 +9,7 @@ use app\common\utils\scaffold\Generate;
use support\Request;
use support\Db;
use support\Cache;
+use support\Redis;
class IndexController
{
@@ -100,14 +101,9 @@ class IndexController
public function test(Request $request)
{
+ $service = new \app\crm\service\StockOrdersService();
+ $result = $service->createdPdfFile(35);
- // $list = (new \app\common\logic\PurchaseOrdersLogic())->getPiList()->toArray();
-
-
- // $list = (new \app\common\logic\PurchaseOrdersLogic())->getOrderNoListByPiNo('ces1222')->toArray();
-
-
- // $list = (new \app\common\logic\PurchaseOrdersLogic())->getOrderItemsListByOrderNo(32)->toArray();
- // var_dump($list);
+ return json($result);
}
}
\ No newline at end of file
diff --git a/config/plugin/webman/gateway-worker/process.php b/config/plugin/webman/gateway-worker/process.php
index 64796e9..a429973 100644
--- a/config/plugin/webman/gateway-worker/process.php
+++ b/config/plugin/webman/gateway-worker/process.php
@@ -22,7 +22,7 @@ return [
],
'worker' => [
'handler' => BusinessWorker::class,
- 'count' => cpu_count()*2,
+ 'count' => 6,
'constructor' => ['config' => [
'eventHandler' => plugin\webman\gateway\Events::class,
'name' => 'ChatBusinessWorker',