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; }
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; }