duqinya пре 6 година
родитељ
комит
388b2d2eb8
1 измењених фајлова са 14 додато и 4 уклоњено
  1. 14 4
      app/Repositories/CmsContentTemplateSetRepository.php

+ 14 - 4
app/Repositories/CmsContentTemplateSetRepository.php

@@ -225,19 +225,29 @@ class CmsContentTemplateSetRepository {
             'apply_type'=>$template->apply_type,
         ];
         $templates = $this->cmsContentTemplate->where($where)->get();
+        $update_is_open_ids=[];
         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, '修改失败,请重试');
-                }
+                  $update_is_open_ids[]=$v['id'];
             }
         }
+
+        $update_open = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->update(['is_open' => 0]);
+        if (!$update_open) {
+            throw new HttpException(500, '修改失败,请重试');
+        }
+
         $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['is_open' => 1]);
         if (!$update_tpl) {
             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, '修改失败,请重试');
+        }
         $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
+
         if (!$res){
             throw new HttpException(500, '修改失败,请重试');
         }