|
@@ -9,8 +9,10 @@ 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) {
|
|
|
+class CmsContentTemplateSetRepository
|
|
|
+{
|
|
|
+ public function __construct(CmsContentTemplateSet $cmsContentTemplateSet, CmsContentTemplate $cmsContentTemplate, CmsSubjectProduct $cmsSubjectProduct, CmsSubject $cmsSubject)
|
|
|
+ {
|
|
|
|
|
|
$this->cmsContentTemplateSet = $cmsContentTemplateSet;
|
|
|
$this->cmsContentTemplate = $cmsContentTemplate;
|
|
@@ -23,49 +25,49 @@ 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])->first();
|
|
|
- if (!$temalates){
|
|
|
+ $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'] =[];
|
|
|
+ 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";
|
|
|
+ $group_array['content'][0]['area_type'] = "banner";
|
|
|
|
|
|
- $banner_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$temalates->id,'area_type'=>0])->get();
|
|
|
+ $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){
|
|
|
+ foreach ($banner_rule->toArray() as $k => $v) {
|
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
|
- $new_rule[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
|
|
|
+ $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();
|
|
|
+ $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){
|
|
|
+ foreach ($subject_rule->toArray() as $k => $v) {
|
|
|
$new_rule1[$k]['id'] = $v['id'];
|
|
|
- $new_rule1[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
|
|
|
+ $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();
|
|
|
+ $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){
|
|
|
+ foreach ($floor_rule->toArray() as $k => $v) {
|
|
|
$new_rule2[$k]['id'] = $v['id'];
|
|
|
- $new_rule2[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
|
|
|
+ $new_rule2[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'], true);
|
|
|
}
|
|
|
- foreach ($new_rule2 as $k=>$v){
|
|
|
- if($v){
|
|
|
+ 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();
|
|
@@ -81,44 +83,45 @@ class CmsContentTemplateSetRepository {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ 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){
|
|
|
+ foreach ($category_rule->toArray() as $k => $v) {
|
|
|
$new_rule3[$k]['id'] = $v['id'];
|
|
|
- $new_rule3[$k]['rule'] = \GuzzleHttp\json_decode($v['rule'],true);
|
|
|
+ $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]['area_type'] = "special";
|
|
|
$group_array['content'][2]['rule'] = $new_rule1;
|
|
|
- $group_array['content'][3]['area_type'] ="floor";
|
|
|
+ $group_array['content'][3]['area_type'] = "floor";
|
|
|
$group_array['content'][3]['rule'] = $new_rule2;
|
|
|
- }else{
|
|
|
- $group_array['content'][1]['area_type'] ="special";
|
|
|
+ } 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]['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 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'){
|
|
|
+ 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){
|
|
|
+ $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);
|
|
|
+ $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();
|
|
@@ -126,15 +129,13 @@ class CmsContentTemplateSetRepository {
|
|
|
|
|
|
|
|
|
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';
|
|
|
+ $sign = generateSign(['ids' => $res_id], config('customer.app_secret'));
|
|
|
+ $url = config("customer.app_service_url") . '/homeProduct';
|
|
|
$array = [
|
|
|
- 'json' => ['sign' => $sign,'ids' => $res_id], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
+ 'json' => ['sign' => $sign, 'ids' => $res_id], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
];
|
|
|
|
|
|
- return http($url,$array);
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
return [];
|
|
|
}
|