|
@@ -6,6 +6,8 @@ use App\Models\CmsContentTemplate;
|
|
|
use App\Models\CmsContentTemplateSet;
|
|
|
use App\Models\CmsSubjectProduct;
|
|
|
use App\Models\CmsSubject;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
|
@@ -25,18 +27,33 @@ class CmsContentTemplateSetRepository
|
|
|
*/
|
|
|
public function preview($request)
|
|
|
{
|
|
|
- $temalates = $this->cmsContentTemplate->select('title', 'id')->where(['city_id' => $request['city_id'], 'apply_type' => $request['type'], 'is_open' => 1,'status'=>1,'deleted_at'=>null])->orderBy('id','desc')->first();
|
|
|
+ $where = [
|
|
|
+ 'city_id' => $request['city_id'],
|
|
|
+ 'apply_type' => $request['type'],
|
|
|
+ 'is_open' => 1,
|
|
|
+ 'status'=>1,
|
|
|
+ 'deleted_at'=>null
|
|
|
+ ];
|
|
|
+ $temalates = $this->cmsContentTemplate->select('title', 'id')->where($where)->orderBy('id','desc')->first();
|
|
|
if (!$temalates) {
|
|
|
throw new HttpException(500, '没有找到对应模板');
|
|
|
}
|
|
|
|
|
|
- //团购首页
|
|
|
$group_array = [];
|
|
|
+ $group_key = env('REDIS_HOME_GROUP_KEY');
|
|
|
+ $market_key = env('REDIS_HOME_MARKET_KEY');
|
|
|
+ //团购首页
|
|
|
if ($request['type'] == 0) {
|
|
|
+ if (Cache::has($group_key)) {
|
|
|
+ return Cache::store('redis')->get($group_key);
|
|
|
+ }
|
|
|
$group_array['apply_type'] = "group";
|
|
|
$group_array['title'] = $temalates->title;
|
|
|
$group_array['content'] = [];
|
|
|
- } else {//菜市场首页
|
|
|
+ }else {//菜市场首页
|
|
|
+ if (Cache::has($market_key)) {
|
|
|
+ return Cache::store('redis')->get($market_key);
|
|
|
+ }
|
|
|
$group_array['apply_type'] = "market";
|
|
|
$group_array['title'] = $temalates->title;
|
|
|
$group_array['content'] = [];
|
|
@@ -47,8 +64,6 @@ class CmsContentTemplateSetRepository
|
|
|
$banner_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $temalates->id, 'area_type' => 0,'status'=>1])->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);
|
|
|
$decode_banner = \GuzzleHttp\json_decode($v['rule'], true);
|
|
|
if (count($decode_banner)>0) {
|
|
|
foreach ($decode_banner as $key=>$value){
|
|
@@ -105,13 +120,21 @@ class CmsContentTemplateSetRepository
|
|
|
$group_array['content'][2]['rule'] = $new_rule1;
|
|
|
$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分钟过期
|
|
|
+ }
|
|
|
+
|
|
|
} 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;
|
|
|
- }
|
|
|
|
|
|
+ if (!Cache::has($group_key)) {
|
|
|
+ Cache::store('redis')->put($group_key, $group_array, 600);
|
|
|
+ }
|
|
|
+ }
|
|
|
return $group_array;
|
|
|
}
|
|
|
|