Files
zzp-server/app/api/validate/UserMemberValidate.php
2026-01-19 14:19:22 +08:00

104 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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\member\{UserMember,UserMemberRecord};
use app\common\model\user\User;
use app\common\cache\UserAccountSafeCache;
use app\common\service\{UtilsService};
use think\facade\Config;
/**
* 资金验证器
* Class UserMemberValidate
* @package app\api\validate
*/
class UserMemberValidate extends BaseValidate
{
protected $rule = [
'id' => 'checkJoin',
];
public function sceneJoin()
{
return $this->only(['id']);
}
/**
* @notes 校验开通vip
* @param $id
* @param $rule
* @param $data
* @return bool|string
* @author BD
* @date 2024/02/22 10:54
*/
protected function checkJoin($id, $rule, $data)
{
//判断会员等级是否存在
$member = UserMember::where(['id' => $data['id']])->findOrEmpty();
if ($member->isEmpty()) {
return 'network.parameterAbnormality';
}
//判断当前会员等级
$member_id = UtilsService::get_user_member_id($data['user_id']);
$user_member = UserMember::where(['id' => $member_id])->findOrEmpty();
if ($user_member['price'] >= $member['price']) {
return 'network.parameterAbnormality';//已开通当前会员,请勿重复开通
}
//判断余额
$user = User::where(['id' => $data['user_id']])->findOrEmpty();
if($member['price'] - $user['user_money'] > 0) return 'network.parameterAbnormality';//余额不足
//支付密码
$userAccountSafeCache = new UserAccountSafeCache();
if (empty($data['pay_pwd'])) {
$userAccountSafeCache->record();
return 'network.parameterAbnormality';//请输入密码
}
if (strlen($data['pay_pwd']) != 6) {
$userAccountSafeCache->record();
return 'network.parameterAbnormality';//请输入正确的密码
}
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
if (!$userAccountSafeCache->isSafe()) {
return 'network.frequentOperation';
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
}
$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;
}
}