mark 2 anni fa
parent
commit
d280c31755

+ 60 - 0
app/Http/Bean/Controller/Buy/GetGoodsListResultBean.php

@@ -0,0 +1,60 @@
+<?php
+
+
+namespace App\Http\Bean\Controller\Buy;
+
+
+/**
+ * @SWG\Definition(
+ * )
+ */
+class GetGoodsListResultBean
+{
+    /**
+     * @SWG\Property(
+     *     description="总数量"
+     * )
+     * @var string
+     */
+    public $total;
+
+    /**
+     * @SWG\Property(
+     *     description="数据",
+     *     @SWG\Items(
+     *          @SWG\Property(
+     *              property="goods_name",
+     *              type="string",
+     *              description="商品名称"
+     *          ),
+     *          @SWG\Property(
+     *              property="goods_thumb_url",
+     *              type="string",
+     *              description="商品图片"
+     *          ),
+     *          @SWG\Property(
+     *              property="market_price",
+     *              type="string",
+     *              description="市场价格"
+     *          ),
+     *          @SWG\Property(
+     *              property="price",
+     *              type="string",
+     *              description="优惠价"
+     *          ),
+     *          @SWG\Property(
+     *              property="goods_id",
+     *              type="string",
+     *              description="商品ID"
+     *          ),
+     *          @SWG\Property(
+     *              property="commission",
+     *              type="string",
+     *              description="佣金(单位为分)"
+     *          )
+     *     )
+     * )
+     * @var array
+     */
+    private $list;
+}

+ 1 - 1
app/Http/Controllers/BaseController.php

