sunxbiao месяцев назад: 9
Родитель
Сommit
c7021f436d

+ 42 - 0
app/common/dao/third/ThirdPartyGoodCacheDao.php

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace app\common\dao\third;
4
+
5
+use app\common\dao\BaseDao;
6
+use app\common\model\third\ThirdPartyGoodCacheModel;
7
+use app\entity\CommonEntity;
8
+use app\entity\data\third\ThirdPartyGoodCacheEntity;
9
+
10
+class ThirdPartyGoodCacheDao extends BaseDao
11
+{
12
+
13
+    protected function getModel(): string
14
+    {
15
+        return ThirdPartyGoodCacheModel::class;
16
+    }
17
+
18
+    /**
19
+     * @param array $productIdList
20
+     * @return CommonEntity[]
21
+     */
22
+    public function getThirdPartyGoodCacheEntityListByProductIdList(array $productIdList): array
23
+    {
24
+        $entityList = [];
25
+        try {
26
+            /** @var ThirdPartyGoodCacheModel $model */
27
+            $model = $this->getModel();
28
+            $dataRes = $model::getDB()
29
+                ->whereIn('product_id', $productIdList)
30
+                ->select()
31
+                ->toArray();
32
+            if (!empty($dataRes)) {
33
+                $entityList = array_map(function ($data) {
34
+                    return ThirdPartyGoodCacheEntity::newInstance($data);
35
+                }, $dataRes);
36
+            }
37
+        } catch (\Exception $e) {
38
+
39
+        }
40
+        return $entityList;
41
+    }
42
+}

+ 34 - 0
app/common/enum/third/ThirdPartyGoodCacheEnum.php

@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+namespace app\common\enum\third;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class ThirdPartyGoodCacheEnum extends CommonEnum
8
+{
9
+    const PLATFORM = [
10
+        'Taobao' => ['code' => 'TB', 'name' => '淘宝'],
11
+        'Jingdong' => ['code' => 'JD', 'name' => '京东'],
12
+        'Pdd' => ['code' => 'PDD', 'name' => '拼多多'],
13
+        'Suning' => ['code' => 'SN', 'name' => '苏宁'],
14
+        'Vipshop' => ['code' => 'VPH', 'name' => '唯品会'],
15
+        'Douyin' => ['code' => 'DY', 'name' => '抖音']
16
+    ];
17
+
18
+    /**
19
+     * @param $type
20
+     * @return mixed
21
+     */
22
+    public static function platformCodeMapByThirdPartyGoodEnumTypeCode($type)
23
+    {
24
+        $map = [
25
+            1 => self::PLATFORM['Taobao']['code'],
26
+            2 => self::PLATFORM['Jingdong']['code'],
27
+            3 => self::PLATFORM['Pdd']['code'],
28
+            4 => self::PLATFORM['Suning']['code'],
29
+            5 => self::PLATFORM['Vipshop']['code'],
30
+            9 => self::PLATFORM['Douyin']['code']
31
+        ];
32
+        return $map[$type];
33
+    }
34
+}

+ 18 - 0
app/common/enum/third/ThirdPartyGoodEnum.php

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace app\common\enum\third;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class ThirdPartyGoodEnum extends CommonEnum
8
+{
9
+    // 1-淘宝,2-京东,3-拼多多,4-苏宁,5-唯品会,9-抖音
10
+    const TYPE = [
11
+        'Taobao' => ['code' => 1, 'name' => '淘宝'],
12
+        'Jingdong' => ['code' => 2, 'name' => '京东'],
13
+        'Pdd' => ['code' => 3, 'name' => '拼多多'],
14
+        'Suning' => ['code' => 4, 'name' => '苏宁'],
15
+        'Vipshop' => ['code' => 5, 'name' => '唯品会'],
16
+        'Douyin' => ['code' => 9, 'name' => '抖音'],
17
+    ];
18
+}

