Ver código fonte

Merge branch 'develop'

xielin 5 anos atrás
pai
commit
654a0af222

+ 21 - 3
.rocketeer/config.php

@@ -30,14 +30,14 @@ return [
     ////////////////////////////////////////////////////////////////////
 
     // The default remote connection(s) to execute tasks on
-    'default'          => ['production'],
+    'default'          => ['beta'],
 
     // The various connections you defined
     // You can leave all of this empty or remove it entirely if you don't want
     // to track files with credentials : Rocketeer will prompt you for your credentials
     // and store them locally
     'connections'      => [
-        'production' => [
+        'beta' => [
             'host'      => '47.92.174.125:2345',
             'username'  => 'root',
             'password'  => '',
@@ -46,6 +46,15 @@ return [
             'agent'     => '',
             'db_role'   => true,
         ],
+        'production' => [
+            'host'      => '47.92.121.231:2345',
+            'username'  => 'root',
+            'password'  => '',
+            'key'       => '/root/.ssh/id_rsa',
+            'keyphrase' => '',
+            'agent'     => '',
+            'db_role'   => true,
+        ],
     ],
 
     /*
@@ -77,7 +86,16 @@ return [
         // Stages configurations
         'stages'      => [],
         // Connections configuration
-        'connections' => [],
+        'connections' => [
+            'production'    => [
+                'remote'    => [
+                    'root_directory'    => '/data/wwwroot/uptoyo/api'
+                ],
+                'scm'   => [
+                    'branch'    => 'release'
+                ]
+            ]
+        ],
 
     ],
 

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

@@ -23,7 +23,7 @@ class CmsContentTemplateController extends BaseController
         $this->cmsContentTemplate = $cmsContentTemplateRepository;
     }
 
-    //专题列表
+    //模板列表
     public function index(Request $request)
     {
         $cmsTemplate = $this->cmsContentTemplate->index($request->all());
@@ -32,6 +32,7 @@ class CmsContentTemplateController extends BaseController
         $resource = new Collection($cmsTemplate, new CmsContentTemplateTransformer());
         $resource->setPaginator(new IlluminatePaginatorAdapter($cmsTemplate));
         $data = $fractal->createData($resource)->toArray();
+
         $data['extra'] = [
             'filters' => [
                 'id',

+ 5 - 2
app/Repositories/CmsContentTemplateRepository.php

@@ -34,8 +34,7 @@ class CmsContentTemplateRepository {
                 'status','=',$request['status'],
             ];
         }
-        return $this->cmsContentTemplate->where($where)->where('status',1)->orderBy('id', 'asc')->paginate($perPage);
-
+        return $this->cmsContentTemplate->where($where)->where('status',1)->orderBy('apply_type','desc')->orderBy('id', 'asc')->paginate($perPage);
 
     }
 
@@ -128,6 +127,10 @@ class CmsContentTemplateRepository {
     public function updateTemplateName($data)
     {
         $template = $this->cmsContentTemplate->select('city_id','apply_type')->where('id',$data['id'])->first();
+        if ($template->apply_type == 2){
+            throw new HttpException(500, '兑换商城不允许修改名称');
+        }
+
         $template_array = $this->cmsContentTemplate->where(['city_id' => $template->city_id, 'apply_type' => $template->apply_type])->get();
 
         if (count($template_array)>1){

+ 93 - 47
app/Repositories/CmsContentTemplateSetRepository.php

@@ -49,7 +49,7 @@ class CmsContentTemplateSetRepository
                 if ($v['apply_type'] == 2) {
                     return $this->exchangeMall($request);
                 }
-                if ($v['apply_type'] == 0 || $v['apply_type'] == 1){
+                if ($v['apply_type'] == 0 || $v['apply_type'] == 1) {
                     return $this->preview($request);
                 }
             }
@@ -97,7 +97,7 @@ class CmsContentTemplateSetRepository
                 if ($res->apply_type == 2) {
                     return $this->exchangeMall($request);
                 }
-                if ($res->apply_type == 0 || $res->apply_type == 1){
+                if ($res->apply_type == 0 || $res->apply_type == 1) {
                     return $this->preview($request);
                 }
                 //return Response::create();
@@ -131,27 +131,37 @@ class CmsContentTemplateSetRepository
             'name' => isset($request['name']) ? $request['name'] : '',
             'floor_img' => isset($request['floor_img']) ? $request['floor_img'] : '',
         ];
+        $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
+
         if ($id) {
             $old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($id);
             $subject_id_array = json_decode($old_subject_id['rule'], true);
-            $request_rule = $request['rule'];
-            if (count($request_rule) > 0) {
-                foreach ($request_rule as $k => $v) {
+            if (count($rules) > 0) {
+                foreach ($rules as $k => $v) {
                     if (isset($v['link_type']) && $v['link_type'] == 1) {
-                        $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
-                        $templates->used_count += 1;
-                        $templates->save();
+                        $subject = $this->cmsSubject->where('id', intval($v['link_url']))->first();
+
+                        if ($template_id->apply_type == 2) {
+                            if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
+                                throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
+                            }
+                        }
+
+                        $subject->used_count += 1;
+                        $subject->save();
                     }
                 }
             }
             if (count($subject_id_array) > 0) {
                 foreach ($subject_id_array as $val) {
                     if (isset($val['link_type']) && $val['link_type'] == 1) {
-                        $templates = $this->cmsSubject->where('id', intval($val['link_url']))->first();
-                        $update_template = [
-                            $templates->used_count -= 1
-                        ];
-                        $templates->update($update_template);
+                        $subject = $this->cmsSubject->where('id', intval($val['link_url']))->first();
+                        if ($subject) {
+                            $update_subject = [
+                                $subject->used_count -= 1
+                            ];
+                            $subject->update($update_subject);
+                        }
                     }
                 }
             }
@@ -160,12 +170,17 @@ class CmsContentTemplateSetRepository
                 throw new HttpException(500, '更新失败');
             }
         } else {
-            if (count($request['rule']) > 0) {
-                foreach ($request['rule'] as $v) {
+            if (count($rules) > 0) {
+                foreach ($rules as $v) {
                     if (isset($v['link_type']) && $v['link_type'] == 1) {
-                        $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
-                        $templates->used_count += 1;
-                        $templates->save();
+                        $subject = $this->cmsSubject->where('id', intval($v['link_url']))->first();
+                        if ($template_id->apply_type == 2) {
+                            if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
+                                throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
+                            }
+                        }
+                        $subject->used_count += 1;
+                        $subject->save();
                     }
                 }
             }
@@ -183,26 +198,40 @@ class CmsContentTemplateSetRepository
         $subject_id_array = json_decode($old_subject_id['rule'], true);
         if ($subject_id_array['link_type'] == 1 && $request['rule']['link_type'] == 1) {//链接方式都为专题
             if ($subject_id_array['link_url'] != $request['rule']['link_url']) {
-                $templates = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
-                $update_template = [
-                    $templates->used_count -= 1
-                ];
-                $templates->update($update_template);
+                $subject = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
+                if ($subject) {
+                    $update_subject = [
+                        $subject->used_count -= 1
+                    ];
+                    $subject->update($update_subject);
+                }
 
-                $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
-                $templates->used_count += 1;
-                $templates->save();
+                $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
+                if ($request['apply_type'] == 2) {
+                    if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
+                        throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
+                    }
+                }
+                $subject->used_count += 1;
+                $subject->save();
             }
         } elseif ($subject_id_array['link_type'] == 1 && $request['rule']['link_type'] != 1) {
-            $templates = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
-            $update_template = [
-                $templates->used_count -= 1
-            ];
-            $templates->update($update_template);
+            $subject = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
+            if ($subject) {
+                $update_subject = [
+                    $subject->used_count -= 1
+                ];
+                $subject->update($update_subject);
+            }
         } elseif ($subject_id_array['link_type'] != 1 && $request['rule']['link_type'] == 1) {
-            $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
-            $templates->used_count += 1;
-            $templates->save();
+            $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
+            if ($request['apply_type'] == 2) {
+                if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
+                    throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
+                }
+            }
+            $subject->used_count += 1;
+            $subject->save();
         }
 
     }
@@ -238,6 +267,7 @@ class CmsContentTemplateSetRepository
             'area_type' => $request['area_type'],
             'status' => 0,
         ];
+        $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
 
         if (empty($advertisement_id)) {
             if ($request['rule']['link_type'] == 1) {
@@ -249,6 +279,7 @@ class CmsContentTemplateSetRepository
                 throw new HttpException(500, '添加失败');
             }
         } else {
+            $request['apply_type'] = $template_id->apply_type;
             $this->update_subject($request);
 
             $advertisement_ids = $this->cmsContentTemplateSet->where('id', $advertisement_id)->update($subject);
@@ -270,7 +301,7 @@ class CmsContentTemplateSetRepository
         if (isset($request['rule']['show_num'])) {
             $request['rule']['show_num'] = intval($request['rule']['show_num']);
         }
-        $subject = [
+        $templateSet = [
             'tpl_id' => $request['tpl_id'],
             'rule' => json_encode($request['rule']),
             'area_type' => $request['area_type'],
@@ -279,19 +310,28 @@ class CmsContentTemplateSetRepository
             'name' => isset($request['name']) ? $request['name'] : '',
             'floor_img' => isset($request['floor_img']) ? $request['floor_img'] : '',
         ];
+        $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
+
         if (empty($floor_id)) {
             if ($request['rule']['link_type'] == 1) {
-                $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
-                $templates->used_count += 1;
-                $templates->save();
+                $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
+                if ($template_id->apply_type == 2) {
+                    if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
+                        throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
+                    }
+                }
+
+                $subject->used_count += 1;
+                $subject->save();
             }
-            if (!$this->cmsContentTemplateSet->create($subject)) {
+            if (!$this->cmsContentTemplateSet->create($templateSet)) {
                 throw new HttpException(500, '添加失败');
             }
         } else {
+            $request['apply_type'] = $template_id->apply_type;
             $this->update_subject($request);
 
-            $floor_ids = $this->cmsContentTemplateSet->where('id', $floor_id)->update($subject);
+            $floor_ids = $this->cmsContentTemplateSet->where('id', $floor_id)->update($templateSet);
             if (!$floor_ids) {
                 throw new HttpException(500, '更新失败');
             }
@@ -312,10 +352,15 @@ class CmsContentTemplateSetRepository
             'area_type' => $request['area_type'],
             'status' => 0,
         ];
+        $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
+
         if (empty($category_id)) {
             if ($request['rule']['link_type'] == 1) {
                 $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
-                $templates->used_count += 1;
+                if ($templates == null) {
+                    $templates = new CmsSubject();
+                    $templates->used_count += 1;
+                }
                 $templates->save();
             }
 
@@ -323,6 +368,7 @@ class CmsContentTemplateSetRepository
                 throw new HttpException(500, '添加失败');
             }
         } else {
+            $request['apply_type'] = $template_id->apply_type;
             $this->update_subject($request);
 
             $category_ids = $this->cmsContentTemplateSet->where('id', $category_id)->update($subject);
@@ -601,10 +647,10 @@ class CmsContentTemplateSetRepository
             $new_rule[$k]['rule']['rule'] = json_decode($v['rule'], true);
 //            }
         }
-            foreach ($new_rule as $k => $v) {
-                $group_array['content'][$k + 1]['area_type'] = $new_rule[$k]['area_type'];
-                $group_array['content'][$k + 1]['rule'] = array($new_rule[$k]['rule']);
-            }
+        foreach ($new_rule as $k => $v) {
+            $group_array['content'][$k + 1]['area_type'] = $new_rule[$k]['area_type'];
+            $group_array['content'][$k + 1]['rule'] = array($new_rule[$k]['rule']);
+        }
 
         $floor_rule = $this->cmsContentTemplateSet->select('id', 'rule', 'floor_img')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 2])->orderBy('id', 'asc')->get();
         $new_rule = [];
@@ -628,8 +674,8 @@ class CmsContentTemplateSetRepository
                 unset($v['link_type']);
             }
         }
-            $group_array['content'][$count + 1]['area_type'] = 2;
-            $group_array['content'][$count + 1]['rule'] = $new_rule;
+        $group_array['content'][$count + 1]['area_type'] = 2;
+        $group_array['content'][$count + 1]['rule'] = $new_rule;
 
         return $group_array;
     }

+ 5 - 3
app/Repositories/CmsSubjectRepository.php

@@ -36,7 +36,7 @@ class CmsSubjectRepository {
             $where[] = ['used_mall', '=', $request['used_mall']];
         }
 
-        return $this->cmsSubject->where($where)->orderBy('id', 'asc')->paginate($perPage);
+        return $this->cmsSubject->where($where)->orderBy('id', 'desc')->paginate($perPage);
 
     }
 
@@ -110,13 +110,15 @@ class CmsSubjectRepository {
     public function edit($request)
     {
         $subject = $this->cmsSubject->find($request['id']);
-
+        if ($subject->used_count != 0){
+            $request['is_open'] = 1;
+        }
         $subject->title = $request['title'];
         $subject->city_id = isset($request['city_id']) ? $request['city_id'] : 0;
         $subject->city_name = isset($request['city_name']) ? $request['city_name'] : '';
         $subject->show_type = $request['show_type'];
         $subject->is_open = $request['is_open'];
-        $subject->used_count = 0;
+        //$subject->used_count = 0;
         $subject->used_mall = isset($request['used_mall']) ? $request['used_mall'] : 1;
         $subject->subject_img = isset($request['subject_img']) ? $request['subject_img'] : '';
 

+ 2 - 2
database/seeds/CmsContentTemplateTableSeeder.php

@@ -18,9 +18,9 @@ class CmsContentTemplateTableSeeder extends Seeder
             [
                 'city_id'   => 0,
                 'city_name'    => '',
-                'title'    => '',
+                'title'    => '兑换商城',
                 'apply_type'    => 2,
-                'is_open'    => 0,
+                'is_open'    => 1,
                 'status'    => 1,
                 'created_at'    => $date,
                 'updated_at'    => $date