Package.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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']);
  28. $this->success(1,$list);
  29. }
  30. //新增
  31. public function add(){
  32. $field = ['title','info','servicetype_id','images','days','price','oldprice','content','content_images'];
  33. $data = request_post_hub($field);
  34. $data['company_id'] = $this->auth->company_id;
  35. $data['createtime'] = time();
  36. $data['updatetime'] = time();
  37. $data['status'] = 1;
  38. Db::name('package')->insertGetId($data);
  39. $this->success('添加成功');
  40. }
  41. //上下架
  42. public function changestatus(){
  43. $id = input('id',0);
  44. $status = Db::name('package')->where('id',$id)->value('status');
  45. $new_status = $status == 1 ? 0 : 1;
  46. $info = Db::name('package')->where('id',$id)->update(['status'=>$new_status,'updatetime'=>time()]);
  47. $this->success();
  48. }
  49. //详情
  50. public function info(){
  51. $id = input('id',0);
  52. $info = Db::name('package')->where('id',$id)->find();
  53. $this->success(1,$info);
  54. }
  55. //编辑
  56. public function edit(){
  57. $id = input('id','');
  58. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  59. if(empty($check)){
  60. $this->error('不存在的套餐');
  61. }
  62. //
  63. $field = ['title','info','servicetype_id','images','days','price','oldprice','content','content_images'];
  64. $data = request_post_hub($field);
  65. $data['updatetime'] = time();
  66. Db::name('package')->where('id',$id)->update($data);
  67. $this->success('编辑成功');
  68. }
  69. //删除
  70. public function delete(){
  71. $id = input('id','');
  72. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  73. if(empty($check)){
  74. $this->error('不存在的套餐');
  75. }
  76. Db::name('package')->where('id',$id)->delete();
  77. $this->success('删除成功');
  78. }
  79. }