Base.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }
  21. }
  22. /**
  23. * 检测用户信息
  24. *
  25. * @return mixed
  26. */
  27. protected function checkUser($state = false)
  28. {
  29. if ($this->data['uid'] <= 0) {
  30. # 需要登录
  31. $login = new Login();
  32. $login->location();
  33. }
  34. $where['uid'] = $this->data['uid'];
  35. # 获取用户积分
  36. $this->data['user_score'] = Dever::db('task/user_score')->one($where);
  37. if (!$this->data['user_score']) {
  38. $this->data['user_score'] = array();
  39. $this->data['user_score']['num'] = 0;
  40. $this->data['user_score']['uid'] = $where['uid'];
  41. $this->data['user_score']['id'] = Dever::db('task/user_score')->insert($this->data['user_score']);
  42. }
  43. # 检测用户是否认证
  44. $this->data['user_info'] = Dever::db('task/user_info')->one($where);
  45. if ($this->data['user_info'] && $this->data['user_info']['status'] == 2) {
  46. # 已认证
  47. return true;
  48. } else {
  49. if ($state == true) {
  50. # 未认证 code = 110 就是需要认证,需要跳转到认证页面
  51. Dever::alert('资料认证通过后才能领取任务', 110);
  52. }
  53. return false;
  54. }
  55. }
  56. public function token($request)
  57. {
  58. return http_build_query(Dever::token($request));
  59. }
  60. public function url($method, $request)
  61. {
  62. return Dever::proxy($method, $this->token($request));
  63. }
  64. }