Merge branch 'develop' into feature/mzl_dev

This commit is contained in:
mzl
2025-11-04 10:32:22 +08:00
9 changed files with 210 additions and 19 deletions
@@ -5,6 +5,7 @@ namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\model\Country;
use app\common\model\FinPaymentStock;
use app\common\model\StockOrders;
use app\common\model\SysAccount;
use app\common\model\SysCurrency;
use app\common\model\SysDictItem;
@@ -84,11 +85,15 @@ class FinPaymentApplyController extends BaseController
if (isset($data['id'])){
$finPaymentStock = FinPaymentStock::where('payment_apply_id', $data['id'])->get();
$stock = [];
$stock_order_no = [];
foreach ($finPaymentStock as $v) {
$stock[$v['pi_no']]['pi_no'] = $v['pi_no'];
$stock[$v['pi_no']]['stock_id'][] = [$v['stock_id']];
$stockOrders = StockOrders::where('id', $v['stock_id'])->first();
$stock_order_no[] = $stockOrders['order_no'];
}
$data['stock'] = array_values($stock);
$data['stock_order_no'] = $stock_order_no;
}
return $data;
@@ -157,4 +162,20 @@ class FinPaymentApplyController extends BaseController
$data['stock'] = array_values($stock);
return $data;
}
/**
* 作废
* @param Request $request
* @return \support\Response
*/
public function delete(Request $request)
{
try {
$id = $request->input('id');
$raw = $this->service->delete($id);
return $this->success($raw);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}
+13 -2
View File
@@ -12,6 +12,7 @@ use app\common\model\User;
use app\common\service\OssService;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\FinReceiptService;
use support\Redis;
use support\Request;
class FinReceiptController extends BaseController
@@ -34,7 +35,11 @@ class FinReceiptController extends BaseController
{
try {
$id = $request->input('id');
$raw = $this->service->credit($id);
$exchange_rate = $request->input('exchange_rate');
if(empty($exchange_rate) || !is_numeric($exchange_rate)){
return $this->error('请输入汇率');
}
$raw = $this->service->credit($id,$exchange_rate);
return $this->success($raw);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
@@ -81,14 +86,20 @@ class FinReceiptController extends BaseController
{
if (isset($data['created_at'])){
$data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0;
$data['claim_timeout_time'] = date('Y-m-d H:i:s', $data['created_at']+86400);
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
}
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['arrived_at']))
$data['arrived_at'] = date('Y-m-d H:i:s', $data['arrived_at']);
if (isset($data['received_at']))
if (isset($data['received_at'])){
$data['received_at'] = date('Y-m-d H:i:s', $data['received_at']);
$voucher_no_timeout_hour = redis::get('voucher_no_timeout_hour');
if(!empty($voucher_no_timeout_hour)){
$data['voucher_no_timeout_time'] = date('Y-m-d H:i:s', time()+(60*60*$voucher_no_timeout_hour));
}
}
if (isset($data['account_id'])) { //收款账号
$data['account_name'] = SysAccount::where('id', $data['account_id'])->value('account_name')??'';
$data['account_short_desc'] = SysAccount::where('id', $data['account_id'])->value('short_desc')??'';
+2 -2
View File
@@ -14,8 +14,8 @@ class FinReceiptLogic
*/
protected string $modelClass = FinReceipt::class;
public function credit($id)
public function credit($id, $data)
{
return FinReceipt::where('id', $id)->update(['received_at' => time()]);
return FinReceipt::where('id', $id)->update($data);
}
}
+12 -1
View File
@@ -2,10 +2,12 @@
namespace app\common\model;
use Illuminate\Database\Eloquent\SoftDeletes;
use support\Model;
class FinPaymentApply extends Model
{
use SoftDeletes;
/**
* The connection name for the model.
*
@@ -40,7 +42,7 @@ class FinPaymentApply extends Model
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', 'created_at', 'updated_at', 'claimed_by',];
protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at','warn', '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');
}
/**
* 查询 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');
}
/**
* 关联付款申请
*/
// 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;
}
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;
}
}
+24 -4
View File
@@ -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);
}
}