xielin пре 5 година
родитељ
комит
85574b33ee

+ 2 - 2
.rocketeer/hooks.php

@@ -26,10 +26,10 @@ return [
         'setup'   => [],
         'deploy'  => [
             'composer dumpautoload',
-            'php artisan route:clear',
             'chmod -R 777 bootstrap',
             'chmod -R 777 storage',
-            'chmod -R 777 public'
+            'chmod -R 777 public',
+            'service php-fpm reload'
         ],
         'cleanup' => [],
     ],

+ 38 - 0
app/Http/Middleware/SqlMiddleware.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Illuminate\Support\Facades\DB;
+
+class SqlMiddleware
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request $request
+     * @param  \Closure $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        if ($request->sql_debug==1) {
+            DB::connection()->enableQueryLog();
+        }
+
+        $response = $next($request);
+        if ($request->get('sql_debug')) {
+            $queries = DB::getQueryLog();
+
+            if (!empty($queries)) {
+                foreach ($queries as &$query) {
+                    $query['full_query'] = vsprintf(str_replace('?', '%s', $query['query']), $query['bindings']);
+                }
+            }
+
+            dd($queries);exit;
+        }
+
+        return $response;
+    }
+}

+ 78 - 20
app/Repositories/CmsContentTemplateSetRepository.php

@@ -7,6 +7,7 @@ use App\Models\CmsContentTemplateSet;
 use App\Models\CmsSubjectProduct;
 use App\Models\CmsSubject;
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 use Symfony\Component\HttpKernel\Exception\HttpException;
 use Tymon\JWTAuth\Facades\JWTAuth;
