Merge branch 'develop' into feature/sku_crawl
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\FinPaymentApplyService;
|
||||
|
||||
class FinPaymentApplyController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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 (!empty($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'],
|
||||
];
|
||||
}
|
||||
}else{
|
||||
$data['submit_files'] = [];
|
||||
}
|
||||
|
||||
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']))
|
||||
$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']); //认领时间
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据格式化
|
||||
*
|
||||
* @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 (!empty($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'],
|
||||
];
|
||||
}
|
||||
}else{
|
||||
$data['submit_files'] = [];
|
||||
}
|
||||
|
||||
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']))
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
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;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class FinReceiptController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new FinReceiptService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认入账
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
*/
|
||||
public function credit(Request $request)
|
||||
{
|
||||
try {
|
||||
$id = $request->input('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());
|
||||
}
|
||||
}
|
||||
|
||||
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['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'])){
|
||||
$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')??'';
|
||||
}
|
||||
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 (!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'] = [];
|
||||
}
|
||||
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')??'';
|
||||
|
||||
$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)
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
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\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\FinReceiptHisService;
|
||||
use support\Request;
|
||||
|
||||
class FinReceiptHisController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\FinPaymentApply;
|
||||
|
||||
class FinPaymentApplyLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinPaymentApply::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\FinReceiptHis;
|
||||
|
||||
class FinReceiptHisLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinReceiptHis::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\FinReceipt;
|
||||
|
||||
class FinReceiptLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinReceipt::class;
|
||||
|
||||
public function credit($id, $data)
|
||||
{
|
||||
return FinReceipt::where('id', $id)->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\SysConfig;
|
||||
use app\common\model\SysCurrency;
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
|
||||
class SysConfigLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysCurrency::class;
|
||||
|
||||
public function findByKey(string $key)
|
||||
{
|
||||
return SysConfig::where('status', 1)->where('config_key', $key)->get(['id', 'config_key', 'config_value']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use support\Model;
|
||||
|
||||
class FinPaymentApply extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'fin_payment_apply';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
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',];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 获取对应的收款记录(1-1,可为空)
|
||||
*/
|
||||
public function receipt()
|
||||
{
|
||||
return $this->hasOne(FinReceipt::class, 'payment_apply_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的备货单(通过中间表)
|
||||
*/
|
||||
public function stocks()
|
||||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class FinPaymentStock extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'fin_payment_stock';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'pi_no', 'payment_apply_id', 'receipt_id', 'stock_id', 'allocated_amount', 'allocated_amount_cny', 'updated_at', 'created_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
// 付款申请
|
||||
public function payment_apply()
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class FinReceipt extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'fin_receipt';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
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'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 对应的付款申请(1-1,可为空)
|
||||
*/
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo(FinPaymentApply::class, 'payment_apply_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的备货单(通过中间表)
|
||||
*/
|
||||
public function stocks()
|
||||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class FinReceiptHis extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'fin_receipt_his';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
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'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -107,4 +107,20 @@ 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联收款记录(多对多,经由中间表)
|
||||
*/
|
||||
public function receipts()
|
||||
{
|
||||
return $this->belongsToMany(FinReceipt::class, 'fin_payment_stock', 'stock_id', 'receipt_id');
|
||||
}
|
||||
}
|
||||
@@ -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'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class SysConfig extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_config';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'category', 'config_key', 'config_value', 'config_type', 'description', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class FinPaymentApplyService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinPaymentApply::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = FinPaymentApplyValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$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['scene']) && $p['scene'] == 'file_timeout') {
|
||||
$config['where']['claimed_at'] = ['between', [1, time()-24*60*60]];
|
||||
}
|
||||
|
||||
// 关键字
|
||||
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['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'] == '""')
|
||||
$data['voucher_file'] = '';
|
||||
if($data['submit_files'] == '[]' || $data['submit_files'] == '{}' || $data['submit_files'] == '""')
|
||||
$data['submit_files'] = '';
|
||||
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)
|
||||
{
|
||||
unset($data['stock']);
|
||||
$data['submit_files'] = json_encode($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'] == '{}' || $data['voucher_file'] == '""')
|
||||
$data['voucher_file'] = '';
|
||||
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位字母数字组合
|
||||
*
|
||||
* @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 = [];
|
||||
$orWhere = [];
|
||||
|
||||
// 汇款国家
|
||||
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['scene']) && $param['scene'] == 'file_timeout') {
|
||||
$where[] = ['submit_files', ''];
|
||||
$where[] = ['claimed_at', '<', time()-24*60*60];
|
||||
$where[] = ['claimed_at', '>', 1];
|
||||
}
|
||||
|
||||
// 关键字
|
||||
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'] == '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);
|
||||
}
|
||||
|
||||
$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})";
|
||||
$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);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$res = FinPaymentApply::where('id', $id)->delete();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\validate\FinReceiptHisValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\FinReceiptHis;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
|
||||
class FinReceiptHisService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinReceiptHis::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = FinReceiptHisValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use app\common\model\FinReceipt;
|
||||
use support\exception\BusinessException;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class FinReceiptService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = FinReceipt::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = FinReceiptValidate::class;
|
||||
|
||||
|
||||
protected $logic;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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'] = 0;
|
||||
} elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'already') { //已认领
|
||||
$config['where']['payment_apply_id'] = ['>', 0];
|
||||
} elseif (isset($p['payment_apply']) && $p['payment_apply'] == 'timeout') { //超时未认领
|
||||
$config['where']['payment_apply_id'] = 0;
|
||||
$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;
|
||||
$data['fx_receipt_file'] = json_encode($data['fx_receipt_file']);
|
||||
if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' || $data['fx_receipt_file'] == '""')
|
||||
$data['fx_receipt_file'] = '';
|
||||
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']);
|
||||
|
||||
$data['fx_receipt_file'] = json_encode($data['fx_receipt_file']);
|
||||
if($data['fx_receipt_file'] == '[]' || $data['fx_receipt_file'] == '{}' || $data['fx_receipt_file'] == '""')
|
||||
$data['fx_receipt_file'] = '';
|
||||
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();
|
||||
|
||||
if(isset($param['voucher_no_timeout_hour'])){
|
||||
redis::set('voucher_no_timeout_hour', $param['voucher_no_timeout_hour'], 'EX', 30);
|
||||
}
|
||||
|
||||
$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->where('payment_apply_id', 0);
|
||||
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') {
|
||||
$query->where('payment_apply_id', '>', 0);
|
||||
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'timeout') { //超时未认领
|
||||
$query->where('payment_apply_id', 0);
|
||||
$query->where('created_at', '<' ,time() - 24*60*60);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 计算七天前的时间戳
|
||||
$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, $exchange_rate)
|
||||
{
|
||||
$finReceipt = FinReceipt::find($id);
|
||||
if(!empty($finReceipt->received_at)){
|
||||
throw new BusinessException('该记录已将确认入账');
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新:绑定收款记录,计算折让金额
|
||||
* @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]);
|
||||
FinPaymentStock::where('payment_apply_id', $payment_apply_id)->update(['receipt_id' => $id]);
|
||||
|
||||
//折让金额
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
// 处理原单
|
||||
@@ -161,7 +242,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]);
|
||||
}
|
||||
@@ -270,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);
|
||||
}
|
||||
@@ -295,7 +381,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,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']);
|
||||
@@ -479,14 +569,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 +1000,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 +1074,45 @@ 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
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\SysConfigLogic;
|
||||
use app\common\logic\SysCurrencyLogic;
|
||||
use app\common\logic\SystemsLogic;
|
||||
use support\Redis;
|
||||
|
||||
class SysConfigService
|
||||
{
|
||||
|
||||
protected $logic;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -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)];
|
||||
});
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>邮箱提醒</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.email-container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.header {
|
||||
padding: 20px;
|
||||
background-color: #0056b3;
|
||||
color: white;
|
||||
text-align: center;
|
||||
}
|
||||
.content {
|
||||
padding: 20px;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #0056b3;
|
||||
color: white !important;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
font-weight: bold;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.footer {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
color: #777777;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
@media only screen and (max-width: 480px) {
|
||||
.email-container {
|
||||
width: 100%;
|
||||
}
|
||||
.button {
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!--[if mso]>
|
||||
<style type="text/css">
|
||||
.button {
|
||||
background-color: #0056b3 !important;
|
||||
color: white !important;
|
||||
}
|
||||
</style>
|
||||
<![endif]-->
|
||||
|
||||
<table class="email-container" width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
|
||||
<tr>
|
||||
<td class="header">
|
||||
<h1>付款单提醒</h1>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="content">
|
||||
<p>您好,</p>
|
||||
<p>您有新的付款单待处理。请及时查看:</p>
|
||||
|
||||
<ul>
|
||||
<li>付款单编号:{{code}}</li>
|
||||
<li>付款主体:{{payment_entity}}</li>
|
||||
<li>问题描述:{{content}}</li>
|
||||
{{reply}}
|
||||
</ul>
|
||||
|
||||
<p>请点击下方按钮立即查看详情:</p>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<a href="https://x.hnxinyouhe.com" class="button" style="color: white; text-decoration: none;">立即查看</a>
|
||||
</div>
|
||||
|
||||
<!--<p>如果您未请求此操作,请忽略此邮件或联系我们的客服团队。</p>-->
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="footer">
|
||||
<p>© 2025 河南新友合科技有限公司. 保留所有权利。</p>
|
||||
<p>这是系统自动发送的邮件,请勿直接回复。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class FinPaymentApplyValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class FinReceiptHisValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
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',
|
||||
];
|
||||
|
||||
// 提示
|
||||
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'
|
||||
]
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user