From 36d1d333b1f9ef6ca192f8ad7a033e4999b0ba7e Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 15:13:56 +0800 Subject: [PATCH 01/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E4=B8=8E=E6=94=B6?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 33 +++++ .../controller/FinReceiptController.php | 56 ++++++++ app/common/logic/FinPaymentApplyLogic.php | 17 +++ app/common/logic/FinReceiptLogic.php | 17 +++ app/common/model/FinPaymentApply.php | 65 +++++++++ app/common/model/FinPaymentStock.php | 67 +++++++++ app/common/model/FinReceipt.php | 65 +++++++++ app/common/model/StockOrders.php | 8 ++ app/common/service/FinPaymentApplyService.php | 107 +++++++++++++++ app/common/service/FinReceiptService.php | 127 ++++++++++++++++++ .../validate/FinPaymentApplyValidate.php | 29 ++++ app/common/validate/FinReceiptValidate.php | 56 ++++++++ app/controller/IndexController.php | 38 +++--- config/route.php | 18 +++ 14 files changed, 684 insertions(+), 19 deletions(-) create mode 100644 app/common/controller/FinPaymentApplyController.php create mode 100644 app/common/controller/FinReceiptController.php create mode 100644 app/common/logic/FinPaymentApplyLogic.php create mode 100644 app/common/logic/FinReceiptLogic.php create mode 100644 app/common/model/FinPaymentApply.php create mode 100644 app/common/model/FinPaymentStock.php create mode 100644 app/common/model/FinReceipt.php create mode 100644 app/common/service/FinPaymentApplyService.php create mode 100644 app/common/service/FinReceiptService.php create mode 100644 app/common/validate/FinPaymentApplyValidate.php create mode 100644 app/common/validate/FinReceiptValidate.php diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php new file mode 100644 index 0000000..2d0f22e --- /dev/null +++ b/app/common/controller/FinPaymentApplyController.php @@ -0,0 +1,33 @@ +service = new FinPaymentApplyService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + // protected function indexFormat($data) + // { + // if (isset($data['created_at'])) + // $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + // if (isset($data['updated_at'])) + // $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + // return $data; + // } +} \ No newline at end of file diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php new file mode 100644 index 0000000..4acf899 --- /dev/null +++ b/app/common/controller/FinReceiptController.php @@ -0,0 +1,56 @@ +service = new FinReceiptService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/common/logic/FinPaymentApplyLogic.php b/app/common/logic/FinPaymentApplyLogic.php new file mode 100644 index 0000000..09b93e1 --- /dev/null +++ b/app/common/logic/FinPaymentApplyLogic.php @@ -0,0 +1,17 @@ +hasOne(FinReceipt::class, 'payment_apply_id', 'id'); + } + + /** + * 备货单 + */ + public function stock() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); + } +} \ No newline at end of file diff --git a/app/common/model/FinPaymentStock.php b/app/common/model/FinPaymentStock.php new file mode 100644 index 0000000..6f4a3ba --- /dev/null +++ b/app/common/model/FinPaymentStock.php @@ -0,0 +1,67 @@ +belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); + } + + // 收款记录 + public function receipt() + { + return $this->belongsTo(FinReceipt::class, 'receipt_id', 'id'); + } + + // 付款申请 + public function stock() + { + return $this->belongsTo(StockOrders::class, 'stock_id', 'id'); + } +} \ No newline at end of file diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php new file mode 100644 index 0000000..a98914f --- /dev/null +++ b/app/common/model/FinReceipt.php @@ -0,0 +1,65 @@ +hasOne(FinPaymentApply::class, 'id', 'payment_apply_id'); + } + + /** + * 备货单 + */ + public function stock() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); + } +} \ No newline at end of file diff --git a/app/common/model/StockOrders.php b/app/common/model/StockOrders.php index 0b97fe4..0802afe 100644 --- a/app/common/model/StockOrders.php +++ b/app/common/model/StockOrders.php @@ -95,4 +95,12 @@ class StockOrders extends Model { return $this->hasOne(User::class, 'id', 'salesperson_id'); } + + /** + * 客户的标签 + */ + public function payment() + { + return $this->belongsToMany(FinPaymentApply::class, 'fin_payment_stock', 'stock_id', 'payment_apply_id'); + } } \ No newline at end of file diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php new file mode 100644 index 0000000..00ad976 --- /dev/null +++ b/app/common/service/FinPaymentApplyService.php @@ -0,0 +1,107 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'index'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + case 'update': + case 'destroy': + $config['where']['id'] = $p['id']; + break; + case 'store': + break; + } + + return $config; + } + + public function beforeServiceStore($data, Request $request) + { + $data['apply_no'] = $this->generateUniqueApplyNo(); + $data['submit_files'] = json_encode($data['submit_files']); + return $data; + } + + public function beforeServiceUpdate($data, Request $request) + { + $data['submit_files'] = json_encode($data['submit_files']); + return $data; + } + + + /** + * 生成唯一的付款申请编码 + * 格式:PA + 日期 + 6位字母数字组合 + * + * @return string 唯一编码 + */ + public function generateUniqueApplyNo() + { + $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $maxAttempts = 10; // 防止无限循环 + $secondChar = 'PA' . date('Ymd'); + + for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { + // 生成后6位随机字符 + $suffix = ''; + for ($i = 0; $i < 6; $i++) { + $suffix .= $chars[rand(0, strlen($chars) - 1)]; + } + + $applyNo = $secondChar . $suffix; + + // 检查是否已存在 + $existing = FinPaymentApply::where('apply_no', $applyNo)->first(); + if (!$existing) { + return $applyNo; + } + } + + // 如果1000次尝试后仍然重复,使用时间戳确保唯一性 + $timestamp = substr(time(), -6); + return $secondChar . $timestamp; + } +} \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php new file mode 100644 index 0000000..2cc781c --- /dev/null +++ b/app/common/service/FinReceiptService.php @@ -0,0 +1,127 @@ +validator; + } + + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'index'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 汇款国家 + if (isset($p['country_id']) && !empty($p['country_id'])) { + $config['where']['country_id'] = $p['country_id']; + } + // 收款账户筛选 + if (isset($p['account_id']) && !empty($p['account_id'])) { + $config['where']['account_id'] = $p['account_id']; + } + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + $config['orWhere'][] = ['remitter', 'like', $k]; + } + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + case 'update': + case 'destroy': + $config['where']['id'] = $p['id']; + break; + case 'store': + break; + } + + return $config; + } + + public function beforeServiceStore($data, Request $request) + { + if(isset($data['payment_apply_id']) && empty($data['payment_apply_id'])){ + unset($data['payment_apply_id']); + } + $data['receipt_no'] = $this->generateUniqueReceipt(); + $data['arrived_at'] = strtotime( $data['arrived_at']); + return $data; + } + + public function beforeServiceUpdate($data, Request $request) + { + $data['arrived_at'] = strtotime( $data['arrived_at']); + $data['received_at'] = strtotime( $data['received_at']); + return $data; + } + + + /** + * 生成唯一的付款申请编码 + * 格式:PA + 日期 + 6位字母数字组合 + * + * @return string 唯一编码 + */ + public function generateUniqueReceipt() + { + $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $maxAttempts = 10; // 防止无限循环 + $secondChar = 'RE' . date('Ymd'); + + for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { + // 生成后6位随机字符 + $suffix = ''; + for ($i = 0; $i < 6; $i++) { + $suffix .= $chars[rand(0, strlen($chars) - 1)]; + } + + $ReceiptNo = $secondChar . $suffix; + + // 检查是否已存在 + $existing = FinReceipt::where('receipt_no', $ReceiptNo)->first(); + if (!$existing) { + return $ReceiptNo; + } + } + + // 如果1000次尝试后仍然重复,使用时间戳确保唯一性 + $timestamp = substr(time(), -6); + return $secondChar . $timestamp; + } +} \ No newline at end of file diff --git a/app/common/validate/FinPaymentApplyValidate.php b/app/common/validate/FinPaymentApplyValidate.php new file mode 100644 index 0000000..58145e3 --- /dev/null +++ b/app/common/validate/FinPaymentApplyValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/validate/FinReceiptValidate.php b/app/common/validate/FinReceiptValidate.php new file mode 100644 index 0000000..c006dee --- /dev/null +++ b/app/common/validate/FinReceiptValidate.php @@ -0,0 +1,56 @@ + 'integer|gt:0', + 'country_id' => 'require|integer|gt:0', + 'remitter' => 'require', + 'account_id' => 'require|integer|gt:0', + 'currency_id' => 'require|integer|gt:0', + 'amount' => 'require|gt:0', + 'exchange_rate' => 'require|gt:0', + 'arrived_at' => 'require', + 'is_domestic_return' => 'require|integer', + ]; + + // 提示 + protected $message = [ + 'payment_apply_id.integer' => '付款申请ID必须是整数', + 'payment_apply_id.gt' => '付款申请ID必须大于0', + 'country_id.require' => '付款来源国家ID不能为空', + 'country_id.integer' => '付款来源国家ID必须是整数', + 'country_id.gt' => '付款来源国家ID必须大于0', + 'remitter.require' => '汇款人不能为空', + 'account_id.require' => '收款账号ID不能为空', + 'account_id.integer' => '收款账号ID必须是整数', + 'account_id.gt' => '收款账号ID必须大于0', + 'currency_id.require' => '收款币种ID不能为空', + 'currency_id.integer' => '收款币种ID必须是整数', + 'currency_id.gt' => '收款币种ID必须大于0', + 'amount.require' => '收款金额不能为空', + 'amount.gt' => '收款金额必须大于0', + 'exchange_rate.require' => '实际汇率不能为空', + 'exchange_rate.gt' => '实际汇率必须大于0', + 'arrived_at.require' => '到账时间不能为空', + 'arrived_at.gt' => '到账时间必须大于0', + 'is_domestic_return.require' => '是否回转内地不能为空', + 'is_domestic_return.integer' => '是否回转内地必须是整数', + ]; + + // 场景 + protected $scene = [ + 'store' => [ + 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'exchange_rate', 'arrived_at' + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index b25b5a4..cf30328 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -70,27 +70,27 @@ class IndexController public function createResource() { $options = [ - 'controller' => [ - 'module' => 'crm', - 'name' => 'approval_flows' - ], +// 'controller' => [ +// 'module' => 'common', +// 'name' => 'fin_payment_apply' +// ], 'model' => [ - 'module' => 'crm', - 'name' => 'approval_flows' + 'module' => 'common', + 'name' => 'fin_payment_stock' ], - 'service' => [ - 'module' => 'crm', - 'name' => 'approval_flows' - ], - 'logic' => [ - 'module' => 'crm', - 'name' => 'approval_flows' - ], - 'validate' => [ - 'module' => 'crm', - 'name' => 'approval_flows' - ], - 'table' => 'approval_flows' +// 'service' => [ +// 'module' => 'common', +// 'name' => 'fin_payment_apply' +// ], +// 'logic' => [ +// 'module' => 'common', +// 'name' => 'fin_payment_apply' +// ], +// 'validate' => [ +// 'module' => 'common', +// 'name' => 'fin_payment_apply' +// ], + 'table' => 'fin_payment_stock' ]; $result = (new Generate($options))->doGenerate(); diff --git a/config/route.php b/config/route.php index 887c683..087fcf8 100644 --- a/config/route.php +++ b/config/route.php @@ -351,6 +351,24 @@ Route::group('/admin', function () { Route::any('/user/achieved', [app\admin\targets\controller\StatisticsController::class, 'userAchieved']); }); }); + + // 收款记录 + Route::group('/receipt', function () { + Route::any('/list', [app\common\controller\FinReceiptController::class, 'index']); + Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']); + Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); + Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); + Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); + }); + + // 收款记录 + Route::group('/payment', function () { + Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']); + Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']); + Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']); + Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']); + Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']); + }); }); From 4717bb01ca52dfb3c8ebebf4c617b34155dc71ef Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 15:14:08 +0800 Subject: [PATCH 02/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E4=B8=8E=E6=94=B6?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/FinPaymentApply.php | 8 +++ app/common/model/FinPaymentStock.php | 4 +- app/common/model/FinReceipt.php | 14 ++++-- app/common/model/FinReceiptHis.php | 49 +++++++++++++++++++ app/common/model/StockOrders.php | 8 +++ app/common/service/FinPaymentApplyService.php | 19 +++++++ app/common/service/FinReceiptService.php | 4 +- app/controller/IndexController.php | 4 +- 8 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 app/common/model/FinReceiptHis.php diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index 2fb04a7..0556210 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -62,4 +62,12 @@ class FinPaymentApply extends Model { return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); } + + /** + * 关联的备货单(通过中间表) + */ + public function stocks() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); + } } \ No newline at end of file diff --git a/app/common/model/FinPaymentStock.php b/app/common/model/FinPaymentStock.php index 6f4a3ba..d5b3d10 100644 --- a/app/common/model/FinPaymentStock.php +++ b/app/common/model/FinPaymentStock.php @@ -40,7 +40,7 @@ class FinPaymentStock extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'payment_apply_id', 'receipt_id', 'stock_id', 'allocated_amount', 'allocated_amount_cny']; + protected $fillable = ['id', 'pi_no', 'payment_apply_id', 'receipt_id', 'stock_id', 'allocated_amount', 'allocated_amount_cny', 'updated_at', 'created_at']; /** * 不允许自动填充模型字段 @@ -59,7 +59,7 @@ class FinPaymentStock extends Model return $this->belongsTo(FinReceipt::class, 'receipt_id', 'id'); } - // 付款申请 + // 备货单 public function stock() { return $this->belongsTo(StockOrders::class, 'stock_id', 'id'); diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index a98914f..c87ab12 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -40,7 +40,7 @@ class FinReceipt extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'is_domestic_return', 'created_at', 'updated_at']; + protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'is_domestic_return', 'created_by', 'updated_by', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 @@ -48,11 +48,11 @@ class FinReceipt extends Model protected $guarded = []; /** - * 获取付款申请 + * 对应的付款申请(1-1,可为空) */ public function payment() { - return $this->hasOne(FinPaymentApply::class, 'id', 'payment_apply_id'); + return $this->belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); } /** @@ -62,4 +62,12 @@ class FinReceipt extends Model { return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); } + + /** + * 关联的备货单(通过中间表) + */ + public function stocks() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); + } } \ No newline at end of file diff --git a/app/common/model/FinReceiptHis.php b/app/common/model/FinReceiptHis.php new file mode 100644 index 0000000..814b87f --- /dev/null +++ b/app/common/model/FinReceiptHis.php @@ -0,0 +1,49 @@ +belongsToMany(FinPaymentApply::class, 'fin_payment_stock', 'stock_id', 'payment_apply_id'); } + + /** + * 关联收款记录(多对多,经由中间表) + */ + public function receipts() + { + return $this->belongsToMany(FinReceipt::class, 'fin_payment_stock', 'stock_id', 'receipt_id'); + } } \ No newline at end of file diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 00ad976..d7912e1 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -2,9 +2,11 @@ namespace app\common\service; +use app\common\model\FinPaymentStock; use app\common\validate\FinPaymentApplyValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\FinPaymentApply; +use support\Redis; use support\Request; class FinPaymentApplyService @@ -61,10 +63,27 @@ class FinPaymentApplyService public function beforeServiceStore($data, Request $request) { $data['apply_no'] = $this->generateUniqueApplyNo(); + $data['doc_user_id'] = $request->user->uid; $data['submit_files'] = json_encode($data['submit_files']); + redis::set('stock'.$data['doc_user_id'],json_encode($request->post('stock'))); return $data; } + + public function afterServiceStore($res) + { + $data = [ + 'payment_apply_id' => $res['id'], + ]; + $stock = json_decode(redis::get('stock'.$res['doc_user_id']), true); + redis::del('stock'); + foreach ($stock as $k => $v) { + $data['stock_id'] = $v['stock_id']; + $data['pi_no'] = $v['pi_on']; + FinPaymentStock::create($data); + } + } + public function beforeServiceUpdate($data, Request $request) { $data['submit_files'] = json_encode($data['submit_files']); diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 2cc781c..3a7832d 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -80,12 +80,14 @@ class FinReceiptService unset($data['payment_apply_id']); } $data['receipt_no'] = $this->generateUniqueReceipt(); - $data['arrived_at'] = strtotime( $data['arrived_at']); + $data['arrived_at'] = $request->user->uid; + $data['updated_by'] = $request->user->uid; return $data; } public function beforeServiceUpdate($data, Request $request) { + $data['updated_by'] = $request->user->uid; $data['arrived_at'] = strtotime( $data['arrived_at']); $data['received_at'] = strtotime( $data['received_at']); return $data; diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index cf30328..e92751b 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -76,7 +76,7 @@ class IndexController // ], 'model' => [ 'module' => 'common', - 'name' => 'fin_payment_stock' + 'name' => 'fin_receipt_his' ], // 'service' => [ // 'module' => 'common', @@ -90,7 +90,7 @@ class IndexController // 'module' => 'common', // 'name' => 'fin_payment_apply' // ], - 'table' => 'fin_payment_stock' + 'table' => 'fin_receipt_his' ]; $result = (new Generate($options))->doGenerate(); From e6d3cc3f047e365c0f76fc0ba0e6eb60c6ae8892 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 16:45:06 +0800 Subject: [PATCH 03/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9B=B8=E5=85=B3=E5=AD=97=E6=AE=B5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 65 ++++++++++++++++--- app/common/service/FinPaymentApplyService.php | 6 +- app/common/service/FinReceiptService.php | 28 ++++++++ config/route.php | 2 +- 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 2d0f22e..76e51bf 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -1,7 +1,13 @@ first()->name; + if (isset($data['sales_user_id'])) //业务员 + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + if (isset($data['corp_id'])) //公司(渠道) + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->first()->item_label; + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['submit_files'])) + $data['submit_files'] = json_decode($data['submit_files'], true); + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['doc_user_id'])) //内勤 + $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + if (isset($data['sales_user_id'])) //业务员 + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + if (isset($data['corp_id'])) //公司(渠道) + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->first()->item_label; + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['submit_files'])) + $data['submit_files'] = json_decode($data['submit_files'], true); + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } } \ No newline at end of file diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index d7912e1..535d621 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -65,7 +65,7 @@ class FinPaymentApplyService $data['apply_no'] = $this->generateUniqueApplyNo(); $data['doc_user_id'] = $request->user->uid; $data['submit_files'] = json_encode($data['submit_files']); - redis::set('stock'.$data['doc_user_id'],json_encode($request->post('stock'))); + redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); return $data; } @@ -75,8 +75,8 @@ class FinPaymentApplyService $data = [ 'payment_apply_id' => $res['id'], ]; - $stock = json_decode(redis::get('stock'.$res['doc_user_id']), true); - redis::del('stock'); + $stock = json_decode(redis::get('stock_' . $res['doc_user_id']), true); + redis::del('stock' . $res['doc_user_id']); foreach ($stock as $k => $v) { $data['stock_id'] = $v['stock_id']; $data['pi_no'] = $v['pi_on']; diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 3a7832d..53d61ff 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -2,6 +2,7 @@ namespace app\common\service; +use app\common\model\FinReceiptHis; use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\FinReceipt; @@ -50,10 +51,22 @@ class FinReceiptService if (isset($p['country_id']) && !empty($p['country_id'])) { $config['where']['country_id'] = $p['country_id']; } + + // 没有付款记录的收款记录 + if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { + $config['where']['payment_apply_id'] = ['not null']; + } + + // 收款账户筛选 + if (isset($p['payment_apply_id']) && !empty($p['payment_apply_id'])) { + $config['where']['payment_apply_id'] = $p['payment_apply_id']; + } + // 收款账户筛选 if (isset($p['account_id']) && !empty($p['account_id'])) { $config['where']['account_id'] = $p['account_id']; } + // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; @@ -85,6 +98,14 @@ class FinReceiptService return $data; } + public function afterServiceStore($res) + { + $receipt = FinReceipt::where('id',$res->id)->first()->toArray(); + $receipt = array_merge($receipt,['receipt_id' => $res->id]); + unset($receipt['id']); + FinReceiptHis::create($receipt); + } + public function beforeServiceUpdate($data, Request $request) { $data['updated_by'] = $request->user->uid; @@ -92,6 +113,13 @@ class FinReceiptService $data['received_at'] = strtotime( $data['received_at']); return $data; } + public function afterServiceUpdate($res) + { + $receipt = FinReceipt::where('id',$res->id)->first()->toArray(); + $receipt = array_merge($receipt,['receipt_id' => $res->id]); + unset($receipt['id']); + FinReceiptHis::create($receipt); + } /** diff --git a/config/route.php b/config/route.php index 087fcf8..f2c9cb7 100644 --- a/config/route.php +++ b/config/route.php @@ -361,7 +361,7 @@ Route::group('/admin', function () { Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); }); - // 收款记录 + // 付款申请 Route::group('/payment', function () { Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']); Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']); From 1d6caad7b08f15c56d69db3482f888675338e723 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 17:33:09 +0800 Subject: [PATCH 04/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=93=E6=9E=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 15 +++++++++++++++ app/common/service/FinPaymentApplyService.php | 14 ++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 4acf899..c80dc3a 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -2,6 +2,9 @@ namespace app\common\controller; use app\common\controller\BaseController; +use app\common\model\Country; +use app\common\model\SysAccount; +use app\common\model\SysCurrency; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptService; @@ -32,6 +35,12 @@ class FinReceiptController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; return $data; } @@ -51,6 +60,12 @@ class FinReceiptController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; return $data; } } \ No newline at end of file diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 535d621..14b9d64 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -66,6 +66,7 @@ class FinPaymentApplyService $data['doc_user_id'] = $request->user->uid; $data['submit_files'] = json_encode($data['submit_files']); redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); + unset($data['stock']); return $data; } @@ -75,12 +76,14 @@ class FinPaymentApplyService $data = [ 'payment_apply_id' => $res['id'], ]; - $stock = json_decode(redis::get('stock_' . $res['doc_user_id']), true); + $piStock = json_decode(redis::get('stock_' . $res['doc_user_id']), true); redis::del('stock' . $res['doc_user_id']); - foreach ($stock as $k => $v) { - $data['stock_id'] = $v['stock_id']; - $data['pi_no'] = $v['pi_on']; - FinPaymentStock::create($data); + foreach ($piStock as $stock) { + foreach ($stock['stock_id'] as $v) { + $data['stock_id'] = $v; + $data['pi_no'] = $stock['pi_on']; + FinPaymentStock::create($data); + } } } @@ -90,7 +93,6 @@ class FinPaymentApplyService return $data; } - /** * 生成唯一的付款申请编码 * 格式:PA + 日期 + 6位字母数字组合 From 870bca5e578a5d697491cd8b3f425c71962b6099 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 18:26:17 +0800 Subject: [PATCH 05/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AF=A6=E6=83=85-?= =?UTF-8?q?=E5=A4=87=E8=B4=A7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 76e51bf..3d82e92 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -4,6 +4,7 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\model\Country; +use app\common\model\FinPaymentStock; use app\common\model\SysAccount; use app\common\model\SysCurrency; use app\common\model\SysDictItem; @@ -39,7 +40,7 @@ class FinPaymentApplyController extends BaseController if (isset($data['account_id'])) //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; if (isset($data['submit_files'])) @@ -68,7 +69,7 @@ class FinPaymentApplyController extends BaseController if (isset($data['account_id'])) //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; if (isset($data['submit_files'])) @@ -77,6 +78,14 @@ class FinPaymentApplyController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + + $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); + $stock = []; + foreach ($finPaymentStock as $v) { + $stock[$v['pi_no']] = ['pi_no' => $v['pi_no']]; + $stock[$v['pi_no']]['stock_id'] = [$v['stock_id']]; + } + $data['stock'] = $stock; return $data; } } \ No newline at end of file From db10ece6b702b15188a2b74800018be5439a54a8 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 18:30:13 +0800 Subject: [PATCH 06/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AF=A6=E6=83=85-?= =?UTF-8?q?=E5=A4=87=E8=B4=A7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 3d82e92..abf31a8 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -85,7 +85,7 @@ class FinPaymentApplyController extends BaseController $stock[$v['pi_no']] = ['pi_no' => $v['pi_no']]; $stock[$v['pi_no']]['stock_id'] = [$v['stock_id']]; } - $data['stock'] = $stock; + $data['stock'] = array_values($stock); return $data; } } \ No newline at end of file From 54f83679ea79c08b3fd3366bc2f8a6b9f3537b37 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 23 Sep 2025 18:38:02 +0800 Subject: [PATCH 07/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 53d61ff..e50bc7d 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -93,7 +93,8 @@ class FinReceiptService unset($data['payment_apply_id']); } $data['receipt_no'] = $this->generateUniqueReceipt(); - $data['arrived_at'] = $request->user->uid; + $data['arrived_at'] = strtotime( $data['arrived_at']); + $data['created_by'] = $request->user->uid; $data['updated_by'] = $request->user->uid; return $data; } @@ -109,8 +110,10 @@ class FinReceiptService public function beforeServiceUpdate($data, Request $request) { $data['updated_by'] = $request->user->uid; - $data['arrived_at'] = strtotime( $data['arrived_at']); - $data['received_at'] = strtotime( $data['received_at']); + $data['arrived_at'] = strtotime($data['arrived_at']); + if(isset($data['received_at'])) + $data['received_at'] = strtotime($data['received_at']); + return $data; } public function afterServiceUpdate($res) From abc1142e88e1707d4e1aeaf0070ff691fb8c3897 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 24 Sep 2025 10:16:34 +0800 Subject: [PATCH 08/74] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E4=BB=98=E6=AC=BE?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 9 ++-- app/common/validate/FinReceiptValidate.php | 62 +++++++++++----------- config/route.php | 1 + 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index e50bc7d..bf83f38 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -54,6 +54,8 @@ class FinReceiptService // 没有付款记录的收款记录 if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { + $config['where']['payment_apply_id'] = ['null']; + } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { $config['where']['payment_apply_id'] = ['not null']; } @@ -110,7 +112,8 @@ class FinReceiptService public function beforeServiceUpdate($data, Request $request) { $data['updated_by'] = $request->user->uid; - $data['arrived_at'] = strtotime($data['arrived_at']); + if(isset($data['arrived_at'])) + $data['arrived_at'] = strtotime($data['arrived_at']); if(isset($data['received_at'])) $data['received_at'] = strtotime($data['received_at']); @@ -118,8 +121,8 @@ class FinReceiptService } public function afterServiceUpdate($res) { - $receipt = FinReceipt::where('id',$res->id)->first()->toArray(); - $receipt = array_merge($receipt,['receipt_id' => $res->id]); + $receipt = FinReceipt::where('id',$res['id'])->first()->toArray(); + $receipt = array_merge($receipt,['receipt_id' => $res['id']]); unset($receipt['id']); FinReceiptHis::create($receipt); } diff --git a/app/common/validate/FinReceiptValidate.php b/app/common/validate/FinReceiptValidate.php index c006dee..237b03e 100644 --- a/app/common/validate/FinReceiptValidate.php +++ b/app/common/validate/FinReceiptValidate.php @@ -8,49 +8,49 @@ class FinReceiptValidate extends Validate { // 规则 protected $rule = [ - 'payment_apply_id' => 'integer|gt:0', - 'country_id' => 'require|integer|gt:0', - 'remitter' => 'require', - 'account_id' => 'require|integer|gt:0', - 'currency_id' => 'require|integer|gt:0', - 'amount' => 'require|gt:0', - 'exchange_rate' => 'require|gt:0', - 'arrived_at' => 'require', - 'is_domestic_return' => 'require|integer', +// 'payment_apply_id' => 'integer|gt:0', +// 'country_id' => 'require|integer|gt:0', +// 'remitter' => 'require', +// 'account_id' => 'require|integer|gt:0', +// 'currency_id' => 'require|integer|gt:0', +// 'amount' => 'require|gt:0', +// 'exchange_rate' => 'require|gt:0', +// 'arrived_at' => 'require', +// 'is_domestic_return' => 'require|integer', ]; // 提示 protected $message = [ - 'payment_apply_id.integer' => '付款申请ID必须是整数', - 'payment_apply_id.gt' => '付款申请ID必须大于0', - 'country_id.require' => '付款来源国家ID不能为空', - 'country_id.integer' => '付款来源国家ID必须是整数', - 'country_id.gt' => '付款来源国家ID必须大于0', - 'remitter.require' => '汇款人不能为空', - 'account_id.require' => '收款账号ID不能为空', - 'account_id.integer' => '收款账号ID必须是整数', - 'account_id.gt' => '收款账号ID必须大于0', - 'currency_id.require' => '收款币种ID不能为空', - 'currency_id.integer' => '收款币种ID必须是整数', - 'currency_id.gt' => '收款币种ID必须大于0', - 'amount.require' => '收款金额不能为空', - 'amount.gt' => '收款金额必须大于0', - 'exchange_rate.require' => '实际汇率不能为空', - 'exchange_rate.gt' => '实际汇率必须大于0', - 'arrived_at.require' => '到账时间不能为空', - 'arrived_at.gt' => '到账时间必须大于0', - 'is_domestic_return.require' => '是否回转内地不能为空', - 'is_domestic_return.integer' => '是否回转内地必须是整数', +// 'payment_apply_id.integer' => '付款申请ID必须是整数', +// 'payment_apply_id.gt' => '付款申请ID必须大于0', +// 'country_id.require' => '付款来源国家ID不能为空', +// 'country_id.integer' => '付款来源国家ID必须是整数', +// 'country_id.gt' => '付款来源国家ID必须大于0', +// 'remitter.require' => '汇款人不能为空', +// 'account_id.require' => '收款账号ID不能为空', +// 'account_id.integer' => '收款账号ID必须是整数', +// 'account_id.gt' => '收款账号ID必须大于0', +// 'currency_id.require' => '收款币种ID不能为空', +// 'currency_id.integer' => '收款币种ID必须是整数', +// 'currency_id.gt' => '收款币种ID必须大于0', +// 'amount.require' => '收款金额不能为空', +// 'amount.gt' => '收款金额必须大于0', +// 'exchange_rate.require' => '实际汇率不能为空', +// 'exchange_rate.gt' => '实际汇率必须大于0', +// 'arrived_at.require' => '到账时间不能为空', +// 'arrived_at.gt' => '到账时间必须大于0', +// 'is_domestic_return.require' => '是否回转内地不能为空', +// 'is_domestic_return.integer' => '是否回转内地必须是整数', ]; // 场景 protected $scene = [ 'store' => [ - 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'exchange_rate', 'arrived_at' +// 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'exchange_rate', 'arrived_at' ], 'update' => [ - +// 'payment_apply_id' ] ]; } \ No newline at end of file diff --git a/config/route.php b/config/route.php index f2c9cb7..be37a5b 100644 --- a/config/route.php +++ b/config/route.php @@ -358,6 +358,7 @@ Route::group('/admin', function () { Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']); Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); + Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); }); From 435d3ce67737213c36f5faaa5a307182b08f7dd7 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 24 Sep 2025 15:23:47 +0800 Subject: [PATCH 09/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 14 ++- app/common/model/FinPaymentApply.php | 10 +- app/common/service/FinPaymentApplyService.php | 106 ++++++++++++++++++ 3 files changed, 120 insertions(+), 10 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index abf31a8..3d35f09 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -9,6 +9,7 @@ use app\common\model\SysAccount; use app\common\model\SysCurrency; use app\common\model\SysDictItem; use app\common\model\User; +use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinPaymentApplyService; @@ -43,8 +44,19 @@ class FinPaymentApplyController extends BaseController $data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; - if (isset($data['submit_files'])) + $OssService = new OssService(); + if (isset($data['submit_files'])){ $data['submit_files'] = json_decode($data['submit_files'], true); + foreach ($data['submit_files'] as $key => $value) { + $data['submit_files'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + } + if (isset($data['voucher_file'])) + $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index 0556210..f02f137 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -40,7 +40,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'submit_files', 'created_at', 'updated_at']; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 @@ -55,14 +55,6 @@ class FinPaymentApply extends Model return $this->hasOne(FinReceipt::class, 'payment_apply_id', 'id'); } - /** - * 备货单 - */ - public function stock() - { - return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); - } - /** * 关联的备货单(通过中间表) */ diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 14b9d64..294bc01 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -45,6 +45,23 @@ class FinPaymentApplyService case 'index': // ====== ====== 排序 ====== ====== $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 汇款国家 + if (isset($p['country_id']) && !empty($p['country_id'])) { + $config['where']['country_id'] = $p['country_id']; + } + + // 收款账户筛选 + if (isset($p['account_id']) && !empty($p['account_id'])) { + $config['where']['account_id'] = $p['account_id']; + } + + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + $config['orWhere'][] = ['remitter', 'like', $k]; + } break; case 'show': $config['where']['id'] = $p['id']; @@ -125,4 +142,93 @@ class FinPaymentApplyService $timestamp = substr(time(), -6); return $secondChar . $timestamp; } + + /** + * 根据相似度排序付款记录 + * @param Request $request + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator + */ + public function complexQueryIndex(Request $request) + { + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $param = $request->all(); + + $where = []; + + // 汇款国家 + if (isset($param['country_id']) && !empty($param['country_id'])) { + $where[] = ['country_id', $param['country_id']]; + } + // 收款账户筛选 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $where[] = ['account_id', $param['account_id']]; + } + + // 关键字 + if (isset($param['keyword']) && $param['keyword']) { + $k = '%' . $param['keyword'] . '%'; + $where[] = ['remitter', 'like', $k]; + } + + // 构建查询 + $query = $this->modelClass::where($where); + + // 应用是否有关联收款记录的筛选 + $correlation = $param['correlation']??''; + if ($correlation === 'receipt') { + $query->whereHas('receipt'); + } elseif ($correlation === 'unbind') { + $query->whereDoesntHave('receipt'); + } + + if (isset($param['scene']) && $param['scene'] == 'list') { + return $query->paginate($limit, ['*'], 'page', $page); + } + + // 计算七天前的时间戳 + $sevenDaysAgo = time() - (10 * 24 * 60 * 60); + + // 构建相似度排序逻辑 + $similarityOrder = []; + + // 如果有传入参数,计算相似度 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['country_id']) && !empty($param['country_id'])) { + $similarityOrder[] = "CASE WHEN country_id = {$param['country_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['keyword']) && $param['keyword']) { + $keyword = addslashes($param['keyword']); + $similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END"; + } + + if (isset($param['amount']) && !empty($param['amount'])) { + $amount = (float)$param['amount']; + $similarityOrder[] = "ABS(amount - {$amount})"; + } + + // 构建排序SQL + $orderByClause = ""; + if (!empty($similarityOrder)) { + $orderByClause = "CASE + WHEN created_at >= {$sevenDaysAgo} THEN + (" . implode(' + ', $similarityOrder) . ") + ELSE 999999 + END ASC, "; + } + + $orderByClause .= "CASE + WHEN created_at < {$sevenDaysAgo} THEN id + ELSE 0 + END DESC"; + + $query->orderByRaw($orderByClause); + + return $query->paginate($limit, ['*'], 'page', $page); + } + } \ No newline at end of file From 82e4435a2cca7569342524a33d270f5018484385 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 24 Sep 2025 17:49:14 +0800 Subject: [PATCH 10/74] =?UTF-8?q?=E6=94=B6=E6=B1=87=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 5 +++++ app/common/model/FinReceipt.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index c80dc3a..a443537 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -5,6 +5,7 @@ use app\common\controller\BaseController; use app\common\model\Country; use app\common\model\SysAccount; use app\common\model\SysCurrency; +use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptService; @@ -41,6 +42,8 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['fx_receipt_file'])) + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); return $data; } @@ -66,6 +69,8 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['fx_receipt_file'])) + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); return $data; } } \ No newline at end of file diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index c87ab12..dbefafa 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -40,7 +40,7 @@ class FinReceipt extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'is_domestic_return', 'created_by', 'updated_by', 'created_at', 'updated_at']; + protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'fx_receipt_file_name', 'is_domestic_return', 'created_by', 'updated_by', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 From e0b11718a744fc3d1dd51ee53d6379ba1ecd4018 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 24 Sep 2025 17:55:16 +0800 Subject: [PATCH 11/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=A4=87=E8=B4=A7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/FinReceipt.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index dbefafa..7347be0 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -55,14 +55,6 @@ class FinReceipt extends Model return $this->belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); } - /** - * 备货单 - */ - public function stock() - { - return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); - } - /** * 关联的备货单(通过中间表) */ From ec2502cd586a2060a0862ffa8b37b6fa1045dd47 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 25 Sep 2025 17:48:31 +0800 Subject: [PATCH 12/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 95 +++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index bf83f38..2f77af5 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -59,7 +59,7 @@ class FinReceiptService $config['where']['payment_apply_id'] = ['not null']; } - // 收款账户筛选 + // 收款申请筛选 if (isset($p['payment_apply_id']) && !empty($p['payment_apply_id'])) { $config['where']['payment_apply_id'] = $p['payment_apply_id']; } @@ -70,7 +70,7 @@ class FinReceiptService } // 关键字 - if (isset($p['keyword']) && $p['keyword']) { + if (isset($p['$query']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; $config['orWhere'][] = ['remitter', 'like', $k]; } @@ -160,4 +160,95 @@ class FinReceiptService $timestamp = substr(time(), -6); return $secondChar . $timestamp; } + + /** + * 根据相似度排序付款记录 + * @param Request $request + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator + */ + public function complexQueryIndex(Request $request) + { + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $param = $request->all(); + + $where = []; + + // 汇款国家 + if (isset($param['country_id']) && !empty($param['country_id'])) { + $where[] = ['country_id', $param['country_id']]; + } + // 收款账户筛选 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $where[] = ['account_id', $param['account_id']]; + } + // 收款申请筛选 + if (isset($param['payment_apply_id']) && !empty($param['payment_apply_id'])) { + $where[]['payment_apply_id'] = $param['payment_apply_id']; + } + + // 关键字 + if (isset($param['keyword']) && $param['keyword']) { + $k = '%' . $param['keyword'] . '%'; + $where[] = ['remitter', 'like', $k]; + } + + // 构建查询 + $query = $this->modelClass::where($where); + + // 没有付款记录的收款记录 + if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') { + $query->whereNull('payment_apply_id'); + } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { + $query->whereNotNull('payment_apply_id'); + } + + if (isset($param['scene']) && $param['scene'] == 'list') { + return $query->paginate($limit, ['*'], 'page', $page); + } + + // 计算七天前的时间戳 + $sevenDaysAgo = time() - (10 * 24 * 60 * 60); + + // 构建相似度排序逻辑 + $similarityOrder = []; + + // 如果有传入参数,计算相似度 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['country_id']) && !empty($param['country_id'])) { + $similarityOrder[] = "CASE WHEN country_id = {$param['country_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['keyword']) && $param['keyword']) { + $keyword = addslashes($param['keyword']); + $similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END"; + } + + if (isset($param['amount']) && !empty($param['amount'])) { + $amount = (float)$param['amount']; + $similarityOrder[] = "ABS(amount - {$amount})"; + } + + // 构建排序SQL + $orderByClause = ""; + if (!empty($similarityOrder)) { + $orderByClause = "CASE + WHEN created_at >= {$sevenDaysAgo} THEN + (" . implode(' + ', $similarityOrder) . ") + ELSE 999999 + END ASC, "; + } + + $orderByClause .= "CASE + WHEN created_at < {$sevenDaysAgo} THEN id + ELSE 0 + END DESC"; + + $query->orderByRaw($orderByClause); + + return $query->paginate($limit, ['*'], 'page', $page); + } } \ No newline at end of file From ae6cd4ec78739fee47a584d4b5c55b70c3ea157d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Fri, 26 Sep 2025 16:43:09 +0800 Subject: [PATCH 13/74] =?UTF-8?q?=E5=8F=98=E6=9B=B4=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinReceiptHisController.php | 77 +++++++++++++++++++ app/common/logic/FinReceiptHisLogic.php | 17 ++++ app/common/service/FinReceiptHisService.php | 62 +++++++++++++++ app/common/validate/FinReceiptHisValidate.php | 29 +++++++ config/route.php | 5 ++ 5 files changed, 190 insertions(+) create mode 100644 app/common/controller/FinReceiptHisController.php create mode 100644 app/common/logic/FinReceiptHisLogic.php create mode 100644 app/common/service/FinReceiptHisService.php create mode 100644 app/common/validate/FinReceiptHisValidate.php diff --git a/app/common/controller/FinReceiptHisController.php b/app/common/controller/FinReceiptHisController.php new file mode 100644 index 0000000..eb57d99 --- /dev/null +++ b/app/common/controller/FinReceiptHisController.php @@ -0,0 +1,77 @@ +service = new FinReceiptHisService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['fx_receipt_file'])) + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + if (isset($data['fx_receipt_file'])) + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + return $data; + } +} \ No newline at end of file diff --git a/app/common/logic/FinReceiptHisLogic.php b/app/common/logic/FinReceiptHisLogic.php new file mode 100644 index 0000000..3e90dac --- /dev/null +++ b/app/common/logic/FinReceiptHisLogic.php @@ -0,0 +1,17 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'index'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + if(empty($p['receipt_id'])){ + throw new BusinessException('receipt_id不能为空'); + } + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + $config['where']['receipt_id'] = $p['receipt_id']; + + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } +} \ No newline at end of file diff --git a/app/common/validate/FinReceiptHisValidate.php b/app/common/validate/FinReceiptHisValidate.php new file mode 100644 index 0000000..7a1f7c4 --- /dev/null +++ b/app/common/validate/FinReceiptHisValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index be37a5b..3f7477f 100644 --- a/config/route.php +++ b/config/route.php @@ -361,6 +361,11 @@ Route::group('/admin', function () { Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); }); + // 收款记录历史 + Route::group('/receipt/his', function () { + Route::any('/list', [app\common\controller\FinReceiptHisController::class, 'index']); + Route::any('/show', [app\common\controller\FinReceiptHisController::class, 'show']); + }); // 付款申请 Route::group('/payment', function () { From 40dfd99f4e59d88952b30168e706af70b14c63b6 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sun, 28 Sep 2025 09:47:09 +0800 Subject: [PATCH 14/74] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 33 +++++++++++++------ .../controller/FinReceiptController.php | 15 +++++---- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 3d35f09..d8158fa 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -37,13 +37,13 @@ class FinPaymentApplyController extends BaseController if (isset($data['sales_user_id'])) //业务员 $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; if (isset($data['corp_id'])) //公司(渠道) - $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->first()->item_label; + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; $OssService = new OssService(); if (isset($data['submit_files'])){ $data['submit_files'] = json_decode($data['submit_files'], true); @@ -55,7 +55,8 @@ class FinPaymentApplyController extends BaseController ]; } } - if (isset($data['voucher_file'])) + $data['voucher_file_full'] = ''; + if (!empty($data['voucher_file'])) $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); @@ -77,15 +78,27 @@ class FinPaymentApplyController extends BaseController if (isset($data['sales_user_id'])) //业务员 $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; if (isset($data['corp_id'])) //公司(渠道) - $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->first()->item_label; + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; - if (isset($data['submit_files'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + $OssService = new OssService(); + if (isset($data['submit_files'])){ $data['submit_files'] = json_decode($data['submit_files'], true); + foreach ($data['submit_files'] as $key => $value) { + $data['submit_files'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + } + $data['voucher_file_full'] = ''; + if (!empty($data['voucher_file'])) + $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index a443537..3dcdf72 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -37,12 +37,13 @@ class FinReceiptController extends BaseController if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; - if (isset($data['fx_receipt_file'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + $data['fx_receipt_file_full'] = ''; + if (!empty($data['fx_receipt_file'])) $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); return $data; } @@ -64,11 +65,11 @@ class FinReceiptController extends BaseController if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; if (isset($data['fx_receipt_file'])) $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); return $data; From a3a6cfefc062b2c2d0a3c96da36054dfae973b91 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sun, 28 Sep 2025 09:56:01 +0800 Subject: [PATCH 15/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 12 ++++++++---- app/common/controller/FinReceiptController.php | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index d8158fa..8739043 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -55,9 +55,11 @@ class FinPaymentApplyController extends BaseController ]; } } - $data['voucher_file_full'] = ''; - if (!empty($data['voucher_file'])) + if (!empty($data['voucher_file'])) { $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); + } elseif (isset($data['voucher_file'])) { + $data['voucher_file_full'] = ''; + } if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) @@ -96,9 +98,11 @@ class FinPaymentApplyController extends BaseController ]; } } - $data['voucher_file_full'] = ''; - if (!empty($data['voucher_file'])) + if (!empty($data['voucher_file'])) { $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); + } elseif (isset($data['voucher_file'])) { + $data['voucher_file_full'] = ''; + } if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 3dcdf72..76b1ed8 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -42,9 +42,11 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; - $data['fx_receipt_file_full'] = ''; - if (!empty($data['fx_receipt_file'])) + if (!empty($data['fx_receipt_file'])){ $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } return $data; } @@ -70,8 +72,11 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; - if (isset($data['fx_receipt_file'])) + if (!empty($data['fx_receipt_file'])) { $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + } elseif (isset($data['fx_receipt_file'])) { + $data['fx_receipt_file_full'] = ''; + } return $data; } } \ No newline at end of file From 90cce108b0b3e27d15351b70b420308fc5187a82 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sun, 28 Sep 2025 10:10:15 +0800 Subject: [PATCH 16/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=B8=8E=E4=BF=AE=E6=94=B9=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 8 ++++---- app/common/controller/FinReceiptHisController.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 8739043..7dead81 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -33,9 +33,9 @@ class FinPaymentApplyController extends BaseController protected function indexFormat($data) { if (isset($data['doc_user_id'])) //内勤 - $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['sales_user_id'])) //业务员 - $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['corp_id'])) //公司(渠道) $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; if (isset($data['account_id'])) //收款账号 @@ -76,9 +76,9 @@ class FinPaymentApplyController extends BaseController protected function showFormat($data) { if (isset($data['doc_user_id'])) //内勤 - $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['sales_user_id'])) //业务员 - $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->first()->name; + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['corp_id'])) //公司(渠道) $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; if (isset($data['account_id'])) //收款账号 diff --git a/app/common/controller/FinReceiptHisController.php b/app/common/controller/FinReceiptHisController.php index eb57d99..e10d859 100644 --- a/app/common/controller/FinReceiptHisController.php +++ b/app/common/controller/FinReceiptHisController.php @@ -5,6 +5,7 @@ use app\common\controller\BaseController; use app\common\model\Country; use app\common\model\SysAccount; use app\common\model\SysCurrency; +use app\common\model\User; use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptHisService; @@ -45,6 +46,11 @@ class FinReceiptHisController extends BaseController $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; if (isset($data['fx_receipt_file'])) $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + + if (isset($data['created_by'])) + $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; + if (isset($data['updated_by'])) + $data['updated_by'] = User::where('id', $data['updated_by'])->value('name')??''; return $data; } @@ -72,6 +78,11 @@ class FinReceiptHisController extends BaseController $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; if (isset($data['fx_receipt_file'])) $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + + if (isset($data['created_by'])) + $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; + if (isset($data['updated_by'])) + $data['updated_by'] = User::where('id', $data['updated_by'])->value('name')??''; return $data; } } \ No newline at end of file From d05106f9dfc7cfc323ecc3f686c0d442a8f9de43 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 9 Oct 2025 10:16:21 +0800 Subject: [PATCH 17/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 8 +++++--- app/common/controller/FinReceiptController.php | 4 +++- app/common/controller/FinReceiptHisController.php | 15 ++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 7dead81..9129390 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -81,8 +81,10 @@ class FinPaymentApplyController extends BaseController $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['corp_id'])) //公司(渠道) $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; - if (isset($data['account_id'])) //收款账号 + if (isset($data['account_id'])){ //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 @@ -111,8 +113,8 @@ class FinPaymentApplyController extends BaseController $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); $stock = []; foreach ($finPaymentStock as $v) { - $stock[$v['pi_no']] = ['pi_no' => $v['pi_no']]; - $stock[$v['pi_no']]['stock_id'] = [$v['stock_id']]; + $stock[$v['pi_no']]['pi_no'] = $v['pi_no']; + $stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']]; } $data['stock'] = array_values($stock); return $data; diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 76b1ed8..74052f7 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -36,8 +36,10 @@ class FinReceiptController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); - if (isset($data['account_id'])) //收款账号 + if (isset($data['account_id'])) { //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 diff --git a/app/common/controller/FinReceiptHisController.php b/app/common/controller/FinReceiptHisController.php index e10d859..16e4b3c 100644 --- a/app/common/controller/FinReceiptHisController.php +++ b/app/common/controller/FinReceiptHisController.php @@ -70,14 +70,19 @@ class FinReceiptHisController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); - if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['account_id'])){ //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; - if (isset($data['fx_receipt_file'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])){ $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } if (isset($data['created_by'])) $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; From 73ed4a413c84a81c76b2cacaf8a257f14b90feb6 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 9 Oct 2025 10:24:13 +0800 Subject: [PATCH 18/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 4 +++- app/common/controller/FinReceiptController.php | 4 +++- .../controller/FinReceiptHisController.php | 17 +++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 9129390..e916df4 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -38,8 +38,10 @@ class FinPaymentApplyController extends BaseController $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; if (isset($data['corp_id'])) //公司(渠道) $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; - if (isset($data['account_id'])) //收款账号 + if (isset($data['account_id'])){ //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 74052f7..ddddfac 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -68,8 +68,10 @@ class FinReceiptController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); - if (isset($data['account_id'])) //收款账号 + if (isset($data['account_id'])) { //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 diff --git a/app/common/controller/FinReceiptHisController.php b/app/common/controller/FinReceiptHisController.php index 16e4b3c..7adcf0d 100644 --- a/app/common/controller/FinReceiptHisController.php +++ b/app/common/controller/FinReceiptHisController.php @@ -38,15 +38,20 @@ class FinReceiptHisController extends BaseController $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); if (isset($data['received_at'])) $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); - if (isset($data['account_id'])) //收款账号 - $data['account_name'] = SysAccount::where('id', $data['account_id'])->first()->account_name; + if (isset($data['account_id'])) { //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } if (isset($data['country_id'])) //付款来源国家 - $data['country_name'] = Country::where('id', $data['currency_id'])->first()->cn_addr; + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 - $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name; - if (isset($data['fx_receipt_file'])) + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])){ $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); - + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } + if (isset($data['created_by'])) $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; if (isset($data['updated_by'])) From 4c94392ef648fd15584f794569a094f6218c4ce1 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 21 Oct 2025 13:34:26 +0800 Subject: [PATCH 19/74] ts --- app/common/service/StockOrdersService_bak.php | 1044 +++++++++++++---- app/common/utils/WsEvents.php | 11 +- .../approval/service/ApprovalFlowService.php | 3 +- plugin/webman/gateway/Events.php | 2 +- 4 files changed, 813 insertions(+), 247 deletions(-) diff --git a/app/common/service/StockOrdersService_bak.php b/app/common/service/StockOrdersService_bak.php index 65ef296..5ee03a9 100644 --- a/app/common/service/StockOrdersService_bak.php +++ b/app/common/service/StockOrdersService_bak.php @@ -12,6 +12,10 @@ use app\common\model\SysCurrency; use support\Request; use app\common\model\User; use support\Db; +use support\Model; +use app\common\model\ApprovalInstances; +use app\common\model\ApprovalRecords; +use support\exception\BusinessException; class StockOrdersService_bak { @@ -63,13 +67,13 @@ class StockOrdersService_bak $config['order']['id'] = 'desc'; - // $config['dataLimit']['type'] = 'relation'; - // $config['dataLimit']['userId'] = $request->user->uid; - // $config['dataLimit']['userField'] = 'salesperson_id'; + // $config['where']['salesperson_id'] = $request->user->uid; break; case 'print': + case 'approval': $config['where']['id'] = $p['id']; break; + case 'detail': case 'show': $config['where']['id'] = $p['id']; @@ -93,113 +97,6 @@ class StockOrdersService_bak 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'], '改装费'); - } - - // 二手车 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']; - $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; @@ -210,7 +107,30 @@ class StockOrdersService_bak $data['latest_arrival_date'] = strtotime($data['latest_arrival_date']); $data['salesperson_id'] = $userId; $data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? ''; + $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; + // if ($data['is_final'] == 1) { + $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; + $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; + // } + + if ($data['is_final'] == 1) { + // 检查是否至少有一个车辆填写了vin + $hasVin = false; + foreach ($data['veh_list'] as $k => $v) { + if ($v['vin'] != '') { + $hasVin = true; + break; + } + } + // 如果没有任何车辆填写vin,则抛出异常 + if (!$hasVin) { + throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核'); + } + } + + // 检查绑定 + (new UserService())->checkBind($userId); return $data; } @@ -226,16 +146,27 @@ class StockOrdersService_bak } } // 启动审批 - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $result = $appro->start('stock_orders', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id); - var_dump($result); - - // 异步生成pdf文件 - \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$res->id]); + if ($res->approval_status == 1) { + $this->startApproval($res); + } return $res; } + /** + * 启动审批 + */ + public function startApproval($item) + { + // 启动审批 + $appro = new \app\common\utils\approval\service\ApprovalFlowService(); + $appro->start('stock_orders', 'stock_orders', $item->id, [], $item->salesperson_id); + // 异步生成pdf文件 + \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]); + } + /** + * 创建PDF文件 + */ public function createdPdfFile($id) { $config = []; @@ -248,7 +179,7 @@ class StockOrdersService_bak $config['with'][] = 'moneyValues'; $config['with'][] = 'salesperson'; $item = $this->logicShow($config); - $pdfData = $this->pdfData($item); + $pdfData = $this->formatData($item); // 渲染模板为最终HTML $tplPath = app_path('common/utils/pdf/template/stockOrder.stub'); @@ -269,17 +200,6 @@ class StockOrdersService_bak $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, @@ -287,7 +207,7 @@ class StockOrdersService_bak 'category' => 'pdf', 'original_name' => $fileName ]; - $up = new UploadService(); + $up = new \app\common\service\UploadService(); $res = $up->uploadLocalFile($param); @unlink($dir . $fileName); @@ -299,6 +219,34 @@ class StockOrdersService_bak return $res; } + + /** + * 查询审批 + */ + public function queryAppro($bizId) + { + $instances = ApprovalInstances::where('biz_id', $bizId)->where('biz_type', 'stock_orders')->first(); + if (!$instances) { + return []; + } + + $records = ApprovalRecords::where('instance_id', $instances->id)->where('action', 'approve')->orderBy('step_index', 'asc')->pluck('approver_id')->toArray(); + if (count($records) == 0) { + return []; + } + + $signImgs = []; + foreach ($records as $k => $v) { + $signImg = User::where('id', $v)->value('sign_img'); + $signImgs[$k] = (!empty($signImg))?(new \app\common\service\OssService)->generatePrivateUrl($signImg):''; + } + + return $signImgs; + } + + /** + * 打印数据 + */ public function servicePrint(Request $request) { $config = $this->buildQueryConfig($request, 'show'); @@ -306,130 +254,744 @@ class StockOrdersService_bak return $this->postProcess('Print', $item); } - - public function pdfData($item) + public function serviceDetail(Request $request) { - $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, '.', ',') - ]; + $config = $this->buildQueryConfig($request, 'detail'); + $item = $this->logicShow($config); + $detail = $this->formatData($item); + return $this->postProcess('Detail', $detail); + } - // 根据里程处理 新车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, '.', ','); - } - } + /** + * 审批 + */ + public function serviceApproval(Request $request) + { + $config = $this->buildQueryConfig($request, 'approval'); + $this->logicUpdateBy($config, [ + 'approval_status' => 1 + ]); + $item = $this->logicShow($config); + $this->startApproval($item); + return $this->postProcess('Approval', $item); + } + + /** + * 作废审批 + */ + public function serviceApprovalNullify(Request $request) + { + $config = $this->buildQueryConfig($request, 'approval'); + $item = $this->logicShow($config); + $this->approvalNullify($item); + return $this->postProcess('Approval', $item); + } + + /** + * 审批作废 + */ + public function approvalNullify($item) + { + $appro = new \app\common\utils\approval\service\ApprovalFlowService(); + $appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, [], $item->salesperson_id); + } + + /** + * 撤销审批 + */ + public function serviceApprovalRevoke(Request $request) + { + $config = $this->buildQueryConfig($request, 'approval'); + $item = $this->logicShow($config); + $this->approvalRevoke($item); + return $this->postProcess('Approval', $item); + } + + public function approvalRevoke($item) + { + $instance = \app\common\model\ApprovalInstances::where('biz_id', $item->id)->where('flow_type', 'stock_orders')->first(); + $appro = new \app\common\utils\approval\service\ApprovalFlowService(); + $appro->revoke($instance->id, $item->salesperson_id); + } + + /** + * 创建 + * + * @param Request $request + * @param array $data + * @return mixed + */ + 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); + + // 处理车辆和账户信息 + $this->processOrderItems($created, $data); - $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; + return $this->postProcess('Store', $created); + }); + } + + protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array + { + // 兼容传类名或实例 + $m = \is_string($model) ? new $model : $model; + // 1) 优先使用 fillable + $keys = $m->getFillable(); + // 2) 若没配置 fillable(常见:用 guarded),回退到完整表字段,避免误伤 + if (empty($keys)) { + $keys = $m->getConnection() + ->getSchemaBuilder() + ->getColumnListing($m->getTable()); + } + // 3) 允许额外白名单(如虚拟字段、JSON映射字段) + if ($extraWhitelist) { + $keys = array_merge($keys, $extraWhitelist); + } + return array_intersect_key($data, array_flip($keys)); + } + + /** + * 更新前处理 + * + * @param array $data + * @param Request $request + * @return array + */ + public function beforeServiceUpdate($data, Request $request) + { + $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['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; + + $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; + $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; + return $data; + } + + /** + * 更新后处理 + * + * @param mixed $res + * @return mixed + */ + protected function afterServiceUpdate($res) + { + // 启动审批 + if ($res->approval_status == 1) { + $this->startApproval($res); + } + return $res; + } + + /** + * 更新 + * + * @param Request $request + * @param array $data + * @return mixed + */ + public function serviceUpdate(Request $request, array $data = []) + { + // 关联表较多,增加事务处理 + return Db::transaction(function () use ($request, $data) { + $data = $this->preProcess('Update', $data, $request); + $config = $this->buildQueryConfig($request, 'update'); + // 过滤掉非库字段 + $dbData = $this->onlyFillableData($config['model'], $data); + // 更新主表 + $updated = $this->logicUpdateBy($config, $dbData); + // 获取更新后的数据 + $order = $this->logicShow($config); + // 处理车辆和账户信息 + $this->processOrderItems($order, $data, true); + return $this->postProcess('Update', $order); + }); + } + + /** + * 处理订单项(车辆和账户) + * @param StockOrders $order 订单对象 + * @param array $data 数据 + * @param bool $isUpdate 是否为更新操作 + */ + private function processOrderItems($order, array $data, bool $isUpdate = false): void + { + // 如果是更新操作,先删除原有的关联数据 + if ($isUpdate) { + $this->clearExistingOrderItems($order->id); } + // 处理车辆项 + $this->processVehicleItems($order, $data['veh_list'] ?? []); + + // 处理账户项 + $this->processAccountItems($order, $data['account_list'] ?? []); + } + + /** + * (更新时)清除已存在的订单项 + * @param int $orderId 订单ID + */ + private function clearExistingOrderItems(int $orderId): void + { + // 删除车辆改装项 + StockOrderItemOptions::whereHas('item', function ($query) use ($orderId) { + $query->where('order_id', $orderId); + })->delete(); + + // 删除车辆项及其相关金额记录 + $orderItems = StockOrderItems::where('order_id', $orderId)->get(); + foreach ($orderItems as $item) { + // 删除车辆项的金额记录 + Db::table('veh_money_value') + ->where('object_scene', 'stock_order_items') + ->where('object_id', $item->id) + ->delete(); + } + + // 删除车辆项 + StockOrderItems::where('order_id', $orderId)->delete(); + + // 删除订单本身的金额记录 + Db::table('veh_money_value') + ->where('object_scene', 'stock_orders') + ->where('object_id', $orderId) + ->delete(); + + // 删除账户项 + StockOrderAccounts::where('order_id', $orderId)->delete(); + } + + /** + * 处理车辆项 + */ + private function processVehicleItems($order, array $vehList): void + { $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); + $profitTotalAmount = 0.00; + foreach ($vehList as $veh) { + $veh['order_id'] = $order->id; + $veh['unique_id'] = $this->generateVehicleUniqueId($veh); + + $item = StockOrderItems::create($veh); + + // 处理金额信息 + $this->processVehiclePrices($item, $veh); + + // 计算利润 + // $profit = $this->calculateProfit($veh, $item->mileage, $order); + // $item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润'); + + // 累计到岸价 + $cifTotalAmount += $veh['total_price']['amount'] ?? 0; + $profitTotalAmount += $veh['profit']['amount'] ?? 0; + + // 处理改装项 + $this->processModificationItems($item->id, $veh['modify_list'] ?? []); } + // 保存合计到岸价 + $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, '总利润'); + } + + /** + * 生成车辆唯一标识 + */ + private function generateVehicleUniqueId(array $veh): string + { + // $uniqueIdStr = ""; + // $uniqueIdStr .= $veh['sku_id'] ?? ''; + // $uniqueIdStr .= $veh['model_snapshot'] ?? ''; + // $uniqueIdStr .= $veh['color_interior_code'] ?? ''; + // $uniqueIdStr .= $veh['color_exterior_code'] ?? ''; + // $uniqueIdStr .= $veh['mileage'] ?? ''; + // $uniqueIdStr .= json_encode($veh['modify_list'] ?? []); + + $keysToRemove = ['vin', 'remark', 'modify_list', 'order_id']; + $array = array_diff_key($veh, array_flip($keysToRemove)); + $uniqueIdStr = json_encode($array); + + return md5($uniqueIdStr); + } + + /** + * 处理车辆价格信息 + */ + private function processVehiclePrices($item, array $veh): void + { + // unit_price 单价/成交价/收款价 + // total_price 总价 + // handling_fee 手续费 + // fob_transport_fee FOB运输费 + // port_misc_fee 港杂 + // retrofit_fee 改装费 + // ocean_freight 海运费 + // commission 佣金 + // purchase_tax 购置税 + // tax_refund 预估退税 + // clearance_price 报关价 + // profit 利润 + // official_price 官方指导价 + // discount_price 优惠价 + // listing_price 二手挂牌价 + // reduction_price 二手减价/优惠价 + // retention_price 留款/挂账 + // car_price 车价 + // modify_price 改装价 + + // 基础费用 + $priceFields = [ + 'unit_price' => '收款价', + 'total_price' => '总价', + 'handling_fee' => '手续费', + 'fob_transport_fee' => 'FOB运输费', + 'port_misc_fee' => '港杂', + 'retrofit_fee' => '改装费', + 'ocean_freight' => '海运费', + 'commission' => '佣金', + 'purchase_tax' => '购置税', + 'tax_refund' => '预估退税', + 'clearance_price' => '报关价', + 'profit' => '利润', + 'retention_price' => '挂账', + 'car_price' => '车价', + 'modify_price' => '改装价' + ]; + + foreach ($priceFields as $field => $description) { + $item->addMoney( + $field, + $veh[$field]['currency'], + (float)$veh[$field]['amount'], + $veh[$field]['rate'], + $description + ); + } + + // 根据里程处理新车或二手车价格 + if (!empty($veh['mileage']) && $veh['mileage'] > 0) { + // 二手车 + $item->addMoney( + 'listing_price', + $veh['listing_price']['currency'], + (float)$veh['listing_price']['amount'], + $veh['listing_price']['rate'], + '二手挂牌价' + ); + $item->addMoney( + 'reduction_price', + $veh['reduction_price']['currency'], + (float)$veh['reduction_price']['amount'], + $veh['reduction_price']['rate'], + '优惠价' + ); + } else { + // 新车 + $item->addMoney( + 'official_price', + $veh['official_price']['currency'], + (float)$veh['official_price']['amount'], + $veh['official_price']['rate'], + '官方指导价' + ); + $item->addMoney( + 'discount_price', + $veh['discount_price']['currency'], + (float)$veh['discount_price']['amount'], + $veh['discount_price']['rate'], + '优惠价' + ); + } + } + + /** + * 计算利润 + */ + private function calculateProfit(array $veh, int $mileage, $order): float + { + $contractExchangeRate = $order->contract_exchange_rate ?: 1; + + // 提取单价并进行汇率转换(如果需要) + $unitPriceRate = $veh['unit_price']['rate'] ?: 1; + if ($unitPriceRate != $contractExchangeRate) { + $unitPrice = (float)($veh['unit_price']['amount'] ?? 0) / $contractExchangeRate; + } else { + $unitPrice = (float)($veh['unit_price']['amount'] ?? 0); + } + + // 处理主要价格字段,根据是否需要汇率转换来计算 + if ($mileage > 0) { + // 二手车 + $listingPriceRate = $veh['listing_price']['rate'] ?: 1; + if ($listingPriceRate != $contractExchangeRate) { + $ttPrice = ($veh['listing_price']['amount'] ?? 0) / $contractExchangeRate; + } else { + $ttPrice = $veh['listing_price']['amount'] ?? 0; + } + + $reductionPriceRate = $veh['reduction_price']['rate'] ?: 1; + if ($reductionPriceRate != $contractExchangeRate) { + $ddPrice = ($veh['reduction_price']['amount'] ?? 0) / $contractExchangeRate; + } else { + $ddPrice = $veh['reduction_price']['amount'] ?? 0; + } + } else { + // 新车 + $officialPriceRate = $veh['official_price']['rate'] ?: 1; + if ($officialPriceRate != $contractExchangeRate) { + $ttPrice = ($veh['official_price']['amount'] ?? 0) / $contractExchangeRate; + } else { + $ttPrice = $veh['official_price']['amount'] ?? 0; + } + + $discountPriceRate = $veh['discount_price']['rate'] ?: 1; + if ($discountPriceRate != $contractExchangeRate) { + $ddPrice = ($veh['discount_price']['amount'] ?? 0) / $contractExchangeRate; + } else { + $ddPrice = $veh['discount_price']['amount'] ?? 0; + } + } + + // 处理其他费用字段,根据是否需要汇率转换来计算 + $handlingFeeRate = $veh['handling_fee']['rate'] ?: 1; + if ($handlingFeeRate != $contractExchangeRate) { + $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0) / $contractExchangeRate; + } else { + $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0); + } + + $fobTransportFeeRate = $veh['fob_transport_fee']['rate'] ?: 1; + if ($fobTransportFeeRate != $contractExchangeRate) { + $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0) / $contractExchangeRate; + } else { + $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0); + } + + $portMiscFeeRate = $veh['port_misc_fee']['rate'] ?: 1; + if ($portMiscFeeRate != $contractExchangeRate) { + $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0) / $contractExchangeRate; + } else { + $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0); + } + + $retrofitFeeRate = $veh['retrofit_fee']['rate'] ?: 1; + if ($retrofitFeeRate != $contractExchangeRate) { + $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0) / $contractExchangeRate; + } else { + $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0); + } + + $oceanFreightRate = $veh['ocean_freight']['rate'] ?: 1; + if ($oceanFreightRate != $contractExchangeRate) { + $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0) / $contractExchangeRate; + } else { + $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0); + } + + $commissionRate = $veh['commission']['rate'] ?: 1; + if ($commissionRate != $contractExchangeRate) { + $commission = (float)($veh['commission']['amount'] ?? 0) / $contractExchangeRate; + } else { + $commission = (float)($veh['commission']['amount'] ?? 0); + } + + $purchaseTaxRate = $veh['purchase_tax']['rate'] ?: 1; + if ($purchaseTaxRate != $contractExchangeRate) { + $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0) / $contractExchangeRate; + } else { + $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0); + } + + // 预估退税不需要参与汇率转换计算,前端已经计算过了 + $taxRefund = (float)($veh['tax_refund']['amount'] ?? 0); + + // 退税额 是增加利润 + return $unitPrice - $ttPrice + $ddPrice - $handlingFee - $fobTransportFee - $portMiscFee - $retrofitFee - $oceanFreight - $commission - $purchaseTax + $taxRefund; + } + + /** + * 处理改装项 + */ + private function processModificationItems(int $orderItemId, array $modifyList): void + { + if (empty($modifyList)) { + return; + } + + foreach ($modifyList as $modify) { + $modify['order_item_id'] = $orderItemId; + StockOrderItemOptions::create($modify); + } + } + + /** + * 处理账户项 + */ + private function processAccountItems($order, array $accountList): void + { + if (empty($accountList)) { + return; + } + + foreach ($accountList as $account) { + $account['order_id'] = $order->id; + if (!empty($account['remit_date'])) { + $account['remit_date'] = strtotime($account['remit_date']); + } + StockOrderAccounts::create($account); + } + } + + + // ====== ======= ====== ======= ====== 信息处理 ======= ====== ======= ====== ======= + + // PDF数据 + public function formatData($item) + { + // 提取车辆列表信息 + $vehListData = $this->prepareVehicleListData($item); + + // 提取订单金额信息 + $moneyValues = $this->prepareOrderMoneyValues($item); + + // 提取账户列表信息 + $accountList = $this->prepareAccountList($item); + + // 构建返回数据 $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, - + // 基本信息 + 'order_no' => $item->order_no, + 'salesperson_snapshot' => $item->salesperson_snapshot, + 'sign_img_url' => $this->getSignatureImageUrl($item->salesperson->sign_img ?? null), + '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 + 'veh_list' => array_values($vehListData['list']), + 'contract_exchange_rate' => $item->contract_exchange_rate, + 'cif_total_amount' => $moneyValues['cif_total_amount'] ?? [], + 'profit_total' => $moneyValues['profit_total'] ?? [], + + // 运输和交付信息 + '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), + 'pick_up_date' => date('Y-m-d', $item->pick_up_date), + 'collect_all_date' => date('Y-m-d', $item->collect_all_date), + 'is_final' => $item->is_final, + + // 账户信息 + 'account_list' => $accountList, + 'acc_index' => count($accountList) + 1, + 'currency_symbol' => $item->settlement_currency, + 'sign_imgs' => $this->queryAppro($item->id), + 'contract_url' => $this->getContractUrl($item->contract ?? null) ]; return $veh; } + + /** + * 准备车辆列表数据 + */ + private function prepareVehicleListData($item): array + { + $vehList = []; + $index = 0; + $currencyInfo = $this->getCurrencyInfo($item->settlement_currency); + + foreach ($item->items as $v) { + // 如果已存在相同车辆,增加数量 + 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; + } + + $index++; + // 处理金额信息 + $moneyValues = $this->processItemMoneyValues($v); + + // 处理改装信息 + $modificationText = $this->getModificationText($v->options); + + // 计算单项利润 + // $itemProfit = $this->calculateProfit($moneyValues, $v->mileage, $item); + // var_dump($moneyValues); + $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount']; + + // 构建车辆信息 + $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' => $modificationText, + 'mileage' => $v->mileage, + 'remark' => $v->remark, + ] + $moneyValues; + + // 添加利润信息 + $vehList[$v->unique_id]['profit'] = [ + 'currency' => $item->settlement_currency, + 'amount' => $itemProfit, + 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',') + ]; + } + + return ['list' => $vehList]; + } + + /** + * 处理单项金额值 + */ + private function processItemMoneyValues($item): array + { + $moneyValues = []; + foreach ($item->moneyValues as $money) { + $moneyValues[$money->field] = [ + 'currency' => $money->currency, + 'amount' => $money->amount, + 'rate' => $money->exchange_rate, + 'currency_info' => $this->formatCurrency($money->amount, $money->currency) + ]; + } + return $moneyValues; + } + + /** + * 获取改装文本 + */ + private function getModificationText($options): string + { + $modificationText = ''; + foreach ($options as $option) { + $modificationText .= $option->option_name_snapshot . ' '; + } + return trim($modificationText); + } + + /** + * 增加车辆数量并更新相关金额显示 + */ + private function incrementVehicleCount(array &$vehicleData, array $currencyInfo): void + { + $vehicleData['num'] += 1; + + // 更新总价显示 + if (isset($vehicleData['total_price']['amount'])) { + $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num']; + $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ','); + } + + // 更新利润显示 + if (isset($vehicleData['profit']['amount'])) { + $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num']; + $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ','); + } + } + + /** + * 准备订单金额值 + */ + private function prepareOrderMoneyValues($item): array + { + $moneyValues = []; + foreach ($item->moneyValues as $money) { + $moneyValues[$money->field] = [ + 'currency' => $money->currency, + 'amount' => $money->amount, + 'rate' => $money->exchange_rate, + 'currency_info' => $this->formatCurrency($money->amount, $money->currency) + ]; + } + return $moneyValues; + } + + /** + * 准备账户列表 + */ + private function prepareAccountList($item): array + { + $accountList = []; + foreach ($item->accounts as $k => $account) { + $accountList[] = [ + 'index' => '收款' . ($k + 1), + 'remit_country_name_snapshot' => $account->remit_country_name_snapshot, + 'remit_date' => date('Y-m-d', $account->remit_date), + 'currency_name_snapshot' => $account->currency_name_snapshot, + 'account_name_snapshot' => $account->account_name_snapshot, + 'remitter_name' => $account->remitter_name, + 'amount' => $account->amount, + ]; + } + return $accountList; + } + + /** + * 获取货币信息 + */ + private function getCurrencyInfo(string $currencyCode): array + { + return SysCurrency::where('currency_code', $currencyCode) + ->first(['currency_symbol', 'currency_name']) + ->toArray(); + } + + /** + * 格式化货币显示 + */ + private function formatCurrency(float $amount, string $currencyCode): string + { + $currencySymbol = SysCurrency::where('currency_code', $currencyCode)->value('currency_symbol'); + return $currencySymbol . number_format($amount, 2, '.', ','); + } + + /** + * 获取签名图片URL + */ + private function getSignatureImageUrl(?string $signImg): string + { + if (empty($signImg)) { + return ''; + } + return (new \app\common\service\OssService)->generatePrivateUrl($signImg); + } + + /** + * 获取合同URL + */ + private function getContractUrl(?string $contract): string + { + if (empty($contract)) { + return ''; + } + return (new \app\common\service\OssService)->generatePrivateUrl($contract); + } } \ No newline at end of file diff --git a/app/common/utils/WsEvents.php b/app/common/utils/WsEvents.php index 5bf4792..b02eb90 100644 --- a/app/common/utils/WsEvents.php +++ b/app/common/utils/WsEvents.php @@ -117,7 +117,7 @@ class WsEvents // 绑定SESSION $_SESSION['uid'] = $user->uid; - $_SESSION['name'] = $user->uname; + // $_SESSION['name'] = $user->uname; // 响应 Gateway::sendToClient($client_id, WsResponse::success( @@ -138,9 +138,12 @@ class WsEvents public function logout(string $client_id) { - if ($_SESSION !== null) { - var_dump($_SESSION); - } + // var_dump('====== ====== ====== start ====== ====== ======'); + // var_dump('关闭客户端ID:'.$client_id); + // if ($_SESSION !== null) { + // var_dump($_SESSION); + // } + // var_dump('====== ====== ====== end ====== ====== ======'); } /** diff --git a/app/common/utils/approval/service/ApprovalFlowService.php b/app/common/utils/approval/service/ApprovalFlowService.php index 6eae8d8..60957f0 100644 --- a/app/common/utils/approval/service/ApprovalFlowService.php +++ b/app/common/utils/approval/service/ApprovalFlowService.php @@ -146,7 +146,8 @@ class ApprovalFlowService 'initiator_id' => $instance->initiator_id, 'status' => $action ]; - \Webman\RedisQueue\Redis::send('approval-callback', $approvalcallback); + $xx = \Webman\RedisQueue\Redis::send('approval-callback', $approvalcallback); + var_dump($xx); // 2) 聚合本步结论(any / all) $typeRaw = strtolower($step['type'] ?? 'all'); diff --git a/plugin/webman/gateway/Events.php b/plugin/webman/gateway/Events.php index 9c6573b..72848ce 100644 --- a/plugin/webman/gateway/Events.php +++ b/plugin/webman/gateway/Events.php @@ -33,7 +33,7 @@ class Events public static function onClose($client_id) { self::$wsEvents->logout($client_id); - var_dump('关闭客户端ID:'.$client_id); + // var_dump('关闭客户端ID:'.$client_id); } } \ No newline at end of file From 13ab4b7868fcf778753eaacc94bf665f0589591b Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 21 Oct 2025 19:53:21 +0800 Subject: [PATCH 20/74] =?UTF-8?q?=E6=A0=B9=E6=8D=AE10.17=E6=B2=9F=E9=80=9A?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StockOrdersController.php | 155 +-- .../controller/StockOrdersFilesController.php | 33 + app/common/logic/StockOrdersFilesLogic.php | 17 + app/common/model/StockOrders.php | 12 +- app/common/model/StockOrdersFiles.php | 60 ++ .../service/StockOrdersFilesService.php | 31 + app/common/service/StockOrdersService.php | 350 +++--- app/common/service/StockOrdersService_bak.php | 997 ------------------ .../approval/service/ApprovalFlowService.php | 3 +- .../utils/pdf/template/stockOrder copy.stub | 35 +- app/common/utils/pdf/template/stockOrder.stub | 84 +- .../utils/pdf/template/stockOrder_bak.stub | 255 ----- .../validate/StockOrdersFilesValidate.php | 29 + app/controller/IndexController.php | 12 +- app/crm/controller/StockOrdersController.php | 135 +-- app/crm/service/StockOrdersService.php | 1 + app/crm/service/StockOrdersService_bak.php | 444 -------- app/crm/service/StockOrdersService_bak2.php | 762 ------------- 18 files changed, 545 insertions(+), 2870 deletions(-) create mode 100644 app/common/controller/StockOrdersFilesController.php create mode 100644 app/common/logic/StockOrdersFilesLogic.php create mode 100644 app/common/model/StockOrdersFiles.php create mode 100644 app/common/service/StockOrdersFilesService.php delete mode 100644 app/common/service/StockOrdersService_bak.php delete mode 100644 app/common/utils/pdf/template/stockOrder_bak.stub create mode 100644 app/common/validate/StockOrdersFilesValidate.php delete mode 100644 app/crm/service/StockOrdersService_bak.php delete mode 100644 app/crm/service/StockOrdersService_bak2.php diff --git a/app/admin/controller/StockOrdersController.php b/app/admin/controller/StockOrdersController.php index 1d854b1..39806a5 100644 --- a/app/admin/controller/StockOrdersController.php +++ b/app/admin/controller/StockOrdersController.php @@ -56,20 +56,60 @@ class StockOrdersController extends BaseController if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); 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['biz_date']) && $data['biz_date'] > 0) $data['biz_date'] = date('Y-m-d', $data['biz_date']); + if (isset($data['latest_arrival_date']) && $data['latest_arrival_date'] > 0) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']); + if (isset($data['pick_up_date']) && $data['pick_up_date'] > 0) $data['pick_up_date'] = date('Y-m-d', $data['pick_up_date']); + if (isset($data['collect_all_date']) && $data['collect_all_date'] > 0) $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']); + // 处理文件附件 + $fileTypes = [ + 'contract' => \app\common\model\StockOrdersFiles::CONTRACT, + 'transaction_slip' => \app\common\model\StockOrdersFiles::TRANSACTION_SLIP, + 'pi_doc' => \app\common\model\StockOrdersFiles::PI_DOC + ]; + + // 初始化文件字段 + foreach (array_keys($fileTypes) as $field) { + $data[$field] = []; + $data[$field . '_url'] = []; + } + + // 按file_code分组文件 + if (!empty($data['files'])) { + $groupedFiles = []; + foreach ($data['files'] as $file) { + if (!isset($groupedFiles[$file['file_code']])) { + $groupedFiles[$file['file_code']] = []; + } + $groupedFiles[$file['file_code']][] = $file['file_url']; + } + + // 映射到对应字段 + foreach ($fileTypes as $field => $fileCode) { + if (isset($groupedFiles[$fileCode])) { + // 原始URL数组 + $data[$field] = $groupedFiles[$fileCode]; + + // 完整URL数组 + $fullUrls = []; + foreach ($groupedFiles[$fileCode] as $url) { + $fullUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($url); + } + $data[$field . '_url'] = $fullUrls; + } + } + unset($data['files']); } 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) { @@ -153,99 +193,4 @@ class StockOrdersController extends BaseController return $this->error($e->getMessage()); } } - - public function desc(Request $request) - { - - $data = [ - 'id' => '', //'主键', - 'order_no' => '', //'备货单编号(业务唯一)', - 'pi_no' => '', //'PI号'/'阿里订单号', - 'biz_date' => '', //'单据日期(时间戳)', - 'salesperson_id' => '', //'业务员ID(关联数据)', - 'salesperson_snapshot' => '', //'业务员姓名快照', - 'clearance_country_id' => '', //'清关目的国ID(关联数据)', - 'clearance_country_snapshot' => '', //'清关目的国名称快照', - // 'ali_order_no' => '', //'阿里订单号', - 'customer_source_id' => '', //'客户来源ID(关联数据)', - 'customer_source_snapshot' => '', //'客户来源名称快照', - 'customer_id' => '', //'客户ID(关联数据)', - 'customer_snapshot' => '', //'客户名称快照', - 'customer_country_id' => '', //'客户所在国ID(关联数据)', - 'customer_country_snapshot' => '', //'客户所在国名称快照', - 'declarant_name' => '', //'清关人(文本)', - 'eta_ship_date' => '', //'预计发运日(时间戳)', - 'shipping_method' => '', //'出运方式(如海运/空运/铁路等)', - 'cif_total_amount' => '', //'0.00' COMMENT '合计到岸价(CIF)', - 'domestic_port_id' => '', //'国内收货港ID(关联数据)', - 'domestic_port_snapshot' => '', //'国内收货港名称快照', - 'trade_term_id' => '', //'贸易条款ID(关联数据,EXW/FOB/CIF等)', - 'trade_term_snapshot' => '', //'贸易条款名称快照', - 'clearance_port_id' => '', //'清关目的港ID(关联数据)', - 'clearance_port_snapshot' => '', //'清关目的港名称快照', - 'latest_arrival_date' => '', //'最迟到港时间(时间戳)', - 'contract_exchange_rate' => '', //'合同汇率(下单锁定)', - 'settlement_currency' => '', //'CNY' COMMENT '结算币种', - 'remark' => '', //'备注', - // 'real_veh' => '', //'0' COMMENT '实车ID', - 'is_final' => '', //'0' COMMENT '是否终版1是0否', - 'status' => '', //'draft' COMMENT '单据状态:draft/submitted/approved/void/reversed等', - ]; - - // (?<=\x60 )[^\r\n']*(?=') - - $items = [ - // 'id' => '', // '主键', - // 'order_id' => '', // '所属备货单ID', - // 'product_code' => '', // '商品编号(可作外部编码)', - // 'sku_snapshot' => '', // '商品/车型名称快照', - // 'unit_price_value_id' => '', // '单价', - // 'handling_fee_value_id' => '', // '操作费', - // 'fob_transport_fee_value_id' => '', // 'FOB内陆运费', - // 'port_misc_fee_value_id' => '', // '港杂费', - // 'retrofit_fee_value_id' => '', // '改装费', - // 'total_price_value_id' => '', // '合计(按订单结算币计算)', - - 'vin' => '', // '车架号', - 'sku_id' => '', // '商品/车型ID(关联数据)', - 'model_snapshot' => '', // '车型(若与sku一致可复用;此处为显示快照)', - 'quantity' => '', // '1.000000' COMMENT '数量', - 'color_interior_id' => '', // '颜色内饰ID(关联数据)', - 'color_interior_snapshot' => '', // '颜色内饰名称快照', - 'color_exterior_id' => '', // '颜色外饰ID(关联数据)', - 'color_exterior_snapshot' => '', // '颜色外饰名称快照', - 'remark' => '', // '备注', - 'unit_price' => '', // '0.000000' COMMENT '单价(含/不含税按业务口径约定)', - 'handling_fee' => '', // '0.000000' COMMENT '手续费(按单车)', - 'fob_transport_fee' => '', // '0.000000' COMMENT 'FOB运输费(按单车)', - 'port_misc_fee' => '', // '0.000000' COMMENT '港杂(按单车)', - 'retrofit_fee' => '', // '0.000000' COMMENT '改装费(按单车)', - 'total_price' => '', // '0.000000' COMMENT '总价(quantity*unit_price,写时落地)', - 'official_price' => '', // 官方指导价 - 'discount_price' => '', // 优惠价 - - - 'modify_list' => [ - // 'order_item_id' => '', // '所属明细ID', - 'option_id' => '', // '配置项ID(关联数据)', - 'option_name_snapshot' => '', // '配置项名称快照', - 'option_price' => '', // '配置项价格(可选,写时快照)', - ] - ]; - - - $account = [ - 'order_id' => '', // '所属备货单ID', - // 'seq_no' => '', // '1' COMMENT '账户序号(行号)', - 'remit_country_id' => '', // '汇款国ID(关联数据)', - 'remit_country_name_snapshot' => '', // '汇款国名称快照', - 'remit_date' => '', // '汇款日期(时间戳)', - 'currency_code' => '', // 'USD' COMMENT '币种代码(如USD/CNY/AED等)', - 'currency_name_snapshot' => '', // '币种名称快照(可选)', - 'account_id' => '', // '账户ID(关联数据)', - 'account_name_snapshot' => '', // '账户名称/开户名快照', - 'remitter_name' => '', // '汇款人', - 'amount' => '', // '0.00' COMMENT '金额', - ]; - } } \ No newline at end of file diff --git a/app/common/controller/StockOrdersFilesController.php b/app/common/controller/StockOrdersFilesController.php new file mode 100644 index 0000000..dfb6a23 --- /dev/null +++ b/app/common/controller/StockOrdersFilesController.php @@ -0,0 +1,33 @@ +service = new StockOrdersFilesService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + // protected function indexFormat($data) + // { + // if (isset($data['created_at'])) + // $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + // if (isset($data['updated_at'])) + // $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + // return $data; + // } +} \ No newline at end of file diff --git a/app/common/logic/StockOrdersFilesLogic.php b/app/common/logic/StockOrdersFilesLogic.php new file mode 100644 index 0000000..3e6c795 --- /dev/null +++ b/app/common/logic/StockOrdersFilesLogic.php @@ -0,0 +1,17 @@ +hasMany(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders'); } + /** + * 关联订单文件附件 + */ + public function files() + { + return $this->hasMany(StockOrdersFiles::class, 'order_id', 'id'); + } + public function salesperson() { diff --git a/app/common/model/StockOrdersFiles.php b/app/common/model/StockOrdersFiles.php new file mode 100644 index 0000000..98daa3f --- /dev/null +++ b/app/common/model/StockOrdersFiles.php @@ -0,0 +1,60 @@ + '合同', + self::TRANSACTION_SLIP => '水单', + self::PI_DOC => 'PI', + ]; +} \ No newline at end of file diff --git a/app/common/service/StockOrdersFilesService.php b/app/common/service/StockOrdersFilesService.php new file mode 100644 index 0000000..3b8c91b --- /dev/null +++ b/app/common/service/StockOrdersFilesService.php @@ -0,0 +1,31 @@ +validator; + } +} \ No newline at end of file diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php index 730fd02..f243654 100644 --- a/app/common/service/StockOrdersService.php +++ b/app/common/service/StockOrdersService.php @@ -15,6 +15,7 @@ use support\Db; use support\Model; use app\common\model\ApprovalInstances; use app\common\model\ApprovalRecords; +use app\common\model\StockOrdersFiles; // 添加文件附件模型 use support\exception\BusinessException; class StockOrdersService @@ -83,6 +84,7 @@ class StockOrdersService $config['with'][] = 'accounts'; $config['with'][] = 'moneyValues'; $config['with'][] = 'salesperson'; + $config['with'][] = 'files'; // 添加文件附件关联 break; case 'store': break; @@ -328,10 +330,16 @@ class StockOrdersService $data = $this->preProcess('Store', $data, $request); $dl = $this->getDataLimitFromRequest($request); $created = $this->logicCreate($data, $dl); + + // 添加金额 + $created->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价'); // 处理车辆和账户信息 $this->processOrderItems($created, $data); + // 处理文件附件 + $this->processOrderFiles($created, $data); + return $this->postProcess('Store', $created); }); } @@ -410,6 +418,8 @@ class StockOrdersService $order = $this->logicShow($config); // 处理车辆和账户信息 $this->processOrderItems($order, $data, true); + // 处理文件附件 + $this->processOrderFiles($order, $data, true); return $this->postProcess('Update', $order); }); } @@ -434,6 +444,62 @@ class StockOrdersService $this->processAccountItems($order, $data['account_list'] ?? []); } + /** + * 处理订单文件附件 + * @param StockOrders $order 订单对象 + * @param array $data 数据 + * @param bool $isUpdate 是否为更新操作 + */ + private function processOrderFiles($order, array $data, bool $isUpdate = false): void + { + // 如果是更新操作,先删除原有的文件附件 + if ($isUpdate) { + $this->clearExistingOrderFiles($order->id); + } + + // 处理文件附件项 + $this->processFileItems($order, $data); + } + + /** + * (更新时)清除已存在的订单文件附件 + * @param int $orderId 订单ID + */ + private function clearExistingOrderFiles(int $orderId): void + { + StockOrdersFiles::where('order_id', $orderId)->delete(); + } + + /** + * 处理文件附件项 + */ + private function processFileItems($order, array $data): void + { + // 定义支持的文件类型 + $fileTypes = [ + 'contract' => StockOrdersFiles::CONTRACT, + 'transaction_slip' => StockOrdersFiles::TRANSACTION_SLIP, + 'pi_doc' => StockOrdersFiles::PI_DOC + ]; + + // 遍历每种文件类型 + foreach ($fileTypes as $field => $fileCode) { + // 检查数据中是否存在该字段且为数组 + if (!empty($data[$field]) && is_array($data[$field])) { + // 处理该字段下的每个文件 + foreach ($data[$field] as $fileUrl) { + $fileData = [ + 'order_id' => $order->id, + 'file_code' => $fileCode, + 'file_url' => $fileUrl, + 'file_name' => StockOrdersFiles::FILE_CODE[$fileCode], + ]; + StockOrdersFiles::create($fileData); + } + } + } + } + /** * (更新时)清除已存在的订单项 * @param int $orderId 订单ID @@ -473,8 +539,9 @@ class StockOrdersService */ private function processVehicleItems($order, array $vehList): void { - $cifTotalAmount = 0.00; $profitTotalAmount = 0.00; + $profitCurrency = ''; + $profitRate = 0; foreach ($vehList as $veh) { $veh['order_id'] = $order->id; $veh['unique_id'] = $this->generateVehicleUniqueId($veh); @@ -483,23 +550,18 @@ class StockOrdersService // 处理金额信息 $this->processVehiclePrices($item, $veh); - - // 计算利润 - // $profit = $this->calculateProfit($veh, $item->mileage, $order); - // $item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润'); // 累计到岸价 - $cifTotalAmount += $veh['total_price']['amount'] ?? 0; + // $cifTotalAmount += $veh['total_price']['amount'] ?? 0; + $profitCurrency === '' ? $profitCurrency = $veh['profit']['currency'] ?? '' : ''; + $profitRate === 0 ? $profitRate = $veh['profit']['rate'] ?? 0 : ''; $profitTotalAmount += $veh['profit']['amount'] ?? 0; // 处理改装项 $this->processModificationItems($item->id, $veh['modify_list'] ?? []); } - - // 保存合计到岸价 - $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, '总利润'); + $order->addMoney('profit_total', $profitCurrency, $profitTotalAmount, $profitRate, '总利润'); } /** @@ -507,13 +569,9 @@ class StockOrdersService */ private function generateVehicleUniqueId(array $veh): string { - $uniqueIdStr = ""; - $uniqueIdStr .= $veh['sku_id'] ?? ''; - $uniqueIdStr .= $veh['model_snapshot'] ?? ''; - $uniqueIdStr .= $veh['color_interior_code'] ?? ''; - $uniqueIdStr .= $veh['color_exterior_code'] ?? ''; - $uniqueIdStr .= $veh['mileage'] ?? ''; - $uniqueIdStr .= json_encode($veh['modify_list'] ?? []); + $keysToRemove = ['vin', 'remark', 'modify_list', 'order_id']; + $array = array_diff_key($veh, array_flip($keysToRemove)); + $uniqueIdStr = json_encode($array); return md5($uniqueIdStr); } @@ -523,9 +581,29 @@ class StockOrdersService */ private function processVehiclePrices($item, array $veh): void { + // unit_price 单价/成交价/收款价 + // total_price 总价 + // handling_fee 手续费 + // fob_transport_fee FOB运输费 + // port_misc_fee 港杂 + // retrofit_fee 改装费 + // ocean_freight 海运费 + // commission 佣金 + // purchase_tax 购置税 + // tax_refund 预估退税 + // clearance_price 报关价 + // profit 利润 + // official_price 官方指导价 + // discount_price 优惠价 + // listing_price 二手挂牌价 + // reduction_price 二手减价/优惠价 + // retention_price 留款/挂账 + // car_price 车价 + // accessory_price 配件费 + // 基础费用 $priceFields = [ - 'unit_price' => '单价', + 'unit_price' => '收款价', 'total_price' => '总价', 'handling_fee' => '手续费', 'fob_transport_fee' => 'FOB运输费', @@ -536,7 +614,10 @@ class StockOrdersService 'purchase_tax' => '购置税', 'tax_refund' => '预估退税', 'clearance_price' => '报关价', - 'profit' => '利润' + 'profit' => '利润', + 'retention_price' => '挂账', + 'car_price' => '车价', + 'accessory_price' => '配件费' ]; foreach ($priceFields as $field => $description) { @@ -564,7 +645,7 @@ class StockOrdersService $veh['reduction_price']['currency'], (float)$veh['reduction_price']['amount'], $veh['reduction_price']['rate'], - '二手减价' + '二手优惠价' ); } else { // 新车 @@ -585,111 +666,6 @@ class StockOrdersService } } - /** - * 计算利润 - */ - private function calculateProfit(array $veh, int $mileage, $order): float - { - $contractExchangeRate = $order->contract_exchange_rate ?: 1; - - // 提取单价并进行汇率转换(如果需要) - $unitPriceRate = $veh['unit_price']['rate'] ?: 1; - if ($unitPriceRate != $contractExchangeRate) { - $unitPrice = (float)($veh['unit_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $unitPrice = (float)($veh['unit_price']['amount'] ?? 0); - } - - // 处理主要价格字段,根据是否需要汇率转换来计算 - if ($mileage > 0) { - // 二手车 - $listingPriceRate = $veh['listing_price']['rate'] ?: 1; - if ($listingPriceRate != $contractExchangeRate) { - $ttPrice = ($veh['listing_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ttPrice = $veh['listing_price']['amount'] ?? 0; - } - - $reductionPriceRate = $veh['reduction_price']['rate'] ?: 1; - if ($reductionPriceRate != $contractExchangeRate) { - $ddPrice = ($veh['reduction_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ddPrice = $veh['reduction_price']['amount'] ?? 0; - } - } else { - // 新车 - $officialPriceRate = $veh['official_price']['rate'] ?: 1; - if ($officialPriceRate != $contractExchangeRate) { - $ttPrice = ($veh['official_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ttPrice = $veh['official_price']['amount'] ?? 0; - } - - $discountPriceRate = $veh['discount_price']['rate'] ?: 1; - if ($discountPriceRate != $contractExchangeRate) { - $ddPrice = ($veh['discount_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ddPrice = $veh['discount_price']['amount'] ?? 0; - } - } - - // 处理其他费用字段,根据是否需要汇率转换来计算 - $handlingFeeRate = $veh['handling_fee']['rate'] ?: 1; - if ($handlingFeeRate != $contractExchangeRate) { - $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0); - } - - $fobTransportFeeRate = $veh['fob_transport_fee']['rate'] ?: 1; - if ($fobTransportFeeRate != $contractExchangeRate) { - $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0); - } - - $portMiscFeeRate = $veh['port_misc_fee']['rate'] ?: 1; - if ($portMiscFeeRate != $contractExchangeRate) { - $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0); - } - - $retrofitFeeRate = $veh['retrofit_fee']['rate'] ?: 1; - if ($retrofitFeeRate != $contractExchangeRate) { - $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0); - } - - $oceanFreightRate = $veh['ocean_freight']['rate'] ?: 1; - if ($oceanFreightRate != $contractExchangeRate) { - $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0) / $contractExchangeRate; - } else { - $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0); - } - - $commissionRate = $veh['commission']['rate'] ?: 1; - if ($commissionRate != $contractExchangeRate) { - $commission = (float)($veh['commission']['amount'] ?? 0) / $contractExchangeRate; - } else { - $commission = (float)($veh['commission']['amount'] ?? 0); - } - - $purchaseTaxRate = $veh['purchase_tax']['rate'] ?: 1; - if ($purchaseTaxRate != $contractExchangeRate) { - $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0) / $contractExchangeRate; - } else { - $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0); - } - - // 预估退税不需要参与汇率转换计算,前端已经计算过了 - $taxRefund = (float)($veh['tax_refund']['amount'] ?? 0); - - // 退税额 是增加利润 - return $unitPrice - $ttPrice + $ddPrice - $handlingFee - $fobTransportFee - $portMiscFee - $retrofitFee - $oceanFreight - $commission - $purchaseTax + $taxRefund; - } - /** * 处理改装项 */ @@ -738,6 +714,9 @@ class StockOrdersService // 提取账户列表信息 $accountList = $this->prepareAccountList($item); + // 提取文件附件列表信息 + $fileList = $this->prepareFileList($item); + // 构建返回数据 $veh = [ // 基本信息 @@ -756,8 +735,8 @@ class StockOrdersService // 订单项 'veh_list' => array_values($vehListData['list']), 'contract_exchange_rate' => $item->contract_exchange_rate, - 'cif_total_amount' => $moneyValues['cif_total_amount'] ?? [], 'profit_total' => $moneyValues['profit_total'] ?? [], + 'cif_total' => $moneyValues['cif_total'] ?? [], // 运输和交付信息 'declarant_name' => $item->declarant_name, @@ -776,7 +755,10 @@ class StockOrdersService 'acc_index' => count($accountList) + 1, 'currency_symbol' => $item->settlement_currency, 'sign_imgs' => $this->queryAppro($item->id), - 'contract_url' => $this->getContractUrl($item->contract ?? null) + 'contract_url' => $this->getContractUrl($item->contract ?? null), + + // 文件附件信息 + 'file_list' => $fileList ]; return $veh; @@ -798,7 +780,7 @@ class StockOrdersService // 拼接 remark 值 if (!empty($v->remark)) { if (!empty($vehList[$v->unique_id]['remark'])) { - $vehList[$v->unique_id]['remark'] .= "; " . $v->remark; + $vehList[$v->unique_id]['remark'] .= "
" . $v->remark; } else { $vehList[$v->unique_id]['remark'] = $v->remark; } @@ -811,12 +793,10 @@ class StockOrdersService $moneyValues = $this->processItemMoneyValues($v); // 处理改装信息 - $modificationText = $this->getModificationText($v->options); + // $modificationText = $this->getModificationText($v->options); - // 计算单项利润 - // $itemProfit = $this->calculateProfit($moneyValues, $v->mileage, $item); - // var_dump($moneyValues); - $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount']; + // 利润 + // $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount']; // 构建车辆信息 $vehList[$v->unique_id] = [ @@ -825,17 +805,17 @@ class StockOrdersService 'color_interior_snapshot' => $v->color_interior_snapshot, 'color_exterior_snapshot' => $v->color_exterior_snapshot, 'num' => 1, - 'modify' => $modificationText, + // 'modify' => $modificationText, 'mileage' => $v->mileage, 'remark' => $v->remark, ] + $moneyValues; - + // var_dump($vehList[$v->unique_id]); // 添加利润信息 - $vehList[$v->unique_id]['profit'] = [ - 'currency' => $item->settlement_currency, - 'amount' => $itemProfit, - 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',') - ]; + // $vehList[$v->unique_id]['profit'] = [ + // 'currency' => $item->settlement_currency, + // 'amount' => $itemProfit, + // 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',') + // ]; } return ['list' => $vehList]; @@ -877,16 +857,38 @@ class StockOrdersService { $vehicleData['num'] += 1; - // 更新总价显示 - if (isset($vehicleData['total_price']['amount'])) { - $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num']; - $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ','); - } + // // 更新总价显示 + // if (isset($vehicleData['total_price']['amount'])) { + // $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num']; + // $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ','); + // } - // 更新利润显示 - if (isset($vehicleData['profit']['amount'])) { - $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num']; - $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ','); + // // 更新利润显示 + // if (isset($vehicleData['profit']['amount'])) { + // $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num']; + // $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ','); + // } + + // var_dump($vehicleData); + + $fieldList = [ + 'fob_transport_fee', + 'car_price', + 'ocean_freight', + 'commission', + 'retention_price', + 'port_misc_fee', + 'total_price', + 'clearance_price', + 'profit' + ]; + + foreach ($vehicleData as $field => $value) { + if (in_array($field, $fieldList)) { + $amount = $vehicleData[$field]['amount'] * $vehicleData['num']; + $currencySymbol = SysCurrency::where('currency_code', $vehicleData[$field]['currency'])->value('currency_symbol'); + $vehicleData[$field]['currency_info'] = $currencySymbol . number_format($amount, 2, '.', ','); + } } } @@ -927,6 +929,45 @@ class StockOrdersService return $accountList; } + /** + * 准备文件附件列表 + */ + private function prepareFileList($item): array + { + $fileList = []; + + // 按file_code分组文件 + $groupedFiles = []; + foreach ($item->files as $file) { + if (!isset($groupedFiles[$file->file_code])) { + $groupedFiles[$file->file_code] = []; + } + $groupedFiles[$file->file_code][] = [ + 'id' => $file->id, + 'file_url' => $file->file_url, + 'file_full_url' => $this->getFileUrl($file->file_url), + ]; + } + + // 定义支持的文件类型 + $fileTypes = [ + 'contract' => StockOrdersFiles::CONTRACT, + 'transaction_slip' => StockOrdersFiles::TRANSACTION_SLIP, + 'pi_doc' => StockOrdersFiles::PI_DOC + ]; + + // 按前端需要的字段组织数据 + foreach ($fileTypes as $field => $fileCode) { + if (isset($groupedFiles[$fileCode])) { + $fileList[$field] = $groupedFiles[$fileCode]; + } else { + $fileList[$field] = []; + } + } + + return $fileList; + } + /** * 获取货币信息 */ @@ -967,4 +1008,15 @@ class StockOrdersService } return (new \app\common\service\OssService)->generatePrivateUrl($contract); } + + /** + * 获取文件URL + */ + private function getFileUrl(?string $fileUrl): string + { + if (empty($fileUrl)) { + return ''; + } + return (new \app\common\service\OssService)->generatePrivateUrl($fileUrl); + } } \ No newline at end of file diff --git a/app/common/service/StockOrdersService_bak.php b/app/common/service/StockOrdersService_bak.php deleted file mode 100644 index 5ee03a9..0000000 --- a/app/common/service/StockOrdersService_bak.php +++ /dev/null @@ -1,997 +0,0 @@ -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': - case 'approval': - $config['where']['id'] = $p['id']; - break; - case 'detail': - 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 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') ?? ''; - $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - - // if ($data['is_final'] == 1) { - $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; - $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; - // } - - if ($data['is_final'] == 1) { - // 检查是否至少有一个车辆填写了vin - $hasVin = false; - foreach ($data['veh_list'] as $k => $v) { - if ($v['vin'] != '') { - $hasVin = true; - break; - } - } - // 如果没有任何车辆填写vin,则抛出异常 - if (!$hasVin) { - throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核'); - } - } - - // 检查绑定 - (new UserService())->checkBind($userId); - 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.'】创建终版成功,但更新原单失败'); - } - } - // 启动审批 - if ($res->approval_status == 1) { - $this->startApproval($res); - } - return $res; - } - - /** - * 启动审批 - */ - public function startApproval($item) - { - // 启动审批 - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->start('stock_orders', 'stock_orders', $item->id, [], $item->salesperson_id); - // 异步生成pdf文件 - \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]); - } - - /** - * 创建PDF文件 - */ - 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->formatData($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 - ); - - // 上传云端 - $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 queryAppro($bizId) - { - $instances = ApprovalInstances::where('biz_id', $bizId)->where('biz_type', 'stock_orders')->first(); - if (!$instances) { - return []; - } - - $records = ApprovalRecords::where('instance_id', $instances->id)->where('action', 'approve')->orderBy('step_index', 'asc')->pluck('approver_id')->toArray(); - if (count($records) == 0) { - return []; - } - - $signImgs = []; - foreach ($records as $k => $v) { - $signImg = User::where('id', $v)->value('sign_img'); - $signImgs[$k] = (!empty($signImg))?(new \app\common\service\OssService)->generatePrivateUrl($signImg):''; - } - - return $signImgs; - } - - /** - * 打印数据 - */ - public function servicePrint(Request $request) - { - $config = $this->buildQueryConfig($request, 'show'); - $item = $this->logicShow($config); - return $this->postProcess('Print', $item); - } - - public function serviceDetail(Request $request) - { - $config = $this->buildQueryConfig($request, 'detail'); - $item = $this->logicShow($config); - $detail = $this->formatData($item); - return $this->postProcess('Detail', $detail); - } - - /** - * 审批 - */ - public function serviceApproval(Request $request) - { - $config = $this->buildQueryConfig($request, 'approval'); - $this->logicUpdateBy($config, [ - 'approval_status' => 1 - ]); - $item = $this->logicShow($config); - $this->startApproval($item); - return $this->postProcess('Approval', $item); - } - - /** - * 作废审批 - */ - public function serviceApprovalNullify(Request $request) - { - $config = $this->buildQueryConfig($request, 'approval'); - $item = $this->logicShow($config); - $this->approvalNullify($item); - return $this->postProcess('Approval', $item); - } - - /** - * 审批作废 - */ - public function approvalNullify($item) - { - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, [], $item->salesperson_id); - } - - /** - * 撤销审批 - */ - public function serviceApprovalRevoke(Request $request) - { - $config = $this->buildQueryConfig($request, 'approval'); - $item = $this->logicShow($config); - $this->approvalRevoke($item); - return $this->postProcess('Approval', $item); - } - - public function approvalRevoke($item) - { - $instance = \app\common\model\ApprovalInstances::where('biz_id', $item->id)->where('flow_type', 'stock_orders')->first(); - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->revoke($instance->id, $item->salesperson_id); - } - - /** - * 创建 - * - * @param Request $request - * @param array $data - * @return mixed - */ - 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); - - // 处理车辆和账户信息 - $this->processOrderItems($created, $data); - - return $this->postProcess('Store', $created); - }); - } - - protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array - { - // 兼容传类名或实例 - $m = \is_string($model) ? new $model : $model; - // 1) 优先使用 fillable - $keys = $m->getFillable(); - // 2) 若没配置 fillable(常见:用 guarded),回退到完整表字段,避免误伤 - if (empty($keys)) { - $keys = $m->getConnection() - ->getSchemaBuilder() - ->getColumnListing($m->getTable()); - } - // 3) 允许额外白名单(如虚拟字段、JSON映射字段) - if ($extraWhitelist) { - $keys = array_merge($keys, $extraWhitelist); - } - return array_intersect_key($data, array_flip($keys)); - } - - /** - * 更新前处理 - * - * @param array $data - * @param Request $request - * @return array - */ - public function beforeServiceUpdate($data, Request $request) - { - $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['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - - $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; - $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; - return $data; - } - - /** - * 更新后处理 - * - * @param mixed $res - * @return mixed - */ - protected function afterServiceUpdate($res) - { - // 启动审批 - if ($res->approval_status == 1) { - $this->startApproval($res); - } - return $res; - } - - /** - * 更新 - * - * @param Request $request - * @param array $data - * @return mixed - */ - public function serviceUpdate(Request $request, array $data = []) - { - // 关联表较多,增加事务处理 - return Db::transaction(function () use ($request, $data) { - $data = $this->preProcess('Update', $data, $request); - $config = $this->buildQueryConfig($request, 'update'); - // 过滤掉非库字段 - $dbData = $this->onlyFillableData($config['model'], $data); - // 更新主表 - $updated = $this->logicUpdateBy($config, $dbData); - // 获取更新后的数据 - $order = $this->logicShow($config); - // 处理车辆和账户信息 - $this->processOrderItems($order, $data, true); - return $this->postProcess('Update', $order); - }); - } - - /** - * 处理订单项(车辆和账户) - * @param StockOrders $order 订单对象 - * @param array $data 数据 - * @param bool $isUpdate 是否为更新操作 - */ - private function processOrderItems($order, array $data, bool $isUpdate = false): void - { - // 如果是更新操作,先删除原有的关联数据 - if ($isUpdate) { - $this->clearExistingOrderItems($order->id); - } - - // 处理车辆项 - $this->processVehicleItems($order, $data['veh_list'] ?? []); - - // 处理账户项 - $this->processAccountItems($order, $data['account_list'] ?? []); - } - - /** - * (更新时)清除已存在的订单项 - * @param int $orderId 订单ID - */ - private function clearExistingOrderItems(int $orderId): void - { - // 删除车辆改装项 - StockOrderItemOptions::whereHas('item', function ($query) use ($orderId) { - $query->where('order_id', $orderId); - })->delete(); - - // 删除车辆项及其相关金额记录 - $orderItems = StockOrderItems::where('order_id', $orderId)->get(); - foreach ($orderItems as $item) { - // 删除车辆项的金额记录 - Db::table('veh_money_value') - ->where('object_scene', 'stock_order_items') - ->where('object_id', $item->id) - ->delete(); - } - - // 删除车辆项 - StockOrderItems::where('order_id', $orderId)->delete(); - - // 删除订单本身的金额记录 - Db::table('veh_money_value') - ->where('object_scene', 'stock_orders') - ->where('object_id', $orderId) - ->delete(); - - // 删除账户项 - StockOrderAccounts::where('order_id', $orderId)->delete(); - } - - /** - * 处理车辆项 - */ - private function processVehicleItems($order, array $vehList): void - { - $cifTotalAmount = 0.00; - $profitTotalAmount = 0.00; - foreach ($vehList as $veh) { - $veh['order_id'] = $order->id; - $veh['unique_id'] = $this->generateVehicleUniqueId($veh); - - $item = StockOrderItems::create($veh); - - // 处理金额信息 - $this->processVehiclePrices($item, $veh); - - // 计算利润 - // $profit = $this->calculateProfit($veh, $item->mileage, $order); - // $item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润'); - - // 累计到岸价 - $cifTotalAmount += $veh['total_price']['amount'] ?? 0; - $profitTotalAmount += $veh['profit']['amount'] ?? 0; - - // 处理改装项 - $this->processModificationItems($item->id, $veh['modify_list'] ?? []); - } - - // 保存合计到岸价 - $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, '总利润'); - } - - /** - * 生成车辆唯一标识 - */ - private function generateVehicleUniqueId(array $veh): string - { - // $uniqueIdStr = ""; - // $uniqueIdStr .= $veh['sku_id'] ?? ''; - // $uniqueIdStr .= $veh['model_snapshot'] ?? ''; - // $uniqueIdStr .= $veh['color_interior_code'] ?? ''; - // $uniqueIdStr .= $veh['color_exterior_code'] ?? ''; - // $uniqueIdStr .= $veh['mileage'] ?? ''; - // $uniqueIdStr .= json_encode($veh['modify_list'] ?? []); - - $keysToRemove = ['vin', 'remark', 'modify_list', 'order_id']; - $array = array_diff_key($veh, array_flip($keysToRemove)); - $uniqueIdStr = json_encode($array); - - return md5($uniqueIdStr); - } - - /** - * 处理车辆价格信息 - */ - private function processVehiclePrices($item, array $veh): void - { - // unit_price 单价/成交价/收款价 - // total_price 总价 - // handling_fee 手续费 - // fob_transport_fee FOB运输费 - // port_misc_fee 港杂 - // retrofit_fee 改装费 - // ocean_freight 海运费 - // commission 佣金 - // purchase_tax 购置税 - // tax_refund 预估退税 - // clearance_price 报关价 - // profit 利润 - // official_price 官方指导价 - // discount_price 优惠价 - // listing_price 二手挂牌价 - // reduction_price 二手减价/优惠价 - // retention_price 留款/挂账 - // car_price 车价 - // modify_price 改装价 - - // 基础费用 - $priceFields = [ - 'unit_price' => '收款价', - 'total_price' => '总价', - 'handling_fee' => '手续费', - 'fob_transport_fee' => 'FOB运输费', - 'port_misc_fee' => '港杂', - 'retrofit_fee' => '改装费', - 'ocean_freight' => '海运费', - 'commission' => '佣金', - 'purchase_tax' => '购置税', - 'tax_refund' => '预估退税', - 'clearance_price' => '报关价', - 'profit' => '利润', - 'retention_price' => '挂账', - 'car_price' => '车价', - 'modify_price' => '改装价' - ]; - - foreach ($priceFields as $field => $description) { - $item->addMoney( - $field, - $veh[$field]['currency'], - (float)$veh[$field]['amount'], - $veh[$field]['rate'], - $description - ); - } - - // 根据里程处理新车或二手车价格 - if (!empty($veh['mileage']) && $veh['mileage'] > 0) { - // 二手车 - $item->addMoney( - 'listing_price', - $veh['listing_price']['currency'], - (float)$veh['listing_price']['amount'], - $veh['listing_price']['rate'], - '二手挂牌价' - ); - $item->addMoney( - 'reduction_price', - $veh['reduction_price']['currency'], - (float)$veh['reduction_price']['amount'], - $veh['reduction_price']['rate'], - '优惠价' - ); - } else { - // 新车 - $item->addMoney( - 'official_price', - $veh['official_price']['currency'], - (float)$veh['official_price']['amount'], - $veh['official_price']['rate'], - '官方指导价' - ); - $item->addMoney( - 'discount_price', - $veh['discount_price']['currency'], - (float)$veh['discount_price']['amount'], - $veh['discount_price']['rate'], - '优惠价' - ); - } - } - - /** - * 计算利润 - */ - private function calculateProfit(array $veh, int $mileage, $order): float - { - $contractExchangeRate = $order->contract_exchange_rate ?: 1; - - // 提取单价并进行汇率转换(如果需要) - $unitPriceRate = $veh['unit_price']['rate'] ?: 1; - if ($unitPriceRate != $contractExchangeRate) { - $unitPrice = (float)($veh['unit_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $unitPrice = (float)($veh['unit_price']['amount'] ?? 0); - } - - // 处理主要价格字段,根据是否需要汇率转换来计算 - if ($mileage > 0) { - // 二手车 - $listingPriceRate = $veh['listing_price']['rate'] ?: 1; - if ($listingPriceRate != $contractExchangeRate) { - $ttPrice = ($veh['listing_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ttPrice = $veh['listing_price']['amount'] ?? 0; - } - - $reductionPriceRate = $veh['reduction_price']['rate'] ?: 1; - if ($reductionPriceRate != $contractExchangeRate) { - $ddPrice = ($veh['reduction_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ddPrice = $veh['reduction_price']['amount'] ?? 0; - } - } else { - // 新车 - $officialPriceRate = $veh['official_price']['rate'] ?: 1; - if ($officialPriceRate != $contractExchangeRate) { - $ttPrice = ($veh['official_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ttPrice = $veh['official_price']['amount'] ?? 0; - } - - $discountPriceRate = $veh['discount_price']['rate'] ?: 1; - if ($discountPriceRate != $contractExchangeRate) { - $ddPrice = ($veh['discount_price']['amount'] ?? 0) / $contractExchangeRate; - } else { - $ddPrice = $veh['discount_price']['amount'] ?? 0; - } - } - - // 处理其他费用字段,根据是否需要汇率转换来计算 - $handlingFeeRate = $veh['handling_fee']['rate'] ?: 1; - if ($handlingFeeRate != $contractExchangeRate) { - $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0); - } - - $fobTransportFeeRate = $veh['fob_transport_fee']['rate'] ?: 1; - if ($fobTransportFeeRate != $contractExchangeRate) { - $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0); - } - - $portMiscFeeRate = $veh['port_misc_fee']['rate'] ?: 1; - if ($portMiscFeeRate != $contractExchangeRate) { - $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0); - } - - $retrofitFeeRate = $veh['retrofit_fee']['rate'] ?: 1; - if ($retrofitFeeRate != $contractExchangeRate) { - $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0) / $contractExchangeRate; - } else { - $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0); - } - - $oceanFreightRate = $veh['ocean_freight']['rate'] ?: 1; - if ($oceanFreightRate != $contractExchangeRate) { - $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0) / $contractExchangeRate; - } else { - $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0); - } - - $commissionRate = $veh['commission']['rate'] ?: 1; - if ($commissionRate != $contractExchangeRate) { - $commission = (float)($veh['commission']['amount'] ?? 0) / $contractExchangeRate; - } else { - $commission = (float)($veh['commission']['amount'] ?? 0); - } - - $purchaseTaxRate = $veh['purchase_tax']['rate'] ?: 1; - if ($purchaseTaxRate != $contractExchangeRate) { - $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0) / $contractExchangeRate; - } else { - $purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0); - } - - // 预估退税不需要参与汇率转换计算,前端已经计算过了 - $taxRefund = (float)($veh['tax_refund']['amount'] ?? 0); - - // 退税额 是增加利润 - return $unitPrice - $ttPrice + $ddPrice - $handlingFee - $fobTransportFee - $portMiscFee - $retrofitFee - $oceanFreight - $commission - $purchaseTax + $taxRefund; - } - - /** - * 处理改装项 - */ - private function processModificationItems(int $orderItemId, array $modifyList): void - { - if (empty($modifyList)) { - return; - } - - foreach ($modifyList as $modify) { - $modify['order_item_id'] = $orderItemId; - StockOrderItemOptions::create($modify); - } - } - - /** - * 处理账户项 - */ - private function processAccountItems($order, array $accountList): void - { - if (empty($accountList)) { - return; - } - - foreach ($accountList as $account) { - $account['order_id'] = $order->id; - if (!empty($account['remit_date'])) { - $account['remit_date'] = strtotime($account['remit_date']); - } - StockOrderAccounts::create($account); - } - } - - - // ====== ======= ====== ======= ====== 信息处理 ======= ====== ======= ====== ======= - - // PDF数据 - public function formatData($item) - { - // 提取车辆列表信息 - $vehListData = $this->prepareVehicleListData($item); - - // 提取订单金额信息 - $moneyValues = $this->prepareOrderMoneyValues($item); - - // 提取账户列表信息 - $accountList = $this->prepareAccountList($item); - - // 构建返回数据 - $veh = [ - // 基本信息 - 'order_no' => $item->order_no, - 'salesperson_snapshot' => $item->salesperson_snapshot, - 'sign_img_url' => $this->getSignatureImageUrl($item->salesperson->sign_img ?? null), - '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' => array_values($vehListData['list']), - 'contract_exchange_rate' => $item->contract_exchange_rate, - 'cif_total_amount' => $moneyValues['cif_total_amount'] ?? [], - 'profit_total' => $moneyValues['profit_total'] ?? [], - - // 运输和交付信息 - '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), - 'pick_up_date' => date('Y-m-d', $item->pick_up_date), - 'collect_all_date' => date('Y-m-d', $item->collect_all_date), - 'is_final' => $item->is_final, - - // 账户信息 - 'account_list' => $accountList, - 'acc_index' => count($accountList) + 1, - 'currency_symbol' => $item->settlement_currency, - 'sign_imgs' => $this->queryAppro($item->id), - 'contract_url' => $this->getContractUrl($item->contract ?? null) - ]; - - return $veh; - } - - /** - * 准备车辆列表数据 - */ - private function prepareVehicleListData($item): array - { - $vehList = []; - $index = 0; - $currencyInfo = $this->getCurrencyInfo($item->settlement_currency); - - foreach ($item->items as $v) { - // 如果已存在相同车辆,增加数量 - 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; - } - - $index++; - // 处理金额信息 - $moneyValues = $this->processItemMoneyValues($v); - - // 处理改装信息 - $modificationText = $this->getModificationText($v->options); - - // 计算单项利润 - // $itemProfit = $this->calculateProfit($moneyValues, $v->mileage, $item); - // var_dump($moneyValues); - $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount']; - - // 构建车辆信息 - $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' => $modificationText, - 'mileage' => $v->mileage, - 'remark' => $v->remark, - ] + $moneyValues; - - // 添加利润信息 - $vehList[$v->unique_id]['profit'] = [ - 'currency' => $item->settlement_currency, - 'amount' => $itemProfit, - 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',') - ]; - } - - return ['list' => $vehList]; - } - - /** - * 处理单项金额值 - */ - private function processItemMoneyValues($item): array - { - $moneyValues = []; - foreach ($item->moneyValues as $money) { - $moneyValues[$money->field] = [ - 'currency' => $money->currency, - 'amount' => $money->amount, - 'rate' => $money->exchange_rate, - 'currency_info' => $this->formatCurrency($money->amount, $money->currency) - ]; - } - return $moneyValues; - } - - /** - * 获取改装文本 - */ - private function getModificationText($options): string - { - $modificationText = ''; - foreach ($options as $option) { - $modificationText .= $option->option_name_snapshot . ' '; - } - return trim($modificationText); - } - - /** - * 增加车辆数量并更新相关金额显示 - */ - private function incrementVehicleCount(array &$vehicleData, array $currencyInfo): void - { - $vehicleData['num'] += 1; - - // 更新总价显示 - if (isset($vehicleData['total_price']['amount'])) { - $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num']; - $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ','); - } - - // 更新利润显示 - if (isset($vehicleData['profit']['amount'])) { - $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num']; - $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ','); - } - } - - /** - * 准备订单金额值 - */ - private function prepareOrderMoneyValues($item): array - { - $moneyValues = []; - foreach ($item->moneyValues as $money) { - $moneyValues[$money->field] = [ - 'currency' => $money->currency, - 'amount' => $money->amount, - 'rate' => $money->exchange_rate, - 'currency_info' => $this->formatCurrency($money->amount, $money->currency) - ]; - } - return $moneyValues; - } - - /** - * 准备账户列表 - */ - private function prepareAccountList($item): array - { - $accountList = []; - foreach ($item->accounts as $k => $account) { - $accountList[] = [ - 'index' => '收款' . ($k + 1), - 'remit_country_name_snapshot' => $account->remit_country_name_snapshot, - 'remit_date' => date('Y-m-d', $account->remit_date), - 'currency_name_snapshot' => $account->currency_name_snapshot, - 'account_name_snapshot' => $account->account_name_snapshot, - 'remitter_name' => $account->remitter_name, - 'amount' => $account->amount, - ]; - } - return $accountList; - } - - /** - * 获取货币信息 - */ - private function getCurrencyInfo(string $currencyCode): array - { - return SysCurrency::where('currency_code', $currencyCode) - ->first(['currency_symbol', 'currency_name']) - ->toArray(); - } - - /** - * 格式化货币显示 - */ - private function formatCurrency(float $amount, string $currencyCode): string - { - $currencySymbol = SysCurrency::where('currency_code', $currencyCode)->value('currency_symbol'); - return $currencySymbol . number_format($amount, 2, '.', ','); - } - - /** - * 获取签名图片URL - */ - private function getSignatureImageUrl(?string $signImg): string - { - if (empty($signImg)) { - return ''; - } - return (new \app\common\service\OssService)->generatePrivateUrl($signImg); - } - - /** - * 获取合同URL - */ - private function getContractUrl(?string $contract): string - { - if (empty($contract)) { - return ''; - } - return (new \app\common\service\OssService)->generatePrivateUrl($contract); - } -} \ No newline at end of file diff --git a/app/common/utils/approval/service/ApprovalFlowService.php b/app/common/utils/approval/service/ApprovalFlowService.php index 60957f0..6eae8d8 100644 --- a/app/common/utils/approval/service/ApprovalFlowService.php +++ b/app/common/utils/approval/service/ApprovalFlowService.php @@ -146,8 +146,7 @@ class ApprovalFlowService 'initiator_id' => $instance->initiator_id, 'status' => $action ]; - $xx = \Webman\RedisQueue\Redis::send('approval-callback', $approvalcallback); - var_dump($xx); + \Webman\RedisQueue\Redis::send('approval-callback', $approvalcallback); // 2) 聚合本步结论(any / all) $typeRaw = strtolower($step['type'] ?? 'all'); diff --git a/app/common/utils/pdf/template/stockOrder copy.stub b/app/common/utils/pdf/template/stockOrder copy.stub index 8a2dbf5..43f887f 100644 --- a/app/common/utils/pdf/template/stockOrder copy.stub +++ b/app/common/utils/pdf/template/stockOrder copy.stub @@ -110,7 +110,7 @@ 阿里订单号/PI号: 日期: - 关目的国: + 清关目的国: 客户来源: 客户名称: 客户所在国: @@ -144,6 +144,7 @@ 优惠 单价 总价 + 报关价 利润 @@ -163,16 +164,22 @@ 0): ?> - - + + - - + + - - - + + + + + + + + 备注: + @@ -180,8 +187,8 @@ 合同汇率: - - 合计到岸价: + + 合计到岸价: @@ -275,8 +282,8 @@
备发货负责人签字: - - + + @@ -287,8 +294,8 @@
组长签字: - - + + diff --git a/app/common/utils/pdf/template/stockOrder.stub b/app/common/utils/pdf/template/stockOrder.stub index 43f887f..20b10b3 100644 --- a/app/common/utils/pdf/template/stockOrder.stub +++ b/app/common/utils/pdf/template/stockOrder.stub @@ -120,49 +120,40 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + - - + - + - - + + + 0): ?> @@ -170,28 +161,47 @@ - - - - - + + + + + + + + + + + - + + + + + + + + + + - + + - - - +
编号 车型 数量/台 颜色/外内饰改装官方指导价/二手挂牌价优惠单价总价报关价利润颜色/内收款价总价官方指导价/二手挂牌价优惠利润
+ + + 0): ?> () + +
改装费FOB运费车价海运费佣金挂账港杂
- 备注: +
+ 备注: + +
+ 合同汇率: - 合计到岸价: + + 合计到岸价:
diff --git a/app/common/utils/pdf/template/stockOrder_bak.stub b/app/common/utils/pdf/template/stockOrder_bak.stub deleted file mode 100644 index 6b93ecc..0000000 --- a/app/common/utils/pdf/template/stockOrder_bak.stub +++ /dev/null @@ -1,255 +0,0 @@ - - - - - 合塑实业-汽车事业部-备货单(客户下定) - - - -
- -
-

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

