Merge branch 'feature/fin' into develop
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\SysConfigService;
|
||||
|
||||
class SysConfigController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new SysConfigService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @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']);
|
||||
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']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\SysConfig;
|
||||
|
||||
class SysConfigLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysConfig::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysConfigValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysConfig;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class SysConfigService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysConfig::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysConfigValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['config_key','config_value','description'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function beforeServiceUpdate($data, Request $request)
|
||||
{
|
||||
Redis::del($data['config_key']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class SysConfigValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -66,6 +66,8 @@ class FinPaymentApplyController extends BaseController
|
||||
$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['claimed_at']))
|
||||
$data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,24 @@ class FinReceiptController extends BaseController
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
@@ -61,8 +79,10 @@ class FinReceiptController extends BaseController
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
if (isset($data['created_at'])){
|
||||
$data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0;
|
||||
$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']))
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\SysConfig;
|
||||
use app\common\model\SysCurrency;
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
|
||||
class SysConfigLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysCurrency::class;
|
||||
|
||||
public function findByKey(string $key)
|
||||
{
|
||||
return SysConfig::where('status', 1)->where('config_key', $key)->get(['id', 'config_key', 'config_value']);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class FinPaymentApply extends Model
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files', 'created_at', 'updated_at'];
|
||||
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', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class SysConfig extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_config';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'category', 'config_key', 'config_value', 'config_type', 'description', 'status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\FinReceiptLogic;
|
||||
use app\common\model\FinPaymentApply;
|
||||
use app\common\model\FinReceiptHis;
|
||||
use app\common\validate\FinReceiptValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
@@ -89,6 +90,7 @@ class FinReceiptService
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'update':
|
||||
case 'payment':
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
@@ -272,4 +274,28 @@ class FinReceiptService
|
||||
$this->afterServiceUpdate(['id'=>$id]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新计算折让金额
|
||||
* @param Request $request
|
||||
* @param array $data
|
||||
* @param string $scene
|
||||
* @return mixed
|
||||
*/
|
||||
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);
|
||||
FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time()]);
|
||||
|
||||
//折让金额
|
||||
$payment = FinPaymentApply::where('id', $payment_apply_id)->first();
|
||||
$receipt = FinReceipt::find($id);
|
||||
$data['discount_amount'] = $payment->amount - $payment->amount ?? 0;
|
||||
|
||||
$updated = $this->logicUpdateBy($config, $data);
|
||||
return $this->postProcess(ucfirst($scene), $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\SysConfigLogic;
|
||||
use app\common\logic\SysCurrencyLogic;
|
||||
use app\common\logic\SystemsLogic;
|
||||
use support\Redis;
|
||||
|
||||
class SysConfigService
|
||||
{
|
||||
|
||||
protected $logic;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = (new SysConfigLogic());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统list
|
||||
*/
|
||||
public static function getConfig(string $config_key)
|
||||
{
|
||||
$value = Redis::get($config_key);
|
||||
if (empty($value)) {
|
||||
$config = (new SysConfigLogic())->findByKey($config_key);
|
||||
if (empty($config)) {
|
||||
return null;
|
||||
}
|
||||
$value = $config->config_value;
|
||||
Redis::set($config->config_key, $value, 'EX', 7200);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -428,7 +428,7 @@ Route::group('/admin', function () {
|
||||
Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']);
|
||||
Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']);
|
||||
Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']);
|
||||
Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']);
|
||||
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']);
|
||||
});
|
||||
@@ -446,6 +446,15 @@ Route::group('/admin', function () {
|
||||
Route::any('/update', [app\common\controller\FinPaymentApplyController::class, 'update']);
|
||||
Route::any('/destroy', [app\common\controller\FinPaymentApplyController::class, 'destroy']);
|
||||
});
|
||||
|
||||
// 系统配置
|
||||
Route::group('/config', function () {
|
||||
Route::any('/list', [app\admin\controller\SysConfigController::class, 'index']);
|
||||
Route::any('/show', [app\admin\controller\SysConfigController::class, 'show']);
|
||||
Route::any('/store', [app\admin\controller\SysConfigController::class, 'store']);
|
||||
Route::any('/update', [app\admin\controller\SysConfigController::class, 'update']);
|
||||
Route::any('/destroy', [app\admin\controller\SysConfigController::class, 'destroy']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user