Coupon.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 优惠券
  7. */
  8. class Coupon extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //优惠券管理
  13. public function lists(){
  14. $status = input('status',1);
  15. $where = [
  16. 'company_id' => $this->auth->company_id,
  17. 'status' => $status,
  18. ];
  19. $list = Db::name('coupons')->where($where)->order('id desc')->autopage()->select();
  20. $this->success(1,$list);
  21. }
  22. //新增
  23. public function add(){
  24. $field = ['name','info','days'];
  25. $data = request_post_hub($field);
  26. $data['company_id'] = $this->auth->company_id;
  27. $data['createtime'] = time();
  28. $data['status'] = 1;
  29. Db::name('coupons')->insertGetId($data);
  30. $this->success('添加成功');
  31. }
  32. public function info(){
  33. $id = input('id',0);
  34. $info = Db::name('coupons')->where('id',$id)->find();
  35. $this->success(1,$info);
  36. }
  37. //编辑
  38. public function edit(){
  39. $id = input('id','');
  40. $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  41. if(empty($check)){
  42. $this->error('不存在的卡券');
  43. }
  44. //
  45. $field = ['name','info','days'];
  46. $data = request_post_hub($field);
  47. $data['updatetime'] = time();
  48. Db::name('coupons')->where('id',$id)->update($data);
  49. $this->success('编辑成功');
  50. }
  51. //删除
  52. public function delete(){
  53. $id = input('id','');
  54. $check = Db::name('coupons')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  55. if(empty($check)){
  56. $this->error('不存在的优惠券');
  57. }
  58. Db::name('coupons')->where('id',$id)->delete();
  59. $this->success('删除成功');
  60. }
  61. }