Core.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. }
  23. # 图片处理
  24. protected function pic($data, $type = 't1')
  25. {
  26. //?imageView2/1/w/100/h/100/q/75
  27. $config = array
  28. (
  29. 'pic', 'content', 'contact', 'logo', 'top', 'img', 'link', 'background', 'audio_pic'
  30. );
  31. foreach ($config as $k => $v) {
  32. if (isset($data[$v]) && $data[$v]) {
  33. $data[$v] = $this->replacePic($data[$v], $type);
  34. }
  35. }
  36. return $data;
  37. }
  38. protected function replacePic($pic, $type = 't1')
  39. {
  40. $pic = Dever::pic($pic, $type);
  41. if (strstr($pic, 'http://')) {
  42. $pic = str_replace('http://', 'https://', $pic);
  43. }
  44. return $pic;
  45. }
  46. # 列表页里的数据 根据类型,解析内容
  47. protected function content($data, $content = false)
  48. {
  49. $type = $id = false;
  50. if (isset($data['type']) && isset($data['data_id'])) {
  51. $type = $data['type'];
  52. $id = $data['data_id'];
  53. }
  54. if ($type && $id) {
  55. $table = Dever::config('base')->type_table[$type];
  56. $info = Dever::db($table)->getOne($id);
  57. if ($info) {
  58. return $this->getInfo($type, $info, $content);
  59. } else {
  60. return array();
  61. }
  62. }
  63. return array();
  64. }
  65. protected function getInfo($type, $info, $content = false)
  66. {
  67. $info['type'] = $type;
  68. $info['data_id'] = $info['id'];
  69. if (isset($info['content']) && !$content) {
  70. unset($info['content']);
  71. }
  72. if (isset($info['pdate']) && $info['pdate'] > 0) {
  73. } else {
  74. $info['pdate'] = time();
  75. }
  76. $info['pdate'] = date('Y-m-d', $info['pdate']);
  77. if (isset($info['cate_id']) && $info['cate_id']) {
  78. $cate = Dever::db('content/cate')->one($info['cate_id']);
  79. $info['cate_name'] = $cate['name'];
  80. }
  81. if (isset($info['author_id']) && $info['author_id']) {
  82. $author = Dever::db('content/author')->one($info['author_id']);
  83. $info['author_name'] = $author['name'];
  84. }
  85. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  86. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  87. unset($info['num_add_view']);
  88. }
  89. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  90. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  91. unset($info['num_add_up']);
  92. }
  93. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  94. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  95. unset($info['num_add_user']);
  96. }
  97. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  98. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  99. unset($info['num_add_user']);
  100. }
  101. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  102. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  103. unset($info['num_add_ding']);
  104. }
  105. return $info;
  106. }
  107. protected function getSourceUid($error = true)
  108. {
  109. return Dever::load('invite/api')->getSourceUid($this->data['uid'], $error);
  110. }
  111. protected function log()
  112. {
  113. $input = Dever::json_encode(Dever::input());
  114. $url = Dever::url();
  115. Dever::log($url . '||' . $input, 'request');
  116. }
  117. }