/// <summary> /// 提交订单数据接口到方正电商 /// </summary> public static void FangZheng_Order_Confirm(Guid MyOrderId, bool IsMainOrder) { if (IsMainOrder) { MainOrder.ObjectSet().Where(r => r.MainOrderId == MyOrderId).ToList() .ForEach(Item => { FangZheng_Order_Confirm(Item.SubOrderId); }); } else { FangZheng_Order_Confirm(MyOrderId); } }
public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO UpdateOrderSpreaderExt(Jinher.AMP.BTP.Deploy.CustomDTO.SpreaderAndBuyerWxDTO sbwxDto) { ResultDTO result = new ResultDTO(); if (sbwxDto == null) { result.ResultCode = 1; result.Message = "参数错误,参数不能为空!"; return(result); } if (string.IsNullOrWhiteSpace(sbwxDto.WxOpenId)) { result.ResultCode = 2; result.Message = "参数错误,微信OpenId不能为空!"; return(result); } if (sbwxDto.BuyerId == Guid.Empty) { result.ResultCode = 3; result.Message = "参数错误,买家用户Id不能为空!"; return(result); } if (sbwxDto.OrderId == Guid.Empty) { result.ResultCode = 4; result.Message = "参数错误,订单Id不能为空!"; return(result); } try { ContextSession contextSession = ContextFactory.CurrentThreadContext; //用户id相关 买家-推广者对照表。 var usQuery = from us in UserSpreader.ObjectSet() where us.UserId == sbwxDto.BuyerId select us; //微信Id相关 买家-推广者对照表。 var wxQuery = from u in UserSpreader.ObjectSet() where u.WxOpenId == sbwxDto.WxOpenId select u; //推广者用户id. Guid spreaderId = Guid.Empty; Guid spreadCode = Guid.Empty; //当前买家已有归属的推广主信息。 if (usQuery.Any()) { //没有wxopenId信息,则更新。 var usFirst = usQuery.FirstOrDefault(); spreaderId = usFirst.SpreaderId; spreadCode = usFirst.SpreadCode; if (string.IsNullOrWhiteSpace(usFirst.WxOpenId)) { usFirst.WxOpenId = sbwxDto.WxOpenId; usFirst.ModifiedOn = DateTime.Now; } //删除其它和当前wxOpenId相关的记录。 foreach (var uu in usQuery) { if (uu.Id == usFirst.Id) { continue; } uu.EntityState = System.Data.EntityState.Deleted; } } else { if (wxQuery.Any()) { UserSpreader usRecord = wxQuery.FirstOrDefault(); usRecord.UserId = sbwxDto.BuyerId; usRecord.ModifiedOn = DateTime.Now; spreaderId = usRecord.SpreaderId; spreadCode = usRecord.SpreadCode; } } //推广分成相关订单Id. List <Guid> orderIds = new List <Guid>(); var moQuery = from mo in MainOrder.ObjectSet() where mo.MainOrderId == sbwxDto.OrderId select mo.SubOrderId; if (moQuery.Any()) { //传入的OrderId为主订单id,找出所有子订单。 orderIds = moQuery.ToList(); } else { orderIds.Add(sbwxDto.OrderId); } var coQuery = from co in CommodityOrder.ObjectSet() where orderIds.Contains(co.Id) select co; foreach (var cOrder in coQuery) { cOrder.SpreaderId = spreaderId; cOrder.ModifiedOn = DateTime.Now; cOrder.SpreadCode = spreadCode; } contextSession.SaveChanges(); result.ResultCode = 0; result.Message = "成功!"; return(result); } catch (Exception ex) { LogHelper.Error(string.Format("UpdateOrderSpreaderExt异常。sbwxDto:{0}", JsonHelper.JsonSerializer(sbwxDto)), ex); result.ResultCode = 10; result.Message = "接口异常,请稍后重试!"; return(result); } }