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
using Operater.DAL;
using Operater.DTO.System;
using System;
using System.Collections.Generic;
using System.Text;
using CommonUtil;
using YouZanSDKStandard.Api.Request;
using YouZanSDKStandard.Api;
using Operater.DbModel;
 
namespace Operater.Service.System
{
    public class SendGoodsService : ISendGoodsService
    {
        /// <summary>
        /// 有赞发货
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public YzSendGoodsResponse YzSendGoods(YzSendGoodsRequest request)
        {
            YzSendGoodsResponse response = new YzSendGoodsResponse()
            {
                IsSuccess = false
            };
            try
            {
                //判断是否发货过
                var relatio = new TradeCreateRelationDAL().GetById(request.YzOid);
                if(relatio.IsNull())
                {
                    response.ErrorMsg = "该子订单对应的1688订单未发货";
                    return response;
                }
                if (relatio.YzIssendgoods == 1)
                {
                    response.ErrorMsg = "该子订单已经发货";
                    return response;
                }
                //获取1688物流信息
                var aliLogistics = new AliLogisticsDAL().GetById(relatio.AliOid);
                if (aliLogistics.IsNull() || aliLogistics.AliOid.IsNullOrEmpty())
                {
                    response.ErrorMsg = "获取1688物流信息失败";
                    return response;
                }
                //获取有赞发货的物流
                var expressList = new AliExpressDAL().ListGet(t=>t.ComNo== aliLogistics.CpCode);
                var express = expressList[0];
                YouZanLogisticsConfirmRequest yzReq = new YouZanLogisticsConfirmRequest()
                {
                    tid = relatio.YzTid,
                    out_stype = express.YzId.ToString(),
                    out_sid = aliLogistics.MailNo,
                    is_no_express = 0,
                    oids = request.YzOid
                };
                var yzRsp = YouZanClient.Execute(yzReq, request.YzToken);
                LogUtil.Info("Oid:" + request.YzOid + ",req:" + JSONUtil.ObjectToJson(yzRsp), "有赞发货请求");
                if (yzRsp.IsNull() || !yzRsp.success)
                {
                    response.ErrorMsg = "有赞发货失败:" + (yzRsp.IsNull() ? "返回null" : yzRsp.message);
                    return response;
                }
                YzOrderinfo yzOrderinfo = new YzOrderinfo()
                {
                    YzGoodsStatus = 1
                };
                new YzOrderinfoDAL().Update(yzOrderinfo,i => new{ i.YzGoodsStatus}, t => t.Oid == request.YzOid);
 
                response.IsSuccess = true;
                return response;
            }
            catch (Exception e)
            {
                response.ErrorMsg = e.ToString();
                return response;
            }
        }
    }
}