Merge branch 'feature/fin' into develop
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\dashboard;
|
||||||
|
|
||||||
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\model\FinReceipt;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
class FinStatisticsController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 收款记录统计
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function statistics(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$query = FinReceipt::where('payment_apply_id','>',0);
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
//已认领数量
|
||||||
|
$result['claimed_num'] = $query->count();
|
||||||
|
//已认领金额
|
||||||
|
$result['claimed_amount'] = $query->sum('amount');
|
||||||
|
|
||||||
|
|
||||||
|
$query = FinReceipt::whereNull('payment_apply_id');
|
||||||
|
|
||||||
|
//未认领数量
|
||||||
|
$result['unclaimed_num'] = $query->count();
|
||||||
|
//未认领金额
|
||||||
|
$result['unclaimed_amount'] = $query->sum('amount');
|
||||||
|
|
||||||
|
//已超时未认领数量
|
||||||
|
$result['timeout'] = $query->where('created_at','<',time()-24*3600)->count();
|
||||||
|
|
||||||
|
return $this->success($result);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -147,4 +147,19 @@ class FinReceiptController extends BaseController
|
|||||||
}
|
}
|
||||||
return $data;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace app\common\service;
|
namespace app\common\service;
|
||||||
|
|
||||||
use app\common\model\FinPaymentStock;
|
use app\common\model\FinPaymentStock;
|
||||||
|
use app\common\model\FinReceipt;
|
||||||
use app\common\validate\FinPaymentApplyValidate;
|
use app\common\validate\FinPaymentApplyValidate;
|
||||||
use app\common\traits\crud\CrudServiceTrait;
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\model\FinPaymentApply;
|
use app\common\model\FinPaymentApply;
|
||||||
@@ -182,10 +183,16 @@ class FinPaymentApplyService
|
|||||||
$query->whereDoesntHave('receipt');
|
$query->whereDoesntHave('receipt');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($param['scene']) && $param['scene'] == 'list') {
|
if ((isset($param['scene']) && $param['scene'] == 'list') || empty($param['receipt_id'])) {
|
||||||
return $query->paginate($limit, ['*'], 'page', $page);
|
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);
|
$sevenDaysAgo = time() - (10 * 24 * 60 * 60);
|
||||||
|
|
||||||
@@ -193,29 +200,24 @@ class FinPaymentApplyService
|
|||||||
$similarityOrder = [];
|
$similarityOrder = [];
|
||||||
|
|
||||||
// 如果有传入参数,计算相似度
|
// 如果有传入参数,计算相似度
|
||||||
if (isset($param['account_id']) && !empty($param['account_id'])) {
|
if (!empty($account_id)) {
|
||||||
$similarityOrder[] = "CASE WHEN account_id = {$param['account_id']} THEN 0 ELSE 1 END";
|
$similarityOrder[] = "CASE WHEN account_id = {$account_id} THEN 0 ELSE 1 END";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($param['currency_id']) && !empty($param['currency_id'])) {
|
if (!empty($currency_id)) {
|
||||||
$similarityOrder[] = "CASE WHEN currency_id = {$param['currency_id']} THEN 0 ELSE 1 END";
|
$similarityOrder[] = "CASE WHEN currency_id = {$currency_id} THEN 0 ELSE 1 END";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($param['remitter']) && !empty($param['remitter'])) {
|
if (!empty($remitter)) {
|
||||||
$similarityOrder[] = "CASE WHEN remitter = {$param['remitter']} THEN 0 ELSE 1 END";
|
$similarityOrder[] = "CASE WHEN remitter = {$remitter} THEN 0 ELSE 1 END";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($param['amount']) && !empty($param['amount'])) {
|
if (!empty($amount)) {
|
||||||
$amount = (float)$param['amount'];
|
$amount = (float)$amount;
|
||||||
$similarityOrder[] = "ABS(amount - {$amount}) ASC";
|
$similarityOrder[] = "ABS(amount - {$amount}) ASC";
|
||||||
$similarityOrder[] = "CASE WHEN (ABS(amount - {$amount}) / {$amount} * 100) <= 5 THEN 0 ELSE 1 END";
|
$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
|
// 构建排序SQL
|
||||||
$orderByClause = "";
|
$orderByClause = "";
|
||||||
if (!empty($similarityOrder)) {
|
if (!empty($similarityOrder)) {
|
||||||
@@ -227,11 +229,11 @@ class FinPaymentApplyService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$orderByClause .= "CASE
|
$orderByClause .= "CASE
|
||||||
WHEN created_at < {$sevenDaysAgo} THEN id
|
WHEN created_at > {$sevenDaysAgo} THEN id
|
||||||
ELSE 999999
|
ELSE 999999
|
||||||
END DESC";
|
END DESC, ";
|
||||||
|
|
||||||
$orderByClause .= ", id DESC";
|
$orderByClause .= "id DESC";
|
||||||
|
|
||||||
$query->orderByRaw($orderByClause);
|
$query->orderByRaw($orderByClause);
|
||||||
|
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ class FinReceiptService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新计算折让金额
|
* 更新:绑定收款记录,计算折让金额
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @param string $scene
|
* @param string $scene
|
||||||
@@ -296,9 +296,24 @@ class FinReceiptService
|
|||||||
//折让金额
|
//折让金额
|
||||||
$payment = FinPaymentApply::where('id', $payment_apply_id)->first();
|
$payment = FinPaymentApply::where('id', $payment_apply_id)->first();
|
||||||
$receipt = FinReceipt::find($id);
|
$receipt = FinReceipt::find($id);
|
||||||
$data['discount_amount'] = $payment->amount - $payment->amount ?? 0;
|
$data['discount_amount'] = $payment->amount - $receipt->amount ?? 0;
|
||||||
|
|
||||||
$updated = $this->logicUpdateBy($config, $data);
|
$updated = $this->logicUpdateBy($config, $data);
|
||||||
return $this->postProcess(ucfirst($scene), $data);
|
return $this->postProcess(ucfirst($scene), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款记录统计
|
||||||
|
* @return bool|int
|
||||||
|
*/
|
||||||
|
public function statistics()
|
||||||
|
{
|
||||||
|
$finReceipt = FinReceipt::find($id);
|
||||||
|
if(!empty($finReceipt->received_at)){
|
||||||
|
throw new BusinessException('该记录已将确认入账');
|
||||||
|
}
|
||||||
|
$res = $this->logic->credit($id);
|
||||||
|
$this->afterServiceUpdate(['id'=>$id]);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -438,6 +438,10 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/show', [app\common\controller\FinReceiptHisController::class, 'show']);
|
Route::any('/show', [app\common\controller\FinReceiptHisController::class, 'show']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::group('/fin', function () {
|
||||||
|
Route::any('/statistics', [app\admin\controller\dashboard\FinStatisticsController::class, 'statistics']);
|
||||||
|
});
|
||||||
|
|
||||||
// 付款申请
|
// 付款申请
|
||||||
Route::group('/payment', function () {
|
Route::group('/payment', function () {
|
||||||
Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']);
|
Route::any('/list', [app\common\controller\FinPaymentApplyController::class, 'index']);
|
||||||
|
|||||||
Reference in New Issue
Block a user