|
@@ -20,34 +20,22 @@ class Coupon extends Apic
|
|
|
$status = input('status',1);
|
|
|
|
|
|
$where = [
|
|
|
- 'company_id' => $this->auth->id,
|
|
|
- 'type' => 1,
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
+ 'status' => $status,
|
|
|
];
|
|
|
|
|
|
- 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'];
|
|
|
+ $field = ['name','info','days'];
|
|
|
$data = request_post_hub($field);
|
|
|
|
|
|
- $data['company_id'] = $this->auth->id;
|
|
|
- $data['type'] = 1;
|
|
|
- $data['score'] = 0;
|
|
|
- $data['stock'] = $data['number'];
|
|
|
+ $data['company_id'] = $this->auth->company_id;
|
|
|
$data['createtime'] = time();
|
|
|
- $data['updatetime'] = time();
|
|
|
+ $data['status'] = 1;
|
|
|
|
|
|
Db::name('coupons')->insertGetId($data);
|
|
|
$this->success('添加成功');
|
|
@@ -62,19 +50,16 @@ class Coupon extends Apic
|
|
|
//编辑
|
|
|
public function edit(){
|
|
|
$id = input('id','');
|
|
|
- $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find();
|
|
|
|
|
|
+ $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
|
|
|
if(empty($check)){
|
|
|
- $this->error('不存在的优惠券');
|
|
|
- }
|
|
|
- if($check['usetimestart'] < time()){
|
|
|
- $this->error('优惠券已经进行中,不能修改');
|
|
|
+ $this->error('不存在的卡券');
|
|
|
}
|
|
|
|
|
|
//
|
|
|
- $field = ['enough','amount','number','limit','usetimestart','usetimeend'];
|
|
|
+ $field = ['name','info','days'];
|
|
|
$data = request_post_hub($field);
|
|
|
- $data['stock'] = $data['number'];
|
|
|
+
|
|
|
$data['updatetime'] = time();
|
|
|
|
|
|
Db::name('coupons')->where('id',$id)->update($data);
|
|
@@ -84,16 +69,12 @@ class Coupon extends Apic
|
|
|
//删除
|
|
|
public function delete(){
|
|
|
$id = input('id','');
|
|
|
- $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->id)->find();
|
|
|
|
|
|
+ $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
|
|
|
if(empty($check)){
|
|
|
$this->error('不存在的优惠券');
|
|
|
}
|
|
|
|
|
|
- if($check['usetimestart'] < time()){
|
|
|
- $this->error('优惠券已经进行中,不能删除');
|
|
|
- }
|
|
|
-
|
|
|
Db::name('coupons')->where('id',$id)->delete();
|
|
|
$this->success('删除成功');
|
|
|
}
|