public ActionResult Void(RMAInfoRequest request, UserModel authUser)
         {
             if (!ModelState.IsValid)
             {
                 var error = ModelState.Values.Where(v => v.Errors.Count() > 0).First();
                 return this.RenderError(r => r.Message = error.Errors.First().ErrorMessage);
             }
             var rmaEntity = Context.Set<RMAEntity>().Where(r => r.RMANo == request.RMANo).FirstOrDefault();
             if (rmaEntity == null)
             {
                 return this.RenderError(r => r.Message = "RMANo不存在");
             }
           
             if (!RMARule.CanVoid(rmaEntity.Status))
             {
                 return this.RenderError(r => r.Message = "RMA状态不正确");
             }
             using (var ts = new TransactionScope())
             {
              
                 rmaEntity.UpdateDate = DateTime.Now;
                 rmaEntity.UpdateUser = authUser.Id;
                 rmaEntity.Status = (int)RMAStatus.Void;
                 _rmaRepo.Update(rmaEntity);

                 _rmalogRepo.Insert(new RMALogEntity()
                 {
                     CreateDate = DateTime.Now,
                     CreateUser = authUser.Id,
                     RMANo = request.RMANo,
                     Operation = "取消退货单"
                 });
                 // call erp service to void rma
                 var rmaMap = Context.Set<RMA2ExEntity>().Where(r=>r.RMANo == rmaEntity.RMANo).FirstOrDefault();
                 if (rmaMap == null || string.IsNullOrEmpty(rmaMap.ExRMA))
                    ts.Complete();
                 var erpRma = new List<dynamic>() { new {
                     Orders_refund_frt_sid = rmaMap.ExRMA,
                     REAL_NAME = authUser.Nickname,
                     USER_SID = "0"

                 }};
                 bool isSuccess = ErpServiceHelper.SendHttpMessage(ConfigManager.ErpBaseUrl, new { func = "Cancel_Refund", jsonRefunds = new { Data =erpRma } }, null
                 , null);
                 if (isSuccess)
                    ts.Complete();
                 else
                    return this.RenderError(r => r.Message = "退货单取消失败!");
             }

             return this.RenderSuccess<RMAInfoResponse>(null);
         }
        public ActionResult Detail(RMAInfoRequest request, UserModel authUser)
        {
            var rmaEntity = Context.Set<RMAEntity>().Where(r => r.RMANo == request.RMANo).FirstOrDefault();
            if (rmaEntity == null)
                return this.RenderError(r => r.Message = "RMANo 不存在");
            var response = new RMAInfoResponse().FromEntity<RMAInfoResponse>(rmaEntity, r => { 
                var rmaItemsEntity = Context.Set<RMAItemEntity>().Where(ri=>ri.RMANo== request.RMANo)
                                .GroupJoin(Context.Set<ResourceEntity>().Where(resource=>resource.SourceType==(int)SourceType.Product),
                                        o=>o.ProductId,
                                        i=>i.SourceId,
                                        (o,i)=>new {R=o,RR=i.OrderByDescending(resource=>resource.SortOrder).FirstOrDefault()});
                r.CanVoid =  RMARule.CanVoid(r.Status);

                r.Products = rmaItemsEntity.ToList().Select(ri=>new RMAItemInfoResponse().FromEntity<RMAItemInfoResponse>(ri,ritem=>{
                   ritem.ProductResource = new ResourceInfoResponse().FromEntity<ResourceInfoResponse>(ri.RR);
                    
                }));
                

            });
            return this.RenderSuccess<RMAInfoResponse>(r=>r.Data = response);
        }