AppGuideService.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gaobo
  5. * Date: 2019/08/13
  6. * Time: 下午4:39
  7. */
  8. namespace app\main\service;
  9. use app\common\library\Redis;
  10. use app\common\library\Ua;
  11. use app\common\model\GuideManage;
  12. use app\main\constants\MqConstants;
  13. use app\main\model\object\DotObject;
  14. class AppGuideService extends BaseService
  15. {
  16. /**
  17. * @var AppGuideService
  18. */
  19. protected static $self = NULL;
  20. /**
  21. * @return AppGuideService
  22. */
  23. public static function instance()
  24. {
  25. if (self::$self == NULL) {
  26. self::$self = new self();
  27. }
  28. return self::$self;
  29. }
  30. /**
  31. * @return GuideManage
  32. */
  33. public function getGuideManageModel()
  34. {
  35. return model('GuideManage');
  36. }
  37. /**
  38. * 获取导量APP信息
  39. * @param $channel_id
  40. * @return mixed
  41. */
  42. public function getAppGuideInfo($channel_id)
  43. {
  44. $redis = Redis::instance();
  45. $redis_key = 'APPGUIDE:' . $channel_id;
  46. $data = [];
  47. if ($redis->exists($redis_key)) {
  48. $redis_key_type = $redis->type($redis_key);
  49. if($redis_key_type == \Redis::REDIS_STRING){
  50. return [];
  51. }else{
  52. $data = $redis->hGetAll($redis_key);
  53. }
  54. } else {
  55. $rst = $this->getGuideManageModel()->get(['channel_id' => $channel_id, 'state' => '1']);
  56. if ($rst) {
  57. $data = $rst->toarray();
  58. $redis->hMSet($redis_key, $data);
  59. $redis->expire($redis_key, 24 * 60 * 60);
  60. }else{
  61. $redis->set($redis_key, '0');
  62. $redis->expire($redis_key, 24 * 60 * 60);
  63. }
  64. }
  65. return $data;
  66. }
  67. /**
  68. * App引导入口, 访问UV 打点
  69. * @param $channel_id
  70. * @param $user_id
  71. * @param int $guide_idx
  72. * 1 => '文章头部引导位浏览量'
  73. * 2 => '文章底部引导位浏览量',
  74. * 3 => 'CODE码页面引导位浏览量'
  75. * 4 => '充值成功引导位浏览量',
  76. */
  77. public function appGuideViewDot($channel_id, $user_id, $guide_idx = 1)
  78. {
  79. $guideArr = $this->getAppGuideInfo($channel_id);
  80. if (count($guideArr) && (Ua::getOs() != "iOS")) {
  81. //发送打点数据
  82. $dotData = new DotObject();
  83. //打点信息初始化
  84. $dotData->channel_id = $channel_id;
  85. $dotData->user_id = $user_id;
  86. $dotData->event_time = time();
  87. $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
  88. $dotData->guide_idx = $guide_idx;
  89. $dotData->guide_op_type = MqConstants::APP_GUIDE_OP_TYPE_VIEW;
  90. MqService::instance()->sendMessage($dotData);
  91. }
  92. }
  93. /**
  94. * App引导入口,点击UV 打点
  95. * @param $channel_id
  96. * @param $user_id
  97. * @param int $guide_idx
  98. * 1 => '文章头部引导位浏览量'
  99. * 2 => '文章底部引导位浏览量',
  100. * 3 => 'CODE码页面引导位浏览量'
  101. * 4 => '充值成功引导位浏览量',
  102. */
  103. public function appGuideClickDot($channel_id, $user_id, $guide_idx = 1)
  104. {
  105. $guideArr = $this->getAppGuideInfo($channel_id);
  106. if (count($guideArr) && (Ua::getOs() != "iOS")) {
  107. //发送打点数据
  108. $dotData = new DotObject();
  109. //打点信息初始化
  110. $dotData->channel_id = $channel_id;
  111. $dotData->user_id = $user_id;
  112. $dotData->event_time = time();
  113. $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
  114. $dotData->guide_idx = $guide_idx;
  115. $dotData->guide_op_type = MqConstants::APP_GUIDE_OP_TYPE_CLICK;
  116. MqService::instance()->sendMessage($dotData);
  117. }
  118. }
  119. /**
  120. * 是否展示后台的菜单
  121. * @param $admin_id
  122. * @return bool
  123. */
  124. public function isShowAdminMenu($admin_id)
  125. {
  126. $show = false;
  127. //$row = $this->getGuideManageModel()->where('channel_id', 'EQ', $admin_id)->find();
  128. $row = $this->getAppGuideInfo($admin_id);
  129. if ($row) {
  130. $show = true;
  131. return $show;
  132. }
  133. //是否是代理
  134. $agentRow = model("AdminExtend")->where('admin_id', 'EQ', $admin_id)->find();
  135. if ($agentRow) {
  136. /*$where = [
  137. 'channel_id' => ['eq', $agentRow['create_by']],
  138. ];
  139. $res = $this->getGuideManageModel()->where($where)->find();
  140. */
  141. $res = $this->getAppGuideInfo($agentRow['create_by']);
  142. if ($res) {
  143. $show = true;
  144. return $show;
  145. }
  146. }
  147. //是否是VIP
  148. $slaveRows = model("VipAdminBind")->where("admin_id_master", 'EQ', $admin_id)->select();
  149. if ($slaveRows) {
  150. $ids = array_column($slaveRows, 'admin_id_slave');
  151. $where = [
  152. 'channel_id' => ['in', $ids],
  153. ];
  154. $res = $this->getGuideManageModel()->where($where)->find();
  155. if ($res) {
  156. $show = true;
  157. return $show;
  158. }
  159. }
  160. return $show;
  161. }
  162. }