Base.php 2.8 KB

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