瀏覽代碼

Merge branch 'develop'

caihongxingqiu 6 年之前
父節點
當前提交
b3b9e8cbe3
共有 42 個文件被更改,包括 1254 次插入72 次删除
  1. 6 1
      .env.example
  2. 2 1
      .gitignore
  3. 84 0
      .rocketeer/config.php
  4. 40 0
      .rocketeer/hooks.php
  5. 24 0
      .rocketeer/paths.php
  6. 80 0
      .rocketeer/remote.php
  7. 35 0
      .rocketeer/scm.php
  8. 19 0
      .rocketeer/stages.php
  9. 61 0
      .rocketeer/strategies.php
  10. 85 0
      app/Console/Commands/apollo.php
  11. 2 1
      app/Console/Kernel.php
  12. 33 0
      app/Helper/helper.php
  13. 10 0
      app/Http/Controllers/AuthController.php
  14. 9 0
      app/Http/Controllers/BaseController.php
  15. 72 0
      app/Http/Controllers/CmsContentTemplateSetController.php
  16. 44 0
      app/Http/Controllers/Controller.php
  17. 24 2
      app/Http/Middleware/JwtAuthMiddleware.php
  18. 12 0
      app/Models/BaseModel.php
  19. 22 0
      app/Models/CmsContentTemplate.php
  20. 26 0
      app/Models/CmsContentTemplateSet.php
  21. 26 0
      app/Models/CmsSubject.php
  22. 26 0
      app/Models/CmsSubjectProduct.php
  23. 143 0
      app/Repositories/CmsContentTemplateSetRepository.php
  24. 1 0
      bootstrap/app.php
  25. 1 0
      composer.json
  26. 10 0
      config/apollo.php
  27. 0 5
      config/customer.php
  28. 7 0
      config/customer.tpl
  29. 1 1
      config/jwt.php
  30. 37 0
      database/migrations/2019_04_28_022240_create_table_subject_table.php
  31. 33 0
      database/migrations/2019_04_28_025052_create_cms_subject_product_table.php
  32. 36 0
      database/migrations/2019_04_28_025655_create_cms_content_template_table.php
  33. 33 0
      database/migrations/2019_04_28_030611_create_cms_content_template_set_table.php
  34. 32 0
      database/migrations/2019_04_28_072523_add_cms_subject_product_table.php
  35. 33 0
      database/migrations/2019_04_29_060908_add_template_id_to_cms_content_template_set_table.php
  36. 32 0
      database/migrations/2019_04_30_075256_add_deleted_at_to_cms_content_template_set_table.php
  37. 20 0
      deploy/nginx/conf.d/app.beta.conf
  38. 20 0
      deploy/nginx/conf.d/app.dev.conf
  39. 2 0
      deploy/php/local.ini
  40. 32 0
      docker-compose-beta.yml
  41. 31 0
      docker-compose-dev.yml
  42. 8 61
      routes/api.php

+ 6 - 1
.env.example

@@ -21,4 +21,9 @@ QUEUE_CONNECTION=sync
 ELASTICSEARCH_HOST=localhost
 ELASTICSEARCH_PORT=9200
 ELASTICSEARCH_USER=
-ELASTICSEARCH_PASS=
+ELASTICSEARCH_PASS=
+
+APP_ID=chxq-platform
+CLUSTER=default
+APOLLO_NAMESPACES="application,cms-service"
+APOLLO_CONFIG_SERVER=http://127.0.0.1:18080

+ 2 - 1
.gitignore

@@ -4,4 +4,5 @@ Homestead.json
 Homestead.yaml
 .env
 /storage/*
-composer.lock
+composer.lock
+/config/customer.php

+ 84 - 0
.rocketeer/config.php

@@ -0,0 +1,84 @@
+<?php
+
+use Rocketeer\Services\Connections\ConnectionsHandler;
+
+return [
+
+    // The name of the application to deploy
+    // This will create a folder of the same name in the root directory
+    // configured above, so be careful about the characters used
+    'application_name' => 'cms-service',
+
+    // Plugins
+    ////////////////////////////////////////////////////////////////////
+
+    // The plugins to load
+    'plugins'          => [// 'Rocketeer\Plugins\Slack\RocketeerSlack',
+    ],
+
+    // Logging
+    ////////////////////////////////////////////////////////////////////
+
+    // The schema to use to name log files
+    'logs'             => function (ConnectionsHandler $connections) {
+        return sprintf('%s-%s-%s.log', $connections->getConnection(), $connections->getStage(), date('Ymd'));
+    },
+
+    // Remote access
+    //
+    // You can either use a single connection or an array of connections
+    ////////////////////////////////////////////////////////////////////
+
+    // The default remote connection(s) to execute tasks on
+    'default'          => ['production'],
+
+    // 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' => [
+            'host'      => '47.92.174.125:2345',
+            'username'  => 'root',
+            'password'  => '',
+            'key'       => '/root/.ssh/id_rsa',
+            'keyphrase' => '',
+            'agent'     => '',
+            'db_role'   => true,
+        ],
+    ],
+
+    /*
+     * In most multiserver scenarios, migrations must be run in an exclusive server.
+     * In the event of not having a separate database server (in which case it can
+     * be handled through connections), you can assign a 'db_role' => true to the
+     * server's configuration and it will only run the migrations in that specific
+     * server at the time of deployment.
+     */
+    'use_roles'        => false,
+
+    // Contextual options
+    //
+    // In this section you can fine-tune the above configuration according
+    // to the stage or connection currently in use.
+    // Per example :
+    // 'stages' => array(
+    // 	'staging' => array(
+    // 		'scm' => array('branch' => 'staging'),
+    // 	),
+    //  'production' => array(
+    //    'scm' => array('branch' => 'master'),
+    //  ),
+    // ),
+    ////////////////////////////////////////////////////////////////////
+
+    'on'               => [
+
+        // Stages configurations
+        'stages'      => [],
+        // Connections configuration
+        'connections' => [],
+
+    ],
+
+];

