$this->auth->id, 'type' => 1, ]; if($status == 1){ //未开始 $where['usetimestart'] = ['gt',time()]; }elseif($status == 2){ //进行中 $where['usetimestart'] = ['lt',time()]; $where['usetimeend'] = ['gt',time()]; }else{ //已结束 $where['usetimeend'] = ['lt',time()]; } $list = Db::name('coupons')->where($where)->order('id desc')->autopage()->select(); $this->success(1,$list); } //新增 public function add(){ $field = ['enough','amount','number','limit','usetimestart','usetimeend']; $data = request_post_hub($field); $data['company_id'] = $this->auth->id; $data['type'] = 1; $data['score'] = 0; $data['stock'] = $data['number']; $data['createtime'] = time(); $data['updatetime'] = time(); Db::name('coupons')->insertGetId($data); $this->success('添加成功'); } public function info(){ $id = input('id',0); $info = Db::name('coupons')->where('id',$id)->find(); $this->success(1,$info); } //编辑 public function edit(){ $id = input('id',''); $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find(); if(empty($check)){ $this->error('不存在的优惠券'); } if($check['usetimestart'] < time()){ $this->error('优惠券已经进行中,不能修改'); } // $field = ['enough','amount','number','limit','usetimestart','usetimeend']; $data = request_post_hub($field); $data['stock'] = $data['number']; $data['updatetime'] = time(); Db::name('coupons')->where('id',$id)->update($data); $this->success('编辑成功'); } //删除 public function delete(){ $id = input('id',''); $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find(); if(empty($check)){ $this->error('不存在的优惠券'); } if($check['usetimestart'] < time()){ $this->error('优惠券已经进行中,不能删除'); } Db::name('coupons')->where('id',$id)->delete(); $this->success('删除成功'); } }