Core.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace Collection\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. protected $token;
  7. protected $uid;
  8. protected $share_uid = 0;
  9. protected $user;
  10. protected $year;
  11. protected $times;
  12. protected $day = 0;
  13. protected $parent_page_id;
  14. protected $page_id;
  15. protected $key = 'dreamland1985';
  16. public function __construct()
  17. {
  18. $this->checkCode();
  19. # 获取当前的用户信息
  20. $this->token = Dever::input('token');
  21. $this->uid = 1;
  22. $this->user = Dever::load('passport/api')->info($this->uid);
  23. }
  24. protected function checkInfo()
  25. {
  26. return Dever::db('collection/info')->one($this->id);
  27. }
  28. protected function checkCode()
  29. {
  30. $this->code = Dever::input('code');
  31. if ($this->code) {
  32. $code = Dever::decode($this->code, $this->key);
  33. $code = explode('_', $code);
  34. $this->id = $code[1];
  35. $this->parent_page_id = $code[2];
  36. $this->page_id = $code[3];
  37. $this->index = $code[4];
  38. $this->times = $code[5];
  39. if (isset($code[6]) && $code[6]) {
  40. $this->day = $code[6];
  41. } else {
  42. $this->day = 0;
  43. }
  44. if (isset($code[7]) && $code[7] && $code[7] != $this->uid) {
  45. $this->share_uid = $code[7];
  46. }
  47. } else {
  48. $this->id = Dever::input('id');
  49. }
  50. }
  51. protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)
  52. {
  53. if (Dever::project('invite')) {
  54. $invite = Dever::input('invite');
  55. $uid = Dever::load('invite/api')->getUid($invite);
  56. }
  57. if (!$day) {
  58. $day = $this->day;
  59. }
  60. if ($day) {
  61. if (strstr($day, '-')) {
  62. $day = str_replace('-', '', $day);
  63. }
  64. } else {
  65. $day = 0;
  66. }
  67. $key = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid;
  68. $code = Dever::encode($key, $this->key);
  69. return $code;
  70. }
  71. protected function getInfoCode()
  72. {
  73. # 获取最新的用户记录
  74. $where['info_id'] = $this->id;
  75. $where['uid'] = $this->uid;
  76. $record = Dever::db('collection/user_record')->one($where);
  77. if ($record) {
  78. $parent_page_id = $record['parent_page_id'];
  79. $page_id = $record['page_id'];
  80. $times = $record['times_id'];
  81. $index = $record['index'];
  82. $day = $record['day'];
  83. } else {
  84. # 获取最新的章节页id
  85. $page_where['info_id'] = $this->id;
  86. $page_where = $this->getTimesId($page_where);
  87. $page = Dever::db('collection/page')->child($page_where);
  88. $parent_page_id = $page_id = 0;
  89. if ($page) {
  90. $parent_page_id = $page[0]['page_id'];
  91. $page_id = $page[0]['id'];
  92. } else {
  93. Dever::alert('内容还没有准备好');
  94. }
  95. $times = 0;
  96. if ($this->times) {
  97. $times = $this->times;
  98. }
  99. $index = 0;
  100. $day = 0;
  101. }
  102. # 获取code
  103. $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day);
  104. return $code;
  105. }
  106. # 获取时光id
  107. protected function getTimesId($where)
  108. {
  109. # 获取当前年份的最新的时光
  110. if (!$this->times) {
  111. $where['year'] = date('Y');
  112. $times = Dever::db('collection/times')->getNew($where);
  113. if ($times) {
  114. $this->times = $times['id'];
  115. }
  116. }
  117. if ($this->times) {
  118. $where['times_id'] = $this->times;
  119. }
  120. return $where;
  121. }
  122. # 获取按钮的样式
  123. protected function button($info)
  124. {
  125. $button = array(
  126. 'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;',
  127. 'color' => 'color:#fff',
  128. 'name' => array('入口', '排行榜')
  129. );
  130. $button['name'] = explode(',', $info['button']);
  131. if ($info['button_bgcolor'] && $info['button_bgjcolor']) {
  132. $button['bgcolor'] = 'background: linear-gradient(to right, '.$info['button_bgcolor'].','.$info['button_bgjcolor'].') !important;';
  133. }
  134. if ($info['button_ftcolor']) {
  135. $button['color'] = 'color:' . $info['button_ftcolor'];
  136. $button['bgcolor'] .= $button['color'];
  137. }
  138. return $button;
  139. }
  140. }