Sfoglia il codice sorgente

Merge branch 'develop'

xielin 6 anni fa
parent
commit
1a8816c5bd
1 ha cambiato i file con 30 aggiunte e 16 eliminazioni
  1. 30 16
      app/Repositories/CmsContentTemplateSetRepository.php

+ 30 - 16
app/Repositories/CmsContentTemplateSetRepository.php

@@ -27,6 +27,7 @@ class CmsContentTemplateSetRepository {
     {
         $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
         $templates = $template->toArray();
+//        var_dump($templates);die;
         $where = [
             'city_id'=>$templates['city_id'],
             'apply_type'=>$templates['apply_type'],
@@ -72,12 +73,14 @@ class CmsContentTemplateSetRepository {
                             if (!$result) {
                                 throw new HttpException(500, '生成模板内容失败');
                             }
-                            $request['type'] = $res->apply_type;
-                            $request['tpl_id'] = $res->id;
-                            $request['city_id'] = $res->city_id;
                         }
+
                     }
+                    $request['type'] = $res->apply_type;
+                    $request['tpl_id'] = $res->id;
+                    $request['city_id'] = $res->city_id;
                     DB::commit();
+
                     return $this->preview($request);
                     //return Response::create();
 
@@ -305,28 +308,39 @@ class CmsContentTemplateSetRepository {
         }
 
         if ($update_is_open_ids){
-            $update_open = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->delete();
-            if (!$update_open) {
-                throw new HttpException(500, '删除失败,请重试');
+            $delete_open_ids = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->get();
+            if (count($delete_open_ids)>0){
+                $result = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->delete();
+                if (!$result) {
+                    throw new HttpException(500, '删除失败,请重试');
+                }
             }
 
-            $update_open = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->update(['status' => 0]);
+            $update_open_ids = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->get();
+            if (count($update_open_ids)>0){
+                $res = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->update(['status' => 0]);
+                if (!$res) {
+                    throw new HttpException(500, '修改失败,请重试');
+                }
+            }
+        }
 
-            if (!$update_open) {
+        $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->first();
+        if ($update_tpl){
+            $result = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
+            if (!$result) {
                 throw new HttpException(500, '修改失败,请重试');
             }
         }
 
-        $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
-        if (!$update_tpl) {
-            throw new HttpException(500, '修改失败,请重试');
+        $template_id = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->get();
+        if (count($template_id)>0){
+            $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
+            if (!$res){
+                throw new HttpException(500, '修改失败,请重试');
+            }
         }
 
-        $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
-
-        if (!$res){
-            throw new HttpException(500, '修改失败,请重试');
-        }
         foreach ($templates->toArray() as $k=>$v) {
             $result = $this->cmsContentTemplateSet->where(['status'=>0,'tpl_id'=>$v['id']])->delete();
             if ($result) {