Merge branch 'develop' into feature/mzl_dev
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
namespace app\admin\controller\dashboard;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\FinPaymentApply;
|
||||
use app\common\model\FinReceipt;
|
||||
use app\common\model\SysCurrency;
|
||||
use support\Request;
|
||||
|
||||
class FinStatisticsController extends BaseController
|
||||
@@ -16,33 +18,117 @@ class FinStatisticsController extends BaseController
|
||||
public function statistics(Request $request)
|
||||
{
|
||||
try {
|
||||
$currency = SysCurrency::where('status',1)->get();
|
||||
$query = FinReceipt::where('payment_apply_id','>',0);
|
||||
|
||||
$result = [];
|
||||
//已认领数量
|
||||
$result['claimed_num'] = $query->count();
|
||||
//已认领金额
|
||||
$result['claimed_amount'] = $query->sum('amount');
|
||||
// $result['claimed_amount'] = $query->sum('amount');
|
||||
$result['claimed_amount'] = array_values($this->receiptStatisticsSum($query, $currency)); //各币种的已认领金额
|
||||
$result['claimed_amount_sum'] =$this->amountSum($result['claimed_amount']); //已认领的人民币总金额
|
||||
|
||||
//未入账数量
|
||||
$result['unreceived_num'] = FinReceipt::whereNull('received_at')->count();
|
||||
$query2 = FinReceipt::whereNull('received_at');
|
||||
$result['unreceived_num'] = $query2->count();
|
||||
//未入账金额
|
||||
$result['unreceived_amount'] = FinReceipt::whereNull('received_at')->sum('amount');
|
||||
// $result['unreceived_amount'] = $query2->sum('amount');
|
||||
$result['unreceived_amount'] = array_values($this->receiptStatisticsSum($query2, $currency)); //各币种的未入账金额
|
||||
$result['unreceived_amount_sum'] = $this->amountSum($result['unreceived_amount']); //未入账的已认领的人民币总金额
|
||||
|
||||
$query = FinReceipt::whereNull('payment_apply_id');
|
||||
//今日入账
|
||||
$query6 = FinReceipt::where('received_at','>',strtotime(date("Y-m-d")));
|
||||
//今日入账数量
|
||||
$result['received_num'] = $query6->count();
|
||||
//未入账金额
|
||||
// $result['unreceived_amount'] = $query2->sum('amount');
|
||||
$result['received_amount'] = array_values($this->receiptStatisticsSum($query6, $currency)); //各币种的未入账金额
|
||||
$result['received_amount_sum'] = $this->amountSum($result['unreceived_amount']); //未入账的已认领的人民币总金额
|
||||
|
||||
|
||||
$query3 = FinReceipt::where('payment_apply_id',0);
|
||||
|
||||
//未认领数量
|
||||
$result['unclaimed_num'] = $query->count();
|
||||
$result['unclaimed_num'] = $query3->count();
|
||||
//未认领金额
|
||||
$result['unclaimed_amount'] = $query->sum('amount');
|
||||
// $result['unclaimed_amount'] = $query3->sum('amount');
|
||||
$result['unclaimed_amount'] = $this->receiptStatisticsSum($query3, $currency); //各币种的未认领金额
|
||||
$result['unclaimed_amount_sum'] = $this->amountSum($result['unclaimed_amount']); //未认领的已认领的人民币总金额
|
||||
|
||||
//已超时未认领数量
|
||||
$result['timeout'] = $query->where('created_at','<',time()-24*3600)->count();
|
||||
$query4 = $query3->where('created_at','<',time()-24*3600);
|
||||
$result['timeout'] = $query4->count();
|
||||
|
||||
//在途资金
|
||||
//1、没有认领的付款资金
|
||||
$query5 = FinPaymentApply::where('receipt_id', '=', 0);
|
||||
$unclaimed_payment_amount = $this->receiptStatisticsSum($query5, $currency);
|
||||
foreach ($unclaimed_payment_amount as $key => &$value) {
|
||||
$value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount'];
|
||||
}
|
||||
$result['unclaimed_payment_num'] = $query5->count();
|
||||
$result['unclaimed_payment_amount'] = array_values($unclaimed_payment_amount);
|
||||
$result['unclaimed_payment_amount_sum'] = $this->amountSum($result['unclaimed_payment_amount']);
|
||||
//在途资金 = 没有认领的付款资金-未认领的收款资金
|
||||
$result['intransit_amount_sum'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum'];
|
||||
$intransit_amount_amount = [];
|
||||
//在途资金各币种明细
|
||||
foreach ($unclaimed_payment_amount as $key => $value) {
|
||||
$value['amount'] = $value['amount'] - $result['unclaimed_amount'][$key]['amount'];
|
||||
$intransit_amount_amount[] = $value;
|
||||
}
|
||||
$result['intransit_amount_amount'] = $intransit_amount_amount;
|
||||
//在途数量 = 没有认领的付款数量-未认领的收款数量
|
||||
$result['intransit_count'] = $result['unclaimed_payment_num'] - $result['unclaimed_num'];
|
||||
|
||||
//未认领金额重新组织索引
|
||||
$result['unclaimed_amount'] = array_values($result['unclaimed_amount']);
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同条件查询收款金额
|
||||
* @param $query
|
||||
* @param $currency
|
||||
* @return array
|
||||
*/
|
||||
public function receiptStatisticsSum($query, $currency)
|
||||
{
|
||||
$amount = [];
|
||||
foreach ($currency as $k => $v) {
|
||||
$amount[$v->currency_code] = [
|
||||
'currency_code' => $v->currency_code,
|
||||
'exchange_rate' => $v->exchange_rate,
|
||||
'amount' => $query->where('currency_id',$v->id)->sum('amount'),
|
||||
];
|
||||
}
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 不同币种汇率换算之后求和
|
||||
* @param $query
|
||||
* @param $currency
|
||||
*/
|
||||
public function amountSum($amount)
|
||||
{
|
||||
$amountSum = 0;
|
||||
foreach ($amount as $v) {
|
||||
// 转换为整数(乘以100避免浮点数问题)
|
||||
$v['amount'] = (int) round($v['amount'] * 100);
|
||||
$v['exchange_rate'] = (int) round($v['exchange_rate'] * 10000); // 汇率保留4位小数
|
||||
$amountSum += $v['amount'] * $v['exchange_rate'];
|
||||
}
|
||||
|
||||
// 转换回金额(除以1000000,因为汇率乘了10000)
|
||||
$result = $amountSum / 1000000;
|
||||
|
||||
// 四舍五入到2位小数
|
||||
return round($amountSum, 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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')??'';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -448,7 +448,7 @@ Route::group('/admin', function () {
|
||||
Route::any('/show', [app\common\controller\FinPaymentApplyController::class, 'show']);
|
||||
Route::any('/store', [app\common\controller\FinPaymentApplyController::class, 'store']);
|
||||
Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']);
|
||||
Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']);
|
||||
Route::any('/delete', [app\common\controller\FinPaymentApplyController::class, 'delete']);
|
||||
});
|
||||
|
||||
// 系统配置
|
||||
|
||||
Reference in New Issue
Block a user