12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\api\controller\company;
- use app\common\controller\Apic;
- use think\Db;
- /**
- * 优惠券
- */
- class Coupon extends Apic
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- //优惠券管理
- public function lists(){
- $status = input('status',1);
- $where = [
- 'company_id' => $this->auth->company_id,
- 'status' => $status,
- ];
- $list = Db::name('coupons')->where($where)->order('id desc')->autopage()->select();
- $this->success(1,$list);
- }
- //新增
- public function add(){
- $field = ['name','info','days'];
- $data = request_post_hub($field);
- $data['company_id'] = $this->auth->company_id;
- $data['createtime'] = time();
- $data['status'] = 1;
- 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->company_id)->find();
- if(empty($check)){
- $this->error('不存在的卡券');
- }
- //
- $field = ['name','info','days'];
- $data = request_post_hub($field);
- $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->company_id)->find();
- if(empty($check)){
- $this->error('不存在的优惠券');
- }
- Db::name('coupons')->where('id',$id)->delete();
- $this->success('删除成功');
- }
- }
|