Package.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. ];
  25. if (!empty($servicetypeId)) {
  26. $where['servicetype_id'] = $servicetypeId;
  27. }
  28. if(!empty($keyword)){
  29. $where['p.title|p.info'] = ['LIKE','%'.$keyword.'%'];
  30. }
  31. $field = 'p.id,p.company_id,p.title,p.info,p.images,p.price,p.oldprice,type.title as servicetype_title';
  32. $list = Db::name('package')->alias('p')
  33. ->field($field)
  34. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  35. ->where($where)->order('p.id desc')->autopage()->select();
  36. $list = list_domain_image($list,['images']);
  37. $this->success('获取成功',$list);
  38. }
  39. //详情
  40. public function getInfo()
  41. {
  42. $id = input('id',0);
  43. $info = Db::name('package')->alias('p')
  44. ->field('p.*,type.title as servicetype_title')
  45. ->join('servicetype type','p.servicetype_id = type.id','LEFT')
  46. ->where('p.id',$id)->find();
  47. $afterTime = time() + 86400 * $info['days'];
  48. $info['days_text'] = !empty($info['days']) ? date('Y年m月d日', $afterTime) : '';
  49. $info = info_domain_image($info,['images','content_images']);
  50. $this->success(1,$info);
  51. }
  52. }