-
- 备货单号: - 业务员: -
-
- - - - - - - - - - - - - - - - - - - - - -
阿里订单号/PI号: 日期: 关目的国: 客户来源: 客户名称: 客户所在国:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0): ?> - - - - - - - - - - - - - - - -
编号车型数量/台颜色/外内饰改装单价总价官方指导价/二手挂牌价优惠/二手减价
- 合同汇率: - - 合计到岸价: -
- - - - - - - - - - - - - - - - - - - - - -
清关人: 预计发运日期: 出运方式: 国内收货港: 贸易条款/清关目的港: /最迟到港时间:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
计划收款信息序号汇款国日期币种账户汇款人金额
- -
-
-
- 下单人: - -
-
-
下单时间:
-
- -
- - \ No newline at end of file diff --git a/app/common/validate/StockOrdersFilesValidate.php b/app/common/validate/StockOrdersFilesValidate.php new file mode 100644 index 0000000..c7fca82 --- /dev/null +++ b/app/common/validate/StockOrdersFilesValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 10969ac..72532c7 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -74,25 +74,25 @@ class IndexController $options = [ 'controller' => [ 'module' => 'common', - 'name' => 'user_group_members' + 'name' => 'stock_orders_files' ], 'model' => [ 'module' => 'common', - 'name' => 'user_group_members' + 'name' => 'stock_orders_files' ], 'service' => [ 'module' => 'common', - 'name' => 'user_group_members' + 'name' => 'stock_orders_files' ], 'logic' => [ 'module' => 'common', - 'name' => 'user_group_members' + 'name' => 'stock_orders_files' ], 'validate' => [ 'module' => 'common', - 'name' => 'user_group_members' + 'name' => 'stock_orders_files' ], - 'table' => 'user_group_members' + 'table' => 'stock_orders_files' ]; $result = (new Generate($options))->doGenerate(); diff --git a/app/crm/controller/StockOrdersController.php b/app/crm/controller/StockOrdersController.php index b297b51..3716c69 100644 --- a/app/crm/controller/StockOrdersController.php +++ b/app/crm/controller/StockOrdersController.php @@ -61,8 +61,44 @@ class StockOrdersController extends BaseController if (isset($data['pick_up_date']) && $data['pick_up_date'] > 0) $data['pick_up_date'] = date('Y-m-d', $data['pick_up_date']); if (isset($data['collect_all_date']) && $data['collect_all_date'] > 0) $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']); + // 处理文件附件 + $fileTypes = [ + 'contract' => \app\common\model\StockOrdersFiles::CONTRACT, + 'transaction_slip' => \app\common\model\StockOrdersFiles::TRANSACTION_SLIP, + 'pi_doc' => \app\common\model\StockOrdersFiles::PI_DOC + ]; + + // 初始化文件字段 + foreach (array_keys($fileTypes) as $field) { + $data[$field] = []; + $data[$field . '_url'] = []; + } + + // 按file_code分组文件 + if (!empty($data['files'])) { + $groupedFiles = []; + foreach ($data['files'] as $file) { + if (!isset($groupedFiles[$file['file_code']])) { + $groupedFiles[$file['file_code']] = []; + } + $groupedFiles[$file['file_code']][] = $file['file_url']; + } + + // 映射到对应字段 + foreach ($fileTypes as $field => $fileCode) { + if (isset($groupedFiles[$fileCode])) { + // 原始URL数组 + $data[$field] = $groupedFiles[$fileCode]; + + // 完整URL数组 + $fullUrls = []; + foreach ($groupedFiles[$fileCode] as $url) { + $fullUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($url); + } + $data[$field . '_url'] = $fullUrls; + } + } + unset($data['files']); } if (count($data['moneyValues']) > 0) { @@ -223,99 +259,4 @@ class StockOrdersController extends BaseController return $this->error($e->getMessage()); } } - - public function desc(Request $request) - { - - $data = [ - 'id' => '', //'主键', - 'order_no' => '', //'备货单编号(业务唯一)', - 'pi_no' => '', //'PI号'/'阿里订单号', - 'biz_date' => '', //'单据日期(时间戳)', - 'salesperson_id' => '', //'业务员ID(关联数据)', - 'salesperson_snapshot' => '', //'业务员姓名快照', - 'clearance_country_id' => '', //'清关目的国ID(关联数据)', - 'clearance_country_snapshot' => '', //'清关目的国名称快照', - // 'ali_order_no' => '', //'阿里订单号', - 'customer_source_id' => '', //'客户来源ID(关联数据)', - 'customer_source_snapshot' => '', //'客户来源名称快照', - 'customer_id' => '', //'客户ID(关联数据)', - 'customer_snapshot' => '', //'客户名称快照', - 'customer_country_id' => '', //'客户所在国ID(关联数据)', - 'customer_country_snapshot' => '', //'客户所在国名称快照', - 'declarant_name' => '', //'清关人(文本)', - 'eta_ship_date' => '', //'预计发运日(时间戳)', - 'shipping_method' => '', //'出运方式(如海运/空运/铁路等)', - 'cif_total_amount' => '', //'0.00' COMMENT '合计到岸价(CIF)', - 'domestic_port_id' => '', //'国内收货港ID(关联数据)', - 'domestic_port_snapshot' => '', //'国内收货港名称快照', - 'trade_term_id' => '', //'贸易条款ID(关联数据,EXW/FOB/CIF等)', - 'trade_term_snapshot' => '', //'贸易条款名称快照', - 'clearance_port_id' => '', //'清关目的港ID(关联数据)', - 'clearance_port_snapshot' => '', //'清关目的港名称快照', - 'latest_arrival_date' => '', //'最迟到港时间(时间戳)', - 'contract_exchange_rate' => '', //'合同汇率(下单锁定)', - 'settlement_currency' => '', //'CNY' COMMENT '结算币种', - 'remark' => '', //'备注', - // 'real_veh' => '', //'0' COMMENT '实车ID', - 'is_final' => '', //'0' COMMENT '是否终版1是0否', - 'status' => '', //'draft' COMMENT '单据状态:draft/submitted/approved/void/reversed等', - ]; - - // (?<=\x60 )[^\r\n']*(?=') - - $items = [ - // 'id' => '', // '主键', - // 'order_id' => '', // '所属备货单ID', - // 'product_code' => '', // '商品编号(可作外部编码)', - // 'sku_snapshot' => '', // '商品/车型名称快照', - // 'unit_price_value_id' => '', // '单价', - // 'handling_fee_value_id' => '', // '操作费', - // 'fob_transport_fee_value_id' => '', // 'FOB内陆运费', - // 'port_misc_fee_value_id' => '', // '港杂费', - // 'retrofit_fee_value_id' => '', // '改装费', - // 'total_price_value_id' => '', // '合计(按订单结算币计算)', - - 'vin' => '', // '车架号', - 'sku_id' => '', // '商品/车型ID(关联数据)', - 'model_snapshot' => '', // '车型(若与sku一致可复用;此处为显示快照)', - 'quantity' => '', // '1.000000' COMMENT '数量', - 'color_interior_id' => '', // '颜色内饰ID(关联数据)', - 'color_interior_snapshot' => '', // '颜色内饰名称快照', - 'color_exterior_id' => '', // '颜色外饰ID(关联数据)', - 'color_exterior_snapshot' => '', // '颜色外饰名称快照', - 'remark' => '', // '备注', - 'unit_price' => '', // '0.000000' COMMENT '单价(含/不含税按业务口径约定)', - 'handling_fee' => '', // '0.000000' COMMENT '手续费(按单车)', - 'fob_transport_fee' => '', // '0.000000' COMMENT 'FOB运输费(按单车)', - 'port_misc_fee' => '', // '0.000000' COMMENT '港杂(按单车)', - 'retrofit_fee' => '', // '0.000000' COMMENT '改装费(按单车)', - 'total_price' => '', // '0.000000' COMMENT '总价(quantity*unit_price,写时落地)', - 'official_price' => '', // 官方指导价 - 'discount_price' => '', // 优惠价 - - - 'modify_list' => [ - // 'order_item_id' => '', // '所属明细ID', - 'option_id' => '', // '配置项ID(关联数据)', - 'option_name_snapshot' => '', // '配置项名称快照', - 'option_price' => '', // '配置项价格(可选,写时快照)', - ] - ]; - - - $account = [ - 'order_id' => '', // '所属备货单ID', - // 'seq_no' => '', // '1' COMMENT '账户序号(行号)', - 'remit_country_id' => '', // '汇款国ID(关联数据)', - 'remit_country_name_snapshot' => '', // '汇款国名称快照', - 'remit_date' => '', // '汇款日期(时间戳)', - 'currency_code' => '', // 'USD' COMMENT '币种代码(如USD/CNY/AED等)', - 'currency_name_snapshot' => '', // '币种名称快照(可选)', - 'account_id' => '', // '账户ID(关联数据)', - 'account_name_snapshot' => '', // '账户名称/开户名快照', - 'remitter_name' => '', // '汇款人', - 'amount' => '', // '0.00' COMMENT '金额', - ]; - } } \ No newline at end of file diff --git a/app/crm/service/StockOrdersService.php b/app/crm/service/StockOrdersService.php index 9a98e6f..492ffd3 100644 --- a/app/crm/service/StockOrdersService.php +++ b/app/crm/service/StockOrdersService.php @@ -50,6 +50,7 @@ class StockOrdersService extends \app\common\service\StockOrdersService $config['with'][] = 'accounts'; $config['with'][] = 'moneyValues'; $config['with'][] = 'salesperson'; + $config['with'][] = 'files'; break; case 'store': break; diff --git a/app/crm/service/StockOrdersService_bak.php b/app/crm/service/StockOrdersService_bak.php deleted file mode 100644 index 6e1f287..0000000 --- a/app/crm/service/StockOrdersService_bak.php +++ /dev/null @@ -1,444 +0,0 @@ -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_orders', '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; - } -} \ No newline at end of file diff --git a/app/crm/service/StockOrdersService_bak2.php b/app/crm/service/StockOrdersService_bak2.php deleted file mode 100644 index 1c4f7ea..0000000 --- a/app/crm/service/StockOrdersService_bak2.php +++ /dev/null @@ -1,762 +0,0 @@ -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': - case 'approval': - $config['where']['id'] = $p['id']; - break; - case 'detail': - 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 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') ?? ''; - $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - - // if ($data['is_final'] == 1) { - $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; - $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; - // } - 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.'】创建终版成功,但更新原单失败'); - } - } - // 启动审批 - if ($res->approval_status == 1) { - $this->startApproval($res); - } - return $res; - } - - /** - * 启动审批 - */ - public function startApproval($item) - { - // 启动审批 - $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->start('stock_orders', 'stock_orders', $item->id, [], $item->salesperson_id); - // 异步生成pdf文件 - \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]); - } - - /** - * 创建PDF文件 - */ - 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 - ); - - // 上传云端 - $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 pdfData($item) - { - $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']['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; - - // 处理金额 (每次循环重新初始化) - $mv = []; - foreach ($v->moneyValues as $money) { - $mv[$money->field] = [ - 'currency' => $money->currency, - 'amount' => $money->amount, - 'rate' => $money->exchange_rate, - 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol').number_format($money->amount, 2, '.', ',') - ]; - } - - // 处理改装 (每次循环重新初始化) - $mfy = ''; - foreach ($v->options as $my) { - $mfy .= $my->option_name_snapshot.' '; - } - - // 计算单项利润并累加到总利润 - $itemProfit = $this->calculateProfit($mv, $item); - $totalProfit += $itemProfit; - - // 处理结果集 - $vehListItem = [ - '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 - ]; - - $vehList[$v->unique_id] = $vehListItem + $mv; - } - - $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, '.', ','), - ]; - } - - $accList = []; - 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, - ]; - } - - - - $veh = [ - 'order_no' => $item->order_no, - 'salesperson_snapshot' => $item->salesperson_snapshot, - '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' => array_values($vehList), // 重新索引数组 - - 'contract_exchange_rate' => $item->contract_exchange_rate, - '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), - '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), - 'pick_up_date' => date('Y-m-d', $item->pick_up_date), - 'collect_all_date' => date('Y-m-d', $item->collect_all_date), - 'is_final' => $item->is_final, - - // 账户 - 'account_list' => $accList, - 'acc_index' => count($accList)+1, - 'currency_symbol' => $item->settlement_currency, - 'sign_imgs' => $this->queryAppro($item->id), - 'contract_url' => (!empty($item->contract)) ? (new \app\common\service\OssService)->generatePrivateUrl($item->contract) : '' - ]; - - return $veh; - } - - - public function queryAppro($bizId) - { - $instances = ApprovalInstances::where('biz_id', $bizId)->where('biz_type', 'stock_orders')->first(); - if (!$instances) { - return []; - } - - $records = ApprovalRecords::where('instance_id', $instances->id)->where('action', 'approve')->orderBy('step_index', 'asc')->pluck('approver_id')->toArray(); - if (count($records) == 0) { - return []; - } - - $signImgs = []; - foreach ($records as $k => $v) { - $signImg = User::where('id', $v)->value('sign_img'); - $signImgs[$k] = (!empty($signImg))?(new \app\common\service\OssService)->generatePrivateUrl($signImg):''; - } - - return $signImgs; - } - - /** - * 打印数据 - */ - public function servicePrint(Request $request) - { - $config = $this->buildQueryConfig($request, 'show'); - $item = $this->logicShow($config); - 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); - } - - /** - * 审批 - */ - public function serviceApproval(Request $request) - { - $config = $this->buildQueryConfig($request, 'approval'); - $this->logicUpdateBy($config, [ - 'approval_status' => 1 - ]); - $item = $this->logicShow($config); - $this->startApproval($item); - return $this->postProcess('Approval', $item); - } - - /** - * 最终审批 - */ - public function serviceUltimateApproval(Request $request) - { - $config = $this->buildQueryConfig($request, 'detail'); - $item = $this->logicShow($config); - foreach ($item->items as $k => $v) { - if ($v->vin === '') { - throw new BusinessException('存在未填写vin的车辆,无法完成提交审核'); - } - } - $this->logicUpdateBy($config, [ - 'approval_status' => 1 - ]); - $this->startApproval($item); - return $this->postProcess('UltimateApproval', $item); - } - - /** - * 创建 - * - * @param Request $request - * @param array $data - * @return mixed - */ - 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); - - // 处理车辆和账户信息 - $this->processOrderItems($created, $data); - - return $this->postProcess('Store', $created); - }); - } - - protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array - { - // 兼容传类名或实例 - $m = \is_string($model) ? new $model : $model; - // 1) 优先使用 fillable - $keys = $m->getFillable(); - // 2) 若没配置 fillable(常见:用 guarded),回退到完整表字段,避免误伤 - if (empty($keys)) { - $keys = $m->getConnection() - ->getSchemaBuilder() - ->getColumnListing($m->getTable()); - } - // 3) 允许额外白名单(如虚拟字段、JSON映射字段) - if ($extraWhitelist) { - $keys = array_merge($keys, $extraWhitelist); - } - return array_intersect_key($data, array_flip($keys)); - } - - /** - * 更新前处理 - * - * @param array $data - * @param Request $request - * @return array - */ - public function beforeServiceUpdate($data, Request $request) - { - $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['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - - $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; - $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; - return $data; - } - - /** - * 更新后处理 - * - * @param mixed $res - * @return mixed - */ - protected function afterServiceUpdate($res) - { - // 启动审批 - if ($res->approval_status == 1) { - $this->startApproval($res); - } - return $res; - } - - /** - * 更新 - * - * @param Request $request - * @param array $data - * @return mixed - */ - public function serviceUpdate(Request $request, array $data = []) - { - // 关联表较多,增加事务处理 - return Db::transaction(function () use ($request, $data) { - $data = $this->preProcess('Update', $data, $request); - $config = $this->buildQueryConfig($request, 'update'); - // 过滤掉非库字段 - $dbData = $this->onlyFillableData($config['model'], $data); - // 更新主表 - $updated = $this->logicUpdateBy($config, $dbData); - // 获取更新后的数据 - $order = $this->logicShow($config); - // 处理车辆和账户信息 - $this->processOrderItems($order, $data, true); - return $this->postProcess('Update', $order); - }); - } - - /** - * 处理订单项(车辆和账户) - * @param StockOrders $order 订单对象 - * @param array $data 数据 - * @param bool $isUpdate 是否为更新操作 - */ - private function processOrderItems($order, array $data, bool $isUpdate = false): void - { - // 如果是更新操作,先删除原有的关联数据 - if ($isUpdate) { - $this->clearExistingOrderItems($order->id); - } - - // 处理车辆项 - $this->processVehicleItems($order, $data['veh_list'] ?? []); - - // 处理账户项 - $this->processAccountItems($order, $data['account_list'] ?? []); - } - - /** - * (更新时)清除已存在的订单项 - * @param int $orderId 订单ID - */ - private function clearExistingOrderItems(int $orderId): void - { - // 删除车辆改装项 - StockOrderItemOptions::whereHas('item', function ($query) use ($orderId) { - $query->where('order_id', $orderId); - })->delete(); - - // 删除车辆项及其相关金额记录 - $orderItems = StockOrderItems::where('order_id', $orderId)->get(); - foreach ($orderItems as $item) { - // 删除车辆项的金额记录 - Db::table('veh_money_value') - ->where('object_scene', 'stock_order_items') - ->where('object_id', $item->id) - ->delete(); - } - - // 删除车辆项 - StockOrderItems::where('order_id', $orderId)->delete(); - - // 删除订单本身的金额记录 - Db::table('veh_money_value') - ->where('object_scene', 'stock_orders') - ->where('object_id', $orderId) - ->delete(); - - // 删除账户项 - StockOrderAccounts::where('order_id', $orderId)->delete(); - } - - /** - * 处理车辆项 - */ - private function processVehicleItems($order, array $vehList): void - { - $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); - - $item = StockOrderItems::create($veh); - - // 处理金额信息 - $this->processVehiclePrices($item, $veh); - - // 计算利润 - $profit = $this->calculateProfit($veh, $order); - $item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润'); - - // 累计到岸价 - $cifTotalAmount += $veh['total_price']['amount'] ?? 0; - $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', $order->settlement_currency, $cifTotalAmount, $order->contract_exchange_rate, '合计到岸价'); - // 利润 - $order->addMoney('profit_total', $order->settlement_currency, $profitTotalAmount, $order->contract_exchange_rate, '总利润'); - } - - /** - * 生成车辆唯一标识 - */ - private function generateVehicleUniqueId(array $veh): string - { - $uniqueIdStr = ""; - $uniqueIdStr .= $veh['sku_id'] ?? ''; - $uniqueIdStr .= $veh['model_snapshot'] ?? ''; - $uniqueIdStr .= $veh['color_interior_code'] ?? ''; - $uniqueIdStr .= $veh['color_exterior_code'] ?? ''; - $uniqueIdStr .= $veh['mileage'] ?? ''; - $uniqueIdStr .= json_encode($veh['modify_list'] ?? []); - - return md5($uniqueIdStr); - } - - /** - * 处理车辆价格信息 - */ - private function processVehiclePrices($item, array $veh): void - { - // 基础费用 - $priceFields = [ - 'unit_price' => '单价', - 'total_price' => '总价', - 'handling_fee' => '手续费', - 'fob_transport_fee' => 'FOB运输费', - 'port_misc_fee' => '港杂', - 'retrofit_fee' => '改装费', - 'ocean_freight' => '海运费' - ]; - - foreach ($priceFields as $field => $description) { - if (!empty($veh[$field]['amount'])) { - $item->addMoney( - $field, - $veh[$field]['currency'], - $veh[$field]['amount'], - $veh[$field]['rate'], - $description - ); - } - } - - // 根据里程处理新车或二手车价格 - if (!empty($veh['mileage']) && $veh['mileage'] > 0) { - // 二手车 - if (!empty($veh['listing_price']['amount'])) { - $item->addMoney( - 'listing_price', - $veh['listing_price']['currency'], - $veh['listing_price']['amount'], - $veh['listing_price']['rate'], - '二手挂牌价' - ); - } - - if (!empty($veh['reduction_price']['amount'])) { - $item->addMoney( - 'reduction_price', - $veh['reduction_price']['currency'], - $veh['reduction_price']['amount'], - $veh['reduction_price']['rate'], - '二手减价' - ); - } - } else { - // 新车 - if (!empty($veh['official_price']['amount'])) { - $item->addMoney( - 'official_price', - $veh['official_price']['currency'], - $veh['official_price']['amount'], - $veh['official_price']['rate'], - '官方指导价' - ); - } - - if (!empty($veh['discount_price']['amount'])) { - $item->addMoney( - 'discount_price', - $veh['discount_price']['currency'], - $veh['discount_price']['amount'], - $veh['discount_price']['rate'], - '优惠价' - ); - } - } - } - - /** - * 计算利润 - */ - private function calculateProfit(array $veh, $order): float - { - $unitPrice = (float)($veh['unit_price']['amount'] ?? 0); - - if (!empty($veh['mileage']) && $veh['mileage'] > 0) { - // 二手车 - $ttPrice = ($veh['listing_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1); - $ddPrice = $veh['reduction_price']['amount'] ?? 0; - } else { - // 新车 - $ttPrice = ($veh['official_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1); - $ddPrice = $veh['discount_price']['amount'] ?? 0; - } - - $handlingFee = (float)($veh['handling_fee']['amount'] ?? 0); - $fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0); - $portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0); - $retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0); - $oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0); - - return $unitPrice - $ttPrice - $ddPrice - $handlingFee - $fobTransportFee - $portMiscFee - $retrofitFee - $oceanFreight; - } - - /** - * 处理改装项 - */ - private function processModificationItems(int $orderItemId, array $modifyList): void - { - if (empty($modifyList)) { - return; - } - - foreach ($modifyList as $modify) { - $modify['order_item_id'] = $orderItemId; - StockOrderItemOptions::create($modify); - } - } - - /** - * 处理账户项 - */ - private function processAccountItems($order, array $accountList): void - { - if (empty($accountList)) { - return; - } - - foreach ($accountList as $account) { - $account['order_id'] = $order->id; - if (!empty($account['remit_date'])) { - $account['remit_date'] = strtotime($account['remit_date']); - } - StockOrderAccounts::create($account); - } - } -} \ No newline at end of file From 74868034680dbb04a919715c5ba8e06b2a0bc902 Mon Sep 17 00:00:00 2001 From: mzl Date: Wed, 22 Oct 2025 16:15:08 +0800 Subject: [PATCH 21/74] =?UTF-8?q?=E8=B0=83=E6=95=B4pdf=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/pdf/template/stockOrder copy 2.stub | 336 ++++++++++++++++++ app/common/utils/pdf/template/stockOrder.stub | 165 +++++---- 2 files changed, 436 insertions(+), 65 deletions(-) create mode 100644 app/common/utils/pdf/template/stockOrder copy 2.stub diff --git a/app/common/utils/pdf/template/stockOrder copy 2.stub b/app/common/utils/pdf/template/stockOrder copy 2.stub new file mode 100644 index 0000000..20b10b3 --- /dev/null +++ b/app/common/utils/pdf/template/stockOrder copy 2.stub @@ -0,0 +1,336 @@ + + + + + 合塑实业-汽车事业部-备货单(客户下定) + + + +
+ +
+

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