@@ -128,7 +128,7 @@ class BaseController extends Controller
 
     public function test()
     {
-        $data = JutuikeUtil::getActList();
+        $data = JutuikeUtil::goodsCategory("jd");
         return $this->success($data);
 //        $url = "https://mobile.yangkeduo.com/goods.html?_wvx=10&refer_share_uin=RKJBZMVHVOZWU3HQPZYUD5MAEQ_GEXDA&refer_share_uid=5985443220&share_uin=RKJBZMVHVOZWU3HQPZYUD5MAEQ_GEXDA&page_from=23&_wv=41729&refer_share_id=vJXEDkANGEc4uvPW9QgRCHPj3P6GELOc&refer_share_channel=copy_link&share_uid=5985443220&pxq_secret_key=EUEHP3OMNH3X4GQUAL37HDD7UJBLLM3OD42X55VHLGG6GT3EBPLQ&goods_id=276748200008";
         $url = "https://mobile.yangkeduo.com/goods.html?_wvx=10&refer_share_uin=QKZTKYYF4LYNCB7SVBSL42IYWY_GEXDA&refer_share_uid=3669222324&share_uin=QKZTKYYF4LYNCB7SVBSL42IYWY_GEXDA&page_from=101&_wv=41729&refer_share_id=l6x0HEi8EMpQ2F9CJiCmsW1IqO5fnT3K&refer_share_channel=copy_link&share_uid=3669222324&pxq_secret_key=6T5MOY4WIDK2ALUXMKACS7QZ3CEYWBUQRZATVA5T5PDULJS3CV6A&goods_id=169921843493";

+ 102 - 0
app/Http/Controllers/Buy/BuyController.php

@@ -0,0 +1,102 @@
+<?php
+
+
+namespace App\Http\Controllers\Buy;
+
+
+use App\Http\Controllers\BaseController;
+use App\Http\Logic\Buy\BuyLogic;
+
+class BuyController extends BaseController
+{
+    /**
+     * @SWG\Get(
+     *     path="/buy/cate/list",
+     *     tags={"电商导购"},
+     *     summary="获取电商平台分类",
+     *     description="获取电商平台分类",
+     *     produces={"application/json"},
+     *     @SWG\Parameter(
+     *          name="source",
+     *          in="query",
+     *          description="来源 jd-京东,vip-唯品会,pdd-拼多多,kaola-考拉,taobao-淘宝",
+     *          type="string"
+     *     ),
+     *     @SWG\Response(
+     *         response="200",
+     *         description="success",
+     *          @SWG\Schema(
+     *              @SWG\Property(
+     *                  property="id",
+     *                  type="string",
+     *                  description="分类ID"
+     *              ),
+     *              @SWG\Property(
+     *                  property="name",
+     *                  type="string",
+     *                  description="分类名称"
+     *              )
+     *          )
+     *     ),
+     *     @SWG\Response(
+     *         response="403",
+     *         description="fail",
+     *         @SWG\Schema(ref="#/definitions/ErrorBean")
+     *     )
+     * )
+     */
+    public function getCateList()
+    {
+        $data = BuyLogic::getCateListLogic();
+        return $this->success($data);
+    }
+
+    /**
+     * @SWG\Post(
+     *     path="/buy/goods/list",
+     *     tags={"电商导购"},
+     *     summary="商品列表接口",
+     *     description="商品列表接口",
+     *     produces={"application/json"},
+     *     @SWG\Parameter(
+     *          name="page",
+     *          in="query",
+     *          description="第几页",
+     *          type="string"
+     *     ),
+     *     @SWG\Parameter(
+     *          name="page_size",
+     *          in="query",
+     *          description="每页数量",
+     *          type="string"
+     *     ),
+     *     @SWG\Parameter(
+     *          name="source",
+     *          in="query",
+     *          description="来源 jd-京东,vip-唯品会,pdd-拼多多,kaola-考拉,taobao-淘宝",
+     *          type="string"
+     *     ),
+     *     @SWG\Parameter(
+     *          name="cat_id",
+     *          in="query",
+     *          description="分类ID",
+     *          type="string"
+     *     ),
+     *     @SWG\Response(
+     *         response="200",
+     *         description="success",
+     *         @SWG\Schema(ref="#/definitions/GetGoodsListResultBean")
+     *     ),
+     *     @SWG\Response(
+     *         response="403",
+     *         description="fail",
+     *         @SWG\Schema(ref="#/definitions/ErrorBean")
+     *     )
+     * )
+     */
+    public function getGoodsList()
+    {
+        $data = BuyLogic::getGoodsListLogic();
+        return $this->success($data);
+    }
+}

+ 70 - 0
app/Http/Logic/Buy/BuyLogic.php

@@ -0,0 +1,70 @@
+<?php
+
+
+namespace App\Http\Logic\Buy;
+
+
+use App\Http\Bean\Util\Jutuike\GoodsListParamBean;
+use App\Http\Logic\BaseLogic;
+use App\Http\Utils\BaseUtil;
+use App\Http\Utils\Jutuike\JutuikeUtil;
+use App\Models\UserModel;
+
+class BuyLogic extends BaseLogic
+{
+    /**
+     * 电商平台分类逻辑
+     */
+    public static function getCateListLogic()
+    {
+        $params = request()->all();
+
+        $lists = JutuikeUtil::goodsCategory($params["source"]);
+
+        $datas = [];
+        foreach ($lists as $key=>$list){
+            $datas[] = [
+                "id"=>$key,
+                "name"=>$list
+            ];
+        }
+        return $datas;
+    }
+
+    /**
+     * 获取商品列表逻辑
+     */
+    public static function getGoodsListLogic()
+    {
+        $params = request()->all();
+
+        $arr = [
+            "source"=>$params["source"],
+            "cat"=>$params["cat_id"],
+            "page"=>$params["page"],
+            "pageSize"=>$params["page_size"],
+        ];
+
+        $user = UserModel::findById(BaseUtil::getUserId());
+
+        $bean = new GoodsListParamBean($arr);
+
+        $lists = JutuikeUtil::goodsList($bean);
+
+        $datas = [];
+        foreach ($lists["list"] as $list){
+            $datas[] = [
+                "goods_name"=>$list["goodsName"],
+                "goods_thumb_url"=>$list["goodsThumbUrl"],
+                "market_price"=>$list["marketPrice"],
+                "price"=>$list["price"],
+                "goods_id"=>$list["goodsId"],
+                "commission"=>floor($list["commission"]*$user["user_commission_rate"]/100),
+            ];
+        }
+        return [
+            "total"=>$list["count"],
+            "list"=>$datas
+        ];
+    }
+}

+ 4 - 1
app/Http/Utils/Jutuike/JutuikeUtil.php

@@ -200,7 +200,10 @@ class JutuikeUtil extends BaseUtil
             $instance->info("上游返回数据:".json_encode($res));
             throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
         }
