Procházet zdrojové kódy

客户端-京东服务商从京推推换成官方

sunxbiao před 11 měsíci
rodič
revize
48cb4f9c3d

+ 1 - 1
app/common/repositories/store/order/StoreOrderRepository.php

@@ -3803,7 +3803,7 @@ class StoreOrderRepository extends BaseRepository
3803 3803
 
3804 3804
         $order_sn = $order["order_sn"];
3805 3805
         log::info("进入添加养老金{$order['order_sn']}");
3806
-        $tongji = Db::name("user_bill")->where("order_sn", $order_sn)->count();
3806
+        $tongji = Db::name("user_bill")->where("order_sn", $order_sn)->where('type_shop', $type_shop)->count();
3807 3807
         if ($tongji) {
3808 3808
             //第三方订单状态修改
3809 3809
             log::info("tongji");

+ 1 - 0
app/common/repositories/user/UserThirdRepository.php

@@ -232,6 +232,7 @@ class UserThirdRepository extends BaseRepository
232 232
                 "table"=>$table
233 233
             ];
234 234
 
235
+            /** @var StoreOrderRepository $StoreOrderRepository */
235 236
             $StoreOrderRepository = app()->make(StoreOrderRepository::class);
236 237
 //            $StoreOrderRepository->yugu_rebate($order);
237 238
             log::info("===待进入养老金22222222222");

+ 153 - 119
app/controller/api/store/product/Jd.php

@@ -4,14 +4,15 @@ 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;
7 8
 use think\App;
8
-// use crmeb\basic\BaseController;
9
+use crmeb\basic\BaseController;
9 10
 use think\Exception;
10 11
 use think\exception\ValidateException;
11 12
 use think\facade\Db;
12 13
 use think\facade\Log;
13 14
 
