Пример #1
0
        public HttpResponseMessage Amount(string vipId, decimal amount)
        {
            Loggers.Debug(new DebugLogInfo()
            {
                Message = $"[api/Integral/Amount]接口,参数:\"vipId:{vipId}&&amount:{amount}\""
            });
            try
            {
                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); //会员信息

                var integralAmountResponseModel = new IntegralAmountResponseModel();

                //获取社会化销售配置和积分返现配置
                var       basicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo);
                Hashtable htSetting       = basicSettingBll.GetSocialSetting();

                //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)
                {
                    integralAmountResponseModel.Integral       = 0;
                    integralAmountResponseModel.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(amount * pointsRedeemUpLimit * integralAmountPre, 1);
                    //可使用的积分
                    integralAmountResponseModel.Integral = validIntegral > totalIntegral ? totalIntegral : validIntegral;

                    if (amount == 0)
                    {
                        integralAmountResponseModel.Integral = Convert.ToDecimal(vipIntegralEntity.ValidIntegral);
                    }

                    //rd.IntegralAmount = rd.Integral * integralAmountPre;
                    integralAmountResponseModel.IntegralAmount = bll.GetAmountByIntegralPer(loggingSessionInfo.ClientID,
                                                                                            integralAmountResponseModel.Integral);
                    integralAmountResponseModel.IntegralDesc = "使用积分" +
                                                               integralAmountResponseModel.Integral.ToString("0") +
                                                               ",可兑换"
                                                               +
                                                               integralAmountResponseModel.IntegralAmount.ToString(
                        "0.00") + "元";
                }
                integralAmountResponseModel.IsSucess = true;
                return(Request.CreateResponse(HttpStatusCode.OK, integralAmountResponseModel));
            }
            catch (Exception ex)
            {
                var response = new IntegralAmountResponseModel()
                {
                    IsSucess     = false,
                    ErrorMessage = ex.Message
                };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Пример #2
0
        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));
            }
        }