Merge branch 'develop'

# Conflicts:
#	app/admin/controller/dashboard/FinStatisticsController.php
#	app/common/controller/FinPaymentApplyController.php
#	app/common/controller/FinReceiptController.php
#	app/common/logic/FinReceiptLogic.php
#	app/common/model/FinPaymentApply.php
#	app/common/model/FinReceipt.php
#	app/common/service/FinPaymentApplyService.php
#	app/common/service/FinReceiptService.php
#	app/common/service/StockOrdersService.php
#	config/route.php
This commit is contained in:
mzl
2025-11-04 10:36:52 +08:00
parent 359755fdf1
commit aabd0f4634
10 changed files with 321 additions and 39 deletions
@@ -3,7 +3,9 @@
namespace app\admin\controller\dashboard; namespace app\admin\controller\dashboard;
use app\common\controller\BaseController; use app\common\controller\BaseController;
use app\common\model\FinPaymentApply;
use app\common\model\FinReceipt; use app\common\model\FinReceipt;
use app\common\model\SysCurrency;
use support\Request; use support\Request;
class FinStatisticsController extends BaseController class FinStatisticsController extends BaseController
@@ -16,33 +18,117 @@ class FinStatisticsController extends BaseController
public function statistics(Request $request) public function statistics(Request $request)
{ {
try { try {
$currency = SysCurrency::where('status',1)->get();
$query = FinReceipt::where('payment_apply_id','>',0); $query = FinReceipt::where('payment_apply_id','>',0);
$result = []; $result = [];
//已认领数量 //已认领数量
$result['claimed_num'] = $query->count(); $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'); //今日入账
$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'] = $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_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_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'] = $result['unclaimed_payment_num'] - $result['unclaimed_num'];
//未认领金额重新组织索引
$result['unclaimed_amount'] = array_values($result['unclaimed_amount']);
return $this->success($result); return $this->success($result);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->error($e->getMessage()); 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);
}
} }
@@ -5,6 +5,7 @@ namespace app\common\controller;
use app\common\controller\BaseController; use app\common\controller\BaseController;
use app\common\model\Country; use app\common\model\Country;
use app\common\model\FinPaymentStock; use app\common\model\FinPaymentStock;
use app\common\model\StockOrders;
use app\common\model\SysAccount; use app\common\model\SysAccount;
use app\common\model\SysCurrency; use app\common\model\SysCurrency;
use app\common\model\SysDictItem; use app\common\model\SysDictItem;
@@ -84,11 +85,15 @@ class FinPaymentApplyController extends BaseController
if (isset($data['id'])){ if (isset($data['id'])){
$finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get(); $finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get();
$stock = []; $stock = [];
$stock_order_no = [];
foreach ($finPaymentStock as $v) { foreach ($finPaymentStock as $v) {
$stock[$v['pi_no']]['pi_no'] = $v['pi_no']; $stock[$v['pi_no']]['pi_no'] = $v['pi_no'];
$stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']]; $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'] = array_values($stock);
$data['stock_order_no'] = $stock_order_no;
} }
return $data; return $data;
@@ -157,4 +162,20 @@ class FinPaymentApplyController extends BaseController
$data['stock'] = array_values($stock); $data['stock'] = array_values($stock);
return $data; 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());
}
}
} }
+13 -2
View File
@@ -12,6 +12,7 @@ use app\common\model\User;
use app\common\service\OssService; use app\common\service\OssService;
use app\common\traits\crud\CrudControllerTrait; use app\common\traits\crud\CrudControllerTrait;
use app\common\service\FinReceiptService; use app\common\service\FinReceiptService;
use support\Redis;
use support\Request; use support\Request;
class FinReceiptController extends BaseController class FinReceiptController extends BaseController
@@ -34,7 +35,11 @@ class FinReceiptController extends BaseController
{ {
try { try {
$id = $request->input('id'); $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); return $this->success($raw);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage());
@@ -81,14 +86,20 @@ class FinReceiptController extends BaseController
{ {
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['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']); $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
} }
if (isset($data['updated_at'])) if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['arrived_at'])) if (isset($data['arrived_at']))
$data['arrived_at'] = date('Y-m-d H:i:s', $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']); $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'])) { //收款账号 if (isset($data['account_id'])) { //收款账号
$data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??''; $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')??''; $data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??'';
+2 -2
View File
@@ -14,8 +14,8 @@ class FinReceiptLogic
*/ */
protected string $modelClass = FinReceipt::class; 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);
} }
} }
+12 -1
View File
@@ -2,10 +2,12 @@
namespace app\common\model; namespace app\common\model;
use Illuminate\Database\Eloquent\SoftDeletes;
use support\Model; use support\Model;
class FinPaymentApply extends Model class FinPaymentApply extends Model
{ {
use SoftDeletes;
/** /**
* The connection name for the model. * 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', 'received_at', 'created_at', 'updated_at', 'deleted_at', 'claimed_by', 'created_by',];
/** /**
* 不允许自动填充模型字段 * 不允许自动填充模型字段
@@ -62,4 +64,13 @@ class FinPaymentApply extends Model
{ {
return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id'); 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');
}
} }
+17 -1
View File
@@ -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'); 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');
}
} }
+27 -1
View File
@@ -127,6 +127,13 @@ class FinPaymentApplyService
return $data; 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位字母数字组合 * 格式:PA + 日期 + 6位字母数字组合
@@ -207,7 +214,19 @@ class FinPaymentApplyService
$query->whereDoesntHave('receipt'); $query->whereDoesntHave('receipt');
} }
if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) { if(isset($param['scene']) && $param['scene'] == 'pending'){ //待入账列表
$query->where('receipt_id', '>' ,'0');
$query->where('submit_files','!=','');
$query->whereNull('received_at');
}
if($param['scene'] == 'delete'){ //查询作废数据
$query->onlyTrashed();
}elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据
$query->withTrashed();
}
if ((isset($param['scene']) && ($param['scene'] == 'list' || $param['scene'] == 'pending'))|| empty($param['receipt_id']) ) {
return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page); return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page);
} }
@@ -264,4 +283,11 @@ class FinPaymentApplyService
return $query->paginate($limit, ['*'], 'page', $page); return $query->paginate($limit, ['*'], 'page', $page);
} }
public function delete($id)
{
$res = FinPaymentApply::where('id', $id)->delete();
return $res;
}
} }
+24 -4
View File
@@ -10,6 +10,7 @@ use app\common\validate\FinReceiptValidate;
use app\common\traits\crud\CrudServiceTrait; use app\common\traits\crud\CrudServiceTrait;
use app\common\model\FinReceipt; use app\common\model\FinReceipt;
use support\exception\BusinessException; use support\exception\BusinessException;
use support\Redis;
use support\Request; use support\Request;
class FinReceiptService class FinReceiptService
@@ -194,6 +195,10 @@ class FinReceiptService
$page = (int)$request->get('current', 1); $page = (int)$request->get('current', 1);
$param = $request->all(); $param = $request->all();
if(isset($param['voucher_no_timeout_hour'])){
redis::set('voucher_no_timeout_hour', $param['voucher_no_timeout_hour'], 'EX', 30);
}
$where = []; $where = [];
// 汇款国家 // 汇款国家
@@ -218,7 +223,7 @@ class FinReceiptService
// 构建查询 // 构建查询
$query = $this->modelClass::where($where); $query = $this->modelClass::where($where);
// 没有付款记录的收款记录 // 收款记录绑定情况
if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') { if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') {
$query->where('payment_apply_id', 0); $query->where('payment_apply_id', 0);
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') { } elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') {
@@ -228,7 +233,12 @@ class FinReceiptService
$query->where('created_at', '<' ,time() - 24*60*60); $query->where('created_at', '<' ,time() - 24*60*60);
} }
if (isset($param['scene']) && $param['scene'] == 'list') { if(isset($param['scene']) && $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); return $query->paginate($limit, ['*'], 'page', $page);
} }
@@ -277,13 +287,20 @@ class FinReceiptService
return $query->paginate($limit, ['*'], 'page', $page); return $query->paginate($limit, ['*'], 'page', $page);
} }
public function credit($id) public function credit($id, $exchange_rate)
{ {
$finReceipt = FinReceipt::find($id); $finReceipt = FinReceipt::find($id);
if(!empty($finReceipt->received_at)){ if(!empty($finReceipt->received_at)){
throw new BusinessException('该记录已将确认入账'); 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);
FinPaymentApply::where('id', $finReceipt->payment_apply_id)->update(['received_at' => $data['received_at']]);
$this->afterServiceUpdate(['id'=>$id]); $this->afterServiceUpdate(['id'=>$id]);
return $res; return $res;
} }
@@ -298,6 +315,7 @@ class FinReceiptService
public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment')
{ {
$payment_apply_id = $request->input('payment_apply_id'); $payment_apply_id = $request->input('payment_apply_id');
$id = $request->input('id'); $id = $request->input('id');
$data = $this->preProcess(ucfirst($scene), $data, $request); $data = $this->preProcess(ucfirst($scene), $data, $request);
$config = $this->buildQueryConfig($request, $scene); $config = $this->buildQueryConfig($request, $scene);
@@ -308,8 +326,10 @@ class FinReceiptService
$payment = FinPaymentApply::where('id', $payment_apply_id)->first(); $payment = FinPaymentApply::where('id', $payment_apply_id)->first();
$receipt = FinReceipt::find($id); $receipt = FinReceipt::find($id);
$data['discount_amount'] = $payment->amount - $receipt->amount ?? 0; $data['discount_amount'] = $payment->amount - $receipt->amount ?? 0;
$data['submit_files'] = $payment->submit_files ?? '';
$updated = $this->logicUpdateBy($config, $data); $updated = $this->logicUpdateBy($config, $data);
return $this->postProcess(ucfirst($scene), $data); return $this->postProcess(ucfirst($scene), $data);
} }
} }
+111 -20
View File
@@ -73,6 +73,7 @@ class StockOrdersService
case 'print': case 'print':
case 'approval': case 'approval':
$config['where']['id'] = $p['id']; $config['where']['id'] = $p['id'];
$config['with'][] = 'files'; // 添加文件附件关联
break; break;
case 'detail': case 'detail':
case 'show': case 'show':
@@ -102,22 +103,14 @@ class StockOrdersService
public function beforeServiceStore($data, Request $request) public function beforeServiceStore($data, Request $request)
{ {
$userId = $request->user->uid; $userId = $request->user->uid;
// 检查绑定
$data['order_no'] = generateStockNo(); (new UserService())->checkBind($userId);
$data['biz_date'] = strtotime($data['biz_date']); // 保存不检查文件上传
$data['eta_ship_date'] = strtotime($data['eta_ship_date']); if ($data['approval_status'] != 0) {
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']); $this->validateRequiredFiles($data);
$data['salesperson_id'] = $userId; }
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? ''; // 终版备货单时,至少一个车辆填写了vin
$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) { if ($data['is_final'] == 1) {
// 检查是否至少有一个车辆填写了vin
$hasVin = false; $hasVin = false;
foreach ($data['veh_list'] as $k => $v) { foreach ($data['veh_list'] as $k => $v) {
if ($v['vin'] != '') { if ($v['vin'] != '') {
@@ -125,17 +118,105 @@ class StockOrdersService
break; break;
} }
} }
// 如果没有任何车辆填写vin,则抛出异常
if (!$hasVin) { if (!$hasVin) {
throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核'); throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核');
} }
} }
$data['order_no'] = generateStockNo();
// 检查绑定 $data['biz_date'] = strtotime($data['biz_date']);
(new UserService())->checkBind($userId); $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; 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) protected function afterServiceStore($res)
{ {
// 处理原单 // 处理原单
@@ -271,10 +352,14 @@ class StockOrdersService
public function serviceApproval(Request $request) public function serviceApproval(Request $request)
{ {
$config = $this->buildQueryConfig($request, 'approval'); $config = $this->buildQueryConfig($request, 'approval');
$item = $this->logicShow($config);
// 检查备货单是否包含必需的文件
$this->validateRequiredFilesForApproval($item);
$this->logicUpdateBy($config, [ $this->logicUpdateBy($config, [
'approval_status' => 1 'approval_status' => 1
]); ]);
$item = $this->logicShow($config);
$this->startApproval($item); $this->startApproval($item);
return $this->postProcess('Approval', $item); return $this->postProcess('Approval', $item);
} }
@@ -366,6 +451,9 @@ class StockOrdersService
*/ */
public function beforeServiceUpdate($data, Request $request) public function beforeServiceUpdate($data, Request $request)
{ {
// 检查必填文件是否已上传
// $this->validateRequiredFiles($data);
$data['biz_date'] = strtotime($data['biz_date']); $data['biz_date'] = strtotime($data['biz_date']);
$data['eta_ship_date'] = strtotime($data['eta_ship_date']); $data['eta_ship_date'] = strtotime($data['eta_ship_date']);
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']); $data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
@@ -1024,4 +1112,7 @@ class StockOrdersService
'submit_note' => $submitNote 'submit_note' => $submitNote
]; ];
} }
} }
+1 -1
View File
@@ -448,7 +448,7 @@ Route::group('/admin', function () {
Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']); Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']);
Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']); Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']);
Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']); 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']);
}); });
// 系统配置 // 系统配置