Core.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace Main\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. protected $checkUser = false;
  7. protected $data;
  8. public function __construct()
  9. {
  10. # 获取用户信息
  11. if ($this->checkUser) {
  12. $this->data['uid'] = Dever::load('passport/applet')->check();
  13. } else {
  14. $this->data['uid'] = Dever::load('passport/applet')->check(false);
  15. }
  16. if ($this->data['uid'] < 0) {
  17. $this->data['uid'] = 0;
  18. }
  19. //$this->data['uid'] = 1;
  20. # 获取基本配置
  21. $key = 'config';
  22. $this->data['config'] = Dever::cache($key);
  23. if (!$this->data['config']) {
  24. $this->data['config'] = Dever::db('main/config')->one();
  25. Dever::cache($key, $this->data['config']);
  26. }
  27. $this->data['system'] = Dever::input('system', 1);
  28. $this->source_type = Dever::input('source_type');
  29. $this->app = false;
  30. if ($this->source_type == 'ios' || $this->source_type == 'android') {
  31. $this->app = true;
  32. }
  33. $this->data['ios_state'] = 2;
  34. $version_code = Dever::input('version_code');
  35. if ($version_code && $this->app) {
  36. $version_code = str_replace("\n", "", $version_code);
  37. $version_where['source_type'] = $this->source_type;
  38. $version_where['name'] = $version_code;
  39. $version = Dever::db('main/version')->getOne($version_where);
  40. if ($version && $version['vip'] > 0) {
  41. $this->data['ios_state'] = $version['vip'];
  42. }
  43. }
  44. }
  45. # 图片处理
  46. public function pic($data, $type = 't1')
  47. {
  48. //?imageView2/1/w/100/h/100/q/75
  49. $config = array
  50. (
  51. 'pic','pic_cover', 'pic_cover_169', 'content', 'share_pic'
  52. );
  53. foreach ($config as $k => $v) {
  54. if (isset($data[$v]) && $data[$v]) {
  55. $data[$v] = $this->replacePic($data[$v], $type);
  56. }
  57. }
  58. return $data;
  59. }
  60. public function replacePic($pic, $type = 't1')
  61. {
  62. //$pic = Dever::pic($pic, $type);
  63. if (strstr($pic, 'http://')) {
  64. $pic = str_replace('http://', 'https://', $pic);
  65. }
  66. return $pic;
  67. }
  68. # 列表页里的数据 根据类型,解析内容
  69. protected function content($data, $content = false)
  70. {
  71. $type = $id = false;
  72. if (isset($data['type']) && isset($data['data_id'])) {
  73. $type = $data['type'];
  74. $id = $data['data_id'];
  75. }
  76. if ($type && $id) {
  77. $table = Dever::config('base')->type_table[$type];
  78. //$info = Dever::db($table)->getOne($id);
  79. $info = Dever::db($table)->one($id);
  80. if ($info) {
  81. return $this->getInfo($type, $info, $content);
  82. } else {
  83. return array();
  84. }
  85. }
  86. return array();
  87. }
  88. protected function getInfo($type, $info, $content = false)
  89. {
  90. $info = $this->pic($info);
  91. $info['type'] = $type;
  92. $info['data_id'] = $info['id'];
  93. if (isset($info['content']) && !$content) {
  94. unset($info['content']);
  95. }
  96. if (isset($info['pdate']) && $info['pdate'] > 0) {
  97. } else {
  98. $info['pdate'] = time();
  99. }
  100. $info['cdate'] = $info['pdate'] = date('Y-m-d', $info['pdate']);
  101. //$info['cdate'] = date('Y-m-d', $info['cdate']);
  102. if (isset($info['cate_id']) && $info['cate_id']) {
  103. $cate = Dever::db('content/cate')->one($info['cate_id']);
  104. $info['cate_name'] = $cate['name'];
  105. }
  106. if (isset($info['author_id']) && $info['author_id']) {
  107. $author = Dever::db('content/author')->one($info['author_id']);
  108. $info['author_name'] = $author['name'];
  109. }
  110. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  111. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  112. unset($info['num_add_view']);
  113. }
  114. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  115. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  116. unset($info['num_add_up']);
  117. }
  118. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  119. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  120. unset($info['num_add_user']);
  121. }
  122. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  123. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  124. unset($info['num_add_user']);
  125. }
  126. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  127. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  128. unset($info['num_add_ding']);
  129. }
  130. if (isset($info['name']) && $info['name']) {
  131. $info['name'] = Dever::cut($info['name'], 20, '...');
  132. }
  133. return $info;
  134. }
  135. protected function getSourceUid($error = true)
  136. {
  137. return Dever::load('invite/api')->getSourceUid($this->data['uid'], $error);
  138. }
  139. protected function log()
  140. {
  141. $input = Dever::json_encode(Dever::input());
  142. $url = Dever::url();
  143. Dever::log($url . '||' . $input, 'request');
  144. }
  145. }