Base.php 2.6 KB

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