浏览代码

修改发布内容

duqinya 6 年之前
父节点
当前提交
55a5096462
共有 1 个文件被更改,包括 19 次插入28 次删除
  1. 19 28
      app/Repositories/CmsContentTemplateSetRepository.php

+ 19 - 28
app/Repositories/CmsContentTemplateSetRepository.php

@@ -225,37 +225,28 @@ class CmsContentTemplateSetRepository {
             'apply_type'=>$template->apply_type,
         ];
         $templates = $this->cmsContentTemplate->where($where)->get();
-        foreach ($templates->toArray() as $k=>$v){
-            if ($v['is_open'] == 1){
-                $this->cmsContentTemplate->update(['is_open'=>0]);
+        foreach ($templates->toArray() as $k=>$v) {
+            if ($v['is_open'] == 1) {
+                $update_open = $this->cmsContentTemplate->where('is_open', 1)->update(['is_open' => 0]);
+                if (!$update_open) {
+                    throw new HttpException(500, '修改失败,请重试');
+                }
             }
         }
-        foreach ($tem_array as $k=>$v) {
-                if ($v['status'] == 1) {
-                    $result = $this->cmsContentTemplateSet->where('id', $v['id'])->delete();
-                    if (!$result) {
-                        return Response::create([
-                            'message' => '删除失败,请重试',
-                            'status_code' => 500
-                        ]);
-                    }
-                }
+        $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['is_open' => 1]);
+        if (!$update_tpl) {
+            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) {
+                return Response::create();
+            }
         }
-
-                $update_tpl = $this->cmsContentTemplate->where('id',$request['tpl_id'])->update(['is_open'=>1]);
-                if (!$update_tpl){
-                    return Response::create([
-                        'message'  => '修改失败,请重试',
-                        'status_code'   => 500
-                    ]);
-                }
-                $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
-                if (!$res){
-                    return Response::create([
-                        'message'  => '修改失败,请重试',
-                        'status_code'   => 500
-                    ]);
-                }
 
     }