|
|
@@ -5,6 +5,7 @@ namespace app\controller\api\store\product;
|
|
5
|
5
|
use app\common\repositories\store\product\ProductRepository;
|
|
6
|
6
|
use app\common\repositories\user\UserThirdRepository;
|
|
7
|
7
|
use app\model\common\JdOrderModel;
|
|
|
8
|
+use DateTime;
|
|
8
|
9
|
use think\App;
|
|
9
|
10
|
use crmeb\basic\BaseController;
|
|
10
|
11
|
use think\db\exception\DbException;
|
|
|
@@ -622,47 +623,67 @@ class Jd extends BaseController
|
|
622
|
623
|
// ]);
|
|
623
|
624
|
$time['startTime'] = request()->param('startTime', '');
|
|
624
|
625
|
$time['endTime'] = request()->param('endTime', '');
|
|
625
|
|
-
|
|
626
|
|
- //自定义时间 每20分钟执行一次查询前半小时的数据
|
|
627
|
626
|
if (!$time['startTime'] && !$time['endTime']) {
|
|
628
|
|
- $time['startTime'] = date("Y-m-d H:i:s", strtotime("-1 hour"));
|
|
629
|
|
- $time['endTime'] = date('Y-m-d H:i:s');
|
|
|
627
|
+ // $time['startTime'] = date("Y-m-d H:i:s", strtotime("-1 hour"));
|
|
|
628
|
+ // $time['endTime'] = date('Y-m-d H:i:s');
|
|
|
629
|
+ // 获取当前时间
|
|
|
630
|
+ $currentTime = new DateTime();
|
|
|
631
|
+
|
|
|
632
|
+ // 生成时间范围数组
|
|
|
633
|
+ $timeRanges = [];
|
|
|
634
|
+ for ($i = 0; $i < 30 * 24; $i++) {
|
|
|
635
|
+ $endTime = clone $currentTime;
|
|
|
636
|
+ $endTime->modify("-$i hour");
|
|
|
637
|
+
|
|
|
638
|
+ $startTime = clone $endTime;
|
|
|
639
|
+ $startTime->modify("-1 hour");
|
|
|
640
|
+ $startTime->modify("+1 second");
|
|
|
641
|
+
|
|
|
642
|
+ $timeRanges[] = [
|
|
|
643
|
+ 'startTime' => $startTime->format('Y-m-d H:i:s'),
|
|
|
644
|
+ 'endTime' => $endTime->format('Y-m-d H:i:s')
|
|
|
645
|
+ ];
|
|
|
646
|
+ }
|
|
|
647
|
+ } else {
|
|
|
648
|
+ $timeRanges[] = $time;
|
|
630
|
649
|
}
|
|
631
|
650
|
try {
|
|
632
|
|
- $orderLists = [];
|
|
633
|
|
- $page = 1;
|
|
634
|
|
- $pageSize = 200;
|
|
635
|
|
- $apiName = 'jd.union.open.order.row.query';
|
|
636
|
|
- do {
|
|
637
|
|
- $params = [
|
|
638
|
|
- 'orderReq' => [
|
|
639
|
|
- 'pageIndex' => $page,
|
|
640
|
|
- 'pageSize' => $pageSize,
|
|
641
|
|
- 'type' => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
|
642
|
|
- 'startTime' => $time['startTime'],//格式2020-01-02 21:23:00
|
|
643
|
|
- 'endTime' => $time['endTime'], //格式2020-01-02 21:24:00
|
|
644
|
|
- 'fields' => 'goodsInfo'
|
|
645
|
|
- ],
|
|
646
|
|
- ];
|
|
647
|
|
- $result = $this->getUrlResult($apiName, $params);
|
|
648
|
|
- $result = json_decode($result, true);
|
|
649
|
|
- $result = json_decode($result['jd_union_open_order_row_query_responce']['queryResult'], true);
|
|
650
|
|
- $lists = $result['data'];
|
|
651
|
|
- $countList = count($lists);
|
|
652
|
|
- if (!empty($countList)) {
|
|
653
|
|
- $orderLists = array_merge($orderLists, $lists);
|
|
654
|
|
- }
|
|
|
651
|
+ foreach ($timeRanges as $time) {
|
|
|
652
|
+ $orderLists = [];
|
|
|
653
|
+ $page = 1;
|
|
|
654
|
+ $pageSize = 200;
|
|
|
655
|
+ $apiName = 'jd.union.open.order.row.query';
|
|
|
656
|
+ do {
|
|
|
657
|
+ $params = [
|
|
|
658
|
+ 'orderReq' => [
|
|
|
659
|
+ 'pageIndex' => $page,
|
|
|
660
|
+ 'pageSize' => $pageSize,
|
|
|
661
|
+ 'type' => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
|
|
662
|
+ 'startTime' => $time['startTime'],//格式2020-01-02 21:23:00
|
|
|
663
|
+ 'endTime' => $time['endTime'], //格式2020-01-02 21:24:00
|
|
|
664
|
+ 'fields' => 'goodsInfo'
|
|
|
665
|
+ ],
|
|
|
666
|
+ ];
|
|
|
667
|
+ $result = $this->getUrlResult($apiName, $params);
|
|
|
668
|
+ $result = json_decode($result, true);
|
|
|
669
|
+ $result = json_decode($result['jd_union_open_order_row_query_responce']['queryResult'], true);
|
|
|
670
|
+ $lists = $result['data'];
|
|
|
671
|
+ $countList = count($lists);
|
|
|
672
|
+ if (!empty($countList)) {
|
|
|
673
|
+ $orderLists = array_merge($orderLists, $lists);
|
|
|
674
|
+ }
|
|
655
|
675
|
|
|
656
|
|
- $page++;
|
|
657
|
|
- } while ($countList == $pageSize && $result['hasMore'] ?? false);
|
|
658
|
|
- if (!empty($orderLists)) {
|
|
659
|
|
- //格式化从京东拉取的订单列表
|
|
660
|
|
- $formatLists = $this->formatOrderList($orderLists);
|
|
661
|
|
- //将京东订单列表中的订单进行处理
|
|
662
|
|
- $this->operatePinOrder($formatLists);
|
|
663
|
|
- return app("json")->success("京东订单写入成功");
|
|
664
|
|
- } else {
|
|
665
|
|
- return app("json")->success("暂无最新数据");
|
|
|
676
|
+ $page++;
|
|
|
677
|
+ } while ($countList == $pageSize && $result['hasMore'] ?? false);
|
|
|
678
|
+ if (!empty($orderLists)) {
|
|
|
679
|
+ //格式化从京东拉取的订单列表
|
|
|
680
|
+ $formatLists = $this->formatOrderList($orderLists);
|
|
|
681
|
+ //将京东订单列表中的订单进行处理
|
|
|
682
|
+ $this->operatePinOrder($formatLists);
|
|
|
683
|
+ return app("json")->success("京东订单写入成功");
|
|
|
684
|
+ } else {
|
|
|
685
|
+ return app("json")->success("暂无最新数据");
|
|
|
686
|
+ }
|
|
666
|
687
|
}
|
|
667
|
688
|
} catch (\Exception $e) {
|
|
668
|
689
|
return app("json")->fail($e->getMessage());
|