xuhy
2026-02-05 337d48dbcb60bacb9bad2d4a0c3f2c34b132ef73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.ruoyi.web.controller.yuncang.api.trade;
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.model.TErpProcurement;
import com.ruoyi.system.model.TErpProcurementGoods;
import com.ruoyi.web.controller.yuncang.utils.WdtClient;
import lombok.extern.slf4j.Slf4j;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Slf4j
public class TradePush {
 
    /**
     * 推送erp订单
     * @param sid     卖家账号,接口请求的公共参数sid
     * @param appkey     接口账号,接口请求的公共参数appkey
     * @param appsecret 接口秘钥,接口请求的参数appsecret ,用于计算签名
     * @param url     接口地址,接口请求的公共参数url
     * @param erpProcurement 采购单
     * @param erpProcurementGoods 采购单商品
     * @param trade_status 平台订单状态较多且涉及变更,详情介绍单击这里
     * @param clinicName 采购单所属诊所名称
     * @param status 平台子订单状态,子订单状态可以和主订单不一样,比如其中一个子订单退款完成,其状态是80,但主订单仍然是待发货,可选值同trade_status
     * @param refund_status 0:无退款,1:取消退款,2:已申请退款,3:等待退货,4:等待收货,5:退款成功。本字段在售前退款的时候,根据不同的场景填写不同的值,eg:申请退款值为2,取消退款值为1……
     * @param shop_no     代表店铺所有属性的唯一编码,用于店铺区分,ERP内支持自定义(ERP店铺界面设置,查看路径ERP→设置→基本设置→店铺→店铺列表),用于创建指定店铺单据信息,测试环境店铺编号信息同接口账号。ERP内shop_no对应的“店铺平台”必须为“自有/其它”。正式环境店铺创建成功后ERP会自动授权,如果自动授权失败,在ERP店铺界面(路径ERP→设置→基本设置→店铺→店铺列表)选中授权失败的店铺,点击店铺界面提供的店铺授权按钮重新授权。
     * @param receiver_name 收件人姓名
     * @param receiver_province 收件人省份,传为中文名称需与旺店通地址库匹配
     * @param receiver_city 收件人城市,传为中文名称需与旺店通地址库匹配
     * @param receiver_district 收件人区县,传为中文名称需与旺店通地址库匹配
     * @param receiver_address 收件人地址详情,传为中文名称,需与旺店通地址库匹配,点击查看,如果不传省市区,则会尝试从详细地址解析省市区,必须是空格分隔的才能解析成功,需要注意直辖市的地址格式,举例“北京 北京市 海淀区 花园路xxxx”
     * @param receiver_mobile 手机号码
     */
    public static JSONObject tradePush(String sid, String appkey, String appsecret, String url,
                                 TErpProcurement erpProcurement, List<TErpProcurementGoods> erpProcurementGoods,
                                 Integer trade_status,Integer status,Integer refund_status,String clinicName,
                                   String shop_no,String receiver_name,String receiver_province,
                                   String receiver_city,String receiver_district,String receiver_address,
                                   String receiver_mobile) {
        WdtClient client = new WdtClient(sid, appkey, appsecret, url);
        //测试环境sid、appkey、密钥请到旺店通开放平台-自助对接-申请测试环境内查看,测试环境url=https://sandbox.wangdian.cn/openapi2/
        //调用正式环境时请将sid、appkey、appsecret切换为实际参数,参数在旺店通开放平台-自助对接-应用管理内应用状态为已上线的应用中查看,调用正式环境注意切换正式环境url=https://api.wangdian.cn/openapi2/
 
        List<Map<String, Object>> trade_list = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> order_list = new ArrayList<Map<String, Object>>();
        for (TErpProcurementGoods erpProcurementGood : erpProcurementGoods) {
            Map<String, Object> order_1 = new HashMap<String, Object>();
            order_1.put("oid", erpProcurementGood.getId());
            order_1.put("num", erpProcurementGood.getPurchaseCount());
            order_1.put("price", erpProcurementGood.getPurchasePrice());
            order_1.put("status", status);
            order_1.put("refund_status", refund_status);
            order_1.put("goods_id", erpProcurementGood.getCloudGoodsId());
            order_1.put("spec_id", erpProcurementGood.getCloudSpecId());
            order_1.put("goods_no", erpProcurementGood.getCloudGoodsCode());
            order_1.put("spec_no", erpProcurementGood.getCloudSpecCode());
            order_1.put("goods_name", erpProcurementGood.getGoodsName());
            order_1.put("discount", 0);        //子订单折扣
            order_1.put("adjust_amount", 0);    //手工调整,特别注意:正的表示加价,负的表示减价
            order_1.put("share_discount", 0);
            order_list.add(order_1);
        }
 
        Map<String, Object> trade_1 = new HashMap<String, Object>();
        trade_1.put("tid", erpProcurement.getProcurementCode());
        trade_1.put("trade_status", trade_status);
        trade_1.put("pay_status", "2");
        trade_1.put("delivery_term", 1);
        trade_1.put("trade_time", DateUtils.localDateTimeToString(erpProcurement.getCreateTime()));
        trade_1.put("pay_time", DateUtils.localDateTimeToString(erpProcurement.getPayTime()));
        trade_1.put("buyer_nick", clinicName);
        trade_1.put("receiver_name", receiver_name);
        trade_1.put("receiver_province", receiver_province);
        trade_1.put("receiver_city", receiver_city);
        trade_1.put("receiver_district", receiver_district);
        trade_1.put("receiver_address", receiver_address);
        trade_1.put("receiver_mobile", receiver_mobile);
//        trade_1.put("logistics_type", 4);
        trade_1.put("post_amount", 0);
        trade_1.put("cod_amount", 0);
        trade_1.put("ext_cod_fee", 0);
        trade_1.put("other_amount", 0);
        trade_1.put("paid", erpProcurement.getPayMoney());
        trade_1.put("order_list", order_list);
        trade_list.add(trade_1);
 
        String trade_list_json = JSON.toJSONString(trade_list);
 
        Map<String, String> params = new HashMap<String, String>();
        params.put("shop_no", shop_no);
        params.put("trade_list", trade_list_json);
        try {
            String response = client.execute("trade_push.php", params);
            log.info("推送erp订单结果:{}", response);
            JSONObject jsonObject = JSONObject.parseObject(response);
            if (jsonObject.getIntValue("code") == 0) {
                log.info("推送erp订单成功");
                return jsonObject;
            } else {
                log.info("推送erp订单失败");
                throw new ServiceException(jsonObject.getString("message"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args) {
        WdtClient client = new WdtClient("apidevnew2", "hytycw02-test", "c7ae51196", "https://sandbox.wangdian.cn/openapi2/");
        //测试环境sid、appkey、密钥请到旺店通开放平台-自助对接-申请测试环境内查看,测试环境url=https://sandbox.wangdian.cn/openapi2/
        //调用正式环境时请将sid、appkey、appsecret切换为实际参数,参数在旺店通开放平台-自助对接-应用管理内应用状态为已上线的应用中查看,调用正式环境注意切换正式环境url=https://api.wangdian.cn/openapi2/
 
        List<Map<String, Object>> trade_list = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> order_list = new ArrayList<Map<String, Object>>();
 
        Map<String, Object> order_1 = new HashMap<String, Object>();
        order_1.put("oid", "2011681139470175424");
        order_1.put("num", 1);
        order_1.put("price", 12);
        order_1.put("status", 30);
        order_1.put("refund_status", 0);
        order_1.put("goods_id", "202602051455");
        order_1.put("spec_id","20260205145501");
        order_1.put("goods_no", "AL0204_QTZL014A");
        order_1.put("spec_no", "AL0204_QTZL014A");
        order_1.put("goods_name", "真露西柚13度360ml*20瓶箱装");
        order_1.put("discount", 0);        //子订单折扣
        order_1.put("adjust_amount", 0);    //手工调整,特别注意:正的表示加价,负的表示减价
        order_1.put("share_discount", 0);
 
 
        order_list.add(order_1);
 
        Map<String, Object> trade_1 = new HashMap<String, Object>();
        trade_1.put("tid", "C2026011540514");
        trade_1.put("trade_status", 30);
        trade_1.put("pay_status", "2");
        trade_1.put("delivery_term", 1);
        trade_1.put("trade_time", "2026-02-05 11:21:01");
        trade_1.put("pay_time", "2026-02-05 11:21:01");
        trade_1.put("buyer_nick", "卡卡");
        trade_1.put("receiver_province", "四川省");
        trade_1.put("receiver_city", "成都市");
        trade_1.put("receiver_district", "武侯区");
        trade_1.put("receiver_address", "锦辉西二街天府新谷9号楼");
        trade_1.put("receiver_name", "卡卡");
        trade_1.put("receiver_mobile", "15731511105");
//        trade_1.put("logistics_type", 4);
        trade_1.put("post_amount", 0);
        trade_1.put("cod_amount", 0);
        trade_1.put("ext_cod_fee", 0);
        trade_1.put("other_amount", 0);
        trade_1.put("paid", 12);
        trade_1.put("order_list", order_list);
        trade_list.add(trade_1);
        String trade_list_json = JSON.toJSONString(trade_list);
        //System.out.println(purchase_info_json);
 
        Map<String, String> params = new HashMap<String, String>();
        params.put("shop_no", "hytycw02-test");
        params.put("trade_list", trade_list_json);
        try {
            String response = client.execute("trade_push.php", params);
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}