CmsContentTemplateRepository.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\CmsContentTemplate;
  4. use Symfony\Component\HttpKernel\Exception\HttpException;
  5. class CmsContentTemplateRepository {
  6. public function __construct(CmsContentTemplate $cmsContentTemplate) {
  7. $this->cmsContentTemplate = $cmsContentTemplate;
  8. }
  9. //模板列表
  10. public function index($request)
  11. {
  12. $where = [];
  13. if(isset($request['id'])){
  14. $where[] = ['id', '=', $request['id']];
  15. }
  16. if (isset($request['is_open'])){
  17. $where[] = ['is_open',$request['is_open']];
  18. }
  19. return $this->cmsContentTemplate->where($where)->orderBy('id', 'asc')->paginate(20);
  20. }
  21. /**
  22. * 新建模板
  23. */
  24. public function create($request)
  25. {
  26. if($this->cmsContentTemplate->where('title', trim($request['title']))->exists()){
  27. throw new HttpException(500, '该模块已经存在');
  28. }
  29. $subject = [
  30. 'title' => $request['title'],
  31. 'city_id' => $request['city_id'],
  32. 'city_name' => $request['city_name'],
  33. 'apply_type' => $request['apply_type'],
  34. 'is_open' => $request['is_open'],
  35. ];
  36. if (!$this->cmsContentTemplate->create($subject)) {
  37. throw new HttpException(500, '添加失败');
  38. }
  39. }
  40. }