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

134 lines
4.2 KiB
PHP
Raw Permalink 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\mall\{MallGoods,MallGoodsRecord};
use app\common\model\user\User;
use app\common\service\{UtilsService};
use app\common\cache\UserAccountSafeCache;
use think\facade\Config;
/**
* 积分奖品验证器
* Class MallValidate
* @package app\api\validate
*/
class MallValidate extends BaseValidate
{
protected $rule = [
'buy' => 'checkBuy',
'draw' => 'checkDraw',
];
public function sceneBuy()
{
return $this->only(['buy','id']);
}
public function sceneDraw()
{
return $this->only(['draw','id']);
}
/**
* @notes 校验兑换
* @param $buy
* @param $rule
* @param $data
* @return bool|string
* @author BD
* @date 2024/02/22 10:54
*/
protected function checkBuy($buy, $rule, $data)
{
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
$userAccountSafeCache = new UserAccountSafeCache();
if (!$userAccountSafeCache->isSafe()) {
return 'network.frequentOperation';
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
}
//判断商城商品
$goods = MallGoods::where(['type' => 1,'is_show' => 1])->findOrEmpty($data['id']);
if($goods->isEmpty()){
$userAccountSafeCache->record();
return 'network.parameterAbnormality';
}
//判断积分
$user = User::where(['id' => $data['user_id']])->findOrEmpty();
if($goods['price'] - $user['user_point'] > 0){
$userAccountSafeCache->record();
return 'network.parameterAbnormality';//积分不足
}
//判断剩余数量
if($goods['num'] <= 0){
$userAccountSafeCache->record();
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;
}
/**
* @notes 校验抽奖
* @param $buy
* @param $rule
* @param $data
* @return bool|string
* @author BD
* @date 2024/02/22 10:54
*/
protected function checkDraw($draw, $rule, $data)
{
//单次抽奖消耗积分
$config = ConfigService::get('website', 'trade');
$draw_point = $config['draw_point'];
$user = User::where(['id' => $data['user_id']])->findOrEmpty();
$point = $draw_point;
//判断积分
if($point - $user['user_point'] > 0) return 'network.parameterAbnormality';//积分不足
return true;
}
}