195 lines
7.3 KiB
PHP
195 lines
7.3 KiB
PHP
<?php
|
|
namespace app\common\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\model\Country;
|
|
use app\common\model\FinPaymentApply;
|
|
use app\common\model\FinPaymentStock;
|
|
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\FinReceiptService;
|
|
use support\Redis;
|
|
use support\Request;
|
|
|
|
class FinReceiptController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new FinReceiptService();
|
|
}
|
|
|
|
/**
|
|
* 确认入账
|
|
* @param Request $request
|
|
* @return \support\Response
|
|
*/
|
|
public function credit(Request $request)
|
|
{
|
|
try {
|
|
$id = $request->input('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());
|
|
}
|
|
}
|
|
|
|
public function show(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceShow($request);
|
|
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
|
? [$this, 'showFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新
|
|
*
|
|
* @param Request $request 请求对象
|
|
* @return mixed 返回更新成功的数据或信息
|
|
*/
|
|
public function payment(Request $request)
|
|
{
|
|
try {
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'update');
|
|
$res = $this->service->serviceUpdatePayment($request, $data);
|
|
return $this->success([], '更新成功');
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
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'])){
|
|
$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')??'';
|
|
}
|
|
if (isset($data['country_id'])) //付款来源国家
|
|
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??'';
|
|
if (isset($data['currency_id'])) //付款币种
|
|
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??'';
|
|
|
|
$OssService = new OssService();
|
|
if (!empty($data['fx_receipt_file'])){
|
|
$data['fx_receipt_file'] = json_decode($data['fx_receipt_file'], true);
|
|
foreach ($data['fx_receipt_file'] as $key => $value) {
|
|
$data['fx_receipt_file'][$key] = [
|
|
'file_src' => $value['file_src'],
|
|
'file_full' => $OssService->generatePrivateUrl($value['file_src']),
|
|
'file_name' => $value['file_name'],
|
|
];
|
|
}
|
|
}else{
|
|
$data['fx_receipt_file'] = [];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function showFormat($data)
|
|
{
|
|
if (isset($data['created_at']))
|
|
$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']))
|
|
$data['received_at'] = date('Y-m-d H:i:s', $data['received_at']);
|
|
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')??'';
|
|
}
|
|
if (isset($data['country_id'])) //付款来源国家
|
|
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr')??'';
|
|
if (isset($data['currency_id'])) //付款币种
|
|
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name')??'';
|
|
|
|
$OssService = new OssService();
|
|
if (!empty($data['fx_receipt_file'])){
|
|
$data['fx_receipt_file'] = json_decode($data['fx_receipt_file'], true);
|
|
foreach ($data['fx_receipt_file'] as $key => $value) {
|
|
$data['fx_receipt_file'][$key] = [
|
|
'file_src' => $value['file_src'],
|
|
'file_full' => $OssService->generatePrivateUrl($value['file_src']),
|
|
'file_name' => $value['file_name'],
|
|
];
|
|
}
|
|
}else{
|
|
$data['fx_receipt_file'] = [];
|
|
}
|
|
|
|
//查询关联的付款记录
|
|
if (!empty($data['payment_apply_id'])) {
|
|
$paymentApply = FinPaymentApply::where('id', $data['payment_apply_id'])->first();
|
|
if(!$paymentApply)
|
|
return $data;
|
|
$paymentApply = $paymentApply->toArray();
|
|
$paymentApply['created_at'] = strtotime($paymentApply['created_at']);
|
|
$paymentApply['updated_at'] = strtotime($paymentApply['updated_at']);
|
|
$paymentApply = (new FinPaymentApplyController())->showFormat($paymentApply);
|
|
$data['payment_apply'] = $paymentApply;
|
|
}
|
|
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());
|
|
}
|
|
}
|
|
} |