Package.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $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')->alias('p')
  53. ->field('p.*,type.title as servicetype_title')
  54. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  55. ->where('p.id',$id)->find();
  56. $info = info_domain_image($info,['images','content_images']);
  57. $this->success(1,$info);
  58. }
  59. //编辑
  60. public function edit(){
  61. $id = input('id','');
  62. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  63. if(empty($check)){
  64. $this->error('不存在的套餐');
  65. }
  66. //
  67. $field = ['title','info','servicetype_id','images','days','price','oldprice','content','content_images'];
  68. $data = request_post_hub($field);
  69. $data['updatetime'] = time();
  70. Db::name('package')->where('id',$id)->update($data);
  71. $this->success('编辑成功');
  72. }
  73. //删除
  74. public function delete(){
  75. $id = input('id','');
  76. $check = Db::name('package')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  77. if(empty($check)){
  78. $this->error('不存在的套餐');
  79. }
  80. Db::name('package')->where('id',$id)->delete();
  81. $this->success('删除成功');
  82. }
  83. }