public bool UpdatePrepayAccount(PrepayAccount prepayAccount) { bool result = false; try { DbCommand cmd = null; string sql = @"UPDATE [dbo].[PrepayAccount] SET AccountMoney = @AccountMoney, PresentMoney = @PresentMoney, TotalPresent = @TotalPresent, TotalMoney=@TotalMoney, LastPresentMoney=@LastPresentMoney, LastConsumeMoney = @LastConsumeMoney WHERE Uid = @Uid;"; cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "AccountMoney", DbType.Decimal, prepayAccount.AccountMoney); db.AddInParameter(cmd, "PresentMoney", DbType.Decimal, prepayAccount.PresentMoney); db.AddInParameter(cmd, "TotalPresent", DbType.Decimal, prepayAccount.TotalPresent); db.AddInParameter(cmd, "TotalMoney", DbType.Decimal, prepayAccount.TotalMoney); db.AddInParameter(cmd, "LastConsumeMoney", DbType.Decimal, prepayAccount.LastConsumeMoney); db.AddInParameter(cmd, "LastPresentMoney", DbType.Decimal, prepayAccount.LastPresentMoney); db.AddInParameter(cmd, "Uid", DbType.String, prepayAccount.uid); result = ExecSql(cmd) > 0; } catch (Exception ex) { Logger.Log(LoggingLevel.WxPay, ex); } return(result); }
public PrepayAccount GetPrepayAccount(string uid) { PrepayAccount prepayAccount = null; try { string sql = @"select top 1 * from PrepayAccount where Uid = @Uid"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "Uid", DbType.String, uid); using (var reader = db.ExecuteReader(cmd)) { while (reader.Read()) { prepayAccount = new PrepayAccount() { AccountMoney = reader.TryGetValue <Decimal>("AccountMoney"), LastConsumeDate = reader.TryGetValue <DateTime>("LastConsumeDate"), LastConsumeMoney = reader.TryGetValue <Decimal>("LastConsumeMoney"), LastPresentMoney = reader.TryGetValue <Decimal>("LastPresentMoney"), PAId = reader.TryGetValue <int>("PAId"), PresentMoney = reader.TryGetValue <Decimal>("PresentMoney"), TotalMoney = reader.TryGetValue <Decimal>("TotalMoney"), TotalPresent = reader.TryGetValue <Decimal>("TotalPresent"), uid = reader.TryGetValue <String>("Uid") }; } } } catch { throw; } return(prepayAccount); }
public ActionResult CancelOrder(string uid, string orderId, bool isEdit) { ActionResult result = Content("FAILED"); try { bool success = true; var orderManager = new OrderManager(); var order = orderManager.GetOrderSummary(Guid.Parse(orderId)); if (order != null) { OrderModel orderModel = new OrderModel(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { PrepayRecordModel prepayRecordModel = new PrepayRecordModel(); CrmMemberModel crmMemberModel = new CrmMemberModel(); if (isEdit) { if (order.Status == OrderStatus.New) { success = orderModel.UpdateOrderStatus(Guid.Parse(orderId), OrderStatus.Cancelled); var prepayRecord = prepayRecordModel.GetPrepayRecordByOrderId(orderId); if (prepayRecord != null) { //取消订单,支付失败 prepayRecord.AsureDate = DateTime.Now; prepayRecord.RState = "99"; success = success && prepayRecordModel.UpdatePrepayRecord(prepayRecord); } } else { success = false; } } else { if (OrderStatus.Paid == order.Status) { PrepayRecord prepayRecord = null; PrepayRecord newPrepayRecord = null; PrepayAccount prepayAccount = null; prepayAccount = crmMemberModel.GetPrepayAccount(uid); prepayRecord = prepayRecordModel.GetPrepayRecordByOrderId(orderId); //已退款 prepayRecord.RState = "02"; prepayRecord.AsureDate = DateTime.Now; newPrepayRecord = new PrepayRecord(); newPrepayRecord.AddMoney = -prepayRecord.AddMoney; newPrepayRecord.AsureDate = DateTime.Now; newPrepayRecord.BillPayId = Guid.NewGuid(); newPrepayRecord.DiscountlMoeny = 0; newPrepayRecord.PayByScore = 0; newPrepayRecord.PayModel = "02"; newPrepayRecord.PrepayDate = DateTime.Now; newPrepayRecord.PrepayMoney = -0; newPrepayRecord.PresentMoney = 0; newPrepayRecord.PromotionId = 0; newPrepayRecord.RecMoney = 0; newPrepayRecord.RecordId = -1; newPrepayRecord.RState = ""; newPrepayRecord.RstId = order.RestaurantId; newPrepayRecord.ScoreVip = 0; newPrepayRecord.SId = ""; newPrepayRecord.Uid = uid; newPrepayRecord.UserId = "System"; prepayAccount.AccountMoney += newPrepayRecord.AddMoney.Value; newPrepayRecord.PrepayDate = DateTime.Now; newPrepayRecord.AsureDate = DateTime.Now; success = orderModel.UpdateOrderStatus(Guid.Parse(orderId), OrderStatus.Refunded); success = success && prepayRecordModel.AddPrepayRecord(newPrepayRecord); success = success && crmMemberModel.UpdatePrepayAccount(prepayAccount); success = success && prepayRecordModel.UpdatePrepayRecord(prepayRecord); } else { success = false; } } if (success) { result = Content("SUCCESS"); scope.Complete(); } else { result = Content("FAILED"); scope.Dispose(); } } } else { result = Content("FAILED"); } } catch (Exception ex) { Logger.Log(ex); } return(result); }
public bool JoinOnlineVipGroup(string uid, string verifyCode) { bool result = false; try { PrepayRecordModel prepayRecordModel = new PrepayRecordModel(); CrmMemberModel crmMemberModel = new CrmMemberModel(); PrepayRecord prepayRecord = null; PrepayAccount prepayAccount = null; prepayRecord = new PrepayRecord(); prepayRecord.AddMoney = 30m; prepayRecord.AsureDate = DateTime.Now; prepayRecord.BillPayId = Guid.Empty; prepayRecord.DiscountlMoeny = 0; prepayRecord.PayByScore = 0; prepayRecord.PayModel = "00"; prepayRecord.PrepayDate = DateTime.Now; prepayRecord.PrepayMoney = 0; prepayRecord.PresentMoney = 30m; prepayRecord.PromotionId = 0; prepayRecord.RecMoney = 0; prepayRecord.RecordId = -1; prepayRecord.RState = "01"; prepayRecord.RstId = Guid.Empty; prepayRecord.ScoreVip = 0; prepayRecord.SId = "邀请码:" + verifyCode; prepayRecord.Uid = uid; prepayRecord.UserId = "JoinVipGroup"; prepayAccount = crmMemberModel.GetPrepayAccount(uid); if (prepayAccount != null) { prepayAccount.PresentMoney += 30m; prepayAccount.TotalPresent += 30m; prepayAccount.TotalMoney += 30m; } using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { if (crmMemberModel.UpdatePrepayAccount(prepayAccount) && prepayRecordModel.AddPrepayRecord(prepayRecord)) { result = true; scope.Complete(); } else { scope.Dispose(); } } } catch (Exception ex) { Logger.Log(ex); } return(result); }
public bool SaveMember(string wxOpenid, string companyid) { bool resukt = false; using (TransactionScope transaction = new TransactionScope()) { var user = getCrmMemberListInfoData(wxOpenid); if (user == null || (user != null && user.Count == 0)) { CrmMember member = new CrmMember(); member.MemberSource = "01"; member.SourceAccountId = wxOpenid; member.TypeId = 1; member.UseState = "01"; member.RegDate = DateTime.Now; member.CompanyId = new Guid(companyid); var v = GetNewUserId(); member.Uid = v.ToString(); #region Add new user DbCommand cmd = null; string sql; sql = "insert into CrmMember([Uid],MemberSource,SourceAccountId,TypeId,UseState,RegDate,CompanyId) " + "values(@Uid,@MemberSource,@SourceAccountId,@TypeId,@UseState,@RegDate,@CompanyId)"; cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "Uid", DbType.String, member.Uid); db.AddInParameter(cmd, "MemberSource", DbType.String, member.MemberSource); db.AddInParameter(cmd, "SourceAccountId", DbType.String, member.SourceAccountId); db.AddInParameter(cmd, "TypeId", DbType.Int32, member.TypeId); db.AddInParameter(cmd, "UseState", DbType.String, member.UseState); db.AddInParameter(cmd, "RegDate", DbType.DateTime, member.RegDate); db.AddInParameter(cmd, "CompanyId", DbType.Guid, member.CompanyId); ExecSql(cmd); #endregion #region Add PrepayAccount PrepayAccount acc = new PrepayAccount(); acc.uid = member.Uid; acc.AccountMoney = 0; acc.TotalMoney = 0; acc.PresentMoney = 0; acc.TotalPresent = 0; acc.LastConsumeMoney = 0; acc.LastPresentMoney = 0; cmd = null; sql = "insert into PrepayAccount([Uid],AccountMoney,TotalMoney,PresentMoney,TotalPresent,LastConsumeMoney,LastPresentMoney) " + "values(@Uid,@AccountMoney,@TotalMoney,@PresentMoney,@TotalPresent,@LastConsumeMoney,@LastPresentMoney)"; cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "Uid", DbType.String, acc.uid); db.AddInParameter(cmd, "AccountMoney", DbType.Decimal, acc.AccountMoney); db.AddInParameter(cmd, "TotalMoney", DbType.Decimal, acc.TotalMoney); db.AddInParameter(cmd, "PresentMoney", DbType.Decimal, acc.PresentMoney); db.AddInParameter(cmd, "TotalPresent", DbType.Decimal, acc.TotalPresent); db.AddInParameter(cmd, "LastConsumeMoney", DbType.Decimal, acc.LastConsumeMoney); db.AddInParameter(cmd, "LastPresentMoney", DbType.Decimal, acc.LastPresentMoney); ExecSql(cmd); #endregion #region Add CrmMemberScore CrmMemberScore scroe = new CrmMemberScore() { LastScore = 0, LastScoredDate = DateTime.Now, Score = 0, TotalScore = 0, Uid = member.Uid, UseMoney = 0, UseScore = 0 }; cmd = null; sql = "insert into CrmMemberScore([Uid],LastScoredDate,Score,LastScore,UseMoney,UseScore) " + "values(@Uid,@LastScoredDate,@Score,@LastScore,@UseMoney,@UseScore)"; cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "Uid", DbType.String, scroe.Uid); db.AddInParameter(cmd, "LastScoredDate", DbType.DateTime, scroe.LastScoredDate); db.AddInParameter(cmd, "Score", DbType.Int32, scroe.Score); db.AddInParameter(cmd, "LastScore", DbType.Int32, scroe.LastScore); db.AddInParameter(cmd, "UseMoney", DbType.Int32, scroe.UseMoney); db.AddInParameter(cmd, "UseScore", DbType.Int32, scroe.UseScore); ExecSql(cmd); #endregion } else { #region Set user to New DbCommand cmd = null; string sql; sql = "update CrmMember set UseState='01' where SourceAccountId=@SourceAccountId"; cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "SourceAccountId", DbType.String, wxOpenid); ExecSql(cmd); #endregion } transaction.Complete(); resukt = true; } return(resukt); }