Package.php 2.8 KB

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