+
+ 备货单号: + 业务员: +
+
+ + + + + + + + + + + + + + + + + + + + + +
阿里订单号/PI号: 日期: 清关目的国: 客户来源: 客户名称: 客户所在国:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0): ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
编号车型数量/台颜色/外颜色/内收款价总价官方指导价/二手挂牌价优惠利润
+ + + + 0): ?> + () + + + +
改装费FOB运费车价海运费佣金挂账港杂
+ 备注: + + +
+ 合同汇率: + + 合计到岸价: +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
清关人: 全款收齐日: 预计发运日期: 出运方式: 国内收货港: 贸易条款/清关目的港: /提车日期: 最迟到港时间:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
计划收款信息序号汇款国日期币种账户汇款人金额
+ + +
+ +
+ +
+ 业务员签字: + + + + + +
+ +
+ 备发货负责人签字: + + + + + +
+
+ + +
+
+ 组长签字: + + + + + +
+ +
+ 日期: + +
+
+ +
+
+ + +
+ + \ 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 20b10b3..697b8eb 100644 --- a/app/common/utils/pdf/template/stockOrder.stub +++ b/app/common/utils/pdf/template/stockOrder.stub @@ -124,81 +124,116 @@ 编号 车型 - 数量/台 - 颜色/外 - 颜色/内 - 收款价 - 总价 - 官方指导价/二手挂牌价 - 优惠 - 利润 + 数量 + 颜色 + 费用明细 + - - - - - - - 0): ?> - () + + + + + + + + + + + + 0): ?> + (km) + + + + + + + + + + + 外饰:

