Merge branch 'feature/fin' into develop
# Conflicts: # app/common/service/FinReceiptService.php
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
namespace app\admin\controller\dashboard;
|
namespace app\admin\controller\dashboard;
|
||||||
|
|
||||||
use app\common\controller\BaseController;
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\model\FinPaymentApply;
|
||||||
use app\common\model\FinReceipt;
|
use app\common\model\FinReceipt;
|
||||||
|
use app\common\model\SysCurrency;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
class FinStatisticsController extends BaseController
|
class FinStatisticsController extends BaseController
|
||||||
@@ -16,33 +18,100 @@ class FinStatisticsController extends BaseController
|
|||||||
public function statistics(Request $request)
|
public function statistics(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$currency = SysCurrency::where('status',1)->get();
|
||||||
$query = FinReceipt::where('payment_apply_id','>',0);
|
$query = FinReceipt::where('payment_apply_id','>',0);
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
//已认领数量
|
//已认领数量
|
||||||
$result['claimed_num'] = $query->count();
|
$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');
|
$query3 = FinReceipt::whereNull('payment_apply_id');
|
||||||
|
|
||||||
//未认领数量
|
//未认领数量
|
||||||
$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_amount'] = array_values($result['unclaimed_payment_amount']);
|
||||||
|
$result['unclaimed_payment_amount_sum'] = $this->amountSum($result['unclaimed_payment_amount']);
|
||||||
|
//在途资金 = 没有认领的付款资金-未认领的收款资金
|
||||||
|
$result['intransit_amount'] = $result['unclaimed_payment_amount_sum'] - $result['unclaimed_amount_sum'];
|
||||||
|
|
||||||
|
//在途数量 = 没有认领的付款数量-未认领的收款数量
|
||||||
|
$result['intransit_count'] = count($result['unclaimed_payment_amount']) - count($result['unclaimed_amount']);
|
||||||
|
|
||||||
|
//未认领金额重新组织索引
|
||||||
|
$result['unclaimed_amount'] = array_values($result['unclaimed_amount']);
|
||||||
return $this->success($result);
|
return $this->success($result);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,22 @@ class FinReceiptController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认入账
|
||||||
|
* @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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function show(Request $request)
|
public function show(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -62,4 +62,13 @@ class FinPaymentApply extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'payment_apply_id', 'stock_id');
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use support\Model;
|
use support\Model;
|
||||||
|
|
||||||
class FinReceipt extends Model
|
class FinReceipt extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDeletes;
|
||||||
/**
|
/**
|
||||||
* The connection name for the model.
|
* The connection name for the model.
|
||||||
*
|
*
|
||||||
@@ -40,7 +42,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 +64,20 @@ class FinReceipt extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(StockOrders::class, 'fin_payment_stock', 'receipt_id', 'stock_id');
|
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;
|
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位字母数字组合
|
* 格式:PA + 日期 + 6位字母数字组合
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class FinReceiptService
|
|||||||
// 构建查询
|
// 构建查询
|
||||||
$query = $this->modelClass::where($where);
|
$query = $this->modelClass::where($where);
|
||||||
|
|
||||||
// 没有付款记录的收款记录
|
// 收款记录绑定情况
|
||||||
if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') {
|
if (isset($param['payment_apply']) && $param['payment_apply'] == 'not') {
|
||||||
$query->where('payment_apply_id', 0);
|
$query->where('payment_apply_id', 0);
|
||||||
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') {
|
} elseif (isset($param['payment_apply']) && $param['payment_apply'] == 'already') {
|
||||||
@@ -228,7 +228,18 @@ class FinReceiptService
|
|||||||
$query->where('created_at', '<' ,time() - 24*60*60);
|
$query->where('created_at', '<' ,time() - 24*60*60);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($param['scene']) && $param['scene'] == 'list') {
|
if($param['scene'] == 'pending'){ //待入账列表
|
||||||
|
$query->where('payment_apply_id', '>' ,'0');
|
||||||
|
$query->where('submit_files','!=','');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($param['scene'] == 'delete'){ //查询作废数据
|
||||||
|
$query->onlyTrashed();
|
||||||
|
}elseif ($param['scene'] == 'all'){ //查询包含作废数据的全量数据
|
||||||
|
$query->withTrashed();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($param['scene']) && ($param['scene'] == 'list' ||$param['scene'] == 'pending')) {
|
||||||
return $query->paginate($limit, ['*'], 'page', $page);
|
return $query->paginate($limit, ['*'], 'page', $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,6 +299,13 @@ class FinReceiptService
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$res = FinReceipt::where('id', $id)->delete();
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新:绑定收款记录,计算折让金额
|
* 更新:绑定收款记录,计算折让金额
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@@ -308,8 +326,10 @@ 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 - $receipt->amount ?? 0;
|
$data['discount_amount'] = $payment->amount - $receipt->amount ?? 0;
|
||||||
|
$data['submit_files'] = $payment->submit_files ?? '';
|
||||||
|
|
||||||
$updated = $this->logicUpdateBy($config, $data);
|
$updated = $this->logicUpdateBy($config, $data);
|
||||||
return $this->postProcess(ucfirst($scene), $data);
|
return $this->postProcess(ucfirst($scene), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -429,8 +429,8 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']);
|
Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']);
|
||||||
Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']);
|
Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']);
|
||||||
Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']);
|
Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']);
|
||||||
Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']);
|
|
||||||
Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']);
|
Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']);
|
||||||
|
Route::any('/delete', [app\common\controller\FinReceiptController::class, 'delete']);
|
||||||
});
|
});
|
||||||
// 收款记录历史
|
// 收款记录历史
|
||||||
Route::group('/receipt/his', function () {
|
Route::group('/receipt/his', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user