Member.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Vip\Lib;
  3. use Dever;
  4. class Member
  5. {
  6. public function get($uid, $cate_id = 1)
  7. {
  8. if (is_array($uid)) {
  9. $user = $uid;
  10. } else {
  11. $user = Dever::db('passport/user')->one($uid);
  12. }
  13. if ($user['mobile']) {
  14. $where['mobile'] = $user['mobile'];
  15. $source_type = Dever::input('source_type');
  16. if ($source_type != 'ios' && $source_type != 'android') {
  17. $where['cate_id'] = $cate_id;
  18. }
  19. $member = Dever::db('vip/member')->one($where);
  20. if ($member) {
  21. if (time() > $member['end']) {
  22. # 已过期
  23. return -2;
  24. } else {
  25. return $member['end'];
  26. }
  27. }
  28. }
  29. # 未开通
  30. return -1;
  31. }
  32. public function getEnd($time, $type, $start)
  33. {
  34. $key = 'days';
  35. if ($type == 1) {
  36. $key = 'days';
  37. } elseif ($type == 2) {
  38. $key = 'weeks';
  39. } elseif ($type == 3) {
  40. $key = 'months';
  41. } elseif ($type == 4) {
  42. $key = 'years';
  43. }
  44. $value = strtotime('+' . $time . $key, $start);
  45. return $value;
  46. }
  47. public function test_api()
  48. {
  49. $time = Dever::input('time');
  50. $type = Dever::input('type');
  51. $start = time();
  52. $value = $this->getEnd($time, $type, $start);
  53. return date('Y-m-d H:i:s', $value);
  54. }
  55. }