Usercoupon.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 用户优惠券
  7. */
  8. class Usercoupon extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //优惠券里列表
  13. public function lists(){
  14. $status = input('status',0);
  15. $where = [
  16. 'cu.user_id' => $this->auth->id,
  17. ];
  18. if($status == 0){
  19. //待使用
  20. $where['c.deletetime'] = NULL;
  21. $where['c.switch'] = 1;
  22. $where['c.starttime'] = ['<',time()];
  23. $where['c.endtime'] = ['>',time()];
  24. $where['cu.status'] = 0;
  25. }
  26. if($status == 1){
  27. //已使用
  28. $where['cu.status'] = 1;
  29. }
  30. if($status == 2){
  31. //已失效
  32. $where['c.deletetime'] = NULL;
  33. $where['c.switch'] = 1;
  34. $where['c.starttime'] = ['<',time()];
  35. $where['c.endtime'] = ['<',time()];
  36. $where['cu.status'] = 0;
  37. }
  38. $list = Db::name('unishop_coupon_user')->alias('cu')
  39. ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime','cu.status'])
  40. ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
  41. ->where($where)
  42. ->autopage()
  43. ->select();
  44. $this->success(1,$list);
  45. }
  46. }