-        return $res["data"];
+        return [
+            "count"=>$res["total_results"],
+            "list"=>$res["data"]
+        ];
     }
 
     /**

+ 62 - 0
app/Http/Validate/Buy/BuyControllerValidate.php

@@ -0,0 +1,62 @@
+<?php
+
+
+namespace App\Http\Validate\Buy;
+
+
+use App\Http\Validate\BaseValidate;
+use Illuminate\Support\Facades\Validator;
+
+class BuyControllerValidate extends BaseValidate
+{
+    /**
+     * 电商平台分类列表参数校验
+     * @param $data
+     * @return bool
+     */
+    public function getCateList($data)
+    {
+        $validate = Validator::make($data,
+            [
+                "source"=>"required|integer",
+            ]
+        );
+        if($validate->fails()){
+            //验证错误
+            $this->setError($validate->errors()->first());
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 商品列表参数校验
+     * @param $data
+     */
+    public function getGoodsList($data)
+    {
+        $validate = Validator::make($data,
+            [
+                "source"=>"required|integer",
+                "cat_id"=>"required|integer",
+                "page"=>"required|integer",
+                "page_size"=>"required|integer",
+            ]
+        );
+        if($validate->fails()){
+            //验证错误
+            $this->setError($validate->errors()->first());
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 商品详情页参数校验
+     * @param $data
+     */
+    public function getGoodsDetail($data)
+    {
+
+    }
+}

+ 135 - 0
public/swagger.json

@@ -10,6 +10,101 @@
         "http"
     ],
     "paths": {
+        "/buy/cate/list": {
+            "get": {
+                "tags": [
+                    "\u7535\u5546\u5bfc\u8d2d"
+                ],
+                "summary": "\u83b7\u53d6\u7535\u5546\u5e73\u53f0\u5206\u7c7b",
+                "description": "\u83b7\u53d6\u7535\u5546\u5e73\u53f0\u5206\u7c7b",
+                "produces": [
+                    "application/json"
+                ],
+                "parameters": [
+                    {
+                        "name": "source",
+                        "in": "query",
+                        "description": "\u6765\u6e90 jd-\u4eac\u4e1c,vip-\u552f\u54c1\u4f1a,pdd-\u62fc\u591a\u591a,kaola-\u8003\u62c9,taobao-\u6dd8\u5b9d",
+                        "type": "string"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "success",
+                        "schema": {
+                            "properties": {
+                                "id": {
+                                    "description": "\u5206\u7c7bID",
+                                    "type": "string"
+                                },
+                                "name": {
+                                    "description": "\u5206\u7c7b\u540d\u79f0",
+                                    "type": "string"
+                                }
+                            }
+                        }
+                    },
+                    "403": {
+                        "description": "fail",
+                        "schema": {
+                            "$ref": "#/definitions/ErrorBean"
+                        }
+                    }
+                }
+            }
+        },
+        "/buy/goods/list": {
+            "post": {
+                "tags": [
+                    "\u7535\u5546\u5bfc\u8d2d"
+                ],
+                "summary": "\u5546\u54c1\u5217\u8868\u63a5\u53e3",
+                "description": "\u5546\u54c1\u5217\u8868\u63a5\u53e3",
+                "produces": [
+                    "application/json"
+                ],
+                "parameters": [
+                    {
+                        "name": "page",
+                        "in": "query",
+                        "description": "\u7b2c\u51e0\u9875",
+                        "type": "string"
+                    },
+                    {
+                        "name": "page_size",
+                        "in": "query",
+                        "description": "\u6bcf\u9875\u6570\u91cf",
+                        "type": "string"
+                    },
+                    {
+                        "name": "source",
+                        "in": "query",
+                        "description": "\u6765\u6e90 jd-\u4eac\u4e1c,vip-\u552f\u54c1\u4f1a,pdd-\u62fc\u591a\u591a,kaola-\u8003\u62c9,taobao-\u6dd8\u5b9d",
+                        "type": "string"
+                    },
+                    {
+                        "name": "cat_id",
+                        "in": "query",
+                        "description": "\u5206\u7c7bID",
+                        "type": "string"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "success",
+                        "schema": {
+                            "$ref": "#/definitions/GetGoodsListResultBean"
+                        }
+                    },
+                    "403": {
+                        "description": "fail",
+                        "schema": {
+                            "$ref": "#/definitions/ErrorBean"
+                        }
+                    }
+                }
+            }
+        },
         "/home/list": {
             "get": {
                 "tags": [
@@ -911,6 +1006,46 @@
         }
     },
     "definitions": {
+        "GetGoodsListResultBean": {
+            "properties": {
+                "total": {
+                    "description": "\u603b\u6570\u91cf",
+                    "type": "string"
+                },
+                "list": {
+                    "description": "\u6570\u636e",
+                    "type": "array",
+                    "items": {
+                        "properties": {
+                            "goods_name": {
+                                "description": "\u5546\u54c1\u540d\u79f0",
+                                "type": "string"
+                            },
+                            "goods_thumb_url": {
+                                "description": "\u5546\u54c1\u56fe\u7247",
+                                "type": "string"
+                            },
+                            "market_price": {
+                                "description": "\u5e02\u573a\u4ef7\u683c",
+                                "type": "string"
+                            },
+                            "price": {
+                                "description": "\u4f18\u60e0\u4ef7",
+                                "type": "string"
+                            },
+                            "goods_id": {
+                                "description": "\u5546\u54c1ID",
+                                "type": "string"
+                            },
+                            "commission": {
+                                "description": "\u4f63\u91d1(\u5355\u4f4d\u4e3a\u5206)",
+                                "type": "string"
+                            }
+                        }
+                    }
+                }
+            }
+        },
         "GetOrderListResultBean": {
             "properties": {
                 "total": {

+ 7 - 0
routes/api.php

@@ -104,8 +104,15 @@ Route::prefix("pdd")->namespace("Pdd")->middleware(["checkAuth"])->group(functio
     Route::get("goods/recommendurl","PddController@getGoodsRecommendUrl");
 });
 
+
 //电商相关接口
 Route::prefix("buy")->namespace("Buy")->middleware(["checkAuth"])->group(function (){
+    //获取商品类目接口
+    Route::get("cate/list","BuyController@getCateList");
+    //获取商品列表接口
+    Route::get("goods/list","BuyController@getGoodsList");
+    //获取商品详情页接口
+    Route::get("goods/detail","BuyController@getGoodsDetail");
 
 });