Practical development notes for Doudian order delivery return

Table of contents

Preface

1. Order delivery interface

2. Merchant docking interface steps

1. Business logic analysis

2. Business logic code

Summarize


Preface

The main reason is that I have connected with the Doudian open platform before, so now I want to record it, make a note, and summarize how the docking order delivery interface was implemented at that time, and what were the subsequent optimization points.

1. Order delivery interface

This interface is in the self-developed documents of merchants on the Doudian open platform. It is specially used for merchants who have the ability to connect to return their own logistics numbers to mark the delivery of orders to their own stores. According to the official documents, it is / order/logisticsAdd (order delivery interface), it currently only supports the entire order outbound, that is, when the interface is called, only the parent order number can be passed as an input parameter. Tips: For a parent order in the partially shipped state, if you call this interface to ship, an error will be reported: The order is currently in the "partially shipped" state and this interface cannot be called.

The request parameters of this interface are as shown in the figure:

 So what are its response parameters? The normal response is as follows:

 That is, the value of the code must be 10000, which means that the logistics number of your order has been successfully returned to the open platform, and the open platform has successfully marked it as shipped.

2. Merchant docking interface steps

1. Business logic analysis

The first step is to design a development plan.

First, according to the request parameters of the shipping interface, we get that the order number is required, as well as parameters such as logistics company name, logistics company code, express delivery order number, etc.

Then, we need to analyze various scenarios based on the business of our own merchants.

The first scenario is that our Doudian operators sometimes need to manually guide orders to their own ERP system based on their needs, and then the own ERP system pushes the orders to Zhongtong for delivery. Zhongtong usually will Return the logistics number of the order on the same day,

The logistics number here will be divided into two situations:

The first situation is that the logistics number needs to be sent back to the Doudian open platform to mark the order for shipment;

The second situation is that there is no need to return the logistics number to the Doudian open platform. There will be two situations here;

The first one is that the operation of Douyin will cooperate with the experts on the Douyin platform, and the experts will live broadcast the goods. Then the orders generated by the live broadcast of the goods by the experts will be transmitted to our own store. On the merchant store side, when we pull orders here, we can pull the orders brought by these experts. However, if we want to return the logistics number through this interface and send the order mark, It is not possible to ship goods. We can only manually provide the logistics number to the recipient through Douyin operations to mark the shipment. Therefore, we no longer need to call the interface to return the logistics number, so we will mark it directly. The status of this order is "Reported for processing", so that next time when querying these orders, the order numbers of these shipments will be filtered out.

The second one is the lucky bag, which is the lucky bag that is randomly drawn during the live broadcast. Such an order does not need to return the logistics number to the Doudian open platform. Therefore, this part of the order does not need to call the interface to return the logistics number, so the same. We will directly mark a status of this order as "Returned for processing".

The above two scenarios do not require returning the logistics number; next, it is necessary to return the logistics number.

As long as in the logistics comparison table of our ERP system, if ZTO has returned the logistics number of the order, it will be marked in this comparison table. At that time, we only need to develop this interface and set a period of time every day through scheduled tasks. Time call interface polling to check whether the logistics number of the order within this time already exists. If it exists, immediately call the delivery interface of the Doudian open platform to mark the order for shipment. Otherwise, wait for the logistics number of the order to come back. When calling processing, after the call is successful, we need to return the status of this order as "Returned Processing".

2. Business logic code

First, before starting the interface, we first poll and traverse to obtain qualified orders. These qualified orders are already in the shipping status, and the orders have been pushed to Zhongtong Logistics, and the shipping has been returned. The tracking number can only be found if it meets these conditions.

       LogisticsAddBoResponse response = new LogisticsAddBoResponse();
        response.setErrOrderNos(Lists.newArrayList());
        response.setSuccessOrderNos(Lists.newArrayList());
        BoCriteria criteria = new BoCriteria();
        criteria.setStatus(CodeItemKeys.T_ORDER_STATUS_DELIVER);
        criteria.setExpressStatusEmpty(true);
        criteria.setExprIdEmpty(false);//不允许运单号为空
        criteria.setTranBackToSales(0);     // 回传标识,0代表待回传,1代表已回传,2代表取消
        List<OrderBoBean> orderBeans = OrderService.findBeansByOrderNos(criteria);
        if(CollectionUtils.isEmpty(orderBeans)){
            response.setMessage("抖店_批量订单发货接口"+LocalDateTime.now().format(dateTimeFormatter)+",未查询到需配送订单");
            return response;
        }
        GlobalConfig.initAppKey(projectConfig.getTiktokECommerceAppId());  
        GlobalConfig.initAppSecret(projectConfig.getTiktokECommerceAppSecret());  
        AccessToken accessToken = AccessTokenBuilder.build(Long.valueOf(projectConfig.getTiktokECommerceDefaultStoreId()));  
        BizAssert.isTrue(accessToken.getAccessToken()!= null,"很抱歉,抖店发货生成并获取token失败;返回来的token为空null");
        Map<String,OrderBoBean> duplicateOrderNoCheckMap = new HashMap<>();
        String companyCode = projectConfig.getTikTokLogisticsDefaultCode();  
        TiktokLogisticsCompanyCriteria logisticsCompanyCriteria = new TiktokLogisticsCompanyCriteria();
        logisticsCompanyCriteria.setCode(companyCode);
        TiktokLogisticsCompanyBean logisticsCompanyBean = TiktokLogisticsCompanyService.findOneBean(logisticsCompanyCriteria);

