zhaojs
2023-09-27 74098f1401afe40f961d1d167bb18dd0a71c4d59
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
using AlibabaSDK.Api;
using AlibabaSDK.Request;
using Operater.DAL;
using System;
using System.Collections.Generic;
using System.Text;
using YouZanSDKStandard.Api.Request;
using CommonUtil;
using YouZanSDKStandard.Api.Domain;
using Operater.Service.System;
using YouZanSDKStandard.Api;
using Operater.DbModel;
 
namespace ProductDistribution
{
    public class ProductUpdateHandle
    {
        public static void MainMethod()
        {
            try
            {
                var appSet = (new AppsetDAL().ListGet(t => t.Id != null))[0];
                var proList = new DistributionRelationDAL().ListGet(t => t.ProSource == 0);
                //获取过滤关键词
                var filter = new ProductFilterDAL().ListGet(t => t.Id != null);
                int index = 0;
                foreach (var pro in proList)
                {
 
                    //获取有赞商品详情
                    //YouZanProductDetailGetRequest adetailReq = new YouZanProductDetailGetRequest()
                    //{
                    //    item_id = long.Parse(pro.YzProduct)
                    //};
                    //var sdetailRs = YouZanClient.Execute(adetailReq, appSet.YzToken);
 
                    index++;
                    Console.WriteLine($"{index}/{proList.Count}");
                    try
                    {
                        //获取1688商品详情
                        List<string> ls = new List<string>();
                        ls.Add(pro.SourceProduct);
                        PFTProductDetailRequest request = new PFTProductDetailRequest()
                        {
                            offerIds = ls
                        };
                        var response = AliabaClient.Execute(request, appSet.AlibabaToken);
                        if (response.IsNull() || !response.result.success || response.result.result.Count == 0)
                        {
                            Console.WriteLine("1688获取详情失败:" + response.result.message);
                            continue;
                        }
                        var aliPro = response.result.result[0].productInfo;
                        ////获取有赞商品详情
                        YouZanProductDetailGetRequest detailReq = new YouZanProductDetailGetRequest()
                        {
                            item_id = long.Parse(pro.YzProduct)
                        };
                        var detailRs = YouZanClient.Execute(detailReq, appSet.YzToken);
                        if (detailRs.IsNull() || !detailRs.success)
                        {
                            Console.WriteLine("获取有赞商品详情失败");
                            LogUtil.Info("获取有赞商品详情失败:" + detailRs.message, "错误");
                            continue;
                        }
                        YouZanProductUpdateReqDomain para = new YouZanProductUpdateReqDomain()
                        {
                            item_id = long.Parse(pro.YzProduct)
                        };
                        YouZanProductUpdateRequest yzReq = new YouZanProductUpdateRequest();
                        //获取有赞参数
                        YouZanProductUpdateReqPostSaleParam postSaleParam = new YouZanProductUpdateReqPostSaleParam() { is_support_barter = 0 };
                        postSaleParam.support_unconditional_return = aliPro.sevenDaysRefunds;
                        para.post_sale_param = postSaleParam;
 
                        para.title = ItemDistributionService.FilterMsg(filter, aliPro.subject);
 
                        para.desc = ItemDistributionService.FilterMsg(filter, aliPro.description);
                        para.detail_edit = true;
                        yzReq.param = para;
                        var yzRsp = YouZanClient.Execute(yzReq, appSet.YzToken);
                        if (yzRsp.IsNull() || !yzRsp.success)
                        {
                            Console.WriteLine("有赞接口修改失败:" + yzRsp.message);
                            LogUtil.Info("有赞接口修改失败:" + yzRsp.message, "错误");
                        }
                    }
                    catch (Exception e)
                    {
                        LogUtil.Info("错误:" + e.ToString(), "循环错误");
                        continue;
                    }
                    DistributionRelation distributionRelation = new DistributionRelation()
                    {
                        ProSource = 2
                    };
                    new DistributionRelationDAL().Update(distributionRelation, i => new { i.ProSource }, t => t.Id == pro.Id);
                }
            }
            catch (Exception e)
            {
                LogUtil.Info("错误:" + e.ToString(), "主线程错误");
            }
        }
    }
}