+ 40 - 0
.rocketeer/hooks.php

@@ -0,0 +1,40 @@
+<?php
+
+return [
+
+    // Tasks
+    //
+    // Here you can define in the `before` and `after` array, Tasks to execute
+    // before or after the core Rocketeer Tasks. You can either put a simple command,
+    // a closure which receives a $task object, or the name of a class extending
+    // the Rocketeer\Abstracts\AbstractTask class
+    //
+    // In the `custom` array you can list custom Tasks classes to be added
+    // to Rocketeer. Those will then be available in the command line
+    // with all the other tasks
+    //////////////////////////////////////////////////////////////////////
+
+    // Tasks to execute before the core Rocketeer Tasks
+    'before' => [
+        'setup'   => [],
+        'deploy'  => [],
+        'cleanup' => [],
+    ],
+
+    // Tasks to execute after the core Rocketeer Tasks
+    'after'  => [
+        'setup'   => [],
+        'deploy'  => [
+            'composer dumpautoload',
+            'php artisan route:clear',
+            'chmod -R 777 bootstrap',
+            'chmod -R 777 storage',
+            'chmod -R 777 public'
+        ],
+        'cleanup' => [],
+    ],
+
+    // Custom Tasks to register with Rocketeer
+    'custom' => [],
+
+];

+ 24 - 0
.rocketeer/paths.php

@@ -0,0 +1,24 @@
+<?php
+
+return [
+
+    // Configurable paths
+    //
+    // Here you can manually set paths to some commands Rocketeer
+    // might try to use, if you leave those empty it will try to find them
+    // manually or assume they're in the root folder
+    //
+    // You can also add in this file custom paths for any command or binary
+    // Rocketeer might go looking for
+    ////////////////////////////////////////////////////////////////////
+
+    // Path to the PHP binary
+    'php'      => '/usr/local/php/bin/php',
+
+    // Path to Composer
+    'composer' => '/usr/local/bin/composer',
+
+    // Path to the Artisan CLI
+    'artisan'  => 'artisan',
+
+];

+ 80 - 0
.rocketeer/remote.php

@@ -0,0 +1,80 @@
+<?php
+
+return [
+
+    // Remote server
+    //////////////////////////////////////////////////////////////////////
+
+    // Variables about the servers. Those can be guessed but in
+    // case of problem it's best to input those manually
+    'variables'      => [
+        'directory_separator' => '/',
+        'line_endings'        => "\n",
+    ],
+
+    // The number of releases to keep at all times
+    'keep_releases'  => 4,
+
+    // Folders
+    ////////////////////////////////////////////////////////////////////
+
+    // The root directory where your applications will be deployed
+    // This path *needs* to start at the root, ie. start with a /
+    'root_directory' => '/data/wwwroot/beta',
+
+    // The folder the application will be cloned in
+    // Leave empty to use `application_name` as your folder name
+    'app_directory'  => '',
+
+    // A list of folders/file to be shared between releases
+    // Use this to list folders that need to keep their state, like
+    // user uploaded data, file-based databases, etc.
+    'shared'         => [
+        'storage',
+        'vendor',
+        '.env',
+    ],
+
+    // Execution
+    //////////////////////////////////////////////////////////////////////
+
+    // If enabled will force a shell to be created
+    // which is required for some tools like RVM or NVM
+    'shell'          => false,
+
+    // An array of commands to run under shell
+    'shelled'        => ['which', 'ruby', 'npm', 'bower', 'bundle', 'grunt'],
+
+    // Enable use of sudo for some commands
+    // You can specify a sudo user by doing
+    // 'sudo' => 'the_user'
+    'sudo' => false,
+
+    // An array of commands to run under sudo
+    'sudoed' => [],
+
+    // Permissions$
+    ////////////////////////////////////////////////////////////////////
+
+    'permissions'    => [
+
+        // The folders and files to set as web writable
+        'files'    => [
+            'bootstrap/cache',
+            'storage',
+        ],
+
+        // Here you can configure what actions will be executed to set
+        // permissions on the folder above. The Closure can return
+        // a single command as a string or an array of commands
+        'callback' => function ($task, $file) {
+            return [
+                sprintf('chmod -R 777 %s', $file),
+                sprintf('chmod -R g+s %s', $file),
+                sprintf('chown -R www:www %s', $file),
+            ];
+        },
+
+    ],
+
+];

