/// <summary> /// 添加到购物车 /// </summary> /// <param name="item"></param> /// <param name="groupByPrice">是否按价格分组</param> /// <returns></returns> public int Add(TModel item, bool groupByPrice = false) { DBExtend helper = DBExtend; TModel item2; if (groupByPrice)//按价格分组 { item2 = helper.QueryItem <TModel>(b => b.UserId == item.UserId && b.ProductId == item.ProductId && b.StyleId == item.StyleId && b.CartType == item.CartType && b.Price == item.Price); } else { item2 = helper.QueryItem <TModel>(b => b.UserId == item.UserId && b.ProductId == item.ProductId && b.StyleId == item.StyleId && b.CartType == item.CartType); } if (item2 == null) { //int n = GetCartCount(item.CartType) + 1; //SetCartCount(item.CartType,n); base.Add(item); } else { AddNum(item); } return(GetCartCount(item.CartType)); }
/// <summary> /// 添加到购物车 /// </summary> /// <param name="item"></param> public static int Add(ICartItem item, bool groupByPrice = false) { DBExtend helper = dbHelper; ICartItem item2; if (groupByPrice) { item2 = helper.QueryItem <ICartItem>(b => b.UserId == item.UserId && b.ProductId == item.ProductId && b.StyleId == item.StyleId && b.CartType == item.CartType && b.Price == item.Price); } else { item2 = helper.QueryItem <ICartItem>(b => b.UserId == item.UserId && b.ProductId == item.ProductId && b.StyleId == item.StyleId && b.CartType == item.CartType); } if (item2 == null) { //int n = GetCartCount(item.CartType) + 1; //SetCartCount(item.CartType,n); Add <ICartItem>(item); } else { AddNum(item); } return(GetCartCount(item.CartType)); }
/// <summary> /// 查询订单第一个产品 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public static IOrderDetail QueryFirstOrderDetail(string orderId) { DBExtend helper = dbHelper; var orderDetail = helper.QueryItem <IOrderDetail>(b => b.OrderId == orderId); return(orderDetail); }
/// <summary> /// 查询一个订单 /// </summary> public static TMain Query <TMain>(string orderId) where TMain : IOrder, new() { string table = Base.GetTableName(typeof(TMain)); DBExtend helper = dbHelper; TMain orderMain = helper.QueryItem <TMain>(b => b.OrderId == orderId); return(orderMain); }
/// <summary> /// 移除一项 /// </summary> /// <param name="userId"></param> /// <param name="id"></param> public static bool Remove(string userId, int id) { DBExtend helper = dbHelper; var cartItem = helper.QueryItem <ICartItem>(b => b.UserId == userId && b.Id == id); if (cartItem != null) { //int n = GetCartCount(cartItem.CartType) - cartItem.Num; //SetCartCount(cartItem.CartType, n); } return(Delete <ICartItem>(b => b.UserId == userId && b.Id == id) > 0); }
/// <summary> /// 检测是否存在,并添加 /// </summary> /// <typeparam name="TItem"></typeparam> /// <param name="p"></param> /// <returns></returns> public static new int Add(IFreight p) { DBExtend helper = dbHelper; IFreight item = helper.QueryItem <IFreight>(b => b.AreaId == p.AreaId && b.DeliverType == p.DeliverType); if (item != null) { return(0); } //helper.Clear(); int id = helper.InsertFromObj(p); return(id); }
//public static IAccountDetail GetAccount(string account, int transactionType) //{ // return GetAccount(account, 0, transactionType); //} /// <summary> /// 取得帐号信息,没有则创建(实时) /// </summary> /// <param name="account"></param> /// <param name="accountType"></param> /// <param name="transactionType"></param> /// <returns></returns> public static IAccountDetail GetAccount(string account, int accountType, int transactionType) { DBExtend helper = dbHelper; IAccountDetail info = helper.QueryItem <IAccountDetail>(b => b.Account == account && b.TransactionType == transactionType && b.AccountType == accountType); if (info == null) { info = new IAccountDetail(); info.Account = account; info.AccountType = accountType; info.TransactionType = transactionType; CreateAccount(info); } return(info); }
/// <summary> /// 更改数量 /// </summary> /// <param name="userId"></param> /// <param name="num"></param> /// <param name="id"></param> public static void ChangeNum(string userId, int num, int id) { DBExtend helper = dbHelper; var cartItem = helper.QueryItem <ICartItem>(b => b.UserId == userId && b.Id == id); if (cartItem != null) { //int n = GetCartCount(cartItem.CartType) + num - cartItem.Num; //SetCartCount(cartItem.CartType, n); } ParameCollection c = new ParameCollection(); c["Num"] = num; helper.Update <ICartItem>(b => b.UserId == userId && b.Id == id, c); }
/// <summary> /// 解锁金额,没有事务 /// </summary> public bool UnlockAmount(DBExtend helper, int lockedId, out string message) { //helper.Clear(); var lockRecord = helper.QueryItem <ILockRecord>(b => b.Id == lockedId); message = ""; if (lockRecord == null) { message = "找不到锁ID:" + lockedId; return(false); } if (lockRecord.Checked) { message = "该锁已经解过ID:" + lockedId; return(false); } string key = string.Format("UnlockAmount_{0}", lockedId); if (!CoreHelper.ConcurrentControl.Check(key)) { message = "同时提交了多次相同的参数" + key; return(false); } string sql = "update $IAccountDetail set LockedAmount=LockedAmount-b.Amount from $ILockRecord b where $IAccountDetail.id=b.AccountId and b.id=@id "; //sql += "update $ILockRecord set checked=1 where id=@id"; sql += "delete from $ILockRecord where id=@id"; //sql = FormatTable(sql); helper.AddParam("id", lockedId); int count; try { count = helper.Execute(sql, typeof(IAccountDetail), typeof(ILockRecord)); } catch (Exception ero) { CoreHelper.ConcurrentControl.Remove(key); CoreHelper.EventLog.Log("UnlockAmount 执行出错" + ero, true); message = ero.Message; return(false); } CoreHelper.ConcurrentControl.Remove(key); return(true); }
/// <summary> /// 判断流水是否提交过 /// </summary> /// <param name="item"></param> /// <returns></returns> public bool CheckTransactionSubmited(DBExtend helper, ITransaction item) { return(helper.QueryItem <ITransaction>(b => b.AccountId == item.AccountId && b.TradeType == item.TradeType && b.Hash == item.Hash, true, true) != null); }