130 lines
5.0 KiB
PHP
130 lines
5.0 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\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');
|
|
$raw = $this->service->credit($id);
|
|
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 array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($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')??'';
|
|
if (!empty($data['fx_receipt_file'])){
|
|
$data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']);
|
|
}elseif (isset($data['fx_receipt_file'])){
|
|
$data['fx_receipt_file_full'] = '';
|
|
}
|
|
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')??'';
|
|
if (!empty($data['fx_receipt_file'])) {
|
|
$data['fx_receipt_file_full'] = (new OssService)->generatePrivateUrl($data['fx_receipt_file']);
|
|
} elseif (isset($data['fx_receipt_file'])) {
|
|
$data['fx_receipt_file_full'] = '';
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |