CmsContentTemplateSetRepository.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\CmsContentTemplateSet;
  4. use Symfony\Component\HttpKernel\Exception\HttpException;
  5. class CmsContentTemplateSetRepository {
  6. public function __construct(CmsContentTemplateSet $cmsContentTemplateSet) {
  7. $this->cmsContentTemplateSet = $cmsContentTemplateSet;
  8. }
  9. /**
  10. * banner配置
  11. */
  12. public function create($request)
  13. {
  14. if ($request['rule'] && is_array($request['rule'])){
  15. $rules = json_decode($request['rule'],true);
  16. if (count($rules)>10) {
  17. throw new HttpException(500, '最多只能添加10个banner海报');
  18. }
  19. }else{
  20. throw new HttpException(500, '参数有误');
  21. }
  22. $subject = [
  23. 'tpl_id' => $request['tpl_id'],
  24. 'rule' => $request['rule'],
  25. 'area_type' => $request['area_type'],
  26. 'status' => $request['status'],
  27. ];
  28. if (!$this->cmsContentTemplateSet->create($subject)) {
  29. throw new HttpException(500, '添加失败');
  30. }
  31. }
  32. }