+ 18 - 0
app/common/model/third/ThirdPartyGoodCacheModel.php

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace app\common\model\third;
4
+
5
+use app\common\model\BaseModel;
6
+
7
+class ThirdPartyGoodCacheModel extends BaseModel
8
+{
9
+    public static function tablePk(): string
10
+    {
11
+        return 'product_id';
12
+    }
13
+
14
+    public static function tableName(): string
15
+    {
16
+        return 'third_party_good_cache';
17
+    }
18
+}

+ 128 - 0
app/common/repositories/third/ThirdPartyGoodCacheRepository.php

@@ -0,0 +1,128 @@
1
+<?php
2
+
3
+namespace app\common\repositories\third;
4
+
5
+use app\common\dao\third\ThirdPartyGoodCacheDao;
6
+use app\common\enum\third\ThirdPartyGoodCacheEnum;
7
+use app\common\repositories\BaseRepository;
8
+use app\entity\data\third\ThirdPartyGoodCacheEntity;
9
+use think\exception\ValidateException;
10
+
11
+class ThirdPartyGoodCacheRepository extends BaseRepository
12
+{
13
+    /**
14
+     * @var ThirdPartyGoodCacheDao
15
+     */
16
+    protected $dao;
17
+
18
+    public function __construct(ThirdPartyGoodCacheDao $dao)
19
+    {
20
+        $this->dao = $dao;
21
+    }
22
+
23
+    public function create($data)
24
+    {
25
+        return $this->dao->create($data);
26
+    }
27
+
28
+    /**
29
+     * 写入贡献值记录
30
+     * @param ThirdPartyGoodCacheEntity $storeGroupOrderEntity
31
+     * @return ThirdPartyGoodCacheEntity
32
+     */
33
+    public function createByEntity(ThirdPartyGoodCacheEntity $storeGroupOrderEntity): ThirdPartyGoodCacheEntity
34
+    {
35
+        $result = $this->create($storeGroupOrderEntity->toUnderlineArray())->toArray();
36
+        /** @var ThirdPartyGoodCacheEntity $entity */
37
+        $entity = ThirdPartyGoodCacheEntity::newInstance($result);
38
+        return $entity;
39
+    }
40
+
41
+    /**
42
+     * @param $ids
43
+     * @param $data
44
+     * @return int
45
+     * @throws \think\db\exception\DbException
46
+     */
47
+    public function updates($ids, $data): int
48
+    {
49
+        return $this->dao->updates($ids, $data);
50
+    }
51
+
52
+    /**
53
+     * @param ThirdPartyGoodCacheEntity $thirdPartyProductEntity
54
+     * @return ThirdPartyGoodCacheEntity|false
55
+     * @throws \think\db\exception\DbException
56
+     */
57
+    public function updatesByEntity(ThirdPartyGoodCacheEntity $thirdPartyProductEntity)
58
+    {
59
+        $result = $this->updates([$thirdPartyProductEntity->getProductId()], $thirdPartyProductEntity->toUnderlineArray());
60
+        if (empty($result)) {
61
+            return false;
62
+        }
63
+        return $thirdPartyProductEntity;
64
+    }
65
+
66
+    /**
67
+     * @param string $productId
68
+     * @return ThirdPartyGoodCacheEntity
69
+     */
70
+    public function getThirdPartyGoodCacheEntityByProductId(string $productId): ThirdPartyGoodCacheEntity
71
+    {
72
+        $entityList = $this->getThirdPartyGoodCacheEntityListByProductIdList([$productId]);
73
+        $entity = array_shift($entityList);
74
+        if ($entity instanceof ThirdPartyGoodCacheEntity) {
75
+            return $entity;
76
+        } else {
77
+            /** @var ThirdPartyGoodCacheEntity */
78
+            return ThirdPartyGoodCacheEntity::newInstance();
79
+        }
80
+    }
81
+
82
+    /**
83
+     * @param array $productIdList
84
+     * @return ThirdPartyGoodCacheEntity[]
85
+     */
86
+    public function getThirdPartyGoodCacheEntityListByProductIdList(array $productIdList): array
87
+    {
88
+        return $this->dao->getThirdPartyGoodCacheEntityListByProductIdList($productIdList);
89
+    }
90
+
91
+    /**
92
+     * @param $param
93
+     * @return ThirdPartyGoodCacheEntity
94
+     * @throws \think\db\exception\DbException
95
+     */
96
+    public function saveGoodCacheByFit($param): ThirdPartyGoodCacheEntity
97
+    {
98
+        if (empty($param['skuId']) || empty($param['type'])) {
99
+            throw new ValidateException('缺少必要参数');
100
+        }
101
+        $skuId = $param['skuId'];
102
+        $platform = ThirdPartyGoodCacheEnum::platformCodeMapByThirdPartyGoodEnumTypeCode($param['type']);
103
+
104
+        /** @var ThirdPartyGoodCacheRepository $thirdPartyProductRepository */
105
+        $thirdPartyProductRepository = app()->make(ThirdPartyGoodCacheRepository::class);
106
+        $thirdPartyProductEntity = $thirdPartyProductRepository->getThirdPartyGoodCacheEntityByProductId($skuId);
107
+
108
+        if (empty($thirdPartyProductEntity->getProductId())) {
109
+            /** @var ThirdPartyGoodCacheEntity $thirdPartyProductEntity */
110
+            $thirdPartyProductEntity = ThirdPartyGoodCacheEntity::newInstance();
111
+            $thirdPartyProductEntity
112
+                ->setProductId($skuId)
113
+                ->setPlatform($platform)
114
+                ->setExtraContent($param);
115
+            $thirdPartyProductEntity = $thirdPartyProductRepository->createByEntity($thirdPartyProductEntity);
116
+            if (empty($thirdPartyProductEntity->getProductId())) {
117
+                throw new ValidateException('保存失败');
118
+            }
119
+        } else {
120
+            $thirdPartyProductEntity
121
+                ->setProductId($skuId)
122
+                ->setPlatform($platform)
123
+                ->setExtraContent($param);
124
+            $thirdPartyProductRepository->updatesByEntity($thirdPartyProductEntity);
125
+        }
126
+        return $thirdPartyProductEntity;
127
+    }
128
+}

