Base.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Task\Lib;
  3. use Dever;
  4. use Passport\Src\User;
  5. use Passport\Src\Login;
  6. class Base
  7. {
  8. # 定义返回数据
  9. protected $data;
  10. public function __construct()
  11. {
  12. # 获取用户信息
  13. $user = new User();
  14. $this->user = $user->data();
  15. $config = Dever::db('main/config')->one();
  16. if ($config['avatar']) {
  17. $this->data['avatar'] = $config['avatar'];
  18. } else {
  19. $this->data['avatar'] = Dever::config('host', 'main')->assets . 'mobile/images/avatar.jpg';
  20. }
  21. $this->data['avatar'] =
  22. $this->data['config'] = Dever::db('main/config')->one(1);
  23. $this->data['time'] = time();
  24. $this->data['uid'] = -1;
  25. if ($this->user) {
  26. $this->data['uid'] = $this->user['id'];
  27. if (!$this->user['avatar']) {
  28. $this->user['avatar'] = $this->data['avatar'];
  29. }
  30. $this->user['avatar'] .= '?v=' . time();
  31. }
  32. }
  33. /**
  34. * 获取refer
  35. *
  36. * @return mixed
  37. */
  38. protected function refer()
  39. {
  40. $refer = Dever::input('refer');
  41. $project = 'main';
  42. if ($refer) {
  43. $refer = Dever::decode($refer);
  44. return $refer;
  45. } else {
  46. return Dever::url('home', $project);
  47. }
  48. }
  49. /**
  50. * 检测用户是否登录
  51. *
  52. * @return mixed
  53. */
  54. protected function checkLogin()
  55. {
  56. if ($this->data['uid'] <= 0) {
  57. # 需要登录
  58. $login = new Login();
  59. $login->location();
  60. }
  61. }
  62. /**
  63. * 检测用户信息
  64. *
  65. * @return mixed
  66. */
  67. protected function checkUser($state = false)
  68. {
  69. $this->checkLogin();
  70. $where['uid'] = $this->data['uid'];
  71. # 获取用户积分
  72. $this->data['user_score'] = Dever::db('task/user_score')->one($where);
  73. if (!$this->data['user_score']) {
  74. $refer = Dever::url();
  75. $qrcode = Dever::input('qrcode');
  76. $url = Dever::url('user/set?refer=' . Dever::encode($refer) . '&qrcode=' . $qrcode, 'main');
  77. Dever::location($url);
  78. /*
  79. $this->data['user_score'] = array();
  80. $this->data['user_score']['score'] = 0;
  81. $this->data['user_score']['uid'] = $where['uid'];
  82. $this->data['user_score']['id'] = Dever::db('task/user_score')->insert($this->data['user_score']);
  83. */
  84. }
  85. # 检测用户是否认证
  86. $this->data['user_info'] = Dever::db('task/user_info')->one($where);
  87. if ($this->data['user_info'] && $this->data['user_info']['status'] == 2) {
  88. # 已认证
  89. return true;
  90. } else {
  91. if ($state == true) {
  92. # 未认证 code = 110 就是需要认证,需要跳转到认证页面
  93. //Dever::alert('资料认证通过后才能领取任务', 110);
  94. }
  95. return false;
  96. }
  97. }
  98. public function token($request = array())
  99. {
  100. $request['uid'] = Dever::encode($this->data['uid']);
  101. return http_build_query(Dever::token($request));
  102. }
  103. public function url($method, $request = array())
  104. {
  105. return Dever::proxy($method, $this->token($request));
  106. }
  107. }