Пример #1
0
        public APIResult GetOrderItems([FromBody] GetOrderItemsArgsModel args)
        {
            if (args.OrderType.Equals(OrderTypeE.拼团订单))
            {
                var model = db.GetSingle <ConglomerationOrder>(args.OrderId);
                if (model == null)
                {
                    throw new Exception("订单记录不存在");
                }
                //获取到订单后判断是否拥有指定的店铺的权限
                CheckShopActor(model.ShopId, ShopActorType.超级管理员);
            }
            else
            {
                var model = db.GetSingle <ShopOrder>(args.OrderId);
                if (model == null)
                {
                    throw new Exception("订单记录不存在");
                }
                //获取到订单后判断是否拥有指定的店铺的权限
                CheckShopActor(model.ShopId, ShopActorType.超级管理员);
            }


            var orderContext = new OrderContext(args.OrderType, _mapper);

            if (args.OrderType.Equals(OrderTypeE.拼团订单))
            {
                var query      = orderContext.ExecuteGetOrderItems <ConglomerationOrderModel>(args, db);
                var shopMember = db.ShopMembers.FirstOrDefault(m => !m.IsDel && m.MemberId.Equals(query.MemberId));
                query.OrderShopMember = _mapper.Map <OrderShopMember>(shopMember);
                return(Success(query));
            }
            else
            {
                var query = orderContext.ExecuteGetOrderItems <List <ShopOrderItem> >(args, db);
                var list  = query
                            .Where(m => m.ShopOrderId == args.OrderId)
                            .OrderByDescending(m => m.Id)
                            .Select(m => new
                {
                    AddTime       = m.AddTime,
                    Id            = m.Id,
                    AddIp         = m.AddIp,
                    AddUser       = m.AddUser,
                    CommodityName = m.CommodityName,
                    CostPrice     = m.CostPrice,
                    Count         = m.Count,
                    MarketPrice   = m.MarketPrice,
                    SalePrice     = m.SalePrice,
                    SkuSummary    = m.SkuSummary
                })
                            .ToList();

                ShopOrder shopOrder = db.Query <ShopOrder>()
                                      .Where(m => m.Id == args.OrderId)
                                      .Include(m => m.ShopOrderOtherFee)
                                      .Include(m => m.ShopOrderSelfHelp)
                                      .Include(m => m.ShopOrderMoneyOffRule)
                                      .Include(m => m.ShopPart)
                                      .FirstOrDefault();
                GetOrderInfoResultModel rtn = new GetOrderInfoResultModel()
                {
                    Code       = shopOrder.OrderNumber,
                    CreateTime = shopOrder.AddTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    PayTime    = shopOrder.PayTime?.ToString("yyyy-MM-dd HH:mm:ss"),
                    PayMent    = shopOrder.Payment / 100m,
                    Remark     = shopOrder.Remark ?? "",
                    PayWay     = shopOrder.PayWay ?? ""
                };
                if (shopOrder.ShopOrderMoneyOffRule != null)
                {
                    rtn.MoneyOffRule = new MoneyOffRule()
                    {
                        Discount   = shopOrder.ShopOrderMoneyOffRule.Discount / 100m,
                        FullAmount = shopOrder.ShopOrderMoneyOffRule.FullAmount / 100m
                    };
                }
                if (shopOrder.ShopOrderOtherFee != null)
                {
                    rtn.OtherFee = new OtherFee()
                    {
                        BoxFee      = shopOrder.ShopOrderOtherFee.BoxFee / 100m,
                        DeliveryFee = shopOrder.ShopOrderOtherFee.DeliveryFee / 100m
                    };
                }
                if (shopOrder.ShopOrderSelfHelp != null)
                {
                    rtn.SelfHelp = new SelfHelpInfo()
                    {
                        SelfHelpCode = shopOrder.ShopOrderSelfHelp.Number,
                        TakeWay      = shopOrder.ShopOrderSelfHelp.IsTakeOut ? "外带" : "堂食"
                    };
                }
                if (shopOrder.ShopPart != null)
                {
                    rtn.ShopPartName = shopOrder.ShopPart.Title;
                }
                if (shopOrder.IsTakeOut)
                {
                    var takeOut = db.Query <ShopOrderTakeout>()
                                  .Where(m => m.ShopOrderId == shopOrder.Id)
                                  .FirstOrDefault();
                    rtn.TakeOutInfo = new TakeOutInfo()
                    {
                        DiningWay  = takeOut.TakeWay.ToString(),
                        PickTile   = takeOut.TakeWay == TakeWay.自提 ? "预计自提时间" : "期望配送时间",
                        PickUpTime = takeOut.PickupTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        Address    = takeOut.Address,
                        Person     = takeOut.Name,
                        Phone      = takeOut.Phone
                    };
                }

                var shopMember = db.ShopMembers.FirstOrDefault(m => !m.IsDel && m.MemberId.Equals(shopOrder.MemberId));
                rtn.Items           = list;
                rtn.OrderShopMember = _mapper.Map <OrderShopMember>(shopMember);



                return(Success(rtn));
            }
        }