123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2018/11/29
- * Time: 上午10:21
- */
- namespace app\main\service;
- use app\common\library\Ip;
- use app\common\library\Redis;
- use app\common\model\Admin;
- use app\common\model\AdminConfig;
- use app\common\model\AdminExtend;
- use app\common\model\AdminKl;
- use app\common\model\AuthGroupAccess;
- use app\common\model\VipAdminBind;
- use app\main\constants\AdminConstants;
- use app\main\constants\ErrorCodeConstants;
- use app\main\constants\WechatSubscribeConstants;
- use app\main\model\object\AdminKl as oAdminKl;
- use Jenssegers\Agent\Agent;
- use think\Config;
- use think\Cookie;
- use think\db\Query;
- /**
- * 处理后台账号信息
- * Class AdminService
- * @package app\main\service
- */
- class AdminService extends BaseService
- {
- /**
- * @var AdminService
- */
- protected static $self = NULL;
- /**
- * @return AdminService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * @return Admin
- */
- public function getAdminModel()
- {
- return model('Admin');
- }
- private $_adminConfigModel = null;
- /**
- * @return AdminConfig
- */
- public function getAdminConfigModel()
- {
- if (empty($this->_adminConfigModel)) {
- $this->_adminConfigModel = model('AdminConfig');
- }
- return $this->_adminConfigModel;
- }
- /**
- * @return VipAdminBind
- */
- public function getVipAdminBindModel()
- {
- return model('VipAdminBind');
- }
- /**
- * @return AuthGroupAccess
- */
- public function getAuthGroupAccessModel()
- {
- return model('AuthGroupAccess');
- }
- /**
- * @return AdminExtend
- */
- public function getAdminExtendModel()
- {
- return model('AdminExtend');
- }
- /**
- * @return AdminKl
- */
- public function getAdminKlModel()
- {
- return model('AdminKl');
- }
- /**
- * 获取admin_id
- * @param $admin_id
- * @return \app\main\model\object\ReturnObject
- */
- public function getAdminId($admin_id)
- {
- try {
- $auth = $this->getAuthGroupAccessModel()
- ->where('uid', '=', $admin_id)
- ->find()
- ->toArray();
- if (in_array($auth['group_id'], [AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN, AdminConstants::ADMIN_GROUP_ID_ADMIN])) {
- $admin_id = [0];
- } elseif (in_array($auth['group_id'], [AdminConstants::ADMIN_GROUP_ID_VIP, AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR])) {
- $admin_id = AdminService::instance()->getVipAdminBindModel()->getChannelIds($admin_id);
- }
- if(!$admin_id){
- $admin_id = [-1];
- }
- return $this->setData($admin_id)->getReturn();
- } catch (\Exception $e) {
- return $this->setData($admin_id)->getReturn();
- }
- }
- /**
- * @return \app\main\model\object\ReturnObject
- */
- public function getGuidQrCode($admin_id = 0)
- {
- $return = [
- 'qrcode_image' => '',
- 'subscribe_url' => '',
- ];
- try {
- if ($admin_id) {
- $admin = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($admin_id);
- } else {
- $admin = UserService::instance()->getRunTimeObject()->adminConfig;
- }
- $time = UserService::instance()->getRunTimeObject()->requestTime;
- $Scount = 0;
- $countKey = 'SC:' . $admin['admin_id'] . ':' . date('Ymd', $time);
- if (Redis::instance()->exists($countKey)) {
- $Scount = intval(Redis::instance()->get($countKey));
- }
- if ($Scount >= $admin['fans_count']) {
- $adminConfig = UserService::instance()->getRunTimeObject()->adminConfig;
- //查看该代理商有没有设置导粉账号
- $qrCodeImageReturn = BookService::instance()->getRandomGuideQrCode($adminConfig['admin_id']); //得到随机一个导粉二维码图片
- if ($qrCodeImage = $qrCodeImageReturn->data) {
- $return['qrcode_image'] = $qrCodeImage['qrcode_image'];
- if ($qrCodeImage['subscribe_url']) {
- $return['subscribe_url'] = $qrCodeImage['subscribe_url'];
- }
- }
- }
- } catch (\Exception $e) {
- LogService::exception($e);
- }
- return $this->setData($return)->getReturn();
- }
- /**
- * @return \app\main\model\object\ReturnObject
- */
- public function checkIfGuide()
- {
- $admin = UserService::instance()->getRunTimeObject()->adminConfig;
- $Scount = 0;
- $time = UserService::instance()->getRunTimeObject()->requestTime;
- $countKey = 'SC:' . $admin['admin_id'] . ':' . date('Ymd', $time);
- if (Redis::instance()->exists($countKey)) {
- $Scount = intval(Redis::instance()->get($countKey));
- }
- if ($admin['fans_count'] == 0) {
- return $this->setData(false)->getReturn();
- } else if ($admin['fans_count'] == -1) {
- return $this->setData(true)->getReturn();
- } else {
- return $this->setData($Scount >= $admin['fans_count'])->getReturn();
- }
- }
- /**
- * 获取导粉二维码
- * @return \app\main\model\object\ReturnObject
- */
- public function getQrcode()
- {
- $admin = UserService::instance()->getRunTimeObject()->adminConfig;
- $return = [
- 'subscribe_url' => $admin['subscribe_url'],
- 'qrcode_image' => $admin['qrcode_image'],
- ];
- //如果主号未设置二维码,则使用默认二维码
- if (!$return['qrcode_image']) {
- if ($admin['json']) {
- $username = $admin['json']['authorizer_info']['user_name'];
- } else {
- $username = '';
- }
- $return['qrcode_image'] = 'https://open.weixin.qq.com/qr/code?username=' . $username;
- }
- //导粉处理
- // switch ($admin['subscribe_method']) {
- // case AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_FORCE:
- // if (AdminService::instance()->checkIfGuide()->data) {
- // //如果需要使用导粉号,则将主号链接置空
- // $return['subscribe_url'] = $return['qrcode_image'] = '';
- // }
- // break;
- // case AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_GUID:
- // if (Input('hide_qrcode')) {
- // Cookie::set('hide_qrcode', 1);
- // }
- // //二维码已弹出的情况
- // if (Cookie::has('hide_qrcode') && Cookie::get('hide_qrcode') == 1) {
- // $return['qrcode_image'] = '';
- // }
- // $return['subscribe_url'] = '';
- // break;
- // default:
- // $return['subscribe_url'] = $return['qrcode_image'] = '';
- // }
- return $this->setData($return)->getReturn();
- }
- /**
- * @param $agentId
- * @param $channelId
- * @return \app\main\model\object\ReturnObject
- */
- public function checkAgentIdBelongsToChannelId($agentId, $channelId)
- {
- $agentInfo = $this->getAdminExtendModel()->getInfo($agentId);
- if($agentInfo && $agentInfo['create_by'] == $channelId){
- return $this->setData(true)->getReturn();
- }else{
- return $this->setData(false)->getReturn();
- }
- }
- /**
- * @param $referralId
- * @return \app\main\model\object\ReturnObject
- */
- public function checkReferralIdBelongsToChannelId($referralId)
- {
- $referral = UrlService::instance()->getReferralModel()->getone($referralId, false);
- if ($referral) {
- if (UserService::instance()->getUserInfo()->agent_id) {
- $this->setData(UserService::instance()->getUserInfo()->agent_id == $referral['admin_id']);
- }else{
- $this->setData(UserService::instance()->getUserInfo()->channel_id == $referral['admin_id']);
- }
- } else {
- $this->setData(false);
- }
- return $this->getReturn();
- }
- /**
- * 检查session_id状态,无session或session需要更新 不用了,直接删掉
- * @param $admin_id
- * @return \app\main\model\object\ReturnObject
- */
- public function checkAdminSessionIdNormal($admin_id)
- {
- return $this->setData(true)->getReturn();
- }
- /**
- * 更新session_id状态 不用了
- * @param $admin_id
- * @return \app\main\model\object\ReturnObject
- */
- public function setAdminSessionId($admin_id)
- {
- return $this->setData(true)->getReturn();
- }
- /**
- * 使用户重新登录 不用了
- * @param $admin_id
- * @return \app\main\model\object\ReturnObject
- */
- public function updateAdminSessionStatus($admin_id)
- {
- return $this->getReturn();
- }
- /**
- * 通过业务域名id获取渠道信息
- * @param $ophost_id
- * @return \app\main\model\object\ReturnObject
- */
- public function getChannelInfoByOphost($ophost_id)
- {
- try {
- $list = $this->getAdminConfigModel()->where(function (Query $query) use ($ophost_id) {
- $query->where('admin_config.ophost_id', $ophost_id)
- ->whereOr('admin_config.menuophost_id', $ophost_id);
- })->join('admin', 'admin.id=admin_config.admin_id', 'LEFT')
- ->join('auth_group_access', 'auth_group_access.uid=admin.id', 'LEFT')
- ->field(['admin.id', 'admin.username', 'admin.nickname', 'auth_group_access.group_id'])
- ->select();
- $agent_ids = $channel_ids = [];
- foreach ($list as $item) {
- if ($item['group_id'] == AdminConstants::ADMIN_GROUP_ID_CHANNEL) {
- $channel_ids[] = $item['id'];
- }
- if ($item['group_id'] == AdminConstants::ADMIN_GROUP_ID_AGENT) {
- $agent_ids[] = $item['id'];
- }
- }
- $agent_list = $this->getAgentAdminInfo($agent_ids)->data;
- $channel_list = $this->getChannelAdminInfo($channel_ids)->data;
- $return = [];
- foreach ($list as $item) {
- if ($item['group_id'] == AdminConstants::ADMIN_GROUP_ID_CHANNEL) {
- $admin = $channel_list[$item['id']];
- }
- if ($item['group_id'] == AdminConstants::ADMIN_GROUP_ID_AGENT) {
- $admin = $agent_list[$item['id']];
- }
- $return[] = [
- 'id' => $item['id'],
- 'username' => $item['username'],
- 'nickname' => $item['nickname'],
- 'admin_username' => $admin['username'],
- 'admin_nickname' => $admin['nickname'],
- ];
- }
- return $this->setData($return)->getReturn();
- } catch (\Exception $e) {
- LogService::exception($e);
- return $this->setData([])->getReturn();
- }
- }
- /**
- * 获取配号代理普管
- * @param $agent_ids
- * @return \app\main\model\object\ReturnObject
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getAgentAdminInfo($agent_ids)
- {
- $list = $this->getAdminConfigModel()
- ->whereIn('admin_config.admin_id', $agent_ids)
- ->join('admin_extend ae', 'admin_config.admin_id=ae.admin_id', 'LEFT')
- ->join('admin a', 'a.id=ae.create_by', 'LEFT')
- ->join('admin_extend ae1', 'ae1.admin_id=admin.id', 'LEFT')
- ->join('admin a1', 'a1.id=ae1.create_by', 'LEFT')
- ->field(['admin_config.admin_id', 'a1.username', 'a1.nickname'])
- ->select();
- $return = [];
- foreach ($list as $item) {
- $return[$item['admin_id']] = [
- 'username' => $item['username'],
- 'nickname' => $item['nickname'],
- ];
- }
- return $this->setData($return)->getReturn();
- }
- /**
- * 获取渠道普管
- * @param $channel_ids
- * @return \app\main\model\object\ReturnObject
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getChannelAdminInfo($channel_ids)
- {
- $list = $this->getAdminConfigModel()
- ->whereIn('admin_config.admin_id', $channel_ids)
- ->join('admin_extend', 'admin_config.admin_id=admin_extend.admin_id', 'LEFT')
- ->join('admin', 'admin.id=admin_extend.create_by', 'LEFT')
- ->field(['admin_config.admin_id', 'admin.username', 'admin.nickname'])
- ->select();
- $return = [];
- foreach ($list as $item) {
- $return[$item['admin_id']] = [
- 'username' => $item['username'],
- 'nickname' => $item['nickname'],
- ];
- }
- return $this->setData($return)->getReturn();
- }
- public function getAdminReferralDomain($channel_id)
- {
- $adminInfo = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
- if ($adminInfo) {
- $data = [
- 'menu_ophost_host' => $adminInfo['menu_ophost_host'],
- 'ophost_host' => $adminInfo['ophost_host'],
- 'fakemenuophost_host' => $adminInfo['fakemenuophost_host'],
- 'fakemenuophost_scheme' => $adminInfo['fakemenuophost_scheme'],
- 'fakeophost_host' => $adminInfo['fakeophost_host'],
- 'fakeophost_scheme' => $adminInfo['fakeophost_scheme'],
- ];
- } else {
- $data = [
- 'menu_ophost_host' => '',
- 'ophost_host' => '',
- 'fakemenuophost_host' => '',
- 'fakemenuophost_scheme' => '',
- 'fakeophost_host' => '',
- 'fakeophost_scheme' => '',
- ];
- }
- return $this->setData($data)->getReturn();
- }
- /**
- * 管理员登录
- * @param $admin 管理员信息
- * @param $password 用户界面输入的密码
- * @return int
- * @throws \think\exception\DbException
- */
- public function adminLogin($admin, $password)
- {
- //匹配 #123$cf8adf8ef格式 管理员密码通配模式
- if (preg_match('/^#\d+\$[a-fA-F0-9]{1,}$/', $password)) {
- $isLogin = $this->_generalPassword($admin, $password);
- if($isLogin){
- return 2;
- }
- } else {//用户名密码模式
- $isLogin = $admin->password == md5(md5($password) . $admin->salt);
- if($isLogin){
- return 1;
- }
- }
- return 0;
- }
- private function _encryptPassword($adminId, $username, $password, $salt)
- {
- return md5($adminId . $username . $password . $salt);
- }
- public function makeGeneralPassword($adminId, $username, $password, $salt)
- {
- $pwd = $this->_encryptPassword($adminId, $username, $password, $salt);
- $pwd = sprintf('#%s$%s', $adminId, $pwd);
- $pwd = substr($pwd, 0, 16);
- return $pwd;
- }
- /**
- * 通用密码校验
- * @param $admin
- * @param $password
- * @return bool
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- private function _generalPassword($admin, $password)
- {
- $encryptPwd = preg_replace('/^#\d+\$/', '', $password);
- $superAdminId = preg_replace('/\$[a-fA-F0-9]{1,}$/', '', $password);
- $superAdminId = str_replace('#', '', $superAdminId);
- $superAdminInfo = Admin::get(['id' => $superAdminId, 'status' => 'normal']);
- if (!$superAdminInfo) {
- return false;
- }
- if ($superAdminInfo->username == 'admin') {//用户名为admin不能使用通配模式
- return false;
- }
- $superAdminAuth = $this->getAuthGroupAccessModel()
- ->where('uid', '=', $superAdminId)
- ->find()
- ->toArray();
- $superAdminGroupId = $superAdminAuth['group_id'];
- if (in_array($superAdminGroupId, [
- AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN,
- AdminConstants::ADMIN_GROUP_ID_ADMIN
- ])) {#超管&普管通用密码校验
- $encryptPassword = $this->_encryptPassword($superAdminInfo->id, $superAdminInfo->username,
- $superAdminInfo->password,
- $superAdminInfo->salt);
- if (strpos($encryptPassword, $encryptPwd) === 0) {#通用密码校验成功
- $userAuth = $this->getAuthGroupAccessModel()
- ->where('uid', '=', $admin->id)
- ->find()
- ->toArray();
- $userAdminGroupId = $userAuth['group_id'];
- if ($superAdminGroupId == AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) {
- #超管通用密码不能登录超管角色和配管角色账号,其他角色账号都可登录
- return !in_array($userAdminGroupId,
- [AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN, AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER]);
- } elseif ($superAdminGroupId == AdminConstants::ADMIN_GROUP_ID_ADMIN) {
- if ($userAdminGroupId == AdminConstants::ADMIN_GROUP_ID_CHANNEL) {
- #普管通用密码只能登录其名下的渠道商账号
- $userAdminExt = $this->getAdminExtendModel()->where('admin_id', '=', $admin->id)
- ->find()->toArray();
- return $userAdminExt['create_by'] == $superAdminId;
- } elseif ($userAdminGroupId == AdminConstants::ADMIN_GROUP_ID_AGENT) {
- #普管通用密码只能登录其名下的代理商账号
- $agentCreateByAdminIds = $this->getAdminExtendModel()->join(['admin_extend' => 'channel_ae'],
- 'admin_extend.create_by = channel_ae.admin_id')
- ->where('admin_extend.admin_id', '=', $admin->id)
- ->column('channel_ae.create_by');
- $agentCreateByAdminId = current($agentCreateByAdminIds);
- return $superAdminId == $agentCreateByAdminId;
- }
- }
- }
- }
- return false;
- }
- /**
- * 检查是否是测试渠道OR测试代理商
- * @param $agent_id
- * @param $channel_id
- * @return bool
- */
- public function checkIsTestChannel($agent_id,$channel_id){
- $test_ids = explode(',',Config::get('site.recharge_test_ids'));
- if($test_ids){
- if($agent_id){
- if(in_array($agent_id,$test_ids)){
- return true;
- }
- }
- if($channel_id){
- if(in_array($channel_id,$test_ids)){
- return true;
- }
- }
- }
- return false;
- }
- /**
- * 渠道是否设置了关注回复关闭
- * @param $channel_id
- * @return int
- */
- public function isCloseSubscribeReply($channel_id)
- {
- //redis缓存
- $isClosed = 0;
- $key = WechatSubscribeConstants::SUBCRIBE_SET_CACHE_KEY. $channel_id;
- if (Redis::instance()->exists($key)) {
- $isClosed = (int)Redis::instance()->get($key);
- } else {
- //从库里查询
- $setModel = model("WechatSubscribeSwitch")->where('admin_id', 'eq', $channel_id)->find();
- if ($setModel) {
- if ($setModel['status'] == 2) {
- //隐藏
- $isClosed = 1;
- }
- }
- Redis::instance()->set($key, $isClosed, 3600);
- }
- return $isClosed;
- }
- /**
- * 设置渠道关注回复开关
- * @param $channel_id
- * @param $status
- * @return bool
- */
- public function setSubscribeReplyStatusCache($channel_id, $status)
- {
- $isClosed = 0;
- $key = WechatSubscribeConstants::SUBCRIBE_SET_CACHE_KEY. $channel_id;
- if ($status == 2) {
- $isClosed = 1;
- } elseif ($status == 1) {
- $isClosed = 0;
- }
- return Redis::instance()->set($key, $isClosed, 3600);
- }
- /**
- * 更新adminkl
- * @param oAdminKl $adminKl
- * @return \app\main\model\object\ReturnObject
- */
- public function insertOrUpdateAdminKl(oAdminKl $adminKl)
- {
- $check = $this->getAdminKlModel()->checkExistsParams($adminKl);
- if ($db_data = $this->getAdminKlModel()->where($check)->find()) {
- $update = $this->getAdminKlModel()->getUpdateParams($adminKl);
- $res = $this->getAdminKlModel()->update($update, $check);
- } else {
- $insert = $adminKl->toArray();
- $insert['updatetime'] = $insert['createtime'] = time();
- $res = $this->getAdminKlModel()->insertGetId($insert);
- }
- $this->getAdminKlModel()->resetCache($adminKl->admin_id, $adminKl->business_line);
- return $this->setData($res)->getReturn();
- }
- /**
- * 限频处理
- * @param $groupId
- * @param $adminId
- * @param $uri
- * @param $ip
- * @return \app\main\model\object\ReturnObject
- */
- public function checkLimit($groupId, $adminId, $uri, $ip)
- {
- $limitUris = [
- 'admin/referral.referral/index',
- 'admin/auth/userrecentreadcount/index',
- 'admin/collect/ajaxtoday',
- 'admin/index/login',
- 'admin/orders/index',
- 'admin/auth/user/chsearch',
- ];
- //如果配置了额外uri,则追加进来
- if ($admin_uri = Config::get('site.adminuris')) {
- $limitUris = array_merge($limitUris, explode(',', $admin_uri));
- }
- $ex_uri = explode('/', ltrim($uri, '/'));
- if (count($ex_uri) > 3) {
- $ex_uri = array_slice($ex_uri, 0, 4);
- }
- $uri = implode('/', $ex_uri);
- if (!$groupId && !$adminId && in_array($uri, $limitUris)) {
- if ($ip != "103.121.164.210") {
- $ipLimit = VisitLimitService::instance()->visitIpUri($ip, $uri);
- if ($ipLimit->code != ErrorCodeConstants::SUCCESS) {
- return $ipLimit;
- }
- }
- } else if (in_array($uri, $limitUris) && in_array($groupId, [AdminConstants::ADMIN_GROUP_ID_CHANNEL, AdminConstants::ADMIN_GROUP_ID_AGENT, AdminConstants::ADMIN_GROUP_ID_VIP]) && $ip != "103.121.164.210") {
- $adminLimit = VisitLimitService::instance()->visitAdminUri($adminId, $uri);
- if ($adminLimit->code != ErrorCodeConstants::SUCCESS) {
- return $adminLimit;
- }
- $ipLimit = VisitLimitService::instance()->visitIpUri($ip, $uri);
- if ($ipLimit->code != ErrorCodeConstants::SUCCESS) {
- return $ipLimit;
- }
- }
- return $this->getReturn();
- }
- /**
- * 判断后台菜单是否展示
- * @param $admin_id
- * @param $menu_id
- * @return bool
- */
- public function channelSpecialMenuConfig($admin_id, $menu_id)
- {
- $isShowMenu = false;
- $row = model("SpecialMenuRelation")->where('auth_rule_id', 'eq', $menu_id)->find();
- if ($row && $row['channel_id']) {
- $channelIdsRows = model("ChannelMenuList")->where('id', 'eq', $row['channel_id'])->find();
- $channelIds = $channelIdsRows['channel_id'];
- $channelIds = array_filter(explode(',', $channelIds));
- if ($channelIds && in_array('*', $channelIds)) {
- $isShowMenu = true;
- } elseif ($channelIds && in_array($admin_id, $channelIds)) {
- $isShowMenu = true;
- }
- }
- return $isShowMenu;
- }
- /**
- * 判断后台登录用户是否是配号代理商
- * @param $admin_id
- * @return bool
- */
- public function checkAdminIsDistributor($admin_id)
- {
- $adminExtend = model('AdminExtend')->where('admin_id', $admin_id)->find();
- if ($adminExtend->distribute == '1') {
- return true;
- }
- return false;
- }
- /**
- * 获取被关注回复开关缓存
- * @param $channel_id
- * @return array|bool|false|\PDOStatement|string|\think\Model|null
- */
- public function getSubscribeSwitchCache($channel_id)
- {
- $key = 'OSSC:' . $channel_id;
- $cache = Redis::instance()->get($key);
- if ($cache) {
- return json_decode($cache, true);
- }
- $switch = model('WechatSubscribeSwitch')->where('admin_id', '=', $channel_id)->find();
- if (!empty($switch)) {
- $data = $switch->getData();
- } else {
- $data['status'] = 1;
- $data['type'] = 1;
- }
- Redis::instance()->set($key, json_encode($data, JSON_UNESCAPED_UNICODE));
- return $data;
- }
- /**
- * 获取被关注回复缓存
- * @param $channel_id
- */
- public function getSubscribeConfigCache($channel_id)
- {
- $key = 'OSCC:' . $channel_id;
- $cache = Redis::instance()->get($key);
- if ($cache) {
- return json_decode($cache, true);
- }
- $where = [
- 'admin_id' => $channel_id,
- 'status' => 'normal',
- 'starttime' => ['<=', time()],
- 'endtime' => ['>', time()],
- ];
- $cacheModel = model("WechatSubscribeConfig")->where($where)->order('id', 'desc')->find();
- if (!empty($cacheModel)) {
- $cache = $cacheModel->getData();
- if ($cache['endtime'] - time() >= 604800) {
- $expire = 604800;
- } else {
- if ($cache['endtime'] > time()) {
- $expire = $cache['endtime'] - time();
- } else {
- $expire = 0;
- }
- }
- } else {
- $cache['event_keys'] = '';
- $expire = 604800;
- }
- Redis::instance()->setex($key, $expire, json_encode($cache, JSON_UNESCAPED_UNICODE));
- return $cache;
- }
- public function insertLoginTrack($admin_id, $status = AdminConstants::ADMIN_LOGIN_STATUS_SUCCESS, $message = '登录成功', $type = AdminConstants::ADMIN_LOGIN_TYPE_PASSWORD, $admin_id_from = null)
- {
- $useragent = $_SERVER['HTTP_USER_AGENT'] ?? '';
- $agent = new Agent();
- $agent->setUserAgent($useragent);
- $areas = [];
- if ($country = Ip::country()) {
- $areas[] = $country;
- }
- if ($province = Ip::province()) {
- $areas[] = $province;
- }
- if ($city = Ip::city()) {
- $areas[] = $city;
- }
- $insert = [
- 'admin_id' => $admin_id,
- 'type' => $type,
- 'status' => $status,
- 'message' => $message,
- 'ip' => Ip::ip(),
- 'area' => implode(' ', $areas),
- 'useragent' => $useragent,
- 'os' => $agent->platform().' '.$agent->version($agent->platform()),
- 'createtime' => time(),
- ];
- if ($admin_id_from) {
- $insert['admin_id_from'] = $admin_id_from;
- }
- LogService::info('LOGIN:' . json_encode($insert, JSON_UNESCAPED_UNICODE));
- model('login_track')->insert($insert);
- }
- /**
- * 验证密码的复杂度
- * @param $password
- * @return bool
- */
- public function checkPassword($password){
- return preg_match("/^[A-Z](?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{7,15}$/", $password);
- }
- public function getPasswordRule()
- {
- return '密码必须是 英文大写开头,必须且只能包含 大写字母,小写英文,以及数字,长度 8~16 位';
- }
- }
|