+ 35 - 0
.rocketeer/scm.php

@@ -0,0 +1,35 @@
+<?php
+
+return [
+
+    // SCM repository
+    //////////////////////////////////////////////////////////////////////
+
+    // The SCM used (supported: "git", "svn")
+    'scm'        => 'git',
+
+    // The SSH/HTTPS address to your repository
+    // Example: https://github.com/vendor/website.git
+    'repository' => 'http://caihongxingqiu:Ch20151002@git.caihongxingqiu.net/rainbow/cms-service.git',
+
+    // The repository credentials : you can leave those empty
+    // if you're using SSH or if your repository is public
+    // In other cases you can leave this empty too, and you will
+    // be prompted for the credentials on deploy. If you don't want
+    // to be prompted (public repo, etc) set the values to null
+    'username'   => 'null',
+    'password'   => 'null',
+
+    // The branch to deploy
+    'branch'     => 'master',
+
+    // Whether your SCM should do a "shallow" clone of the repository
+    // or not – this means a clone with just the latest state of your
+    // application (no history)
+    // If you're having problems cloning, try setting this to false
+    'shallow'    => true,
+
+    // Recursively pull in submodules. Works only with GIT.
+    'submodules' => true,
+
+];

+ 19 - 0
.rocketeer/stages.php

@@ -0,0 +1,19 @@
+<?php
+
+return [
+
+    // Stages
+    //
+    // The multiples stages of your application
+    // if you don't know what this does, then you don't need it
+    //////////////////////////////////////////////////////////////////////
+
+    // Adding entries to this array will split the remote folder in stages
+    // Like /var/www/yourapp/staging and /var/www/yourapp/production
+    'stages'  => [],
+
+    // The default stage to execute tasks on when --stage is not provided
+    // Falsey means all of them
+    'default' => '',
+
+];

+ 61 - 0
.rocketeer/strategies.php

@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of Rocketeer
+ *
+ * (c) Maxime Fabre <ehtnam6@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+use Rocketeer\Binaries\PackageManagers\Composer;
+use Rocketeer\Tasks\Subtasks\Primer;
+
+return [
+
+    // Task strategies
+    //
+    // Here you can configure in a modular way which tasks to use to
+    // execute various core parts of your deployment's flow
+    //////////////////////////////////////////////////////////////////////
+
+    // Which strategy to use to check the server
+    'check'        => 'Php',
+
+    // Which strategy to use to create a new release
+    'deploy'       => 'Clone',
+
+    // Which strategy to use to test your application
+    'test'         => 'Phpunit',
+
+    // Which strategy to use to migrate your database
+    'migrate'      => 'Artisan',
+
+    // Which strategy to use to install your application's dependencies
+    'dependencies' => 'Composer',
+
+    // Execution hooks
+    //////////////////////////////////////////////////////////////////////
+
+    'composer'     => [
+        'install' => function (Composer $composer, $task) {
+            return $composer->install([], ['--no-interaction' => null, '--prefer-dist' => null]);
+        },
+        'update'  => function (Composer $composer) {
+            return $composer->update();
+        },
+    ],
+
+    // Here you can configure the Primer tasks
+    // which will run a set of commands on the local
+    // machine, determining whether the deploy can proceed
+    // or not
+    'primer'       => function (Primer $task) {
+        return [
+            // $task->executeTask('Test'),
+            // $task->binary('grunt')->execute('lint'),
+        ];
+    },
+
+];

+ 85 - 0
app/Console/Commands/apollo.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Org\Multilinguals\Apollo\Client\ApolloClient;
+
+class Apollo extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'apollo';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Apollo配置服务';
+
+
+    private $apollo;
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->save_dir = storage_path('apollo');
+        $this->config_tpl = config_path() . '/customer.tpl';
+        $this->config_file = config_path() . '/customer.php';
+
+        $this->apollo = new ApolloClient(
+            config('apollo.config_server'),
+            config('apollo.app_id'),
+            config('apollo.namespaces')
+        );
+        $this->apollo->save_dir = $this->save_dir;
+        if(!is_dir($this->save_dir)){
+            mkdir($this->save_dir);
+        }
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line('apollo配置服务开启');
+        $restart = true; //失败自动重启
+        do {
+            $error = $this->apollo->start(function () {
+                $list = glob($this->save_dir . DIRECTORY_SEPARATOR . 'apolloConfig.*');
+                $apollo = [];
+                foreach ($list as $l) {
+                    $config = require $l;
+                    if (is_array($config) && isset($config['configurations'])) {
+                        $apollo = array_merge($apollo, $config['configurations']);
+                    }
+                }
+                if (!$apollo) {
+                    Log::error('Load Apollo Config Failed, no config available');
+                }
+                $tpl = file_get_contents($this->config_tpl);
+                foreach ($apollo as $key =>$value){
+                    $tpl = str_replace('{'.$key.'}',$value,$tpl);
+                }
+                file_put_contents($this->config_file,$tpl);
+            }); //此处传入回调
+            if ($error) {
+                Log::info("Apollo Hand error :" . $error);
+            }
+        } while ($error && $restart);
+    }
+}