The above code can be decomposed into three parts. The first part is to prepare the order data, the second part is to obtain the token, and the third part is to prepare the data of the logistics company and other related information.

The next part of the code is divided into scenarios:

This part of the code is the normal code for requesting the shipping interface to mark the shipment. It is executed by the execute request method in orderLogisticsAddRequest. After getting the res response, we will do further processing. First, mark the order as "has been" Return status".

OrderLogisticsAddResponse res = orderLogisticsAddRequest.execute(accessToken);
logger.info("抖音发货接口返回的响应体"+res.toString());
logger.info(""+CodeItemKeys.TIKTOK_API_RES_CODE_SUCCESS.equals(res.getCode().longValue()));
if(CodeItemKeys.TIKTOK_API_RES_CODE_SUCCESS.equals(res.getCode().longValue())) {
  successOrderNum++;
  OrderExpressBean updateBean = BeanUtils.copy(order,OrderExpressBean.class);
  BizAssert.isTrue(StringUtils.isNotBlank(updateBean.getOrderNo()),"很抱歉,更新order_express失败,不存在order_no订单号");                    updateBean.setExprStatus(CodeItemKeys.ORDER_EXPRESS_STATUS_DELIVER);
 updateBean.setTranBackToSales(1);  //将它设置为1,代表已经回传成功
Integer updateSql = OrderExpressService.updateBeanByOrderNo(updateBean);
  logger.error("订单批量发货成功的订单:"+channelOrderId);
  logger.info("订单批量发货成功的订单:"+channelOrderId);
  response.getSuccessOrderNos().add(channelOrderId);

The following code does not require postback scenarios:

We make judgments based on the SubCode returned in the res.getSubCode() response. The first one is the judgment of repeated shipments, because sometimes Doudian orders are manually imported into our system through operations. Therefore, after the logistics number is sent back, it can be sent back to the platform according to the above logic. However, it may not be marked, so an additional judgment is added here. If it has been sent back repeatedly, it will be marked as "already Postback processing" is all.

Another situation is that Douyin operators sometimes manually guide Douyin orders to the order form and push them to ZTO for delivery. This type of order does not need to be sent back to Douyin. At this time, The SubCode returned in the res.getSubCode() response is a code that does not exist for the order, so based on this code, these orders can be marked as "returned for processing".

if(CodeItemKeys.TIKTOK_API_RES_CODE_FAIL_DELIVER.equals(res.getSubCode())){   
                        logger.info("返回来的错误码==="+res.getSubCode());
                        logger.info("说明该订单已经回传物流号了");
                        OrderExpressBean updateBean = BeanUtils.copy(order,OrderExpressBean.class);
                        BizAssert.isTrue(StringUtils.isNotBlank(updateBean.getOrderNo()),"很抱歉,更新order_express失败,不存在order_no订单号");
                        updateBean.setExprStatus(CodeItemKeys.ORDER_EXPRESS_STATUS);
                        updateBean.setTranBackToSales(1);  //将它设置为1,代表已经回传成功
                        Integer updateSql = OrderExpressService.updateBeanByOrderNo(updateBean);
                        logger.error("订单批量发货==重复发货的订单:"+channelOrderId);
                        logger.info("订单批量发货==重复发货的订单:"+channelOrderId);
                    }
                    //TODO 抖音运营人员有时会自己人工导抖音单到订单表上,推到中通发货,这种类型的订单,是不需要回传给抖音的
                    if(CodeItemKeys.API_RES_CODE_FAIL_NULL.equals(res.getSubCode())){
                        logger.info("返回来的错误码==="+res.getSubCode());
                        logger.info("说明该订单在抖音平台上的店铺中不存在");
                        OrderExpressBean updateBean = BeanUtils.copy(order,OrderExpressBean.class);
                        
                        updateBean.setExprStatus(CodeItemKeys.ORDER_EXPRESS_STATUS_DELIVER);
                        updateBean.setTranBackToSales(1);  //将它设置为1,代表已经回传成功
                        Integer updateSql = OrderExpressService.updateBeanByOrderNo(updateBean);

                    }

The code is as follows (example):

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import  ssl
ssl._create_default_https_context = ssl._create_unverified_context


Summarize

The main reason is that I have connected with the Doudian open platform before, so now I want to record it, make a note, and summarize how the docking order delivery interface was implemented at that time, and what were the subsequent optimization points.

Guess you like

Origin blog.csdn.net/weixin_46442877/article/details/127921610