+ 29 - 0
app/controller/api/thirdParty/Taobao/EcoController.php

@@ -0,0 +1,29 @@
1
+<?php
2
+
3
+namespace app\controller\api\thirdParty\Taobao;
4
+
5
+
6
+use app\services\ThirdParty\Taobao\ProductService;
7
+use think\Request;
8
+
9
+class EcoController
10
+{
11
+
12
+    /**
13
+     * 查询 商品信息
14
+     * @param Request $request
15
+     * @return mixed
16
+     */
17
+    public function searchProducts(Request $request)
18
+    {
19
+        try {
20
+            /** @var ProductService $productService */
21
+            $productService = app()->make(ProductService::class);
22
+            $products = $productService->searchProducts($request->param());
23
+            $productDataList = $productService->generateUniversalTemplate($products);
24
+            return app("json")->success($productDataList);
25
+        } catch (\Exception $exception) {
26
+            return app('json')->fail($exception->getMessage(), null, 401);
27
+        }
28
+    }
29
+}

+ 40 - 0
app/controller/api/thirdParty/ThirdPartyGoodCacheController.php

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace app\controller\api\thirdParty;
4
+
5
+use app\common\repositories\third\ThirdPartyGoodCacheRepository;
6
+use think\db\exception\DbException;
7
+use think\Request;
8
+
9
+class ThirdPartyGoodCacheController
10
+{
11
+    protected $repository;
12
+
13
+    public function __construct(ThirdPartyGoodCacheRepository $repository)
14
+    {
15
+        $this->repository = $repository;
16
+    }
17
+
18
+    /**
19
+     * @param Request $request
20
+     * @return void
21
+     */
22
+    public function saveGoodCacheByFit(Request $request)
23
+    {
24
+        try {
25
+            $thirdPartyGoodCacheEntity = $this->repository->saveGoodCacheByFit($request->param());
26
+            return app("json")->success($thirdPartyGoodCacheEntity->toArray());
27
+        } catch (DbException $e) {
28
+            return app('json')->fail($e->getMessage(), null, 401);
29
+        }
30
+    }
31
+
32
+    public function getGoodCache(Request $request)
33
+    {
34
+        if (empty($request['productId'])) {
35
+            return app('json')->fail('缺少必要参数', null, 401);
36
+        }
37
+        $thirdPartyGoodCacheEntity = $this->repository->getThirdPartyGoodCacheEntityByProductId($request['productId']);
38
+        return app("json")->success($thirdPartyGoodCacheEntity->toArray());
39
+    }
40
+}

+ 107 - 0
app/entity/data/third/ThirdPartyGoodCacheEntity.php

@@ -0,0 +1,107 @@
1
+<?php
2
+
3
+namespace app\entity\data\third;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class ThirdPartyGoodCacheEntity extends DataEntity
8
+{
9
+    public $productId = null;  // 商品ID
10
+    public $platform = null;    // 所属平台前缀
11
+    public $extraContent = null; // 扩展信息
12
+    public $createTime = null;  // 添加时间
13
+    public $updateTime = null;  // 更新时间
14
+
15
+    /**
16
+     * @return mixed
17
+     */
18
+    public function getProductId()
19
+    {
20
+        return $this->productId;
21
+    }
22
+
23
+    /**
24
+     * @param mixed $productId
25
+     * @return ThirdPartyGoodCacheEntity
26
+     */
27
+    public function setProductId($productId): ThirdPartyGoodCacheEntity
28
+    {
29
+        $this->productId = $productId;
30
+        return $this;
31
+    }
32
+
33
+    /**
34
+     * @return mixed
35
+     */
36
+    public function getPlatform()
37
+    {
38
+        return $this->platform;
39
+    }
40
+
41
+    /**
42
+     * @param mixed $platform
43
+     * @return ThirdPartyGoodCacheEntity
44
+     */
45
+    public function setPlatform($platform): ThirdPartyGoodCacheEntity
46
+    {
47
+        $this->platform = $platform;
48
+        return $this;
49
+    }
50
+
51
+    /**
52
+     * @return mixed
53
+     */
54
+    public function getExtraContent()
55
+    {
56
+        return $this->extraContent;
57
+    }
58
+
59
+    /**
60
+     * @param mixed $extraContent
61
+     * @return ThirdPartyGoodCacheEntity
62
+     */
63
+    public function setExtraContent($extraContent): ThirdPartyGoodCacheEntity
64
+    {
65
+        if (is_array($extraContent)) {
66
+            $extraContent = json_encode($extraContent, JSON_UNESCAPED_UNICODE);
67
+        }
68
+        $this->extraContent = $extraContent;
69
+        return $this;
70
+    }
71
+
72
+    /**
73
+     * @return mixed
74
+     */
75
+    public function getCreateTime()
76
+    {
77
+        return $this->createTime;
78
+    }
79
+
80
+    /**
81
+     * @param mixed $createTime
82
+     * @return ThirdPartyGoodCacheEntity
83
+     */
84
+    public function setCreateTime($createTime): ThirdPartyGoodCacheEntity
85
+    {
86
+        $this->createTime = $createTime;
87
+        return $this;
88
+    }
89
+
90
+    /**
91
+     * @return mixed
92
+     */
93
+    public function getUpdateTime()
94
+    {
95
+        return $this->updateTime;
96
+    }
97
+
98
+    /**
99
+     * @param mixed $updateTime
100
+     * @return ThirdPartyGoodCacheEntity
101
+     */
102
+    public function setUpdateTime($updateTime): ThirdPartyGoodCacheEntity
103
+    {
104
+        $this->updateTime = $updateTime;
105
+        return $this;
106
+    }
107
+}

+ 143 - 0
app/services/ThirdParty/Taobao/ProductService.php

@@ -0,0 +1,143 @@
1
+<?php
2
+
3
+namespace app\services\ThirdParty\Taobao;
4
+
5
+use app\common\enum\third\ThirdPartyGoodCacheEnum;
6
+use app\common\enum\third\ThirdPartyGoodEnum;
7
+use app\utils\ArrayUtil;
8
+use think\exception\ValidateException;
9
+
10
+class ProductService extends TaobaoService
11
+{
12
+
13
+    protected $cat;
14
+
15
+    public function __construct()
16
+    {
17
+        parent::__construct();
18
+
19
+        $this->cat = $this->config['taobao']['cat'];
20
+    }
21
+
22
+    /**
23
+     * 商品搜索 TbkDgMaterialRecommendRequest
24
+     * 推广者使用,支持入参对应的“推广位”和官方提供的“物料id”,获取指定物料信息和推广链接。
25
+     * Tack:taobao.tbk.dg.material.optional.upgrade
26
+     * 官方文档地址:https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.5cf2669aEojnlE&source=search&docId=64759&docType=2#responseParams
27
+     * @param $params
28
+     * @return mixed
29
+     */
30
+    public function searchProducts($params)
31
+    {
32
+        $req = new \TbkDgMaterialOptionalUpgradeRequest();
33
+        $this->batchSetProperties($req, $params);
34
+        $req->setAdzoneId($this->adzoneId);
35
+        // 商品筛选-后台类目ID 和 商品筛选-查询词 必须填一个
36
+        if (empty($req->getQ())) {
37
+            $req->setCat($this->cat);
38
+        }
39
+        // SimpleXMLElement
40
+        $res = $this->execute($req);
41
+        if (!$res) {
42
+            throw new ValidateException('网络错误,请稍后重试');
43
+        }
44
+        return $res;
45
+    }
46
+
47
+    /**
48
+     * @param $res
49
+     * @return array
50
+     */
51
+    public function generateUniversalTemplate($res): array
52
+    {
53
+        // 将 SimpleXMLElement 转换为数组
54
+        $resMap = json_decode(json_encode($res), true);
55
+        $productList = [];
56
+        if (!empty($resMap['result_list']['map_data'])) {
57
+            foreach ($resMap['result_list']['map_data'] as $data) {
58
+                // $productList[] = $data;
59
+                $coupon_money = [];
60
+                // 链接-宝贝+券二合一页面链接 || 链接-宝贝推广链接
61
+                $coupon_share_url = $data['publish_info']['coupon_share_url'] ?? ($data['publish_info']['click_url'] ?? '');
62
+                // 商品佣金金额
63
+                $commissionMoney = $data['publish_info']['income_info']['commission_amount'];
64
+                $commissionMoney = bcmul($commissionMoney, 0.8, 2);
65
+
66
+                // 到手价优惠路径列表 也就是 需要把列表内所有优惠叠加 才能从划线价 到达 到手价
67
+                if (!empty($data['price_promotion_info']['final_promotion_path_list']['final_promotion_path_map_data'])) {
68
+                    if (is_array($data['price_promotion_info']['final_promotion_path_list']['final_promotion_path_map_data'])) {
69
+                        $depth = ArrayUtil::array_depth($data['price_promotion_info']['final_promotion_path_list']['final_promotion_path_map_data']);
70
+                        if ($depth === 1) {
71
+                            $coupon_money[] = [
72
+                                'discount' => $data['price_promotion_info']['final_promotion_path_list']['final_promotion_path_map_data']['promotion_fee'], // 实际优惠金额(元)
73
+                                'getStartTime' => '',
74
+                                'getEndTime' => '',
75
+                                'link' => $data['publish_info']['coupon_share_url'] ?? '',
76
+                                'useStartTime' => '',
77
+                                'useEndTime' => '',
78
+                            ];
79
+                        } else {
80
+                            foreach ($data['price_promotion_info']['final_promotion_path_list']['final_promotion_path_map_data'] as $coupon) {
81
+                                if (!empty($coupon['promotion_fee']) && (0.00 < (double)$coupon['promotion_fee'])) {
82
+                                    $coupon_money[] = [
83
+                                        'discount' => $coupon['promotion_fee'], // 实际优惠金额(元)
84
+                                        'getStartTime' => '',
85
+                                        'getEndTime' => '',
86
+                                        'link' => $data['publish_info']['coupon_share_url'] ?? '',
87
+                                        'useStartTime' => '',
88
+                                        'useEndTime' => '',
89
+                                    ];
90
+                                }
91
+                            }
92
+                        }
93
+                    }
94
+
95
+                }
96
+
97
+                if (empty($data['item_id'])) {
98
+                    throw new ValidateException('缺少必要参数');
99
+                }
100
+                $skuId = $data['item_id'];
101
+                $segments = explode('-', $skuId);
102
+                $skuId = end($segments);
103
+                $skuId = ThirdPartyGoodCacheEnum::PLATFORM['Taobao']['code'] . '_' . $skuId;
104
+
105
+                $productList[] = [
106
+                    // 商品信息-淘宝客新商品id;
107
+                    'skuId' => $skuId,
108
+                    'itemId' => $data['item_id'],
109
+                    'type' => ThirdPartyGoodEnum::TYPE['Taobao']['code'],
110
+                    // 商品信息-商品标题
111
+                    'name' => $data['item_basic_info']['title'] ?? '',
112
+                    // 商品信息-商品主图
113
+                    'thumb' => $data['item_basic_info']['pict_url'] ?? '',
114
+
115
+                    'pv' => bcmul($commissionMoney, 0.7, 2),//PV金额
116
+                    'gongxian' => bcmul($commissionMoney, 0.7, 2),
117
+                    'jifen' => bcmul($commissionMoney, 0.7, 2),
118
+                    'yanglaojin' => bcmul($commissionMoney, 0.3, 2),
119
+
120
+                    // 商品佣金金额
121
+                    'commission' => $data['publish_info']['income_info']['commission_amount'] ?? 0.00,
122
+                    // 商品佣金比率
123
+                    'commission_rate' => bcdiv($data['publish_info']['income_info']['commission_rate'] ?? 0, 100, 2),
124
+                    // 优惠券集合
125
+                    'coupon_money' => $coupon_money,
126
+                    // 优惠券地址
127
+                    'coupon_link' => $coupon_share_url,
128
+                    // 最低 实际价格 促销信息-预估到手价(元)。若属于预售商品,付定金时间内,预估到手价价=定金+尾款的预估到手价
129
+                    'lowestCouponPrice' => $data['price_promotion_info']['final_promotion_price'],
130
+                    // 划线价 促销信息-销售价格,无促销时等于一口价,有促销时为促销价。若属于预售商品,付定金时间内,在线售卖价=预售价 ?? 商品信息-一口价通常显示为划线价
131
+                    'price' => $data['price_promotion_info']['zk_final_price'] ?? $data['price_promotion_info']['reserve_price'],
132
+                    'imageList' => $data['item_basic_info']['small_images']['string'],
133
+                    'materialUrl' => $coupon_share_url,
134
+                    // 最低 实际价格 促销信息-预估到手价(元)。若属于预售商品,付定金时间内,预估到手价价=定金+尾款的预估到手价
135
+                    'commission_' => $data['price_promotion_info']['final_promotion_price'],
136
+                    'monthSales' => 0.00,
137
+                    'cid' => 0
138
+                ];
139
+            }
140
+        }
141
+        return $productList;
142
+    }
143
+}

+ 76 - 0
app/services/ThirdParty/Taobao/TaobaoService.php

@@ -0,0 +1,76 @@
1
+<?php
2
+
3
+namespace app\services\ThirdParty\Taobao;
4
+
5
+use think\facade\Config;
6
+use think\facade\Log;
7
+
8
+class TaobaoService
9
+{
10
+    protected $client;
11
+    protected $config;
12
+    protected $adzoneId;
13
+
14
+    public function __construct()
15
+    {
16
+        // 从配置文件读取淘宝联盟配置
17
+        $this->config = Config::get('third_party');
18
+
19
+        // 引入淘宝SDK
20
+        require_once app()->getRootPath() . 'extend/TaobaoSdk/TopSdk.php';
21
+
22
+        $this->client = new \TopClient();
23
+        $this->client->appkey = $this->config['taobao']['appKey'];
24
+        $this->client->secretKey = $this->config['taobao']['appSecret'];
25
+        // 推广位ID
26
+        $this->adzoneId = $this->config['taobao']['adzoneId'];
27
+    }
28
+
29
+    /**
30
+     * 执行API请求
31
+     * @param $request
32
+     * @return false|mixed
33
+     */
34
+    protected function execute($request)
35
+    {
36
+        try {
37
+            $response = $this->client->execute($request);
38
+            // var_dump($response);
39
+            return $this->formatResponse($response);
40
+        } catch (\Exception $e) {
41
+            // 记录错误日志
42
+            Log::error('淘宝API请求失败: ' . $e->getMessage());
43
+            return false;
44
+        }
45
+    }
46
+
47
+    /**
48
+     * 格式化响应
49
+     * @param $response
50
+     * @return false|mixed
51
+     */
52
+    protected function formatResponse($response)
53
+    {
54
+        if (isset($response->code) && $response->code) {
55
+            // API返回错误
56
+            Log::error("淘宝API错误: {$response->msg} [{$response->code}]");
57
+            return false;
58
+        }
59
+        return $response;
60
+    }
61
+
62
+    /**
63
+     * 批量设置对象属性
64
+     * @param object $object 目标对象
65
+     * @param array $params 参数数组
66
+     */
67
+    protected function batchSetProperties($object, array $params)
68
+    {
69
+        foreach ($params as $key => $value) {
70
+            $setter = 'set' . ucfirst($key);
71
+            if (method_exists($object, $setter)) {
72
+                $object->$setter($value);
73
+            }
74
+        }
75
+    }
76
+}

