123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * 渠道前台特殊功能
- * Created by: PhpStorm
- * User: lytian
- * Date: 2019/10/28
- * Time: 15:22
- */
- namespace app\main\service;
- use app\common\library\Redis;
- use app\main\constants\UserConstants;
- use app\main\model\object\UserObject;
- use think\Cache;
- use think\Exception;
- use think\Log;
- class ChannelSpecialManageService extends BaseService
- {
- /**
- * @var ChannelSpecialManageService
- */
- protected static $self = NULL;
- /**
- * @return ChannelSpecialManageService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * 阅读页sell条
- * @param UserObject $userinfo
- * @return array
- */
- public function chapterSellBar(UserObject $userinfo)
- {
- $result = [0, [], []];
- if (true) {
- $channelId = $userinfo->channel_id;
- $cacheKey = 'BSA:'.$channelId;
- $data = Cache::get($cacheKey);
- if (true) {
- $isOpen = model("ChannelSpecialManage")->isWhite("read_sell", $channelId);
- $result = [$isOpen, [], []];
- $list = [];
- if (true) {
- //拉取配置的活动
- $time = time();
- $maps = [
- 'activity.admin_id' => 0,
- 'activity.status' => ['eq', '1'],
- // 'activity.starttime' => ['<=', $time],
- // 'activity.endtime' => ['>=', $time],
- 'activity.is_system' => 1,
- ];
- //系统活动前3条 固定 对号入座 第一条30元 第二条15元 第三天10元
- $activityRows = model("Activity")
- ->field("activity.id")
- //->field("activity.id, r.popimage")
- //->join("resource r", "activity.id = r.activity_id", "left")
- ->where($maps)
- ->order('activity.id', 'asc')
- ->limit(3)
- ->select();
- if ($activityRows) {
- foreach ($activityRows as $activityRow) {
- $list[] = [
- 'id' => $activityRow['id']
- ];
- }
- }
- Cache::set($cacheKey, json_encode($list, JSON_UNESCAPED_UNICODE), 300);
- } else {
- Cache::set($cacheKey, json_encode([], JSON_UNESCAPED_UNICODE), 300);
- }
- } else {
- $list = json_decode($data, true);
- }
- if ($list) {
- $icons = [
- [
- 'icon' => '6_1.png',
- 'uppop' => '6.png',
- ],
- [
- 'icon' => '5_1.png',
- 'uppop' => '5.png',
- ],
- [
- 'icon' => '4_1.png',
- 'uppop' => '4.png',
- ],
- ];
- //判断时间
- $today = strtotime(date("Ymd"));
- $yesterday = $today-86400;
- $secondday = $today-172800;
- if ($userinfo->createtime > $today) {
- $result = [1, [], []];
- } elseif ($userinfo->createtime > $yesterday && isset($list[0])) {
- $result = [1, $list[0], $icons[0]];
- } elseif ($userinfo->createtime > $secondday && isset($list[1])) {
- $result = [1, $list[1], $icons[1]];
- } else if (isset($list[2])) {
- $result = [1, $list[2], $icons[2]];
- }
- $result = [1, $list[2], $icons[2]];
- }
- }
- return $result;
- }
- /**
- * 获取关联的渠道ID, 全部渠道返回 * ,非全部渠道返回 1,2,3
- * 提供给JOB推送使用,一天调用一次,没有用缓存
- * @param $methodName
- * @return string
- */
- public function getChannelsByMethod($methodName)
- {
- $channels = '';
- $obj = model("ChannelSpecialManage")
- ->join('channel_menu_list', 'channel_special_manage.channel_id = channel_menu_list.id ', 'LEFT')
- ->where('channel_special_manage.rule_name', 'eq', $methodName)
- ->field('channel_menu_list.channel_id')
- ->find();
- if($obj){
- if($obj->channel_id == '*'){
- $channels = $obj->channel_id;
- }else{
- $channels = implode(',', array_filter(explode(',', $obj->channel_id)));
- }
- }
- return $channels;
- }
- }
|