/// <summary> /// 查询 /// </summary> public string GetVipLevelListData() { string content = string.Empty; SysVipCardGradeBLL service = new SysVipCardGradeBLL(CurrentUserInfo); var listObj = service.QueryByEntity(new SysVipCardGradeEntity { CustomerID = CurrentUserInfo.CurrentUser.customer_id }, null); if (listObj != null && listObj.Length > 0) { foreach (SysVipCardGradeEntity info in listObj) { info.VipLevelCount = service.GetVipLevelCount(Convert.ToString(info.VipCardGradeID)); } } var jsonData = new JsonData(); jsonData.totalCount = listObj.Length.ToString(); jsonData.data = listObj; content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}", jsonData.data.ToJSON(), jsonData.totalCount); return(content); }
/// <summary> /// 新闻类型 /// </summary> public string GetVipCardGradeData() { var server = new SysVipCardGradeBLL(new SessionManager().CurrentUserLoginInfo); var vipCardGradeArray = server.Query(null, null); string content = string.Empty; var jsonData = new JsonData(); jsonData.totalCount = vipCardGradeArray.Length.ToString(); jsonData.data = vipCardGradeArray; content = jsonData.ToJSON(); return(content); }
/// <summary> /// /// </summary> public string GetVipLevelData() { var billService = new SysVipCardGradeBLL(new SessionManager().CurrentUserLoginInfo); //IList<BillStatusModel> list = new List<BillStatusModel>(); //list.Add(new BillStatusModel() { Id = "1", Description = "基本" }); //list.Add(new BillStatusModel() { Id = "2", Description = "高级" }); var list = billService.QueryByEntity(new SysVipCardGradeEntity() { CustomerID = CurrentUserInfo.CurrentUser.customer_id }, null); string content = string.Empty; var jsonData = new JsonData(); jsonData.totalCount = list.Length.ToString(); jsonData.data = list; content = jsonData.ToJSON(); return(content); }
protected override SetReceiveAmountOrderRD ProcessRequest(APIRequest <SetReceiveAmountOrderRP> pRequest) { SetReceiveAmountOrderRP rp = pRequest.Parameters; SetReceiveAmountOrderRD rd = new SetReceiveAmountOrderRD(); var receiveAmountOrderBll = new ReceiveAmountOrderBLL(CurrentUserInfo); var sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo); //获取折扣表 var vipBLL = new VipBLL(CurrentUserInfo); var unitBLL = new t_unitBLL(CurrentUserInfo); var vipInfo = vipBLL.GetByID(pRequest.UserID); //获取会员信息 if (vipInfo == null) { throw new APIException("没有会员信息") { ErrorCode = 101 }; } var unitInfo = unitBLL.GetByID(rp.UnitId); if (unitInfo == null) { throw new APIException("没有服务门店信息") { ErrorCode = 101 }; } decimal discountAmount = 0; //抵扣金额汇总 decimal couponAmount = 0; //优惠券抵用金额 decimal endAmount = rp.VipEndAmount; //余额 decimal integralAmount = rp.Integral; //获取订单号 TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(CurrentUserInfo); string orderNo = serviceUnitExpand.GetUnitOrderNo(); //折扣 decimal discount = 1; if (rp.VipDiscount > 0) { discount = sysVipCardGradeBLL.GetVipDiscount() / 10;//会员折扣 } decimal tempAmount = Math.Round((discount == 0 ? 1 : discount) * rp.TotalAmount, 2, MidpointRounding.AwayFromZero); Guid orderId = Guid.NewGuid(); //积分处理 if (rp.IntegralFlag == 1) { //加入折扣金额 discountAmount = discountAmount + rp.IntegralAmount; } else { integralAmount = 0; } //使用优惠券 if (rp.CouponFlag == 1) { #region 判断优惠券是否是该会员的 var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo); var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity() { VIPID = vipInfo.VIPID, CouponID = rp.CouponId }, null); if (vipcouponmappingList == null || vipcouponmappingList.Length == 0) { throw new APIException("此张优惠券不是该会员的") { ErrorCode = 103 }; } #endregion #region 判断优惠券是否有效 var couponBll = new CouponBLL(CurrentUserInfo); var couponEntity = couponBll.GetByID(rp.CouponId); if (couponEntity == null) { throw new APIException("无效的优惠券") { ErrorCode = 103 }; } if (couponEntity.Status == 1) { throw new APIException("优惠券已使用") { ErrorCode = 103 }; } if (couponEntity.EndDate < DateTime.Now) { throw new APIException("优惠券已过期") { ErrorCode = 103 }; } var couponTypeBll = new CouponTypeBLL(CurrentUserInfo); var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID); if (couponTypeEntity == null) { throw new APIException("无效的优惠券类型") { ErrorCode = 103 }; } #endregion discountAmount = discountAmount + couponTypeEntity.ParValue ?? 0; couponAmount = couponTypeEntity.ParValue ?? 0; //更新使用记录 var couponUseBll = new CouponUseBLL(CurrentUserInfo); var couponUseEntity = new CouponUseEntity() { CouponUseID = Guid.NewGuid(), CouponID = rp.CouponId, VipID = vipInfo.VIPID, UnitID = rp.UnitId, OrderID = orderId.ToString(), Comment = "商城使用电子券", CustomerID = CurrentUserInfo.ClientID, CreateBy = CurrentUserInfo.UserID, CreateTime = DateTime.Now, LastUpdateBy = CurrentUserInfo.UserID, LastUpdateTime = DateTime.Now, IsDelete = 0 }; couponUseBll.Create(couponUseEntity); //更新CouponType数量 var conponTypeBll = new CouponTypeBLL(CurrentUserInfo); var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault(); conponTypeEntity.IsVoucher += 1; conponTypeBll.Update(conponTypeEntity); //停用该优惠券 couponEntity.Status = 1; couponBll.Update(couponEntity); } //使用余额 if (rp.VipEndAmountFlag == 1) { var vipAmountBll = new VipAmountBLL(CurrentUserInfo); var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo); var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity() { VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode }, null).FirstOrDefault(); if (vipAmountEntity != null) { //判断该会员账户是否被冻结 if (vipAmountEntity.IsLocking == 1) { throw new APIException("账户已被冻结,请先解冻") { ErrorCode = 103 } } ; //判断该会员的账户余额是否大于本次使用的余额 if (vipAmountEntity.EndAmount < rp.VipEndAmount) { throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount)) { ErrorCode = 103 } } ; //所剩余额大于商品价格,扣除余额的数量为商品价格 if (tempAmount < rp.VipEndAmount) { rp.VipEndAmount = endAmount = Convert.ToDecimal(tempAmount); } } } //不使用余额,余额为0 else { endAmount = 0; } //实付金额 decimal transAmount = tempAmount - discountAmount; //支付状态 string payStatus = "0"; //支付时间 DateTime?PayDatetTime = null; //实付金额全是由余额支付,支付状态和支付时间全部更新,积分扣减、余额扣减、优惠券使用 if (transAmount == endAmount || transAmount == 0) { payStatus = "10"; PayDatetTime = DateTime.Now; //处理积分抵扣 if (rp.IntegralFlag == 1) { var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo); string sourceId = "20"; //积分抵扣 var IntegralDetail = new VipIntegralDetailEntity() { Integral = -Convert.ToInt32(rp.Integral), IntegralSourceID = sourceId, ObjectId = orderId.ToString() }; if (IntegralDetail.Integral != 0) { //变动前积分 string OldIntegral = (vipInfo.Integration ?? 0).ToString(); //变动积分 string ChangeIntegral = (IntegralDetail.Integral ?? 0).ToString(); var vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo); //发送微信积分变动通知模板消息 if (!string.IsNullOrWhiteSpace(vipIntegralDetailId)) { var CommonBLL = new CommonBLL(); CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo); } } } //处理余额抵扣 if (rp.VipEndAmountFlag == 1) { var vipAmountBll = new VipAmountBLL(CurrentUserInfo); var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo); var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity() { VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode }, null).FirstOrDefault(); if (vipAmountEntity != null) { var detailInfo = new VipAmountDetailEntity() { Amount = -rp.VipEndAmount, AmountSourceId = "1", ObjectId = orderId.ToString() }; var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo); if (!string.IsNullOrWhiteSpace(vipAmountDetailId)) {//发送微信账户余额变动模板消息 var CommonBLL = new CommonBLL(); CommonBLL.BalanceChangedMessage(orderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo); } } } } //收款订单 ReceiveAmountOrderEntity receiveAmountOrderEntity = new ReceiveAmountOrderEntity() { OrderId = orderId, OrderNo = orderNo, VipId = vipInfo.VIPID, ServiceUnitId = unitInfo.unit_id, ServiceUserId = rp.EmployeeID, TotalAmount = rp.TotalAmount, VipDiscount = discount * 100, TransAmount = transAmount, PayPoints = integralAmount, AmountFromPayPoints = rp.IntegralAmount, CouponUsePay = couponAmount, AmountAcctPay = endAmount, PayStatus = payStatus, TimeStamp = rp.TimeStamp, PayDatetTime = PayDatetTime, CustomerId = CurrentUserInfo.ClientID }; receiveAmountOrderBll.Create(receiveAmountOrderEntity); //订单奖励 if (transAmount == endAmount || transAmount == 0) { var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo); vipIntegralBll.OrderReward(receiveAmountOrderEntity, null); } rd.orderId = orderId.ToString(); return(rd); } } }
public HttpResponseMessage MemberBenefits(string vipId, decimal?TotalPayAmount) { string guid = Guid.NewGuid().ToString(); Loggers.Debug(new DebugLogInfo() { Message = $"调用[api/Vip/MemberBenefits],参数:\"vipId:{vipId}\"", UserID = vipId, ClientID = guid }); try { if (string.IsNullOrEmpty(vipId)) { throw new Exception("会员数据不能为空!"); } var orderResponse = new MemberBenefitsResponeModel(); #region MyRegion string customerid = ConfigurationManager.AppSettings["CustomerId"].Trim(); var loggingSessionInfo = Default.GetLoggingSession(customerid, vipId); loggingSessionInfo.Conn = ConfigurationManager.AppSettings["Conn"].Trim(); var bll = new VipBLL(loggingSessionInfo); var vipInfo = bll.GetByID(vipId); //会员信息 if (vipInfo == null) { throw new APIException("没有该会员信息") { ErrorCode = 302 }; } #endregion //获取社会化销售配置和积分返现配置 var basicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo); Hashtable htSetting = basicSettingBll.GetSocialSetting(); orderResponse.EnableIntegral = int.Parse(htSetting["enableIntegral"].ToString()); orderResponse.EnableRewardCash = int.Parse(htSetting["enableRewardCash"].ToString()); //应付金额 decimal?totalPayAmount = 0; if (TotalPayAmount != null) { totalPayAmount = TotalPayAmount; } #region 启用积分 if (orderResponse.EnableIntegral == 1) { //2.获取会员的积分和账户余额 var vipIntegralbll = new VipIntegralBLL(loggingSessionInfo); //var vipIntegralEntity = vipIntegralbll.GetByID(rp.UserID); //根据会员和会员卡号获取积分 var vipIntegralEntity = vipIntegralbll.QueryByEntity( new VipIntegralEntity() { VipID = vipInfo.UserId, VipCardCode = vipInfo.VipCode }, null) .FirstOrDefault(); if (vipIntegralEntity == null) { orderResponse.Integral = 0; orderResponse.IntegralAmount = 0; } else { decimal validIntegral = vipIntegralEntity.ValidIntegral ?? 0; //会员积分 int totalIntegral = 0; //可使用积分(取整) //if (int.Parse(htSetting["rewardsType"].ToString()) == 1)//按商品奖励 // totalIntegral = (int)Math.Round(bll.GetIntegralBySkuId(skuIdList), 1); //积分使用上限比例 decimal pointsRedeemUpLimit = decimal.Parse(htSetting["pointsRedeemUpLimit"].ToString()) / 100; //3.获取积分与金额的兑换比例 var integralAmountPre = bll.GetIntegralAmountPre(customerid); if (integralAmountPre == 0) { integralAmountPre = (decimal)0.01; } totalIntegral = (int)Math.Round(totalPayAmount.Value * pointsRedeemUpLimit * integralAmountPre, 1); //可使用的积分 orderResponse.Integral = validIntegral > totalIntegral ? totalIntegral : validIntegral; if (totalPayAmount == 0) { orderResponse.Integral = Convert.ToDecimal(vipIntegralEntity.ValidIntegral); } //rd.IntegralAmount = rd.Integral * integralAmountPre; orderResponse.IntegralAmount = bll.GetAmountByIntegralPer(loggingSessionInfo.ClientID, orderResponse.Integral); orderResponse.IntegralDesc = "使用积分" + orderResponse.Integral.ToString("0") + ",可兑换" + orderResponse.IntegralAmount.ToString("0.00") + "元"; orderResponse.PointsRedeemLowestLimit = int.Parse(htSetting["pointsRedeemLowestLimit"].ToString()); } } #endregion //根据会员和会员卡号获取余额和返现 var vipAmountBll = new VipAmountBLL(loggingSessionInfo); var vipAmountInfo = vipAmountBll.QueryByEntity( new VipAmountEntity() { VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode }, null) .FirstOrDefault(); #region 启用返现 if (orderResponse.EnableRewardCash == 1) { if (vipAmountInfo != null) { //累计返现金额 decimal returnAmount = vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value; //订单可使用最大返现金额 decimal returnAmountOrder = totalPayAmount.Value * (decimal.Parse(htSetting["cashRedeemUpLimit"].ToString()) / 100); orderResponse.ReturnAmount = returnAmount > returnAmountOrder ? returnAmountOrder : returnAmount; orderResponse.CashRedeemLowestLimit = decimal.Parse(htSetting["cashRedeemLowestLimit"].ToString()); } } #endregion //账户余额 //var vipEndAmount = bll.GetVipEndAmount(rp.UserID); //rd.VipEndAmount = totalPayAmount > vipEndAmount ? vipEndAmount : totalPayAmount; if (vipAmountInfo != null) { orderResponse.VipEndAmount = vipAmountInfo.EndAmount.Value; } //获取会员折扣 var sysVipCardGradeBLL = new SysVipCardGradeBLL(loggingSessionInfo); decimal vipDiscount = 10; //会员折扣 //如果订单业务类型为null var orderReason = GetOrderReason(EnumOrderReason.Pos); //超级分销、团购、抢购、砍价商品没有会员折扣 if (orderReason != "CB43DD7DD1C94853BE98C4396738E00C" && orderReason != "671E724C85B847BDA1E96E0E5A62055A" && orderReason != "096419BFDF394F7FABFE0DFCA909537F") { //if (rp.Parameters.DiscountType == 0) vipDiscount = sysVipCardGradeBLL.GetVipDiscount(); } orderResponse.VipDiscount = vipDiscount; var tempAmount = totalPayAmount.Value; if (totalPayAmount.Value > 0 && vipDiscount > 0) { tempAmount = totalPayAmount.Value * (vipDiscount / 10); } var ds = bll.GetVipCouponDataSet(vipInfo.VIPID, tempAmount, 2, string.Empty, 1, customerid); if (ds.Tables[0].Rows.Count > 0) { var temp = ds.Tables[0].AsEnumerable().Select(t => new CouponModel() { CouponId = t["CouponID"].ToString(), CouponCode = t["CouponCode"].ToString(), CouponAmount = Convert.ToDecimal(t["parValue"]), CouponName = t["CoupnName"].ToString(), CouponDesc = t["CouponDesc"].ToString(), DisplayIndex = Convert.ToInt32(t["displayIndex"]), EnableFlag = Convert.ToInt32(t["EnableFlag"]), //ValidDateDesc = t["ValidDateDesc"].ToString(), StartDate = t["BeginDate"].ToString(), EndDate = t["EndDate"].ToString() }); orderResponse.CouponInfoList = temp.ToList(); } orderResponse.IsSucess = true; var json = new JavaScriptSerializer().Serialize(orderResponse); Loggers.Debug(new DebugLogInfo() { Message = $"调用[api/Vip/MemberBenefits],返回参数:\"{json}\"", UserID = vipId, ClientID = guid }); return(Request.CreateResponse(HttpStatusCode.OK, orderResponse)); } catch (Exception ex) { var orderResponse = new MemberBenefitsResponeModel() { IsSucess = false, ErrorMessage = ex.Message }; Loggers.Debug(new DebugLogInfo() { Message = $"[api/Vip/MemberBenefits]错误,参数:\"ErrorMsg:{ex.Message}\"", UserID = vipId, ClientID = guid }); return(Request.CreateResponse(HttpStatusCode.InternalServerError, orderResponse)); } }
//<summary> //Pos订单入库 //</summary> //<param name="pRequest"></param> //<returns></returns> protected override SetPosOrderRD ProcessRequest(APIRequest <SetPosOrderRP> pRequest) { //请求参数 var rp = pRequest.Parameters; //返回参数 var rd = new SetPosOrderRD(); //订单 var inoutBll = new T_InoutBLL(CurrentUserInfo); var inoutDetail = new T_Inout_DetailBLL(CurrentUserInfo); //商品 var itemCategoryBll = new T_Item_CategoryBLL(CurrentUserInfo); var itemBll = new T_ItemBLL(CurrentUserInfo); var porpBll = new T_PropBLL(CurrentUserInfo); var itemSkuPropBll = new T_ItemSkuPropBLL(CurrentUserInfo); var skuBll = new T_SkuBLL(CurrentUserInfo); var skuPriceBll = new T_Sku_PriceBLL(CurrentUserInfo); var skuProperty = new T_Sku_PropertyBLL(CurrentUserInfo); //获取会员信息 var vipBll = new VipBLL(CurrentUserInfo); var vipInfo = vipBll.GetByID(pRequest.UserID); var vipCardVipMappingBll = new VipCardVipMappingBLL(CurrentUserInfo); var vipCardBll = new VipCardBLL(CurrentUserInfo); var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity() { VIPID = vipInfo.VIPID, CustomerID = CurrentUserInfo.ClientID }, null).FirstOrDefault(); string VipCardTypeID = ""; //卡类型Id if (vipCardVipMappingEntity != null) { var vipCardEntity = vipCardBll.GetByID(vipCardVipMappingEntity.VipCardID); VipCardTypeID = vipCardEntity.VipCardTypeID.ToString(); } //员工 var userBll = new T_UserBLL(CurrentUserInfo); //获取门店信息 var unitBll = new t_unitBLL(CurrentUserInfo); t_unitEntity unitInfo = null; if (!string.IsNullOrEmpty(rp.UnitCode)) { unitInfo = unitBll.QueryByEntity(new t_unitEntity() { unit_code = rp.UnitCode, customer_id = CurrentUserInfo.ClientID }, null).FirstOrDefault(); if (unitInfo == null) { throw new APIException("请在正念商户后台录入相应门店") { ErrorCode = 100 }; } } else { throw new APIException("缺少请求参数:门店编码") { ErrorCode = 102 }; } //获取员工信息 T_UserEntity userEntity = null; if (!string.IsNullOrEmpty(rp.MobliePhone)) { userEntity = userBll.QueryByEntity(new T_UserEntity() { user_telephone = rp.MobliePhone, customer_id = CurrentUserInfo.ClientID }, null).FirstOrDefault(); //没有员工,新增默认员工(店员APP) if (userEntity == null) { var roleBll = new T_RoleBLL(CurrentUserInfo); var roleEntity = roleBll.QueryByEntity(new T_RoleEntity() { role_code = "clerkAPP", customer_id = CurrentUserInfo.ClientID }, null).FirstOrDefault(); if (roleEntity == null) { throw new APIException("请在正念商户后台录入相应角色") { ErrorCode = 100 }; } userEntity = new T_UserEntity(); userEntity.user_telephone = rp.MobliePhone; userEntity.user_code = rp.UserCode; userEntity.user_name = rp.UserCode; userEntity.user_birthday = rp.Birthday; userEntity.user_email = rp.EmailAddress; userEntity.user_address = rp.Address; userEntity.user_postcode = rp.Zip; userBll.AddUser(ref userEntity, unitInfo, roleEntity); } } else { throw new APIException("缺少请求参数:员工手机号") { ErrorCode = 102 }; } //获取会员折扣 var sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo); decimal vipDiscount = sysVipCardGradeBLL.GetVipDiscount() * 10; //订单号 string orderId = BaseService.NewGuidPub(); T_InoutEntity tInoutEntity = new T_InoutEntity(); tInoutEntity.order_id = orderId; tInoutEntity.order_no = rp.OrderNo; //拼接ItemCodes //StringBuilder ItemCodes = new StringBuilder(); //for (int j = 0; j < pRequest.Parameters.OrderDetailList.Count(); j++) //{ // if (j != 0) // { // ItemCodes.Append(","); // } // ItemCodes.Append(string.Format("{0}", pRequest.Parameters.OrderDetailList[j].ItemCode)); //} ////通过itemCodes取出商品价格 //SkuPriceService skuPriceService = new SkuPriceService(CurrentUserInfo); //List<SkuPrice> skuPriceList = skuPriceService.GetPriceListByItemCodes(ItemCodes.ToString(), CurrentUserInfo.ClientID); //if(skuPriceList.Count == 0) //{ // throw new APIException("未找到商品") { ErrorCode = 100 }; //} //订单总金额 decimal totalAmount = rp.TotalAmount; //订单实付金额 decimal ActualAmount = rp.DiscountAmount; //订单折扣后金额 decimal DiscountAmount = rp.DiscountAmount; //订单明细显示顺序 int i = 1; //商品价格重新计算 foreach (var item in pRequest.Parameters.OrderDetailList) { T_ItemEntity itemEntity = null; //商品 T_SkuEntity skuEntity = null; //sku if (!string.IsNullOrEmpty(item.ItemCode)) { itemEntity = itemBll.QueryByEntity(new T_ItemEntity() { item_code = item.ItemCode, CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault(); if (itemEntity == null) { if (string.IsNullOrEmpty(item.ItemCategoryCode)) { throw new APIException("缺少参数:商品类别名称") { ErrorCode = 200 }; } itemEntity = new T_ItemEntity(); itemEntity.item_code = item.ItemCode; itemEntity.item_name = item.ItemName; itemBll.AddItem(itemEntity, out skuEntity, item.ItemCategoryName, item.ItemCategoryCode, item.SkuOriginPrice, item.SkuSalesPrice); } else { skuEntity = skuBll.QueryByEntity(new T_SkuEntity() { item_id = itemEntity.item_id }, null).FirstOrDefault(); } } else { throw new APIException("缺少参数:商品编码") { ErrorCode = 300 }; } //订单明细相关处理 T_Inout_DetailBLL inoutDetailBll = new T_Inout_DetailBLL(CurrentUserInfo); T_Inout_DetailEntity inoutDetailEntity = new T_Inout_DetailEntity() { order_detail_id = BaseService.NewGuidPub(), order_id = orderId, //订单Id sku_id = skuEntity.sku_id, //skuId unit_id = unitInfo.unit_id, //门店Id order_qty = item.Qty, //订单qty enter_qty = item.Qty, //实际qty enter_price = item.price, //折扣价 enter_amount = item.price * item.Qty, //折扣价 std_price = item.price, //原价 discount_rate = vipDiscount, //折扣 retail_price = item.price * item.Qty, //零售价 retail_amount = item.price * item.Qty, //零售价 order_detail_status = "1", display_index = i, if_flag = 0 }; inoutDetailBll.Create(inoutDetailEntity); i++; } //优惠券使用 if (!string.IsNullOrEmpty(rp.CouponId)) { #region 判断优惠券是否是该会员的 var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo); var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity() { VIPID = pRequest.UserID, CouponID = rp.CouponId }, null); if (vipcouponmappingList == null || vipcouponmappingList.Length == 0) { throw new APIException("此张优惠券不是该会员的") { ErrorCode = 103 }; } #endregion #region 判断优惠券是否有效 var couponBll = new CouponBLL(CurrentUserInfo); var couponEntity = couponBll.GetByID(rp.CouponId); if (couponEntity == null) { throw new APIException("无效的优惠券") { ErrorCode = 103 }; } if (couponEntity.Status == 1) { throw new APIException("优惠券已使用") { ErrorCode = 103 }; } if (couponEntity.EndDate < DateTime.Now) { throw new APIException("优惠券已过期") { ErrorCode = 103 }; } var couponTypeBll = new CouponTypeBLL(CurrentUserInfo); var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID); if (couponTypeEntity == null) { throw new APIException("无效的优惠券类型") { ErrorCode = 103 }; } #endregion #region 优惠券核销 var couponUseBll = new CouponUseBLL(CurrentUserInfo); var couponUseEntity = new CouponUseEntity() { CouponUseID = Guid.NewGuid(), CouponID = rp.CouponId, VipID = pRequest.UserID, UnitID = unitInfo.unit_id, OrderID = orderId, Comment = "商城使用电子券", CustomerID = pRequest.CustomerID, CreateBy = pRequest.UserID, CreateTime = DateTime.Now, LastUpdateBy = pRequest.UserID, LastUpdateTime = DateTime.Now, IsDelete = 0 }; couponUseBll.Create(couponUseEntity); #endregion #region 更新CouponType数量 var conponTypeBll = new CouponTypeBLL(CurrentUserInfo); var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = pRequest.CustomerID }, null).FirstOrDefault(); conponTypeEntity.IsVoucher += 1; conponTypeBll.Update(conponTypeEntity); #endregion #region 更新优惠券状态 couponEntity.Status = 1; couponBll.Update(couponEntity); #endregion ActualAmount -= couponTypeEntity.ParValue ?? 0; } #region 使用积分 //使用积分 if (rp.IntegralFlag == 1) { var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo); string sourceId = "20"; //积分抵扣 var IntegralDetail = new VipIntegralDetailEntity() { Integral = -Convert.ToInt32(rp.Integral), IntegralSourceID = sourceId, ObjectId = orderId }; if (IntegralDetail.Integral != 0) { //变动前积分 string OldIntegral = (vipInfo.Integration ?? 0).ToString(); //变动积分 string ChangeIntegral = (IntegralDetail.Integral ?? 0).ToString(); var vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo); //发送微信积分变动通知模板消息 if (!string.IsNullOrWhiteSpace(vipIntegralDetailId)) { var CommonBLL = new CommonBLL(); CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo); } } tInoutEntity.pay_points = rp.Integral; tInoutEntity.receive_points = rp.Integral; ActualAmount -= rp.IntegralAmount; } #endregion #region 余额和返现修改 var vipAmountBll = new VipAmountBLL(CurrentUserInfo); var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo); var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity() { VipId = pRequest.UserID, VipCardCode = vipInfo.VipCode }, null).FirstOrDefault(); if (vipAmountEntity != null) { //判断该会员账户是否被冻结 if (vipAmountEntity.IsLocking == 1) { throw new APIException("账户已被冻结,请先解冻") { ErrorCode = 103 } } ; //判断该会员的账户余额是否大于本次使用的余额 if (vipAmountEntity.EndAmount < rp.EndAmount) { throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount)) { ErrorCode = 103 } } ; } //使用余额 if (rp.EndAmountFlag == 1) { var detailInfo = new VipAmountDetailEntity() { Amount = -rp.EndAmount, AmountSourceId = "1", ObjectId = orderId }; var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo); if (!string.IsNullOrWhiteSpace(vipAmountDetailId)) {//发送微信账户余额变动模板消息 var CommonBLL = new CommonBLL(); CommonBLL.BalanceChangedMessage(tInoutEntity.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo); } tInoutEntity.Field3 = rp.EndAmount.ToString(); } #endregion //订单主表更新 tInoutEntity.VipCardCode = vipInfo.VipCardCode;//会员卡号 tInoutEntity.order_reason_id = "2F6891A2194A4BBAB6F17B4C99A6C6F5"; tInoutEntity.order_type_id = "1F0A100C42484454BAEA211D4C14B80F"; tInoutEntity.warehouse_id = "67bb4c12785c42d4912aff7d34606592"; tInoutEntity.data_from_id = ""; tInoutEntity.red_flag = "1"; tInoutEntity.order_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //订单时间 tInoutEntity.create_unit_id = unitInfo.unit_id; //门店 tInoutEntity.unit_id = unitInfo.unit_id; //门店 tInoutEntity.sales_unit_id = unitInfo.unit_id; //门店 tInoutEntity.purchase_unit_id = unitInfo.unit_id; tInoutEntity.sales_user = userEntity.user_id; tInoutEntity.total_amount = totalAmount; //订单金额 tInoutEntity.discount_rate = vipDiscount; //会员折扣 tInoutEntity.actual_amount = ActualAmount; //实付金额 tInoutEntity.total_qty = rp.qty; tInoutEntity.total_retail = totalAmount; //订单金额 tInoutEntity.vip_no = vipInfo.VIPID; tInoutEntity.Field6 = vipInfo.Phone; tInoutEntity.Field14 = vipInfo.VipName; tInoutEntity.Field17 = VipCardTypeID; tInoutEntity.Field12 = DiscountAmount.ToString(); tInoutEntity.Field11 = "知行易"; tInoutEntity.customer_id = CurrentUserInfo.ClientID; tInoutEntity.Field1 = "1"; //支付完成 tInoutEntity.Field7 = "700"; //已完成 tInoutEntity.status = "700"; //已完成 tInoutEntity.status_desc = "已完成"; tInoutEntity.Field10 = "已完成"; rd.Amount = ActualAmount - rp.EndAmount; inoutBll.Create(tInoutEntity); //订单奖励 new SendOrderRewardMsgBLL().OrderReward(tInoutEntity, this.CurrentUserInfo, null);//存入到缓存 rd.orderId = orderId; return(rd); } } }