duqinya 6 rokov pred
rodič
commit
27acd5c91a

+ 1 - 0
app/Http/Controllers/CmsContentTemplateController.php

@@ -37,6 +37,7 @@ class CmsContentTemplateController extends BaseController
                 'id',
                 'city_id',
                 'is_open',
+                'status',
             ],
             'columns' => [
                 'id',

+ 13 - 5
app/Repositories/CmsContentTemplateRepository.php

@@ -21,14 +21,14 @@ class CmsContentTemplateRepository {
             $where[] = ['is_open','=',$request['is_open']];
         }else{
             $where[] = ['is_open', '=',1];
-
         }
+
         if (isset($request['city_id'])){
             $where[] = [
                 'city_id','=',$request['city_id'],
             ];
         }
-        return $this->cmsContentTemplate->where($where)->orderBy('id', 'asc')->paginate($perPage);
+        return $this->cmsContentTemplate->where($where)->where('status',1)->orderBy('id', 'asc')->paginate($perPage);
 
 
     }
@@ -56,7 +56,8 @@ class CmsContentTemplateRepository {
             'city_id' => $request['city_id'],
             'city_name' => $request['city_name'],
             'apply_type' => $request['apply_type'],
-            'is_open' => $request['is_open'],
+            'is_open' => $request['is_open'] ?? 0,
+            'status' => 0
         ];
 
         if (!$this->cmsContentTemplate->create($subject)) {
@@ -69,11 +70,18 @@ class CmsContentTemplateRepository {
      */
     public function edit($request)
     {
+        $template_id = $this->cmsContentTemplate->find($request['id']);
+        $where = ['city_id'=>$template_id->city_id,'title'=>$template_id->title,'apply_type'=>$template_id->apply_type];
+        $template = $this->cmsContentTemplate->where($where)->get();
+//        foreach ($template->toArray() as $v){
+//            if ($v['is_open'] == 1 && $request['is_open'] == 0){
+//                throw new HttpException(500, '请先关闭该城市模块下已开启的模板后操作');
+//            }
+//        }
         if ($request['city_id'] == 610100 && $request['is_open'] == 0){
-            throw new HttpException(500, '西安的模板不允许手动关闭');
+            throw new HttpException(500, '城市为西安的模板不允许手动关闭');
         }
 
-        $template_id = $this->cmsContentTemplate->find($request['id']);
         $template_id->is_open = $request['is_open'];
         $template_id->updated_at = date('Y-m-d H:i:s');
 

+ 7 - 6
app/Repositories/CmsContentTemplateSetRepository.php

@@ -25,7 +25,7 @@ class CmsContentTemplateSetRepository {
      */
     public function set($request)
     {
-        $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open')->where('id',$request['tpl_id'])->first();
+        $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
         $templates = $template->toArray();
         $where = [
             'city_id'=>$templates['city_id'],
@@ -36,7 +36,7 @@ class CmsContentTemplateSetRepository {
         $request = [];
         $need_create=true;
         foreach ($copys_template as $k=>$v) {
-            if ($v['is_open'] == 0) {
+            if ($v['status'] == 0) {
                 $need_create = false;
                 $request['type'] = $v['apply_type'];
                 $request['tpl_id'] = $v['id'];
@@ -49,7 +49,8 @@ class CmsContentTemplateSetRepository {
                     'city_id' => $templates['city_id'],
                     'city_name' => $templates['city_name'],
                     'apply_type' => $templates['apply_type'],
-                    'is_open' => 0,
+                    'status' => 0,
+                    'is_open' => $templates['is_open'],
                 ];
                 DB::beginTransaction();
                 try {
@@ -218,7 +219,7 @@ class CmsContentTemplateSetRepository {
         //同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
         $templateSet = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->select('id','status')->get();
         $tem_array = $templateSet->toArray();
-        $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open')->where('id',$request['tpl_id'])->first();
+        $template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
         $where = [
             'city_id'=>$template->city_id,
             'title'=>$template->title,
@@ -227,12 +228,12 @@ class CmsContentTemplateSetRepository {
         $templates = $this->cmsContentTemplate->where($where)->get();
         $update_is_open_ids=[];
         foreach ($templates->toArray() as $k=>$v) {
-            if ($v['is_open'] == 1) {
+            if ($v['status'] == 1) {
                   $update_is_open_ids[]=$v['id'];
             }
         }
 
-        $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['is_open' => 1]);
+        $update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1,'is_open'=>1]);
         if (!$update_tpl) {
             throw new HttpException(500, '修改失败,请重试');
         }