Core.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 content($data, $content = false)
  25. {
  26. $type = $id = false;
  27. if (isset($data['type']) && isset($data['data_id'])) {
  28. $type = $data['type'];
  29. $id = $data['data_id'];
  30. }
  31. if ($type && $id) {
  32. $table = Dever::config('base')->type_table[$type];
  33. $info = Dever::db($table)->getOne($id);
  34. if ($info) {
  35. return $this->getInfo($type, $info, $content);
  36. } else {
  37. return array();
  38. }
  39. }
  40. return array();
  41. }
  42. protected function getInfo($type, $info, $content = false)
  43. {
  44. $info['type'] = $type;
  45. $info['data_id'] = $info['id'];
  46. if (isset($info['content']) && !$content) {
  47. unset($info['content']);
  48. }
  49. if (isset($info['pdate']) && $info['pdate'] > 0) {
  50. } else {
  51. $info['pdate'] = time();
  52. }
  53. $info['pdate'] = date('Y-m-d', $info['pdate']);
  54. if (isset($info['cate_id']) && $info['cate_id']) {
  55. $cate = Dever::db('content/cate')->one($info['cate_id']);
  56. $info['cate_name'] = $cate['name'];
  57. }
  58. if (isset($info['author_id']) && $info['author_id']) {
  59. $author = Dever::db('content/author')->one($info['author_id']);
  60. $info['author_name'] = $author['name'];
  61. }
  62. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  63. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  64. unset($info['num_add_view']);
  65. }
  66. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  67. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  68. unset($info['num_add_up']);
  69. }
  70. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  71. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  72. unset($info['num_add_user']);
  73. }
  74. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  75. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  76. unset($info['num_add_user']);
  77. }
  78. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  79. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  80. unset($info['num_add_ding']);
  81. }
  82. return $info;
  83. }
  84. protected function getSourceUid($error = true)
  85. {
  86. return Dever::load('invite/api')->getSourceUid($this->data['uid'], $error);
  87. }
  88. protected function log()
  89. {
  90. $input = Dever::json_encode(Dever::input());
  91. $url = Dever::url();
  92. Dever::log($url . '||' . $input, 'request');
  93. }
  94. }