+ 2 - 1
app/Console/Kernel.php

@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use App\Console\Commands\Apollo;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
      * @var array
      */
     protected $commands = [
-        //
+        Apollo::class
     ];
 
     /**

+ 33 - 0
app/Helper/helper.php

@@ -3,6 +3,20 @@
  * 添加自定义辅助函数
  */
 
+if ( ! function_exists('config_path'))
+{
+    /**
+     * Get the configuration path.
+     *
+     * @param string $path
+     * @return string
+     */
+    function config_path($path = '')
+    {
+        return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
+    }
+}
+
 /**
  * 参数签名校验
  * @param array $params
@@ -45,3 +59,22 @@ function verifySign($sign, $params, $secret_key)
     };
 
 }
+
+
+function http($url, $param, $method = 'post')
+{
+    try {
+        $client = new \GuzzleHttp\Client();
+        $response = $client->request($method, $url, $param);
+        $result = json_decode($response->getBody()->getContents(), true);
+        if ($result['code'] == 0) {
+            return $result['data'];
+        } else {
+            return [];
+        }
+    } catch (\Exception $exception) {
+        return [];
+    }
+
+}
+

+ 10 - 0
app/Http/Controllers/AuthController.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Http\Controllers;
+
+
+class  AuthController extends BaseController
+{
+
+
+}

+ 9 - 0
app/Http/Controllers/BaseController.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace App\Http\Controllers;
+
+
+class BaseController extends Controller
+{
+
+}

+ 72 - 0
app/Http/Controllers/CmsContentTemplateSetController.php

@@ -0,0 +1,72 @@
+<?php
+namespace App\Http\Controllers;
+
+use App\Repositories\CmsContentTemplateSetRepository;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+/**
+ * Created by PhpStorm.
+ * User: qinyaer
+ * Date: 2019/5/5
+ * Time: 上午9:30
+ */
+
+class CmsContentTemplateSetController extends BaseController
+{
+    public function __construct(CmsContentTemplateSetRepository $cmsContentTemplateSetRepository)
+    {
+        $this->cmsContentSetTemplate = $cmsContentTemplateSetRepository;
+    }
+
+    //内容预览
+    public function preview(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'city_id' => 'required|integer',
+            'type' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->jsonError($validator->errors()->first());
+        }
+
+        return  $this->jsonSuccess($this->cmsContentSetTemplate->preview($request->all()));
+
+    }
+
+    /**
+     * 获取城市模板名称及类型
+     * @param Request $request
+     * @return array
+     */
+    public function template(Request $request){
+        $validator = Validator::make($request->all(), [
+            'city_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->jsonError($validator->errors()->first());
+        }
+        return $this->jsonSuccess($this->cmsContentSetTemplate->getTemplate($request->only('city_id')));
+    }
+
+    //获取商品列表
+    public function productList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+            'area_type' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return $this->jsonError($validator->errors()->first());
+        }
+
+        $product_list = $this->cmsContentSetTemplate->productList($request->all());
+        if ($product_list){
+            return $this->jsonSuccess($product_list);
+        }else{
+            return $this->jsonError('没有找到对应商品');
+        }
+    }
+
+
+
+}

+ 44 - 0
app/Http/Controllers/Controller.php

@@ -2,9 +2,53 @@
 
 namespace App\Http\Controllers;
 
+use Dingo\Api\Routing\Helpers;
 use Illuminate\Routing\Controller as BaseController;
 
 class Controller extends BaseController
 {
+    use Helpers;
+    public function jsonSuccess($data = [], $msg = "成功")
+    {
+        $response = array(
+            'code' => 0,
+            'msg' => $msg,
+            'data' => []
+        );
+        if ($data) {
+            if (is_array($data)) {
+                //带有分页格式转换
+                if (isset($data['meta'])) {
+                    // 更改元数据格式,全部包含在data下
+                    $temp = array(
+                        'data' => array(
+                            'data' => $data['data'],
+                            'pagination' => $data['meta']['pagination']
+                        )
+                    );
+                    $response = array_merge($response, $temp);
+                } elseif (isset($data['data'])) {
+                    $response = array_merge($response, $data);
+                } else {
+                    $temp = array(
+                        'data' => $data
+                    );
+                    $response = array_merge($response, $temp);
+                }
+            } else {
+                $response['data'] = $data;
+            }
+        }
+        return $response;
+    }
 
+    public function jsonError($msg)
+    {
+        $response = array(
+            'code' => 1,
+            'msg' => $msg,
+            'data' => ""
+        );
+        return $response;
+    }
 }

+ 24 - 2
app/Http/Middleware/JwtAuthMiddleware.php

@@ -5,8 +5,8 @@ namespace App\Http\Middleware;
 use Closure;
 use Tymon\JWTAuth\Exceptions\JWTException;
 use Tymon\JWTAuth\Exceptions\TokenExpiredException;
