Ejemplo n.º 1
0
        /// <summary>
        /// 获取已经支付未完成的的订单
        /// </summary>
        /// <param name="requst"></param>
        /// <returns></returns>
        public bool ExistsPayReg(RequestUserOPDRegisterSubmitDTO requst, out OrderRepeatReturnDTO order)
        {
            using (DBEntities db = new DBEntities())
            {
                OrderRepeatReturnDTO opdModel = null;
                opdModel = (from opd in db.UserOpdRegisters.Where(a => a.UserID == requst.UserID &&
                                                                  a.MemberID == requst.MemberID && a.OPDType == requst.OPDType &&
                                                                  a.IsDeleted == false)
                            join opdOrder in db.Orders on opd.OPDRegisterID equals opdOrder.OrderOutID
                            join room in db.ConversationRooms on opd.OPDRegisterID equals room.ServiceID
                            where opdOrder.OrderState == EnumOrderState.Paid &&
                            room.RoomState != EnumRoomState.AlreadyVisit
                            orderby opdOrder.OrderTime descending
                            select new OrderRepeatReturnDTO
                {
                    OrderOutID = opd.OPDRegisterID,
                    OrderNo = opdOrder.OrderNo,
                    OrderState = opdOrder.OrderState,
                    ChannelID = room.ChannelID,
                    DoctorID = opd.DoctorID,
                }).FirstOrDefault();

                //已经预约了
                if (opdModel != null)
                {
                    order = opdModel;
                    return(true);
                }
                else
                {
                    order = null;
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 提交预约
        /// </summary>
        /// <param name="request"></param>
        /// <param name="CheckExists">是否检查重复预约</param>
        /// <returns></returns>
        public ResponseUserOPDRegisterSubmitDTO Submit(RequestUserOPDRegisterSubmitDTO request)
        {
            #region 校验失败:重复预约
            var existsOrder = new OrderRepeatReturnDTO();

            if (ExistsWithSubmitRequest(request, out existsOrder))
            {
                if (existsOrder.OrderState == EnumOrderState.NoPay)
                {
                    return(new ResponseUserOPDRegisterSubmitDTO
                    {
                        ErrorInfo = "预约成功",
                        ActionStatus = "Success",
                        OPDRegisterID = existsOrder.OrderOutID,
                        OrderNO = existsOrder.OrderNo,
                        OrderState = existsOrder.OrderState,
                        ChannelID = existsOrder.ChannelID
                    });
                }
                else
                {
                    return(new ResponseUserOPDRegisterSubmitDTO
                    {
                        ErrorInfo = "已有未完成的预约,不能重复预约",
                        OPDRegisterID = existsOrder.OrderOutID,
                        OrderNO = existsOrder.OrderNo,
                        OrderState = existsOrder.OrderState,
                        ChannelID = existsOrder.ChannelID,
                        ActionStatus = "Repeat"
                    });
                }
            }
            #endregion

            using (DAL.EF.DBEntities db = new DBEntities())
            {
                var Reason = "";

                var orderService = new OrderService(CurrentOperatorUserID);

                //获取服务价格
                decimal ServicePrice    = 0.01M;
                var     OPDDate         = DateTime.Now;
                var     OPDBeginTime    = DateTime.Now.ToString("HH:mm");
                var     OPDEndTime      = DateTime.Now.AddMinutes(30).ToString("HH:mm");
                var     OrderExpireTime = DateTime.Now.AddMinutes(30);

                RequestUserMemberDTO member = new UserMemberService().
                                              GetDefaultMemberInfo(request.UserID).Map <ResponseUserMemberDTO, RequestUserMemberDTO>();


                #region 新增预约记录
                UserOPDRegister model = new UserOPDRegister()
                {
                    CreateUserID   = request.UserID,
                    OPDType        = request.OPDType,
                    MemberID       = request.MemberID,
                    Fee            = ServicePrice,//服务价格
                    OPDRegisterID  = Guid.NewGuid().ToString("N"),
                    UserID         = request.UserID,
                    ConsultContent = string.IsNullOrEmpty(request.ConsultContent) ? "" : request.ConsultContent,
                };

                if (member != null)
                {
                    model.MemberName = member.MemberName;
                    model.Gender     = member.Gender;
                    model.Marriage   = member.Marriage;
                    model.Age        = member.Age;
                    model.IDNumber   = string.IsNullOrEmpty(member.IDNumber) ? "" : member.IDNumber;
                    model.IDType     = member.IDType;
                    model.Mobile     = member.Mobile;
                    model.Address    = member.Address;
                    model.Birthday   = member.Birthday;
                }

                db.UserOpdRegisters.Add(model);

                #endregion

                #region 添加附件
                if (request.Files != null)
                {
                    foreach (var file in request.Files)
                    {
                        db.UserFiles.Add(new UserFile()
                        {
                            FileID     = Guid.NewGuid().ToString("N"),
                            FileName   = file.FileUrl,
                            FileUrl    = file.FileUrl,
                            FileType   = 0,
                            Remark     = file.Remark,
                            AccessKey  = "",
                            ResourceID = "",
                            OutID      = model.OPDRegisterID,
                            UserID     = request.UserID
                        });
                    }
                }
                #endregion

                #region 创建房间
                var room = new Entity.ConversationRoom();
                room.EndTime            = DateTime.Parse(OPDDate.ToString("yyyy-MM-dd ") + OPDEndTime);
                room.BeginTime          = DateTime.Parse(OPDDate.ToString("yyyy-MM-dd ") + OPDBeginTime);
                room.TotalTime          = 0;
                room.RoomState          = EnumRoomState.NoTreatment;//状态
                room.ConversationRoomID = Guid.NewGuid().ToString("N");
                room.ServiceID          = model.OPDRegisterID;
                room.ServiceType        = model.OPDType;
                //如果预约类型是挂号那么房间类型就是线下看诊,否则是线上看诊
                room.RoomType = EnumRoomType.Group;
                db.Set <ConversationRoom>().Add(room);
                #endregion

                #region 创建订单

                EnumProductType ProductType = EnumProductType.Other;

                switch (model.OPDType)
                {
                case EnumDoctorServiceType.VidServiceType:
                    ProductType = EnumProductType.video;
                    break;

                default:
                    break;
                }

                var order = orderService.CreateOrder(new OrderDTO()
                {
                    OrderType       = ProductType,
                    OrderOutID      = model.OPDRegisterID,
                    UserID          = model.UserID,
                    OrderTime       = DateTime.Now,
                    OrderExpireTime = OrderExpireTime,
                    Details         = new List <OrderDetailDTO>()
                    {
                        new OrderDetailDTO()
                        {
                            Subject     = ProductType.GetEnumDescript(),
                            Body        = "",
                            ProductId   = "",
                            ProductType = ProductType,
                            Quantity    = 1,
                            UnitPrice   = model.Fee
                        }
                    }
                }, db);

                #endregion

                if (db.SaveChanges() > 0)
                {
                    //确定订单
                    if (orderService.Confirm(order.OrderNo, new RequestOrderConfirmDTO()
                    {
                        OrderNo = order.OrderOutID,
                    }) == EnumApiStatus.BizOK)
                    {
                        order = orderService.GetOrder(order.OrderNo);

                        return(new ResponseUserOPDRegisterSubmitDTO
                        {
                            ErrorInfo = "预约成功",
                            ActionStatus = "Success",
                            OPDRegisterID = model.OPDRegisterID,
                            OrderNO = order.OrderNo,
                            OrderState = order.OrderState,
                            ChannelID = room.ChannelID
                        });
                    }
                    else
                    {
                        orderService.Cancel(order.OrderNo);
                    }
                }

                return(new ResponseUserOPDRegisterSubmitDTO
                {
                    ErrorInfo = "预约失败",
                    ActionStatus = "Fail",
                });
            }
        }