123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gaobo
- * Date: 2019/08/13
- * Time: 下午4:39
- */
- namespace app\main\service;
- use app\common\library\Redis;
- use app\common\library\Ua;
- use app\common\model\GuideManage;
- use app\main\constants\MqConstants;
- use app\main\model\object\DotObject;
- class AppGuideService extends BaseService
- {
- /**
- * @var AppGuideService
- */
- protected static $self = NULL;
- /**
- * @return AppGuideService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * @return GuideManage
- */
- public function getGuideManageModel()
- {
- return model('GuideManage');
- }
- /**
- * 获取导量APP信息
- * @param $channel_id
- * @return mixed
- */
- public function getAppGuideInfo($channel_id)
- {
- $redis = Redis::instance();
- $redis_key = 'APPGUIDE:' . $channel_id;
- $data = [];
- if ($redis->exists($redis_key)) {
- $redis_key_type = $redis->type($redis_key);
- if($redis_key_type == \Redis::REDIS_STRING){
- return [];
- }else{
- $data = $redis->hGetAll($redis_key);
- }
- } else {
- $rst = $this->getGuideManageModel()->get(['channel_id' => $channel_id, 'state' => '1']);
- if ($rst) {
- $data = $rst->toarray();
- $redis->hMSet($redis_key, $data);
- $redis->expire($redis_key, 24 * 60 * 60);
- }else{
- $redis->set($redis_key, '0');
- $redis->expire($redis_key, 24 * 60 * 60);
- }
- }
- return $data;
- }
- /**
- * App引导入口, 访问UV 打点
- * @param $channel_id
- * @param $user_id
- * @param int $guide_idx
- * 1 => '文章头部引导位浏览量'
- * 2 => '文章底部引导位浏览量',
- * 3 => 'CODE码页面引导位浏览量'
- * 4 => '充值成功引导位浏览量',
- */
- public function appGuideViewDot($channel_id, $user_id, $guide_idx = 1)
- {
- $guideArr = $this->getAppGuideInfo($channel_id);
- if (count($guideArr) && (Ua::getOs() != "iOS")) {
- //发送打点数据
- $dotData = new DotObject();
- //打点信息初始化
- $dotData->channel_id = $channel_id;
- $dotData->user_id = $user_id;
- $dotData->event_time = time();
- $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
- $dotData->guide_idx = $guide_idx;
- $dotData->guide_op_type = MqConstants::APP_GUIDE_OP_TYPE_VIEW;
- MqService::instance()->sendMessage($dotData);
- }
- }
- /**
- * App引导入口,点击UV 打点
- * @param $channel_id
- * @param $user_id
- * @param int $guide_idx
- * 1 => '文章头部引导位浏览量'
- * 2 => '文章底部引导位浏览量',
- * 3 => 'CODE码页面引导位浏览量'
- * 4 => '充值成功引导位浏览量',
- */
- public function appGuideClickDot($channel_id, $user_id, $guide_idx = 1)
- {
- $guideArr = $this->getAppGuideInfo($channel_id);
- if (count($guideArr) && (Ua::getOs() != "iOS")) {
- //发送打点数据
- $dotData = new DotObject();
- //打点信息初始化
- $dotData->channel_id = $channel_id;
- $dotData->user_id = $user_id;
- $dotData->event_time = time();
- $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
- $dotData->guide_idx = $guide_idx;
- $dotData->guide_op_type = MqConstants::APP_GUIDE_OP_TYPE_CLICK;
- MqService::instance()->sendMessage($dotData);
- }
- }
- /**
- * 是否展示后台的菜单
- * @param $admin_id
- * @return bool
- */
- public function isShowAdminMenu($admin_id)
- {
- $show = false;
- //$row = $this->getGuideManageModel()->where('channel_id', 'EQ', $admin_id)->find();
- $row = $this->getAppGuideInfo($admin_id);
- if ($row) {
- $show = true;
- return $show;
- }
- //是否是代理
- $agentRow = model("AdminExtend")->where('admin_id', 'EQ', $admin_id)->find();
- if ($agentRow) {
- /*$where = [
- 'channel_id' => ['eq', $agentRow['create_by']],
- ];
- $res = $this->getGuideManageModel()->where($where)->find();
- */
- $res = $this->getAppGuideInfo($agentRow['create_by']);
- if ($res) {
- $show = true;
- return $show;
- }
- }
- //是否是VIP
- $slaveRows = model("VipAdminBind")->where("admin_id_master", 'EQ', $admin_id)->select();
- if ($slaveRows) {
- $ids = array_column($slaveRows, 'admin_id_slave');
- $where = [
- 'channel_id' => ['in', $ids],
- ];
- $res = $this->getGuideManageModel()->where($where)->find();
- if ($res) {
- $show = true;
- return $show;
- }
- }
- return $show;
- }
- }
|