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