+ 内饰: + + + + 改装费 + 配件费 + 收款价 + 总价 + 官方指导价/二手挂牌价 + 优惠 + 利润 + + + + + + + + + + 0): ?> + + + + + + + - - - - - - - - - - 0): ?> - - - - - - - - - - - 改装费 - FOB运费 - 车价 - 海运费 - 佣金 - 挂账 - 港杂 - - - - - - - - - - - - - 备注: - - - - - + + + + + + + 报关价 + FOB运费 + 车价 + 海运费 + 佣金 + 挂账 + 港杂 + + + + + + + + + + + + + + + + 备注 + + + + + + + + - - 合同汇率: + + + 合同汇率: + - - 合计到岸价: + + 合计到岸价: + From 6644cc1c58e01c3f8fb60cd4fe5eeb8832b7c4a6 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 23 Oct 2025 11:27:24 +0800 Subject: [PATCH 22/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 2 +- app/common/controller/FinReceiptController.php | 10 ++++++++++ app/common/service/FinReceiptService.php | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index e916df4..57c4b75 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -75,7 +75,7 @@ class FinPaymentApplyController extends BaseController * @param array $data * @return array */ - protected function showFormat($data) + public function showFormat($data) { if (isset($data['doc_user_id'])) //内勤 $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index ddddfac..c558d44 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -3,8 +3,12 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\model\Country; +use app\common\model\FinPaymentApply; +use app\common\model\FinPaymentStock; use app\common\model\SysAccount; use app\common\model\SysCurrency; +use app\common\model\SysDictItem; +use app\common\model\User; use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptService; @@ -81,6 +85,12 @@ class FinReceiptController extends BaseController } elseif (isset($data['fx_receipt_file'])) { $data['fx_receipt_file_full'] = ''; } + + if (!empty($data['payment_apply_id'])) { + $paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first()->toArray(); + $paymentApply = (new FinPaymentApplyController())->showFormat($paymentApply); + $data['payment_apply'] = $paymentApply; + } return $data; } } \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 2f77af5..155aecd 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -70,7 +70,7 @@ class FinReceiptService } // 关键字 - if (isset($p['$query']) && $p['keyword']) { + if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; $config['orWhere'][] = ['remitter', 'like', $k]; } From 0f505d5c567d1a70ec0a73126be73044e3921b3d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 23 Oct 2025 16:25:02 +0800 Subject: [PATCH 23/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E8=81=94=E6=9F=A5=E4=BB=98=E6=AC=BE=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index c558d44..ebfd956 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -87,7 +87,10 @@ class FinReceiptController extends BaseController } if (!empty($data['payment_apply_id'])) { - $paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first()->toArray(); + $paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first(); + if(!$paymentApply) + return $data; + $paymentApply = $paymentApply->toArray(); $paymentApply = (new FinPaymentApplyController())->showFormat($paymentApply); $data['payment_apply'] = $paymentApply; } From 7036e3b849803d8d2100836a77b5f3f6f55bfa9c Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 23 Oct 2025 17:09:40 +0800 Subject: [PATCH 24/74] =?UTF-8?q?=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= =?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/controller/FinReceiptController.php | 16 +++++++++++++++- app/common/service/FinPaymentApplyService.php | 6 ++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index ebfd956..56d7bfb 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -12,6 +12,7 @@ use app\common\model\User; use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptService; +use support\Request; class FinReceiptController extends BaseController { @@ -23,7 +24,18 @@ class FinReceiptController extends BaseController { $this->service = new FinReceiptService(); } - + public function show(Request $request) + { + try { + $raw = $this->service->serviceShow($request); + $data = $this->transformData($raw, method_exists($this, 'showFormat') + ? [$this, 'showFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } /** * 列表页数据格式化 * @@ -91,6 +103,8 @@ class FinReceiptController extends BaseController if(!$paymentApply) return $data; $paymentApply = $paymentApply->toArray(); + $paymentApply['created_at'] = strtotime($paymentApply['created_at']); + $paymentApply['updated_at'] = strtotime($paymentApply['updated_at']); $paymentApply = (new FinPaymentApplyController())->showFormat($paymentApply); $data['payment_apply'] = $paymentApply; } diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 294bc01..f451ce4 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -217,14 +217,16 @@ class FinPaymentApplyService $orderByClause = "CASE WHEN created_at >= {$sevenDaysAgo} THEN (" . implode(' + ', $similarityOrder) . ") - ELSE 999999 + ELSE 0 END ASC, "; } $orderByClause .= "CASE WHEN created_at < {$sevenDaysAgo} THEN id - ELSE 0 + ELSE 999999 END DESC"; + + $orderByClause .= ", id DESC"; $query->orderByRaw($orderByClause); From 4326bcd68b7798e59e180338d5644ffe69f2abff Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 24 Oct 2025 10:43:36 +0800 Subject: [PATCH 25/74] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=87=E8=B4=A7?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/StockOrdersService.php | 57 ++++------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php index f243654..76d2ab5 100644 --- a/app/common/service/StockOrdersService.php +++ b/app/common/service/StockOrdersService.php @@ -330,33 +330,25 @@ class StockOrdersService $data = $this->preProcess('Store', $data, $request); $dl = $this->getDataLimitFromRequest($request); $created = $this->logicCreate($data, $dl); - // 添加金额 $created->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价'); - // 处理车辆和账户信息 $this->processOrderItems($created, $data); - // 处理文件附件 $this->processOrderFiles($created, $data); - return $this->postProcess('Store', $created); }); } protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array { - // 兼容传类名或实例 $m = \is_string($model) ? new $model : $model; - // 1) 优先使用 fillable $keys = $m->getFillable(); - // 2) 若没配置 fillable(常见:用 guarded),回退到完整表字段,避免误伤 if (empty($keys)) { $keys = $m->getConnection() ->getSchemaBuilder() ->getColumnListing($m->getTable()); } - // 3) 允许额外白名单(如虚拟字段、JSON映射字段) if ($extraWhitelist) { $keys = array_merge($keys, $extraWhitelist); } @@ -413,11 +405,13 @@ class StockOrdersService // 过滤掉非库字段 $dbData = $this->onlyFillableData($config['model'], $data); // 更新主表 - $updated = $this->logicUpdateBy($config, $dbData); + $this->logicUpdateBy($config, $dbData); // 获取更新后的数据 $order = $this->logicShow($config); // 处理车辆和账户信息 $this->processOrderItems($order, $data, true); + // 添加金额 + $order->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价'); // 处理文件附件 $this->processOrderFiles($order, $data, true); return $this->postProcess('Update', $order); @@ -436,10 +430,8 @@ class StockOrdersService if ($isUpdate) { $this->clearExistingOrderItems($order->id); } - // 处理车辆项 $this->processVehicleItems($order, $data['veh_list'] ?? []); - // 处理账户项 $this->processAccountItems($order, $data['account_list'] ?? []); } @@ -552,7 +544,6 @@ class StockOrdersService $this->processVehiclePrices($item, $veh); // 累计到岸价 - // $cifTotalAmount += $veh['total_price']['amount'] ?? 0; $profitCurrency === '' ? $profitCurrency = $veh['profit']['currency'] ?? '' : ''; $profitRate === 0 ? $profitRate = $veh['profit']['rate'] ?? 0 : ''; $profitTotalAmount += $veh['profit']['amount'] ?? 0; @@ -572,7 +563,6 @@ class StockOrdersService $keysToRemove = ['vin', 'remark', 'modify_list', 'order_id']; $array = array_diff_key($veh, array_flip($keysToRemove)); $uniqueIdStr = json_encode($array); - return md5($uniqueIdStr); } @@ -600,6 +590,7 @@ class StockOrdersService // retention_price 留款/挂账 // car_price 车价 // accessory_price 配件费 + // increase_price 加价 // 基础费用 $priceFields = [ @@ -617,7 +608,8 @@ class StockOrdersService 'profit' => '利润', 'retention_price' => '挂账', 'car_price' => '车价', - 'accessory_price' => '配件费' + 'accessory_price' => '配件费', + 'increase_price' => '加价' ]; foreach ($priceFields as $field => $description) { @@ -771,12 +763,10 @@ class StockOrdersService { $vehList = []; $index = 0; - $currencyInfo = $this->getCurrencyInfo($item->settlement_currency); - foreach ($item->items as $v) { // 如果已存在相同车辆,增加数量 if (isset($vehList[$v->unique_id])) { - $this->incrementVehicleCount($vehList[$v->unique_id], $currencyInfo); + $this->incrementVehicleCount($vehList[$v->unique_id]); // 拼接 remark 值 if (!empty($v->remark)) { if (!empty($vehList[$v->unique_id]['remark'])) { @@ -787,17 +777,9 @@ class StockOrdersService } continue; } - $index++; // 处理金额信息 $moneyValues = $this->processItemMoneyValues($v); - - // 处理改装信息 - // $modificationText = $this->getModificationText($v->options); - - // 利润 - // $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount']; - // 构建车辆信息 $vehList[$v->unique_id] = [ 'index' => $index, @@ -805,19 +787,10 @@ class StockOrdersService 'color_interior_snapshot' => $v->color_interior_snapshot, 'color_exterior_snapshot' => $v->color_exterior_snapshot, 'num' => 1, - // 'modify' => $modificationText, 'mileage' => $v->mileage, 'remark' => $v->remark, ] + $moneyValues; - // var_dump($vehList[$v->unique_id]); - // 添加利润信息 - // $vehList[$v->unique_id]['profit'] = [ - // 'currency' => $item->settlement_currency, - // 'amount' => $itemProfit, - // 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',') - // ]; } - return ['list' => $vehList]; } @@ -853,23 +826,9 @@ class StockOrdersService /** * 增加车辆数量并更新相关金额显示 */ - private function incrementVehicleCount(array &$vehicleData, array $currencyInfo): void + private function incrementVehicleCount(array &$vehicleData): void { $vehicleData['num'] += 1; - - // // 更新总价显示 - // if (isset($vehicleData['total_price']['amount'])) { - // $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num']; - // $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ','); - // } - - // // 更新利润显示 - // if (isset($vehicleData['profit']['amount'])) { - // $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num']; - // $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ','); - // } - - // var_dump($vehicleData); $fieldList = [ 'fob_transport_fee', From c1ab40031dc49ab2eb965356188edc73184586df Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 24 Oct 2025 11:02:54 +0800 Subject: [PATCH 26/74] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PurchaseOrdersLogic.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/logic/PurchaseOrdersLogic.php b/app/common/logic/PurchaseOrdersLogic.php index 500379d..0914f43 100644 --- a/app/common/logic/PurchaseOrdersLogic.php +++ b/app/common/logic/PurchaseOrdersLogic.php @@ -24,7 +24,7 @@ class PurchaseOrdersLogic public function getPiList() { return (new StockOrders())->where('pi_no', '!=', '') - ->select('pi_no') + ->select('pi_no', 'salesperson_snapshot') ->distinct() ->get(); } @@ -35,6 +35,7 @@ class PurchaseOrdersLogic public function getOrderNoListByPiNo($piNo) { return (new StockOrders())->where('pi_no', $piNo) + ->where('approval_status', 2) ->select('order_no', 'biz_date', 'salesperson_snapshot', 'id as stock_orders_id', 'salesperson_id') ->get(); } From 6bd4ed9ec32c826cb57a60187e0c4e10b932c6ab Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 24 Oct 2025 15:46:20 +0800 Subject: [PATCH 27/74] =?UTF-8?q?ts=E5=A4=87=E8=B4=A7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/ApprovalRecordsService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/service/ApprovalRecordsService.php b/app/common/service/ApprovalRecordsService.php index 3b37365..61c026e 100644 --- a/app/common/service/ApprovalRecordsService.php +++ b/app/common/service/ApprovalRecordsService.php @@ -56,9 +56,9 @@ class ApprovalRecordsService case 'todo': if ($p['scene'] === 'todo') { - // if (!in_array(1, $request->user->role_ids)) { - // $config['where']['approver_id'] = $request->user->uid; - // } + if (!in_array(1, $request->user->role_ids)) { + $config['where']['approver_id'] = $request->user->uid; + } $config['where']['status'] = 'pending'; $config['where']['instance.status'] = 'processing'; } From 83d76b16b4a154ae11ca388e904ea1c548ca6ede Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 27 Oct 2025 10:57:47 +0800 Subject: [PATCH 28/74] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=85=A5=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinReceiptController.php | 17 +++++++++++++++++ app/common/logic/FinReceiptLogic.php | 4 ++++ app/common/service/FinReceiptService.php | 19 +++++++++++++++++++ config/route.php | 1 + 4 files changed, 41 insertions(+) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 56d7bfb..486bfde 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -24,6 +24,23 @@ class FinReceiptController extends BaseController { $this->service = new FinReceiptService(); } + + /** + * 确认入账 + * @param Request $request + * @return \support\Response + */ + public function credit(Request $request) + { + try { + $id = $request->input('id'); + $raw = $this->service->credit($id); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + public function show(Request $request) { try { diff --git a/app/common/logic/FinReceiptLogic.php b/app/common/logic/FinReceiptLogic.php index 5d8f5f3..62db50f 100644 --- a/app/common/logic/FinReceiptLogic.php +++ b/app/common/logic/FinReceiptLogic.php @@ -14,4 +14,8 @@ class FinReceiptLogic */ protected string $modelClass = FinReceipt::class; + public function credit($id) + { + return FinReceipt::where('id', $id)->update(['received_at' => time()]); + } } \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 155aecd..e2611d7 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -2,10 +2,12 @@ namespace app\common\service; +use app\common\logic\FinReceiptLogic; use app\common\model\FinReceiptHis; use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\FinReceipt; +use support\exception\BusinessException; use support\Request; class FinReceiptService @@ -23,6 +25,14 @@ class FinReceiptService */ protected $validator = FinReceiptValidate::class; + + protected $logic; + + public function __construct() + { + $this->logic = (new FinReceiptLogic()); + } + /** * 获取验证器 */ @@ -251,4 +261,13 @@ class FinReceiptService return $query->paginate($limit, ['*'], 'page', $page); } + + public function credit($id) + { + $finReceipt = FinReceipt::find($id); + if(!empty($finReceipt->received_at)){ + throw new BusinessException('该记录已将确认入账'); + } + return $this->logic->credit($id); + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 3f7477f..ba10155 100644 --- a/config/route.php +++ b/config/route.php @@ -360,6 +360,7 @@ Route::group('/admin', function () { Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); + Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); }); // 收款记录历史 Route::group('/receipt/his', function () { From 19cb169abdbd6365ae93382f19f5e600123df312 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 27 Oct 2025 11:57:00 +0800 Subject: [PATCH 29/74] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index e2611d7..7154bfa 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -268,6 +268,7 @@ class FinReceiptService if(!empty($finReceipt->received_at)){ throw new BusinessException('该记录已将确认入账'); } + $this->afterServiceUpdate(['id'=>$id]); return $this->logic->credit($id); } } \ No newline at end of file From 1bd2eee8db7922ef3a8e40437a9e55a63043ff2c Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 27 Oct 2025 14:52:04 +0800 Subject: [PATCH 30/74] =?UTF-8?q?=E5=85=A5=E8=B4=A6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 7154bfa..bc9ff6a 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -268,7 +268,8 @@ class FinReceiptService if(!empty($finReceipt->received_at)){ throw new BusinessException('该记录已将确认入账'); } + $res = $this->logic->credit($id); $this->afterServiceUpdate(['id'=>$id]); - return $this->logic->credit($id); + return $res; } } \ No newline at end of file From 21274732909ba0b3f7a5981309db574d9d9eb3b3 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 28 Oct 2025 16:59:51 +0800 Subject: [PATCH 31/74] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/SysConfigController.php | 48 +++++++++++++ app/admin/logic/SysConfigLogic.php | 17 +++++ app/admin/service/SysConfigService.php | 76 ++++++++++++++++++++ app/admin/validate/SysConfigValidate.php | 29 ++++++++ app/common/logic/SysConfigLogic.php | 22 ++++++ app/common/model/SysConfig.php | 49 +++++++++++++ app/common/service/SysConfigService.php | 37 ++++++++++ 7 files changed, 278 insertions(+) create mode 100644 app/admin/controller/SysConfigController.php create mode 100644 app/admin/logic/SysConfigLogic.php create mode 100644 app/admin/service/SysConfigService.php create mode 100644 app/admin/validate/SysConfigValidate.php create mode 100644 app/common/logic/SysConfigLogic.php create mode 100644 app/common/model/SysConfig.php create mode 100644 app/common/service/SysConfigService.php diff --git a/app/admin/controller/SysConfigController.php b/app/admin/controller/SysConfigController.php new file mode 100644 index 0000000..3534079 --- /dev/null +++ b/app/admin/controller/SysConfigController.php @@ -0,0 +1,48 @@ +service = new SysConfigService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/admin/logic/SysConfigLogic.php b/app/admin/logic/SysConfigLogic.php new file mode 100644 index 0000000..60be4a8 --- /dev/null +++ b/app/admin/logic/SysConfigLogic.php @@ -0,0 +1,17 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 状态 + if (isset($p['status']) && in_array($p['status'], [0,1])) { + $config['where']['status'] = $p['status']; + } + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + foreach (['config_key','config_value','description'] as $col) { + $config['orWhere'][] = [$col, 'like', $k]; + } + } + break; + case 'show': + $config['where']['id'] = $p['id']; + //$config['where']['status'] = 1; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } +} \ No newline at end of file diff --git a/app/admin/validate/SysConfigValidate.php b/app/admin/validate/SysConfigValidate.php new file mode 100644 index 0000000..2bb978a --- /dev/null +++ b/app/admin/validate/SysConfigValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/logic/SysConfigLogic.php b/app/common/logic/SysConfigLogic.php new file mode 100644 index 0000000..633d177 --- /dev/null +++ b/app/common/logic/SysConfigLogic.php @@ -0,0 +1,22 @@ +where('config_key', $key)->get(['id', 'config_key', 'config_value']); + } +} \ No newline at end of file diff --git a/app/common/model/SysConfig.php b/app/common/model/SysConfig.php new file mode 100644 index 0000000..29b4577 --- /dev/null +++ b/app/common/model/SysConfig.php @@ -0,0 +1,49 @@ +logic = (new SysConfigLogic()); + } + + /** + * 获取系统list + */ + public static function getConfig(string $config_key) + { + $value = Redis::get($config_key); + if (empty($value)) { + $config = (new SysConfigLogic())->findByKey($config_key); + if (empty($config)) { + return null; + } + $value = $config->config_value; + Redis::set($config->config_key, $value, 'EX', 7200); + } + + return $value; + } +} \ No newline at end of file From 8a1b2f236936b8e943798db3b0742c7ad2648527 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 28 Oct 2025 17:05:23 +0800 Subject: [PATCH 32/74] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/SysConfigService.php | 7 +++++++ config/route.php | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/app/admin/service/SysConfigService.php b/app/admin/service/SysConfigService.php index cedca5b..62e4812 100644 --- a/app/admin/service/SysConfigService.php +++ b/app/admin/service/SysConfigService.php @@ -5,6 +5,7 @@ namespace app\admin\service; use app\admin\validate\SysConfigValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\SysConfig; +use support\Redis; use support\Request; class SysConfigService @@ -73,4 +74,10 @@ class SysConfigService return $config; } + + + public function beforeServiceUpdate($data, Request $request) + { + Redis::del($data['config_key']); + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index ba10155..29c4e6e 100644 --- a/config/route.php +++ b/config/route.php @@ -376,6 +376,15 @@ Route::group('/admin', function () { Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']); Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']); }); + + // 系统配置 + Route::group('/config', function () { + Route::any('/list', [app\admin\controller\SysConfigController::class, 'index']); + Route::any('/show', [app\admin\controller\SysConfigController::class, 'show']); + Route::any('/store', [app\admin\controller\SysConfigController::class, 'store']); + Route::any('/update', [app\admin\controller\SysConfigController::class, 'update']); + Route::any('/destroy', [app\admin\controller\SysConfigController::class, 'destroy']); + }); }); From e62becd30b6d394e9c991c03f03819086161ad15 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 11:46:08 +0800 Subject: [PATCH 33/74] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/UploadController.php | 7 +++-- app/common/service/OssService.php | 34 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/common/controller/UploadController.php b/app/common/controller/UploadController.php index d90c84a..a025666 100644 --- a/app/common/controller/UploadController.php +++ b/app/common/controller/UploadController.php @@ -87,12 +87,15 @@ class UploadController } $originalName = $file->getUploadName(); + $ossservice = new OssService(); + $mimes = $ossservice->getMimeTypes(['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'zip', 'rar']); + $result = Storage::adapter('oss') ->path('x_server/' . $sceneUrl . date('Ymd')) ->size(1024*1024*5) + ->extYes($mimes) ->upload($file); - - $ossservice = new OssService(); + $data = [ 'original_name' => $originalName, diff --git a/app/common/service/OssService.php b/app/common/service/OssService.php index 72a956e..1aacc1c 100644 --- a/app/common/service/OssService.php +++ b/app/common/service/OssService.php @@ -76,4 +76,38 @@ class OssService throw new BusinessException('Delete Error: ' . $th->getMessage()); } } + + /** + * 获取对应的 MIME 类型 + */ + public function getMimeTypes($extensions) + { + $mimeMap = [ + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'png' => 'image/png', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + 'webp' => 'image/webp', + 'pdf' => 'application/pdf', + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xls' => 'application/vnd.ms-excel', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'ppt' => 'application/vnd.ms-powerpoint', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'txt' => 'text/plain', + 'zip' => 'application/zip', + 'rar' => 'application/x-rar-compressed' + ]; + + $mimes = []; + foreach ($extensions as $ext) { + if (isset($mimeMap[$ext])) { + $mimes[] = $mimeMap[$ext]; + } + } + + return array_unique($mimes); + } } \ No newline at end of file From 07c0b2a2f3ab249a6e48451b57e4cacd21ceed0a Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 14:14:40 +0800 Subject: [PATCH 34/74] =?UTF-8?q?=E6=94=B6=E4=BB=98=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 2 ++ .../controller/FinReceiptController.php | 22 +++++++++++++++- app/common/model/FinPaymentApply.php | 2 +- app/common/service/FinReceiptService.php | 26 +++++++++++++++++++ config/route.php | 2 +- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 57c4b75..37fc4d7 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -66,6 +66,8 @@ class FinPaymentApplyController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['claimed_at'])) + $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); return $data; } diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 486bfde..d8ef9c2 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -53,6 +53,24 @@ class FinReceiptController extends BaseController return $this->error($e->getMessage()); } } + + /** + * 更新 + * + * @param Request $request 请求对象 + * @return mixed 返回更新成功的数据或信息 + */ + public function payment(Request $request) + { + try { + $data = $this->validate($this->service->getValidator(), $request->post(), 'update'); + $res = $this->service->serviceUpdatePayment($request, $data); + return $this->success([], '更新成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * @@ -61,8 +79,10 @@ class FinReceiptController extends BaseController */ protected function indexFormat($data) { - if (isset($data['created_at'])) + if (isset($data['created_at'])){ + $data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0; $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + } if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['arrived_at'])) diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index f02f137..82f81cb 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -40,7 +40,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files', 'created_at', 'updated_at']; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index bc9ff6a..6e7b7e3 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -3,6 +3,7 @@ namespace app\common\service; use app\common\logic\FinReceiptLogic; +use app\common\model\FinPaymentApply; use app\common\model\FinReceiptHis; use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; @@ -89,6 +90,7 @@ class FinReceiptService $config['where']['id'] = $p['id']; break; case 'update': + case 'payment': case 'destroy': $config['where']['id'] = $p['id']; break; @@ -272,4 +274,28 @@ class FinReceiptService $this->afterServiceUpdate(['id'=>$id]); return $res; } + + /** + * 更新计算折让金额 + * @param Request $request + * @param array $data + * @param string $scene + * @return mixed + */ + public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') + { + $payment_apply_id = $request->input('payment_apply_id'); + $id = $request->input('id'); + $data = $this->preProcess(ucfirst($scene), $data, $request); + $config = $this->buildQueryConfig($request, $scene); + FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time()]); + + //折让金额 + $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); + $receipt = FinReceipt::find($id); + $data['discount_amount'] = $payment->amount - $payment->amount ?? 0; + + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess(ucfirst($scene), $data); + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 29c4e6e..b962ee9 100644 --- a/config/route.php +++ b/config/route.php @@ -358,7 +358,7 @@ Route::group('/admin', function () { Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']); Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); - Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']); + Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']); Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); }); From b440c032410ad41e76b05dfd2a139be8c954fbc3 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 15:47:51 +0800 Subject: [PATCH 35/74] =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=9C=AA=E8=AE=A4?= =?UTF-8?q?=E9=A2=86=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 6e7b7e3..48f9832 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -64,10 +64,13 @@ class FinReceiptService } // 没有付款记录的收款记录 - if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { + if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { //未认领 $config['where']['payment_apply_id'] = ['null']; - } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { + } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { //已认领 $config['where']['payment_apply_id'] = ['not null']; + } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'timeout') { //超时未认领 + $config['where']['payment_apply_id'] = ['not null']; + $config['where']['created_at'] = ['<' ,time() - 24*60*60]; } // 收款申请筛选 From cf45acbf0f7ae47a3bfa124dbb323dc4401eb024 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 15:58:23 +0800 Subject: [PATCH 36/74] =?UTF-8?q?=E5=85=A5=E8=B4=A6=E8=B5=84=E6=96=99?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 37fc4d7..3bf4b15 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -66,8 +66,10 @@ class FinPaymentApplyController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - if (isset($data['claimed_at'])) - $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); + if (isset($data['claimed_at'])){ + $data['enter_file_last'] = date('Y-m-d H:i:s', ($data['claimed_at']+86400)); //入账资料最后提交时间 + $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); //认领时间 + } return $data; } From 346d67c084c1dc6063d7680869c2f78b291213d4 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 18:05:23 +0800 Subject: [PATCH 37/74] =?UTF-8?q?=E8=B6=85=E8=BF=8724=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5=E6=8F=90=E4=BA=A4=E5=85=A5?= =?UTF-8?q?=E8=B4=A6=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/FinPaymentApply.php | 2 +- app/common/service/FinReceiptService.php | 2 +- .../scaffold/templates/paymentFiles.stub | 103 ++++++++++++++++++ app/functions.php | 3 +- app/process/Task.php | 44 +++++++- 5 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 app/common/utils/scaffold/templates/paymentFiles.stub diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index 82f81cb..0f4d157 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -40,7 +40,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at', 'created_at', 'updated_at']; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'created_at', 'updated_at', 'claimed_by',]; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 48f9832..91db094 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -291,7 +291,7 @@ class FinReceiptService $id = $request->input('id'); $data = $this->preProcess(ucfirst($scene), $data, $request); $config = $this->buildQueryConfig($request, $scene); - FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time()]); + FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time(), 'claimed_by' => $request->user->uid]); //折让金额 $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); diff --git a/app/common/utils/scaffold/templates/paymentFiles.stub b/app/common/utils/scaffold/templates/paymentFiles.stub new file mode 100644 index 0000000..6c9cded --- /dev/null +++ b/app/common/utils/scaffold/templates/paymentFiles.stub @@ -0,0 +1,103 @@ + + + + + + 邮箱提醒 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/functions.php b/app/functions.php index 7ae0d0a..075dfbf 100644 --- a/app/functions.php +++ b/app/functions.php @@ -179,7 +179,8 @@ if (!function_exists('tplUrl')) { { $urlArray = [ 'email' => 'common/utils/scaffold/templates/Email.stub', - 'work_order' => 'common/utils/scaffold/templates/workOrder.stub' + 'work_order' => 'common/utils/scaffold/templates/workOrder.stub', + 'payment_files' => 'common/utils/scaffold/templates/paymentFiles.stub', ]; return $urlArray[$tplKey]; } diff --git a/app/process/Task.php b/app/process/Task.php index 910b5ad..47dbb93 100644 --- a/app/process/Task.php +++ b/app/process/Task.php @@ -2,6 +2,8 @@ namespace app\process; +use app\common\model\FinPaymentApply; +use app\common\model\User; use app\crm\model\Customer; use support\Log; use Workerman\Crontab\Crontab; @@ -11,7 +13,7 @@ class Task public function onWorkerStart() { - // 每半小时执行一次 + // 每半小时执行一次,通知待跟进客户 new Crontab('0 */30 * * * *', function(){ echo date('Y-m-d H:i:s') . "\n"; Log::info('send follow start',[time()]); @@ -34,7 +36,45 @@ class Task $item->save(); } - Log::info('send follow start',[time()]); + Log::info('send follow end',[time()]); + }); + + // 检查入账资料是否提交 + new Crontab('* */70 * * * *', function () { + $G = date('G'); + if ($G > 22 || $G < 8) { + return; + } + Log::info('fin_payment_apply submit_files start', [time()]); + $orWhere = [ + ['submit_files', '=', '[]'], + ['submit_files', '=', ''], + ]; + $where = [ + ['warn', '<', 2], + ['created_at', '>', time() - 60 * 60 * 48], + ['created_at', '<', time() - 60 * 60 * 24], + ]; + $payment = FinPaymentApply::where($where)->orWhere($orWhere)->orderBy('id', 'desc')->get(); + foreach ($payment as $item) { + Log::info('fin_payment_apply submit_files ', [$item->toArray()]); + $notice = [ + 'code' => $item->apply_no, + 'payment_entity' => $item->payment_entity ?? $item->remitter, + 'content' => '认领收款单后请在24小时内提交入账资料', + 'reply' => '', + ]; + $email = []; + $email[] = User::where('id', $item->claimed_by)->value('email'); + $email[] = User::where('id', $item->doc_user_id)->value('email'); + $email = array_unique($email); + \app\common\utils\email\MailSend::send($email, '【XYH】付款记录', replaceTpl($notice, 'payment_files')); + + $item->warn = ++$item->warn; + $item->save(); + } + + Log::info('fin_payment_apply submit_files end', [time()]); }); } From f3b1c9bae43074430c2a97972261f63ace668280 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 29 Oct 2025 18:38:37 +0800 Subject: [PATCH 38/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index f451ce4..19a2f3f 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -174,11 +174,11 @@ class FinPaymentApplyService // 构建查询 $query = $this->modelClass::where($where); - // 应用是否有关联收款记录的筛选 + // 是否已关联收款记录的筛选 $correlation = $param['correlation']??''; - if ($correlation === 'receipt') { + if ($correlation === 'receipt') { //已关联 $query->whereHas('receipt'); - } elseif ($correlation === 'unbind') { + } elseif ($correlation === 'unbind') { //未关联 $query->whereDoesntHave('receipt'); } @@ -186,7 +186,7 @@ class FinPaymentApplyService return $query->paginate($limit, ['*'], 'page', $page); } - // 计算七天前的时间戳 + // 计算十天前的时间戳 $sevenDaysAgo = time() - (10 * 24 * 60 * 60); // 构建相似度排序逻辑 @@ -197,8 +197,18 @@ class FinPaymentApplyService $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; } - if (isset($param['country_id']) && !empty($param['country_id'])) { - $similarityOrder[] = "CASE WHEN country_id = {$param['country_id']} THEN 0 ELSE 1 END"; + if (isset($param['currency_id']) && !empty($param['currency_id'])) { + $similarityOrder[] = "CASE WHEN currency_id = {$param['currency_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['remitter']) && !empty($param['remitter'])) { + $similarityOrder[] = "CASE WHEN remitter = {$param['remitter']} THEN 0 ELSE 1 END"; + } + + if (isset($param['amount']) && !empty($param['amount'])) { + $amount = (float)$param['amount']; + $similarityOrder[] = "ABS(amount - {$amount}) ASC"; + $similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 THEN 0 ELSE 1 END"; } if (isset($param['keyword']) && $param['keyword']) { @@ -206,11 +216,6 @@ class FinPaymentApplyService $similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END"; } - if (isset($param['amount']) && !empty($param['amount'])) { - $amount = (float)$param['amount']; - $similarityOrder[] = "ABS(amount - {$amount})"; - } - // 构建排序SQL $orderByClause = ""; if (!empty($similarityOrder)) { From 9f944ae92cc86093b7b8e8bb750c4e088c8155f2 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 09:52:20 +0800 Subject: [PATCH 39/74] =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 19a2f3f..e5091fd 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -3,6 +3,7 @@ namespace app\common\service; use app\common\model\FinPaymentStock; +use app\common\model\FinReceipt; use app\common\validate\FinPaymentApplyValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\FinPaymentApply; @@ -182,10 +183,16 @@ class FinPaymentApplyService $query->whereDoesntHave('receipt'); } - if (isset($param['scene']) && $param['scene'] == 'list') { - return $query->paginate($limit, ['*'], 'page', $page); + if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) { + return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page); } + $receipt = FinReceipt::where('id', $param['receipt_id'])->first(); + $account_id = $receipt->account_id; + $currency_id = $receipt->currency_id; + $remitter = $receipt->remitter; + $amount = $receipt->amount; + // 计算十天前的时间戳 $sevenDaysAgo = time() - (10 * 24 * 60 * 60); @@ -193,29 +200,24 @@ class FinPaymentApplyService $similarityOrder = []; // 如果有传入参数,计算相似度 - if (isset($param['account_id']) && !empty($param['account_id'])) { - $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; + if (!empty($account_id)) { + $similarityOrder[] = "CASE WHEN account_id = {$account_id} THEN 0 ELSE 1 END"; } - if (isset($param['currency_id']) && !empty($param['currency_id'])) { - $similarityOrder[] = "CASE WHEN currency_id = {$param['currency_id']} THEN 0 ELSE 1 END"; + if (!empty($currency_id)) { + $similarityOrder[] = "CASE WHEN currency_id = {$currency_id} THEN 0 ELSE 1 END"; } - if (isset($param['remitter']) && !empty($param['remitter'])) { - $similarityOrder[] = "CASE WHEN remitter = {$param['remitter']} THEN 0 ELSE 1 END"; + if (!empty($remitter)) { + $similarityOrder[] = "CASE WHEN remitter = {$remitter} THEN 0 ELSE 1 END"; } - if (isset($param['amount']) && !empty($param['amount'])) { - $amount = (float)$param['amount']; + if (!empty($amount)) { + $amount = (float)$amount; $similarityOrder[] = "ABS(amount - {$amount}) ASC"; $similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 THEN 0 ELSE 1 END"; } - if (isset($param['keyword']) && $param['keyword']) { - $keyword = addslashes($param['keyword']); - $similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END"; - } - // 构建排序SQL $orderByClause = ""; if (!empty($similarityOrder)) { @@ -227,11 +229,11 @@ class FinPaymentApplyService } $orderByClause .= "CASE - WHEN created_at < {$sevenDaysAgo} THEN id + WHEN created_at > {$sevenDaysAgo} THEN id ELSE 999999 - END DESC"; + END DESC, "; - $orderByClause .= ", id DESC"; + $orderByClause .= "id DESC"; $query->orderByRaw($orderByClause); From 672258e594d1f2634f81f890458ffcc0e4966a5a Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 13:35:53 +0800 Subject: [PATCH 40/74] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/FinStatisticsController.php | 44 +++++++++++++++++++ .../controller/FinReceiptController.php | 15 +++++++ app/common/service/FinReceiptService.php | 19 +++++++- config/route.php | 4 ++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 app/admin/controller/dashboard/FinStatisticsController.php diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php new file mode 100644 index 0000000..a3d3f9b --- /dev/null +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -0,0 +1,44 @@ +',0); + + $result = []; + //已认领数量 + $result['claimed_num'] = $query->count(); + //已认领金额 + $result['claimed_amount'] = $query->sum('amount'); + + + $query = FinReceipt::whereNull('payment_apply_id'); + + //未认领数量 + $result['unclaimed_num'] = $query->count(); + //未认领金额 + $result['unclaimed_amount'] = $query->sum('amount'); + + //已超时未认领数量 + $result['timeout'] = $query->where('created_at','<',time()-24*3600)->count(); + + return $this->success($result); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index d8ef9c2..4e9c574 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -147,4 +147,19 @@ class FinReceiptController extends BaseController } return $data; } + + /** + * 收款记录统计 + * @param Request $request + * @return \support\Response + */ + public function statistics(Request $request) + { + try { + $raw = $this->service->statistics(); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 91db094..1f1c731 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -279,7 +279,7 @@ class FinReceiptService } /** - * 更新计算折让金额 + * 更新:绑定收款记录,计算折让金额 * @param Request $request * @param array $data * @param string $scene @@ -296,9 +296,24 @@ class FinReceiptService //折让金额 $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); $receipt = FinReceipt::find($id); - $data['discount_amount'] = $payment->amount - $payment->amount ?? 0; + $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; $updated = $this->logicUpdateBy($config, $data); return $this->postProcess(ucfirst($scene), $data); } + + /** + * 收款记录统计 + * @return bool|int + */ + public function statistics() + { + $finReceipt = FinReceipt::find($id); + if(!empty($finReceipt->received_at)){ + throw new BusinessException('该记录已将确认入账'); + } + $res = $this->logic->credit($id); + $this->afterServiceUpdate(['id'=>$id]); + return $res; + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index b962ee9..ec7d821 100644 --- a/config/route.php +++ b/config/route.php @@ -368,6 +368,10 @@ Route::group('/admin', function () { Route::any('/show', [app\common\controller\FinReceiptHisController::class, 'show']); }); + Route::group('/fin', function () { + Route::any('/statistics', [app\admin\controller\dashboard\FinStatisticsController::class, 'statistics']); + }); + // 付款申请 Route::group('/payment', function () { Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']); From ea3d511c4d486e56b133a7e0c9b84074a480c97d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 14:26:59 +0800 Subject: [PATCH 41/74] =?UTF-8?q?=E6=9C=AA=E5=85=A5=E8=B4=A6=E9=87=91?= =?UTF-8?q?=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/dashboard/FinStatisticsController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php index a3d3f9b..95cf09d 100644 --- a/app/admin/controller/dashboard/FinStatisticsController.php +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -24,6 +24,10 @@ class FinStatisticsController extends BaseController //已认领金额 $result['claimed_amount'] = $query->sum('amount'); + //未入账数量 + $result['unreceived_num'] = FinReceipt::whereNull('received_at')->count(); + //未入账金额 + $result['unreceived_amount'] = FinReceipt::whereNull('received_at')->sum('amount'); $query = FinReceipt::whereNull('payment_apply_id'); From a7d623656d18da446b29c81efd3295e7e7f912e3 Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 14:37:21 +0800 Subject: [PATCH 42/74] =?UTF-8?q?=E5=86=85=E5=8B=A4=E4=BB=AA=E8=A1=A8?= =?UTF-8?q?=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/OfficeClerkController.php | 164 ++++++++++++++++++ config/route.php | 11 ++ 2 files changed, 175 insertions(+) create mode 100644 app/admin/controller/dashboard/OfficeClerkController.php diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php new file mode 100644 index 0000000..2bd2bcc --- /dev/null +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -0,0 +1,164 @@ +where('approver_id', $request->user->uid) + ->where('status', 'approved') + ->count('id'); + + $pending = Db::table('approval_records') + ->where('approver_id', $request->user->uid) + ->where('status', 'pending') + ->count('id'); + + $unclaimed = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', 0) + ->count('id'); + + $claimed = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', '>', 0) + ->count('id'); + + $twentyFourHoursAgo = time() - (24 * 3600); + $timeout = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->whereNotNull('submit_files') + ->whereJsonLength('submit_files', '>', 0) + ->where('receipt_id', '>', 0) + ->where('claimed_at', '<', $twentyFourHoursAgo) + ->count('id'); + + return $this->success([ + 'approved' => $approved, + 'pending' => $pending, + 'unclaimed' => $unclaimed, + 'claimed' => $claimed, + 'timeout' => $timeout + ]); + } + + // 曲线 + public function curve() + { + $groupIds = Db::table('user_group') + ->where('scenario_code', 'stock_orders') + ->pluck('id'); + $userIds = Db::table('user_group_members') + ->whereIn('group_id', $groupIds) + ->pluck('user_id'); + $list = Db::table('stock_orders') + ->join('user', 'stock_orders.salesperson_id', '=', 'user.id') + ->whereIn('stock_orders.salesperson_id', $userIds) + ->whereIn('stock_orders.approval_status', [0, 1, 2]) + ->whereNull('stock_orders.deleted_at') + ->groupBy('stock_orders.salesperson_id', 'user.name') + ->selectRaw('user.name, count(*) as count') + ->pluck('count', 'name') + ->toArray(); + $optionType = []; + $counts = []; + foreach ($list as $key=>$val) { + $optionType[] = $key; + $counts[] = $val; + } + $arr = [ + "optionType" => $optionType, + "counts" => $counts + ]; + return $this->success($arr); + } + + // 审批 + public function approval(Request $request) + { + $list = Db::table('approval_records as ar') + ->join('approval_instances as ai', 'ar.instance_id', '=', 'ai.id') + ->join('stock_orders as so', 'ai.biz_id', '=', 'so.id') + ->where('ar.approver_id', $request->user->uid) + ->where('ar.status', 'pending') + ->where('ai.flow_type', 'stock_orders') + ->where('ai.biz_type', 'stock_orders') + ->where('ai.status', 'processing') + ->whereNull('so.deleted_at') + ->select( + 'so.order_no', + 'ai.created_at as approval_created_at', + 'so.salesperson_snapshot as salesperson_name' + ) + ->get() + ->map(function($item) { + return [ + 'order_no' => $item->order_no, + 'approval_created_at' => date('Y-m-d H:i:s', strtotime($item->approval_created_at)), // 格式化时间 + 'salesperson_name' => $item->salesperson_name + ]; + }) + ->toArray(); + return $this->success($list); + } + + // 认领 + public function claim(Request $request) + { + $type = $request->get('type'); + if ($type == 'unclaimed') { + $list = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', 0) + ->select( + 'apply_no', + 'amount', + 'created_at' + ) + ->get() + ->map(function($item) { + return [ + 'apply_no' => $item->apply_no, + 'amount' => $item->amount, + 'created_at' => date('Y-m-d H:i:s', $item->created_at) + ]; + }) + ->toArray(); + } else { + $twentyFourHoursAgo = time() - (24 * 3600); + $list = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->whereNotNull('submit_files') + ->whereJsonLength('submit_files', '>', 0) + ->where('receipt_id', '>', 0) + ->where('claimed_at', '<', $twentyFourHoursAgo) + ->select( + 'apply_no', + 'amount', + 'created_at' + ) + ->get() + ->map(function($item) { + return [ + 'apply_no' => $item->apply_no, + 'amount' => $item->amount, + 'created_at' => date('Y-m-d H:i:s', $item->created_at) + ]; + }) + ->toArray(); + } + return $this->success($list); + } +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index 2fafd16..a19797e 100644 --- a/config/route.php +++ b/config/route.php @@ -422,6 +422,17 @@ Route::group('/admin', function () { Route::any('/update', [app\common\controller\SysUpdateLogController::class, 'update']); Route::any('/destroy', [app\common\controller\SysUpdateLogController::class, 'destroy']); }); + + // 仪表盘 + Route::group('/dashboard', function () { + // 内勤 + Route::group('/officeclerk', function () { + Route::any('/card', [app\admin\controller\dashboard\OfficeClerkController::class, 'card']); + Route::any('/curve', [app\admin\controller\dashboard\OfficeClerkController::class, 'curve']); + Route::any('/approval', [app\admin\controller\dashboard\OfficeClerkController::class, 'approval']); + Route::any('/claim', [app\admin\controller\dashboard\OfficeClerkController::class, 'claim']); + }); + }); }); From 8c3a445a39b1d7c54d061966445f80a461efc3cc Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 14:39:10 +0800 Subject: [PATCH 43/74] Merge branch 'develop' into feature/mzl_dev # Conflicts: # config/route.php --- app/admin/controller/SysConfigController.php | 48 +++ .../dashboard/FinStatisticsController.php | 48 +++ app/admin/logic/SysConfigLogic.php | 17 + app/admin/service/SysConfigService.php | 83 +++++ app/admin/validate/SysConfigValidate.php | 29 ++ .../controller/FinPaymentApplyController.php | 128 +++++++ .../controller/FinReceiptController.php | 165 +++++++++ .../controller/FinReceiptHisController.php | 98 ++++++ app/common/controller/UploadController.php | 7 +- app/common/logic/FinPaymentApplyLogic.php | 17 + app/common/logic/FinReceiptHisLogic.php | 17 + app/common/logic/FinReceiptLogic.php | 21 ++ app/common/logic/SysConfigLogic.php | 22 ++ app/common/model/FinPaymentApply.php | 65 ++++ app/common/model/FinPaymentStock.php | 67 ++++ app/common/model/FinReceipt.php | 65 ++++ app/common/model/FinReceiptHis.php | 49 +++ app/common/model/StockOrders.php | 16 + app/common/model/SysConfig.php | 49 +++ app/common/service/FinPaymentApplyService.php | 243 +++++++++++++ app/common/service/FinReceiptHisService.php | 62 ++++ app/common/service/FinReceiptService.php | 319 ++++++++++++++++++ app/common/service/OssService.php | 34 ++ app/common/service/SysConfigService.php | 37 ++ app/common/service/SysOpLogService.php | 2 +- .../scaffold/templates/paymentFiles.stub | 103 ++++++ .../validate/FinPaymentApplyValidate.php | 29 ++ app/common/validate/FinReceiptHisValidate.php | 29 ++ app/common/validate/FinReceiptValidate.php | 56 +++ app/functions.php | 3 +- app/process/Task.php | 44 ++- config/route.php | 39 ++- 32 files changed, 2004 insertions(+), 7 deletions(-) create mode 100644 app/admin/controller/SysConfigController.php create mode 100644 app/admin/controller/dashboard/FinStatisticsController.php create mode 100644 app/admin/logic/SysConfigLogic.php create mode 100644 app/admin/service/SysConfigService.php create mode 100644 app/admin/validate/SysConfigValidate.php create mode 100644 app/common/controller/FinPaymentApplyController.php create mode 100644 app/common/controller/FinReceiptController.php create mode 100644 app/common/controller/FinReceiptHisController.php create mode 100644 app/common/logic/FinPaymentApplyLogic.php create mode 100644 app/common/logic/FinReceiptHisLogic.php create mode 100644 app/common/logic/FinReceiptLogic.php create mode 100644 app/common/logic/SysConfigLogic.php create mode 100644 app/common/model/FinPaymentApply.php create mode 100644 app/common/model/FinPaymentStock.php create mode 100644 app/common/model/FinReceipt.php create mode 100644 app/common/model/FinReceiptHis.php create mode 100644 app/common/model/SysConfig.php create mode 100644 app/common/service/FinPaymentApplyService.php create mode 100644 app/common/service/FinReceiptHisService.php create mode 100644 app/common/service/FinReceiptService.php create mode 100644 app/common/service/SysConfigService.php create mode 100644 app/common/utils/scaffold/templates/paymentFiles.stub create mode 100644 app/common/validate/FinPaymentApplyValidate.php create mode 100644 app/common/validate/FinReceiptHisValidate.php create mode 100644 app/common/validate/FinReceiptValidate.php diff --git a/app/admin/controller/SysConfigController.php b/app/admin/controller/SysConfigController.php new file mode 100644 index 0000000..3534079 --- /dev/null +++ b/app/admin/controller/SysConfigController.php @@ -0,0 +1,48 @@ +service = new SysConfigService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php new file mode 100644 index 0000000..95cf09d --- /dev/null +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -0,0 +1,48 @@ +',0); + + $result = []; + //已认领数量 + $result['claimed_num'] = $query->count(); + //已认领金额 + $result['claimed_amount'] = $query->sum('amount'); + + //未入账数量 + $result['unreceived_num'] = FinReceipt::whereNull('received_at')->count(); + //未入账金额 + $result['unreceived_amount'] = FinReceipt::whereNull('received_at')->sum('amount'); + + $query = FinReceipt::whereNull('payment_apply_id'); + + //未认领数量 + $result['unclaimed_num'] = $query->count(); + //未认领金额 + $result['unclaimed_amount'] = $query->sum('amount'); + + //已超时未认领数量 + $result['timeout'] = $query->where('created_at','<',time()-24*3600)->count(); + + return $this->success($result); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/admin/logic/SysConfigLogic.php b/app/admin/logic/SysConfigLogic.php new file mode 100644 index 0000000..60be4a8 --- /dev/null +++ b/app/admin/logic/SysConfigLogic.php @@ -0,0 +1,17 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 状态 + if (isset($p['status']) && in_array($p['status'], [0,1])) { + $config['where']['status'] = $p['status']; + } + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + foreach (['config_key','config_value','description'] as $col) { + $config['orWhere'][] = [$col, 'like', $k]; + } + } + break; + case 'show': + $config['where']['id'] = $p['id']; + //$config['where']['status'] = 1; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } + + + public function beforeServiceUpdate($data, Request $request) + { + Redis::del($data['config_key']); + } +} \ No newline at end of file diff --git a/app/admin/validate/SysConfigValidate.php b/app/admin/validate/SysConfigValidate.php new file mode 100644 index 0000000..2bb978a --- /dev/null +++ b/app/admin/validate/SysConfigValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php new file mode 100644 index 0000000..3bf4b15 --- /dev/null +++ b/app/common/controller/FinPaymentApplyController.php @@ -0,0 +1,128 @@ +service = new FinPaymentApplyService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['doc_user_id'])) //内勤 + $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; + if (isset($data['sales_user_id'])) //业务员 + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; + if (isset($data['corp_id'])) //公司(渠道) + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; + if (isset($data['account_id'])){ //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + $OssService = new OssService(); + if (isset($data['submit_files'])){ + $data['submit_files'] = json_decode($data['submit_files'], true); + foreach ($data['submit_files'] as $key => $value) { + $data['submit_files'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + } + if (!empty($data['voucher_file'])) { + $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); + } elseif (isset($data['voucher_file'])) { + $data['voucher_file_full'] = ''; + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['claimed_at'])){ + $data['enter_file_last'] = date('Y-m-d H:i:s', ($data['claimed_at']+86400)); //入账资料最后提交时间 + $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); //认领时间 + } + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + public function showFormat($data) + { + if (isset($data['doc_user_id'])) //内勤 + $data['doc_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; + if (isset($data['sales_user_id'])) //业务员 + $data['sales_user_name'] = User::where('id', $data['doc_user_id'])->value('name')??''; + if (isset($data['corp_id'])) //公司(渠道) + $data['corp_name'] = SysDictItem::where('id', $data['corp_id'])->value('item_label')??''; + if (isset($data['account_id'])){ //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + $OssService = new OssService(); + if (isset($data['submit_files'])){ + $data['submit_files'] = json_decode($data['submit_files'], true); + foreach ($data['submit_files'] as $key => $value) { + $data['submit_files'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + } + if (!empty($data['voucher_file'])) { + $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); + } elseif (isset($data['voucher_file'])) { + $data['voucher_file_full'] = ''; + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + + $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); + $stock = []; + foreach ($finPaymentStock as $v) { + $stock[$v['pi_no']]['pi_no'] = $v['pi_no']; + $stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']]; + } + $data['stock'] = array_values($stock); + return $data; + } +} \ No newline at end of file diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php new file mode 100644 index 0000000..4e9c574 --- /dev/null +++ b/app/common/controller/FinReceiptController.php @@ -0,0 +1,165 @@ +service = new FinReceiptService(); + } + + /** + * 确认入账 + * @param Request $request + * @return \support\Response + */ + public function credit(Request $request) + { + try { + $id = $request->input('id'); + $raw = $this->service->credit($id); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + public function show(Request $request) + { + try { + $raw = $this->service->serviceShow($request); + $data = $this->transformData($raw, method_exists($this, 'showFormat') + ? [$this, 'showFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + /** + * 更新 + * + * @param Request $request 请求对象 + * @return mixed 返回更新成功的数据或信息 + */ + public function payment(Request $request) + { + try { + $data = $this->validate($this->service->getValidator(), $request->post(), 'update'); + $res = $this->service->serviceUpdatePayment($request, $data); + return $this->success([], '更新成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])){ + $data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0; + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + } + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) { //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) { //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])) { + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + } elseif (isset($data['fx_receipt_file'])) { + $data['fx_receipt_file_full'] = ''; + } + + if (!empty($data['payment_apply_id'])) { + $paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first(); + if(!$paymentApply) + return $data; + $paymentApply = $paymentApply->toArray(); + $paymentApply['created_at'] = strtotime($paymentApply['created_at']); + $paymentApply['updated_at'] = strtotime($paymentApply['updated_at']); + $paymentApply = (new FinPaymentApplyController())->showFormat($paymentApply); + $data['payment_apply'] = $paymentApply; + } + return $data; + } + + /** + * 收款记录统计 + * @param Request $request + * @return \support\Response + */ + public function statistics(Request $request) + { + try { + $raw = $this->service->statistics(); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/common/controller/FinReceiptHisController.php b/app/common/controller/FinReceiptHisController.php new file mode 100644 index 0000000..7adcf0d --- /dev/null +++ b/app/common/controller/FinReceiptHisController.php @@ -0,0 +1,98 @@ +service = new FinReceiptHisService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])) { //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } + + if (isset($data['created_by'])) + $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; + if (isset($data['updated_by'])) + $data['updated_by'] = User::where('id', $data['updated_by'])->value('name')??''; + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['arrived_at'])) + $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); + if (isset($data['received_at'])) + $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + if (isset($data['account_id'])){ //收款账号 + $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; + $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; + } + if (isset($data['country_id'])) //付款来源国家 + $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; + if (isset($data['currency_id'])) //付款币种 + $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + if (!empty($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); + }elseif (isset($data['fx_receipt_file'])){ + $data['fx_receipt_file_full'] = ''; + } + + if (isset($data['created_by'])) + $data['created_by'] = User::where('id', $data['created_by'])->value('name')??''; + if (isset($data['updated_by'])) + $data['updated_by'] = User::where('id', $data['updated_by'])->value('name')??''; + return $data; + } +} \ No newline at end of file diff --git a/app/common/controller/UploadController.php b/app/common/controller/UploadController.php index d90c84a..a025666 100644 --- a/app/common/controller/UploadController.php +++ b/app/common/controller/UploadController.php @@ -87,12 +87,15 @@ class UploadController } $originalName = $file->getUploadName(); + $ossservice = new OssService(); + $mimes = $ossservice->getMimeTypes(['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'zip', 'rar']); + $result = Storage::adapter('oss') ->path('x_server/' . $sceneUrl . date('Ymd')) ->size(1024*1024*5) + ->extYes($mimes) ->upload($file); - - $ossservice = new OssService(); + $data = [ 'original_name' => $originalName, diff --git a/app/common/logic/FinPaymentApplyLogic.php b/app/common/logic/FinPaymentApplyLogic.php new file mode 100644 index 0000000..09b93e1 --- /dev/null +++ b/app/common/logic/FinPaymentApplyLogic.php @@ -0,0 +1,17 @@ +update(['received_at' => time()]); + } +} \ No newline at end of file diff --git a/app/common/logic/SysConfigLogic.php b/app/common/logic/SysConfigLogic.php new file mode 100644 index 0000000..633d177 --- /dev/null +++ b/app/common/logic/SysConfigLogic.php @@ -0,0 +1,22 @@ +where('config_key', $key)->get(['id', 'config_key', 'config_value']); + } +} \ No newline at end of file diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php new file mode 100644 index 0000000..0f4d157 --- /dev/null +++ b/app/common/model/FinPaymentApply.php @@ -0,0 +1,65 @@ +hasOne(FinReceipt::class, 'payment_apply_id', 'id'); + } + + /** + * 关联的备货单(通过中间表) + */ + public function stocks() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); + } +} \ No newline at end of file diff --git a/app/common/model/FinPaymentStock.php b/app/common/model/FinPaymentStock.php new file mode 100644 index 0000000..d5b3d10 --- /dev/null +++ b/app/common/model/FinPaymentStock.php @@ -0,0 +1,67 @@ +belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); + } + + // 收款记录 + public function receipt() + { + return $this->belongsTo(FinReceipt::class, 'receipt_id', 'id'); + } + + // 备货单 + public function stock() + { + return $this->belongsTo(StockOrders::class, 'stock_id', 'id'); + } +} \ No newline at end of file diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php new file mode 100644 index 0000000..7347be0 --- /dev/null +++ b/app/common/model/FinReceipt.php @@ -0,0 +1,65 @@ +belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); + } + + /** + * 关联的备货单(通过中间表) + */ + public function stocks() + { + return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); + } +} \ No newline at end of file diff --git a/app/common/model/FinReceiptHis.php b/app/common/model/FinReceiptHis.php new file mode 100644 index 0000000..814b87f --- /dev/null +++ b/app/common/model/FinReceiptHis.php @@ -0,0 +1,49 @@ +hasOne(User::class, 'id', 'salesperson_id'); } + + /** + * 客户的标签 + */ + public function payment() + { + return $this->belongsToMany(FinPaymentApply::class, 'fin_payment_stock', 'stock_id', 'payment_apply_id'); + } + + /** + * 关联收款记录(多对多,经由中间表) + */ + public function receipts() + { + return $this->belongsToMany(FinReceipt::class, 'fin_payment_stock', 'stock_id', 'receipt_id'); + } } \ No newline at end of file diff --git a/app/common/model/SysConfig.php b/app/common/model/SysConfig.php new file mode 100644 index 0000000..29b4577 --- /dev/null +++ b/app/common/model/SysConfig.php @@ -0,0 +1,49 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'index'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 汇款国家 + if (isset($p['country_id']) && !empty($p['country_id'])) { + $config['where']['country_id'] = $p['country_id']; + } + + // 收款账户筛选 + if (isset($p['account_id']) && !empty($p['account_id'])) { + $config['where']['account_id'] = $p['account_id']; + } + + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + $config['orWhere'][] = ['remitter', 'like', $k]; + } + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + case 'update': + case 'destroy': + $config['where']['id'] = $p['id']; + break; + case 'store': + break; + } + + return $config; + } + + public function beforeServiceStore($data, Request $request) + { + $data['apply_no'] = $this->generateUniqueApplyNo(); + $data['doc_user_id'] = $request->user->uid; + $data['submit_files'] = json_encode($data['submit_files']); + redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); + unset($data['stock']); + return $data; + } + + + public function afterServiceStore($res) + { + $data = [ + 'payment_apply_id' => $res['id'], + ]; + $piStock = json_decode(redis::get('stock_' . $res['doc_user_id']), true); + redis::del('stock' . $res['doc_user_id']); + foreach ($piStock as $stock) { + foreach ($stock['stock_id'] as $v) { + $data['stock_id'] = $v; + $data['pi_no'] = $stock['pi_on']; + FinPaymentStock::create($data); + } + } + } + + public function beforeServiceUpdate($data, Request $request) + { + $data['submit_files'] = json_encode($data['submit_files']); + return $data; + } + + /** + * 生成唯一的付款申请编码 + * 格式:PA + 日期 + 6位字母数字组合 + * + * @return string 唯一编码 + */ + public function generateUniqueApplyNo() + { + $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $maxAttempts = 10; // 防止无限循环 + $secondChar = 'PA' . date('Ymd'); + + for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { + // 生成后6位随机字符 + $suffix = ''; + for ($i = 0; $i < 6; $i++) { + $suffix .= $chars[rand(0, strlen($chars) - 1)]; + } + + $applyNo = $secondChar . $suffix; + + // 检查是否已存在 + $existing = FinPaymentApply::where('apply_no', $applyNo)->first(); + if (!$existing) { + return $applyNo; + } + } + + // 如果1000次尝试后仍然重复,使用时间戳确保唯一性 + $timestamp = substr(time(), -6); + return $secondChar . $timestamp; + } + + /** + * 根据相似度排序付款记录 + * @param Request $request + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator + */ + public function complexQueryIndex(Request $request) + { + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $param = $request->all(); + + $where = []; + + // 汇款国家 + if (isset($param['country_id']) && !empty($param['country_id'])) { + $where[] = ['country_id', $param['country_id']]; + } + // 收款账户筛选 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $where[] = ['account_id', $param['account_id']]; + } + + // 关键字 + if (isset($param['keyword']) && $param['keyword']) { + $k = '%' . $param['keyword'] . '%'; + $where[] = ['remitter', 'like', $k]; + } + + // 构建查询 + $query = $this->modelClass::where($where); + + // 是否已关联收款记录的筛选 + $correlation = $param['correlation']??''; + if ($correlation === 'receipt') { //已关联 + $query->whereHas('receipt'); + } elseif ($correlation === 'unbind') { //未关联 + $query->whereDoesntHave('receipt'); + } + + if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) { + return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page); + } + + $receipt = FinReceipt::where('id', $param['receipt_id'])->first(); + $account_id = $receipt->account_id; + $currency_id = $receipt->currency_id; + $remitter = $receipt->remitter; + $amount = $receipt->amount; + + // 计算十天前的时间戳 + $sevenDaysAgo = time() - (10 * 24 * 60 * 60); + + // 构建相似度排序逻辑 + $similarityOrder = []; + + // 如果有传入参数,计算相似度 + if (!empty($account_id)) { + $similarityOrder[] = "CASE WHEN account_id = {$account_id} THEN 0 ELSE 1 END"; + } + + if (!empty($currency_id)) { + $similarityOrder[] = "CASE WHEN currency_id = {$currency_id} THEN 0 ELSE 1 END"; + } + + if (!empty($remitter)) { + $similarityOrder[] = "CASE WHEN remitter = {$remitter} THEN 0 ELSE 1 END"; + } + + if (!empty($amount)) { + $amount = (float)$amount; + $similarityOrder[] = "ABS(amount - {$amount}) ASC"; + $similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 THEN 0 ELSE 1 END"; + } + + // 构建排序SQL + $orderByClause = ""; + if (!empty($similarityOrder)) { + $orderByClause = "CASE + WHEN created_at >= {$sevenDaysAgo} THEN + (" . implode(' + ', $similarityOrder) . ") + ELSE 0 + END ASC, "; + } + + $orderByClause .= "CASE + WHEN created_at > {$sevenDaysAgo} THEN id + ELSE 999999 + END DESC, "; + + $orderByClause .= "id DESC"; + + $query->orderByRaw($orderByClause); + + return $query->paginate($limit, ['*'], 'page', $page); + } + +} \ No newline at end of file diff --git a/app/common/service/FinReceiptHisService.php b/app/common/service/FinReceiptHisService.php new file mode 100644 index 0000000..f43f77b --- /dev/null +++ b/app/common/service/FinReceiptHisService.php @@ -0,0 +1,62 @@ +validator; + } + + /** + * 构建查询条件 + */ + protected function buildQueryConfig(Request $request, string $scene = 'index'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + if(empty($p['receipt_id'])){ + throw new BusinessException('receipt_id不能为空'); + } + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + $config['where']['receipt_id'] = $p['receipt_id']; + + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } +} \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php new file mode 100644 index 0000000..1f1c731 --- /dev/null +++ b/app/common/service/FinReceiptService.php @@ -0,0 +1,319 @@ +logic = (new FinReceiptLogic()); + } + + /** + * 获取验证器 + */ + 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': + // ====== ====== 排序 ====== ====== + $config['order']['id'] = 'desc'; + + // ====== ====== 筛选 ====== ====== + // 汇款国家 + if (isset($p['country_id']) && !empty($p['country_id'])) { + $config['where']['country_id'] = $p['country_id']; + } + + // 没有付款记录的收款记录 + if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { //未认领 + $config['where']['payment_apply_id'] = ['null']; + } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { //已认领 + $config['where']['payment_apply_id'] = ['not null']; + } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'timeout') { //超时未认领 + $config['where']['payment_apply_id'] = ['not null']; + $config['where']['created_at'] = ['<' ,time() - 24*60*60]; + } + + // 收款申请筛选 + if (isset($p['payment_apply_id']) && !empty($p['payment_apply_id'])) { + $config['where']['payment_apply_id'] = $p['payment_apply_id']; + } + + // 收款账户筛选 + if (isset($p['account_id']) && !empty($p['account_id'])) { + $config['where']['account_id'] = $p['account_id']; + } + + // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + $config['orWhere'][] = ['remitter', 'like', $k]; + } + break; + case 'show': + $config['where']['id'] = $p['id']; + break; + case 'update': + case 'payment': + case 'destroy': + $config['where']['id'] = $p['id']; + break; + case 'store': + break; + } + + return $config; + } + + public function beforeServiceStore($data, Request $request) + { + if(isset($data['payment_apply_id']) && empty($data['payment_apply_id'])){ + unset($data['payment_apply_id']); + } + $data['receipt_no'] = $this->generateUniqueReceipt(); + $data['arrived_at'] = strtotime( $data['arrived_at']); + $data['created_by'] = $request->user->uid; + $data['updated_by'] = $request->user->uid; + return $data; + } + + public function afterServiceStore($res) + { + $receipt = FinReceipt::where('id',$res->id)->first()->toArray(); + $receipt = array_merge($receipt,['receipt_id' => $res->id]); + unset($receipt['id']); + FinReceiptHis::create($receipt); + } + + public function beforeServiceUpdate($data, Request $request) + { + $data['updated_by'] = $request->user->uid; + if(isset($data['arrived_at'])) + $data['arrived_at'] = strtotime($data['arrived_at']); + if(isset($data['received_at'])) + $data['received_at'] = strtotime($data['received_at']); + + return $data; + } + public function afterServiceUpdate($res) + { + $receipt = FinReceipt::where('id',$res['id'])->first()->toArray(); + $receipt = array_merge($receipt,['receipt_id' => $res['id']]); + unset($receipt['id']); + FinReceiptHis::create($receipt); + } + + + /** + * 生成唯一的付款申请编码 + * 格式:PA + 日期 + 6位字母数字组合 + * + * @return string 唯一编码 + */ + public function generateUniqueReceipt() + { + $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $maxAttempts = 10; // 防止无限循环 + $secondChar = 'RE' . date('Ymd'); + + for ($attempt = 0; $attempt < $maxAttempts; $attempt++) { + // 生成后6位随机字符 + $suffix = ''; + for ($i = 0; $i < 6; $i++) { + $suffix .= $chars[rand(0, strlen($chars) - 1)]; + } + + $ReceiptNo = $secondChar . $suffix; + + // 检查是否已存在 + $existing = FinReceipt::where('receipt_no', $ReceiptNo)->first(); + if (!$existing) { + return $ReceiptNo; + } + } + + // 如果1000次尝试后仍然重复,使用时间戳确保唯一性 + $timestamp = substr(time(), -6); + return $secondChar . $timestamp; + } + + /** + * 根据相似度排序付款记录 + * @param Request $request + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator + */ + public function complexQueryIndex(Request $request) + { + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $param = $request->all(); + + $where = []; + + // 汇款国家 + if (isset($param['country_id']) && !empty($param['country_id'])) { + $where[] = ['country_id', $param['country_id']]; + } + // 收款账户筛选 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $where[] = ['account_id', $param['account_id']]; + } + // 收款申请筛选 + if (isset($param['payment_apply_id']) && !empty($param['payment_apply_id'])) { + $where[]['payment_apply_id'] = $param['payment_apply_id']; + } + + // 关键字 + if (isset($param['keyword']) && $param['keyword']) { + $k = '%' . $param['keyword'] . '%'; + $where[] = ['remitter', 'like', $k]; + } + + // 构建查询 + $query = $this->modelClass::where($where); + + // 没有付款记录的收款记录 + if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') { + $query->whereNull('payment_apply_id'); + } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { + $query->whereNotNull('payment_apply_id'); + } + + if (isset($param['scene']) && $param['scene'] == 'list') { + return $query->paginate($limit, ['*'], 'page', $page); + } + + // 计算七天前的时间戳 + $sevenDaysAgo = time() - (10 * 24 * 60 * 60); + + // 构建相似度排序逻辑 + $similarityOrder = []; + + // 如果有传入参数,计算相似度 + if (isset($param['account_id']) && !empty($param['account_id'])) { + $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['country_id']) && !empty($param['country_id'])) { + $similarityOrder[] = "CASE WHEN country_id = {$param['country_id']} THEN 0 ELSE 1 END"; + } + + if (isset($param['keyword']) && $param['keyword']) { + $keyword = addslashes($param['keyword']); + $similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END"; + } + + if (isset($param['amount']) && !empty($param['amount'])) { + $amount = (float)$param['amount']; + $similarityOrder[] = "ABS(amount - {$amount})"; + } + + // 构建排序SQL + $orderByClause = ""; + if (!empty($similarityOrder)) { + $orderByClause = "CASE + WHEN created_at >= {$sevenDaysAgo} THEN + (" . implode(' + ', $similarityOrder) . ") + ELSE 999999 + END ASC, "; + } + + $orderByClause .= "CASE + WHEN created_at < {$sevenDaysAgo} THEN id + ELSE 0 + END DESC"; + + $query->orderByRaw($orderByClause); + + return $query->paginate($limit, ['*'], 'page', $page); + } + + public function credit($id) + { + $finReceipt = FinReceipt::find($id); + if(!empty($finReceipt->received_at)){ + throw new BusinessException('该记录已将确认入账'); + } + $res = $this->logic->credit($id); + $this->afterServiceUpdate(['id'=>$id]); + return $res; + } + + /** + * 更新:绑定收款记录,计算折让金额 + * @param Request $request + * @param array $data + * @param string $scene + * @return mixed + */ + public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') + { + $payment_apply_id = $request->input('payment_apply_id'); + $id = $request->input('id'); + $data = $this->preProcess(ucfirst($scene), $data, $request); + $config = $this->buildQueryConfig($request, $scene); + FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time(), 'claimed_by' => $request->user->uid]); + + //折让金额 + $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); + $receipt = FinReceipt::find($id); + $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; + + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess(ucfirst($scene), $data); + } + + /** + * 收款记录统计 + * @return bool|int + */ + public function statistics() + { + $finReceipt = FinReceipt::find($id); + if(!empty($finReceipt->received_at)){ + throw new BusinessException('该记录已将确认入账'); + } + $res = $this->logic->credit($id); + $this->afterServiceUpdate(['id'=>$id]); + return $res; + } +} \ No newline at end of file diff --git a/app/common/service/OssService.php b/app/common/service/OssService.php index 72a956e..1aacc1c 100644 --- a/app/common/service/OssService.php +++ b/app/common/service/OssService.php @@ -76,4 +76,38 @@ class OssService throw new BusinessException('Delete Error: ' . $th->getMessage()); } } + + /** + * 获取对应的 MIME 类型 + */ + public function getMimeTypes($extensions) + { + $mimeMap = [ + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'png' => 'image/png', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + 'webp' => 'image/webp', + 'pdf' => 'application/pdf', + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xls' => 'application/vnd.ms-excel', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'ppt' => 'application/vnd.ms-powerpoint', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'txt' => 'text/plain', + 'zip' => 'application/zip', + 'rar' => 'application/x-rar-compressed' + ]; + + $mimes = []; + foreach ($extensions as $ext) { + if (isset($mimeMap[$ext])) { + $mimes[] = $mimeMap[$ext]; + } + } + + return array_unique($mimes); + } } \ No newline at end of file diff --git a/app/common/service/SysConfigService.php b/app/common/service/SysConfigService.php new file mode 100644 index 0000000..d52972f --- /dev/null +++ b/app/common/service/SysConfigService.php @@ -0,0 +1,37 @@ +logic = (new SysConfigLogic()); + } + + /** + * 获取系统list + */ + public static function getConfig(string $config_key) + { + $value = Redis::get($config_key); + if (empty($value)) { + $config = (new SysConfigLogic())->findByKey($config_key); + if (empty($config)) { + return null; + } + $value = $config->config_value; + Redis::set($config->config_key, $value, 'EX', 7200); + } + + return $value; + } +} \ No newline at end of file diff --git a/app/common/service/SysOpLogService.php b/app/common/service/SysOpLogService.php index 3291093..ee19817 100644 --- a/app/common/service/SysOpLogService.php +++ b/app/common/service/SysOpLogService.php @@ -61,7 +61,7 @@ class SysOpLogService // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; - foreach (['user_name', 'route'] as $col) { + foreach (['user_name', 'route', 'params_brief'] as $col) { $config['orWhere'][] = [$col, 'like', $k]; } } diff --git a/app/common/utils/scaffold/templates/paymentFiles.stub b/app/common/utils/scaffold/templates/paymentFiles.stub new file mode 100644 index 0000000..6c9cded --- /dev/null +++ b/app/common/utils/scaffold/templates/paymentFiles.stub @@ -0,0 +1,103 @@ + + + + + + 邮箱提醒 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/common/validate/FinPaymentApplyValidate.php b/app/common/validate/FinPaymentApplyValidate.php new file mode 100644 index 0000000..58145e3 --- /dev/null +++ b/app/common/validate/FinPaymentApplyValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/validate/FinReceiptHisValidate.php b/app/common/validate/FinReceiptHisValidate.php new file mode 100644 index 0000000..7a1f7c4 --- /dev/null +++ b/app/common/validate/FinReceiptHisValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/common/validate/FinReceiptValidate.php b/app/common/validate/FinReceiptValidate.php new file mode 100644 index 0000000..237b03e --- /dev/null +++ b/app/common/validate/FinReceiptValidate.php @@ -0,0 +1,56 @@ + 'integer|gt:0', +// 'country_id' => 'require|integer|gt:0', +// 'remitter' => 'require', +// 'account_id' => 'require|integer|gt:0', +// 'currency_id' => 'require|integer|gt:0', +// 'amount' => 'require|gt:0', +// 'exchange_rate' => 'require|gt:0', +// 'arrived_at' => 'require', +// 'is_domestic_return' => 'require|integer', + ]; + + // 提示 + protected $message = [ +// 'payment_apply_id.integer' => '付款申请ID必须是整数', +// 'payment_apply_id.gt' => '付款申请ID必须大于0', +// 'country_id.require' => '付款来源国家ID不能为空', +// 'country_id.integer' => '付款来源国家ID必须是整数', +// 'country_id.gt' => '付款来源国家ID必须大于0', +// 'remitter.require' => '汇款人不能为空', +// 'account_id.require' => '收款账号ID不能为空', +// 'account_id.integer' => '收款账号ID必须是整数', +// 'account_id.gt' => '收款账号ID必须大于0', +// 'currency_id.require' => '收款币种ID不能为空', +// 'currency_id.integer' => '收款币种ID必须是整数', +// 'currency_id.gt' => '收款币种ID必须大于0', +// 'amount.require' => '收款金额不能为空', +// 'amount.gt' => '收款金额必须大于0', +// 'exchange_rate.require' => '实际汇率不能为空', +// 'exchange_rate.gt' => '实际汇率必须大于0', +// 'arrived_at.require' => '到账时间不能为空', +// 'arrived_at.gt' => '到账时间必须大于0', +// 'is_domestic_return.require' => '是否回转内地不能为空', +// 'is_domestic_return.integer' => '是否回转内地必须是整数', + ]; + + // 场景 + protected $scene = [ + 'store' => [ +// 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'exchange_rate', 'arrived_at' + ], + + 'update' => [ +// 'payment_apply_id' + ] + ]; +} \ No newline at end of file diff --git a/app/functions.php b/app/functions.php index 21e53c9..43c2f9a 100644 --- a/app/functions.php +++ b/app/functions.php @@ -180,7 +180,8 @@ if (!function_exists('tplUrl')) { { $urlArray = [ 'email' => 'common/utils/scaffold/templates/Email.stub', - 'work_order' => 'common/utils/scaffold/templates/workOrder.stub' + 'work_order' => 'common/utils/scaffold/templates/workOrder.stub', + 'payment_files' => 'common/utils/scaffold/templates/paymentFiles.stub', ]; return $urlArray[$tplKey]; } diff --git a/app/process/Task.php b/app/process/Task.php index ccaa228..8f9cea1 100644 --- a/app/process/Task.php +++ b/app/process/Task.php @@ -2,6 +2,8 @@ namespace app\process; +use app\common\model\FinPaymentApply; +use app\common\model\User; use app\crm\model\Customer; use support\Log; use Workerman\Crontab\Crontab; @@ -11,7 +13,7 @@ class Task public function onWorkerStart() { - // 每半小时执行一次 + // 每半小时执行一次,通知待跟进客户 new Crontab('0 */30 * * * *', function(){ echo date('Y-m-d H:i:s') . "\n"; Log::info('send follow start',[time()]); @@ -41,7 +43,45 @@ class Task $item->save(); } - Log::info('send follow start',[time()]); + Log::info('send follow end',[time()]); + }); + + // 检查入账资料是否提交 + new Crontab('* */70 * * * *', function () { + $G = date('G'); + if ($G > 22 || $G < 8) { + return; + } + Log::info('fin_payment_apply submit_files start', [time()]); + $orWhere = [ + ['submit_files', '=', '[]'], + ['submit_files', '=', ''], + ]; + $where = [ + ['warn', '<', 2], + ['created_at', '>', time() - 60 * 60 * 48], + ['created_at', '<', time() - 60 * 60 * 24], + ]; + $payment = FinPaymentApply::where($where)->orWhere($orWhere)->orderBy('id', 'desc')->get(); + foreach ($payment as $item) { + Log::info('fin_payment_apply submit_files ', [$item->toArray()]); + $notice = [ + 'code' => $item->apply_no, + 'payment_entity' => $item->payment_entity ?? $item->remitter, + 'content' => '认领收款单后请在24小时内提交入账资料', + 'reply' => '', + ]; + $email = []; + $email[] = User::where('id', $item->claimed_by)->value('email'); + $email[] = User::where('id', $item->doc_user_id)->value('email'); + $email = array_unique($email); + \app\common\utils\email\MailSend::send($email, '【XYH】付款记录', replaceTpl($notice, 'payment_files')); + + $item->warn = ++$item->warn; + $item->save(); + } + + Log::info('fin_payment_apply submit_files end', [time()]); }); } diff --git a/config/route.php b/config/route.php index a19797e..22b0862 100644 --- a/config/route.php +++ b/config/route.php @@ -389,7 +389,6 @@ Route::group('/admin', function () { }); }); - Route::group('/purchase/order', function () { Route::any('/predata', [app\common\controller\PurchaseOrdersController::class, 'preQueryData']); Route::any('/list', [app\common\controller\PurchaseOrdersController::class, 'index']); @@ -423,6 +422,44 @@ Route::group('/admin', function () { Route::any('/destroy', [app\common\controller\SysUpdateLogController::class, 'destroy']); }); + // 收款记录 + Route::group('/receipt', function () { + Route::any('/list', [app\common\controller\FinReceiptController::class, 'index']); + Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']); + Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); + Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); + Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']); + Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); + Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); + }); + // 收款记录历史 + Route::group('/receipt/his', function () { + Route::any('/list', [app\common\controller\FinReceiptHisController::class, 'index']); + Route::any('/show', [app\common\controller\FinReceiptHisController::class, 'show']); + }); + + Route::group('/fin', function () { + Route::any('/statistics', [app\admin\controller\dashboard\FinStatisticsController::class, 'statistics']); + }); + + // 付款申请 + Route::group('/payment', function () { + Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']); + Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']); + Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']); + Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']); + Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']); + }); + + // 系统配置 + Route::group('/config', function () { + Route::any('/list', [app\admin\controller\SysConfigController::class, 'index']); + Route::any('/show', [app\admin\controller\SysConfigController::class, 'show']); + Route::any('/store', [app\admin\controller\SysConfigController::class, 'store']); + Route::any('/update', [app\admin\controller\SysConfigController::class, 'update']); + Route::any('/destroy', [app\admin\controller\SysConfigController::class, 'destroy']); + }); + // 仪表盘 Route::group('/dashboard', function () { // 内勤 From ef0c23613015490356c887a3b7139eb8c5da2636 Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 14:39:35 +0800 Subject: [PATCH 44/74] Merge branch 'develop' into feature/mzl_dev # Conflicts: # config/route.php From 077edc5fd6bf914e31c22f1909c2e1187a1be706 Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 14:40:24 +0800 Subject: [PATCH 45/74] Merge branch 'feature/mzl_dev' into develop # Conflicts: # config/route.php --- .../dashboard/OfficeClerkController.php | 164 ++++++++++++++++++ config/route.php | 11 ++ 2 files changed, 175 insertions(+) create mode 100644 app/admin/controller/dashboard/OfficeClerkController.php diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php new file mode 100644 index 0000000..2bd2bcc --- /dev/null +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -0,0 +1,164 @@ +where('approver_id', $request->user->uid) + ->where('status', 'approved') + ->count('id'); + + $pending = Db::table('approval_records') + ->where('approver_id', $request->user->uid) + ->where('status', 'pending') + ->count('id'); + + $unclaimed = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', 0) + ->count('id'); + + $claimed = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', '>', 0) + ->count('id'); + + $twentyFourHoursAgo = time() - (24 * 3600); + $timeout = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->whereNotNull('submit_files') + ->whereJsonLength('submit_files', '>', 0) + ->where('receipt_id', '>', 0) + ->where('claimed_at', '<', $twentyFourHoursAgo) + ->count('id'); + + return $this->success([ + 'approved' => $approved, + 'pending' => $pending, + 'unclaimed' => $unclaimed, + 'claimed' => $claimed, + 'timeout' => $timeout + ]); + } + + // 曲线 + public function curve() + { + $groupIds = Db::table('user_group') + ->where('scenario_code', 'stock_orders') + ->pluck('id'); + $userIds = Db::table('user_group_members') + ->whereIn('group_id', $groupIds) + ->pluck('user_id'); + $list = Db::table('stock_orders') + ->join('user', 'stock_orders.salesperson_id', '=', 'user.id') + ->whereIn('stock_orders.salesperson_id', $userIds) + ->whereIn('stock_orders.approval_status', [0, 1, 2]) + ->whereNull('stock_orders.deleted_at') + ->groupBy('stock_orders.salesperson_id', 'user.name') + ->selectRaw('user.name, count(*) as count') + ->pluck('count', 'name') + ->toArray(); + $optionType = []; + $counts = []; + foreach ($list as $key=>$val) { + $optionType[] = $key; + $counts[] = $val; + } + $arr = [ + "optionType" => $optionType, + "counts" => $counts + ]; + return $this->success($arr); + } + + // 审批 + public function approval(Request $request) + { + $list = Db::table('approval_records as ar') + ->join('approval_instances as ai', 'ar.instance_id', '=', 'ai.id') + ->join('stock_orders as so', 'ai.biz_id', '=', 'so.id') + ->where('ar.approver_id', $request->user->uid) + ->where('ar.status', 'pending') + ->where('ai.flow_type', 'stock_orders') + ->where('ai.biz_type', 'stock_orders') + ->where('ai.status', 'processing') + ->whereNull('so.deleted_at') + ->select( + 'so.order_no', + 'ai.created_at as approval_created_at', + 'so.salesperson_snapshot as salesperson_name' + ) + ->get() + ->map(function($item) { + return [ + 'order_no' => $item->order_no, + 'approval_created_at' => date('Y-m-d H:i:s', strtotime($item->approval_created_at)), // 格式化时间 + 'salesperson_name' => $item->salesperson_name + ]; + }) + ->toArray(); + return $this->success($list); + } + + // 认领 + public function claim(Request $request) + { + $type = $request->get('type'); + if ($type == 'unclaimed') { + $list = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->where('receipt_id', 0) + ->select( + 'apply_no', + 'amount', + 'created_at' + ) + ->get() + ->map(function($item) { + return [ + 'apply_no' => $item->apply_no, + 'amount' => $item->amount, + 'created_at' => date('Y-m-d H:i:s', $item->created_at) + ]; + }) + ->toArray(); + } else { + $twentyFourHoursAgo = time() - (24 * 3600); + $list = Db::table('fin_payment_apply') + ->where('doc_user_id', $request->user->uid) + ->whereNotNull('submit_files') + ->whereJsonLength('submit_files', '>', 0) + ->where('receipt_id', '>', 0) + ->where('claimed_at', '<', $twentyFourHoursAgo) + ->select( + 'apply_no', + 'amount', + 'created_at' + ) + ->get() + ->map(function($item) { + return [ + 'apply_no' => $item->apply_no, + 'amount' => $item->amount, + 'created_at' => date('Y-m-d H:i:s', $item->created_at) + ]; + }) + ->toArray(); + } + return $this->success($list); + } +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index d6536c4..22b0862 100644 --- a/config/route.php +++ b/config/route.php @@ -459,6 +459,17 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\SysConfigController::class, 'update']); Route::any('/destroy', [app\admin\controller\SysConfigController::class, 'destroy']); }); + + // 仪表盘 + Route::group('/dashboard', function () { + // 内勤 + Route::group('/officeclerk', function () { + Route::any('/card', [app\admin\controller\dashboard\OfficeClerkController::class, 'card']); + Route::any('/curve', [app\admin\controller\dashboard\OfficeClerkController::class, 'curve']); + Route::any('/approval', [app\admin\controller\dashboard\OfficeClerkController::class, 'approval']); + Route::any('/claim', [app\admin\controller\dashboard\OfficeClerkController::class, 'claim']); + }); + }); }); From 15df6ad9a3ec5de4a5a98c1c68ab346ec104692f Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 14:58:29 +0800 Subject: [PATCH 46/74] =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=9C=AA=E8=AE=A4?= =?UTF-8?q?=E9=A2=86=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 1f1c731..52e3681 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -216,6 +216,9 @@ class FinReceiptService $query->whereNull('payment_apply_id'); } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { $query->whereNotNull('payment_apply_id'); + } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'timeout') { //超时未认领 + $query->whereNull('payment_apply_id'); + $query->where('created_at', '<' ,time() - 24*60*60); } if (isset($param['scene']) && $param['scene'] == 'list') { @@ -301,19 +304,4 @@ class FinReceiptService $updated = $this->logicUpdateBy($config, $data); return $this->postProcess(ucfirst($scene), $data); } - - /** - * 收款记录统计 - * @return bool|int - */ - public function statistics() - { - $finReceipt = FinReceipt::find($id); - if(!empty($finReceipt->received_at)){ - throw new BusinessException('该记录已将确认入账'); - } - $res = $this->logic->credit($id); - $this->afterServiceUpdate(['id'=>$id]); - return $res; - } } \ No newline at end of file From 499b0894b7fe374a0711416a80c1c6577c4fa06e Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 15:24:05 +0800 Subject: [PATCH 47/74] =?UTF-8?q?=E5=B7=B2=E8=AE=A4=E9=A2=86=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 52e3681..3cbc6d2 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -65,11 +65,11 @@ class FinReceiptService // 没有付款记录的收款记录 if (isset($p['payment_apply']) && $p['payment_apply'] == 'not') { //未认领 - $config['where']['payment_apply_id'] = ['null']; + $config['where']['payment_apply_id'] = 0; } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { //已认领 - $config['where']['payment_apply_id'] = ['not null']; + $config['where']['payment_apply_id'] = ['>', 0]; } elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'timeout') { //超时未认领 - $config['where']['payment_apply_id'] = ['not null']; + $config['where']['payment_apply_id'] = 0; $config['where']['created_at'] = ['<' ,time() - 24*60*60]; } @@ -213,11 +213,11 @@ class FinReceiptService // 没有付款记录的收款记录 if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') { - $query->whereNull('payment_apply_id'); + $query->where('payment_apply_id', 0); } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { - $query->whereNotNull('payment_apply_id'); + $query->where('payment_apply_id', '>', 0); } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'timeout') { //超时未认领 - $query->whereNull('payment_apply_id'); + $query->where('payment_apply_id', 0); $query->where('created_at', '<' ,time() - 24*60*60); } From f64324fba536356ac882f5ce9f77954ec5d752a8 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 16:29:54 +0800 Subject: [PATCH 48/74] =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=9C=AA=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E8=B4=A6=E8=B5=84=E6=96=99=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 10 ++++++++++ app/common/service/FinPaymentApplyService.php | 20 +++++++++++++++++-- app/common/service/FinReceiptService.php | 2 ++ app/process/Task.php | 4 +++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 3bf4b15..6f29595 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -70,6 +70,16 @@ class FinPaymentApplyController extends BaseController $data['enter_file_last'] = date('Y-m-d H:i:s', ($data['claimed_at']+86400)); //入账资料最后提交时间 $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); //认领时间 } + if (isset($data['id'])){ + $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); + $stock = []; + foreach ($finPaymentStock as $v) { + $stock[$v['pi_no']]['pi_no'] = $v['pi_no']; + $stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']]; + } + $data['stock'] = array_values($stock); + } + return $data; } diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index e5091fd..ce2bbfd 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -58,6 +58,11 @@ class FinPaymentApplyService $config['where']['account_id'] = $p['account_id']; } + // 入账资料超时 + if (isset($p['scene']) && $p['scene'] == 'file_timeout') { + $config['where']['claimed_at'] = ['between', [1, time()-24*60*60]]; + } + // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; @@ -156,7 +161,8 @@ class FinPaymentApplyService $param = $request->all(); $where = []; - + $orWhere = []; + // 汇款国家 if (isset($param['country_id']) && !empty($param['country_id'])) { $where[] = ['country_id', $param['country_id']]; @@ -166,6 +172,14 @@ class FinPaymentApplyService $where[] = ['account_id', $param['account_id']]; } + // 入账资料超时 + if (isset($param['scene']) && $param['scene'] == 'file_timeout') { + $where[] = ['claimed_at', '<', time()-24*60*60]; + $where[] = ['claimed_at', '>', 1]; + $orWhere[] = ['submit_files', '[]']; + $orWhere[] = ['submit_files', '']; + } + // 关键字 if (isset($param['keyword']) && $param['keyword']) { $k = '%' . $param['keyword'] . '%'; @@ -173,7 +187,9 @@ class FinPaymentApplyService } // 构建查询 - $query = $this->modelClass::where($where); + $query = $this->modelClass::where($where)->where(function($query) use ($orWhere) { + $query->orWhere($orWhere); + }); // 是否已关联收款记录的筛选 $correlation = $param['correlation']??''; diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 52e3681..be72fc9 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -4,6 +4,7 @@ namespace app\common\service; use app\common\logic\FinReceiptLogic; use app\common\model\FinPaymentApply; +use app\common\model\FinPaymentStock; use app\common\model\FinReceiptHis; use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; @@ -295,6 +296,7 @@ class FinReceiptService $data = $this->preProcess(ucfirst($scene), $data, $request); $config = $this->buildQueryConfig($request, $scene); FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time(), 'claimed_by' => $request->user->uid]); + FinPaymentStock::where('payment_apply_id', $payment_apply_id)->update(['receipt_id' => $id]); //折让金额 $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); diff --git a/app/process/Task.php b/app/process/Task.php index 47dbb93..7175244 100644 --- a/app/process/Task.php +++ b/app/process/Task.php @@ -55,7 +55,9 @@ class Task ['created_at', '>', time() - 60 * 60 * 48], ['created_at', '<', time() - 60 * 60 * 24], ]; - $payment = FinPaymentApply::where($where)->orWhere($orWhere)->orderBy('id', 'desc')->get(); + $payment = FinPaymentApply::where($where)->where(function($query) use ($orWhere) { + $query->orWhere($orWhere); + })->orderBy('id', 'desc')->get(); foreach ($payment as $item) { Log::info('fin_payment_apply submit_files ', [$item->toArray()]); $notice = [ From 9fbe77a3a95a66dc98db499c90f7500c95a6ff7e Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 16:42:42 +0800 Subject: [PATCH 49/74] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A4=E9=A2=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/OfficeClerkController.php | 85 +++++++++++-------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php index 2bd2bcc..6fa70ee 100644 --- a/app/admin/controller/dashboard/OfficeClerkController.php +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -120,44 +120,59 @@ class OfficeClerkController extends BaseController $type = $request->get('type'); if ($type == 'unclaimed') { $list = Db::table('fin_payment_apply') - ->where('doc_user_id', $request->user->uid) - ->where('receipt_id', 0) - ->select( - 'apply_no', - 'amount', - 'created_at' - ) - ->get() - ->map(function($item) { - return [ - 'apply_no' => $item->apply_no, - 'amount' => $item->amount, - 'created_at' => date('Y-m-d H:i:s', $item->created_at) - ]; - }) - ->toArray(); + ->join('sys_currency', 'fin_payment_apply.currency_id', '=', 'sys_currency.id') + ->where('fin_payment_apply.doc_user_id', $request->user->uid) + ->where('fin_payment_apply.receipt_id', 0) + ->get([ + 'fin_payment_apply.id', + 'fin_payment_apply.created_at', + 'fin_payment_apply.doc_user_id', + 'fin_payment_apply.payment_entity', + 'fin_payment_apply.payment_account', + 'fin_payment_apply.currency_id', + 'sys_currency.currency_name', + 'fin_payment_apply.amount', + 'fin_payment_apply.apply_no' + ]); + foreach ($list as $key => &$val) { + $val->created_at = date('Y-m-d H:i:s', $val->created_at); + } + unset($val); } else { $twentyFourHoursAgo = time() - (24 * 3600); $list = Db::table('fin_payment_apply') - ->where('doc_user_id', $request->user->uid) - ->whereNotNull('submit_files') - ->whereJsonLength('submit_files', '>', 0) - ->where('receipt_id', '>', 0) - ->where('claimed_at', '<', $twentyFourHoursAgo) - ->select( - 'apply_no', - 'amount', - 'created_at' - ) - ->get() - ->map(function($item) { - return [ - 'apply_no' => $item->apply_no, - 'amount' => $item->amount, - 'created_at' => date('Y-m-d H:i:s', $item->created_at) - ]; - }) - ->toArray(); + ->join('user', 'fin_payment_apply.doc_user_id', '=', 'user.id') + ->join('sys_currency', 'fin_payment_apply.currency_id', '=', 'sys_currency.id') + ->where('fin_payment_apply.doc_user_id', $request->user->uid) + ->whereNotNull('fin_payment_apply.submit_files') + ->whereJsonLength('fin_payment_apply.submit_files', '>', 0) + ->where('fin_payment_apply.receipt_id', '>', 0) + ->where('fin_payment_apply.claimed_at', '<', $twentyFourHoursAgo) + ->get([ + 'fin_payment_apply.id', + 'fin_payment_apply.created_at', + 'fin_payment_apply.doc_user_id', + 'user.name', + 'fin_payment_apply.payment_entity', + 'fin_payment_apply.payment_account', + 'fin_payment_apply.currency_id', + 'sys_currency.currency_name', + 'fin_payment_apply.amount', + 'fin_payment_apply.apply_no' + ]); + + foreach ($list as $key => &$val) { + $stockIds = Db::table('fin_payment_stock') + ->where('payment_apply_id', $val->id) + ->pluck('stock_id') + ->toArray(); + $val->order_no = Db::table('stock_orders') + ->whereIn('id', $stockIds) + ->pluck('order_no') + ->toArray(); + $val->created_at = date('Y-m-d H:i:s', $val->created_at); + } + unset($val); } return $this->success($list); } From 94e9d6eb7e8b294e1390fb9e409b8f5a8a2d946c Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 16:51:58 +0800 Subject: [PATCH 50/74] xg --- app/admin/controller/dashboard/OfficeClerkController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php index 6fa70ee..f1762c4 100644 --- a/app/admin/controller/dashboard/OfficeClerkController.php +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -39,8 +39,7 @@ class OfficeClerkController extends BaseController $twentyFourHoursAgo = time() - (24 * 3600); $timeout = Db::table('fin_payment_apply') ->where('doc_user_id', $request->user->uid) - ->whereNotNull('submit_files') - ->whereJsonLength('submit_files', '>', 0) + ->where('fin_payment_apply.submit_files', '[]') ->where('receipt_id', '>', 0) ->where('claimed_at', '<', $twentyFourHoursAgo) ->count('id'); @@ -144,8 +143,7 @@ class OfficeClerkController extends BaseController ->join('user', 'fin_payment_apply.doc_user_id', '=', 'user.id') ->join('sys_currency', 'fin_payment_apply.currency_id', '=', 'sys_currency.id') ->where('fin_payment_apply.doc_user_id', $request->user->uid) - ->whereNotNull('fin_payment_apply.submit_files') - ->whereJsonLength('fin_payment_apply.submit_files', '>', 0) + ->where('fin_payment_apply.submit_files', '[]') ->where('fin_payment_apply.receipt_id', '>', 0) ->where('fin_payment_apply.claimed_at', '<', $twentyFourHoursAgo) ->get([ From 659f6d486694ecdcbb1c5a94a64643a44392f42a Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 17:09:41 +0800 Subject: [PATCH 51/74] ts --- app/admin/controller/dashboard/OfficeClerkController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php index f1762c4..9bf30d8 100644 --- a/app/admin/controller/dashboard/OfficeClerkController.php +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -39,7 +39,7 @@ class OfficeClerkController extends BaseController $twentyFourHoursAgo = time() - (24 * 3600); $timeout = Db::table('fin_payment_apply') ->where('doc_user_id', $request->user->uid) - ->where('fin_payment_apply.submit_files', '[]') + ->where('fin_payment_apply.submit_files', '') ->where('receipt_id', '>', 0) ->where('claimed_at', '<', $twentyFourHoursAgo) ->count('id'); @@ -143,7 +143,7 @@ class OfficeClerkController extends BaseController ->join('user', 'fin_payment_apply.doc_user_id', '=', 'user.id') ->join('sys_currency', 'fin_payment_apply.currency_id', '=', 'sys_currency.id') ->where('fin_payment_apply.doc_user_id', $request->user->uid) - ->where('fin_payment_apply.submit_files', '[]') + ->where('fin_payment_apply.submit_files', '') ->where('fin_payment_apply.receipt_id', '>', 0) ->where('fin_payment_apply.claimed_at', '<', $twentyFourHoursAgo) ->get([ From a3819bcba7b4ba3ec47d6d143c84c07f7fb46513 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 17:21:10 +0800 Subject: [PATCH 52/74] =?UTF-8?q?=E5=85=A5=E8=B4=A6=E8=B5=84=E6=96=99?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E6=A0=BC=E5=BC=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 9 +++++++-- app/common/model/FinReceiptHis.php | 2 +- app/common/service/FinPaymentApplyService.php | 11 ++++++----- app/process/Task.php | 9 ++------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 6f29595..1db09d3 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -47,7 +47,7 @@ class FinPaymentApplyController extends BaseController if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; $OssService = new OssService(); - if (isset($data['submit_files'])){ + if (!empty($data['submit_files'])){ $data['submit_files'] = json_decode($data['submit_files'], true); foreach ($data['submit_files'] as $key => $value) { $data['submit_files'][$key] = [ @@ -56,6 +56,8 @@ class FinPaymentApplyController extends BaseController 'file_name' => $value['file_name'], ]; } + }else{ + $data['submit_files'] = []; } if (!empty($data['voucher_file'])) { $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); @@ -106,7 +108,7 @@ class FinPaymentApplyController extends BaseController if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; $OssService = new OssService(); - if (isset($data['submit_files'])){ + if (!empty($data['submit_files'])){ $data['submit_files'] = json_decode($data['submit_files'], true); foreach ($data['submit_files'] as $key => $value) { $data['submit_files'][$key] = [ @@ -115,7 +117,10 @@ class FinPaymentApplyController extends BaseController 'file_name' => $value['file_name'], ]; } + }else{ + $data['submit_files'] = []; } + if (!empty($data['voucher_file'])) { $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); } elseif (isset($data['voucher_file'])) { diff --git a/app/common/model/FinReceiptHis.php b/app/common/model/FinReceiptHis.php index 814b87f..8a036b3 100644 --- a/app/common/model/FinReceiptHis.php +++ b/app/common/model/FinReceiptHis.php @@ -40,7 +40,7 @@ class FinReceiptHis extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'receipt_id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'is_domestic_return', 'created_by', 'updated_by', 'created_at', 'updated_at']; + protected $fillable = ['id', 'receipt_id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'is_domestic_return', 'created_by', 'updated_by', 'claimed_by', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index ce2bbfd..f5f9ed3 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -90,6 +90,8 @@ class FinPaymentApplyService $data['submit_files'] = json_encode($data['submit_files']); redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); unset($data['stock']); + if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) + $data['submit_files'] = ''; return $data; } @@ -113,6 +115,8 @@ class FinPaymentApplyService public function beforeServiceUpdate($data, Request $request) { $data['submit_files'] = json_encode($data['submit_files']); + if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) + $data['submit_files'] = ''; return $data; } @@ -174,10 +178,9 @@ class FinPaymentApplyService // 入账资料超时 if (isset($param['scene']) && $param['scene'] == 'file_timeout') { + $where[] = ['submit_files', '']; $where[] = ['claimed_at', '<', time()-24*60*60]; $where[] = ['claimed_at', '>', 1]; - $orWhere[] = ['submit_files', '[]']; - $orWhere[] = ['submit_files', '']; } // 关键字 @@ -187,9 +190,7 @@ class FinPaymentApplyService } // 构建查询 - $query = $this->modelClass::where($where)->where(function($query) use ($orWhere) { - $query->orWhere($orWhere); - }); + $query = $this->modelClass::where($where); // 是否已关联收款记录的筛选 $correlation = $param['correlation']??''; diff --git a/app/process/Task.php b/app/process/Task.php index 7175244..cf526c6 100644 --- a/app/process/Task.php +++ b/app/process/Task.php @@ -46,18 +46,13 @@ class Task return; } Log::info('fin_payment_apply submit_files start', [time()]); - $orWhere = [ - ['submit_files', '=', '[]'], - ['submit_files', '=', ''], - ]; $where = [ + ['submit_files', '=', ''], ['warn', '<', 2], ['created_at', '>', time() - 60 * 60 * 48], ['created_at', '<', time() - 60 * 60 * 24], ]; - $payment = FinPaymentApply::where($where)->where(function($query) use ($orWhere) { - $query->orWhere($orWhere); - })->orderBy('id', 'desc')->get(); + $payment = FinPaymentApply::where($where)->orderBy('id', 'desc')->get(); foreach ($payment as $item) { Log::info('fin_payment_apply submit_files ', [$item->toArray()]); $notice = [ From 0110e393ce4a55468843c2bd8b0aeb9094f7ef0b Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 17:38:40 +0800 Subject: [PATCH 53/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E5=8D=95=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=A4=87=E8=B4=A7=E5=8D=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index f5f9ed3..69fb4ce 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -114,6 +114,7 @@ class FinPaymentApplyService public function beforeServiceUpdate($data, Request $request) { + unset($data['stock']); $data['submit_files'] = json_encode($data['submit_files']); if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) $data['submit_files'] = ''; From d73728128366ecf4f9d747fd05a4615271874a03 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 17:54:38 +0800 Subject: [PATCH 54/74] =?UTF-8?q?=E6=B0=B4=E5=8D=95=E5=A4=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 33 ++++++++++++++----- .../controller/FinReceiptController.php | 33 +++++++++++++++---- app/common/service/FinPaymentApplyService.php | 6 ++++ app/common/service/FinReceiptService.php | 6 +++- 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 1db09d3..0939646 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -59,11 +59,20 @@ class FinPaymentApplyController extends BaseController }else{ $data['submit_files'] = []; } - if (!empty($data['voucher_file'])) { - $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); - } elseif (isset($data['voucher_file'])) { - $data['voucher_file_full'] = ''; + + if (!empty($data['voucher_file'])){ + $data['voucher_file'] = json_decode($data['voucher_file'], true); + foreach ($data['voucher_file'] as $key => $value) { + $data['voucher_file'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + }else{ + $data['voucher_file'] = []; } + if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) @@ -121,11 +130,19 @@ class FinPaymentApplyController extends BaseController $data['submit_files'] = []; } - if (!empty($data['voucher_file'])) { - $data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']); - } elseif (isset($data['voucher_file'])) { - $data['voucher_file_full'] = ''; + if (!empty($data['voucher_file'])){ + $data['voucher_file'] = json_decode($data['voucher_file'], true); + foreach ($data['voucher_file'] as $key => $value) { + $data['voucher_file'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + }else{ + $data['voucher_file'] = []; } + if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 4e9c574..cade259 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -97,10 +97,19 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; + + $OssService = new OssService(); if (!empty($data['fx_receipt_file'])){ - $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); - }elseif (isset($data['fx_receipt_file'])){ - $data['fx_receipt_file_full'] = ''; + $data['fx_receipt_file'] = json_decode($data['fx_receipt_file'], true); + foreach ($data['fx_receipt_file'] as $key => $value) { + $data['fx_receipt_file'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + }else{ + $data['fx_receipt_file'] = []; } return $data; } @@ -129,12 +138,22 @@ class FinReceiptController extends BaseController $data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??''; if (isset($data['currency_id'])) //付款币种 $data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??''; - if (!empty($data['fx_receipt_file'])) { - $data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']); - } elseif (isset($data['fx_receipt_file'])) { - $data['fx_receipt_file_full'] = ''; + + $OssService = new OssService(); + if (!empty($data['fx_receipt_file'])){ + $data['fx_receipt_file'] = json_decode($data['fx_receipt_file'], true); + foreach ($data['fx_receipt_file'] as $key => $value) { + $data['fx_receipt_file'][$key] = [ + 'file_src' => $value['file_src'], + 'file_full' => $OssService->generatePrivateUrl($value['file_src']), + 'file_name' => $value['file_name'], + ]; + } + }else{ + $data['fx_receipt_file'] = []; } + //查询关联的付款记录 if (!empty($data['payment_apply_id'])) { $paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first(); if(!$paymentApply) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 69fb4ce..0f6bec7 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -87,9 +87,12 @@ class FinPaymentApplyService { $data['apply_no'] = $this->generateUniqueApplyNo(); $data['doc_user_id'] = $request->user->uid; + $data['voucher_file'] = json_encode($data['voucher_file']); $data['submit_files'] = json_encode($data['submit_files']); redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); unset($data['stock']); + if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' ) + $data['voucher_file'] = ''; if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) $data['submit_files'] = ''; return $data; @@ -118,6 +121,9 @@ class FinPaymentApplyService $data['submit_files'] = json_encode($data['submit_files']); if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) $data['submit_files'] = ''; + $data['voucher_file'] = json_encode($data['voucher_file']); + if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' ) + $data['voucher_file'] = ''; return $data; } diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index be72fc9..f55ac9a 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -114,6 +114,8 @@ class FinReceiptService $data['arrived_at'] = strtotime( $data['arrived_at']); $data['created_by'] = $request->user->uid; $data['updated_by'] = $request->user->uid; + if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) + $data['fx_receipt_file'] = ''; return $data; } @@ -132,7 +134,9 @@ class FinReceiptService $data['arrived_at'] = strtotime($data['arrived_at']); if(isset($data['received_at'])) $data['received_at'] = strtotime($data['received_at']); - + + if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) + $data['fx_receipt_file'] = ''; return $data; } public function afterServiceUpdate($res) From e9636513ec8c24ed17fd96ae13adc26b1690a94e Mon Sep 17 00:00:00 2001 From: mzl Date: Thu, 30 Oct 2025 17:55:08 +0800 Subject: [PATCH 55/74] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/AuthLogic.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/common/logic/AuthLogic.php b/app/common/logic/AuthLogic.php index ee449b9..9abe5e1 100644 --- a/app/common/logic/AuthLogic.php +++ b/app/common/logic/AuthLogic.php @@ -172,7 +172,7 @@ class AuthLogic $payload = $this->buildJwtPayload($user, $system); $token = $this->generateAccessToken($payload); $refreshToken = $this->generateRefreshToken($user->id, $data['system_code']); - $homeUrl = $this->getHome($system->id); + $homeUrl = $this->getHome($system->id, $payload); // 记录 token 到 Redis 和 MySQL $this->recordUserToken($user->id, $token, $data['system_code']); @@ -537,8 +537,22 @@ class AuthLogic } - public function getHome($systemId) + public function getHome($systemId, $data) { + // 2025.10.30 临时处理 ====== start + if ($systemId == 1) { + if (in_array(1, $data['role_ids'])) { + return '/dashboard/console'; + } + if (count($data['role_ids']) == 1 && in_array(5, $data['role_ids'])) { + return '/dashboard/console/backoffice'; + } + if (count($data['role_ids']) == 1 && in_array(6, $data['role_ids'])) { + return '/dashboard/console/finance'; + } + } + // 2025.10.30 临时处理 ====== end + $info = Resource::where('system_id', $systemId) ->where('is_home', 1) ->first(); From ad67a88d0f1062760ceb8332702d5e96d4748c0a Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 18:11:50 +0800 Subject: [PATCH 56/74] =?UTF-8?q?=E6=B0=B4=E5=8D=95=E5=A4=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index f55ac9a..676ab0f 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -114,6 +114,7 @@ class FinReceiptService $data['arrived_at'] = strtotime( $data['arrived_at']); $data['created_by'] = $request->user->uid; $data['updated_by'] = $request->user->uid; + $data['fx_receipt_file'] = json_encode($data['fx_receipt_file']); if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) $data['fx_receipt_file'] = ''; return $data; @@ -135,6 +136,7 @@ class FinReceiptService if(isset($data['received_at'])) $data['received_at'] = strtotime($data['received_at']); + $data['fx_receipt_file'] = json_encode($data['fx_receipt_file']); if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) $data['fx_receipt_file'] = ''; return $data; From 72fa638cf56877a56bc484af1970b8ff28838df1 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 18:37:40 +0800 Subject: [PATCH 57/74] =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 0f6bec7..78d0d37 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -233,12 +233,12 @@ class FinPaymentApplyService } if (!empty($remitter)) { - $similarityOrder[] = "CASE WHEN remitter = {$remitter} THEN 0 ELSE 1 END"; + $similarityOrder[] = "CASE WHEN remitter = '{$remitter}' THEN 0 ELSE 1 END"; } if (!empty($amount)) { $amount = (float)$amount; - $similarityOrder[] = "ABS(amount - {$amount}) ASC"; + $similarityOrder[] = "ABS(amount - {$amount})"; $similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 THEN 0 ELSE 1 END"; } @@ -252,9 +252,9 @@ class FinPaymentApplyService END ASC, "; } - $orderByClause .= "CASE - WHEN created_at > {$sevenDaysAgo} THEN id - ELSE 999999 + $orderByClause .= "CASE + WHEN created_at > {$sevenDaysAgo} THEN id + ELSE 999999 END DESC, "; $orderByClause .= "id DESC"; From 206eff87e2b2a73ac5474371eef0360c8df8e224 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 30 Oct 2025 18:49:28 +0800 Subject: [PATCH 58/74] =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 8 ++++---- app/common/service/FinReceiptService.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 78d0d37..e55b6a7 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -91,9 +91,9 @@ class FinPaymentApplyService $data['submit_files'] = json_encode($data['submit_files']); redis::set('stock_' . $data['doc_user_id'], json_encode($request->post('stock')), 'EX', 30); unset($data['stock']); - if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' ) + if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' || $data['voucher_file'] == '""') $data['voucher_file'] = ''; - if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) + if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' || $data['submit_files'] == '""') $data['submit_files'] = ''; return $data; } @@ -119,10 +119,10 @@ class FinPaymentApplyService { unset($data['stock']); $data['submit_files'] = json_encode($data['submit_files']); - if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' ) + if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' || $data['submit_files'] == '""') $data['submit_files'] = ''; $data['voucher_file'] = json_encode($data['voucher_file']); - if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' ) + if($data['voucher_file'] == '[]' || $data['voucher_file'] == '{}' || $data['voucher_file'] == '""') $data['voucher_file'] = ''; return $data; } diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 676ab0f..775d77d 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -115,7 +115,7 @@ class FinReceiptService $data['created_by'] = $request->user->uid; $data['updated_by'] = $request->user->uid; $data['fx_receipt_file'] = json_encode($data['fx_receipt_file']); - if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) + if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' || $data['fx_receipt_file'] == '""') $data['fx_receipt_file'] = ''; return $data; } @@ -137,7 +137,7 @@ class FinReceiptService $data['received_at'] = strtotime($data['received_at']); $data['fx_receipt_file'] = json_encode($data['fx_receipt_file']); - if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' ) + if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' || $data['fx_receipt_file'] == '""') $data['fx_receipt_file'] = ''; return $data; } From 24805257c717c98916deb032c05be21b73fbf421 Mon Sep 17 00:00:00 2001 From: mzl Date: Fri, 31 Oct 2025 09:46:57 +0800 Subject: [PATCH 59/74] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=86=85=E5=8B=A4?= =?UTF-8?q?=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=9B=B2=E7=BA=BF=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/OfficeClerkController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/dashboard/OfficeClerkController.php b/app/admin/controller/dashboard/OfficeClerkController.php index 9bf30d8..463a874 100644 --- a/app/admin/controller/dashboard/OfficeClerkController.php +++ b/app/admin/controller/dashboard/OfficeClerkController.php @@ -54,13 +54,18 @@ class OfficeClerkController extends BaseController } // 曲线 - public function curve() + public function curve(Request $request) { - $groupIds = Db::table('user_group') - ->where('scenario_code', 'stock_orders') - ->pluck('id'); + $groupId = Db::table('user_group_members as ugm') + ->join('user_group as ug', 'ugm.group_id', '=', 'ug.id') + ->where('ugm.user_id', $request->user->uid) + ->where('ugm.is_leader', 1) + ->where('ugm.status', 1) + ->where('ug.scenario_code', 'stock_orders') + ->where('ug.status', 1) + ->value('ug.id'); $userIds = Db::table('user_group_members') - ->whereIn('group_id', $groupIds) + ->where('group_id', $groupId) ->pluck('user_id'); $list = Db::table('stock_orders') ->join('user', 'stock_orders.salesperson_id', '=', 'user.id') From 43fe263df1e441047237cded74ea391f7e1b0eb5 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Fri, 31 Oct 2025 10:17:41 +0800 Subject: [PATCH 60/74] =?UTF-8?q?=E5=A4=87=E8=B4=A7=E5=8D=95=E7=BC=96?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinPaymentApplyController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 0939646..d58c1d6 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -5,6 +5,7 @@ namespace app\common\controller; use app\common\controller\BaseController; use app\common\model\Country; use app\common\model\FinPaymentStock; +use app\common\model\StockOrders; use app\common\model\SysAccount; use app\common\model\SysCurrency; use app\common\model\SysDictItem; @@ -84,11 +85,15 @@ class FinPaymentApplyController extends BaseController if (isset($data['id'])){ $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); $stock = []; + $stock_order_no = []; foreach ($finPaymentStock as $v) { $stock[$v['pi_no']]['pi_no'] = $v['pi_no']; $stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']]; + $stockOrders = StockOrders::where('id', $v['stock_id'])->first(); + $stock_order_no[] = $stockOrders['order_no']; } $data['stock'] = array_values($stock); + $data['stock_order_no'] = $stock_order_no; } return $data; From 29ba35f9b6309c04c9c2beac1420d71963e64d45 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Fri, 31 Oct 2025 16:22:28 +0800 Subject: [PATCH 61/74] =?UTF-8?q?=E6=94=B6=E4=BB=98=E6=AC=BE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/FinStatisticsController.php | 83 +++++++++++++++++-- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php index 95cf09d..59965da 100644 --- a/app/admin/controller/dashboard/FinStatisticsController.php +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -3,7 +3,9 @@ namespace app\admin\controller\dashboard; use app\common\controller\BaseController; +use app\common\model\FinPaymentApply; use app\common\model\FinReceipt; +use app\common\model\SysCurrency; use support\Request; class FinStatisticsController extends BaseController @@ -16,33 +18,100 @@ class FinStatisticsController extends BaseController public function statistics(Request $request) { try { + $currency = SysCurrency::where('status',1)->get(); $query = FinReceipt::where('payment_apply_id','>',0); $result = []; //已认领数量 $result['claimed_num'] = $query->count(); //已认领金额 - $result['claimed_amount'] = $query->sum('amount'); +// $result['claimed_amount'] = $query->sum('amount'); + $result['claimed_amount'] = array_values($this->receiptStatisticsSum($query, $currency)); //各币种的已认领金额 + $result['claimed_amount_sum'] =$this->amountSum($result['claimed_amount']); //已认领的人民币总金额 //未入账数量 - $result['unreceived_num'] = FinReceipt::whereNull('received_at')->count(); + $query2 = FinReceipt::whereNull('received_at'); + $result['unreceived_num'] = $query2->count(); //未入账金额 - $result['unreceived_amount'] = FinReceipt::whereNull('received_at')->sum('amount'); +// $result['unreceived_amount'] = $query2->sum('amount'); + $result['unreceived_amount'] = array_values($this->receiptStatisticsSum($query2, $currency)); //各币种的未入账金额 + $result['unreceived_amount_sum'] = $this->amountSum($result['unreceived_amount']); //未入账的已认领的人民币总金额 - $query = FinReceipt::whereNull('payment_apply_id'); + $query3 = FinReceipt::whereNull('payment_apply_id'); //未认领数量 - $result['unclaimed_num'] = $query->count(); + $result['unclaimed_num'] = $query3->count(); //未认领金额 - $result['unclaimed_amount'] = $query->sum('amount'); +// $result['unclaimed_amount'] = $query3->sum('amount'); + $result['unclaimed_amount'] = $this->receiptStatisticsSum($query3, $currency); //各币种的未认领金额 + $result['unclaimed_amount_sum'] = $this->amountSum($result['unclaimed_amount']); //未认领的已认领的人民币总金额 //已超时未认领数量 - $result['timeout'] = $query->where('created_at','<',time()-24*3600)->count(); + $query4 = $query3->where('created_at','<',time()-24*3600); + $result['timeout'] = $query4->count(); + //在途资金 + //1、没有认领的付款资金 + $query5 = FinPaymentApply::where('receipt_id', '=', 0); + $unclaimed_payment_amount = $this->receiptStatisticsSum($query5, $currency); + foreach ($unclaimed_payment_amount as $key => &$value) { + $value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount']; + } + $result['unclaimed_payment_amount'] = array_values($result['unclaimed_payment_amount']); + $result['unclaimed_payment_amount_sum'] = $this->amountSum($result['unclaimed_payment_amount']); + //在途资金 = 没有认领的付款资金-未认领的收款资金 + $result['intransit_amount'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum']; + + //在途数量 = 没有认领的付款数量-未认领的收款数量 + $result['intransit_count'] = count($result['unclaimed_payment_amount']) - count($result['unclaimed_amount']); + + //未认领金额重新组织索引 + $result['unclaimed_amount'] = array_values($result['unclaimed_amount']); return $this->success($result); } catch (\Throwable $e) { return $this->error($e->getMessage()); } } + /** + * 根据不同条件查询收款金额 + * @param $query + * @param $currency + * @return array + */ + public function receiptStatisticsSum($query, $currency) + { + $amount = []; + foreach ($currency as $k => $v) { + $amount[$v->currency_code] = [ + 'currency_code' => $v->currency_code, + 'exchange_rate' => $v->exchange_rate, + 'amount' => $query->where('currency_id',$v->id)->sum('amount'), + ]; + } + return $amount; + } + + /** + * 不同币种汇率换算之后求和 + * @param $query + * @param $currency + */ + public function amountSum($amount) + { + $amountSum = 0; + foreach ($amount as $v) { + // 转换为整数(乘以100避免浮点数问题) + $v['amount'] = (int) round($v['amount'] * 100); + $v['exchange_rate'] = (int) round($v['exchange_rate'] * 10000); // 汇率保留4位小数 + $amountSum += $v['amount'] * $v['exchange_rate']; + } + + // 转换回金额(除以1000000,因为汇率乘了10000) + $result = $amountSum / 1000000; + + // 四舍五入到2位小数 + return round($amountSum, 2); + } + } \ No newline at end of file From f7faf798091967fdbbc84faf48a970ae1a75c447 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 08:56:48 +0800 Subject: [PATCH 62/74] =?UTF-8?q?=E5=BE=85=E5=85=A5=E8=B4=A6=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/FinPaymentApply.php | 9 +++++++++ app/common/model/FinReceipt.php | 18 +++++++++++++++++- app/common/service/FinPaymentApplyService.php | 7 +++++++ app/common/service/FinReceiptService.php | 17 ++++++++++++----- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index 0f4d157..8dbe4f9 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -62,4 +62,13 @@ class FinPaymentApply extends Model { return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); } + + /** + * 查询 submit_files 不为空的记录 + */ + public function scopeWithNonEmptyFiles($query) + { + return $query->whereNotNull('submit_files') + ->whereRaw('JSON_LENGTH(submit_files) > 0'); + } } \ No newline at end of file diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index 7347be0..88d3090 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -40,7 +40,7 @@ class FinReceipt extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'fx_receipt_file_name', 'is_domestic_return', 'created_by', 'updated_by', 'created_at', 'updated_at']; + protected $fillable = ['id', 'receipt_no', 'payment_apply_id', 'country_id', 'remitter', 'account_id', 'currency_id', 'amount', 'discount_amount', 'total_amount_cny', 'exchange_rate', 'arrived_at', 'received_at', 'voucher_no', 'fx_receipt_file', 'fx_receipt_file_name', 'is_domestic_return', 'submit_files', 'created_by', 'updated_by', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 @@ -62,4 +62,20 @@ class FinReceipt extends Model { return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id'); } + + /** + * 关联付款申请 + */ +// public function finPaymentApply() +// { +// return $this->hasOne(FinPaymentApply::class, 'receipt_id', 'id'); +// } + + /** + * 关联付款申请表 + */ + public function paymentApply() + { + return $this->belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id'); + } } \ No newline at end of file diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index e55b6a7..e659a86 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -127,6 +127,13 @@ class FinPaymentApplyService return $data; } + + public function afterServiceUpdate($res, Request $request) + { + if($res->submit_files != '' && $res->receipt_id != 0) + FinReceipt::where('id', $res->receipt_id)->update(['submit_files' => $res->submit_files]); + } + /** * 生成唯一的付款申请编码 * 格式:PA + 日期 + 6位字母数字组合 diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 775d77d..6dd69a7 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -218,17 +218,22 @@ class FinReceiptService // 构建查询 $query = $this->modelClass::where($where); - // 没有付款记录的收款记录 + // 收款记录绑定情况 if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') { - $query->whereNull('payment_apply_id'); + $query->where('payment_apply_id', '0'); } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { - $query->whereNotNull('payment_apply_id'); + $query->where('payment_apply_id', '>' ,'0'); } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'timeout') { //超时未认领 - $query->whereNull('payment_apply_id'); + $query->where('payment_apply_id', '0'); $query->where('created_at', '<' ,time() - 24*60*60); } - if (isset($param['scene']) && $param['scene'] == 'list') { + if($param['scene'] == 'pending'){ //待入账列表 + $query->where('payment_apply_id', '>' ,'0'); + $query->where('submit_files','!=',''); + } + + if (isset($param['scene']) && ($param['scene'] == 'list' ||$param['scene'] == 'pending')) { return $query->paginate($limit, ['*'], 'page', $page); } @@ -308,8 +313,10 @@ class FinReceiptService $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); $receipt = FinReceipt::find($id); $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; + $data['submit_files'] = $payment->submit_files ?? ''; $updated = $this->logicUpdateBy($config, $data); return $this->postProcess(ucfirst($scene), $data); } + } \ No newline at end of file From 139d3509f44973f8468fe7bf28b4f4d4362c0047 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 09:45:41 +0800 Subject: [PATCH 63/74] =?UTF-8?q?=E4=BD=9C=E5=BA=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 16 ++++++++++++++++ app/common/model/FinReceipt.php | 2 ++ app/common/service/FinReceiptService.php | 13 +++++++++++++ config/route.php | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index cade259..aeca0eb 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -41,6 +41,22 @@ class FinReceiptController extends BaseController } } + /** + * 确认入账 + * @param Request $request + * @return \support\Response + */ + public function delete(Request $request) + { + try { + $id = $request->input('id'); + $raw = $this->service->delete($id); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + public function show(Request $request) { try { diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index 88d3090..099697f 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -2,10 +2,12 @@ namespace app\common\model; +use Illuminate\Database\Eloquent\SoftDeletes; use support\Model; class FinReceipt extends Model { + use SoftDeletes; /** * The connection name for the model. * diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 6dd69a7..5b04368 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -233,6 +233,12 @@ class FinReceiptService $query->where('submit_files','!=',''); } + if($param['scene'] == 'delete'){ //查询作废数据 + $query->onlyTrashed(); + }elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据 + $query->withTrashed(); + } + if (isset($param['scene']) && ($param['scene'] == 'list' ||$param['scene'] == 'pending')) { return $query->paginate($limit, ['*'], 'page', $page); } @@ -293,6 +299,13 @@ class FinReceiptService return $res; } + + public function delete($id) + { + $res = FinReceipt::where('id', $id)->delete(); + return $res; + } + /** * 更新:绑定收款记录,计算折让金额 * @param Request $request diff --git a/config/route.php b/config/route.php index ec7d821..e313549 100644 --- a/config/route.php +++ b/config/route.php @@ -359,8 +359,8 @@ Route::group('/admin', function () { Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']); - Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); + Route::any('/delete', [app\common\controller\FinReceiptController::class, 'delete']); }); // 收款记录历史 Route::group('/receipt/his', function () { From 18eb3e7c5dd01ce2934395b9ee606d935279f854 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 11:32:10 +0800 Subject: [PATCH 64/74] =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/dashboard/FinStatisticsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php index 59965da..3a66c8c 100644 --- a/app/admin/controller/dashboard/FinStatisticsController.php +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -57,7 +57,7 @@ class FinStatisticsController extends BaseController foreach ($unclaimed_payment_amount as $key => &$value) { $value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount']; } - $result['unclaimed_payment_amount'] = array_values($result['unclaimed_payment_amount']); + $result['unclaimed_payment_amount'] = array_values($unclaimed_payment_amount); $result['unclaimed_payment_amount_sum'] = $this->amountSum($result['unclaimed_payment_amount']); //在途资金 = 没有认领的付款资金-未认领的收款资金 $result['intransit_amount'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum']; From 6493bdebb115a3da14dd9f7c0a23267c44d782f9 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 11:34:49 +0800 Subject: [PATCH 65/74] =?UTF-8?q?=E5=BE=85=E5=85=A5=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinReceiptService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 062d3ee..b93b074 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -228,14 +228,14 @@ class FinReceiptService $query->where('created_at', '<' ,time() - 24*60*60); } - if($param['scene'] == 'pending'){ //待入账列表 + if(isset($param['scene']) && $param['scene'] == 'pending'){ //待入账列表 $query->where('payment_apply_id', '>' ,'0'); $query->where('submit_files','!=',''); } - if($param['scene'] == 'delete'){ //查询作废数据 + if(isset($param['scene']) && $param['scene'] == 'delete'){ //查询作废数据 $query->onlyTrashed(); - }elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据 + }elseif (isset($param['scene']) && $param['scene'] == 'all'){ //查询包含作废数据的全量数据 $query->withTrashed(); } From 74ac8941ea0717d01b321570693cd3e098b2e522 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 13:20:33 +0800 Subject: [PATCH 66/74] =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/FinStatisticsController.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/admin/controller/dashboard/FinStatisticsController.php b/app/admin/controller/dashboard/FinStatisticsController.php index 3a66c8c..6901082 100644 --- a/app/admin/controller/dashboard/FinStatisticsController.php +++ b/app/admin/controller/dashboard/FinStatisticsController.php @@ -37,7 +37,17 @@ class FinStatisticsController extends BaseController $result['unreceived_amount'] = array_values($this->receiptStatisticsSum($query2, $currency)); //各币种的未入账金额 $result['unreceived_amount_sum'] = $this->amountSum($result['unreceived_amount']); //未入账的已认领的人民币总金额 - $query3 = FinReceipt::whereNull('payment_apply_id'); + //今日入账 + $query6 = FinReceipt::where('received_at','>',strtotime(date("Y-m-d"))); + //今日入账数量 + $result['received_num'] = $query6->count(); + //未入账金额 +// $result['unreceived_amount'] = $query2->sum('amount'); + $result['received_amount'] = array_values($this->receiptStatisticsSum($query6, $currency)); //各币种的未入账金额 + $result['received_amount_sum'] = $this->amountSum($result['unreceived_amount']); //未入账的已认领的人民币总金额 + + + $query3 = FinReceipt::where('payment_apply_id',0); //未认领数量 $result['unclaimed_num'] = $query3->count(); @@ -57,13 +67,20 @@ class FinStatisticsController extends BaseController foreach ($unclaimed_payment_amount as $key => &$value) { $value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount']; } + $result['unclaimed_payment_num'] = $query5->count(); $result['unclaimed_payment_amount'] = array_values($unclaimed_payment_amount); $result['unclaimed_payment_amount_sum'] = $this->amountSum($result['unclaimed_payment_amount']); //在途资金 = 没有认领的付款资金-未认领的收款资金 - $result['intransit_amount'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum']; - + $result['intransit_amount_sum'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum']; + $intransit_amount_amount = []; + //在途资金各币种明细 + foreach ($unclaimed_payment_amount as $key => $value) { + $value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount']; + $intransit_amount_amount[] = $value; + } + $result['intransit_amount_amount'] = $intransit_amount_amount; //在途数量 = 没有认领的付款数量-未认领的收款数量 - $result['intransit_count'] = count($result['unclaimed_payment_amount']) - count($result['unclaimed_amount']); + $result['intransit_count'] = $result['unclaimed_payment_num'] - $result['unclaimed_num']; //未认领金额重新组织索引 $result['unclaimed_amount'] = array_values($result['unclaimed_amount']); From 1094bc406f093040c3ab5a0e039fbf3390b7b0cc Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 13:22:45 +0800 Subject: [PATCH 67/74] =?UTF-8?q?Revert=20"=E4=BD=9C=E5=BA=9F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 139d3509f44973f8468fe7bf28b4f4d4362c0047. --- app/common/controller/FinReceiptController.php | 16 ---------------- app/common/model/FinReceipt.php | 2 -- app/common/service/FinReceiptService.php | 13 ------------- config/route.php | 2 +- 4 files changed, 1 insertion(+), 32 deletions(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index aeca0eb..cade259 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -41,22 +41,6 @@ class FinReceiptController extends BaseController } } - /** - * 确认入账 - * @param Request $request - * @return \support\Response - */ - public function delete(Request $request) - { - try { - $id = $request->input('id'); - $raw = $this->service->delete($id); - return $this->success($raw); - } catch (\Throwable $e) { - return $this->error($e->getMessage()); - } - } - public function show(Request $request) { try { diff --git a/app/common/model/FinReceipt.php b/app/common/model/FinReceipt.php index 099697f..88d3090 100644 --- a/app/common/model/FinReceipt.php +++ b/app/common/model/FinReceipt.php @@ -2,12 +2,10 @@ namespace app\common\model; -use Illuminate\Database\Eloquent\SoftDeletes; use support\Model; class FinReceipt extends Model { - use SoftDeletes; /** * The connection name for the model. * diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 5b04368..6dd69a7 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -233,12 +233,6 @@ class FinReceiptService $query->where('submit_files','!=',''); } - if($param['scene'] == 'delete'){ //查询作废数据 - $query->onlyTrashed(); - }elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据 - $query->withTrashed(); - } - if (isset($param['scene']) && ($param['scene'] == 'list' ||$param['scene'] == 'pending')) { return $query->paginate($limit, ['*'], 'page', $page); } @@ -299,13 +293,6 @@ class FinReceiptService return $res; } - - public function delete($id) - { - $res = FinReceipt::where('id', $id)->delete(); - return $res; - } - /** * 更新:绑定收款记录,计算折让金额 * @param Request $request diff --git a/config/route.php b/config/route.php index e313549..ec7d821 100644 --- a/config/route.php +++ b/config/route.php @@ -359,8 +359,8 @@ Route::group('/admin', function () { Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']); + Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); - Route::any('/delete', [app\common\controller\FinReceiptController::class, 'delete']); }); // 收款记录历史 Route::group('/receipt/his', function () { From 8674063e6e0a8254781ce1a26f8383310fedb291 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 13:36:18 +0800 Subject: [PATCH 68/74] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=BD=9C=E5=BA=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FinPaymentApplyController.php | 16 ++++++++++++++++ app/common/model/FinPaymentApply.php | 4 +++- app/common/service/FinPaymentApplyService.php | 13 +++++++++++++ config/route.php | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index d58c1d6..98c49c2 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -162,4 +162,20 @@ class FinPaymentApplyController extends BaseController $data['stock'] = array_values($stock); return $data; } + + /** + * 作废 + * @param Request $request + * @return \support\Response + */ + public function delete(Request $request) + { + try { + $id = $request->input('id'); + $raw = $this->service->delete($id); + return $this->success($raw); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index 8dbe4f9..c81ac0a 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -2,10 +2,12 @@ namespace app\common\model; +use Illuminate\Database\Eloquent\SoftDeletes; use support\Model; class FinPaymentApply extends Model { + use SoftDeletes; /** * The connection name for the model. * @@ -40,7 +42,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'created_at', 'updated_at', 'claimed_by',]; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'created_at', 'updated_at', 'deleted_at', 'claimed_by', 'created_by',]; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index e659a86..4567461 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -214,6 +214,12 @@ class FinPaymentApplyService $query->whereDoesntHave('receipt'); } + if($param['scene'] == 'delete'){ //查询作废数据 + $query->onlyTrashed(); + }elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据 + $query->withTrashed(); + } + if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) { return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page); } @@ -271,4 +277,11 @@ class FinPaymentApplyService return $query->paginate($limit, ['*'], 'page', $page); } + public function delete($id) + { + $res = FinPaymentApply::where('id', $id)->delete(); + return $res; + } + + } \ No newline at end of file diff --git a/config/route.php b/config/route.php index ec7d821..c390d7a 100644 --- a/config/route.php +++ b/config/route.php @@ -378,7 +378,7 @@ Route::group('/admin', function () { Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']); Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']); Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']); - Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']); + Route::any('/delete', [app\common\controller\FinPaymentApplyController::class, 'delete']); }); // 系统配置 From 4dbd72acce839f711b70f8a8dad60cff0014dcb4 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 14:02:15 +0800 Subject: [PATCH 69/74] =?UTF-8?q?=E5=BE=85=E5=85=A5=E8=B4=A6=E4=B8=8E?= =?UTF-8?q?=E5=85=A5=E8=B4=A6=E5=AE=9E=E9=99=85=E6=B1=87=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 7 ++++++- app/common/service/FinReceiptService.php | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 4567461..be467e5 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -214,13 +214,18 @@ class FinPaymentApplyService $query->whereDoesntHave('receipt'); } + if(isset($param['scene']) && $param['scene'] == 'pending'){ //待入账列表 + $query->where('receipt_id', '>' ,'0'); + $query->where('submit_files','!=',''); + } + if($param['scene'] == 'delete'){ //查询作废数据 $query->onlyTrashed(); }elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据 $query->withTrashed(); } - if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) { + if ((isset($param['scene']) && ($param['scene'] == 'list' || $param['scene'] == 'pending'))|| empty($param['receipt_id']) ) { return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page); } diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 6dd69a7..37b9c94 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -303,6 +303,11 @@ class FinReceiptService public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') { $payment_apply_id = $request->input('payment_apply_id'); + $exchange_rate = $request->input('exchange_rate'); + if(empty($exchange_rate) || !is_numeric($exchange_rate)){ + throw new BusinessException('请输入汇率'); + } + $id = $request->input('id'); $data = $this->preProcess(ucfirst($scene), $data, $request); $config = $this->buildQueryConfig($request, $scene); @@ -314,6 +319,8 @@ class FinReceiptService $receipt = FinReceipt::find($id); $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; $data['submit_files'] = $payment->submit_files ?? ''; + $data['exchange_rate'] = $exchange_rate; + $data['total_amount_cny'] = round($data['amount']*$exchange_rate,2); $updated = $this->logicUpdateBy($config, $data); return $this->postProcess(ucfirst($scene), $data); From f1d5fae122bdeb66a7ed3db0439c91ac0eccab8b Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 14:13:55 +0800 Subject: [PATCH 70/74] =?UTF-8?q?=E5=85=A5=E8=B4=A6=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=B1=87=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 6 +++++- app/common/logic/FinReceiptLogic.php | 4 ++-- app/common/service/FinReceiptService.php | 16 ++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index cade259..f0e0626 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -34,7 +34,11 @@ class FinReceiptController extends BaseController { try { $id = $request->input('id'); - $raw = $this->service->credit($id); + $exchange_rate = $request->input('exchange_rate'); + if(empty($exchange_rate) || !is_numeric($exchange_rate)){ + return $this->error('请输入汇率'); + } + $raw = $this->service->credit($id,$exchange_rate); return $this->success($raw); } catch (\Throwable $e) { return $this->error($e->getMessage()); diff --git a/app/common/logic/FinReceiptLogic.php b/app/common/logic/FinReceiptLogic.php index 62db50f..622663b 100644 --- a/app/common/logic/FinReceiptLogic.php +++ b/app/common/logic/FinReceiptLogic.php @@ -14,8 +14,8 @@ class FinReceiptLogic */ protected string $modelClass = FinReceipt::class; - public function credit($id) + public function credit($id, $data) { - return FinReceipt::where('id', $id)->update(['received_at' => time()]); + return FinReceipt::where('id', $id)->update($data); } } \ No newline at end of file diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 37b9c94..0070585 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -282,13 +282,19 @@ class FinReceiptService return $query->paginate($limit, ['*'], 'page', $page); } - public function credit($id) + public function credit($id, $exchange_rate) { $finReceipt = FinReceipt::find($id); if(!empty($finReceipt->received_at)){ throw new BusinessException('该记录已将确认入账'); } - $res = $this->logic->credit($id); + + $data = [ + 'received_at' => time(), + 'exchange_rate' => $exchange_rate, + 'total_amount_cny' => round($finReceipt['amount']*$exchange_rate,2), + ]; + $res = $this->logic->credit($id,$data); $this->afterServiceUpdate(['id'=>$id]); return $res; } @@ -303,10 +309,6 @@ class FinReceiptService public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') { $payment_apply_id = $request->input('payment_apply_id'); - $exchange_rate = $request->input('exchange_rate'); - if(empty($exchange_rate) || !is_numeric($exchange_rate)){ - throw new BusinessException('请输入汇率'); - } $id = $request->input('id'); $data = $this->preProcess(ucfirst($scene), $data, $request); @@ -319,8 +321,6 @@ class FinReceiptService $receipt = FinReceipt::find($id); $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; $data['submit_files'] = $payment->submit_files ?? ''; - $data['exchange_rate'] = $exchange_rate; - $data['total_amount_cny'] = round($data['amount']*$exchange_rate,2); $updated = $this->logicUpdateBy($config, $data); return $this->postProcess(ucfirst($scene), $data); From 56ad5517075843898a748a113d75cb64620e2cc7 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 14:44:47 +0800 Subject: [PATCH 71/74] =?UTF-8?q?=E6=94=B6=E6=B1=87=E5=87=AD=E8=AF=81?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/FinReceiptController.php | 9 ++++++++- app/common/model/FinPaymentApply.php | 2 +- app/common/service/FinPaymentApplyService.php | 1 + app/common/service/FinReceiptService.php | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index f0e0626..4c73b7a 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -12,6 +12,7 @@ use app\common\model\User; use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\FinReceiptService; +use support\Redis; use support\Request; class FinReceiptController extends BaseController @@ -85,14 +86,20 @@ class FinReceiptController extends BaseController { if (isset($data['created_at'])){ $data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0; + $data['claim_timeout_time'] = date('Y-m-d H:i:s', $data['created_at']+86400); $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); } if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['arrived_at'])) $data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']); - if (isset($data['received_at'])) + if (isset($data['received_at'])){ $data['received_at'] = date('Y-m-d H:i:s', $data['received_at']); + $voucher_no_timeout_hour = redis::get('voucher_no_timeout_hour'); + if(!empty($voucher_no_timeout_hour)){ + $data['voucher_no_timeout_time'] = date('Y-m-d H:i:s', time()+(60*60*$voucher_no_timeout_hour)); + } + } if (isset($data['account_id'])) { //收款账号 $data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??''; diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index c81ac0a..af52c85 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -42,7 +42,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'created_at', 'updated_at', 'deleted_at', 'claimed_by', 'created_by',]; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'received_at', 'created_at', 'updated_at', 'deleted_at', 'claimed_by', 'created_by',]; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index be467e5..ed9267a 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -217,6 +217,7 @@ class FinPaymentApplyService if(isset($param['scene']) && $param['scene'] == 'pending'){ //待入账列表 $query->where('receipt_id', '>' ,'0'); $query->where('submit_files','!=',''); + $query->whereNotNull('received_at'); } if($param['scene'] == 'delete'){ //查询作废数据 diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index 0070585..5f6b480 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -10,6 +10,7 @@ use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\FinReceipt; use support\exception\BusinessException; +use support\Redis; use support\Request; class FinReceiptService @@ -194,6 +195,10 @@ class FinReceiptService $page = (int)$request->get('current', 1); $param = $request->all(); + if(isset($param['voucher_no_timeout_hour'])){ + redis::set('voucher_no_timeout_hour', $param['voucher_no_timeout_hour'], 'EX', 30); + } + $where = []; // 汇款国家 @@ -295,6 +300,7 @@ class FinReceiptService 'total_amount_cny' => round($finReceipt['amount']*$exchange_rate,2), ]; $res = $this->logic->credit($id,$data); + FinPaymentApply::where('id', $finReceipt->payment_apply_id)->update(['received_at' => $data['received_at']]); $this->afterServiceUpdate(['id'=>$id]); return $res; } From 5b77b8ed834f2f98d192a79763fd11cb42cf1a0d Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 1 Nov 2025 14:59:41 +0800 Subject: [PATCH 72/74] =?UTF-8?q?=E5=BE=85=E5=85=A5=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/FinPaymentApplyService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index ed9267a..42cae9a 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -217,7 +217,7 @@ class FinPaymentApplyService if(isset($param['scene']) && $param['scene'] == 'pending'){ //待入账列表 $query->where('receipt_id', '>' ,'0'); $query->where('submit_files','!=',''); - $query->whereNotNull('received_at'); + $query->whereNull('received_at'); } if($param['scene'] == 'delete'){ //查询作废数据 From 2f8f7dccf9cbc82c5664532317a492b251515d2f Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 3 Nov 2025 18:07:56 +0800 Subject: [PATCH 73/74] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=87=E8=B4=A7?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StockOrdersController.php | 11 ++-- app/admin/controller/UserController.php | 5 ++ app/admin/service/UserService.php | 2 + app/common/model/StockOrdersFiles.php | 2 +- app/common/service/StockOrdersService.php | 56 +++++++++++++++++-- .../approval/service/ApprovalFlowService.php | 10 +++- app/crm/controller/StockOrdersController.php | 42 ++++++++------ 7 files changed, 98 insertions(+), 30 deletions(-) diff --git a/app/admin/controller/StockOrdersController.php b/app/admin/controller/StockOrdersController.php index 39806a5..47e694a 100644 --- a/app/admin/controller/StockOrdersController.php +++ b/app/admin/controller/StockOrdersController.php @@ -81,19 +81,22 @@ class StockOrdersController extends BaseController if (!isset($groupedFiles[$file['file_code']])) { $groupedFiles[$file['file_code']] = []; } - $groupedFiles[$file['file_code']][] = $file['file_url']; + $groupedFiles[$file['file_code']][] = [ + 'url' => $file['file_url'], + 'original_name' => $file['original_name'] + ]; } // 映射到对应字段 foreach ($fileTypes as $field => $fileCode) { if (isset($groupedFiles[$fileCode])) { - // 原始URL数组 + // 文件信息数组,包含url和original_name $data[$field] = $groupedFiles[$fileCode]; // 完整URL数组 $fullUrls = []; - foreach ($groupedFiles[$fileCode] as $url) { - $fullUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($url); + foreach ($groupedFiles[$fileCode] as $fileInfo) { + $fullUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($fileInfo['url']); } $data[$field . '_url'] = $fullUrls; } diff --git a/app/admin/controller/UserController.php b/app/admin/controller/UserController.php index 8c24c6c..e9ef8d4 100644 --- a/app/admin/controller/UserController.php +++ b/app/admin/controller/UserController.php @@ -118,6 +118,11 @@ class UserController extends BaseController $data['system_ids'][] = $system['id']; } } + if ($data['reportToInfo']) { + $data['report_to_name'] = $data['reportToInfo']['id'] == $data['id'] ? '/' : $data['reportToInfo']['name']; + } else { + $data['report_to_name'] = '-'; + } return $data; } diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index 7f2fadd..9d850a5 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -100,6 +100,8 @@ class UserService $config['with']['roles'][] = 'name'; $config['with']['systems'][] = 'id'; $config['with']['systems'][] = 'name'; + $config['with']['reportToInfo'][] = 'id'; + $config['with']['reportToInfo'][] = 'name'; break; case 'show': $config['where']['id'] = $p['id']; diff --git a/app/common/model/StockOrdersFiles.php b/app/common/model/StockOrdersFiles.php index 98daa3f..3b78e5c 100644 --- a/app/common/model/StockOrdersFiles.php +++ b/app/common/model/StockOrdersFiles.php @@ -40,7 +40,7 @@ class StockOrdersFiles extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'order_id', 'file_name', 'file_code', 'file_url', 'created_at', 'updated_at']; + protected $fillable = ['id', 'order_id', 'file_name', 'file_code', 'file_url', 'original_name', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php index 76d2ab5..d4187a1 100644 --- a/app/common/service/StockOrdersService.php +++ b/app/common/service/StockOrdersService.php @@ -161,7 +161,8 @@ class StockOrdersService { // 启动审批 $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->start('stock_orders', 'stock_orders', $item->id, [], $item->salesperson_id); + $formData = $this->checkNewOrUsedVehicles($item->id); + $appro->start('stock_orders', 'stock_orders', $item->id, $formData, $item->salesperson_id); // 异步生成pdf文件 \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]); } @@ -295,7 +296,8 @@ class StockOrdersService public function approvalNullify($item) { $appro = new \app\common\utils\approval\service\ApprovalFlowService(); - $appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, [], $item->salesperson_id); + $formData = $this->checkNewOrUsedVehicles($item->id); + $appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, $formData, $item->salesperson_id); } /** @@ -479,14 +481,19 @@ class StockOrdersService // 检查数据中是否存在该字段且为数组 if (!empty($data[$field]) && is_array($data[$field])) { // 处理该字段下的每个文件 - foreach ($data[$field] as $fileUrl) { + foreach ($data[$field] as $fileInfo) { $fileData = [ 'order_id' => $order->id, 'file_code' => $fileCode, - 'file_url' => $fileUrl, + 'file_url' => $fileInfo['url'] ?? '', 'file_name' => StockOrdersFiles::FILE_CODE[$fileCode], + 'original_name' => $fileInfo['original_name'] ?? StockOrdersFiles::FILE_CODE[$fileCode], ]; - StockOrdersFiles::create($fileData); + + // 只有当file_url不为空时才创建记录 + if (!empty($fileData['file_url'])) { + StockOrdersFiles::create($fileData); + } } } } @@ -905,6 +912,7 @@ class StockOrdersService 'id' => $file->id, 'file_url' => $file->file_url, 'file_full_url' => $this->getFileUrl($file->file_url), + 'original_name' => $file->original_name, ]; } @@ -978,4 +986,42 @@ class StockOrdersService } return (new \app\common\service\OssService)->generatePrivateUrl($fileUrl); } + + /** + * 检查备货单中的车辆是新车还是二手车 + * @param int $stockOrderId 备货单ID + * @return array 返回包含has_new和has_used的数组 + */ + public function checkNewOrUsedVehicles(int $stockOrderId): array + { + // 获取备货单关联的所有车辆项 + $vehicles = StockOrderItems::where('order_id', $stockOrderId)->get(); + + $hasNew = false; + $hasUsed = false; + $submitNote = ''; + + foreach ($vehicles as $vehicle) { + // 判断是否为二手车(mileage > 0) + if ($vehicle->mileage > 0) { + $hasUsed = true; + $submitNote = '本单只有二手车'; + } else { + $hasNew = true; + $submitNote = '本单只有新车'; + } + + // 如果两种类型都已经存在,可以提前退出循环 + if ($hasNew && $hasUsed) { + $submitNote = '本单包含新车和二手车'; + break; + } + } + + return [ + 'has_new' => $hasNew ? 1 : 0, + 'has_used' => $hasUsed ? 1 : 0, + 'submit_note' => $submitNote + ]; + } } \ No newline at end of file diff --git a/app/common/utils/approval/service/ApprovalFlowService.php b/app/common/utils/approval/service/ApprovalFlowService.php index 6eae8d8..a26b79a 100644 --- a/app/common/utils/approval/service/ApprovalFlowService.php +++ b/app/common/utils/approval/service/ApprovalFlowService.php @@ -68,7 +68,7 @@ class ApprovalFlowService } $this->sendNotification($approverIds, $instance, 'pending', false, $extra); - $this->notifyCCs($firstStep, $instance, 'pending'); + // $this->notifyCCs($firstStep, $instance, 'pending'); $this->pushTodoChanged($approverIds); @@ -193,6 +193,12 @@ class ApprovalFlowService 'updated_at' => $now, ]); $this->onFlowFinalized($instance, $finalStatus); + + // 新增:在流程最终完成时才发本步骤的抄送 + if (!empty($step['cc'])) { + $this->notifyCCs($step, $instance, $notifyAction); + } + $this->sendNotification([$instance->initiator_id], $instance, $notifyAction, false); $this->pushTodoChanged([$approverId]); return ['status' => 'completed', 'msg' => ($finalStatus === 'voided' ? '已作废' : '同意')]; @@ -215,7 +221,7 @@ class ApprovalFlowService $this->insertApprovalRecord($instance, $nextIndex, $uid); } $this->sendNotification($nextApprovers, $instance, 'pending', false); - $this->notifyCCs($nextStep, $instance, 'pending'); + // $this->notifyCCs($nextStep, $instance, 'pending'); $this->pushTodoChanged(array_merge([$approverId], $nextApprovers)); return ['status' => 'next_step', 'msg' => '进行下一步:'.$nextStep['name'] ?? ('Step '.$nextIndex)]; }); diff --git a/app/crm/controller/StockOrdersController.php b/app/crm/controller/StockOrdersController.php index 3716c69..3f6c6e4 100644 --- a/app/crm/controller/StockOrdersController.php +++ b/app/crm/controller/StockOrdersController.php @@ -61,43 +61,49 @@ class StockOrdersController extends BaseController if (isset($data['pick_up_date']) && $data['pick_up_date'] > 0) $data['pick_up_date'] = date('Y-m-d', $data['pick_up_date']); if (isset($data['collect_all_date']) && $data['collect_all_date'] > 0) $data['collect_all_date'] = date('Y-m-d', $data['collect_all_date']); - // 处理文件附件 + // 处理文件附件:只允许 _url 字段调用 OSS 生成私有链接 $fileTypes = [ 'contract' => \app\common\model\StockOrdersFiles::CONTRACT, 'transaction_slip' => \app\common\model\StockOrdersFiles::TRANSACTION_SLIP, 'pi_doc' => \app\common\model\StockOrdersFiles::PI_DOC ]; - + // 初始化文件字段 foreach (array_keys($fileTypes) as $field) { - $data[$field] = []; - $data[$field . '_url'] = []; + $data[$field] = []; // 存储原始文件信息(不包含签名链接) + $data[$field . '_url'] = []; // 存储通过OSS生成的私有链接 } - - // 按file_code分组文件 + + // 按 file_code 分组文件 if (!empty($data['files'])) { $groupedFiles = []; foreach ($data['files'] as $file) { - if (!isset($groupedFiles[$file['file_code']])) { - $groupedFiles[$file['file_code']] = []; + $code = $file['file_code']; + if (!isset($groupedFiles[$code])) { + $groupedFiles[$code] = []; } - $groupedFiles[$file['file_code']][] = $file['file_url']; + $groupedFiles[$code][] = [ + 'url' => $file['file_url'], // 原始路径 + 'original_name' => $file['original_name'] // 原始文件名 + ]; } - - // 映射到对应字段 + + // 映射到对应字段,并仅对 _url 调用 OSS 服务 foreach ($fileTypes as $field => $fileCode) { if (isset($groupedFiles[$fileCode])) { - // 原始URL数组 + // 主字段存储基本信息(无签名链接) $data[$field] = $groupedFiles[$fileCode]; - - // 完整URL数组 - $fullUrls = []; - foreach ($groupedFiles[$fileCode] as $url) { - $fullUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($url); + + // 只有 *_url 字段才生成带签名的完整 URL + $signedUrls = []; + foreach ($groupedFiles[$fileCode] as $fileInfo) { + $signedUrls[] = (new \app\common\service\OssService)->generatePrivateUrl($fileInfo['url']); } - $data[$field . '_url'] = $fullUrls; + $data[$field . '_url'] = $signedUrls; } } + + // 清理临时数据 unset($data['files']); } From 42bf32a9a58a520c05f4e34559eaf4502e40b367 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 4 Nov 2025 10:31:45 +0800 Subject: [PATCH 74/74] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E5=A4=87=E8=B4=A7=E5=8D=95=E7=BB=95=E8=BF=87?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/StockOrdersService.php | 131 ++++++++++++++++++---- 1 file changed, 111 insertions(+), 20 deletions(-) diff --git a/app/common/service/StockOrdersService.php b/app/common/service/StockOrdersService.php index d4187a1..9d5e4df 100644 --- a/app/common/service/StockOrdersService.php +++ b/app/common/service/StockOrdersService.php @@ -73,6 +73,7 @@ class StockOrdersService case 'print': case 'approval': $config['where']['id'] = $p['id']; + $config['with'][] = 'files'; // 添加文件附件关联 break; case 'detail': case 'show': @@ -102,22 +103,14 @@ class StockOrdersService 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') ?? ''; - $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; - - // if ($data['is_final'] == 1) { - $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; - $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; - // } - + // 检查绑定 + (new UserService())->checkBind($userId); + // 保存不检查文件上传 + if ($data['approval_status'] != 0) { + $this->validateRequiredFiles($data); + } + // 终版备货单时,至少一个车辆填写了vin if ($data['is_final'] == 1) { - // 检查是否至少有一个车辆填写了vin $hasVin = false; foreach ($data['veh_list'] as $k => $v) { if ($v['vin'] != '') { @@ -125,17 +118,105 @@ class StockOrdersService break; } } - // 如果没有任何车辆填写vin,则抛出异常 if (!$hasVin) { throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核'); } } - - // 检查绑定 - (new UserService())->checkBind($userId); + $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') ?? ''; + $data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0; + $data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0; + $data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0; return $data; } + /** + * 验证创建备货单时必需的文件是否已提供 + * + * @param array $data 提交的数据 + * @throws BusinessException 当必需的文件缺失或为空时抛出异常 + */ + private function validateRequiredFiles(array $data): void + { + $requiredFiles = [ + 'contract' => '合同', + 'transaction_slip' => '水单', + 'pi_doc' => 'PI' + ]; + + foreach ($requiredFiles as $fileType => $fileLabel) { + if (!isset($data[$fileType]) || !is_array($data[$fileType]) || empty($data[$fileType])) { + throw new BusinessException("创建备货单时{$fileLabel}文件不能为空"); + } + + // 检查文件数组中的每个条目是否都有有效的URL + $hasValidFile = false; + foreach ($data[$fileType] as $fileInfo) { + if (isset($fileInfo['url']) && !empty($fileInfo['url'])) { + $hasValidFile = true; + break; + } + } + + if (!$hasValidFile) { + throw new BusinessException("创建备货单时{$fileLabel}文件不能为空"); + } + } + } + + /** + * 验证备货单审批时必需的文件是否存在 + * + * @param StockOrders $item 备货单对象 + * @throws BusinessException 当必需的文件缺失或为空时抛出异常 + */ + private function validateRequiredFilesForApproval($item): void + { + // 确保已加载文件关联 + if (!isset($item->files)) { + $item->load('files'); + } + + $requiredFiles = [ + \app\common\model\StockOrdersFiles::CONTRACT => '合同', + \app\common\model\StockOrdersFiles::TRANSACTION_SLIP => '水单', + \app\common\model\StockOrdersFiles::PI_DOC => 'PI' + ]; + + // 按文件类型分组现有文件 + $existingFiles = []; + foreach ($item->files as $file) { + if (!isset($existingFiles[$file->file_code])) { + $existingFiles[$file->file_code] = []; + } + $existingFiles[$file->file_code][] = $file; + } + + // 检查每种必需文件是否存在 + foreach ($requiredFiles as $fileCode => $fileLabel) { + if (!isset($existingFiles[$fileCode]) || empty($existingFiles[$fileCode])) { + throw new BusinessException("提交审批前必须上传{$fileLabel}文件"); + } + + // 检查文件中是否有有效的URL + $hasValidFile = false; + foreach ($existingFiles[$fileCode] as $file) { + if (!empty($file->file_url)) { + $hasValidFile = true; + break; + } + } + + if (!$hasValidFile) { + throw new BusinessException("提交审批前必须上传有效的{$fileLabel}文件"); + } + } + } + protected function afterServiceStore($res) { // 处理原单 @@ -271,10 +352,14 @@ class StockOrdersService public function serviceApproval(Request $request) { $config = $this->buildQueryConfig($request, 'approval'); + $item = $this->logicShow($config); + + // 检查备货单是否包含必需的文件 + $this->validateRequiredFilesForApproval($item); + $this->logicUpdateBy($config, [ 'approval_status' => 1 ]); - $item = $this->logicShow($config); $this->startApproval($item); return $this->postProcess('Approval', $item); } @@ -366,6 +451,9 @@ class StockOrdersService */ public function beforeServiceUpdate($data, Request $request) { + // 检查必填文件是否已上传 + // $this->validateRequiredFiles($data); + $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']); @@ -1024,4 +1112,7 @@ class StockOrdersService 'submit_note' => $submitNote ]; } + + + } \ No newline at end of file