Quellcode durchsuchen

新增模板、编辑模板、修改模板状态 修改

durong vor 5 Jahren
Ursprung
Commit
df5d7805c3

+ 2 - 4
app/Http/Controllers/CmsContentTemplateController.php

@@ -57,10 +57,8 @@ class CmsContentTemplateController extends BaseController
     public function create(Request $request)
     {
         $validator = Validator::make($request->all(), [
-            'city_id' => 'required|integer',
-            'city_name' => 'required|string',
             'title' => 'required|string',
-            'apply_type' => ['required', Rule::in(0,1)],
+            'apply_type' => ['required', Rule::in(0,1,2)],
         ]);
         if ($validator->fails()) {
             return $this->response->error($validator->errors()->first(), 500);
@@ -76,7 +74,7 @@ class CmsContentTemplateController extends BaseController
         $validator = Validator::make($request->all(), [
             'id' => 'required|exists:cms_content_template',
             'is_open' => ['required', Rule::in(0,1)],
-            'apply_type' => ['required', Rule::in(0,1)],
+            'apply_type' => ['required', Rule::in(0,1,2)],
             'city_id' => 'required',
         ]);
         if ($validator->fails()) {

+ 20 - 9
app/Repositories/CmsContentTemplateRepository.php

@@ -44,24 +44,32 @@ class CmsContentTemplateRepository {
      */
     public function create($request)
     {
-        $where = ['city_id'=>$request['city_id'],'apply_type'=>$request['apply_type']];
-        $template = $this->cmsContentTemplate->where($where)->get();
-        if (count($template) >= 1){
-            throw new HttpException(500, '当前城市该模版类型已存在');
+        if (isset($request['city_id'])) {
+            if ($this->cmsContentTemplate->where(['city_id' => $request['city_id'], 'apply_type' => $request['apply_type']])->exists()) {
+                throw new HttpException(500, '当前城市该模版类型已存在');
+            }
+        }
+        if ($request['apply_type'] == 2) {
+            if ($this->cmsContentTemplate->where(['title' => $request['title'], 'apply_type' => 2])->exists()) {
+                throw new HttpException(500, '当前模版类型下该名称已存在');
+            }
         }
 
         $subject = [
             'title' => $request['title'],
-            'city_id' => $request['city_id'],
-            'city_name' => $request['city_name'],
+            'city_id' => isset($request['city_id']) ? $request['city_id'] : 0,
+            'city_name' => isset($request['city_name']) ? $request['city_name'] : '',
             'apply_type' => $request['apply_type'],
             'status' => 1,
             'is_open' => 0,
         ];
 
-        if ($request['city_id'] == 610100){
+        //默认开启,且不可手动关闭
+        if (isset($request['city_id']) && $request['city_id'] == 610100){
+            $subject['is_open'] = 1;
+        }
+        if ($request['apply_type'] == 2){
             $subject['is_open'] = 1;
-
         }
 
         if (!$this->cmsContentTemplate->create($subject)) {
@@ -88,6 +96,9 @@ class CmsContentTemplateRepository {
         if (count($template) == 0){
             throw new HttpException(500, '配置内容为空无法开启');
         }
+        if ($template_id->apply_type == 2){
+            throw new HttpException(500, '兑换商城不允许手动关闭');
+        }
 
         $template_id->is_open = $request['is_open'];
         $template_id->updated_at = date('Y-m-d H:i:s');
@@ -117,7 +128,7 @@ class CmsContentTemplateRepository {
     public function updateTemplateName($data)
     {
         $template = $this->cmsContentTemplate->select('city_id','apply_type')->where('id',$data['id'])->first();
-        $template_array = $this->cmsContentTemplate->where(['city_id'=>$template->city_id,'apply_type'=>$template->apply_type])->get();
+        $template_array = $this->cmsContentTemplate->where(['city_id' => $template->city_id, 'apply_type' => $template->apply_type])->get();
 
         if (count($template_array)>1){
             foreach ($template_array->toArray() as $value){

+ 32 - 0
database/migrations/2019_07_09_061003_update_apply_type_to_cms_content_template_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateApplyTypeToCmsContentTemplateTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('cms_content_template', function (Blueprint $table) {
+            \Illuminate\Support\Facades\DB::statement("ALTER TABLE cms_content_template MODIFY COLUMN apply_type TINYINT (4) NOT NULL DEFAULT 1 COMMENT '对应模板:0:团购首页;1:菜市场首页;2.兑换商城首页'");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('cms_content_template', function (Blueprint $table) {
+            //
+        });
+    }
+}