|
|
@@ -4,8 +4,11 @@ namespace app\controller\api\store\product;
|
|
4
|
4
|
|
|
5
|
5
|
use app\common\repositories\store\product\ProductRepository;
|
|
6
|
6
|
use app\common\repositories\user\UserThirdRepository;
|
|
|
7
|
+use app\model\common\JdOrderModel;
|
|
|
8
|
+use DateTime;
|
|
7
|
9
|
use think\App;
|
|
8
|
10
|
use crmeb\basic\BaseController;
|
|
|
11
|
+use think\db\exception\DbException;
|
|
9
|
12
|
use think\Exception;
|
|
10
|
13
|
use think\exception\ValidateException;
|
|
11
|
14
|
use think\facade\Db;
|
|
|
@@ -24,10 +27,14 @@ class Jd extends BaseController
|
|
24
|
27
|
{
|
|
25
|
28
|
|
|
26
|
29
|
parent::__construct($app);
|
|
27
|
|
- $this->appid = '4100076550';
|
|
28
|
|
- $this->key = '5ce3da55dc739b6e7d9021d59618c5faa3b4030f41c5699658c7ca30cfd19f09b4046d606d196f1d';
|
|
29
|
|
- $this->appKey = 'a2ad5078501e928b991cd8aaeb0446dc';
|
|
30
|
|
- $this->secretKey = 'fd8aab59e9b94d9e889cb22838c03f2a';
|
|
|
30
|
+ $this->appid = '4101490811';
|
|
|
31
|
+ $this->key = 'a7c43c21f3e156d2fd41dfbe884b9f62592ceb03b9f199c0811c82e35be53c0580a2638a7af39e74';
|
|
|
32
|
+ $this->appKey = 'e99703d01cbb6a2e48a8a34f19af9d87';
|
|
|
33
|
+ $this->secretKey = 'cea7578d5a314ef88086daa4ee3a5b4d';
|
|
|
34
|
+ // $this->appid = '4100076550';
|
|
|
35
|
+ // $this->key = '5ce3da55dc739b6e7d9021d59618c5faa3b4030f41c5699658c7ca30cfd19f09b4046d606d196f1d';
|
|
|
36
|
+ // $this->appKey = 'a2ad5078501e928b991cd8aaeb0446dc';
|
|
|
37
|
+ // $this->secretKey = 'fd8aab59e9b94d9e889cb22838c03f2a';
|
|
31
|
38
|
$this->userThird = app()->make(UserThirdRepository::class);
|
|
32
|
39
|
$this->url = 'https://api.jd.com/routerjson';
|
|
33
|
40
|
}
|
|
|
@@ -150,57 +157,73 @@ class Jd extends BaseController
|
|
150
|
157
|
/*京粉精选商品查询接口*/
|
|
151
|
158
|
public function jdList()
|
|
152
|
159
|
{
|
|
153
|
|
-// [$page, $limit] = $this->getPage();
|
|
154
|
|
-// $apiName = 'jd.union.open.goods.jingfen.query';
|
|
155
|
|
-// $params = [
|
|
156
|
|
-// 'goodsReq'=>[
|
|
157
|
|
-// 'eliteId'=>2,
|
|
158
|
|
-// 'pageIndex'=>$page??1,
|
|
159
|
|
-// 'pageSize' =>20,
|
|
160
|
|
-// ]
|
|
161
|
|
-// ];
|
|
162
|
|
-// $result = $this->getUrlResult($apiName,$params);
|
|
163
|
|
-// $result = json_decode($result,true);
|
|
164
|
|
-// $result = json_decode($result['jd_union_open_goods_jingfen_query_responce']['result'],true);
|
|
165
|
|
-// $result =$result['data']??[];
|
|
166
|
|
-// $goodsList = [];
|
|
167
|
|
-//
|
|
168
|
|
-// foreach ($result as $k=> $goods) {
|
|
169
|
|
-// $goodsList[] = [
|
|
170
|
|
-// 'type' => 6,//京东商品
|
|
171
|
|
-// 'skuId' =>$goods['skuId'],//skuid
|
|
172
|
|
-// 'id' => $goods['brandCode']??'', //id
|
|
173
|
|
-// 'thumb' => $goods['imageInfo']['imageList'][0]['url']??'',//商品缩略图
|
|
174
|
|
-// 'name' => $goods['skuName'],//名称
|
|
175
|
|
-// 'commission' =>app()->make(ProductRepository::class)->yanglaojin(0,$goods['commissionInfo']['commission']??''),//佣金
|
|
176
|
|
-// 'commission_rate' => $goods['commissionInfo']['commissionShare']??'',//佣金比例
|
|
177
|
|
-// 'sales' => "",
|
|
178
|
|
-// 'coupon_money' => $goods['couponInfo']['couponList'] ?? [],
|
|
179
|
|
-// 'lowestCouponPrice' => $goods['priceInfo']['price']??'', //券后价lowestCouponPrice
|
|
180
|
|
-// 'price' => $goods['priceInfo']['price']??'', //价格
|
|
181
|
|
-// ];
|
|
182
|
|
-// }
|
|
|
160
|
+ $keyword = request()->param('keyword', '');
|
|
|
161
|
+ $_cid = request()->param('cid', '');
|
|
183
|
162
|
|
|
184
|
163
|
[$page, $limit] = $this->getPage();
|
|
185
|
|
- $list = Db::name('third_party_goods')
|
|
186
|
|
- ->where('type', 2)
|
|
187
|
|
- ->page($page, $limit)
|
|
188
|
|
- ->field('json')
|
|
189
|
|
- ->select()
|
|
190
|
|
- ->toArray();
|
|
|
164
|
+
|
|
|
165
|
+
|
|
|
166
|
+ $goods_obj = Db::name('third_party_goods')
|
|
|
167
|
+ ->where('type', 2);
|
|
|
168
|
+ if ($keyword) {
|
|
|
169
|
+ $goods_obj = $goods_obj->where('json', 'like', '%' . $keyword . '%');
|
|
|
170
|
+ }
|
|
|
171
|
+ if ($_cid) {
|
|
|
172
|
+ /**
|
|
|
173
|
+ * 旧品类标识到新品类eliteId的映射关系
|
|
|
174
|
+ *
|
|
|
175
|
+ * 映射规则:
|
|
|
176
|
+ * 1. 精品(0) -> 精选卖场(2) + 自营热卖榜(41)
|
|
|
177
|
+ * 2. 其他品类按最接近的京东新分类映射
|
|
|
178
|
+ * 3. 未明确对应的品类映射到通用分类(好券商品+京东好物)
|
|
|
179
|
+ */
|
|
|
180
|
+ $oldToNewMapping = [
|
|
|
181
|
+ // 精品 -> 精选卖场 + 自营热卖榜
|
|
|
182
|
+ 0 => [2, 41],
|
|
|
183
|
+ // 居家日用 -> 家具日用
|
|
|
184
|
+ 1 => [27],
|
|
|
185
|
+ // 食品 -> 超市
|
|
|
186
|
+ 2 => [25],
|
|
|
187
|
+ // 生鲜 -> 超市
|
|
|
188
|
+ 3 => [25],
|
|
|
189
|
+ // 图书 -> 图书文具
|
|
|
190
|
+ 4 => [30],
|
|
|
191
|
+ // 美妆个护 -> 美妆穿搭
|
|
|
192
|
+ 5 => [28],
|
|
|
193
|
+ // 母婴 -> 母婴玩具
|
|
|
194
|
+ 6 => [26],
|
|
|
195
|
+ // 数码家电 -> 数码家电 + 3C新品 + 3C长尾商品
|
|
|
196
|
+ 7 => [24, 341, 343],
|
|
|
197
|
+ // 内衣 -> 京东好物(通用分类)
|
|
|
198
|
+ 8 => [32],
|
|
|
199
|
+ // 配饰 -> 京东好物(通用分类)
|
|
|
200
|
+ 9 => [32],
|
|
|
201
|
+ // 女装 -> 美妆穿搭(服装相关)
|
|
|
202
|
+ 10 => [28],
|
|
|
203
|
+ // 男装 -> 京东好物(通用分类)
|
|
|
204
|
+ 11 => [32],
|
|
|
205
|
+ // 鞋品 -> 京东好物(通用分类)
|
|
|
206
|
+ 12 => [32],
|
|
|
207
|
+ // 家装家纺 -> 家具日用
|
|
|
208
|
+ 13 => [27],
|
|
|
209
|
+ // 文娱车品 -> 图书文具 + 京东好物
|
|
|
210
|
+ 14 => [30, 32],
|
|
|
211
|
+ // 箱包 -> 京东好物(通用分类)
|
|
|
212
|
+ 15 => [32],
|
|
|
213
|
+ // 户外运动 -> 京东好物(通用分类)
|
|
|
214
|
+ 16 => [32],
|
|
|
215
|
+ ];
|
|
|
216
|
+ $goods_obj = $goods_obj->whereIn('cid', $oldToNewMapping[$_cid]);
|
|
|
217
|
+ }
|
|
|
218
|
+ $list = $goods_obj->page($page, $limit)
|
|
|
219
|
+ ->select()->toArray();
|
|
|
220
|
+
|
|
191
|
221
|
$formatList = [];
|
|
192
|
222
|
foreach ($list as $value) {
|
|
193
|
223
|
$json = json_decode($value['json'], true);
|
|
194
|
|
- $json['pension'] = $json['pension']??'0';
|
|
195
|
|
- $json['pv'] = $json['pension'];
|
|
196
|
|
- $json['yanglaojin'] = $json['pension'];
|
|
197
|
|
-
|
|
198
|
|
- // $json['shopName'] = "";
|
|
199
|
|
- // $json['monthSales'] = "0";
|
|
200
|
|
- // $json['cid'] = "0";
|
|
201
|
|
- $json['shopName'] = isset($json['shopName'])?$json['shopName']:"";
|
|
202
|
|
- $json['monthSales'] = isset($json['monthSales'])?$json['monthSales']:0;
|
|
203
|
|
- $json['cid'] = isset($value['cid'])?$json['cid']:0;
|
|
|
224
|
+ $json['commission_'] = $json['lowestCouponPrice'];
|
|
|
225
|
+ $json['monthSales'] = 0;
|
|
|
226
|
+ $json['cid'] = $value['cid'] ?? 0;
|
|
204
|
227
|
$formatList[] = $json;
|
|
205
|
228
|
}
|
|
206
|
229
|
shuffle($formatList);
|
|
|
@@ -210,7 +233,44 @@ class Jd extends BaseController
|
|
210
|
233
|
/*京粉精选商品查询接口*/
|
|
211
|
234
|
public function search()
|
|
212
|
235
|
{
|
|
213
|
|
-// [$page, $limit] = $this->getPage();
|
|
|
236
|
+ $keyword = request()->param('keyword', '');
|
|
|
237
|
+ $_cid = request()->param('cid', '');
|
|
|
238
|
+
|
|
|
239
|
+ [$page, $limit] = $this->getPage();
|
|
|
240
|
+ try {
|
|
|
241
|
+ $uid = $this->request->uid();
|
|
|
242
|
+ TaoKe::set_third_history($uid, $keyword);
|
|
|
243
|
+ } catch (\Exception $exception) {
|
|
|
244
|
+
|
|
|
245
|
+ }
|
|
|
246
|
+
|
|
|
247
|
+ $goods_obj = Db::name('third_party_goods')
|
|
|
248
|
+ -> where('type',2);
|
|
|
249
|
+ // -> when(!empty($keyword),function($query) use ($keyword) {
|
|
|
250
|
+ // $query -> where('json',"like",'%'.$keyword.'%');
|
|
|
251
|
+ // })
|
|
|
252
|
+ // -> page($page,$limit)
|
|
|
253
|
+ // -> field('json')
|
|
|
254
|
+ // -> select()
|
|
|
255
|
+ // -> toArray();
|
|
|
256
|
+
|
|
|
257
|
+ if($keyword){
|
|
|
258
|
+ $goods_obj=$goods_obj->where('json', 'like', '%' . $keyword . '%');
|
|
|
259
|
+ }
|
|
|
260
|
+ if($_cid){
|
|
|
261
|
+ $goods_obj=$goods_obj->where('cid', $_cid);
|
|
|
262
|
+ }
|
|
|
263
|
+ $list=$goods_obj->page($page, $limit)
|
|
|
264
|
+ ->select()->toArray();
|
|
|
265
|
+
|
|
|
266
|
+ $formatList = [];
|
|
|
267
|
+ foreach ($list as $value){
|
|
|
268
|
+ $formatList[] = json_decode($value['json'],true);
|
|
|
269
|
+ }
|
|
|
270
|
+ return app("json")->success($formatList);
|
|
|
271
|
+
|
|
|
272
|
+
|
|
|
273
|
+ // [$page, $limit] = $this->getPage();
|
|
214
|
274
|
// $apiName = 'jd.union.open.goods.query';
|
|
215
|
275
|
// $keyword = $this->request->param(['keyword']);
|
|
216
|
276
|
// $params = [
|
|
|
@@ -245,55 +305,79 @@ class Jd extends BaseController
|
|
245
|
305
|
// ];
|
|
246
|
306
|
// }
|
|
247
|
307
|
|
|
248
|
|
- $keyword = request()->param('keyword', '');
|
|
249
|
|
- [$page, $limit] = $this->getPage();
|
|
250
|
|
- $uid = $this->request->uid();
|
|
251
|
|
- TaoKe::set_third_history($uid, $keyword);
|
|
252
|
|
-
|
|
253
|
|
- $list = Db::name('third_party_goods')
|
|
254
|
|
- ->where('type', 2)
|
|
255
|
|
- ->when(!empty($keyword), function ($query) use ($keyword) {
|
|
256
|
|
- $query->where('json', "like", '%' . $keyword . '%');
|
|
257
|
|
- })
|
|
258
|
|
- ->page($page, $limit)
|
|
259
|
|
- ->field('json')
|
|
260
|
|
- ->select()
|
|
261
|
|
- ->toArray();
|
|
262
|
|
- $formatList = [];
|
|
263
|
|
- foreach ($list as $value) {
|
|
264
|
|
- $json = json_decode($value['json'], true);
|
|
265
|
|
- $json['pension'] = $json['pension']??'0';
|
|
266
|
|
- $json['pv'] = $json['pension']*0.5;
|
|
267
|
|
- $json['yanglaojin'] = $json['pv']*0.05;
|
|
268
|
|
-
|
|
269
|
|
- $json['shopName'] = "";
|
|
270
|
|
- $json['monthSales'] = "0";
|
|
271
|
|
- $json['cid'] = "0";
|
|
272
|
|
- $formatList[] = $json;
|
|
273
|
|
- }
|
|
274
|
|
- return app("json")->success($formatList);
|
|
|
308
|
+ // $keyword = request()->param('keyword', '');
|
|
|
309
|
+ // [$page, $limit] = $this->getPage();
|
|
|
310
|
+ // $uid = $this->request->uid();
|
|
|
311
|
+ // TaoKe::set_third_history($uid, $keyword);
|
|
|
312
|
+ //
|
|
|
313
|
+ // $list = Db::name('third_party_goods')
|
|
|
314
|
+ // ->where('type', 2)
|
|
|
315
|
+ // ->when(!empty($keyword), function ($query) use ($keyword) {
|
|
|
316
|
+ // $query->where('json', "like", '%' . $keyword . '%');
|
|
|
317
|
+ // })
|
|
|
318
|
+ // ->page($page, $limit)
|
|
|
319
|
+ // ->field('json')
|
|
|
320
|
+ // ->select()
|
|
|
321
|
+ // ->toArray();
|
|
|
322
|
+ // $formatList = [];
|
|
|
323
|
+ // foreach ($list as $value) {
|
|
|
324
|
+ // $json = json_decode($value['json'], true);
|
|
|
325
|
+ // $json['pension'] = $json['pension']??'0';
|
|
|
326
|
+ // $json['pv'] = $json['pension']*0.5;
|
|
|
327
|
+ // $json['yanglaojin'] = $json['pv']*0.05;
|
|
|
328
|
+ //
|
|
|
329
|
+ // $json['shopName'] = "";
|
|
|
330
|
+ // $json['monthSales'] = "0";
|
|
|
331
|
+ // $json['cid'] = "0";
|
|
|
332
|
+ // $formatList[] = $json;
|
|
|
333
|
+ // }
|
|
|
334
|
+ // return app("json")->success($formatList);
|
|
275
|
335
|
}
|
|
276
|
336
|
|
|
277
|
337
|
|
|
278
|
338
|
/*京东商品详情*/
|
|
279
|
339
|
public function jdDetail()
|
|
280
|
340
|
{
|
|
281
|
|
-
|
|
282
|
341
|
try {
|
|
283
|
|
- $sku = $this->request->param(['skuId']);
|
|
284
|
|
- $apiName = 'jd.union.open.goods.promotiongoodsinfo.query';
|
|
285
|
|
- $params = [
|
|
286
|
|
- 'skuIds' => $sku['skuId'],
|
|
|
342
|
+ $sku = request()->param('skuId', '');
|
|
|
343
|
+ if (empty($sku)) {
|
|
|
344
|
+ return app('json')->fail('商品下架不存在', null, 401);
|
|
|
345
|
+ }
|
|
|
346
|
+ // 老版本
|
|
|
347
|
+ // $apiName = 'jd.union.open.goods.promotiongoodsinfo.query';
|
|
|
348
|
+ // $params = [
|
|
|
349
|
+ // 'skuIds' => $sku['skuId'],
|
|
|
350
|
+ // ];
|
|
|
351
|
+ // $result = $this->getUrlResult($apiName, $params);
|
|
|
352
|
+ // $result = json_decode($result, true);
|
|
|
353
|
+ // $result = json_decode($result['jd_union_open_goods_promotiongoodsinfo_query_responce']['queryResult'], true);
|
|
|
354
|
+ // $result = $result['data'][0] ?? [];
|
|
|
355
|
+ // $goodsDetail = $this->doGetJtDetail($result);
|
|
|
356
|
+
|
|
|
357
|
+ $third_party_goods_detail = Db::name('third_party_goods')
|
|
|
358
|
+ ->whereLike('json', '%' . $sku . '%')
|
|
|
359
|
+ ->find();
|
|
|
360
|
+ $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
|
|
|
361
|
+ $formatData = [
|
|
|
362
|
+ 'goodsName' => $third_party_goods_json_detail['name'],
|
|
|
363
|
+ 'imgUrl' => $third_party_goods_json_detail['imageList'][0],
|
|
|
364
|
+ 'unitPrice' => $third_party_goods_json_detail['price'],//原价
|
|
|
365
|
+ 'wlUnitPrice' => $third_party_goods_json_detail['lowestCouponPrice'],
|
|
|
366
|
+ 'couMoney' => $third_party_goods_json_detail['coupon_money'][0]['discount'],
|
|
|
367
|
+ 'nowPrice' => $third_party_goods_json_detail['lowestCouponPrice'],//现价
|
|
|
368
|
+ 'detail' => $third_party_goods_json_detail['imageList'],
|
|
|
369
|
+
|
|
|
370
|
+ 'commission' => $third_party_goods_json_detail['commission'],
|
|
|
371
|
+ 'pv' => $third_party_goods_json_detail['pv'],
|
|
|
372
|
+ 'yanglaojin' => $third_party_goods_json_detail['yanglaojin'],
|
|
|
373
|
+ 'gongxian' => $third_party_goods_json_detail['gongxian'],
|
|
|
374
|
+ 'jifen' => $third_party_goods_json_detail['jifen'],
|
|
|
375
|
+ 'discount_link' => $third_party_goods_json_detail['coupon_link'],
|
|
|
376
|
+ 'materialUrl' => ''
|
|
287
|
377
|
];
|
|
288
|
|
- $result = $this->getUrlResult($apiName, $params);
|
|
289
|
|
- $result = json_decode($result, true);
|
|
290
|
|
- $result = json_decode($result['jd_union_open_goods_promotiongoodsinfo_query_responce']['queryResult'], true);
|
|
291
|
|
- $result = $result['data'][0] ?? [];
|
|
292
|
|
- $goodsDetail = $this->doGetJtDetail($result);
|
|
293
|
|
- return app("json")->success($goodsDetail);
|
|
294
|
|
- } catch (\Exception $e) {
|
|
295
|
|
- Db::name('log')->insert(['data'=>'微信审核------'.$e->getMessage().$e->getFile().$e->getLine()]);
|
|
296
|
378
|
|
|
|
379
|
+ return app("json")->success([$formatData]);
|
|
|
380
|
+ } catch (\Exception $e) {
|
|
297
|
381
|
return app('json')->fail('商品下架不存在', null, 401);
|
|
298
|
382
|
}
|
|
299
|
383
|
}
|
|
|
@@ -323,13 +407,32 @@ class Jd extends BaseController
|
|
323
|
407
|
];
|
|
324
|
408
|
// var_dump($third_party_goods_json_detail['coupon_money'][0]['link']);
|
|
325
|
409
|
//加入转链地址
|
|
326
|
|
- $formatData['materialUrl'] = $this->linkChange($goodsDetail['materialUrl'], $this->request->uid(), $third_party_goods_json_detail['coupon_money'][0]['link'] ?? '');;
|
|
|
410
|
+ $formatData['materialUrl'] = $this->linkChange($goodsDetail['materialUrl'], $this->request->uid(), $third_party_goods_json_detail['coupon_money'][0]['link'] ?? '');
|
|
327
|
411
|
$return[] = $formatData;
|
|
328
|
412
|
return $return;
|
|
329
|
413
|
}
|
|
330
|
414
|
|
|
|
415
|
+ public function changLinkApi()
|
|
|
416
|
+ {
|
|
|
417
|
+ $skuId = request()->param('skuId', '');
|
|
|
418
|
+ if (empty($skuId)) {
|
|
|
419
|
+ return app('json')->fail('商品下架不存在', null, 401);
|
|
|
420
|
+ }
|
|
|
421
|
+ $uid = $this->request->uid();
|
|
|
422
|
+ if (empty($uid)) {
|
|
|
423
|
+ return app('json')->fail('请重新登录', null, 401);
|
|
|
424
|
+ }
|
|
|
425
|
+ $third_party_goods_detail = Db::name('third_party_goods')->where('type', '=', 2)->whereLike('json', '%' . $skuId . '%')->find();
|
|
|
426
|
+ $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
|
|
|
427
|
+
|
|
|
428
|
+ $subUnionId = (int)($third_party_goods_json_detail['commission'] * 1000) . '_' . (int)($third_party_goods_json_detail['yanglaojin'] * 1000);
|
|
|
429
|
+ $url = $this->linkChange($third_party_goods_json_detail['materialUrl'], $uid, $third_party_goods_json_detail['coupon_link'] ?? '', $subUnionId);
|
|
|
430
|
+
|
|
|
431
|
+ return app("json")->success(['url' => $url]);
|
|
|
432
|
+ }
|
|
|
433
|
+
|
|
331
|
434
|
/*转链*/
|
|
332
|
|
- public function linkChange($url, $uid,$couponUrl)
|
|
|
435
|
+ public function linkChange($url, $uid,$couponUrl, $subUnionId)
|
|
333
|
436
|
{
|
|
334
|
437
|
|
|
335
|
438
|
if (!$uid) {
|
|
|
@@ -347,8 +450,10 @@ class Jd extends BaseController
|
|
347
|
450
|
'promotionCodeReq' => [
|
|
348
|
451
|
'materialId' => $url,
|
|
349
|
452
|
'siteId' => $this->appid,
|
|
350
|
|
- 'positionId' => pow(11, 5) + $uid, //自定义,和订单关联
|
|
351
|
|
- 'couponUrl' => $couponUrl
|
|
|
453
|
+ 'positionId' => $uid, //自定义,和订单关联
|
|
|
454
|
+ 'couponUrl' => $couponUrl,
|
|
|
455
|
+ 'sceneId' => 1,
|
|
|
456
|
+ 'subUnionId' => $subUnionId
|
|
352
|
457
|
],
|
|
353
|
458
|
];
|
|
354
|
459
|
$result = $this->getUrlResult($apiName, $params);
|
|
|
@@ -366,169 +471,255 @@ class Jd extends BaseController
|
|
366
|
471
|
|
|
367
|
472
|
$eliteIdList = [
|
|
368
|
473
|
'1', //好券商品
|
|
369
|
|
- '2', //精选卖场
|
|
370
|
|
- '10', //9.9包邮
|
|
371
|
|
- '15', //京东配送
|
|
372
|
|
- '22', //实时热销榜
|
|
373
|
|
-// '23', //为你推荐
|
|
374
|
|
- '24', //数码家电
|
|
375
|
|
- '25', //超市
|
|
376
|
|
- '26', //母婴玩具
|
|
377
|
|
- '27', //家具日用
|
|
378
|
|
- '28', //美妆穿搭
|
|
379
|
|
- '30', //图书文具
|
|
380
|
|
- '31', //今日必推
|
|
381
|
|
- '32', //京东好物
|
|
382
|
|
- '33', //京东秒杀
|
|
383
|
|
- '34', //拼购商品
|
|
384
|
|
- '40', //高收益榜
|
|
385
|
|
- '41', //自营热卖榜
|
|
386
|
|
-// '108', //秒杀进行中
|
|
387
|
|
- '109', //新品首发
|
|
388
|
|
- '110', //自营
|
|
389
|
|
- '112', //京东爆品
|
|
390
|
|
- '125', //首购商品
|
|
391
|
|
- '129', //高佣榜单
|
|
392
|
|
-// '130', //视频商品
|
|
393
|
|
-// '153', //历史最低价商品榜
|
|
394
|
|
-// '238', //新人价商品
|
|
395
|
|
-// '315', //秒杀未开始
|
|
396
|
|
- '341', //3C新品
|
|
397
|
|
- '342', //智能新品
|
|
398
|
|
- '343', //3C长尾商品
|
|
399
|
|
- '345', //时尚新品
|
|
400
|
|
- '346', //时尚爆品
|
|
401
|
|
-// '1001', //选品库
|
|
402
|
|
-// '515', //订单接龙商品
|
|
403
|
|
-// '519', //官方活动
|
|
404
|
|
- '12254', //超级补贴
|
|
405
|
|
- '12318', //便宜包邮
|
|
406
|
|
- '12339', //超市卡
|
|
|
474
|
+ // '2', //精选卖场
|
|
|
475
|
+ // '10', //9.9包邮
|
|
|
476
|
+ // '15', //京东配送
|
|
|
477
|
+ // '22', //实时热销榜
|
|
|
478
|
+ // // '23', //为你推荐
|
|
|
479
|
+ // '24', //数码家电
|
|
|
480
|
+ // '25', //超市
|
|
|
481
|
+ // '26', //母婴玩具
|
|
|
482
|
+ // '27', //家具日用
|
|
|
483
|
+ // '28', //美妆穿搭
|
|
|
484
|
+ // '30', //图书文具
|
|
|
485
|
+ // '31', //今日必推
|
|
|
486
|
+ // '32', //京东好物
|
|
|
487
|
+ // '33', //京东秒杀
|
|
|
488
|
+ // '34', //拼购商品
|
|
|
489
|
+ // '40', //高收益榜
|
|
|
490
|
+ // '41', //自营热卖榜
|
|
|
491
|
+ // // '108', //秒杀进行中
|
|
|
492
|
+ // '109', //新品首发
|
|
|
493
|
+ // '110', //自营
|
|
|
494
|
+ // '112', //京东爆品
|
|
|
495
|
+ // // '125', //首购商品
|
|
|
496
|
+ // '129', //高佣榜单
|
|
|
497
|
+ // // '130', //视频商品
|
|
|
498
|
+ // // '153', //历史最低价商品榜
|
|
|
499
|
+ // // '238', //新人价商品
|
|
|
500
|
+ // // '315', //秒杀未开始
|
|
|
501
|
+ // '341', //3C新品
|
|
|
502
|
+ // // '342', //智能新品
|
|
|
503
|
+ // '343', //3C长尾商品
|
|
|
504
|
+ // // '345', //时尚新品
|
|
|
505
|
+ // // '346', //时尚爆品
|
|
|
506
|
+ // // '1001', //选品库
|
|
|
507
|
+ // // '515', //订单接龙商品
|
|
|
508
|
+ // // '519', //官方活动
|
|
|
509
|
+ // '12254', //超级补贴
|
|
|
510
|
+ // // '12318', //便宜包邮
|
|
|
511
|
+ // '12339', //超市卡
|
|
407
|
512
|
];
|
|
408
|
|
- Log::info("===============get_jd_goods_list===================");
|
|
409
|
|
-// $eliteIdList = [1];
|
|
|
513
|
+ $maxExecutionTime = 1800; // 最大执行时间5分钟
|
|
|
514
|
+ $startTime = time();
|
|
|
515
|
+
|
|
410
|
516
|
foreach ($eliteIdList as $eliteId) {
|
|
411
|
|
- $jq_query=$this->jd_query($eliteId,1);
|
|
412
|
|
- $yema=(int)ceil($jq_query['totalCount']/50);
|
|
413
|
|
- for ($page = 1; $page <= $yema; $page++) {
|
|
414
|
|
- $result=$this->jd_query($eliteId,$page);
|
|
415
|
|
- if(isset($result['data']) && $result['data']){
|
|
416
|
|
- $this->formatGoodsList($result['data']);
|
|
417
|
|
- }
|
|
|
517
|
+ // 检查是否超时
|
|
|
518
|
+ if (time() - $startTime > $maxExecutionTime) {
|
|
|
519
|
+ log::info("JD API error (eliteId:{$eliteId}): timeout");
|
|
|
520
|
+ break; // 或记录日志
|
|
|
521
|
+ }
|
|
|
522
|
+
|
|
|
523
|
+ $page = 1;
|
|
|
524
|
+ $maxPage = 1; // 默认值
|
|
|
525
|
+
|
|
|
526
|
+ Db::startTrans();
|
|
|
527
|
+ try {
|
|
|
528
|
+ // 清除数据
|
|
|
529
|
+ Db::name("third_party_goods")->where('type', '=', 2)->where('cid', '=', $eliteId)->delete();
|
|
|
530
|
+ do {
|
|
|
531
|
+ try {
|
|
|
532
|
+ $result = $this->jd_query($eliteId, $page);
|
|
|
533
|
+ // 安全退出条件
|
|
|
534
|
+ if (empty($result) || !is_array($result)) {
|
|
|
535
|
+ break;
|
|
|
536
|
+ }
|
|
|
537
|
+ // 首次请求获取总页数
|
|
|
538
|
+ if ($page === 1 && isset($result['totalCount'])) {
|
|
|
539
|
+ // $maxPage = max(1, (int)ceil($result['totalCount'] / 50));
|
|
|
540
|
+ }
|
|
|
541
|
+ // 处理数据
|
|
|
542
|
+ if (!empty($result['data'])) {
|
|
|
543
|
+ // 写入数据
|
|
|
544
|
+ $this->formatGoodsList($result['data'], $eliteId);
|
|
|
545
|
+ }
|
|
|
546
|
+ $page++;
|
|
|
547
|
+ } catch (\Exception $e) {
|
|
|
548
|
+ // 记录错误并继续下一个分类
|
|
|
549
|
+ log::info("JD API error (eliteId:{$eliteId}, page:{$page}): " . $e->getMessage());
|
|
|
550
|
+ break;
|
|
|
551
|
+ }
|
|
|
552
|
+ } while ($page <= $maxPage);
|
|
|
553
|
+ Db::commit();
|
|
|
554
|
+ } catch (DbException $e) {
|
|
|
555
|
+ Db::startTrans();
|
|
418
|
556
|
}
|
|
419
|
557
|
}
|
|
|
558
|
+
|
|
420
|
559
|
return 'ok';
|
|
421
|
560
|
}
|
|
422
|
561
|
//请求京东联盟接口描述:京东联盟精选优质商品,每日更新,可通过频道ID查询各个频道下的精选商品。用获取的优惠券链接调用转链接口时,需传入搜索接口link字段返回的原始优惠券链接,切勿对链接进行任何encode、decode操作,否则将导致转链二合一推广链接时校验失败。
|
|
423
|
|
- public function jd_query($eliteId,$page){
|
|
|
562
|
+ public function jd_query($eliteId, $page)
|
|
|
563
|
+ {
|
|
424
|
564
|
$apiName = 'jd.union.open.goods.jingfen.query';
|
|
425
|
565
|
$params = [
|
|
426
|
566
|
'goodsReq' => [
|
|
427
|
|
- 'eliteId' => $eliteId,
|
|
|
567
|
+ 'eliteId' => $eliteId,
|
|
428
|
568
|
'pageIndex' => $page ?? 1,
|
|
429
|
|
- 'pageSize' => 50,
|
|
|
569
|
+ 'pageSize' => 10,
|
|
430
|
570
|
]
|
|
431
|
571
|
];
|
|
432
|
572
|
$result = $this->getUrlResult($apiName, $params);
|
|
433
|
573
|
$result = json_decode($result, true);
|
|
434
|
574
|
|
|
435
|
575
|
$result = json_decode($result['jd_union_open_goods_jingfen_query_responce']['queryResult'], true);
|
|
436
|
|
-// $result = $result['data'] ?? [];
|
|
|
576
|
+ // $result = $result['data'] ?? [];
|
|
437
|
577
|
return $result;
|
|
438
|
578
|
}
|
|
439
|
579
|
|
|
440
|
580
|
//格式化从京东联盟获取到的商品列表
|
|
441
|
|
- public function formatGoodsList($goodsList)
|
|
|
581
|
+ public function formatGoodsList($goodsList, $eliteId)
|
|
442
|
582
|
{
|
|
443
|
583
|
$install = [];
|
|
444
|
584
|
foreach ($goodsList as $goods) {
|
|
445
|
|
- $commissionMoney = $goods['commissionInfo']['couponCommission'] ?? 0;
|
|
446
|
|
- //养老金
|
|
447
|
|
- $oldMoney = app()->make(ProductRepository::class)->yanglaojin(0, $commissionMoney);
|
|
448
|
|
-// var_dump($goods);
|
|
449
|
|
-// return;
|
|
450
|
|
- if ($oldMoney < 0.1) continue;
|
|
451
|
|
- if (!isset($goods['couponInfo']['couponList'][0])) continue;
|
|
452
|
|
- foreach ($goods['couponInfo']['couponList'] as $coupon){
|
|
|
585
|
+ // 售价
|
|
|
586
|
+ if (!isset($goods['priceInfo']['price'])) {
|
|
|
587
|
+ continue;
|
|
|
588
|
+ }
|
|
453
|
589
|
|
|
|
590
|
+ // 获取最优优惠券信息
|
|
|
591
|
+ // 优惠券信息
|
|
|
592
|
+ $maxCoupon = [];
|
|
|
593
|
+ if (!empty($goods['couponInfo']['couponList'])) {
|
|
|
594
|
+ foreach ($goods['couponInfo']['couponList'] as $coupon) {
|
|
|
595
|
+ // isBest 最优 优惠券
|
|
|
596
|
+ if ($coupon['isBest'] == 1) {
|
|
|
597
|
+ $maxCoupon = [
|
|
|
598
|
+ 'discount' => $coupon['discount'],//优惠券金额
|
|
|
599
|
+ 'getStartTime' => date('Y-m-d', intval($coupon['getStartTime'] / 1000)),
|
|
|
600
|
+ 'getEndTime' => date('Y-m-d', intval($coupon['getEndTime'] / 1000)),
|
|
|
601
|
+ 'link' => $coupon['link'],
|
|
|
602
|
+ 'useStartTime' => date('Y-m-d', intval($coupon['useStartTime'] / 1000)),
|
|
|
603
|
+ 'useEndTime' => date('Y-m-d', intval($coupon['useEndTime'] / 1000)),
|
|
|
604
|
+ ];
|
|
|
605
|
+ break;
|
|
|
606
|
+ }
|
|
|
607
|
+ }
|
|
|
608
|
+ }
|
|
|
609
|
+
|
|
|
610
|
+ // 最低到手价
|
|
|
611
|
+ $purchasePrice = $goods['priceInfo']['price'];
|
|
|
612
|
+ // 券后价
|
|
|
613
|
+ if (!empty($maxCoupon['discount'])) {
|
|
|
614
|
+ // 拥有优惠券
|
|
|
615
|
+ $purchasePrice = bcsub($goods['priceInfo']['price'], $maxCoupon['discount'], 2);
|
|
|
616
|
+ }
|
|
|
617
|
+ // 到手价
|
|
|
618
|
+ if (!empty($goods['purchasePriceInfo']['purchasePrice']) && $goods['purchasePriceInfo']['purchasePrice'] < $purchasePrice) {
|
|
|
619
|
+ $purchasePrice = $goods['purchasePriceInfo']['purchasePrice'];
|
|
454
|
620
|
}
|
|
455
|
|
- $goods['couponInfo']['couponList'][0]['getStartTime'] = date('Y-m-d', intval($goods['couponInfo']['couponList'][0]['getStartTime'] / 1000));
|
|
456
|
|
- $goods['couponInfo']['couponList'][0]['getEndTime'] = date('Y-m-d', intval($goods['couponInfo']['couponList'][0]['getEndTime'] / 1000));
|
|
|
621
|
+
|
|
|
622
|
+ // 券后佣金,(促销价-优惠券面额)*佣金比例
|
|
|
623
|
+ $commissionMoney = bcmul($purchasePrice, bcdiv($goods['commissionInfo']['commissionShare'] ?? 0.00, 100, 5), 2);
|
|
|
624
|
+ $commissionMoney = bcmul($commissionMoney, 0.8, 2);
|
|
|
625
|
+
|
|
457
|
626
|
$formatList = [
|
|
458
|
|
- 'type' => 6,//京东商品
|
|
459
|
|
- 'skuId' => $goods['skuId'],//skuid
|
|
460
|
|
- 'id' => $goods['brandCode'] ?? '', //id
|
|
461
|
|
- 'thumb' => $goods['imageInfo']['imageList'][0]['url'] ?? '',//商品缩略图
|
|
462
|
|
- 'name' => $goods['skuName'],//名称
|
|
463
|
|
- 'commission' => $oldMoney,//佣金
|
|
464
|
|
- 'commission_rate' => $goods['commissionInfo']['commissionShare'] ?? '',//佣金比例
|
|
465
|
|
- 'sales' => "",
|
|
466
|
|
- 'coupon_money' => $goods['couponInfo']['couponList'] ?? [],
|
|
467
|
|
- 'lowestCouponPrice' => decimal2($goods['priceInfo']['lowestCouponPrice']), //券后价lowestCouponPrice
|
|
468
|
|
- 'price' => $goods['priceInfo']['price'], //价格
|
|
469
|
|
- 'imageList' => array_column($goods['imageInfo']['imageList'], 'url'), //图片合集
|
|
|
627
|
+ 'type' => 6,//京东商品
|
|
|
628
|
+ 'skuId' => $goods['itemId'] ?? '',//itemId 京东官方 已不返回skuId , 使用 联盟商品ID 代替skuId
|
|
|
629
|
+ 'id' => $goods['brandCode'] ?? '', //id
|
|
|
630
|
+ 'name' => $goods['skuName'],//名称
|
|
|
631
|
+ 'thumb' => $goods['imageInfo']['imageList'][0]['url'] ?? '',//商品缩略图
|
|
|
632
|
+
|
|
|
633
|
+ 'pv' => bcmul($commissionMoney, 0.7, 2),//PV金额
|
|
|
634
|
+ 'gongxian' => bcmul($commissionMoney, 0.7, 2),
|
|
|
635
|
+ 'jifen' => bcmul($commissionMoney, 0.7, 2),
|
|
|
636
|
+ 'yanglaojin' => bcmul($commissionMoney, 0.3, 2),
|
|
|
637
|
+
|
|
|
638
|
+ 'commission' => $commissionMoney,//佣金
|
|
|
639
|
+ 'commission_rate' => $goods['commissionInfo']['commissionShare'] ?? 0.00,//佣金比例
|
|
|
640
|
+ 'coupon_money' => empty($maxCoupon) ? [] : [$maxCoupon],
|
|
|
641
|
+ 'coupon_link' => $maxCoupon['link'] ?? '',
|
|
|
642
|
+ 'lowestCouponPrice' => $purchasePrice,
|
|
|
643
|
+ 'price' => $goods['priceInfo']['price'], //价格
|
|
|
644
|
+ 'imageList' => array_column($goods['imageInfo']['imageList'], 'url'), //图片合集
|
|
|
645
|
+ 'materialUrl' => $goods['materialUrl']
|
|
470
|
646
|
];
|
|
471
|
|
- $install[]=['json' => json_encode($formatList, JSON_UNESCAPED_UNICODE), 'pension' => $oldMoney, 'type' => 2];
|
|
472
|
|
-// Db::name("third_party_goods")->insert(['json' => json_encode($formatList, JSON_UNESCAPED_UNICODE), 'pension' => $oldMoney, 'type' => 2]);
|
|
|
647
|
+ $install[] = ['json' => json_encode($formatList, JSON_UNESCAPED_UNICODE), 'pension' => $commissionMoney, 'type' => 2, 'cid' => $eliteId];
|
|
473
|
648
|
}
|
|
474
|
|
- if($install){
|
|
|
649
|
+ if ($install) {
|
|
475
|
650
|
Db::name("third_party_goods")->insertAll($install);
|
|
476
|
651
|
}
|
|
477
|
|
-
|
|
478
|
|
-// return $formatList;
|
|
479
|
652
|
}
|
|
480
|
653
|
|
|
481
|
654
|
/*订单获取(时间段,时间不能超过一小时)*/
|
|
482
|
655
|
public function orderList()
|
|
483
|
656
|
{
|
|
484
|
|
- $time = $this->request->params([
|
|
485
|
|
- 'startTime',
|
|
486
|
|
- 'endTime'
|
|
487
|
|
- ]);
|
|
488
|
|
- //自定义时间 每20分钟执行一次查询前半小时的数据
|
|
|
657
|
+ // $time = $this->request->params([
|
|
|
658
|
+ // 'startTime',
|
|
|
659
|
+ // 'endTime'
|
|
|
660
|
+ // ]);
|
|
|
661
|
+ $time['startTime'] = request()->param('startTime', '');
|
|
|
662
|
+ $time['endTime'] = request()->param('endTime', '');
|
|
489
|
663
|
if (!$time['startTime'] && !$time['endTime']) {
|
|
490
|
|
- $time['startTime'] = date("Y-m-d H:i:s", strtotime("-200 minute"));
|
|
491
|
|
- $time['endTime'] = date('Y-m-d H:i:s');
|
|
|
664
|
+ // $time['startTime'] = date("Y-m-d H:i:s", strtotime("-1 hour"));
|
|
|
665
|
+ // $time['endTime'] = date('Y-m-d H:i:s');
|
|
|
666
|
+ // 获取当前时间
|
|
|
667
|
+ $currentTime = new DateTime();
|
|
|
668
|
+
|
|
|
669
|
+ // 生成时间范围数组
|
|
|
670
|
+ $timeRanges = [];
|
|
|
671
|
+ for ($i = 0; $i < 30 * 24; $i++) {
|
|
|
672
|
+ $endTime = clone $currentTime;
|
|
|
673
|
+ $endTime->modify("-$i hour");
|
|
|
674
|
+
|
|
|
675
|
+ $startTime = clone $endTime;
|
|
|
676
|
+ $startTime->modify("-1 hour");
|
|
|
677
|
+ $startTime->modify("+1 second");
|
|
|
678
|
+
|
|
|
679
|
+ $timeRanges[] = [
|
|
|
680
|
+ 'startTime' => $startTime->format('Y-m-d H:i:s'),
|
|
|
681
|
+ 'endTime' => $endTime->format('Y-m-d H:i:s')
|
|
|
682
|
+ ];
|
|
|
683
|
+ }
|
|
|
684
|
+ } else {
|
|
|
685
|
+ $timeRanges[] = $time;
|
|
492
|
686
|
}
|
|
493
|
|
-// var_dump($time);
|
|
494
|
687
|
try {
|
|
495
|
|
- $orderLists = [];
|
|
496
|
|
- $page = 1;
|
|
497
|
|
- $pageSize = 40;
|
|
498
|
|
- $apiName = 'jd.union.open.order.row.query';
|
|
499
|
|
- do {
|
|
500
|
|
- $params = [
|
|
501
|
|
- 'orderReq' => [
|
|
502
|
|
- 'pageNo' => $page,
|
|
503
|
|
- 'pageSize' => $pageSize,
|
|
504
|
|
- 'type' => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
|
505
|
|
- 'startTime' => $time['startTime'],//格式2020-01-02 21:23:00
|
|
506
|
|
- 'endTime' => $time['endTime'] //格式2020-01-02 21:24:00
|
|
507
|
|
- ],
|
|
508
|
|
- ];
|
|
509
|
|
- $result = $this->getUrlResult($apiName, $params);
|
|
510
|
|
-// var_dump($result);
|
|
511
|
|
- $result = json_decode($result, true);
|
|
512
|
|
- $result = json_decode($result['jd_union_open_order_row_query_responce']['queryResult'], true);
|
|
513
|
|
- $lists = $result['data'];
|
|
514
|
|
- $countList = count($lists);
|
|
515
|
|
- if (!empty($countList)) {
|
|
516
|
|
- $orderLists = array_merge($orderLists, $lists);
|
|
517
|
|
- }
|
|
|
688
|
+ foreach ($timeRanges as $time) {
|
|
|
689
|
+ $orderLists = [];
|
|
|
690
|
+ $page = 1;
|
|
|
691
|
+ $pageSize = 200;
|
|
|
692
|
+ $apiName = 'jd.union.open.order.row.query';
|
|
|
693
|
+ do {
|
|
|
694
|
+ $params = [
|
|
|
695
|
+ 'orderReq' => [
|
|
|
696
|
+ 'pageIndex' => $page,
|
|
|
697
|
+ 'pageSize' => $pageSize,
|
|
|
698
|
+ 'type' => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
|
|
699
|
+ 'startTime' => $time['startTime'],//格式2020-01-02 21:23:00
|
|
|
700
|
+ 'endTime' => $time['endTime'], //格式2020-01-02 21:24:00
|
|
|
701
|
+ 'fields' => 'goodsInfo'
|
|
|
702
|
+ ],
|
|
|
703
|
+ ];
|
|
|
704
|
+ $result = $this->getUrlResult($apiName, $params);
|
|
|
705
|
+ $result = json_decode($result, true);
|
|
|
706
|
+ $result = json_decode($result['jd_union_open_order_row_query_responce']['queryResult'], true);
|
|
|
707
|
+ $lists = $result['data'] ?? [];
|
|
|
708
|
+ $countList = count($lists);
|
|
|
709
|
+ if (!empty($countList)) {
|
|
|
710
|
+ $orderLists = array_merge($orderLists, $lists);
|
|
|
711
|
+ }
|
|
518
|
712
|
|
|
519
|
|
-// var_dump($result);
|
|
520
|
|
- $page++;
|
|
521
|
|
- } while ($countList == $pageSize);
|
|
522
|
|
- if (!empty($orderLists)) {
|
|
523
|
|
- //格式化从京东拉取的订单列表
|
|
524
|
|
- $formatLists = $this->formatOrderList($orderLists);
|
|
525
|
|
-// var_dump($formatLists);
|
|
526
|
|
- //将京东订单列表中的订单进行处理
|
|
527
|
|
- $this->operatePinOrder($formatLists);
|
|
528
|
|
- return app("json")->success("京东订单写入成功");
|
|
529
|
|
- } else {
|
|
530
|
|
- return app("json")->success("暂无最新数据");
|
|
|
713
|
+ $page++;
|
|
|
714
|
+ } while ($countList == $pageSize && $result['hasMore'] ?? false);
|
|
|
715
|
+ if (!empty($orderLists)) {
|
|
|
716
|
+ //格式化从京东拉取的订单列表
|
|
|
717
|
+ $formatLists = $this->formatOrderList($orderLists);
|
|
|
718
|
+ //将京东订单列表中的订单进行处理
|
|
|
719
|
+ $this->operatePinOrder($formatLists);
|
|
|
720
|
+ }
|
|
531
|
721
|
}
|
|
|
722
|
+ return app("json")->success("京东订单写入成功");
|
|
532
|
723
|
} catch (\Exception $e) {
|
|
533
|
724
|
return app("json")->fail($e->getMessage());
|
|
534
|
725
|
}
|
|
|
@@ -538,8 +729,7 @@ class Jd extends BaseController
|
|
538
|
729
|
//格式化从京东拉取的订单列表
|
|
539
|
730
|
public function formatOrderList($orderLists)
|
|
540
|
731
|
{
|
|
541
|
|
-// $user = app()->make(UserThirdRepository::class);
|
|
542
|
|
- $formatLists = [];
|
|
|
732
|
+ $formatList = [];
|
|
543
|
733
|
foreach ($orderLists as $order) {
|
|
544
|
734
|
switch ($order['validCode']) {
|
|
545
|
735
|
case 15://待付款订单
|
|
|
@@ -554,92 +744,136 @@ class Jd extends BaseController
|
|
554
|
744
|
default://失效订单
|
|
555
|
745
|
$billStatus = 2;
|
|
556
|
746
|
}
|
|
557
|
|
- if($order['validCode']==15){ //未支付的不处理
|
|
|
747
|
+ if ($order['validCode'] == 15) { //未支付的不处理
|
|
558
|
748
|
continue;
|
|
559
|
749
|
}
|
|
560
|
750
|
//通过订单关联
|
|
561
|
751
|
$positionId = $order['positionId'];
|
|
562
|
|
- $userId = $positionId - pow(11, 5);
|
|
563
|
|
- //订单关联推广位ID
|
|
564
|
|
-// $pid = $order['subUnionId'] ?: '';
|
|
565
|
|
- // if (empty($pid)) continue;
|
|
566
|
|
- //订单关联推广位ID
|
|
567
|
|
-// $chanTag = $user->getDetail(['pid' => $order['subUnionId'], 'type' => 6], 'uid,pid');
|
|
568
|
|
- //if(!$chanTag){continue;}
|
|
569
|
|
- $formatLists[] = [
|
|
570
|
|
- 'uid' => $userId,
|
|
571
|
|
- 'sku_id' => $order['skuId'],
|
|
572
|
|
- 'jd_id' => $order['id'],
|
|
573
|
|
- 'order_sn' => $order['orderId'], //订单编号
|
|
574
|
|
- 'sku_num' => $order['skuNum'], //购买商品的数量
|
|
575
|
|
- 'image_url' => $order['goodsInfo']['imageUrl'] ?? '',
|
|
576
|
|
- 'sku_name' => $order['skuName'],
|
|
577
|
|
- //订单中sku的单件价格,单位为分
|
|
578
|
|
- 'price' => $order['price'],
|
|
579
|
|
- //未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,
|
|
580
|
|
- //8.无效-企业订单,9.无效-团购订单,11.无效-乡村推广员下单,13.无效-违规订单,14.无效-来源与备案网址不符,
|
|
581
|
|
- //15.待付款,16.已付款,17.已完成(购买用户确认收货),20.无效-此复购订单对应的首购订单无效,21.无效-云店订单',
|
|
582
|
|
- 'status' => $order['validCode'],
|
|
583
|
|
- //商家信息
|
|
584
|
|
- 'shop_id' => $order['goodsInfo']['shopId'],
|
|
585
|
|
- //订单生成时间
|
|
586
|
|
- 'create_time' => $order['orderTime'] ? $order['orderTime'] : 0, //下单时间
|
|
587
|
|
- 'finish_time' => $order['finishTime'] ? $order['finishTime'] : 0,//完成时间
|
|
588
|
|
- 'modify_time' => $order['modifyTime'] ? $order['modifyTime'] : 0,//更新时间
|
|
589
|
|
- 'sub_union_id' => $order['subUnionId'], //订单关联推广位ID
|
|
590
|
|
- //佣金比例
|
|
591
|
|
- 'commission_share' => $order['finalRate'], //最终分佣比例
|
|
592
|
|
- //实际佣金
|
|
593
|
|
- 'commission' => $order['estimateFee'],
|
|
594
|
|
- 'bill_status' => $billStatus, //平台是否结算
|
|
595
|
|
- 'type' => 2
|
|
|
752
|
+ $userId = $positionId;
|
|
|
753
|
+ if ($userId <= 0) {//拉取的订单没有匹配到用户
|
|
|
754
|
+ continue;
|
|
|
755
|
+ }
|
|
|
756
|
+
|
|
|
757
|
+ //订单实际计算佣金的金额(订单完成时,会将误扣除的运费券金额更正,如订单完成后发生退款,此金额会更新)
|
|
|
758
|
+ $goodsInfo = $order['goodsInfo'] ?? [];
|
|
|
759
|
+ $createTime = strtotime($order['orderTime']);
|
|
|
760
|
+ //平台可以进行结算的时间戳=订单创建时间+系统设置的间隔时间
|
|
|
761
|
+ $billEndTime = $this->userThird->getSettleTime($createTime);
|
|
|
762
|
+
|
|
|
763
|
+ $address = Db::name('user_address')->field('code_list,village_id')->where('uid', $userId)->where('is_default', 1)->find();
|
|
|
764
|
+
|
|
|
765
|
+ $commission = $order['actualFee'] ?: $order['estimateFee'];
|
|
|
766
|
+ // 生成推广链接时自定义放里边的参数(佣金_养老金)
|
|
|
767
|
+ if (!empty($order['subUnionId'])) {
|
|
|
768
|
+ $subUnionIdList = explode('_', $order['subUnionId']);
|
|
|
769
|
+ if (!empty($subUnionIdList[0])) {
|
|
|
770
|
+ $commission = bcdiv($subUnionIdList[0], 1000, 2);
|
|
|
771
|
+ }
|
|
|
772
|
+ }
|
|
|
773
|
+ $formatList[] = [
|
|
|
774
|
+ 'uid' => $userId,
|
|
|
775
|
+ 'commission' => $commission,//佣金
|
|
|
776
|
+ 'commission_share' => $order['finalRate'],
|
|
|
777
|
+ 'order_sn' => $order['orderId'],
|
|
|
778
|
+ 'pay_money' => $order['actualCosPrice'] ?: $order['estimateCosPrice'],
|
|
|
779
|
+ 'jd_id' => $order['id'],
|
|
|
780
|
+ 'create_time' => $order['orderTime'],
|
|
|
781
|
+ 'finish_time' => $order['finishTime'],//用户确认收货时间
|
|
|
782
|
+ 'modify_time' => $order['modifyTime'],//更新时间
|
|
|
783
|
+ 'sku_num' => $order['skuNum'],
|
|
|
784
|
+ 'sku_id' => $order['itemId'] ?? '', // 目前京东官方不返回 skuId
|
|
|
785
|
+ 'sku_name' => $order['skuName'],
|
|
|
786
|
+ 'price' => $order['price'],//原价
|
|
|
787
|
+ 'sub_union_id' => $order['positionId'],
|
|
|
788
|
+ 'image_url' => $goodsInfo['imageUrl'] ?? '',
|
|
|
789
|
+ 'shop_name' => $goodsInfo['shopName'] ?? '京东',
|
|
|
790
|
+ 'shop_id' => $goodsInfo['shopId'] ?? 0,
|
|
|
791
|
+ 'status' => $order['validCode'],//订单状态
|
|
|
792
|
+ 'bill_status' => $billStatus, //平台是否结算
|
|
|
793
|
+ 'bill_end_time' => $billEndTime,
|
|
|
794
|
+ 'user_address_ids' => !empty($address) ? $address['code_list'] . ',' . $address['village_id'] : '',
|
|
|
795
|
+ 'type' => 1
|
|
596
|
796
|
];
|
|
597
|
797
|
}
|
|
598
|
|
- return $formatLists;
|
|
|
798
|
+ return $formatList;
|
|
599
|
799
|
}
|
|
600
|
800
|
|
|
601
|
801
|
//将拼多多订单列表中的订单写入第三方平台订单表
|
|
602
|
802
|
public function operatePinOrder($orderLists)
|
|
603
|
803
|
{
|
|
|
804
|
+ /** @var UserThirdRepository $orderThird */
|
|
604
|
805
|
$orderThird = app()->make(UserThirdRepository::class);
|
|
|
806
|
+ $type_shop = 6;
|
|
605
|
807
|
foreach ($orderLists as $k => $order) {
|
|
606
|
808
|
if (empty($order)) continue;
|
|
607
|
809
|
//判断数据库有无此订单
|
|
608
|
|
- $orderVip = $orderThird->getOrderDetail("order_jd", ['order_sn' => $order['order_sn'], 'sub_union_id' => $order['sub_union_id']]);
|
|
609
|
|
- if (!$orderVip) {
|
|
610
|
|
- // 读取商品详情 拿到商品图
|
|
611
|
|
- $third_party_goods_detail = Db::name('third_party_goods')->whereLike('json', '%' . $order['sku_id'] . '%')->find();
|
|
612
|
|
- $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
|
|
613
|
|
- $order['image_url'] = $third_party_goods_json_detail['thumb']??'';
|
|
614
|
|
-
|
|
615
|
|
- $orderThird->createOrder('order_jd', $order, strtotime($order['create_time'])); //订单写入数据库
|
|
|
810
|
+ $localOrder = JdOrderModel::getInstance()->getOne(['order_sn' => $order['order_sn']]);
|
|
|
811
|
+ if (empty($localOrder)) {
|
|
|
812
|
+ //订单写入数据库,bill_end_time再格式化订单的时候已经加入,所以写入订单的时候就不需要在计算了
|
|
|
813
|
+ $localOrder = JdOrderModel::create($order);
|
|
616
|
814
|
//预估养老金
|
|
617
|
815
|
$orderThird->yuguOrder(
|
|
618
|
|
- $order['jd_id'],
|
|
619
|
|
- $order['commission'],
|
|
620
|
|
- $order['uid'],
|
|
621
|
|
- $order['order_sn'],
|
|
622
|
|
- 6,
|
|
|
816
|
+ $localOrder['order_jd_id'],
|
|
|
817
|
+ $localOrder['commission'],
|
|
|
818
|
+ $localOrder['uid'],
|
|
|
819
|
+ $localOrder['order_sn'],
|
|
|
820
|
+ $type_shop,
|
|
623
|
821
|
'order_jd');
|
|
624
|
822
|
//预估积分
|
|
625
|
823
|
$orderThird->yuguJifen(
|
|
626
|
|
- $order['jd_id'],
|
|
627
|
|
- $order['commission'],
|
|
628
|
|
- $order['uid'],
|
|
629
|
|
- $order['order_sn'],
|
|
630
|
|
- 6
|
|
|
824
|
+ $localOrder['order_jd_id'],
|
|
|
825
|
+ $localOrder['commission'],
|
|
|
826
|
+ $localOrder['uid'],
|
|
|
827
|
+ $localOrder['order_sn'],
|
|
|
828
|
+ $type_shop
|
|
631
|
829
|
);
|
|
632
|
830
|
} else {
|
|
633
|
|
- //更新
|
|
634
|
|
- if ($orderVip['status'] != $order['status']) {
|
|
635
|
|
- $saveOrderPdd['status'] = $order['status'];
|
|
636
|
|
- if(isset($order['bill_status'])){
|
|
637
|
|
- $saveOrderPdd['bill_status'] = $order['bill_status'];
|
|
|
831
|
+ if($localOrder['status']!=$order['status']) {
|
|
|
832
|
+ $localOrder->save($order);//更新订单信息
|
|
|
833
|
+ if(!in_array($order['status'],[15,16,17])){
|
|
|
834
|
+ //修改积分和贡献,yanglaojin值记录
|
|
|
835
|
+ $orderThird->updateJilu(
|
|
|
836
|
+ $localOrder['uid'],
|
|
|
837
|
+ $localOrder['order_jd_id'],
|
|
|
838
|
+ $type_shop);
|
|
638
|
839
|
}
|
|
639
|
|
- $orderThird->saveOrder("order_jd", ['order_jd_id' => $orderVip['order_jd_id']], $saveOrderPdd); //修改订单
|
|
640
|
840
|
}
|
|
641
|
841
|
}
|
|
642
|
842
|
|
|
|
843
|
+ // $orderVip = $orderThird->getOrderDetail("order_jd", ['order_sn' => $order['order_sn'], 'sub_union_id' => $order['sub_union_id']]);
|
|
|
844
|
+ // if (!$orderVip) {
|
|
|
845
|
+ // // 读取商品详情 拿到商品图
|
|
|
846
|
+ // $third_party_goods_detail = Db::name('third_party_goods')->whereLike('json', '%' . $order['sku_id'] . '%')->find();
|
|
|
847
|
+ // $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
|
|
|
848
|
+ // $order['image_url'] = $third_party_goods_json_detail['thumb']??'';
|
|
|
849
|
+ //
|
|
|
850
|
+ // $orderThird->createOrder('order_jd', $order, strtotime($order['create_time'])); //订单写入数据库
|
|
|
851
|
+ // //预估养老金
|
|
|
852
|
+ // $orderThird->yuguOrder(
|
|
|
853
|
+ // $order['jd_id'],
|
|
|
854
|
+ // $order['commission'],
|
|
|
855
|
+ // $order['uid'],
|
|
|
856
|
+ // $order['order_sn'],
|
|
|
857
|
+ // 6,
|
|
|
858
|
+ // 'order_jd');
|
|
|
859
|
+ // //预估积分
|
|
|
860
|
+ // $orderThird->yuguJifen(
|
|
|
861
|
+ // $order['jd_id'],
|
|
|
862
|
+ // $order['commission'],
|
|
|
863
|
+ // $order['uid'],
|
|
|
864
|
+ // $order['order_sn'],
|
|
|
865
|
+ // 6
|
|
|
866
|
+ // );
|
|
|
867
|
+ // } else {
|
|
|
868
|
+ // //更新
|
|
|
869
|
+ // if ($orderVip['status'] != $order['status']) {
|
|
|
870
|
+ // $saveOrderPdd['status'] = $order['status'];
|
|
|
871
|
+ // if(isset($order['bill_status'])){
|
|
|
872
|
+ // $saveOrderPdd['bill_status'] = $order['bill_status'];
|
|
|
873
|
+ // }
|
|
|
874
|
+ // $orderThird->saveOrder("order_jd", ['order_jd_id' => $orderVip['order_jd_id']], $saveOrderPdd); //修改订单
|
|
|
875
|
+ // }
|
|
|
876
|
+ // }
|
|
643
|
877
|
}
|
|
644
|
878
|
}
|
|
645
|
879
|
|