+use Tymon\JWTAuth\Exceptions\TokenInvalidException;
 use Tymon\JWTAuth\Facades\JWTAuth;
-use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;
 
 class JwtAuthMiddleware
 {
@@ -21,7 +21,22 @@ class JwtAuthMiddleware
     {
 
         try {
-            $user = JWTAuth::parseToken()->authenticate();
+            $token = JWTAuth::getToken();
+            if(empty($token)){
+                $error = [
+                    'message' => 'token is required',
+                    'code' => 401,
+                ];
+                return response()->json($error);
+            }
+            $data = JWTAuth::decode($token)['user'];
+            if ($data->sign !== md5($data->uid . env('JWT_SECRET'))) {
+                $error = [
+                    'message' => 'request is not allow',
+                    'code' => 401,
+                ];
+                return response()->json($error);
+            }
         } catch (TokenExpiredException $e) {
             $error = [
                 'message' => 'Token is Expired',
@@ -39,6 +54,13 @@ class JwtAuthMiddleware
                 'message' => $e->getMessage(),
                 'code' => 401,
             ];
+
+            return response()->json($error)->setStatusCode(401);
+        }catch (\Exception $e){
+            $error = [
+                'message' => $e->getMessage(),
+                'code' => 401,
+            ];
             return response()->json($error)->setStatusCode(401);
         }
         return $next($request);

+ 12 - 0
app/Models/BaseModel.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BaseModel extends Model
+{
+    protected $guarded = ['id'];
+
+    protected $hidden = ['deleted_at'];
+}

+ 22 - 0
app/Models/CmsContentTemplate.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+
+class CmsContentTemplate extends BaseModel
+{
+    protected  $table = 'cms_content_template';
+
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['city_id','city_name','title','apply_type','is_open'];
+
+    //一对多关联模板内容表
+    public function cmsContentTemplateSet()
+    {
+        return $this->hasMany('App\Models\CmsContentTemplateSet','tpl_id');
+    }
+
+}

+ 26 - 0
app/Models/CmsContentTemplateSet.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CmsContentTemplateSet extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $dates = ['deleted_at'];
+    protected  $table = 'cms_content_template_set';
+
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['rule','tpl_id','area_type'];
+
+    //一对多关联模板内容表
+    public function cmsContentTemplate()
+    {
+        return $this->belongsTo('App\Models\CmsContentTemplate','tpl_id');
+    }
+
+}

+ 26 - 0
app/Models/CmsSubject.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CmsSubject extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $dates = ['deleted_at'];
+    protected  $table = 'cms_subject';
+
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['city_id','city_name','title','show_type','is_open'];
+
+    //一对多关联专题商品表
+    public function cmsSubjectProduct()
+    {
+        return $this->hasMany('App\Models\CmsSubjectProduct','subject_id');
+    }
+
+}

+ 26 - 0
app/Models/CmsSubjectProduct.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class CmsSubjectProduct extends BaseModel
+{
+    use SoftDeletes;
+
+    protected $dates = ['deleted_at'];
+    protected  $table = 'cms_subject_product';
+
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['product_id','sort','subject_id'];
+
+    //相对关联到专题表
+    public function cmsSubject()
+    {
+        return $this->belongsTo('App\Models\CmsSubject','subject_id');
+    }
+
+}

