Core.php 5.0 KB

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