Core.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $this->data['uid'] = 1;
  17. # 获取基本配置
  18. $this->data['config'] = Dever::db('main/config')->one();
  19. }
  20. # 列表页里的数据 根据类型,解析内容
  21. protected function content($data, $content = false)
  22. {
  23. $type = $id = false;
  24. if (isset($data['type']) && isset($data['data_id'])) {
  25. $type = $data['type'];
  26. $id = $data['data_id'];
  27. }
  28. if ($type && $id) {
  29. $table = Dever::config('base')->type_table[$type];
  30. $info = Dever::db($table)->getOne($id);
  31. if ($info) {
  32. return $this->getInfo($type, $info, $content);
  33. } else {
  34. return (object) array();
  35. }
  36. }
  37. return (object) array();
  38. }
  39. protected function getInfo($type, $info, $content = false)
  40. {
  41. $info['type'] = $type;
  42. $info['data_id'] = $info['id'];
  43. if (isset($info['content']) && !$content) {
  44. unset($info['content']);
  45. }
  46. if (isset($info['pdate']) && $info['pdate'] > 0) {
  47. } else {
  48. $info['pdate'] = time();
  49. }
  50. $info['pdate'] = date('Y-m-d', $info['pdate']);
  51. if (isset($info['cate_id']) && $info['cate_id']) {
  52. $cate = Dever::db('content/cate')->one($info['cate_id']);
  53. $info['cate_name'] = $cate['name'];
  54. }
  55. if (isset($info['author_id']) && $info['author_id']) {
  56. $author = Dever::db('content/author')->one($info['author_id']);
  57. $info['author_name'] = $author['name'];
  58. }
  59. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  60. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  61. unset($info['num_add_view']);
  62. }
  63. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  64. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  65. unset($info['num_add_up']);
  66. }
  67. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  68. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  69. unset($info['num_add_user']);
  70. }
  71. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  72. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  73. unset($info['num_add_user']);
  74. }
  75. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  76. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  77. unset($info['num_add_ding']);
  78. }
  79. return $info;
  80. }
  81. protected function log()
  82. {
  83. $input = Dever::json_encode(Dever::input());
  84. $url = Dever::url();
  85. Dever::log($url . '||' . $input, 'request');
  86. }
  87. }