Base.php 3.1 KB

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