/// <summary> /// 获取订单 /// </summary> /// <param name="id">订单id</param> /// <param name="userId">用户id</param> /// <param name="isSeller">是否为卖家</param> /// <param name="includeItems">是否包含明细</param> /// <returns></returns> public Order OrderGet(string id, int userId, bool isSeller, bool includeItems = false) { return(Try(nameof(OrderGet), () => { if (includeItems) { var sql = @"select * from orderinfo where id=@id and BuyerId=@userId;select * from orderitem where orderid=@id and BuyerId=@userId;"; if (isSeller) { sql = @"select * from orderinfo where id=@id and SellerId=@userId;select * from orderitem where orderid=@id and SellerId=@userId;;"; } var cmd = SqlBuilder.Raw(sql, new { id, userId }).ToCommand(); using (var reader = TradeConn.QueryMultiple(cmd)) { var o = reader.Read <Order>().FirstOrDefault(); if (o != null) { o.Items = reader.Read <OrderItem>().ToList(); } return o; } } else { var cmd = SqlBuilder .Select("*").From("orderinfo") .Where("id=@id", new { id }) .Where(isSeller ? "SellerId=@userId" : "BuyerId=@userId", new { userId }) .ToCommand(); return TradeConn.QueryFirstOrDefault <Order>(cmd); } })); }
/// <summary> /// 模块 列表 /// </summary> /// <returns></returns> public IList <RBAC.Module> ModuleWidthFuncList() { var sql = @"select * from Module;select * from Func;"; return(Try(nameof(ModuleWidthFuncList), () => { var cmd = SqlBuilder.Raw(sql).ToCommand(); using (var reader = TradeConn.QueryMultiple(cmd)) { var ms = reader.Read <RBAC.Module>(); if (ms != null) { var fs = reader.Read <RBAC.Func>(); if (fs != null) { foreach (var m in ms) { m.Funcs = fs.Where(x => x.Mid == m.Id).ToList(); } } } return ms.ToList(); } })); }
/// <summary> /// 延迟订单有效期 /// </summary> /// <param name="id">订单id</param> /// <param name="sellerId"></param> /// <param name="day"></param> /// <returns></returns> public bool OrderDelay(string id, int sellerId, int day) { return(Try(nameof(OrderDelay), () => { var cmd = SqlBuilder.Update("orderinfo") .Column("ExpiredOn=date_add(now(),interval " + day + " day)") .Where("Id=@Id and SellerId=@sellerId", new { id, sellerId }) .ToCommand(); return TradeConn.Execute(cmd) > 0; })); }
/// <summary> /// 获取订单信息 /// </summary> /// <param name="id">订单id</param> /// <returns></returns> public OrderMini OrderMiniGet(string id, int userId) { var fields = "Id,Type,Quantity,SubTotal,Freight,Tax,Discount,Total,Paid,PayId,PaidOn,PointUse,PointRealUse,PointReward,Coupon,CouponUse,GiftCard,GiftCardUse,Weight,ETicket,IsVirtual,IsBonded,IsOversea,PaymentType,ShipmentType,ExpiredOn,BuyerId,BuyerName,SellerId,SellerName,MediaId,TraceCode,Status,CreatedOn"; return(Try(nameof(OrderMiniGet), () => { var cmd = SqlBuilder .Select(fields) .From("orderinfo") .Where("Id=@Id", new { id }) .ToCommand(0); return TradeConn.QueryFirstOrDefault <OrderMini>(cmd); })); }
/// <summary> /// 获取订单状态 /// </summary> /// <param name="id">订单id</param> /// <param name="userId">用户id</param> /// <param name="isSeller">是否为卖家</param> /// <returns></returns> public OrderStatus OrderStatusGet(string id, int userId, bool isSeller) { return(Try(nameof(OrderStatusGet), () => { var cmd = SqlBuilder .Select("Status") .From("orderinfo") .Where("Id=@Id", new { id }) .Where(isSeller ? "SellerId=@userId" : "BuyerId=@userId", new { userId }) .ToCommand(0); return TradeConn.ExecuteScalar <OrderStatus>(cmd); })); }
/* * /// <summary> * /// 更新订单状态 * /// </summary> * /// <param name="id">订单id</param> * /// <param name="status">订单状态</param> * /// <returns></returns> * public bool OrderStatusUpdate(string id, OrderStatus status) * { * return Try(nameof(OrderStatusUpdate), () => * { * var sql = @"update orderinfo set status=@statue where id=@id"; * * return TradeConn.Execute(sql, new { id, status }) > 0; * }); * } */ /// <summary> /// 更新订单已付金额及状态 /// </summary> /// <param name="id">订单id</param> /// <param name="amount">本次支付金额</param> /// <param name="done">是否已付清(付清后如果是在线支付订单则会更新订单状态为已付款待发货并更新订单有效期)</param> /// <returns></returns> public bool OrderPaid(string id, decimal amount, bool done) { var time = DateTime.Now; var expire = time.AddDays(7); return(Try(nameof(OrderPaid), () => { var sql = @"update orderinfo set Paid=Paid+@amount,PaidOn=@time where status=2 and id=@id"; if (done) { sql = @"update orderinfo set Paid=Paid+@amount,PaidOn=@time,ExpiredOn=@expire,Status=3 where status=2 and id=@id"; } return TradeConn.Execute(sql, new { id, amount, time, expire }) > 0; })); }
/// <summary> /// 取消订单 /// </summary> /// <param name="id">订单id</param> /// <param name="userId">用户id</param> /// <param name="isSeller">是否为卖家</param> /// <param name="cancelId">取消类型 0为none 1为系统取消 2为买家取消 3为卖家取消</param> /// <param name="cancelReason">取消原因</param> /// <returns></returns> public bool OrderCancel(string id, int userId, bool isSeller, byte cancelId, string cancelReason = "") { return(Try(nameof(OrderMemoGet), () => { var cmd = SqlBuilder.Update("orderinfo") .Column("Status", OrderStatus.Canceled) .Column("CancelId", cancelId) .Column("CancelReason", cancelReason) .Column("FinishedOn", DateTime.Now) .Where(isSeller ? "SellerId=@userId" : "BuyerId=@userId", new { userId }) .Where("Id=@Id", new { id }) .ToCommand(); return TradeConn.Execute(cmd) > 0; })); }
/// <summary> /// 更新订单备注 /// </summary> /// <param name="id">订单id</param> /// <param name="userId">用户id</param> /// <param name="isSeller">是否为卖家</param> /// <param name="flag">标识</param> /// <param name="memo">备注</param> /// <returns></returns> public bool OrderMemoUpdate(string id, int userId, bool isSeller, byte flag, string memo) { return(Try(nameof(OrderMemoGet), () => { var cmd = SqlBuilder.Update("orderinfo") .Column(isSeller, "SellerFlag", flag) .Column(isSeller, "SellerMemo", memo) .Column(!isSeller, "BuyerFlag", flag) .Column(!isSeller, "BuyerMemo", memo) .Where(isSeller ? "SellerId=@userId" : "BuyerId=@userId", new { userId }) .Where("Id=@Id", new { id }) .ToCommand(); return TradeConn.Execute(cmd) > 0; })); }
///<summary> /// 订单Note创建 ///</summary> ///<param name="o">订单Note</param> ///<returns></returns> public int OrderNoteCreate(OrderNote o) { return(Try(nameof(OrderNoteCreate), () => { var cmd = SqlBuilder.Insert("OrderNote") .Column("Type", o.Type) .Column("UserId", o.UserId) .Column("OrderId", o.OrderId) .Column("Subject", o.Subject) .Column("Message", o.Message) .Column("Extra", o.Extra) .Column("CreatedBy", o.CreatedBy) .Column("CreatedOn", o.CreatedOn) .ToCommand(true); return TradeConn.ExecuteScalar <int>(cmd); })); }
public IPagedList <Order> OrderPagedList() { return(Try(nameof(OrderPagedList), () => { var cmd = SqlBuilder.Select("*") .From("orderinfo") .ToCommand(1, 50); var list = TradeConn.PagedList <Order>(1, 50, cmd); var ids = list.Select(x => x.Id).Aggregate((a, b) => "'" + a + "','" + b + "'"); var sql = "select * from orderitem where orderid in(" + ids + ")"; var items = TradeConn.Query <OrderItem>(sql); foreach (var o in list) { o.Items = items.Where(x => x.OrderId == o.Id).ToList(); } return list; })); }
/// <summary> /// 获取订单备注 Flag Memo Message /// </summary> /// <param name="id">订单id</param> /// <param name="userId">用户id</param> /// <param name="isSeller">是否为卖家</param> /// <returns></returns> public Magic <byte, string, string> OrderMemoGet(string id, int userId, bool isSeller) { return(Try(nameof(OrderMemoGet), () => { var fields = "BuyerFlag as First,BuyerMemo as Second,BuyerMessage as Third"; if (isSeller) { fields = "SellerFlag as First,SellerMemo as Second,'' as Third"; } var cmd = SqlBuilder.Select(fields) .From("orderinfo") .Where("Id=@Id", new { id }) .Where(isSeller, "SellerId=@userId", new { userId }) .Where(!isSeller, "BuyerId=@userId", new { userId }) .ToCommand(0); return TradeConn.QueryFirstOrDefault <Magic <byte, string, string> >(cmd); })); }