Esempio n. 1
0
        public ActionResult Void(MyOrderDetailRequest request, UserModel authUser)
        {
            var dbContext = Context;
            var linq = dbContext.Set<OrderEntity>().Where(o => o.OrderNo == request.OrderNo && o.CustomerId == authUser.Id).FirstOrDefault();   
            if (linq == null)
            {
                return this.RenderError(m => m.Message = "订单号不存在");
            }
            var itemsEntity = dbContext.Set<OrderItemEntity>().Where(o => o.OrderNo == request.OrderNo).ToList();
            var currentStatus = linq.Status;
           var voidStatus = new int[]{(int)OrderStatus.Create,(int)OrderStatus.Paid,
               (int)OrderStatus.PassConfirmed,
               (int)OrderStatus.PreparePack};
           if (!voidStatus.Any(s=>s==currentStatus))
           {
               return this.RenderError(m => m.Message = "订单状态现在不能取消");
           }
           using (var ts = new TransactionScope())
           {
               linq.Status = (int)OrderStatus.Void;
               linq.UpdateDate = DateTime.Now;
               linq.UpdateUser = authUser.Id;
               _orderRepo.Update(linq);

               foreach (var item in itemsEntity)
               {
                   var inventoryEntity = dbContext.Set<InventoryEntity>().Where(i => i.ProductId == item.ProductId && i.PColorId == item.ColorValueId && i.PSizeId == item.SizeValueId).FirstOrDefault();
                   if (inventoryEntity == null)
                       continue;
                   inventoryEntity.Amount += item.Quantity;
                   _inventoryRepo.Update(inventoryEntity);
               }

               _orderlogRepo.Insert(new OrderLogEntity() {
                 CreateDate = DateTime.Now,
                  CreateUser = authUser.Id,
                   CustomerId = authUser.Id,
                     OrderNo = linq.OrderNo,
                      Type = (int)OrderOpera.CustomerVoid,
                       Operation="用户取消订单。"
               });
               
               bool isSuccess = false;
               if (currentStatus != (int)OrderStatus.Create)
               {
                   //create ex rma request here to refund
                   var products = dbContext.Set<OrderItemEntity>().Where(o => o.OrderNo == linq.OrderNo)
                     .Select(oi => new RMAProductDetailRequest()
                     {
                         ProductId = oi.ProductId,
                         Properties = new ProductPropertyValueRequest() { 
                             ColorValueId = oi.ColorValueId,
                              SizeValueId = oi.SizeValueId
                         },
                          Quantity = oi.Quantity
                     });
                   var result = DoRMA(new RMARequest() {
                     OrderNo = linq.OrderNo,
                     RMAReason = ConfigManager.VoidOrderRMAReason,
                      Reason = "取消订单",
                     Products = JsonConvert.SerializeObject(products)
                   }, authUser,false) as RestfulResult;
                   if (result.Data is ExecuteResult<MyRMAResponse>)
                   {
                       isSuccess = true;
                   }
               }
               else {
                   isSuccess = ErpServiceHelper.SendHttpMessage(ConfigManager.ErpBaseUrl, new { func = "CancelOrders", dealCode = linq.OrderNo}, null
                  , null);
                   
               }
               if (isSuccess)
               {
                   ts.Complete();

               }
               else
               {
                   return this.RenderError(r => r.Message = "取消失败");
               }
               
           }
           return Detail(request, authUser);
          
        }
Esempio n. 2
0
        public ActionResult Detail(MyOrderDetailRequest request, UserModel authUser)
        {
            var dbContext = Context;
            var linq = dbContext.Set<OrderEntity>().Where(o => o.OrderNo == request.OrderNo && o.CustomerId == authUser.Id)
                        .GroupJoin(dbContext.Set<OrderItemEntity>(),
                            o => o.OrderNo,
                            i => i.OrderNo,
                            (o, i) => new { O = o, OI = i })
                        .FirstOrDefault();
            if (linq == null)
            {
                return this.RenderError(m => m.Message = "订单号不存在");
            }
            var result = new MyOrderDetailResponse().FromEntity<MyOrderDetailResponse>(linq.O, o =>
            {

                o.Products =linq.OI.Select(oi=> new MyOrderItemDetailResponse().FromEntity<MyOrderItemDetailResponse>(oi, op =>
                {
                    op.ProductResource = new ResourceInfoResponse().FromEntity<ResourceInfoResponse>(
                            dbContext.Set<ResourceEntity>()
                                     .Where(resource => resource.SourceType == (int)SourceType.Product 
                                                        && resource.SourceId == oi.ProductId
                                                        && resource.ColorId == oi.ColorValueId
                                                        && resource.Type == (int)ResourceType.Image)
                                     .OrderByDescending(resource => resource.SortOrder).FirstOrDefault());
                 


                }));

                o.RMAs = dbContext.Set<RMAEntity>().Where(r => r.OrderNo == o.OrderNo).OrderByDescending(r => r.CreateDate)
                        .ToList()
                        .Select(r => new MyRMAResponse().FromEntity<MyRMAResponse>(r));

                o.Outbounds = dbContext.Set<OutboundEntity>().Where(ob => ob.SourceType == (int)OutboundType.Order && ob.SourceNo == o.OrderNo)
                              .Join(dbContext.Set<ShipViaEntity>(),ob=>ob.ShippingVia,i=>i.Id,(ob,i)=>new {OB=ob,OS=i})
                             .ToList().Select(ob => new MyShipResponse() { 
                                 ShipViaName = ob.OS.Name,
                                  ShipNo = ob.OB.ShippingNo
                             });

            });
            return this.RenderSuccess<MyOrderDetailResponse>(r => r.Data=result);
        }