ChannelSpecialManageService.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * 渠道前台特殊功能
  4. * Created by: PhpStorm
  5. * User: lytian
  6. * Date: 2019/10/28
  7. * Time: 15:22
  8. */
  9. namespace app\main\service;
  10. use app\common\library\Redis;
  11. use app\main\constants\UserConstants;
  12. use app\main\model\object\UserObject;
  13. use think\Cache;
  14. use think\Exception;
  15. use think\Log;
  16. class ChannelSpecialManageService extends BaseService
  17. {
  18. /**
  19. * @var ChannelSpecialManageService
  20. */
  21. protected static $self = NULL;
  22. /**
  23. * @return ChannelSpecialManageService
  24. */
  25. public static function instance()
  26. {
  27. if (self::$self == NULL) {
  28. self::$self = new self();
  29. }
  30. return self::$self;
  31. }
  32. /**
  33. * 阅读页sell条
  34. * @param UserObject $userinfo
  35. * @return array
  36. */
  37. public function chapterSellBar(UserObject $userinfo)
  38. {
  39. $result = [0, [], []];
  40. if (true) {
  41. $channelId = $userinfo->channel_id;
  42. $cacheKey = 'BSA:'.$channelId;
  43. $data = Cache::get($cacheKey);
  44. if (true) {
  45. $isOpen = model("ChannelSpecialManage")->isWhite("read_sell", $channelId);
  46. $result = [$isOpen, [], []];
  47. $list = [];
  48. if (true) {
  49. //拉取配置的活动
  50. $time = time();
  51. $maps = [
  52. 'activity.admin_id' => 0,
  53. 'activity.status' => ['eq', '1'],
  54. // 'activity.starttime' => ['<=', $time],
  55. // 'activity.endtime' => ['>=', $time],
  56. 'activity.is_system' => 1,
  57. ];
  58. //系统活动前3条 固定 对号入座 第一条30元 第二条15元 第三天10元
  59. $activityRows = model("Activity")
  60. ->field("activity.id")
  61. //->field("activity.id, r.popimage")
  62. //->join("resource r", "activity.id = r.activity_id", "left")
  63. ->where($maps)
  64. ->order('activity.id', 'asc')
  65. ->limit(3)
  66. ->select();
  67. if ($activityRows) {
  68. foreach ($activityRows as $activityRow) {
  69. $list[] = [
  70. 'id' => $activityRow['id']
  71. ];
  72. }
  73. }
  74. Cache::set($cacheKey, json_encode($list, JSON_UNESCAPED_UNICODE), 300);
  75. } else {
  76. Cache::set($cacheKey, json_encode([], JSON_UNESCAPED_UNICODE), 300);
  77. }
  78. } else {
  79. $list = json_decode($data, true);
  80. }
  81. if ($list) {
  82. $icons = [
  83. [
  84. 'icon' => '6_1.png',
  85. 'uppop' => '6.png',
  86. ],
  87. [
  88. 'icon' => '5_1.png',
  89. 'uppop' => '5.png',
  90. ],
  91. [
  92. 'icon' => '4_1.png',
  93. 'uppop' => '4.png',
  94. ],
  95. ];
  96. //判断时间
  97. $today = strtotime(date("Ymd"));
  98. $yesterday = $today-86400;
  99. $secondday = $today-172800;
  100. if ($userinfo->createtime > $today) {
  101. $result = [1, [], []];
  102. } elseif ($userinfo->createtime > $yesterday && isset($list[0])) {
  103. $result = [1, $list[0], $icons[0]];
  104. } elseif ($userinfo->createtime > $secondday && isset($list[1])) {
  105. $result = [1, $list[1], $icons[1]];
  106. } else if (isset($list[2])) {
  107. $result = [1, $list[2], $icons[2]];
  108. }
  109. $result = [1, $list[2], $icons[2]];
  110. }
  111. }
  112. return $result;
  113. }
  114. /**
  115. * 获取关联的渠道ID, 全部渠道返回 * ,非全部渠道返回 1,2,3
  116. * 提供给JOB推送使用,一天调用一次,没有用缓存
  117. * @param $methodName
  118. * @return string
  119. */
  120. public function getChannelsByMethod($methodName)
  121. {
  122. $channels = '';
  123. $obj = model("ChannelSpecialManage")
  124. ->join('channel_menu_list', 'channel_special_manage.channel_id = channel_menu_list.id ', 'LEFT')
  125. ->where('channel_special_manage.rule_name', 'eq', $methodName)
  126. ->field('channel_menu_list.channel_id')
  127. ->find();
  128. if($obj){
  129. if($obj->channel_id == '*'){
  130. $channels = $obj->channel_id;
  131. }else{
  132. $channels = implode(',', array_filter(explode(',', $obj->channel_id)));
  133. }
  134. }
  135. return $channels;
  136. }
  137. }