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); } } }
protected override SetRechargeOrderRD ProcessRequest(APIRequest <SetRechargeOrderRP> pRequest) { SetRechargeOrderRP rp = pRequest.Parameters; SetRechargeOrderRD rd = new SetRechargeOrderRD(); var rechargeOrderBll = new RechargeOrderBLL(CurrentUserInfo); TUnitExpandBLL serviceUnitExpandBll = new TUnitExpandBLL(CurrentUserInfo); var vipBll = new VipBLL(CurrentUserInfo); var vipCardVipMappingBll = new VipCardVipMappingBLL(CurrentUserInfo); var vipCardBll = new VipCardBLL(CurrentUserInfo); var sysVipCardTypeBll = new SysVipCardTypeBLL(CurrentUserInfo); var vipCardUpgradeRuleBll = new VipCardUpgradeRuleBLL(CurrentUserInfo); //获取会员信息 VipEntity vipInfo; string userId = ""; //微信 if (pRequest.ChannelId == "2") { vipInfo = vipBll.GetByID(pRequest.UserID); UnitService unitServer = new UnitService(CurrentUserInfo); rp.UnitId = unitServer.GetUnitByUnitTypeForWX("OnlineShopping", null).Id; //获取在线商城的门店标识 } //掌柜App else { vipInfo = vipBll.GetByID(rp.VipId); userId = pRequest.UserID; } string OrderDesc = "ReRecharge"; //"升级","充值" int? VipCardTypeId = null; //会员卡类型 decimal returnAmount = 0; //赠送金额 //会员卡类型条件 List <IWhereCondition> complexConditionOne = new List <IWhereCondition> { }; //获取会员与会员卡关系表 var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity() { CustomerID = CurrentUserInfo.ClientID, VIPID = vipInfo.VIPID }, null).FirstOrDefault(); //该会员有会员卡 if (vipCardVipMappingEntity != null) { //获取该会员会员卡信息 var vipCardEntity = vipCardBll.QueryByEntity(new VipCardEntity() { CustomerID = CurrentUserInfo.ClientID, VipCardID = vipCardVipMappingEntity.VipCardID }, null).FirstOrDefault(); //获取该会员卡类型 var sysVipCardTypeEntity = sysVipCardTypeBll.GetByID(vipCardEntity.VipCardTypeID); VipCardTypeId = vipCardEntity.VipCardTypeID; //获取会员卡的会员活动 var rechargeStrategyBLL = new RechargeStrategyBLL(CurrentUserInfo); var RechargeActivityDS = rechargeStrategyBLL.GetRechargeActivityList(CurrentUserInfo.ClientID, VipCardTypeId.ToString(), 3); var RechargeStrategy = new RechargeStrategyInfo(); if (RechargeActivityDS != null && RechargeActivityDS.Tables[0].Rows.Count > 0) { var RechargeStrategyList = DataTableToObject.ConvertToList <RechargeStrategyInfo>(RechargeActivityDS.Tables[0]); //获取与充值金额最接近的活动 RechargeStrategy = RechargeStrategyList.Where(n => n.RechargeAmount <= rp.ActuallyPaid).OrderByDescending(n => n.RechargeAmount).FirstOrDefault(); if (RechargeStrategy != null) { //梯度 if (RechargeStrategy.RuleType == "Step") { //赠送金额 = 会员活动梯度设置赠送金额 returnAmount = RechargeStrategy.GiftAmount; } //叠加 if (RechargeStrategy.RuleType == "Superposition") { //赠送金额与满赠条件金额比例 decimal discount = RechargeStrategy.GiftAmount / RechargeStrategy.RechargeAmount; //赠送金额 = 充值金额 * (设置赠送金额 / 设置满赠条件金额) returnAmount = rp.ActuallyPaid * RechargeStrategy.GiftAmount / RechargeStrategy.RechargeAmount; } } } //获取等级高的会员卡类型条件 complexConditionOne.Add(new MoreThanCondition() { FieldName = "VipCardLevel", Value = sysVipCardTypeEntity.VipCardLevel, IncludeEquals = false }); complexConditionOne.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID }); } //该会员没有会员卡 else { //获取所有的会员卡类型条件 complexConditionOne.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID }); } var sysVipCardTypeList = sysVipCardTypeBll.Query(complexConditionOne.ToArray(), null).ToList(); if (sysVipCardTypeList == null) { throw new APIException("没有建立会员体系") { ErrorCode = 200 }; } //获取会员卡类型升级规则 List <IWhereCondition> complexConditionTwo = new List <IWhereCondition> { }; complexConditionTwo.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID }); complexConditionTwo.Add(new EqualsCondition() { FieldName = "IsRecharge", Value = 1 }); var vipCardUpgradeRuleList = vipCardUpgradeRuleBll.Query(complexConditionTwo.ToArray(), null); //将升级卡规则和可升级的会员卡匹配 var vipCardTypeDetailList = vipCardUpgradeRuleList.Join(sysVipCardTypeList, n => n.VipCardTypeID, m => m.VipCardTypeID, (n, m) => new { n, m }).OrderByDescending(t => t.m.VipCardLevel).ToList(); //判断是否满充值条件 bool isUpgrade = false; for (int i = 0; i < vipCardTypeDetailList.Count; i++) { //实付金额 >= 可升级金额 if (vipCardTypeDetailList[i].n.OnceRechargeAmount <= rp.ActuallyPaid) { isUpgrade = true; VipCardTypeId = vipCardTypeDetailList[i].n.VipCardTypeID ?? 0; break; } } if (isUpgrade) { OrderDesc = "Upgrade"; //升级 } //充值订单 var rechargeOrderEntity = new RechargeOrderEntity() { OrderID = Guid.NewGuid(), OrderNo = serviceUnitExpandBll.GetUnitOrderNo(), OrderDesc = OrderDesc, VipID = vipInfo.VIPID, VipCardNo = vipInfo.VipCode, UnitId = rp.UnitId, UserId = userId, TotalAmount = rp.ActuallyPaid, ActuallyPaid = rp.ActuallyPaid, PosSourceName = rp.PosSourceName, ReturnAmount = returnAmount, PayerID = vipInfo.VIPID, Status = 0, CustomerID = CurrentUserInfo.ClientID, VipCardTypeId = VipCardTypeId }; rechargeOrderBll.Create(rechargeOrderEntity); rd.orderId = rechargeOrderEntity.OrderID.ToString(); //支付完成 if (rp.PayStatus == 1) { //获取门店信息 t_unitBLL unitBLL = new t_unitBLL(CurrentUserInfo); t_unitEntity unitInfo = null; if (!string.IsNullOrEmpty(rechargeOrderEntity.UnitId)) { unitInfo = unitBLL.GetByID(rechargeOrderEntity.UnitId); } //充值 rechargeOrderBll.Recharge(rechargeOrderEntity, vipInfo, unitInfo, ""); } return(rd); }
public string setOrderInfo() { //string content = string.Empty; var respData = new setOrderInfoRespData(); //try //{ string reqContent = ""; Loggers.Debug(new DebugLogInfo() { Message = string.Format("setOrderInfo: {0}", reqContent) }); #region //解析请求字符串 chech //var reqObj = reqContent.DeserializeJSONTo<setOrderInfoReqData>(); //reqObj = reqObj == null ? new setOrderInfoReqData() : reqObj; //if (reqObj.special == null) //{ // reqObj.special = new setOrderInfoReqSpecialData(); //} //if (reqObj.special == null) //{ // respData.code = "102"; // respData.description = "没有特殊参数"; // return respData.ToJSON().ToString(); //} //if (reqObj.special.skuId == null || reqObj.special.skuId.Equals("")) //{ // respData.code = "2201"; // respData.description = "skuId不能为空"; // return respData.ToJSON().ToString(); //} //if (reqObj.special.qty == null || reqObj.special.qty.Equals("")) //{ // respData.code = "2202"; // respData.description = "qty购买的数量不能为空"; // return respData.ToJSON().ToString(); //} //if (reqObj.special.salesPrice == null || reqObj.special.salesPrice.Equals("")) //{ // respData.code = "2203"; // respData.description = "salesPrice销售价格不能为空"; // return respData.ToJSON().ToString(); //} //if (reqObj.special.stdPrice == null || reqObj.special.stdPrice.Equals("")) //{ // respData.code = "2204"; // respData.description = "stdPrice原价格不能为空"; // return respData.ToJSON().ToString(); //} //if (reqObj.special.deliveryId == null || reqObj.special.deliveryId.Equals("")) //{ // respData.code = "2205"; // respData.description = "deliveryId提货方式不能为空"; // return respData.ToJSON().ToString(); //} //if (reqObj.common.userId == null || reqObj.common.userId.Equals("")) //{ // respData.code = "2206"; // respData.description = "userId不能为空"; // return respData.ToJSON().ToString(); //} #endregion #region //判断客户ID是否传递 //if (!string.IsNullOrEmpty(reqObj.common.customerId)) //{ // customerId = reqObj.common.customerId; //} var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; #endregion #region 设置参数 InoutService service = new InoutService(loggingSessionInfo); SetOrderEntity orderInfo = new SetOrderEntity(); orderInfo.SkuId = "1"; orderInfo.TotalQty = 1; //if (reqObj.special.storeId == null || reqObj.special.storeId.Trim().Equals("")) //{ // UnitService unitServer = new UnitService(loggingSessionInfo); // orderInfo.StoreId = unitServer.GetUnitByUnitType("OnlineShopping", null).Id; //获取在线商城的门店标识 //} //else //{ // orderInfo.StoreId = ToStr(reqObj.special.storeId); //} orderInfo.StoreId = "1"; orderInfo.SalesPrice = 0; orderInfo.StdPrice = -1; orderInfo.TotalAmount = 0; orderInfo.Mobile = ""; orderInfo.Email = ""; orderInfo.Remark = ""; orderInfo.CreateBy = ""; orderInfo.LastUpdateBy = ""; orderInfo.DeliveryId = ""; orderInfo.DeliveryTime = ""; orderInfo.DeliveryAddress = ""; orderInfo.CustomerId = loggingSessionInfo.CurrentLoggingManager.Customer_Id; orderInfo.OpenId = ""; orderInfo.username = ""; if (orderInfo.OrderId == null || orderInfo.OrderId.Equals("")) { orderInfo.OrderId = BaseService.NewGuidPub(); orderInfo.OrderDate = System.DateTime.Now.ToString("yyyy-MM-dd"); orderInfo.Status = "100"; orderInfo.StatusDesc = "待审核"; orderInfo.DiscountRate = Convert.ToDecimal((orderInfo.SalesPrice / orderInfo.StdPrice) * 100); //获取订单号 TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(loggingSessionInfo); orderInfo.OrderCode = serviceUnitExpand.GetUnitOrderNo(); } #endregion string strError = string.Empty; string strMsg = string.Empty; Loggers.Debug(new DebugLogInfo() { Message = string.Format("setOrderInfo: {0}", "开始保存") }); bool bReturn = service.SetOrderOnlineShoppingCoupon(orderInfo, out strError, out strMsg); #region 返回信息设置 //respData.content = new setOrderInfoRespContentData(); //respData.content.orderId = orderInfo.OrderId; //respData.exception = strError; //respData.description = strMsg; //if (!bReturn) //{ // respData.code = "111"; //} #endregion //} //content = respData.ToJSON(); //return content; return(orderInfo.OrderCode); }