/// <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> /// <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> /// 获取订单备注 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); })); }