/// <summary> /// 消费处理 /// </summary> /// <param name="order"></param> /// <param name="payment"></param> public static void GetEarnThroughBuy(Mall_Order order = null, Payment payment = null) { //消费赠与处理 if (order == null) { return; } int[] ProductIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsProduct: true); int[] ServiceIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsService: true); if (payment == null) { payment = Payment.GetPaymentByTradeNo(order.TradeNo); } decimal TotalCost = order.TotalCost; if (payment != null) { TotalCost = payment.Amount / 100; } Dictionary <string, object> BackObject = new Dictionary <string, object>(); Mall_AmountRule.GetBackAmountPoint(TotalCost, out BackObject, ProductIDList, ServiceIDList, AmountType: 2, UserID: order.UserID); string Title = "消费赠与"; int CategoryType = 6; using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); decimal BackAmount = Utility.Tools.GetValueFromDic <decimal>(BackObject, "BackAmount"); int AmountRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "AmountRuleID"); bool AmountIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "AmountIsSendNow"); DateTime AmountIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "AmountIsReadySendTime"); if (BackAmount > 0 && AmountRuleID > 0) { Insert_Mall_UserBalance(order.UserID, 1, BackAmount, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", RelatedID: order.ID, AmountRuleID: AmountRuleID, helper: helper, PaymentMethod: order.PaymentMethod, IsSent: AmountIsSendNow, IsReadySendTime: AmountIsReadySendTime); } int BackPoint = Utility.Tools.GetValueFromDic <int>(BackObject, "BackPoint"); int PointRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "PointRuleID"); bool PointIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "PointIsSendNow"); DateTime PointIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "PointIsReadySendTime"); if (BackPoint > 0 && PointRuleID > 0) { Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 1, 0, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", 0, helper, RelatedID: order.ID, PointValue: BackPoint, AmountRuleID: PointRuleID, IsSent: PointIsSendNow, IsReadySendTime: PointIsReadySendTime); } if (order.TotalOrderPointCost > 0) { Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 2, 0, "购买商品", "OrderID:" + order.ID, 1, "System", 1, order.TradeNo, order.ID, helper, RelatedID: order.ID, PointValue: -order.TotalOrderPointCost, AmountRuleID: 0); } List <int> CouponIDList = Utility.Tools.GetValueFromDic <List <int> >(BackObject, "CouponIDList"); int CouponRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "CouponRuleID"); bool CouponIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "CouponIsSendNow"); DateTime CouponIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "CouponIsReadySendTime"); int SendCouponCount = Utility.Tools.GetValueFromDic <int>(BackObject, "SendCouponCount"); if (CouponIDList != null && CouponIDList.Count > 0 && CouponRuleID > 0) { foreach (var CouponID in CouponIDList) { for (int i = 0; i < SendCouponCount; i++) { Mall_CouponUser.Insert_Mall_CouponUser(order.UserID, CouponID, 3, CouponRuleID, CouponIsReadySendTime, helper: helper, IsSent: CouponIsSendNow); } } } if (payment != null) { payment.Save(helper); } if (order != null) { order.Save(helper); } helper.Commit(); } catch (Exception ex) { helper.Rollback(); Utility.LogHelper.WriteError("Mall_UserBalance.cs", "GetEarnThroughBuy", ex); } } }
/// <summary> /// 充值处理 /// </summary> /// <param name="BalanceStatus"></param> /// <param name="TradeNo"></param> /// <param name="payment"></param> /// <param name="AmountType"></param> public static void UpdateMall_UserBalanceStatus(int BalanceStatus, string TradeNo, Payment payment = null, int AmountType = 1, string PaymentMethod = "") { //充值赠与处理 Dictionary <string, object> BackObject = new Dictionary <string, object>(); Mall_UserBalance data = null; if (BalanceStatus == 1) { data = GetMall_UserBalanceByTradeNo(TradeNo); if (data == null) { return; } Mall_AmountRule.GetBackAmountPoint(data.BalanceValue, out BackObject, new int[] { }, new int[] { }, AmountType: AmountType, UserID: data.UserID); //AmountRuleID = Utility.Tools.GetValueFromDic<int>(BackObject, "AmountRuleID"); //BackAmount = Utility.Tools.GetValueFromDic<decimal>(BackObject, "BackAmount"); } string Title = "充值赠与"; int CategoryType = 5; User user = null; var user_level = Mall_UserLevel.GetMall_UserLevelByUserID(data.UserID, out user); using (SqlHelper helper = new SqlHelper()) { try { helper.BeginTransaction(); data.BalanceStatus = 1; data.Save(helper); if (user != null && user_level != null) { if (user.UserLevelID != user_level.ID) { string LevelTitle = "充值满" + user_level.StartAmount.ToString("0.00") + "升到到合伙人(" + user_level.Name + ")"; Mall_UserLevelApprove.Insert_Mall_UserLevelApprove(data.UserID, LevelTitle, user_level.ID, helper: helper, IncomingAmount: data.BalanceValue, IncomingType: data.PaymentMethodDesc, UserBalanceID: data.ID); } } decimal BackAmount = Utility.Tools.GetValueFromDic <decimal>(BackObject, "BackAmount"); int AmountRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "AmountRuleID"); bool AmountIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "AmountIsSendNow"); DateTime AmountIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "AmountIsReadySendTime"); if (BackAmount > 0 && AmountRuleID > 0) { Insert_Mall_UserBalance(data.UserID, 1, BackAmount, Title, "BalaceID:" + data.ID, CategoryType, "System", 1, "", RelatedID: data.ID, AmountRuleID: AmountRuleID, helper: helper, PaymentMethod: PaymentMethod, IsSent: AmountIsSendNow, IsReadySendTime: AmountIsReadySendTime); } int BackPoint = Utility.Tools.GetValueFromDic <int>(BackObject, "BackPoint"); int PointRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "PointRuleID"); bool PointIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "PointIsSendNow"); DateTime PointIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "PointIsReadySendTime"); if (BackPoint > 0 && PointRuleID > 0) { Mall_UserPoint.Insert_Mall_UserPoint(data.UserID, 1, 0, Title, "BalaceID:" + data.ID, CategoryType, "System", 1, "", 0, helper, RelatedID: data.ID, PointValue: BackPoint, AmountRuleID: PointRuleID, IsSent: PointIsSendNow, IsReadySendTime: PointIsReadySendTime); } List <int> CouponIDList = Utility.Tools.GetValueFromDic <List <int> >(BackObject, "CouponIDList"); int CouponRuleID = Utility.Tools.GetValueFromDic <int>(BackObject, "CouponRuleID"); bool CouponIsSendNow = Utility.Tools.GetValueFromDic <bool>(BackObject, "CouponIsSendNow"); DateTime CouponIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "CouponIsReadySendTime"); int SendCouponCount = Utility.Tools.GetValueFromDic <int>(BackObject, "SendCouponCount"); if (CouponIDList != null && CouponIDList.Count > 0 && CouponRuleID > 0) { foreach (var CouponID in CouponIDList) { for (int i = 0; i < SendCouponCount; i++) { Mall_CouponUser.Insert_Mall_CouponUser(data.UserID, CouponID, 1, CouponRuleID, CouponIsReadySendTime, helper: helper, IsSent: CouponIsSendNow); } } } if (payment != null) { payment.Save(helper); } helper.Commit(); } catch (Exception ex) { helper.Rollback(); Utility.LogHelper.WriteError("Mall_UserBalance.cs", "UpdateMall_UserBalanceStatus", ex); } } }