+ 143 - 0
app/Repositories/CmsContentTemplateSetRepository.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace App\Repositories;
+
+use App\Models\CmsContentTemplate;
+use App\Models\CmsContentTemplateSet;
+use App\Models\CmsSubjectProduct;
+use App\Models\CmsSubject;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+use Tymon\JWTAuth\Facades\JWTAuth;
+
+class CmsContentTemplateSetRepository {
+    public function __construct(CmsContentTemplateSet $cmsContentTemplateSet,CmsContentTemplate $cmsContentTemplate,CmsSubjectProduct $cmsSubjectProduct,CmsSubject $cmsSubject) {
+
+        $this->cmsContentTemplateSet = $cmsContentTemplateSet;
+        $this->cmsContentTemplate = $cmsContentTemplate;
+        $this->cmsSubjectProduct = $cmsSubjectProduct;
+        $this->cmsSubject = $cmsSubject;
+    }
+
+    /**
+     * 内容预览
+     */
+    public function preview($request)
+    {
+        $temalates = $this->cmsContentTemplate->select('title','id')->where(['city_id'=>$request['city_id'],'apply_type'=>$request['type'],'is_open'=>1])->first();
+        if (!$temalates){
+            throw new HttpException(500, '没有找到对应模板');
+        }
+
+        //团购首页
+        $group_array = [];
+        if ($request['type'] == 0){
+            $group_array['apply_type'] ="group";
+            $group_array['title'] =$temalates->title;
+            $group_array['content'] =[];
+        }else{//菜市场首页
+            $group_array['apply_type'] ="market";
+            $group_array['title'] =$temalates->title;
+            $group_array['content'] =[];
+        }
+
+        $group_array['content'][0]['area_type'] ="banner";
+
+        $banner_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$temalates->id,'area_type'=>0])->get();
+        $new_rule = [];
+        foreach ($banner_rule->toArray() as $k=>$v){
+            $new_rule[$k]['id'] = $v['id'];
+            $new_rule[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
+        }
+        $group_array['content'][0]['rule'] = $new_rule;
+
+        $subject_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$temalates->id,'area_type'=>1])->get();
+
+        $new_rule1 = [];
+        foreach ($subject_rule->toArray() as $k=>$v){
+            $new_rule1[$k]['id'] = $v['id'];
+            $new_rule1[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
+        }
+
+        $floor_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$temalates->id,'area_type'=>2])->get();
+        $new_rule2 = [];
+        foreach ($floor_rule->toArray() as $k=>$v){
+            $new_rule2[$k]['id'] = $v['id'];
+            $new_rule2[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
+        }
+        foreach ($new_rule2 as $k=>$v){
+            if($v){
+                $rules = $v['rule'];
+                $show_type = $this->cmsSubject->select('show_type')->where('id', $rules['link_url'])->first();
+                $product = $this->cmsSubjectProduct->where('subject_id', $rules['link_url'])->orderBy('sort', 'asc')->get();
+                $pro_array = $product->toArray();
+                $res_id = implode(",", array_column($pro_array, 'product_id'));
+                $new_rule2[$k]['product_id'] = $res_id;
+                $new_rule2[$k]['subject_id'] = $rules['link_url'];
+                $new_rule2[$k]['show_type'] = $show_type->show_type ?? '';
+                unset($v['url']);
+                unset($v['show_num']);
+                unset($rules['link_url']);
+                unset($v['link_type']);
+            }
+        }
+
+        if ($request['type'] == 1){
+            $group_array['content'][1]['area_type'] ="category";
+            $category_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$temalates->id,'area_type'=>3])->get();
+            $new_rule3 = [];
+            foreach ($category_rule->toArray() as $k=>$v){
+                $new_rule3[$k]['id'] = $v['id'];
+                $new_rule3[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
+            }
+            $group_array['content'][1]['rule'] = $new_rule3;
+            $group_array['content'][2]['area_type'] ="special";
+            $group_array['content'][2]['rule'] = $new_rule1;
+            $group_array['content'][3]['area_type'] ="floor";
+            $group_array['content'][3]['rule'] = $new_rule2;
+        }else{
+            $group_array['content'][1]['area_type'] ="special";
+            $group_array['content'][1]['rule'] = $new_rule1;
+            $group_array['content'][2]['area_type'] ="floor";
+            $group_array['content'][2]['rule'] = $new_rule2;
+        }
+
+        return $group_array;
+    }
+
+    public function getTemplate($cityId){
+        return $this->cmsContentTemplate->select('title','apply_type')->where(['city_id'=>$cityId,'is_open'=>1])->orderBy('apply_type','asc')->get();
+    }
+
+    public function productList($request)
+    {
+        $area_type = '';
+        if ($request['area_type'] == 'floor'){
+            $area_type = 2;
+        }
+        $template_set = $this->cmsContentTemplateSet->select('rule')->where(['area_type'=>$area_type,'id'=>$request['id']])->first();
+        if (!$template_set){
+            throw new HttpException(500, '没有找到对应模板内容');
+        }
+        $template_array = json_decode($template_set->rule,true);
+
+        $product = $this->cmsSubjectProduct->where('subject_id', $template_array['link_url'])->orderBy('sort', 'asc')->get();
+        $pro_array = $product->toArray();
+        $res_id = implode(",", array_column($pro_array, 'product_id'));
+
+
+        try {
+            $sign = generateSign(['ids'=>$res_id], config('customer.app_secret'));
+            $url = config("customer.user-service-url").'/honmeProduct';
+//            $url = '192.168.33.127:8080/honmeProduct';
+            $url = 'https://api.dev.caihongxingqiu.com/product/honmeProduct';
+            $array = [
+                'json' => ['sign' => $sign,'ids' => $res_id], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+
+            return http($url,$array);
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+}

+ 1 - 0
bootstrap/app.php

@@ -26,6 +26,7 @@ $app->withFacades();
 $app->withEloquent();
 
 $app->configure('api');
+$app->configure('apollo');
 $app->configure('auth');
 $app->configure('jwt');
 $app->configure('customer');

+ 1 - 0
composer.json

@@ -16,6 +16,7 @@
         "predis/predis": "^1.1",
         "tymon/jwt-auth": "1.0.0-rc.4.1",
         "vlucas/phpdotenv": "^3.3",
+        "multilinguals/apollo-client": "^0.1.2",
         "yansongda/laravel-pay": "^2.0"
     },
     "require-dev": {

+ 10 - 0
config/apollo.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'namespaces' => explode(',', env('APOLLO_NAMESPACES')),
+    'cluster' => env('APOLLO_CLUSTER'),
+    'save_dir' => storage_path('apollo'),
+    'config_server' => env('APOLLO_CONFIG_SERVER'),
+    'app_id' => env('APP_ID'),
+    'timeout_interval' => 70
+];

+ 0 - 5
config/customer.php

@@ -1,5 +0,0 @@
-<?php
-//此文件为apollo配置文件模板,禁止修改移动
-return [
-    'app_secret' => 'aaaaaaaaaaa'
-];

+ 7 - 0
config/customer.tpl

@@ -0,0 +1,7 @@
+<?php
+//此文件为apollo配置文件模板,禁止修改移动
+return [
+    'app_secret' => '{app_secret}',
+    'jwt_secret' => '{jwt_secret}',
+    'app_service_url' => '{app_service_url}',
+];

+ 1 - 1
config/jwt.php

@@ -25,7 +25,7 @@ return [
     |
     */
 
-    'secret' => env('JWT_SECRET'),
+    'secret' => env('JWT_SECRET',config('customer.jwt_secret')),
 
     /*
     |--------------------------------------------------------------------------

+ 37 - 0
database/migrations/2019_04_28_022240_create_table_subject_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableSubjectTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cms_subject', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('city_id');
+            $table->string('city_name',20)->comment('城市名称'); //城市名称
+            $table->string('title',70)->comment('专题名称');
+            $table->tinyInteger('show_type')->default(0)->comment('商品展示方式:0:左图右字;1:通栏大图;2:左右滑动');
+            $table->tinyInteger('is_open')->default(1)->comment('是否启用:0:关闭;1:开启');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+            Schema::dropIfExists('cms_subject');
+    }
+}

+ 33 - 0
database/migrations/2019_04_28_025052_create_cms_subject_product_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCmsSubjectProductTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cms_subject_product', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('sort')->comment('商品排序');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('cms_subject_product');
+    }
+}

+ 36 - 0
database/migrations/2019_04_28_025655_create_cms_content_template_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCmsContentTemplateTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cms_content_template', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('city_id')->comment('城市ID');
+            $table->string('city_name',20)->comment('城市名称');
+            $table->string('title',200)->comment('模板名称');
+            $table->tinyInteger('apply_type')->default(1)->comment('对应模板:0:团购首页;1:菜市场首页');
+            $table->tinyInteger('is_open')->default(0)->comment('是否启用:0:禁用;1:启用');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('cms_content_template');
+    }
+}

+ 33 - 0
database/migrations/2019_04_28_030611_create_cms_content_template_set_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCmsContentTemplateSetTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cms_content_template_set', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->json('rule')->comment('设置项');
+            $table->tinyInteger('status')->default(0)->comment('状态:0:草稿;1:发布');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('cms_content_template_set');
+    }
+}

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

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddCmsSubjectProductTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('cms_subject_product', function (Blueprint $table) {
+            $table->integer('subject_id')->comment('专题ID');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('cms_subject_product', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2019_04_29_060908_add_template_id_to_cms_content_template_set_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddTemplateIdToCmsContentTemplateSetTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('cms_content_template_set', function (Blueprint $table) {
+            $table->integer('tpl_id')->comment('模板ID');
+            $table->tinyInteger('area_type')->default(0)->comment('状态:0:banner;1:专题广告;2.商品楼层;3.分类专题(菜市场)');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('cms_content_template_set', function (Blueprint $table) {
+            //
+        });
+    }
+}

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

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddDeletedAtToCmsContentTemplateSetTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('cms_content_template_set', function (Blueprint $table) {
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('cms_content_template_set', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 20 - 0
deploy/nginx/conf.d/app.beta.conf

@@ -0,0 +1,20 @@
+server {
+    listen 80;
+    index index.php index.html;
+    error_log  /var/log/nginx/error.log;
+    access_log /var/log/nginx/access.log;
+    root /var/www/public;
+    location ~ \.php$ {
+        try_files $uri =404;
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+        fastcgi_pass app_cms_service_beta:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+    }
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+        gzip_static on;
+    }
+}

+ 20 - 0
deploy/nginx/conf.d/app.dev.conf

@@ -0,0 +1,20 @@
+server {
+    listen 80;
+    index index.php index.html;
+    error_log  /var/log/nginx/error.log;
+    access_log /var/log/nginx/access.log;
+    root /var/www/public;
+    location ~ \.php$ {
+        try_files $uri =404;
+        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+        fastcgi_pass app_cms_service_dev:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        fastcgi_param PATH_INFO $fastcgi_path_info;
+    }
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+        gzip_static on;
+    }
+}

+ 2 - 0
deploy/php/local.ini

@@ -0,0 +1,2 @@
+upload_max_filesize=40M
+post_max_size=40M

+ 32 - 0
docker-compose-beta.yml

@@ -0,0 +1,32 @@
+version: '3'
+
+services:
+  app_cms_service_beta:
+    image: harbor.caihongxingqiu.com:9401/library/php:latest
+    tty: true
+    working_dir: /var/www
+    volumes:
+      - ./:/var/www
+      - ./deploy/php/local.ini:/usr/local/etc/php/conf.d/local.ini
+      - /data/wwwroot/beta/cms-service:/data/wwwroot/beta/cms-service
+    networks:
+      - chxq
+
+  server_cms_service_beta:
+    image: harbor.caihongxingqiu.com:9401/library/nginx:latest
+    tty: true
+    depends_on:
+      - app_cms_service_beta
+    ports:
+      - "28211:80"
+    volumes:
+      - ./:/var/www
+      - ./deploy/nginx/conf.d/app.beta.conf:/etc/nginx/conf.d/app.beta.conf
+    networks:
+      - chxq
+
+#docker networks
+#docker network create --driver overlay chxq
+networks:
+  chxq:
+    external: true

+ 31 - 0
docker-compose-dev.yml

@@ -0,0 +1,31 @@
+version: '3'
+
+services:
+  app_cms_service_dev:
+    image: harbor.caihongxingqiu.com:9401/library/php:latest
+    tty: true
+    working_dir: /var/www
+    volumes:
+      - ./:/var/www
+      - ./deploy/php/local.ini:/usr/local/etc/php/conf.d/local.ini
+    networks:
+      - chxq
+
+  server_cms_service_dev:
+    image: harbor.caihongxingqiu.com:9401/library/nginx:latest
+    tty: true
+    depends_on:
+      - app_cms_service_dev
+    ports:
+      - "18211:80"
+    volumes:
+      - ./:/var/www
+      - ./deploy/nginx/conf.d/app.dev.conf:/etc/nginx/conf.d/app.dev.conf
+    networks:
+      - chxq
+
+#docker networks
+#docker network create --driver overlay chxq
+networks:
+  chxq:
+    external: true

+ 8 - 61
routes/api.php

@@ -14,73 +14,20 @@
 $api = app('Dingo\Api\Routing\Router');
 
 $api->version('v1', [
-    'namespace' => 'App\Http\Controllers\V1',
+    'namespace' => 'App\Http\Controllers',
 ], function ($api) {
-    //登录
-    $api->post('login', 'AuthController@authenticate');
-    //测试签名
-    $api->post('sign', 'IndexController@index4');
-    //测试支付宝 支付
-    $api->post('alipay', 'AlipayController@index');
-    //回调
-    $api->post('return', 'AlipayController@return');
-    //异步回调
-    $api->post('notify', 'AlipayController@notify');
-    //测试微信支付
-    $api->post('weixin', 'WeixinPayController@index');
-    //微信回调
-    $api->post('wxin_notify', 'WeixinPayController@notify');
-    //测试短信验证码
-    $api->post('send_sms', 'SendSmsController@index');
-    //手机号码注册
-    $api->post('mobileRegister', 'AuthController@mobileRegister');
-    //微信注册
-    $api->post('weixinRegister', 'AuthController@weixinRegister');
-    //手机号码,密码登录
-    $api->post('mobileLogin', 'AuthController@mobileLogin');
-    //手机号码短信登陆
-    $api->post('mobileSmsLogin', 'AuthController@mobileSmsLogin');
-    //微信登录
-    $api->post('weixinLogin', 'AuthController@weixinLogin');
-    //测试reids
-    $api->post('loginCount', 'AuthController@loginCount');
-
-
-    $api->group(['middleware' => 'auth:api'], function ($api) {
-
-    });
-
     //登录+验签
     $api->group(['middleware' => ['chxq_jwt_auth','chxq_sign']], function ($api) {
-        //登出
-        $api->post('logout', 'AuthController@logout');
-        //刷新身份令牌
-        $api->post('refresh', 'AuthController@refresh');
-        //绑定微信
-        $api->post('bindWeixin', 'AuthController@bindWeixin');
-        //绑定手机
-        $api->post('bindMobile', 'AuthController@bindMobile');
-        //设置密码
-        $api->post('setPassword', 'AuthController@setPassword');
-        //修改密码
-        $api->post('updatePassword', 'AuthController@updatePassword');
-        //解绑温馨
-        $api->post('unbindWeixin', 'AuthController@unbindWeixin');
-        //检查微信号是否绑定
-        $api->post('isBindWeixin', 'AuthController@isBindWeixin');
-        //新增快递地址
-        $api->post('addExpressAddress', 'MemberExpressAddressController@addExpressAddress');
-        //新增自提地址
-        $api->post('addSelfAddress', 'MemberExpressAddressController@addSelfAddress');
-        //用户自提地址
-        $api->post('selfAddressList', 'MemberExpressAddressController@selfAddressList');
-        //删除地址
-        $api->post('addressDelete', 'MemberExpressAddressController@delete');
-        //设置默认地址
-        $api->post('addressIsDefault', 'MemberExpressAddressController@isDefault');
+
     });
     //仅验签
     $api->group(['middleware' => 'chxq_sign'], function ($api) {
+        //内容预览
+        $api->post('/templateSet/preview', 'CmsContentTemplateSetController@preview');
+        $api->post('/templateSet/templateName', 'CmsContentTemplateSetController@template');
+        //首页商品列表
+        $api->post('/templateSet/productList', 'CmsContentTemplateSetController@productList');
 
     });
+
 });