diff --git a/app/common/service/FinPaymentApplyService.php b/app/common/service/FinPaymentApplyService.php index 19a2f3f..e5091fd 100644 --- a/app/common/service/FinPaymentApplyService.php +++ b/app/common/service/FinPaymentApplyService.php @@ -3,6 +3,7 @@ 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; @@ -182,10 +183,16 @@ class FinPaymentApplyService $query->whereDoesntHave('receipt'); } - if (isset($param['scene']) && $param['scene'] == 'list') { - return $query->paginate($limit, ['*'], 'page', $page); + if ((isset($param['scene']) && $param['scene'] == 'list') || 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); @@ -193,29 +200,24 @@ class FinPaymentApplyService $similarityOrder = []; // 如果有传入参数,计算相似度 - if (isset($param['account_id']) && !empty($param['account_id'])) { - $similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END"; + if (!empty($account_id)) { + $similarityOrder[] = "CASE WHEN account_id = {$account_id} THEN 0 ELSE 1 END"; } - if (isset($param['currency_id']) && !empty($param['currency_id'])) { - $similarityOrder[] = "CASE WHEN currency_id = {$param['currency_id']} THEN 0 ELSE 1 END"; + if (!empty($currency_id)) { + $similarityOrder[] = "CASE WHEN currency_id = {$currency_id} THEN 0 ELSE 1 END"; } - if (isset($param['remitter']) && !empty($param['remitter'])) { - $similarityOrder[] = "CASE WHEN remitter = {$param['remitter']} THEN 0 ELSE 1 END"; + if (!empty($remitter)) { + $similarityOrder[] = "CASE WHEN remitter = {$remitter} THEN 0 ELSE 1 END"; } - if (isset($param['amount']) && !empty($param['amount'])) { - $amount = (float)$param['amount']; + if (!empty($amount)) { + $amount = (float)$amount; $similarityOrder[] = "ABS(amount - {$amount}) ASC"; $similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 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"; - } - // 构建排序SQL $orderByClause = ""; if (!empty($similarityOrder)) { @@ -227,11 +229,11 @@ class FinPaymentApplyService } $orderByClause .= "CASE - WHEN created_at < {$sevenDaysAgo} THEN id + WHEN created_at > {$sevenDaysAgo} THEN id ELSE 999999 - END DESC"; + END DESC, "; - $orderByClause .= ", id DESC"; + $orderByClause .= "id DESC"; $query->orderByRaw($orderByClause);