zhaojs
2023-09-15 fc13938ff90213060532d99a600dea4a84456885
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
using Operater.DTO.System;
using System;
using CommonUtil;
using System.Collections.Generic;
using System.Text;
using AlibabaSDK.Request;
using AlibabaSDK.Api;
using Operater.DbModel;
using Operater.DAL;
using System.Linq;
using Newtonsoft.Json.Linq;
 
namespace ProductDistribution.Handle
{
    public class DistributebillGetHandle
    {
        /// <summary>
        /// 代发商品铺货单获取
        /// </summary>
        public static void MainMethod(ProductDistributionMq msg)
        {
            string memo = "";
            try
            {
                var _Token = CommonHandle.GetToken();
                //接口获取可铺货单商品id
                AlibabaDistributebillListRequest billListRequest = new AlibabaDistributebillListRequest();
                var billListResponse = AliabaClient.Execute(billListRequest, _Token.AliToken);
                if (billListResponse.IsNull() || !billListResponse.Success|| billListResponse.result.IsNull())
                {
                    LogUtil.Info("接口获取可铺货单商品id错误:" + (billListResponse.IsNull() ? "null" : billListResponse.ErrorCode), "代发商品铺货单获取error");
                    DaifaTask daifaTask = new DaifaTask()
                    {
                        TaskStatus = 2,
                        Memo = "接口获取可铺货单商品id错误:" + (billListResponse.IsNull() ? "null" : billListResponse.ErrorCode)
                    };
                    new DaifaTaskDAL().Update(daifaTask, i => new { i.TaskStatus, i.Memo }, t => t.Id == msg.TaskId);
                    return;
                }
                List<string> errorCount = new List<string>();
                foreach (var proId in billListResponse.result.offerIds)
                {
                    try
                    {
                        if (new DaifaProductDAL().IsExist(t => t.Id == proId.ToString()))
                        {//已存在
                            continue;
                        }
                        //获取商品详情
                        FenXiaoProductInfoGetRequest proReq = new FenXiaoProductInfoGetRequest()
                        {
                            offerId = proId
                        };
                        var proResponse = AliabaClient.Execute(proReq, _Token.AliToken);
                        if (proResponse.IsNull() || !proResponse.Success)
                        {
                            LogUtil.Info("获取商品详情错误:" + proId + "--" + (proResponse.IsNull() ? "null" : proResponse.ErrorMsg), "代发商品铺货单获取error");
                            errorCount.Add(proId.ToString());
                            continue;
                        }
                        var productInfo = proResponse.productInfo;
                        int supportOnlineTrade = productInfo.productSaleInfo.supportOnlineTrade ? 1 : 0;
                        DaifaProduct daifaProduct = new DaifaProduct()
                        {
                            Id = proId.ToString(),
                            Img = "https://cbu01.alicdn.com/" + productInfo.productImage.images[0],
                            MinPrice = decimal.Parse(productInfo.productSkuInfos.Min(t => t.consignPrice).ToString()),
                            MaxPrice = decimal.Parse(productInfo.productSkuInfos.Max(t => t.consignPrice).ToString()),
                            ProductStatus = productInfo.status,
                            Subject = productInfo.subject,
                            SupportOnlineTrade = supportOnlineTrade,
                            IsDistribute = 0,
                            CreateTime = DateTime.Now
                        };
                        //处理买家保障
                        string mjbz = "";
                        foreach (var m in productInfo.productExtendInfos)
                        {
                            if (!"buyerProtection,buyerProtectionDistribution".Contains(m.key) || m.value.IsNullOrEmpty())
                            {
                                continue;
                            }
                            List<string> arr = JSONUtil.JsonToObject<List<string>>(m.value);
                            foreach (var a in arr)
                            {
                                mjbz += GetMjbz(a) + ",";
                            }
                        }
                        mjbz = mjbz.Length > 0 ? (mjbz.Substring(0, mjbz.Length - 1)) : mjbz;
                        daifaProduct.BuyerProtection = mjbz;
                        new DaifaProductDAL().Insert(daifaProduct);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        LogUtil.Info("循环错误:" + e.ToString(), "代发商品铺货单获取error");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                LogUtil.Info("主线程错误:" + e.ToString(), "代发商品铺货单获取error");
                memo = "主线程错误:" + e.ToString();
            }
            DaifaTask sdaifaTask = new DaifaTask()
            {
                TaskStatus = 2,
                Memo = memo
            };
            new DaifaTaskDAL().Update(sdaifaTask, i => new { i.TaskStatus, i.Memo }, t => t.Id == msg.TaskId);
        }
 
        public static string GetMjbz(string m)
        {
            switch (m)
            {
                case "qtwlybt":
                    return "七天无理由包退";
                case "drfh":
                    return "当日发货";
                case "qqqqqqq":
                    return "qqqqq";
                case "essxsfh":
                    return "24小时发货";
                case "ssbxsfh":
                    return "48小时发货";
                case "qsexsfh":
                    return "72小时发货";
                case "qtbh":
                    return "7天包换";
                case "stdhbz":
                    return "3天到货保障";
                case "wtdhbz":
                    return "5天到货保障";
                case "qtdhbz":
                    return "7天到货保障";
                case "btwlybt":
                    return "8天无理由包退";
                case "shbp":
                    return "少货必赔";
                case "czbz":
                    return "材质保障";
                case "psbp":
                    return "破损包赔";
                case "gfzs":
                    return "官方直送";
                default:
                    return m;
            }
        }
    }
}