90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\api\validate;
|
||
|
||
use app\common\enum\PayEnum;
|
||
use app\common\service\ConfigService;
|
||
use app\common\validate\BaseValidate;
|
||
use app\common\model\setting\RechargeMethod;
|
||
use app\common\model\finance\{RechargeRecord};
|
||
|
||
/**
|
||
* 用户验证器
|
||
* Class RechargeValidate
|
||
* @package app\api\validate
|
||
*/
|
||
class RechargeValidate extends BaseValidate
|
||
{
|
||
|
||
protected $rule = [
|
||
'money' => 'require|gt:0|checkMoney',
|
||
];
|
||
|
||
protected $message = [
|
||
'money.require' => 'network.parameterAbnormality',//请输入金额
|
||
'money.gt' => 'network.parameterAbnormality',//请输入正确的金额
|
||
];
|
||
|
||
|
||
public function sceneRecharge()
|
||
{
|
||
return $this->only(['money']);
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @notes 校验金额
|
||
* @param $money
|
||
* @param $rule
|
||
* @param $data
|
||
* @return bool|string
|
||
* @author 段誉
|
||
* @date 2023/2/24 10:42
|
||
*/
|
||
protected function checkMoney($money, $rule, $data)
|
||
{
|
||
//判断充值方式
|
||
$method = RechargeMethod::where(['id' => $data['id']])->findOrEmpty();
|
||
if ($method->isEmpty()) {
|
||
return 'network.parameterAbnormality';//充值方式不存在
|
||
}
|
||
|
||
//判断充值次数
|
||
$config = ConfigService::get('website', 'trade');
|
||
$todayStart = strtotime("today midnight");
|
||
$recharge_num = RechargeRecord::where(['user_id' => $data['user_id']])
|
||
->where("create_time > $todayStart")
|
||
->count();
|
||
if($config['recharge_num'] <= $recharge_num){
|
||
return 'recharge.rechargeNumError';//每日充值次数限制
|
||
}
|
||
|
||
//查询充值凭证
|
||
if ($method['is_voucher']&&!isset($data['voucher'])) {
|
||
return 'network.parameterAbnormality';//请上传支付凭证
|
||
}
|
||
|
||
//判断充值金额
|
||
$config = ConfigService::get('website', 'trade');
|
||
|
||
if ($data['money'] < $config['recharge_min']) {
|
||
return 'network.parameterAbnormality';
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
} |