@@ -44,16 +45,32 @@ class CmsContentTemplateSetRepository
         $market_key = config('constants.CMS_MARKET');
         //团购首页
         if ($request['type'] == 0) {
-            if (Cache::has($group_key)) {
-                return Cache::store('redis')->get($group_key);
+//            if (Cache::has($group_key)) {
+//                return Cache::store('redis')->get($group_key);
+//            }
+            Log::info(Redis::exists($group_key));
+            if (Redis::exists($group_key)) {
+                $result = Redis::get($group_key);
+                $res = json_decode($result, true);
+                Log::info($res);
+                return $res;
             }
+
             $group_array['apply_type'] = "group";
             $group_array['title'] = $temalates->title;
             $group_array['content'] = [];
         } else {//菜市场首页
-            if (Cache::has($market_key)) {
-                return Cache::store('redis')->get($market_key);
+//            if (Cache::has($market_key)) {
+//                return Cache::store('redis')->get($market_key);
+//            }
+            Log::info(Redis::exists($market_key));
+            if (Redis::exists($market_key)) {
+                $result = Redis::get($market_key);
+                $res = json_decode($result, true);
+                Log::info($res);
+                return $res;
             }
+
             $group_array['apply_type'] = "market";
             $group_array['title'] = $temalates->title;
             $group_array['content'] = [];
@@ -130,8 +147,13 @@ class CmsContentTemplateSetRepository
             $group_array['content'][3]['area_type'] = "floor";
             $group_array['content'][3]['rule'] = $new_rule2;
 
-            if (!Cache::has($market_key)) {
-                Cache::store('redis')->put($market_key, $group_array, 600);//10分钟过期
+//            if (!Cache::has($market_key)) {
+//                Cache::store('redis')->put($market_key, $group_array, 600);//10分钟过期
+//            }
+
+            if (!Redis::exists($market_key)) {
+                Redis::setex($market_key, 600, json_encode($group_array));//10分钟过期
+                Log::debug('菜市场首页缓存存储成功-' . json_encode($group_array));
             }
 
         } else {
@@ -140,9 +162,16 @@ class CmsContentTemplateSetRepository
             $group_array['content'][2]['area_type'] = "floor";
             $group_array['content'][2]['rule'] = $new_rule2;
 
-            if (!Cache::has($group_key)) {
-                Cache::store('redis')->put($group_key, $group_array, 600);
+//            if (!Cache::has($group_key)) {
+//                Cache::store('redis')->put($group_key, $group_array, 600);
+//            }
+
+            if (!Redis::exists($group_key)) {
+                Redis::setex($group_key, 600, json_encode($group_array));//10分钟过期
+                Log::debug('团购首页缓存存储成功-' . json_encode($group_array));
             }
+
+
         }
         return $group_array;
     }
@@ -194,8 +223,16 @@ class CmsContentTemplateSetRepository
         $group_array['title'] = $temalates->title;
         $group_array['content'] = [];
         $exchange_key = config('constants.CMS_EXCHANGE');
-        if (Cache::has($exchange_key)) {
-            return Cache::store('redis')->get($exchange_key);
+//        if (Cache::has($exchange_key)) {
+//            return Cache::store('redis')->get($exchange_key);
+//        }
+
+        Log::info(Redis::exists($exchange_key));
+        if (Redis::exists($exchange_key)) {
+            $result = Redis::get($exchange_key);
+            $res = json_decode($result, true);
+            Log::info($res);
+            return $res;
         }
 
         $banner_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $temalates->id, 'area_type' => 0, 'status' => 1])->limit(1)->first();
@@ -269,8 +306,13 @@ class CmsContentTemplateSetRepository
             $group_array['content'][$count + $key + 1]['rule'] = $val['rule'];
         }
 
-        if (!Cache::has($exchange_key)) {
-            Cache::store('redis')->put($exchange_key, $group_array, 600);//10分钟过期
+//        if (!Cache::has($exchange_key)) {
+//            Cache::store('redis')->put($exchange_key, $group_array, 600);//10分钟过期
+//        }
+//
+        if (!Redis::exists($exchange_key)) {
+            Redis::setex($exchange_key, 600, json_encode($group_array));//10分钟过期
+            Log::debug('兑换商城缓存存储成功-' . json_encode($group_array));
         }
 
         return $group_array;
@@ -298,17 +340,31 @@ class CmsContentTemplateSetRepository
         $res_id = implode(",", array_column($pro_array, 'product_id'));
 
         $product_key = config('constants.CMS_PRODUCTS');
-        $product_key = sprintf($product_key,md5($res_id));
-        if (Cache::has($product_key)) {
-            return Cache::store('redis')->get($product_key);
+        $product_keys = '';
+        if (isset($request['field_order'])) {
+            $field_order = intval($request['field_order']);
+            if ($field_order == 2) {
+                $product_keys = md5($product_key . 'one' . $res_id);
+            } elseif ($field_order == 3) {
+                $product_keys = md5($product_key . 'two' . $res_id);
+            }
+        } else {
+            $product_keys = md5($product_key . $res_id);
+        }
+
+        Log::info(Redis::exists($product_keys));
+        if (Redis::exists($product_keys)) {
+            $result = Redis::get($product_keys);
+            $res = json_decode($result, true);
+            Log::info($res);
+            return $res;
         }
 
         try {
             if (isset($request['field_order'])) {
-                $field_order = $request['field_order'];
-                $sign = generateSign(['ids' => $res_id, 'field_order' => $field_order], config('customer.app_secret'));
+                $sign = generateSign(['ids' => $res_id, 'field_order' => intval($request['field_order'])], config('customer.app_secret'));
                 $array = [
-                    'json' => ['sign' => $sign, 'ids' => $res_id, 'field_order' => $field_order], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
+                    'json' => ['sign' => $sign, 'ids' => $res_id, 'field_order' => intval($request['field_order'])], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
                 ];
             } else {
                 $sign = generateSign(['ids' => $res_id], config('customer.app_secret'));
@@ -319,8 +375,10 @@ class CmsContentTemplateSetRepository
 
             $url = config("customer.app_service_url") . '/product/exchange/subject';
             $http = http($url, $array, 'get');
-            if (!Cache::has($product_key)) {
-                Cache::store('redis')->put($product_key, $http, 600);//10分钟过期
+
+            if (!Redis::exists($product_keys)) {
+                Redis::setex($product_keys, 300, json_encode($http));//5分钟过期
+                Log::debug('专题商品缓存存储成功-' . json_encode($http));
             }
             return $http;
 

+ 3 - 1
bootstrap/app.php

@@ -70,7 +70,9 @@ $app->routeMiddleware([
     'chxq_jwt_auth' => App\Http\Middleware\JwtAuthMiddleware::class,
     'chxq_sign' => App\Http\Middleware\SignAuthMiddleware::class,
 ]);
-
+$app->middleware([
+    \App\Http\Middleware\SqlMiddleware::class
+]);
 /*
 |--------------------------------------------------------------------------
 | Register Service Providers

+ 1 - 1
public/index.php

@@ -10,7 +10,7 @@
 | is ready to receive HTTP / Console requests from the environment.
 |
 */
-
+ini_set('molten.service_name', 'cms-service');
 $app = require __DIR__.'/../bootstrap/app.php';
 
 /*