123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 用户优惠券
- */
- class Usercoupon extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //优惠券里列表
- public function lists(){
- $status = input('status',0);
- $where = [
- 'cu.user_id' => $this->auth->id,
- ];
- if($status == 0){
- //待使用
- $where['c.deletetime'] = NULL;
- $where['c.switch'] = 1;
- $where['c.starttime'] = ['<',time()];
- $where['c.endtime'] = ['>',time()];
- $where['cu.status'] = 0;
- }
- if($status == 1){
- //已使用
- $where['cu.status'] = 1;
- }
- if($status == 2){
- //已失效
- $where['c.deletetime'] = NULL;
- $where['c.switch'] = 1;
- $where['c.starttime'] = ['<',time()];
- $where['c.endtime'] = ['<',time()];
- $where['cu.status'] = 0;
- }
- $list = Db::name('unishop_coupon_user')->alias('cu')
- ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime','cu.status'])
- ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
- ->where($where)
- ->autopage()
- ->select();
- $this->success(1,$list);
- }
- }
|