Package.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Package extends Api
  6. {
  7. protected $noNeedLogin = '*';
  8. protected $noNeedRight = '*';
  9. protected $model = null;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->model = Db::name('package');
  14. }
  15. //列表
  16. public function getList()
  17. {
  18. $servicetypeId = input('servicetype_id',0);
  19. $companyId = input('company_id',$this->auth->company_id);
  20. $keyword = input('keyword','');
  21. $where = [
  22. 'p.company_id' => $companyId,
  23. 'p.status' => 1,
  24. 'p.num' => ['gt',0],
  25. ];
  26. if (!empty($servicetypeId)) {
  27. $where['servicetype_id'] = $servicetypeId;
  28. }
  29. if(!empty($keyword)){
  30. $where['p.title|p.info'] = ['LIKE','%'.$keyword.'%'];
  31. }
  32. $field = 'p.id,p.company_id,p.title,p.info,p.images,p.price,p.oldprice,p.num,type.title as servicetype_title';
  33. $list = Db::name('package')->alias('p')
  34. ->field($field)
  35. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  36. ->where($where)->order('p.id desc')->autopage()->select();
  37. $list = list_domain_image($list,['images']);
  38. $this->success('获取成功',$list);
  39. }
  40. //详情
  41. public function getInfo()
  42. {
  43. $id = input('id',0);
  44. $where['p.id'] = $id;
  45. $where['p.num'] = ['gt',0];
  46. $info = Db::name('package')->alias('p')
  47. ->field('p.*,type.title as servicetype_title')
  48. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  49. ->where($where)->find();
  50. $info = info_domain_image($info,['images','content_images']);
  51. $this->success(1,$info);
  52. }
  53. }