Base.php 3.1 KB

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