Example #1
0
        public LongResponse Create(long orderId, long orderGoodsId, string deliveryCompany, string deliveryNumber, OrderReturnType type, OrderReturnReason reason, int count)
        {
            try
            {
                string      op      = ServiceContainer.GetCurrentLoginInfo().op.Number;
                var         ors     = this.GetByOrderIdAndOrderGoodsId(orderId, orderGoodsId);
                OrderReturn or      = null;
                DateTime    minTime = this.GetDbMinTime();

                if (ors != null && ors.Datas.Count > 0)
                {
                    return(new LongResponse(ors.Datas[0].Id));
                }

                var o = ServiceContainer.GetService <OrderService>().GetById(orderId.ToString()).First;

                if (o == null)
                {
                    throw new Exception("订单不存在");
                }

                if ((int)o.State < (int)OrderState.SHIPPED)
                {
                    throw new Exception("订单未发货不能创建退货");
                }

                var og = o.OrderGoodss.FirstOrDefault(obj => obj.Id == orderGoodsId);

                if (og == null)
                {
                    throw new Exception("订单商品不存在");
                }

                if ((int)og.State < (int)OrderState.SHIPPED)
                {
                    throw new Exception("订单未发货不能创建退货");
                }

                or = new OrderReturn
                {
                    Comment         = "",
                    Count           = count,
                    CreateOperator  = op,
                    CreateTime      = DateTime.Now,
                    DeliveryCompany = deliveryCompany,
                    DeliveryNumber  = deliveryNumber,
                    State           = OrderReturnState.WAITPROCESS,
                    GoodsInfo       = og.Vendor + "," + og.Number + " " + og.Edtion + " " + og.Color + " " + og.Size,
                    OrderGoodsId    = orderGoodsId,
                    OrderId         = orderId,
                    ProcessOperator = "",
                    ProcessTime     = minTime,
                    Reason          = reason,
                    Type            = type,
                    GoodsMoney      = og.Price * og.Count,
                    Id         = 0,
                    NewOrderId = 0,
                };
                this.dao.Save(or);
                return(new LongResponse(or.Id));
            }
            catch (Exception ex)
            {
                throw new WebFaultException <ResponseBase>(new ResponseBase(ex.Message), System.Net.HttpStatusCode.OK);
            }
        }