ExportFansService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2020/4/1
  6. * Time: 下午3:26
  7. */
  8. namespace app\main\service;
  9. use app\common\library\Redis;
  10. use app\common\model\ExportFans;
  11. use app\main\constants\CacheConstants;
  12. use app\main\constants\ExportFansConstants;
  13. use think\Config;
  14. use think\Cookie;
  15. class ExportFansService extends BaseService
  16. {
  17. /**
  18. * @var ExportFansService
  19. */
  20. protected static $self = NULL;
  21. /**
  22. * @return ExportFansService
  23. */
  24. public static function instance()
  25. {
  26. if (self::$self == NULL) {
  27. self::$self = new self();
  28. }
  29. return self::$self;
  30. }
  31. /**
  32. * @return ExportFans
  33. */
  34. public function getExportFansModel()
  35. {
  36. return model('export_fans');
  37. }
  38. public function checkFansReadToExport($channel_id, $user_id, $chapter_id)
  39. {
  40. $result = false;
  41. if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
  42. $cacheUser = CacheConstants::getExportFansUserCache($user_id);
  43. if ($user = Redis::instance()->hGetAll($cacheUser)) {
  44. if ($user['chapter'] != -1) {
  45. $chapter = explode(',', $user['chapter']);
  46. array_push($chapter, $chapter_id);
  47. $chapter = array_unique($chapter);
  48. $count = count($chapter);
  49. $chapter = implode(',', $chapter);
  50. if ($count == 2 || $count == 7) {
  51. $result = $this->getExportFansModel()->getOne($user['id']);
  52. }
  53. if($count < 7){
  54. Redis::instance()->hSet($cacheUser, 'chapter', $chapter);
  55. } else {
  56. Redis::instance()->hSet($cacheUser, 'chapter', '-1');
  57. }
  58. }
  59. }
  60. }
  61. return $this->setData($result)->getReturn();
  62. }
  63. public function checkFansPayToExport($channel_id, $user_id)
  64. {
  65. $result = false;
  66. if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
  67. $cacheUser = CacheConstants::getExportFansUserCache($user_id);
  68. if ($user = Redis::instance()->hGetAll($cacheUser)) {
  69. $result = $this->getExportFansModel()->getOne($user['id']);
  70. if ($result['pay_status'] == ExportFansConstants::PAY_STATUS_NO) {
  71. $result = false;
  72. }
  73. }
  74. }
  75. return $this->setData($result)->getReturn();
  76. }
  77. public function checkFansSignToExport($channel_id, $user_id)
  78. {
  79. $result = false;
  80. if (Config::get('site.theme') == 'sf' && model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
  81. $cacheUser = CacheConstants::getExportFansUserCache($user_id);
  82. if ($user = Redis::instance()->hGetAll($cacheUser)) {
  83. $result = $this->getExportFansModel()->getOne($user['id']);
  84. }
  85. }
  86. return $this->setData($result)->getReturn();
  87. }
  88. /**
  89. * 是否导粉设置
  90. * @param $channel_id
  91. * @param $user_id
  92. * @return \app\main\model\object\ReturnObject
  93. */
  94. public function checkFansLead($channel_id, $user_id)
  95. {
  96. $result = false;
  97. if (model('ChannelSpecialManage')->isWhite('export_fans', $channel_id)) {
  98. $cacheUser = CacheConstants::getLeadUser($user_id);
  99. if ($data = Redis::instance()->hGetAll($cacheUser)) {
  100. $match = [];
  101. foreach ($data as $row) {
  102. $row = json_decode($row, true);
  103. if ($row['expire_time'] > time() && $row['start_time'] < time()) {
  104. $config = $this->getExportFansModel()->getOne($row['id']);
  105. if ($config && $config['status'] == '1') {
  106. $match[] = $config;
  107. }
  108. }
  109. }
  110. if ($match) {
  111. usort($match, function ($v1, $v2) {
  112. if ($v2['weigh'] > $v1['weigh']) {
  113. return true;
  114. }
  115. if ($v2['id'] > $v1['id']) {
  116. return true;
  117. }
  118. return false;
  119. });
  120. $result = array_shift($match);
  121. }
  122. }
  123. }
  124. return $this->setData($result)->getReturn();
  125. }
  126. }