protected override ProcessActionRD ProcessRequest(APIRequest <ProcessActionRP> pRequest) { #region 错误码 const int ERROR_ORDER_NOTEXISTS = 301; const int ERROR_ORDER_PROCESSED = 302; #endregion ProcessActionRD rd = new ProcessActionRD(); T_InoutBLL _TInoutbll = new T_InoutBLL(this.CurrentUserInfo); //订单表 TInoutStatusBLL _TInoutStatusBLL = new TInoutStatusBLL(this.CurrentUserInfo); //日志表 VipIntegralBLL vipIntegralBLL = new VipIntegralBLL(this.CurrentUserInfo); //会员业务对象实例化 var UserBLL = new T_UserBLL(this.CurrentUserInfo); //员工实例 string OrderID = pRequest.Parameters.OrderID; //订单ID string ActionCode = pRequest.Parameters.ActionCode; //订单操作码(当前订单状态码作为操作码) string ActionParameter = pRequest.Parameters.ActionParameter; //订单操作参数,可为空 string DeliverCompany = pRequest.Parameters.DeliverCompany; //快递公司 string DeliverOrder = pRequest.Parameters.DeliverOrder; //快递单号 string VipID = pRequest.UserID; if (pRequest.ChannelId != "2") { VipID = pRequest.Parameters.VipID; } var tran = _TInoutbll.GetTran(); using (tran.Connection)//事物 { try { #region 1.根据订单ID,订单操作码更新订单表中订单状态和状态描述 var entity = _TInoutbll.GetInoutInfo(OrderID, this.CurrentUserInfo); //根据标识获取新的实例 if (entity.status == ActionCode) //判断是否重复操作 { throw new APIException("操作已处理") { ErrorCode = ERROR_ORDER_PROCESSED } } ; #region 当状态为完成时,返现,返积分 if (ActionCode == "700" && entity.status != "700") { //确认收货时处理积分、返现、佣金[完成订单] // vipIntegralBLL.OrderReward(entity, tran); new SendOrderRewardMsgBLL().OrderReward(entity, this.CurrentUserInfo, tran);//存入到缓存 } #endregion if (entity == null) { throw new APIException(string.Format("未找到OrderID:{0}订单", pRequest.Parameters.OrderID)) { ErrorCode = ERROR_ORDER_NOTEXISTS } } ; if (entity.status == ActionCode) //如果状态以及国内是要提交的状态了,就不要再提交了 { return(rd); } string Updatebeforestatus = entity.status_desc; //更新之前的订单状态描述 entity.status = ActionCode; //输入的状态码 entity.Field7 = ActionCode; entity.status_desc = GetStatusDesc(ActionCode); //输入的状态码对应的状态描述 entity.Field10 = GetStatusDesc(ActionCode); //Field10=status_desc状态描述 entity.modify_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //修改时间 entity.modify_user_id = pRequest.UserID; //修改人 if (ActionCode == "600" || !string.IsNullOrEmpty(DeliverOrder) || !string.IsNullOrEmpty(DeliverCompany)) { entity.Field9 = DateTime.Now.ToSQLFormatString(); entity.Field2 = DeliverOrder; //快递单号 entity.carrier_id = DeliverCompany; //快递单号 //更新订单配送商及配送单号 } if (ActionCode == "700" && pRequest.ChannelId != "2") { if (string.IsNullOrEmpty(entity.sales_user)) { entity.sales_user = pRequest.UserID;//把当前用户作为服务人员。****!! } //更新订单支付状态 entity.Field1 = "1"; entity.accpect_time = DateTime.Now.ToString(); #region 提货,订单明细修改 T_Inout_DetailBLL inoutDetailBll = new T_Inout_DetailBLL(CurrentUserInfo); VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo); if (pRequest.Parameters.OrderItemInfoList != null) { foreach (var item in pRequest.Parameters.OrderItemInfoList) { T_Inout_DetailEntity inoutDetailEntity = inoutDetailBll.QueryByEntity(new T_Inout_DetailEntity() { order_id = OrderID, sku_id = item.SkuId }, null).FirstOrDefault(); var vipAmountDetailEntity = vipAmountDetailBll.QueryByEntity(new VipAmountDetailEntity() { ObjectId = OrderID, AmountSourceId = "1" }, null).FirstOrDefault(); //将提货金额 + 余额 = SumPrice if (vipAmountDetailEntity != null) { item.SumPrice += Math.Abs(Convert.ToDecimal(vipAmountDetailEntity.Amount)); } inoutDetailEntity.enter_qty = item.EnterQty; inoutDetailEntity.Field9 = "kg"; inoutDetailEntity.enter_amount = item.SumPrice; inoutDetailEntity.enter_price = Convert.ToDecimal(Math.Round(item.SumPrice / item.EnterQty, 2)); entity.total_amount = entity.total_amount + Math.Round(Convert.ToDecimal(item.SumPrice / (entity.discount_rate / 100)), 2) - inoutDetailEntity.retail_amount; entity.total_retail = entity.total_amount; entity.actual_amount = entity.actual_amount + Math.Round(Convert.ToDecimal(item.SumPrice / (entity.discount_rate / 100)), 2) - inoutDetailEntity.retail_amount; inoutDetailBll.Update(inoutDetailEntity, tran); } } #endregion } entity.accpect_time = DateTime.Now.ToString(); _TInoutbll.Update(entity, tran); //用事物更新订单表(T_Inout) #endregion #region 2.根据订单ID更新订单日志表中数据 string CreateName = ""; if (pRequest.ChannelId != "2") { var UserData = UserBLL.GetByID(this.CurrentUserInfo.CurrentUser.User_Id); CreateName = string.Format("[操作人:{0}]", (UserData == null ? "" : UserData.user_name)); } else { CreateName = "[操作人:客户]"; } var _TInoutStatusEntity = new TInoutStatusEntity() { InoutStatusID = Guid.NewGuid(), OrderID = OrderID, //订单ID OrderStatus = Convert.ToInt32(ActionCode), //状态码 //StatusRemark = "订单状态从" + Updatebeforestatus + "变为" + GetStatusDesc(ActionCode) + "[操作人:" + CurrentUserInfo.CurrentUser.User_Name + "]", //状态更新描述 StatusRemark = "订单状态从" + Updatebeforestatus + "变为" + GetStatusDesc(ActionCode) + CreateName, //状态更新描述 CustomerID = CurrentUserInfo.ClientID //客户ID }; _TInoutStatusBLL.Create(_TInoutStatusEntity, tran); //用事物更新,向日志表(TInoutStatus)中插入一条数据 #endregion tran.Commit(); if (ActionCode == "600") { #region 处理订单发货发送微信模板消息 //获取会员信息 var vipBll = new VipBLL(CurrentUserInfo); var vipInfo = vipBll.GetByID(entity.vip_no); var inoutService = new Inout3Service(CurrentUserInfo); //物流公司 string LogisticsName = inoutService.GetCompanyName(entity.carrier_id); var InoutInfo = new InoutInfo() { order_no = entity.order_no, carrier_name = LogisticsName, vipId = entity.vip_no, Field2 = entity.Field2 }; // var CommonBLL = new CommonBLL(); // CommonBLL.SentShipMessage(InoutInfo, vipInfo.WeiXinUserId, InoutInfo.vip_no, CurrentUserInfo); new SendOrderSendMsgBLL().SentShipMessage(InoutInfo, vipInfo.WeiXinUserId, InoutInfo.vip_no, CurrentUserInfo); #endregion } } catch (Exception ex) { tran.Rollback(); throw new APIException(ex.Message) { ErrorCode = ERROR_ORDER_NOTEXISTS }; } } return(rd); }
/// <summary> /// 计算购卡分润 /// </summary> public void CalculateSalesVipCardOrderJob() { var numCount = 50; var customerIDs = CustomerBLL.Instance.GetCustomerList(); foreach (var customer in customerIDs) { string connString = customer.Value; var count = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrderLength(new CC_Order { CustomerID = customer.Key }); if (count.Code != ResponseCode.Success) { BaseService.WriteLog("从redis获取vipcard订单数据失败"); continue; } if (count.Result <= 0) { continue; } if (count.Result < numCount) { numCount = Convert.ToInt32(count.Result); } //DataTable dtAmountDetail = CreateTableAmountDetail(); //DataTable dtAmount = CreateTableAmount(); //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord(); for (var i = 0; i < numCount; i++) { var response = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrder(new CC_Order { CustomerID = customer.Key }); if (response.Code == ResponseCode.Success) { var orderInfo = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>(); var loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem"); T_InoutBLL inoutBLL = new T_InoutBLL(loggingSessionInfo); if (orderInfo != null) { VipBLL bllVip = new VipBLL(loggingSessionInfo); T_Inout_DetailBLL bllInoutDetail = new T_Inout_DetailBLL(loggingSessionInfo); T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo); VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo); VipAmountBLL bllVipAmount = new VipAmountBLL(loggingSessionInfo); VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo); T_SplitProfitRecordBLL bllSplitProfitRecord = new T_SplitProfitRecordBLL(loggingSessionInfo); VipAmountEntity entityVipAmount = new VipAmountEntity(); VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity(); T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity(); DataSet dsVipCardLevel = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID); var entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity() { order_id = orderInfo.order_id }, null).FirstOrDefault(); if (entityInoutDetail == null) { continue; } var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity() { SkuId = entityInoutDetail.sku_id, IsDelete = 0 }, null).FirstOrDefault(); if (vipCardType != null) { int intVipCardTypeID = Convert.ToInt32(vipCardType.ObjecetTypeId); var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity() { VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0 }, null).SingleOrDefault(); if (entityVipCardUpgradeRule != null) { VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo); var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity() { VipCardTypeID = intVipCardTypeID, IsDelete = 0 }, null); foreach (var ProfitRule in entityVipCardProfitRule) { if (ProfitRule.IsApplyAllUnits == 0) { VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo); var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity() { CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID }, null).SingleOrDefault(); if (vipCardProfitRuleUnitMapping == null) { continue; } } decimal amount = 0; string strAmountSourceId = string.Empty; string strVipId = string.Empty; string strUserType = string.Empty; if (ProfitRule.ProfitOwner == "Employee") { strAmountSourceId = "37"; strVipId = orderInfo.sales_user; strUserType = "User"; } if (ProfitRule.ProfitOwner == "Unit") { strAmountSourceId = "40"; strVipId = orderInfo.sales_unit_id; strUserType = "Unit"; } amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01; var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity() { ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId }, null); if (vipAmountDetail != null && vipAmountDetail.Length > 0) { continue; } if (amount > 0) { IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction(); try { // DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow(); // dr_SplitProfitRecord["Id"] = Guid.NewGuid(); // dr_SplitProfitRecord["SourceType"] = "Amount"; // dr_SplitProfitRecord["SourceId"] = strAmountSourceId; // dr_SplitProfitRecord["ObjectId"] = orderInfo.order_id; //dr_SplitProfitRecord["UserType"] = strUserType; // dr_SplitProfitRecord["UserId"] = orderInfo.sales_user; // dr_SplitProfitRecord["SplitAmount"] = amount; // dr_SplitProfitRecord["SplitSattus"] = "10"; // dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID; // dr_SplitProfitRecord["CreateTime"] = DateTime.Now; // dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID; // dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now; // dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID; // dr_SplitProfitRecord["IsDelete"] = 0; // dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord); // DataRow dr_AmountDetail = dtAmountDetail.NewRow(); // dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid(); //dr_AmountDetail["VipId"] = strVipId; // dr_AmountDetail["VipCardCode"] = ""; // dr_AmountDetail["UnitID"] = ""; // dr_AmountDetail["UnitName"] = ""; // dr_AmountDetail["SalesAmount"] = 0; // dr_AmountDetail["Amount"] = amount; // dr_AmountDetail["UsedReturnAmount"] = 0; // dr_AmountDetail["Reason"] = "首次售卡分润"; // dr_AmountDetail["EffectiveDate"] = DateTime.Now; // dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59"); // dr_AmountDetail["AmountSourceId"] = strAmountSourceId; // dr_AmountDetail["ObjectId"] = orderInfo.order_id; // dr_AmountDetail["Remark"] = "首次售卡分润"; // dr_AmountDetail["IsValid"] = 0; // dr_AmountDetail["IsWithdrawCash"] = 0; // dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID; // dr_AmountDetail["CreateTime"] = DateTime.Now; // dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID; // dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID; // dr_AmountDetail["LastUpdateTime"] = DateTime.Now; // dr_AmountDetail["IsDelete"] = 0; // //dr_AmountDetail["IsCalculated"] = 1; // dtAmountDetail.Rows.Add(dr_AmountDetail); entitySplitProfitRecord = new T_SplitProfitRecordEntity() { ID = Guid.NewGuid().ToString(), SourceType = "Amount", SourceId = strAmountSourceId, ObjectId = orderInfo.order_id, UserType = strUserType, UserId = orderInfo.sales_user, SplitAmount = amount, SplitSattus = "10", CustomerID = loggingSessionInfo.ClientID }; bllSplitProfitRecord.Create(entitySplitProfitRecord, tran); entityVipAmountDetail = new VipAmountDetailEntity { VipAmountDetailId = Guid.NewGuid(), VipId = strVipId, Amount = amount, UsedReturnAmount = 0, EffectiveDate = DateTime.Now, DeadlineDate = Convert.ToDateTime("9999-12-31 23:59:59"), AmountSourceId = strAmountSourceId, ObjectId = orderInfo.order_id, CustomerID = loggingSessionInfo.ClientID, Reason = "首次售卡分润", Remark = "首次售卡分润", IsWithdrawCash = 0 }; bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran); entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity() { VipId = orderInfo.sales_user, IsDelete = 0 }, null).SingleOrDefault(); if (entityVipAmount == null) { //DataRow dr_Amount = dtAmount.NewRow(); //dr_Amount["VipId"] = orderInfo.sales_user; //dr_Amount["VipCardCode"] = ""; //dr_Amount["BeginAmount"] = 0; //dr_Amount["InAmount"] = amount; //dr_Amount["OutAmount"] = 0; //dr_Amount["EndAmount"] = amount; //dr_Amount["TotalAmount"] = amount; //dr_Amount["BeginReturnAmount"] = 0; //dr_Amount["InReturnAmount"] = 0; //dr_Amount["OutReturnAmount"] = 0; //dr_Amount["ReturnAmount"] = 0; //dr_Amount["ImminentInvalidRAmount"] = 0; //dr_Amount["InvalidReturnAmount"] = 0; //dr_Amount["ValidReturnAmount"] = 0; //dr_Amount["TotalReturnAmount"] = 0; //dr_Amount["PayPassword"] = ""; //dr_Amount["IsLocking"] = 0; //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID; //dr_Amount["CreateTime"] = DateTime.Now; //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID; //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID; //dr_Amount["LastUpdateTime"] = DateTime.Now; //dr_Amount["IsDelete"] = 0; //dtAmount.Rows.Add(dr_Amount); entityVipAmount = new VipAmountEntity { VipId = strVipId, BeginAmount = 0, InAmount = amount, OutAmount = 0, EndAmount = amount, TotalAmount = amount, BeginReturnAmount = 0, InReturnAmount = 0, OutReturnAmount = 0, ReturnAmount = 0, ImminentInvalidRAmount = 0, InvalidReturnAmount = 0, ValidReturnAmount = 0, TotalReturnAmount = 0, IsLocking = 0, CustomerID = loggingSessionInfo.ClientID, VipCardCode = "" }; bllVipAmount.Create(entityVipAmount, tran); } else { entityVipAmount.InReturnAmount = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount; entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount; entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount; entityVipAmount.ReturnAmount = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount; bllVipAmount.Update(entityVipAmount); } tran.Commit(); } catch (Exception) { tran.Rollback(); throw; } } } } } } } } //if (dtAmount.Rows.Count > 0) //{ // Utils.SqlBulkCopy(connString, dtAmount, "VipAmount"); //} //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0) //{ // Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord"); // Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail"); //} } }
protected override GetOrderDetailRD ProcessRequest(DTO.Base.APIRequest <GetOrderDetailRP> pRequest) { GetOrderDetailRD rd = new GetOrderDetailRD(); string orderId = pRequest.Parameters.OrderId; rd.OrderListInfo = new OrderListInfo(); #region 获取订单列表 T_InoutBLL orderBll = new T_InoutBLL(this.CurrentUserInfo); var orderList = orderBll.QueryByEntity(new T_InoutEntity() { order_id = orderId }, null); #endregion #region 获取会员信息 string vipNo = orderList[0].vip_no; VipBLL vipBll = new VipBLL(this.CurrentUserInfo); var vipList = vipBll.QueryByEntity(new VipEntity() { VIPID = vipNo }, null); #endregion #region 获取配方式 //Bear 20160928 注释 更具商品信息获取对应配送 string deliveryId = orderList[0].Field8; DeliveryBLL deliverBll = new DeliveryBLL(this.CurrentUserInfo); var deliverList = deliverBll.QueryByEntity(new DeliveryEntity() { DeliveryId = deliveryId }, null); #endregion #region 获取门店信息 string storeId = orderList[0].sales_unit_id; if (!string.IsNullOrEmpty(orderList[0].purchase_unit_id))//如果有发货门店,则显示发货门店信息 { storeId = orderList[0].purchase_unit_id; } TInoutBLL tInoutBll = new TInoutBLL(this.CurrentUserInfo); //string storeName = tInoutBll.GetStoreName(storeId); DataSet storeDs = tInoutBll.GetStoreInfo(storeId); rd.OrderListInfo.StoreID = storeId; #endregion //配送商 string carrierId = orderList[0].carrier_id; //DataSet carrierDs = tInoutBll.GetStoreInfo(carrierId); //if (carrierDs.Tables[0].Rows.Count > 0) //{ // rd.OrderListInfo.CarrierID = carrierId; // rd.OrderListInfo.CarrierName = carrierDs.Tables[0].Rows[0]["unit_name"].ToString(); //} if (!string.IsNullOrEmpty(carrierId)) { //配送方式 1.送货到家;2.到店提货 if (deliveryId == "1") { var logisticsCompanyBLL = new T_LogisticsCompanyBLL(this.CurrentUserInfo); Guid m_carrierId = Guid.Parse(carrierId); var logCompInfo = logisticsCompanyBLL.GetByID(m_carrierId); if (logCompInfo != null) { rd.OrderListInfo.CarrierID = carrierId; rd.OrderListInfo.CarrierName = logCompInfo.LogisticsName; } } else if (deliveryId == "2") { var unitBLL = new t_unitBLL(this.CurrentUserInfo); var unitInfo = unitBLL.GetByID(carrierId); if (unitInfo != null) { rd.OrderListInfo.CarrierID = carrierId; rd.OrderListInfo.CarrierName = unitInfo.unit_name; } } else if (deliveryId == "4") { var unitBLL = new t_unitBLL(this.CurrentUserInfo); var unitInfo = unitBLL.GetByID(carrierId); if (unitInfo != null) { rd.OrderListInfo.CarrierID = carrierId; rd.OrderListInfo.CarrierName = unitInfo.unit_name; } } } rd.OrderListInfo.CourierNumber = orderList[0].Field2; //配送单号 rd.OrderListInfo.Invoice = orderList[0].Field19 == null ? "" : orderList[0].Field19; //发票信息 if (vipList.Count() > 0) { rd.OrderListInfo.VipID = vipList[0].VIPID; rd.OrderListInfo.Phone = vipList[0].Phone; rd.OrderListInfo.UserName = vipList[0].VipName; rd.OrderListInfo.VipRealName = vipList[0].VipRealName; rd.OrderListInfo.VipLevelDesc = vipList[0].VipLevelDesc; rd.OrderListInfo.VipCode = vipList[0].VipCode; rd.OrderListInfo.Email = vipList[0].Email; rd.OrderListInfo.VipLevel = Convert.ToInt32(vipList[0].VipLevel); } if (storeDs.Tables[0].Rows.Count > 0) { rd.OrderListInfo.StoreName = storeDs.Tables[0].Rows[0]["unit_name"].ToString(); rd.OrderListInfo.StoreAddress = storeDs.Tables[0].Rows[0]["unit_address"].ToString(); rd.OrderListInfo.StoreTel = storeDs.Tables[0].Rows[0]["unit_tel"].ToString(); } if (orderList.Count() > 0) { rd.OrderListInfo.discount_rate = orderList[0].discount_rate ?? 100;//订单折扣 rd.OrderListInfo.OrderID = orderList[0].order_id; rd.OrderListInfo.OrderCode = orderList[0].order_no; rd.OrderListInfo.OrderDate = orderList[0].order_date; rd.OrderListInfo.ReceiverName = orderList[0].Field14; //收件人 rd.OrderListInfo.TotalQty = Convert.ToDecimal(orderList[0].total_qty); string TotalAmount = String.Format("{0:F}", orderList[0].total_amount ?? 0); rd.OrderListInfo.TotalAmount = TotalAmount; rd.OrderListInfo.Total_Retail = Convert.ToDecimal(orderList[0].total_retail); rd.OrderListInfo.Remark = orderList[0].remark; rd.OrderListInfo.Status = orderList[0].status; rd.OrderListInfo.OrderStatus = int.Parse(orderList[0].Field7); rd.OrderListInfo.StatusDesc = orderList[0].status_desc; rd.OrderListInfo.DeliveryAddress = orderList[0].Field4; rd.OrderListInfo.DeliveryTime = orderList[0].Field9; rd.OrderListInfo.ClinchTime = orderList[0].create_time; rd.OrderListInfo.ReceiptTime = orderList[0].accpect_time; rd.OrderListInfo.CouponsPrompt = orderList[0].Field16; rd.OrderListInfo.DeliveryID = orderList[0].Field8; rd.OrderListInfo.IsPayment = orderList[0].Field1; rd.OrderListInfo.ReceivePoints = orderList[0].receive_points; rd.OrderListInfo.PaymentTime = orderList[0].Field1 == "1" ? orderList[0].complete_date : null; rd.OrderListInfo.OrderReasonTypeId = orderList[0].order_reason_id; rd.OrderListInfo.ActualDecimal = orderList[0].actual_amount ?? 0; rd.OrderListInfo.PaymentTypeCode = orderList[0].Payment_Type_Code; rd.OrderListInfo.PaymentTypeName = orderList[0].Payment_Type_Name; rd.OrderListInfo.ReserveTime = orderList[0].reserveDay + " " + orderList[0].reserveQuantum; var deliveryBll = new TOrderCustomerDeliveryStrategyMappingBLL(this.CurrentUserInfo); rd.OrderListInfo.DeliveryAmount = deliveryBll.GetDeliverAmount(orderId); //配送费 add by henry*** if (!string.IsNullOrEmpty(orderList[0].Field15) && orderList[0].Field15 != "0") //是否是团购商品 add by Henry 2014-12-22 { rd.OrderListInfo.IsEvent = 1; //团购商品 } else { rd.OrderListInfo.IsEvent = 0; //普通商品 } #region update by changjian.tian rd.OrderListInfo.Mobile = orderList[0].Field6; //配送联系电话 rd.OrderListInfo.DeliveryRemark = orderList[0].remark; rd.OrderListInfo.IsEvaluation = orderList[0].IsEvaluation == null ? 0 : orderList[0].IsEvaluation.Value;//评论 #endregion } if (deliverList.Count() > 0) { rd.OrderListInfo.DeliveryName = deliverList[0].DeliveryName; } T_Inout_DetailBLL orderDetailBll = new T_Inout_DetailBLL(this.CurrentUserInfo); //退换货Bll实例化 T_SalesReturnBLL salesReturnBll = new T_SalesReturnBLL(this.CurrentUserInfo); var orderDetailList = orderDetailBll.QueryByEntity(new T_Inout_DetailEntity() { order_id = orderId }, null); var inoutService = new InoutService(this.CurrentUserInfo); #region 根据订单ID获取订单明细 var ds = inoutService.GetOrderDetailByOrderId(orderId); #endregion #region 获取订单详细列表中的商品规格 var ggDs = inoutService.GetInoutDetailGgByOrderId(orderId); #endregion if (ds.Tables[0].Rows.Count > 0) { string ItemIdList = ds.Tables[0].AsEnumerable().Aggregate("", (x, j) => { x += string.Format("'{0}',", j["item_id"].ToString()); return(x); }).Trim(','); TInoutDetailBLL tInoutDetailBll = new TInoutDetailBLL(this.CurrentUserInfo); //获取商品的图片 DataSet imageDs = tInoutDetailBll.GetOrderDetailImageList(ItemIdList); var tmp = ds.Tables[0].AsEnumerable().Select(t => new OrderDetailEntity() { ItemID = t["item_id"].ToString(), ItemName = t["item_name"].ToString(), SkuID = t["sku_id"].ToString(), SalesReturnFlag = salesReturnBll.CheckSalesReturn(orderId, t["sku_id"].ToString()),//是否可申请退换货 //GG = t["prop_1_detail_name"].ToString()+t["prop_2_detail_name"].ToString()+t["prop_3_detail_name"].ToString() //+t["prop_4_detail_name"].ToString()+t["prop_5_detail_name"].ToString(), Field9 = t["Field9"].ToString(), isGB = Convert.ToInt32(t["isGB"]), GG = ggDs.Tables[0].AsEnumerable() .Where(tt => tt["sku_id"].ToString() == t["sku_id"].ToString()) .Select(tt => new GuiGeInfo { PropName1 = tt["prop_1_name"].ToString(), PropDetailName1 = tt["prop_1_detail_name"].ToString(), PropName2 = tt["prop_2_name"].ToString(), PropDetailName2 = tt["prop_2_detail_name"].ToString(), PropName3 = tt["prop_3_name"].ToString(), PropDetailName3 = tt["prop_3_detail_name"].ToString(), PropName4 = tt["prop_4_name"].ToString(), PropDetailName4 = tt["prop_4_detail_name"].ToString(), PropName5 = tt["prop_5_name"].ToString(), PropDetailName5 = tt["prop_5_detail_name"].ToString() }).FirstOrDefault(), SalesPrice = Convert.ToDecimal(t["enter_price"]), //DiscountRate = Convert.ToDecimal(t["discount_rate"]), DiscountRate = Convert.ToDecimal(t["order_discount_rate"]), ItemCategoryName = t["itemCategoryName"].ToString(), BeginDate = t["Field1"].ToString(), EndDate = t["Field2"].ToString(), DayCount = Convert.ToInt32(t["DayCount"]), Qty = Convert.ToDecimal(t["enter_qty"]), ImageInfo = imageDs.Tables[0].AsEnumerable() .Where(c => c["ObjectId"].ToString() == t["item_id"].ToString()) .OrderBy(c => c["displayIndex"]) .Select(c => new OrderDetailImage { ImageID = c["imageId"].ToString(), ImageUrl = ImagePathUtil.GetImagePathStr(c["imageUrl"].ToString(), "240") }).ToArray(), IfService = Convert.ToInt32(t["IfService"]) }); int tempCount = 0; foreach (var i in tmp) { if (i.IfService == 0) { tempCount++; } } if (tempCount == 0) { rd.OrderListInfo.IsAllService = 3; // 3-全部为虚拟商品 } else if (tempCount == tmp.Count()) { rd.OrderListInfo.IsAllService = 1; // 1-全部为实物商品 } else { rd.OrderListInfo.IsAllService = 2; // 2-包含实物商品和虚拟商品 } #region 根据商品获取配送方式 var deliveryIds = new List <int?>(); if (rd.OrderListInfo.IsAllService == 3) { deliveryIds.Add(1); deliveryIds.Add(2); deliveryIds.Add(4); rd.OrderListInfo.CanUseDeliveryIDs = deliveryIds; } else { T_Item_Delivery_MappingBLL mappingBll = new T_Item_Delivery_MappingBLL(this.CurrentUserInfo); var complexCondition = new List <IWhereCondition> { }; var itemIdArray = ItemIdList.Replace("'", "").Split(','); complexCondition.Add(new InCondition <string>() { FieldName = "Item_Id", Values = itemIdArray }); var itemDeliveryList = mappingBll.Query(complexCondition.ToArray(), null); bool needAddDelivery4 = false; bool needAddDelivery2 = false; if (itemDeliveryList.ToList().Find(d => d.DeliveryId == 4) != null) { needAddDelivery4 = true; } else { if (itemDeliveryList.ToList().Find(d => d.DeliveryId == 2) != null) { needAddDelivery2 = true; } } var itemDeliveryGroupList = itemDeliveryList.GroupBy(d => d.Item_Id); var index = 0; foreach (var info in itemDeliveryGroupList) { var tmpList = info.ToList <T_Item_Delivery_MappingEntity>(); //分组后的集合 if (index == 0) { deliveryIds.AddRange(tmpList.Select(d => d.DeliveryId)); index++; continue; } deliveryIds = deliveryIds.Intersect(tmpList.Select(d => d.DeliveryId)).ToList(); if (deliveryIds.Count <= 0) { break; // 后面的不用求了 } index++; } if (!deliveryIds.Contains(4) && needAddDelivery4) { deliveryIds.Add(4); } if (!deliveryIds.Contains(2) && needAddDelivery2) { deliveryIds.Add(2); } rd.OrderListInfo.CanUseDeliveryIDs = deliveryIds.OrderBy(t => t.Value).ToList(); } #endregion rd.OrderListInfo.OrderDetailInfo = tmp.ToArray(); } var vipIntegralDetailBll = new VipIntegralDetailBLL(this.CurrentUserInfo); // var integral = vipIntegralDetailBll.GetVipIntegralByOrder(orderId, pRequest.UserID); //使用积分 rd.OrderListInfo.OrderIntegral = Math.Abs(vipIntegralDetailBll.GetVipIntegralByOrder(orderId, vipNo)); //积分抵扣金额 add by Henry 2014-10-8 //decimal integralAmountPre = vipBll.GetIntegralAmountPre(this.CurrentUserInfo.ClientID);//获取积分金额比例 //rd.OrderListInfo.UseIntegralToAmount =rd.OrderListInfo.OrderIntegral*(integralAmountPre>0?integralAmountPre:0.01M); rd.OrderListInfo.UseIntegralToAmount = vipBll.GetAmountByIntegralPer(CurrentUserInfo.ClientID, rd.OrderListInfo.OrderIntegral); var couponUseBll = new CouponUseBLL(this.CurrentUserInfo); var couponParValue = couponUseBll.GetCouponParValue(orderId); rd.OrderListInfo.CouponAmount = couponParValue; var vipAmountDetailBll = new VipAmountDetailBLL(this.CurrentUserInfo); //使用的账户余额 rd.OrderListInfo.VipEndAmount = Math.Abs(vipAmountDetailBll.GetVipAmountByOrderId(orderId, vipNo, 1)); //使用余额,将余额从实付款中分开 if (rd.OrderListInfo.VipEndAmount != 0) { rd.OrderListInfo.ActualDecimal = rd.OrderListInfo.ActualDecimal - rd.OrderListInfo.VipEndAmount; } //使用的返现金额 rd.OrderListInfo.ReturnAmount = Math.Abs(vipAmountDetailBll.GetVipAmountByOrderId(orderId, vipNo, 13)); //使用阿拉币和阿拉币抵扣 add by Henry 2014-10-13 if (pRequest.ChannelId == "4")//阿拉丁APP调用 { decimal aldAmount = Math.Abs(vipAmountDetailBll.GetVipAmountByOrderId(orderId, vipNo, 11)); rd.OrderListInfo.ALDAmount = aldAmount; rd.OrderListInfo.ALDAmountMoney = aldAmount * 0.01M; } #region 获取订单积分,优惠券金额,使用余额 //var vipIntegralDetailBll = new VipIntegralDetailBLL(this.CurrentUserInfo); //var vipIntegralList = vipIntegralDetailBll.QueryByEntity(new VipIntegralDetailEntity() //{ // VIPID = pRequest.UserID, // ObjectId = orderId //}, null); //if (vipIntegralList != null && vipIntegralList.Length > 0) //{ // rd.OrderListInfo.OrderIntegral = Math.Abs(vipIntegralList[0].Integral??0); //} //var tOrderCouponMappingBll = new TOrderCouponMappingBLL(this.CurrentUserInfo); //var tOrderCouponMappingList = tOrderCouponMappingBll.QueryByEntity(new TOrderCouponMappingEntity() //{ // OrderId = orderId //}, null); //if (tOrderCouponMappingList != null && tOrderCouponMappingList.Length > 0) //{ // var couponId = tOrderCouponMappingList[0].CouponId; // var couponBll = new CouponBLL(this.CurrentUserInfo); // var couponEntity = couponBll.GetByID(couponId); // if (couponEntity != null) // { // var couponTypeId = couponEntity.CouponTypeID; // var couponTypeBll = new CouponTypeBLL(this.CurrentUserInfo); // var couponTypeEntity = couponTypeBll.GetByID(couponTypeId); // if (couponTypeEntity != null) // { // rd.OrderListInfo.CouponAmount = couponTypeEntity.ParValue ?? 0; // } // } //} //var vipAmountDetailBll = new VipAmountDetailBLL(this.CurrentUserInfo); //var vipAmountDetailList = vipAmountDetailBll.QueryByEntity(new VipAmountDetailEntity() //{ // VipId = pRequest.UserID, // ObjectId = orderId //}, null); //if (vipAmountDetailList != null && vipAmountDetailList.Length > 0) //{ // rd.OrderListInfo.VipEndAmount = Math.Abs(vipAmountDetailList[0].Amount ?? 0); //} #endregion return(rd); }