Core.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /*
  17. # 定义全局的系统类型
  18. 'system_source' => array
  19. (
  20. 1 => 'H5',
  21. 2 => '安卓',
  22. 3 => 'ios',
  23. 4 => 'pc',
  24. 5 => '微信小程序',
  25. 6 => '微信公众号',
  26. ),
  27. */
  28. protected $system_source = 1;
  29. public function __construct()
  30. {
  31. $this->checkCode();
  32. # 获取当前的用户信息
  33. $this->token = Dever::input('token');
  34. $this->uid = 1;
  35. $this->user = $this->getUser($this->uid, $this->id);
  36. $this->user['id'] = $this->uid;
  37. $this->system_source = Dever::input('system_source', 1);
  38. }
  39. protected function getUser($uid, $collection_id)
  40. {
  41. return Dever::load('user/lib/info')->get($uid, $collection_id);
  42. }
  43. protected function checkInfo()
  44. {
  45. return Dever::db('collection/info')->one($this->id);
  46. }
  47. protected function checkCode()
  48. {
  49. $this->code = Dever::input('code');
  50. if ($this->code) {
  51. $code = Dever::decode($this->code, $this->key);
  52. $code = explode('_', $code);
  53. $this->id = $code[1];
  54. $this->parent_page_id = $code[2];
  55. $this->page_id = $code[3];
  56. $this->index = $code[4];
  57. $this->times = $code[5];
  58. if (isset($code[6]) && $code[6]) {
  59. $this->day = $code[6];
  60. } else {
  61. $this->day = 0;
  62. }
  63. if (isset($code[7]) && $code[7] && $code[7] != $this->uid) {
  64. $this->share_uid = $code[7];
  65. }
  66. } else {
  67. $this->id = Dever::input('id');
  68. }
  69. }
  70. protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)
  71. {
  72. if (Dever::project('invite')) {
  73. $invite = Dever::input('invite');
  74. $uid = Dever::load('invite/api')->getUid($invite);
  75. }
  76. if (!$day) {
  77. $day = $this->day;
  78. }
  79. if ($day) {
  80. if (strstr($day, '-')) {
  81. $day = str_replace('-', '', $day);
  82. }
  83. } else {
  84. $day = 0;
  85. }
  86. $key = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid;
  87. $code = Dever::encode($key, $this->key);
  88. return $code;
  89. }
  90. protected function getInfoCode()
  91. {
  92. # 获取最新的用户记录
  93. $where['info_id'] = $this->id;
  94. $where['uid'] = $this->uid;
  95. $record = Dever::db('user/record')->one($where);
  96. if ($record) {
  97. $parent_page_id = $record['parent_page_id'];
  98. $page_id = $record['page_id'];
  99. $times = $record['times_id'];
  100. $index = $record['index'];
  101. $day = $record['day'];
  102. } else {
  103. # 获取最新的章节页id
  104. $page_where['info_id'] = $this->id;
  105. $page_where = $this->getTimesId($page_where);
  106. $page = Dever::db('collection/page')->child($page_where);
  107. $parent_page_id = $page_id = 0;
  108. if ($page) {
  109. $parent_page_id = $page[0]['page_id'];
  110. $page_id = $page[0]['id'];
  111. } else {
  112. Dever::alert('内容还没有准备好');
  113. }
  114. $times = 0;
  115. if ($this->times) {
  116. $times = $this->times;
  117. }
  118. $index = 0;
  119. $day = 0;
  120. }
  121. # 获取code
  122. $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day);
  123. return $code;
  124. }
  125. # 获取时光id
  126. protected function getTimesId($where)
  127. {
  128. # 获取当前年份的最新的时光
  129. if (!$this->times) {
  130. $where['year'] = date('Y');
  131. $times = Dever::db('collection/times')->getNew($where);
  132. if ($times) {
  133. $this->times = $times['id'];
  134. }
  135. }
  136. if ($this->times) {
  137. $where['times_id'] = $this->times;
  138. }
  139. return $where;
  140. }
  141. # 获取按钮的样式
  142. protected function button($info)
  143. {
  144. $button = array(
  145. 'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;',
  146. 'color' => 'color:#fff',
  147. 'name' => array('入口', '排行榜')
  148. );
  149. $button['name'] = explode(',', $info['button']);
  150. if ($info['button_bgcolor'] && $info['button_bgjcolor']) {
  151. $button['bgcolor'] = 'background: linear-gradient(to right, '.$info['button_bgcolor'].','.$info['button_bgjcolor'].') !important;';
  152. }
  153. if ($info['button_ftcolor']) {
  154. $button['color'] = 'color:' . $info['button_ftcolor'];
  155. $button['bgcolor'] .= $button['color'];
  156. }
  157. return $button;
  158. }
  159. }