'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; } }