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:
@@ -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位字母数字组合
|
||||
@@ -207,7 +214,19 @@ class FinPaymentApplyService
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -264,4 +283,11 @@ class FinPaymentApplyService
|
||||
return $query->paginate($limit, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$res = FinPaymentApply::where('id', $id)->delete();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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 = [];
|
||||
|
||||
// 汇款国家
|
||||
@@ -218,7 +223,7 @@ class FinReceiptService
|
||||
// 构建查询
|
||||
$query = $this->modelClass::where($where);
|
||||
|
||||
// 没有付款记录的收款记录
|
||||
// 收款记录绑定情况
|
||||
if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') {
|
||||
$query->where('payment_apply_id', 0);
|
||||
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') {
|
||||
@@ -228,7 +233,12 @@ class FinReceiptService
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -277,13 +287,20 @@ 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);
|
||||
FinPaymentApply::where('id', $finReceipt->payment_apply_id)->update(['received_at' => $data['received_at']]);
|
||||
$this->afterServiceUpdate(['id'=>$id]);
|
||||
return $res;
|
||||
}
|
||||
@@ -298,6 +315,7 @@ class FinReceiptService
|
||||
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);
|
||||
@@ -308,8 +326,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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user