Ejemplo n.º 1
0
        /// <summary>
        /// 计算商品赠送积分
        /// </summary>
        public int CalcPresentedPointForGoods(int corpId, decimal paidAmount)
        {
            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                try
                {
                    string key = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.Goods);

                    var rules = conn.Query <Tb_App_Point_PropertyPresentedRule>(@"SELECT * FROM Tb_App_Point_PropertyPresentedRule 
                                        WHERE CorpID=@CorpID AND CommunityID IS NULL AND PresentedObject=@PresentedObject AND IsDelete=0 
                                        ORDER BY ConditionAmount,DiscountsAmount",
                                                                                new
                    {
                        CorpID          = corpId,
                        PresentedObject = key
                    });

                    if (rules.Count() > 0)
                    {
                        Tb_App_Point_PropertyPresentedRule rule = null;

                        foreach (var item in rules)
                        {
                            if (paidAmount >= item.ConditionAmount)
                            {
                                rule = item;
                            }
                        }

                        if (rule != null)
                        {
                            return(rule.PresentedPoints);
                        }
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算赠送积分
        /// </summary>
        private void PresentedPoint(string bussId, string orderId, decimal paidAmount)
        {
            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                var trans = conn.BeginTransaction();

                try
                {
                    int    corpId = 0;
                    string userId = null;
                    using (var bzconn = new SqlConnection(PubConstant.BusinessContionString))
                    {
                        var sql = @"SELECT BussNature FROM Tb_System_BusinessCorp WHERE BussId=@BussId;
                                    SELECT CorpID FROM Unified..Tb_Community WHERE Id=(SELECT CommunityId FROM Tb_System_BusinessConfig 
                                                                                    WHERE BussId=@BussId);
                                    SELECT CorpID FROM Tb_System_BusinessCorp_Config WHERE BussId=@BussId";

                        var reader = bzconn.QueryMultiple(sql, new { BussId = bussId });

                        var bussNature = reader.Read <string>().FirstOrDefault();
                        if (bussNature == "平台商城")
                        {
                            Business.Alipay.Log("支付宝购物:未赠送积分,平台商城不赠送积分");
                            return;
                        }

                        var nature_1 = reader.Read <int>().FirstOrDefault();
                        var nature_2 = reader.Read <int>().FirstOrDefault();

                        if (nature_1 != 0)
                        {
                            corpId = nature_1;
                        }
                        if (nature_2 != 0)
                        {
                            corpId = nature_2;
                        }

                        userId = bzconn.Query <string>(@"SELECT UserId FROM Tb_Charge_Receipt WHERE OrderId=@OrderId", new { OrderId = orderId }).FirstOrDefault();
                        if (string.IsNullOrEmpty(userId))
                        {
                            Business.Alipay.Log("支付宝购物:未赠送积分,未找到用户信息");
                            return;
                        }
                    }

                    var rules = conn.Query <Tb_App_Point_PropertyPresentedRule>(@"SELECT * FROM Tb_App_Point_PropertyPresentedRule 
                                                                                WHERE CorpID=@CorpID AND CommunityID IS NULL AND PresentedObject=@PresentedObject AND IsDelete=0 
                                                                                AND getdate() BETWEEN StartTime AND EndTime ORDER BY ConditionAmount",
                                                                                new
                    {
                        CorpID          = corpId,
                        PresentedObject = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.Goods)
                    }, trans);

                    if (rules.Count() > 0)
                    {
                        Tb_App_Point_PropertyPresentedRule current = null;
                        foreach (var item in rules)
                        {
                            if (paidAmount >= item.ConditionAmount)
                            {
                                current = item;
                            }
                        }

                        if (current != null)
                        {
                            var userPoint = conn.Query("SELECT * FROM Tb_App_UserPoint WHERE UserID=@UserID", new { UserID = userId }, trans).FirstOrDefault();
                            int balance   = 0;

                            if (userPoint == null)
                            {
                                balance = 0;
                                conn.Execute(@"INSERT INTO Tb_App_UserPoint(UserID, PointBalance) VALUES(@UserID, @PointBalance)",
                                             new { UserID = userId, PointBalance = current.PresentedPoints }, trans);
                            }
                            else
                            {
                                balance = userPoint.PointBalance;
                                conn.Execute("UPDATE Tb_App_UserPoint SET PointBalance=(PointBalance+@PresentedPoints) WHERE UserID=@UserID",
                                             new
                                {
                                    PresentedPoints = current.PresentedPoints,
                                    UserID          = userId
                                }, trans);
                            }

                            // 赠送历史
                            conn.Execute(@"INSERT INTO Tb_App_Point_PresentedHistory(UserID,PresentedWay,PresentedPoints,PointBalance,Remark) 
                                        VALUES(@UserID, @PresentedWay, @PresentedPoints, @PointBalance, @Remark)",
                                         new
                            {
                                UserID          = userId,
                                PresentedWay    = AppPointPresentedWayConverter.GetKey(AppPointPresentedWay.StoreTrade),
                                PresentedPoints = current.PresentedPoints,
                                PointBalance    = balance + current.PresentedPoints,
                                Remark          = AppPointPresentedWayConverter.GetValue(AppPointPresentedWay.StoreTrade),
                            }, trans);
                        }
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    Business.Alipay.Log("支付宝购物:计算赠送积分异常," + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 计算物业类、车位类赠送积分数量
        /// </summary>
        public void CalcPresentedPointForPropertyFees(string communityId, decimal paidPropertyFeeAmount, decimal paidParkingFeeAmount,
                                                      out int propertyRulePresentedPoint, out int parkingRulePresentedPoint)
        {
            propertyRulePresentedPoint = 0;
            parkingRulePresentedPoint  = 0;

            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                try
                {
                    string propertyFeeKey = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.PropertyFee);
                    string parkingFeeKey  = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.ParkingFee);

                    var rules = conn.Query <Tb_App_Point_PropertyPresentedRule>(@"SELECT * FROM Tb_App_Point_PropertyPresentedRule 
                                        WHERE CommunityID=@CommunityID AND (PresentedObject=@PresentedObject1 OR PresentedObject=@PresentedObject2)
                                        AND IsDelete=0 ORDER BY ConditionAmount",
                                                                                new
                    {
                        CommunityID      = communityId,
                        PresentedObject1 = propertyFeeKey,
                        PresentedObject2 = parkingFeeKey
                    });

                    if (rules.Count() > 0)
                    {
                        Tb_App_Point_PropertyPresentedRule propertyRule = null;
                        Tb_App_Point_PropertyPresentedRule parkingRule  = null;

                        foreach (var item in rules)
                        {
                            // 物业类
                            if (item.PresentedObject == propertyFeeKey)
                            {
                                if (paidPropertyFeeAmount >= item.ConditionAmount)
                                {
                                    propertyRule = item;
                                }
                            }

                            // 车位类
                            if (item.PresentedObject == parkingFeeKey)
                            {
                                if (paidParkingFeeAmount >= item.ConditionAmount)
                                {
                                    parkingRule = item;
                                }
                            }
                        }

                        if (propertyRule != null)
                        {
                            propertyRulePresentedPoint = propertyRule.PresentedPoints;
                        }

                        if (parkingRule != null)
                        {
                            parkingRulePresentedPoint = parkingRule.PresentedPoints;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }