付款记录
This commit is contained in:
@@ -9,6 +9,7 @@ use app\common\model\SysAccount;
|
||||
use app\common\model\SysCurrency;
|
||||
use app\common\model\SysDictItem;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\FinPaymentApplyService;
|
||||
|
||||
@@ -43,8 +44,19 @@ class FinPaymentApplyController extends BaseController
|
||||
$data['country_name'] = Country::where('id', $data['country_id'])->first()->cn_addr;
|
||||
if (isset($data['currency_id'])) //付款币种
|
||||
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->first()->currency_name;
|
||||
if (isset($data['submit_files']))
|
||||
$OssService = new OssService();
|
||||
if (isset($data['submit_files'])){
|
||||
$data['submit_files'] = json_decode($data['submit_files'], true);
|
||||
foreach ($data['submit_files'] as $key => $value) {
|
||||
$data['submit_files'][$key] = [
|
||||
'file_src' => $value['file_src'],
|
||||
'file_full' => $OssService->generatePrivateUrl($value['file_src']),
|
||||
'file_name' => $value['file_name'],
|
||||
];
|
||||
}
|
||||
}
|
||||
if (isset($data['voucher_file']))
|
||||
$data['voucher_file_full'] = $OssService->generatePrivateUrl($data['voucher_file']);
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
|
||||
@@ -40,7 +40,7 @@ class FinPaymentApply extends Model
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'submit_files', 'created_at', 'updated_at'];
|
||||
protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
@@ -55,14 +55,6 @@ class FinPaymentApply extends Model
|
||||
return $this->hasOne(FinReceipt::class, 'payment_apply_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 备货单
|
||||
*/
|
||||
public function stock()
|
||||
{
|
||||
return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的备货单(通过中间表)
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,23 @@ class FinPaymentApplyService
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 汇款国家
|
||||
if (isset($p['country_id']) && !empty($p['country_id'])) {
|
||||
$config['where']['country_id'] = $p['country_id'];
|
||||
}
|
||||
|
||||
// 收款账户筛选
|
||||
if (isset($p['account_id']) && !empty($p['account_id'])) {
|
||||
$config['where']['account_id'] = $p['account_id'];
|
||||
}
|
||||
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
$config['orWhere'][] = ['remitter', 'like', $k];
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
@@ -125,4 +142,93 @@ class FinPaymentApplyService
|
||||
$timestamp = substr(time(), -6);
|
||||
return $secondChar . $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据相似度排序付款记录
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function complexQueryIndex(Request $request)
|
||||
{
|
||||
$limit = (int)$request->get('size', 15);
|
||||
$page = (int)$request->get('current', 1);
|
||||
$param = $request->all();
|
||||
|
||||
$where = [];
|
||||
|
||||
// 汇款国家
|
||||
if (isset($param['country_id']) && !empty($param['country_id'])) {
|
||||
$where[] = ['country_id', $param['country_id']];
|
||||
}
|
||||
// 收款账户筛选
|
||||
if (isset($param['account_id']) && !empty($param['account_id'])) {
|
||||
$where[] = ['account_id', $param['account_id']];
|
||||
}
|
||||
|
||||
// 关键字
|
||||
if (isset($param['keyword']) && $param['keyword']) {
|
||||
$k = '%' . $param['keyword'] . '%';
|
||||
$where[] = ['remitter', 'like', $k];
|
||||
}
|
||||
|
||||
// 构建查询
|
||||
$query = $this->modelClass::where($where);
|
||||
|
||||
// 应用是否有关联收款记录的筛选
|
||||
$correlation = $param['correlation']??'';
|
||||
if ($correlation === 'receipt') {
|
||||
$query->whereHas('receipt');
|
||||
} elseif ($correlation === 'unbind') {
|
||||
$query->whereDoesntHave('receipt');
|
||||
}
|
||||
|
||||
if (isset($param['scene']) && $param['scene'] == 'list') {
|
||||
return $query->paginate($limit, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
// 计算七天前的时间戳
|
||||
$sevenDaysAgo = time() - (10 * 24 * 60 * 60);
|
||||
|
||||
// 构建相似度排序逻辑
|
||||
$similarityOrder = [];
|
||||
|
||||
// 如果有传入参数,计算相似度
|
||||
if (isset($param['account_id']) && !empty($param['account_id'])) {
|
||||
$similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END";
|
||||
}
|
||||
|
||||
if (isset($param['country_id']) && !empty($param['country_id'])) {
|
||||
$similarityOrder[] = "CASE WHEN country_id = {$param['country_id']} THEN 0 ELSE 1 END";
|
||||
}
|
||||
|
||||
if (isset($param['keyword']) && $param['keyword']) {
|
||||
$keyword = addslashes($param['keyword']);
|
||||
$similarityOrder[] = "CASE WHEN remitter LIKE '%{$keyword}%' THEN 0 ELSE 1 END";
|
||||
}
|
||||
|
||||
if (isset($param['amount']) && !empty($param['amount'])) {
|
||||
$amount = (float)$param['amount'];
|
||||
$similarityOrder[] = "ABS(amount - {$amount})";
|
||||
}
|
||||
|
||||
// 构建排序SQL
|
||||
$orderByClause = "";
|
||||
if (!empty($similarityOrder)) {
|
||||
$orderByClause = "CASE
|
||||
WHEN created_at >= {$sevenDaysAgo} THEN
|
||||
(" . implode(' + ', $similarityOrder) . ")
|
||||
ELSE 999999
|
||||
END ASC, ";
|
||||
}
|
||||
|
||||
$orderByClause .= "CASE
|
||||
WHEN created_at < {$sevenDaysAgo} THEN id
|
||||
ELSE 0
|
||||
END DESC";
|
||||
|
||||
$query->orderByRaw($orderByClause);
|
||||
|
||||
return $query->paginate($limit, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user