浏览代码

banner等模板内容设置所有接口修改

duqinya 6 年之前
父节点
当前提交
6e032974b5

+ 13 - 3
app/Repositories/CmsContentTemplateRepository.php

@@ -35,9 +35,19 @@ class CmsContentTemplateRepository {
      */
     public function create($request)
     {
-        if($this->cmsContentTemplate->where(['city_id'=>$request['city_id'],'title'=>trim($request['title'])])->exists()){
-            throw new HttpException(500, '当前城市该模块已经存在');
-        }
+        $where = ['city_id'=>$request['city_id'],'title'=>trim($request['title'])];
+        $template = $this->cmsContentTemplate->where($where)->get();
+        foreach ($template->toArray() as $k=>$v){
+            if ($v['is_open']==1){
+                $template_id = $this->cmsContentTemplate->find($v['id']);
+                $template_id->is_open = 0;
+                $template_id->updated_at = date('Y-m-d H:i:s');
+                $res = $template_id->save();
+                if (!$res) {
+                    throw new HttpException(500, '模板状态修改失败');
+                }
+            }
+    }
 
         $subject = [
             'title' => $request['title'],

+ 38 - 6
app/Repositories/CmsContentTemplateSetRepository.php

@@ -23,6 +23,7 @@ class CmsContentTemplateSetRepository {
      */
     public function bannerSet($request)
     {
+        $banner_id = $request['id']??'';
             $rules = json_decode($request['rule'],true);
             if (is_array($rules)){
                 if (count($rules)>10) {
@@ -38,9 +39,17 @@ class CmsContentTemplateSetRepository {
                                 'area_type' => $request['area_type'],
                                 'status' => 0,
                             ];
-                            if (!$this->cmsContentTemplateSet->create($subject)) {
-                                throw new HttpException(500, '添加失败');
+                            if ($banner_id){
+                                $banners = $this->cmsContentTemplateSet->where('id',$banner_id)->update($subject);
+                                if (!$banners) {
+                                    throw new HttpException(500, '更新失败');
+                                }
+                            }else{
+                                if (!$this->cmsContentTemplateSet->create($subject)) {
+                                    throw new HttpException(500, '添加失败');
+                                }
                             }
+
                         }
                     }
             }else{
@@ -54,6 +63,7 @@ class CmsContentTemplateSetRepository {
      */
     public function advertisementSet($request)
     {
+        $advertisement_id = $request['id']??'';
             $subject = [
                 'tpl_id' => $request['tpl_id'],
                 'rule' => $request['rule'],
@@ -61,10 +71,18 @@ class CmsContentTemplateSetRepository {
                 'status' => 0,
             ];
 
-            if (!$this->cmsContentTemplateSet->create($subject)) {
-                throw new HttpException(500, '添加失败');
+            if ($advertisement_id){
+                $advertisement_ids = $this->cmsContentTemplateSet->where('id',$advertisement_id)->update($subject);
+                if (!$advertisement_ids) {
+                    throw new HttpException(500, '更新失败');
+                }
+            }else{
+                if (!$this->cmsContentTemplateSet->create($subject)) {
+                    throw new HttpException(500, '添加失败');
+                }
             }
 
+
     }
 
     /**
@@ -72,16 +90,23 @@ class CmsContentTemplateSetRepository {
      */
     public function floorSet($request)
     {
+        $floor_id = $request['id']??'';
             $subject = [
                 'tpl_id' => $request['tpl_id'],
                 'rule' => $request['rule'],
                 'area_type' => $request['area_type'],
                 'status' => 0,
             ];
-
+        if ($floor_id){
+            $floor_ids = $this->cmsContentTemplateSet->where('id',$floor_id)->update($subject);
+            if (!$floor_ids) {
+                throw new HttpException(500, '更新失败');
+            }
+        }else {
             if (!$this->cmsContentTemplateSet->create($subject)) {
                 throw new HttpException(500, '添加失败');
             }
+        }
 
     }
 
@@ -90,16 +115,23 @@ class CmsContentTemplateSetRepository {
      */
     public function categorySet($request)
     {
+        $category_id = $request['id']??'';
             $subject = [
                 'tpl_id' => $request['tpl_id'],
                 'rule' => $request['rule'],
                 'area_type' => $request['area_type'],
                 'status' => 0,
             ];
-
+        if ($category_id){
+            $category_ids = $this->cmsContentTemplateSet->where('id',$category_id)->update($subject);
+            if (!$category_ids) {
+                throw new HttpException(500, '更新失败');
+            }
+        }else {
             if (!$this->cmsContentTemplateSet->create($subject)) {
                 throw new HttpException(500, '添加失败');
             }
+        }
 
     }