first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
<?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\item\{Item,ItemRecord};
use app\common\model\user\User;
use app\common\service\{UtilsService};
use app\common\model\member\UserMember;
use app\common\cache\UserAccountSafeCache;
use think\facade\Config;
/**
* 项目验证器
* Class ItemValidate
* @package app\api\validate
*/
class ItemValidate extends BaseValidate
{
protected $rule = [
'invest' => 'checkInvest',
];
public function sceneInvest()
{
return $this->only(['invest','id','money']);
}
/**
* @notes 校验投资
* @param $invest
* @param $rule
* @param $data
* @return bool|string
* @author BD
* @date 2024/02/22 10:54
*/
protected function checkInvest($invest, $rule, $data)
{
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
$userAccountSafeCache = new UserAccountSafeCache();
if (!$userAccountSafeCache->isSafe()) {
return 'network.frequentOperation';
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
}
// 获取今天0点的时间戳
$todayStart = strtotime(date('Y-m-d 00:00:00'));
//判断项目
$item = Item::where(['is_show' => 1])->findOrEmpty($data['id']);
if($item->isEmpty()){
return 'network.parameterAbnormality';
}
//判断投资金额
if($data['money'] < $item['min_money'] || $data['money'] > $item['max_money']) return 'network.parameterAbnormality';
//判断余额
$user = User::where(['id' => $data['user_id']])->findOrEmpty();
if($data['money'] - $user['user_money'] > 0) return 'common.InsufficientBalance';//余额不足
//限制等级
//查询会员等级
$member_id = UtilsService::get_user_member_id($data['user_id']);
$userMember = UserMember::where(['id' => $member_id])->findOrEmpty();
if($item['member_id'] - $member_id > 0) return 'network.parameterAbnormality';//会员等级限制
//判断今日投资次数
//今日量化次数
$today_order = ItemRecord::where("create_time > $todayStart")->where(['user_id' => $data['user_id']])->count();
if ($today_order >= $userMember['item_num']) {
return 'network.parameterAbnormality';
}
//投资进度
if($item['progress'] >= 100) return 'network.parameterAbnormality';//进度已满
//交易密码
if (empty($data['pay_pwd'])) {
$userAccountSafeCache->record();
return 'network.parameterAbnormality';//请输入密码
}
if (strlen($data['pay_pwd']) != 6) {
$userAccountSafeCache->record();
return 'network.parameterAbnormality';//请输入正确的密码
}
$passwordSalt = Config::get('project.unique_identification');
if ($user['password_pay'] !== create_password($data['pay_pwd'], $passwordSalt)) {
$userAccountSafeCache->record();
return 'common.payPwdError';//密码错误
}
$userAccountSafeCache->relieve();
return true;
}
}