123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2020/4/1
- * Time: 下午3:26
- */
- namespace app\main\service;
- use app\common\library\Redis;
- use app\common\model\ExportFans;
- use app\main\constants\CacheConstants;
- use app\main\constants\ExportFansConstants;
- use think\Config;
- use think\Cookie;
- class ExportFansService extends BaseService
- {
- /**
- * @var ExportFansService
- */
- protected static $self = NULL;
- /**
- * @return ExportFansService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * @return ExportFans
- */
- public function getExportFansModel()
- {
- return model('export_fans');
- }
- public function checkFansReadToExport($channel_id, $user_id, $chapter_id)
- {
- $result = false;
- if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
- $cacheUser = CacheConstants::getExportFansUserCache($user_id);
- if ($user = Redis::instance()->hGetAll($cacheUser)) {
- if ($user['chapter'] != -1) {
- $chapter = explode(',', $user['chapter']);
- array_push($chapter, $chapter_id);
- $chapter = array_unique($chapter);
- $count = count($chapter);
- $chapter = implode(',', $chapter);
- if ($count == 2 || $count == 7) {
- $result = $this->getExportFansModel()->getOne($user['id']);
- }
- if($count < 7){
- Redis::instance()->hSet($cacheUser, 'chapter', $chapter);
- } else {
- Redis::instance()->hSet($cacheUser, 'chapter', '-1');
- }
- }
- }
- }
- return $this->setData($result)->getReturn();
- }
- public function checkFansPayToExport($channel_id, $user_id)
- {
- $result = false;
- if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
- $cacheUser = CacheConstants::getExportFansUserCache($user_id);
- if ($user = Redis::instance()->hGetAll($cacheUser)) {
- $result = $this->getExportFansModel()->getOne($user['id']);
- if ($result['pay_status'] == ExportFansConstants::PAY_STATUS_NO) {
- $result = false;
- }
- }
- }
- return $this->setData($result)->getReturn();
- }
- public function checkFansSignToExport($channel_id, $user_id)
- {
- $result = false;
- if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
- $cacheUser = CacheConstants::getExportFansUserCache($user_id);
- if ($user = Redis::instance()->hGetAll($cacheUser)) {
- $result = $this->getExportFansModel()->getOne($user['id']);
- }
- }
- return $this->setData($result)->getReturn();
- }
- /**
- * 是否导粉设置
- * @param $channel_id
- * @param $user_id
- * @return \app\main\model\object\ReturnObject
- */
- public function checkFansLead($channel_id, $user_id)
- {
- $result = false;
- if (model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
- $cacheUser = CacheConstants::getLeadUser($user_id);
- if ($data = Redis::instance()->hGetAll($cacheUser)) {
- $match = [];
- foreach ($data as $row) {
- $row = json_decode($row, true);
- if ($row['expire_time'] > time() && $row['start_time'] < time()) {
- $config = $this->getExportFansModel()->getOne($row['id']);
- if ($config && $config['status'] == '1') {
- $match[] = $config;
- }
- }
- }
- if ($match) {
- usort($match, function ($v1, $v2) {
- if ($v2['weigh'] > $v1['weigh']) {
- return true;
- }
- if ($v2['id'] > $v1['id']) {
- return true;
- }
- return false;
- });
- $result = array_shift($match);
- }
- }
- }
- return $this->setData($result)->getReturn();
- }
- }
|