Beispiel #1
0
        public static PageOfList <TResult> ToList <T, TResult>(this QueryObject <T> query, int pageIndex, int pageSize, string orderBy, Func <T, TResult> selector) where T : new()
        {
            var             totalItemCount = (int)query.Count();
            IEnumerable <T> list           = query.ToList((pageIndex - 1) * pageSize, pageSize, orderBy);

            return(ToList(pageIndex, pageSize, orderBy, selector, list, totalItemCount));
        }
Beispiel #2
0
        public void OnOrderCancelTimer(object source, System.Timers.ElapsedEventArgs e)
        {
            string sql  = "select * from fz_Orders where orderState=1 and DATEDIFF(mi,submitTime,GETDATE())>30";
            var    list = new QueryObject <Order>(_databaseInstance, sql, null).ToList();

            if (list != null && list.Count() > 0)
            {
                foreach (var item in list)
                {
                    var tran = _databaseInstance.BeginTransaction();
                    try
                    {
                        var order = IOrderService.GetById(item.orderId);
                        if (order.orderState == OrderStates.awaitPay)
                        {
                            if (order.orderType == OrderType.normal)
                            {
                                var details = IOrderDetailService.GetAllByOrderNo(order.orderNo).ToList();
                                if (details != null && details.Count() > 0)
                                {
                                    foreach (var detail in details)
                                    {
                                        var commodit = ICommodityService.GetById(detail.commodityId);
                                        if (commodit != null)
                                        {
                                            commodit.commodityInventory += detail.quantity;
                                            commodit.sellQuantity       -= detail.quantity;
                                            commodit.sellQuantity1      -= detail.quantity;
                                            ICommodityService.Update(commodit);
                                        }
                                    }
                                }
                            }
                            else if (order.orderType == OrderType.secondKill)
                            {
                                var details = IOrderDetailService.GetAllByOrderNo(order.orderNo).ToList();
                                if (details != null && details.Count() > 0)
                                {
                                    foreach (var detail in details)
                                    {
                                        var secondKillCommodity = ISecondKillCommoditysService.GetBycommodityId(detail.commodityId);
                                        if (secondKillCommodity != null)
                                        {
                                            secondKillCommodity.payNum     -= detail.quantity;
                                            secondKillCommodity.surplusNum += detail.quantity;
                                            ISecondKillCommoditysService.Update(secondKillCommodity);
                                        }
                                    }
                                }
                            }
                            order.orderState   = OrderStates.cancel;
                            order.completeTime = DateTime.Now;
                            IOrderService.Update(order);
                            tran.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        tran.Rollback();
                        log.Debug(string.Format("取消订单出错:{0}!", ex.Message));
                    }
                    finally
                    {
                        tran.Dispose();
                    }
                }
            }
        }