Przeglądaj źródła

修复首次进入找不到tpl_id

duqinya 6 lat temu
rodzic
commit
97816849e8
1 zmienionych plików z 25 dodań i 14 usunięć
  1. 25 14
      app/Repositories/CmsContentTemplateSetRepository.php

+ 25 - 14
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,15 +308,20 @@ 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]);
-
-            if (!$update_open) {
-                throw new HttpException(500, '修改失败,请重试');
+            $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, '修改失败,请重试');
+                }
             }
         }
 
@@ -322,11 +330,14 @@ class CmsContentTemplateSetRepository {
             throw new HttpException(500, '修改失败,请重试');
         }
 
-        $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
-
-        if (!$res){
-            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, '修改失败,请重试');
+            }
         }
+
         foreach ($templates->toArray() as $k=>$v) {
             $result = $this->cmsContentTemplateSet->where(['status'=>0,'tpl_id'=>$v['id']])->delete();
             if ($result) {