Base.php 3.0 KB

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