where($field.'=:'.$field, [':'.$field=>$userId])->exists()){ Yii::$app->redis->hset(self::SOCKET_KEY_PREFIX.$app, $userId, $fd); } } return $fd; } /** * 获取会员的WebSocket的fd * @param $app * @param $userId * @return mixed */ public static function getWebSocketFd($app, $userId){ return Yii::$app->redis->hget(self::SOCKET_KEY_PREFIX.$app, $userId); } /** * 获取系统配置信息 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getSystemConfig(){ return Config::getFromCache(); } /** * 更新系统配置 * @return array|\yii\db\ActiveRecord[] */ public static function updateSystemConfig(){ return Config::updateToCache(); } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getDecLevelConfig(){ return DeclarationLevel::getFromCache(); } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getEliteLevelConfig(){ return EliteLevel::getFromCache(); } /** * 获取国家列表 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getCountries(){ return Countries::getFromCache(); } /** * 获取国家列表 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getLanguages(){ return Language::getFromCache(); } /** * 获取货币列表 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getCurrencies(){ return Currency::getFromCache(); } /** * 更新报单级别 * @return array|\yii\db\ActiveRecord[] */ public static function updateDecLevelConfig(){ return DeclarationLevel::updateToCache(); } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getDecRoleConfig(){ return DecRole::getFromCache(); } /** * 更新报单级别 * @return array|\yii\db\ActiveRecord[] */ public static function updateDecRoleConfig(){ return DecRole::updateToCache(); } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getDealType(){ return DealType::getFromCache(); } /** * 获取地区 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getRegionConfig(){ return Region::getFromCache(); } /** * 获取聘级 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getEmpLevelConfig(){ return EmployLevel::getFromCache(); } /** * 更新管理员角色 * @return array|\yii\db\ActiveRecord[] */ public static function updateAdminRole(){ return AdminRole::updateToCache(); } /** * 获取管理员角色 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getAdminRole(){ return AdminRole::getFromCache(); } /** * 更新聘级 * @return array|\yii\db\ActiveRecord[] */ public static function updateEmpLevelConfig(){ return EmployLevel::updateToCache(); } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getRegType(){ return RegType::getFromCache(); } /** * 获取用户基本信息 * @param $userId * @return array|null|\yii\db\ActiveRecord */ public static function getUserBaseInfo($userId){ return User::getBaseInfoFromRedis($userId); } /** * 执行异步任务时往缓存中把要传递的参数都存起来,方便在异步方法中直接调用 * @param $params * @return string * @throws \yii\base\Exception */ public static function setAsyncParams($params){ // 生成一个随机key $taskKey = self::createRandomKey(self::ASYNC_KEY_PREFIX); Yii::$app->cache->set($taskKey, $params); return $taskKey; } /** * 获取异步参数 * @param $taskKey * @return mixed */ public static function getAsyncParams($taskKey){ $result = Yii::$app->cache->get($taskKey); Yii::$app->cache->delete($taskKey); return $result; } /** * 获取异步参数但不删除异步参数缓存 * (用于临时获取一下,但还不影响正式获取后删除的逻辑) * @param $taskKey * @return mixed */ public static function getAsyncParamsWithoutDel($taskKey){ return Yii::$app->cache->get($taskKey); } /** * @param $key * @return bool */ public static function deleteAsyncParams($key){ return Yii::$app->cache->delete($key); } /** * 生成一个随机不重复的key * @param $prefix * @return string * @throws \yii\base\Exception */ public static function createRandomKey($prefix){ $key = Yii::$app->security->generateRandomString(20); if(Yii::$app->cache->exists($prefix.$key)){ self::createRandomKey($prefix); } return $prefix.$key; } /** * 获取报单级别 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getOcrApiConfig(){ return OcrApi::getFromCache(); } /** * 获取短信接口设置 * @return array|mixed|\yii\db\ActiveRecord[] */ public static function getSmsApiConfig(){ return SmsApi::getFromCache(); } /** * 设置上传token * @return string * @throws \yii\base\Exception */ public static function setUploadToken(){ $token = Yii::$app->security->generateRandomString(32); Yii::$app->cache->set($token, 1, 5 * 60); return $token; } /** * 用上传token获取上传资格 * @param $token * @return mixed */ public static function getUploadToken($token){ $result = Yii::$app->cache->get($token); Yii::$app->cache->delete($token); return $result; } /** * 获取全部安置网络上级 * @param $userId * @return array|mixed */ public static function getAllNetworkParents($userId){ return UserNetwork::getAllParentsFromRedis($userId); } /** * 获取全部推荐网络的上级 * @param $userId * @return array|mixed */ public static function getAllRelationParents($userId){ return UserRelation::getAllParentsFromRedis($userId); } /** * 设置 当前自动发放奖金的状态 * * */ public static function setWithdrawLock($status){ Yii::$app->cache->set('withdrawLock', $status); } /** * 获取 当前自动发放奖金的状态 * * */ public static function getWithdrawLock(){ return Yii::$app->cache->get('withdrawLock'); } }