14
-class Jd
15
+class Jd extends BaseController
15 16
 {
16 17
     public $appid = '';
17 18
     public $key = '';
@@ -23,7 +24,7 @@ class Jd
23 24
     public function __construct(App $app)
24 25
     {
25 26
 
26
-        // parent::__construct($app);
27
+        parent::__construct($app);
27 28
         $this->appid = '4101490811';
28 29
         $this->key = 'a7c43c21f3e156d2fd41dfbe884b9f62592ceb03b9f199c0811c82e35be53c0580a2638a7af39e74';
29 30
         $this->appKey = 'e99703d01cbb6a2e48a8a34f19af9d87';
@@ -382,45 +383,45 @@ class Jd
382 383
         set_time_limit(0);
383 384
 
384 385
         $eliteIdList = [
385
-            // '1', //好券商品
386
-                        '2', //精选卖场
387
-            //             '10', //9.9包邮
388
-            //             '15', //京东配送
389
-            //             '22', //实时热销榜
390
-            // //            '23', //为你推荐
391
-            //             '24', //数码家电
392
-            //             '25', //超市
393
-            //             '26', //母婴玩具
394
-            //             '27', //家具日用
395
-            //             '28', //美妆穿搭
396
-            //             '30', //图书文具
397
-            //             '31', //今日必推
398
-            //             '32', //京东好物
399
-            //             '33', //京东秒杀
400
-            //             '34', //拼购商品
401
-            //             '40', //高收益榜
402
-            //             '41', //自营热卖榜
403
-            // //            '108', //秒杀进行中
404
-            //             '109', //新品首发
405
-            //             '110', //自营
406
-            //             '112', //京东爆品
407
-            //             '125', //首购商品
408
-            //             '129', //高佣榜单
409
-            // //            '130', //视频商品
410
-            // //            '153', //历史最低价商品榜
411
-            // //            '238', //新人价商品
412
-            // //            '315', //秒杀未开始
413
-            //             '341', //3C新品
414
-            //             '342', //智能新品
415
-            //             '343', //3C长尾商品
416
-            //             '345', //时尚新品
417
-            //             '346', //时尚爆品
418
-            // //            '1001', //选品库
419
-            // //            '515', //订单接龙商品
420
-            // //            '519', //官方活动
421
-            //             '12254', //超级补贴
422
-            //             '12318', //便宜包邮
423
-            //             '12339', //超市卡
386
+            '1', //好券商品
387
+            '2', //精选卖场
388
+            '10', //9.9包邮
389
+            '15', //京东配送
390
+            '22', //实时热销榜
391
+            //            '23', //为你推荐
392
+            '24', //数码家电
393
+            '25', //超市
394
+            '26', //母婴玩具
395
+            '27', //家具日用
396
+            '28', //美妆穿搭
397
+            '30', //图书文具
398
+            '31', //今日必推
399
+            '32', //京东好物
400
+            '33', //京东秒杀
401
+            '34', //拼购商品
402
+            '40', //高收益榜
403
+            '41', //自营热卖榜
404
+            //            '108', //秒杀进行中
405
+            '109', //新品首发
406
+            '110', //自营
407
+            '112', //京东爆品
408
+            '125', //首购商品
409
+            '129', //高佣榜单
410
+            //            '130', //视频商品
411
+            //            '153', //历史最低价商品榜
412
+            //            '238', //新人价商品
413
+            //            '315', //秒杀未开始
414
+            '341', //3C新品
415
+            '342', //智能新品
416
+            '343', //3C长尾商品
417
+            '345', //时尚新品
418
+            '346', //时尚爆品
419
+            //            '1001', //选品库
420
+            //            '515', //订单接龙商品
421
+            //            '519', //官方活动
422
+            '12254', //超级补贴
423
+            '12318', //便宜包邮
424
+            '12339', //超市卡
424 425
         ];
425 426
         foreach ($eliteIdList as $eliteId) {
426 427
             $page = 1;
@@ -519,33 +520,34 @@ class Jd
519 520
     /*订单获取(时间段,时间不能超过一小时)*/
520 521
     public function orderList()
521 522
     {
522
-        $time = $this->request->params([
523
-            'startTime',
524
-            'endTime'
525
-        ]);
523
+        // $time = $this->request->params([
524
+        //     'startTime',
525
+        //     'endTime'
526
+        // ]);
527
+        $time['startTime'] = request()->param('startTime', '');
528
+        $time['endTime'] = request()->param('endTime', '');
529
+
526 530
         //自定义时间  每20分钟执行一次查询前半小时的数据
527 531
         if (!$time['startTime'] && !$time['endTime']) {
528 532
             $time['startTime'] = date("Y-m-d H:i:s", strtotime("-200 minute"));
529 533
             $time['endTime'] = date('Y-m-d H:i:s');
530 534
         }
531
-//        var_dump($time);
532 535
         try {
533 536
             $orderLists = [];
534 537
             $page = 1;
535
-            $pageSize = 40;
538
+            $pageSize = 200;
536 539
             $apiName = 'jd.union.open.order.row.query';
537 540
             do {
538 541
                 $params = [
539 542
                     'orderReq' => [
540
-                        'pageNo'    => $page,
541
-                        'pageSize'  => $pageSize,
542
-                        'type'      => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
543
-                        'startTime' => $time['startTime'],//格式2020-01-02 21:23:00
544
-                        'endTime'   => $time['endTime'] //格式2020-01-02 21:24:00
543
+                        'pageIndex' => $page,
544
+                        'pageSize' => $pageSize,
545
+                        'type' => 3,//(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
546
+                        'startTime' => '2025-08-05 19:00:00',// $time['startTime'],//格式2020-01-02 21:23:00
547
+                        'endTime' => '2025-08-05 19:59:59'// $time['endTime'] //格式2020-01-02 21:24:00
545 548
                     ],
546 549
                 ];
547 550
                 $result = $this->getUrlResult($apiName, $params);
548
-//                var_dump($result);
549 551
                 $result = json_decode($result, true);
550 552
                 $result = json_decode($result['jd_union_open_order_row_query_responce']['queryResult'], true);
551 553
                 $lists = $result['data'];
@@ -554,13 +556,11 @@ class Jd
554 556
                     $orderLists = array_merge($orderLists, $lists);
555 557
                 }
556 558
 
557
-//                var_dump($result);
558 559
                 $page++;
559
-            } while ($countList == $pageSize);
560
+            } while ($countList == $pageSize && $result['hasMore'] ?? false);
560 561
             if (!empty($orderLists)) {
561 562
                 //格式化从京东拉取的订单列表
562 563
                 $formatLists = $this->formatOrderList($orderLists);
563
-//                var_dump($formatLists);
564 564
                 //将京东订单列表中的订单进行处理
565 565
                 $this->operatePinOrder($formatLists);
566 566
                 return app("json")->success("京东订单写入成功");
@@ -576,8 +576,7 @@ class Jd
576 576
     //格式化从京东拉取的订单列表
577 577
     public function formatOrderList($orderLists)
578 578
     {
579
-//        $user = app()->make(UserThirdRepository::class);
580
-        $formatLists = [];
579
+        $formatList = [];
581 580
         foreach ($orderLists as $order) {
582 581
             switch ($order['validCode']) {
583 582
                 case 15://待付款订单
@@ -592,92 +591,127 @@ class Jd
592 591
                 default://失效订单
593 592
                     $billStatus = 2;
594 593
             }
595
-            if($order['validCode']==15){ //未支付的不处理
594
+            if ($order['validCode'] == 15) { //未支付的不处理
596 595
                 continue;
597 596
             }
598 597
             //通过订单关联
599 598
             $positionId = $order['positionId'];
600
-            $userId = $positionId - pow(11, 5);
601
-            //订单关联推广位ID
602
-//            $pid = $order['subUnionId'] ?: '';
603
-            // if (empty($pid)) continue;
604
-            //订单关联推广位ID
605
-//            $chanTag = $user->getDetail(['pid' => $order['subUnionId'], 'type' => 6], 'uid,pid');
606
-            //if(!$chanTag){continue;}
607
-            $formatLists[] = [
608
-                'uid'              => $userId,
609
-                'sku_id'           => $order['skuId'],
610
-                'jd_id'            => $order['id'],
611
-                'order_sn'         => $order['orderId'],                              //订单编号
612
-                'sku_num'          => $order['skuNum'],                               //购买商品的数量
613
-                'image_url'        => $order['goodsInfo']['imageUrl'] ?? '',
614
-                'sku_name'         => $order['skuName'],
615
-                //订单中sku的单件价格,单位为分
616
-                'price'            => $order['price'],
617
-                //未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,
618
-                //8.无效-企业订单,9.无效-团购订单,11.无效-乡村推广员下单,13.无效-违规订单,14.无效-来源与备案网址不符,
619
-                //15.待付款,16.已付款,17.已完成(购买用户确认收货),20.无效-此复购订单对应的首购订单无效,21.无效-云店订单',
620
-                'status'           => $order['validCode'],
621
-                //商家信息
622
-                'shop_id'          => $order['goodsInfo']['shopId'],
623
-                //订单生成时间
624
-                'create_time'      => $order['orderTime'] ? $order['orderTime'] : 0,  //下单时间
625
-                'finish_time'      => $order['finishTime'] ? $order['finishTime'] : 0,//完成时间
626
-                'modify_time'      => $order['modifyTime'] ? $order['modifyTime'] : 0,//更新时间
627
-                'sub_union_id'     => $order['subUnionId'],                           //订单关联推广位ID
628
-                //佣金比例
629
-                'commission_share' => $order['finalRate'],                            //最终分佣比例
630
-                //实际佣金
631
-                'commission'       => $order['estimateFee'],
632
-                'bill_status'      => $billStatus,        //平台是否结算
633
-                'type'             => 2
599
+            $userId = $positionId - pow(10, 5);
600
+            if ($userId <= 0) {//拉取的订单没有匹配到用户
601
+                continue;
602
+            }
603
+
604
+            //订单实际计算佣金的金额(订单完成时,会将误扣除的运费券金额更正,如订单完成后发生退款,此金额会更新)
605
+            $goodsInfo = $order['goodsInfo'] ?? [];
606
+            $createTime = strtotime($order['orderTime']);
607
+            //平台可以进行结算的时间戳=订单创建时间+系统设置的间隔时间
608
+            $billEndTime = $this->userThird->getSettleTime($createTime);
609
+
610
+            $address = Db::name('user_address')->field('code_list,village_id')->where('uid', $userId)->where('is_default', 1)->find();
611
+            $formatList[] = [
612
+                'uid' => $userId,
613
+                'commission' => $order['actualFee'] ?: $order['estimateFee'],//佣金
614
+                'commission_share' => $order['finalRate'],
615
+                'order_sn' => $order['orderId'],
616
+                'pay_money' => $order['actualCosPrice'] ?: $order['estimateCosPrice'],
617
+                'jd_id' => $order['id'],
618
+                'create_time' => $order['orderTime'],
619
+                'finish_time' => $order['finishTime'],//用户确认收货时间
620
+                'modify_time' => $order['modifyTime'],//更新时间
621
+                'sku_num' => $order['skuNum'],
622
+                'sku_id' => $order['itemId'] ?? '', // 目前京东官方不返回 skuId
623
+                'sku_name' => $order['skuName'],
624
+                'price' => $order['price'],//原价
625
+                'sub_union_id' => $order['positionId'],
626
+                'image_url' => $goodsInfo['imageUrl'] ?? '',
627
+                'shop_name' => $goodsInfo['shopName'] ?? '京东',
628
+                'shop_id' => $goodsInfo['shopId'] ?? 0,
629
+                'status' => $order['validCode'],//订单状态
630
+                'bill_status' => $billStatus,        //平台是否结算
631
+                'bill_end_time' => $billEndTime,
632
+                'user_address_ids' => !empty($address) ? $address['code_list'] . ',' . $address['village_id'] : '',
633
+                'type' => 1
634 634
             ];
635 635
         }
636
-        return $formatLists;
636
+        return $formatList;
637 637
     }
638 638
 
639 639
     //将拼多多订单列表中的订单写入第三方平台订单表
640 640
     public function operatePinOrder($orderLists)
641 641
     {
642
+        /** @var UserThirdRepository $orderThird */
642 643
         $orderThird = app()->make(UserThirdRepository::class);
644
+        $type_shop = 6;
643 645
         foreach ($orderLists as $k => $order) {
644 646
             if (empty($order)) continue;
645 647
             //判断数据库有无此订单
646
-            $orderVip = $orderThird->getOrderDetail("order_jd", ['order_sn' => $order['order_sn'], 'sub_union_id' => $order['sub_union_id']]);
647
-            if (!$orderVip) {
648
-                // 读取商品详情 拿到商品图
649
-                $third_party_goods_detail = Db::name('third_party_goods')->whereLike('json', '%' . $order['sku_id'] . '%')->find();
650
-                $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
651
-                $order['image_url'] =  $third_party_goods_json_detail['thumb']??'';
652
-
653
-                $orderThird->createOrder('order_jd', $order, strtotime($order['create_time'])); //订单写入数据库
648
+            $localOrder = JdOrderModel::getInstance()->getOne(['order_sn' => $order['order_sn']]);
649
+            if (empty($localOrder)) {
650
+                //订单写入数据库,bill_end_time再格式化订单的时候已经加入,所以写入订单的时候就不需要在计算了
651
+                $localOrder = JdOrderModel::create($order);
654 652
                 //预估养老金
655 653
                 $orderThird->yuguOrder(
656
-                    $order['jd_id'],
657
-                    $order['commission'],
658
-                    $order['uid'],
659
-                    $order['order_sn'],
660
-                    6,
654
+                    $localOrder['order_jd_id'],
655
+                    $localOrder['commission'],
656
+                    $localOrder['uid'],
657
+                    $localOrder['order_sn'],
658
+                    $type_shop,
661 659
                     'order_jd');
662 660
                 //预估积分
663 661
                 $orderThird->yuguJifen(
664
-                    $order['jd_id'],
665
-                    $order['commission'],
666
-                    $order['uid'],
667
-                    $order['order_sn'],
668
-                    6
662
+                    $localOrder['order_jd_id'],
663
+                    $localOrder['commission'],
664
+                    $localOrder['uid'],
665
+                    $localOrder['order_sn'],
666
+                    $type_shop
669 667
                 );
670 668
             } else {
671
-                //更新
672
-                if ($orderVip['status'] != $order['status']) {
673
-                    $saveOrderPdd['status'] = $order['status'];
674
-                    if(isset($order['bill_status'])){
675
-                        $saveOrderPdd['bill_status'] = $order['bill_status'];
669
+                if($localOrder['status']!=$order['status']) {
670
+                    $localOrder->save($order);//更新订单信息
671
+                    if(!in_array($order['status'],[15,16,17])){
672
+                        //修改积分和贡献,yanglaojin值记录
673
+                        $orderThird->updateJilu(
674
+                            $localOrder['uid'],
675
+                            $localOrder['order_jd_id'],
676
+                            $type_shop);
676 677
                     }
677
-                    $orderThird->saveOrder("order_jd", ['order_jd_id' => $orderVip['order_jd_id']], $saveOrderPdd); //修改订单
678 678
                 }
679 679
             }
680 680
 
681
+            // $orderVip = $orderThird->getOrderDetail("order_jd", ['order_sn' => $order['order_sn'], 'sub_union_id' => $order['sub_union_id']]);
682
+            // if (!$orderVip) {
683
+            //     // 读取商品详情 拿到商品图
684
+            //     $third_party_goods_detail = Db::name('third_party_goods')->whereLike('json', '%' . $order['sku_id'] . '%')->find();
685
+            //     $third_party_goods_json_detail = json_decode($third_party_goods_detail['json'], true);
686
+            //     $order['image_url'] =  $third_party_goods_json_detail['thumb']??'';
687
+            //
688
+            //     $orderThird->createOrder('order_jd', $order, strtotime($order['create_time'])); //订单写入数据库
689
+            //     //预估养老金
690
+            //     $orderThird->yuguOrder(
691
+            //         $order['jd_id'],
692
+            //         $order['commission'],
693
+            //         $order['uid'],
694
+            //         $order['order_sn'],
695
+            //         6,
696
+            //         'order_jd');
697
+            //     //预估积分
698
+            //     $orderThird->yuguJifen(
699
+            //         $order['jd_id'],
700
+            //         $order['commission'],
701
+            //         $order['uid'],
702
+            //         $order['order_sn'],
703
+            //         6
704
+            //     );
705
+            // } else {
706
+            //     //更新
707
+            //     if ($orderVip['status'] != $order['status']) {
708
+            //         $saveOrderPdd['status'] = $order['status'];
709
+            //         if(isset($order['bill_status'])){
710
+            //             $saveOrderPdd['bill_status'] = $order['bill_status'];
711
+            //         }
712
+            //         $orderThird->saveOrder("order_jd", ['order_jd_id' => $orderVip['order_jd_id']], $saveOrderPdd); //修改订单
713
+            //     }
714
+            // }
681 715
         }
682 716
     }
683 717