Package.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 套餐管理
  7. */
  8. class Package extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //列表
  13. public function lists(){
  14. $status = input('status',1);
  15. $keyword = input('keyword','');
  16. $where = [
  17. 'p.company_id' => $this->auth->company_id,
  18. 'p.status' => $status,
  19. ];
  20. if(!empty($keyword)){
  21. $where['p.title|p.info'] = ['LIKE','%'.$keyword.'%'];
  22. }
  23. $list = Db::name('package')->alias('p')
  24. ->field('p.*,type.title as servicetype_title')
  25. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  26. ->where($where)->order('p.id desc')->autopage()->select();
  27. $list = list_domain_image($list,['images','content_images']);
  28. $this->success(1,$list);
  29. }
  30. //新增
  31. public function add(){
  32. //验证
  33. if($this->auth->type != 1){
  34. $this->error('只有门店老板才能设置');
  35. }
  36. $field = ['title','info','servicetype_id','images','price','oldprice','num','content','content_images'];
  37. $data = request_post_hub($field);
  38. $data['company_id'] = $this->auth->company_id;
  39. $data['createtime'] = time();
  40. $data['updatetime'] = time();
  41. $data['status'] = 1;
  42. Db::name('package')->insertGetId($data);
  43. $this->success('添加成功');
  44. }
  45. //上下架
  46. public function changestatus(){
  47. //验证
  48. if($this->auth->type != 1){
  49. $this->error('只有门店老板才能设置');
  50. }
  51. $id = input('id',0);
  52. $status = Db::name('package')->where('id',$id)->value('status');
  53. $new_status = $status == 1 ? 0 : 1;
  54. $info = Db::name('package')->where('id',$id)->update(['status'=>$new_status,'updatetime'=>time()]);
  55. $this->success();
  56. }
  57. //详情
  58. public function info(){
  59. $id = input('id',0);
  60. $info = Db::name('package')->alias('p')
  61. ->field('p.*,type.title as servicetype_title')
  62. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  63. ->where('p.id',$id)->find();
  64. $info = info_domain_image($info,['images','content_images']);
  65. $this->success(1,$info);
  66. }
  67. //编辑
  68. public function edit(){
  69. //验证
  70. if($this->auth->type != 1){
  71. $this->error('只有门店老板才能设置');
  72. }
  73. $id = input('id','');
  74. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->lock(true)->find();
  75. if(empty($check)){
  76. $this->error('不存在的套餐');
  77. }
  78. //
  79. $field = ['title','info','servicetype_id','images','price','oldprice','num','content','content_images'];
  80. $data = request_post_hub($field);
  81. $data['updatetime'] = time();
  82. Db::name('package')->where('id',$id)->update($data);
  83. $this->success('编辑成功');
  84. }
  85. //删除
  86. public function delete(){
  87. //验证
  88. if($this->auth->type != 1){
  89. $this->error('只有门店老板才能设置');
  90. }
  91. $id = input('id','');
  92. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  93. if(empty($check)){
  94. $this->error('不存在的套餐');
  95. }
  96. Db::name('package')->where('id',$id)->delete();
  97. $this->success('删除成功');
  98. }
  99. }