Bläddra i källkod

新增首页商品列表

duqinya 6 år sedan
förälder
incheckning
e151f7b314

+ 0 - 27
app/Http/Controllers/CmsContentTemplateController.php

@@ -1,27 +0,0 @@
-<?php
-namespace App\Http\Controllers;
-
-use App\Repositories\CmsContentTemplateRepository;
-use App\Transformers\CmsContentTemplateTransformer;
-use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Validator;
-
-use League\Fractal\Manager;
-use League\Fractal\Pagination\IlluminatePaginatorAdapter;
-use League\Fractal\Resource\Collection;
-/**
- * Created by PhpStorm.
- * User: qinyaer
- * Date: 2019/5/6
- * Time: 下午14:30
- */
-
-class CmsContentTemplateController extends BaseController
-{
-    public function __construct(CmsContentTemplateRepository $cmsContentTemplateRepository)
-    {
-        $this->cmsContentTemplate = $cmsContentTemplateRepository;
-    }
-
-
-}

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

@@ -1,6 +1,7 @@
 <?php
 namespace App\Http\Controllers;
 
+use App\Models\CmsContentTemplateSet;
 use App\Repositories\CmsContentTemplateSetRepository;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Validator;
@@ -48,6 +49,25 @@ class CmsContentTemplateSetController extends BaseController
         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('没有找到对应商品');
+        }
+    }
+
 
 
 }

+ 31 - 1
app/Http/Repositories/CmsContentTemplateSetRepository.php

@@ -7,6 +7,7 @@ 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) {
@@ -72,7 +73,7 @@ class CmsContentTemplateSetRepository {
                 $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, 'id'));
+                $res_id = implode(",", array_column($pro_array, 'product_id'));
                 $new_rule[$k]['product_id'] = $res_id;
                 $new_rule[$k]['subject_id'] = $rules['link_url'];
                 $new_rule[$k]['show_type'] = $show_type->show_type ?? '';
@@ -103,4 +104,33 @@ class CmsContentTemplateSetRepository {
     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();
+        $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([], config('customer.app_secret'));
+            $url = config("customer.user-service-url").'/api/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 [];
+        }
+
+    }
 }

+ 4 - 0
routes/api.php

@@ -25,5 +25,9 @@ $api->version('v1', [
         //内容预览
         $api->post('/templateSet/preview', 'CmsContentTemplateSetController@preview');
         $api->post('/templateSet/templateName', 'CmsContentTemplateSetController@template');
+        //首页商品列表
+        $api->post('/templateSet/productList', 'CmsContentTemplateSetController@productList');
+
     });
+
 });