private void changeCredit(string objectId, int addCredit) { _User user = userbll.QuerySingleById(objectId); userbll.UpdateById(objectId, new Dictionary <string, Object>() { { "credit", user.credit + addCredit }, }); CreditsHistoryBLL chBll = new CreditsHistoryBLL(); chBll.Insert(new CreditsHistory() { objectId = Guid.NewGuid().ToString(), createdAt = DateTime.Now, updatedAt = DateTime.Now, userId = user.objectId, type = 0, change = addCredit, credit = user.credit + addCredit }); }
public IHttpActionResult parseCreditConsume( string uid, long credits, string appKey, string timestamp, string orderNum, string type, bool waitAudit, string sign, string description = null, int facePrice = 0, int actualPrice = 0, string ip = null, string @params = null ) { _User user = userBll.QuerySingleById(uid); if (user == null) { return(creditError("no such user", 0)); } long userCredit = user.credit; if (!appKey.Equals(APP_KEY)) { return(creditError("appKey not match", userCredit)); } if (timestamp == null) { return(creditError("timestamp can't be null", userCredit)); } Hashtable hshTable = duiba.GetUrlParams(HttpUtility.UrlDecode(Request.RequestUri.AbsoluteUri)); string newSign; bool verify = duiba.SignVerify(APP_SECRET, hshTable, out newSign); if (!verify) { return(creditError("sign verify fail", userCredit)); } else { if (userCredit < credits) { return(creditError("credits not enough!", userCredit)); } userBll.UpdateById(uid, new Dictionary <string, object> { { "credit", userCredit - credits } }); CreditsHistory ch = new CreditsHistory(); ch.objectId = "test" + Guid.NewGuid().ToString(); ch.orderNum = orderNum; ch.createdAt = DateTime.Now; ch.updatedAt = DateTime.Now; ch.userId = uid; ch.type = getCreditType(type); ch.change = (int)-credits; ch.credit = userBll.QuerySingleById(uid).credit; ch.orderNum = orderNum; ch.bizId = duiba.GetMd5(orderNum); bool flag = chBll.Insert(ch); return(flag ? creditOK(ch.bizId, ch.credit) : creditError("Unexpected Error, data roll back", userCredit));; } }