+ 20 - 0
app/utils/ArrayUtil.php

@@ -43,4 +43,24 @@ class ArrayUtil
43 43
         }
44 44
         return null;
45 45
     }
46
+
47
+    /**
48
+     * 获取数组维度 几维数组
49
+     * @param $array
50
+     * @return int
51
+     */
52
+    public static function array_depth($array): int
53
+    {
54
+        if (!is_array($array)) return 0;
55
+        $max_depth = 1;
56
+        foreach ($array as $value) {
57
+            if (is_array($value)) {
58
+                $depth = self::array_depth($value) + 1;
59
+                if ($depth > $max_depth) {
60
+                    $max_depth = $depth;
61
+                }
62
+            }
63
+        }
64
+        return $max_depth;
65
+    }
46 66
 }

+ 12 - 0
config/third_party.php

@@ -0,0 +1,12 @@
1
+<?php
2
+
3
+return [
4
+    'taobao' => [
5
+        'appKey' => '35214206',
6
+        'appSecret' => 'b4ec4e885fb4a189d3beb475fbb15dc6',
7
+        // 推广位ID
8
+        'adzoneId' => 116174700455,
9
+        // 商品筛选-后台类目ID。用,分割,最大10个
10
+        'cat' => '50016422,50012486,50008164,50002766,50050359,50022703,50000436,50011130,50011277,50020579'
11
+    ]
12
+];

+ 12 - 0
route/api.php

@@ -32,6 +32,18 @@ Route::group('lplplp',function (){
32 32
     ->middleware(\app\common\middleware\InstallMiddleware::class)
33 33
     ->middleware(\app\common\middleware\CheckSiteOpenMiddleware::class);
34 34
 Route::group('api/', function () {
35
+
36
+    Route::group('thirdParty', function () {
37
+        // 保存第三方商品信息
38
+        Route::post('saveGoodCacheByFit', 'ThirdPartyGoodCacheController/saveGoodCacheByFit');
39
+        // 获取第三方商品信息
40
+        Route::get('getGoodCache', 'ThirdPartyGoodCacheController/getGoodCache');
41
+
42
+        Route::group('taobao', function () {
43
+            Route::get('eco/searchProducts', 'EcoController/searchProducts');
44
+        })->prefix('api.thirdParty.taobao.');
45
+    })->prefix('api.thirdParty.');
46
+
35 47
     Route::any('huiFuSettleIn','admin.system.merchant.MerchantIntention/huiFuSettleIn');//汇付入驻测试
36 48
     Route::any('test', 'api.Auth/test');
37 49
     Route::any('queryHaike', 'api.Auth/queryHaike');