12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Repositories;
- use App\Models\CmsContentTemplate;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- class CmsContentTemplateRepository {
- public function __construct(CmsContentTemplate $cmsContentTemplate) {
- $this->cmsContentTemplate = $cmsContentTemplate;
- }
- //模板列表
- public function index($request)
- {
- $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
- $where = [];
- if(isset($request['id'])){
- $where[] = ['id', '=', $request['id']];
- }
- if (isset($request['is_open'])){
- $where[] = ['is_open',$request['is_open']];
- }
- if (isset($request['city_id'])){
- $where[] = ['city_id',$request['city_id']];
- }
- return $this->cmsContentTemplate->where($where)->orderBy('id', 'asc')->paginate($perPage);
- }
- /**
- * 新建模板
- */
- public function create($request)
- {
- if($this->cmsContentTemplate->where('title', trim($request['title']))->exists()){
- throw new HttpException(500, '该模块已经存在');
- }
- $subject = [
- 'title' => $request['title'],
- 'city_id' => $request['city_id'],
- 'city_name' => $request['city_name'],
- 'apply_type' => $request['apply_type'],
- 'is_open' => $request['is_open'],
- ];
- if (!$this->cmsContentTemplate->create($subject)) {
- throw new HttpException(500, '添加失败');
- }
- }
- /**
- * 修改模板状态
- */
- public function edit($request)
- {
- $template = $this->cmsContentTemplate->find($request['id']);
- $template->is_open = $request['is_open'];
- $template->updated_at = date('Y-m-d H:i:s');
- $res = $template->save();
- if (!$res) {
- throw new HttpException(500, '修改状态失败');
- }
- }
- }
|