Exemple #1
0
        public ActionResult <Result> PublishAuth([FromBody] dynamic ticket)
        {
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            JObject data = JObject.Parse(ticket.ToString());
            //解析数据
            TTicket tkt = new TTicket
            {
                UserId = user.UserId,
                TypeId = int.Parse(data["TypeId"].ToString())
            };

            TTicketChat tktc = new TTicketChat
            {
                Content = data["Content"].ToString(),
                Annex   = data["Annex"]?.ToString(),
                UserId  = user.UserId
            };

            if (tkt.TypeId != 0 && tkt.TypeId != 400002 && (tkt.TypeId < 600000 || tkt.TypeId >= 700000))
            {
                throw new ResultException("工单类型错误");
            }

            //发布
            ticketServer.Publish(tkt, tktc);

            return(new Result(200, "成功"));
        }
Exemple #2
0
        public ActionResult <Result> Complete(string ticketId)
        {
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            TTicket ticket = ticketServer.Retrieve(new TTicket {
                TicketId = ticketId
            });

            if (ticket == null)
            {
                throw new ResultException("工单不存在");
            }

            ticketServer.Update(new TTicket
            {
                TicketId = ticketId,
                StatusId = 700003
            });

            return(new Result(200, "成功"));
        }
        public string InsertTicket(TTicket ticket, string userId)
        {
            try
            {
                //------------------------------------------------------------//
                // check a valid of Ticket
                //------------------------------------------------------------//
                TicketSaleDateBusiness saleDatebusines = new TicketSaleDateBusiness();
                Ticket newTicket = ThriftUtil.ConvertToEntityObject(ticket) as Ticket;

                string errorMessage = CheckTicketInfo(newTicket);
                errorMessage += saleDatebusines.ValidateDateTime(newTicket.departure_time);

                if (string.IsNullOrEmpty(errorMessage) == false)
                {
                    return(errorMessage);
                }

                TicketBusiness business  = new TicketBusiness();
                string         resultMsg = business.Insert(newTicket);

                ////notify to the others client station
                //ticket.TicketId = ticketId;
                //BroadcastToClient(ClientAction.SellTicket,ticket);

                return(resultMsg);
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[InsertTicket]", exc);
                return(exc.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// 根据状态id获取所工单回复记录
        /// </summary>
        /// <param name="ticketId">工单Id</param>
        /// <param name="statusId">状态Id</param>
        /// <returns></returns>
        dynamic ITicket.RetrieveAllByType(string ticketId, int statusId)
        {
            TTicket t = m_iTicket.Retrieve(new TTicket {
                TicketId = ticketId
            });

            dynamic tc_all = m_db.TTicketChat
                             .Include(i => i.User)
                             .Where(w => w.TicketId == ticketId && (statusId == 700000 ? 1 == 1 : t.StatusId == statusId))
                             .Select(s => new
            {
                s.TicketChatId,
                s.Content,
                s.Annex,
                s.CreateTime,
                s.UserId,
                //User = (s.User!=null?1:2),
                // User = (s.User != null ? new
                // {
                //     s.User.UserId,
                //     s.User.UserName,
                //     s.User.Photo,
                //     s.User.CreateTime
                // } : null)
            })
                             .OrderByDescending(o => o.CreateTime)
                             .ToList();

            JArray list_arr = JArray.FromObject(tc_all);

            foreach (JObject item in list_arr)
            {
                string userId = item["UserId"].ToString();

                item.Remove("UserId");
                if (userId == null)
                {
                    continue;
                }

                TUser user = m_user.Retrieve(new TUser {
                    UserId = userId
                });
                if (user == null)
                {
                    continue;
                }

                var user_fil = new
                {
                    user.UserId,
                    user.UserName,
                    user.Photo,
                    user.CreateTime
                };
                item.Add("user", JObject.FromObject(user_fil));
            }

            return(list_arr);
        }
Exemple #5
0
        /// <summary>
        /// 根据ID获取数据
        /// </summary>
        /// <param name="t">HuobiProject.Models</param>
        /// <returns>
        /// Success:T
        /// Failed:NULL
        /// </returns>
        TTicket ICURD <TTicket> .Retrieve(TTicket t)
        {
            //if (m_redis.HashExists(RedisDB, t.TicketId))
            //    return m_redis.HashGet<TTicket>(RedisDB, t.TicketId);

            return(m_db.TTicket.Find(t.TicketId));
        }
Exemple #6
0
        /// <summary>
        /// 根据ID删除数据
        /// </summary>
        /// <param name="t">HuobiProject.Models</param>
        /// <returns>
        /// Success:T
        /// Failed:F
        /// </returns>
        bool ICURD <TTicket> .Delete(TTicket t)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TTicket tk = m_iTicket.Retrieve(t);
                m_db.TTicket.Remove(tk);
                m_db.SaveChanges();

                m_redis.HashDelete(RedisDB, t.TicketId);

                scope.Complete();
            }
            return(true);
        }
Exemple #7
0
        /// <summary>
        /// 根据ID更新数据
        /// </summary>
        /// <param name="t">HuobiProject.Models</param>
        /// <returns>
        /// True:成功
        /// False:失败
        /// </returns>
        bool ICURD <TTicket> .Update(TTicket t)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TTicket tkt = m_iTicket.Retrieve(t);
                tkt.StatusId   = t.StatusId;
                tkt.ActiveTime = DateTime.Now;

                m_db.SaveChanges();

                //更新Redis
                m_redis.HashSet(RedisDB, tkt.TicketId, tkt);

                scope.Complete();
            }
            return(true);
        }
Exemple #8
0
        /// <summary>
        /// 提交新工单
        /// </summary>
        /// <param name="t">工单信息</param>
        /// <param name="tc">内容信息</param>
        void ITicket.Publish(TTicket t, TTicketChat tc)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                m_iTicket.Create(t);

                m_iTicket.AddReply(t, new TTicketChat
                {
                    TicketId = t.TicketId,
                    Content  = tc.Content,
                    UserId   = tc.UserId,
                    Annex    = tc.Annex
                });

                scope.Complete();
            }
        }
Exemple #9
0
        public ActionResult <Result> Publish([FromBody] dynamic ticket)
        {
            JObject data = JObject.Parse(ticket.ToString());

            //解析数据
            TTicket tkt = new TTicket
            {
                Email  = data["Email"].ToString(),
                TypeId = int.Parse(data["TypeId"].ToString())
            };

            TTicketChat tktc = new TTicketChat
            {
                Content = data["Content"].ToString(),
                Annex   = data["Annex"]?.ToString()
            };

            string reg_email = @"^\w+(?<=[^ ])@\w+\.\w+$";

            if (!Regex.IsMatch(tkt.Email, reg_email))
            {
                throw new ResultException("邮箱格式错误");
            }

            if (tkt.TypeId != 0 && tkt.TypeId != 400002 && (tkt.TypeId < 600000 || tkt.TypeId >= 700000))
            {
                throw new ResultException("工单类型错误");
            }

            //发布
            ticketServer.Publish(tkt, tktc);

            // ticketServer.Create(new TTicket()
            // {
            //     TypeId = ticket.TypeId == 0 ? 400002 : ticket.TypeId,
            //     Email = ticket.Email,
            //     Content = ticket.Content,
            //     Annex = ticket.Annex
            // });
            return(new Result(200, "成功"));
        }
Exemple #10
0
        public ActionResult <Result> Reply([FromBody] TTicketChat tc)
        {
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            TTicket t = ticketServer.Retrieve(new TTicket {
                TicketId = tc.TicketId
            });

            if (t.UserId != user.UserId && user.Super == 0)
            {
                throw new ResultException("无权操作");
            }

            if (t == null)
            {
                throw new ResultException("工单不存在");
            }

            if (tc.Content == null || tc.Content == "")
            {
                throw new ResultException("工单内容为空");
            }

            if (t.UserId != user.UserId)
            {
                t.StatusId = 700002;//等待回复
            }
            ticketServer.AddReply(t, new TTicketChat
            {
                TicketId = t.TicketId,
                Content  = tc.Content,
                Annex    = tc.Annex,
                UserId   = user.UserId
            });

            return(new Result(200, "成功"));
        }
Exemple #11
0
        public ActionResult <Result> RetrieveChats(string ticketId, int statusId, int page, int count)
        {
            string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7));
            TUser  user    = userServer.Retrieve(new TUser()
            {
                UserId = user_id
            });

            TTicket t = ticketServer.Retrieve(new TTicket {
                TicketId = ticketId
            });

            if (t.UserId != user.UserId && user.Super == 0)
            {
                throw new ResultException("无法获取他人工单信息");
            }

            dynamic tc_all = ticketServer.RetrieveAllByType(ticketId, statusId);

            return(new Result(200, "成功", Pagination <dynamic> .Paging(tc_all, page, count)));
        }
Exemple #12
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="t">HuobiProject.Models</param>
        /// <returns>
        /// True:成功
        /// False:失败
        /// </returns>
        bool ICURD <TTicket> .Create(TTicket t)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                Random rand = new Random((int)Tools.Ticks());
                string id   = Tools.Ticks() + "" + rand.Next(1000, 10000);

                t.TicketId = id;
                t.StatusId = 700001;

                t.CreateTime = DateTime.Now;
                t.ActiveTime = t.CreateTime;
                m_db.TTicket.Add(t);
                m_db.SaveChanges();

                m_redis.HashSet(RedisDB, t.TicketId, t);

                scope.Complete();
            }
            return(true);
        }
        public string UpdateTicket(TTicket tticket, string userId)
        {
            try
            {
                using (ThanhVanTranSysEntities context = new ThanhVanTranSysEntities())
                {
                    DateTime departTime    = DateTime.Parse(tticket.DepartTime);
                    var      existedTicket = context.Tickets.FirstOrDefault(t => t.bus_id == tticket.BusId &&
                                                                            t.departure_time == departTime &&
                                                                            t.seat_number == tticket.SeatNo &&
                                                                            t.seat_class == tticket.SeatType &&
                                                                            t.tour_id == tticket.TourId);

                    if (existedTicket == null || (existedTicket != null && existedTicket.status == Constants.TicketStatus.Cancel.ToString()))
                    {
                        return(Constants.SERVER_ERROR_CODE_SINGLE_DATA_NOT_SYNC + " Vé đã bị xóa!");
                    }
                }

                if (CheckUserPermission(userId, tticket.UserId) == false)
                {
                    return(Constants.Messages.MSG_TICKET_INSUFFICIENT_PERMISSION);
                }

                TicketBusiness business  = new TicketBusiness();
                Ticket         ticket    = ThriftUtil.ConvertToEntityObject(tticket) as Ticket;
                string         resultMsg = business.Update(ticket);

                //notify to the others client station
                //BroadcastToClient(ClientAction.UpdateTicket,ticket);

                return(resultMsg);
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[UpdateTicket]", exc);
                return(exc.Message);
            }
        }
        public string CancelTicket(TTicket tticket, string userId)
        {
            try
            {
                using (TicketReturnFeeConfigurationBusiness _ticketReturnFeeBusiness = new TicketReturnFeeConfigurationBusiness())
                    using (TicketBusiness business = new TicketBusiness())
                    {
                        Ticket cancelTicket = business.Get(tticket.TicketId);

                        if (cancelTicket == null)
                        {
                            return(string.Format("{0} Vé không tồn tại, không thể hủy vé, Mã:{0}", Constants.SERVER_ERROR_CODE_SINGLE_DATA_NOT_SYNC, tticket.TicketId));
                        }

                        string  result    = string.Empty;
                        decimal returnFee = _ticketReturnFeeBusiness.GetReturnFee(cancelTicket, DateTime.Now);
                        if (returnFee > 0)
                        {
                            result = business.Cancel(cancelTicket, returnFee);
                        }
                        else
                        {
                            result = business.Delete(cancelTicket.id);
                        }
                        return(result);
                    }

                //notify to the others client station
                //BroadcastToClient(ClientAction.CancelTicket,tticket);
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[CancelTicket]", exc);
                return(exc.Message);
            }
        }
Exemple #15
0
        /// <summary>
        /// 为工单添加回复
        /// </summary>
        /// <param name="t">工单信息</param>
        /// <param name="tc">回复信息</param>
        void ITicket.AddReply(TTicket t, TTicketChat tc)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                Random rand = new Random((int)Tools.Ticks());
                string id   = Tools.Ticks() + "" + rand.Next(1000, 10000);
                tc.TicketChatId = id;

                tc.CreateTime = DateTime.Now;
                m_db.TTicketChat.Add(tc);
                m_db.SaveChanges();

                m_redis.HashSet("DB:T_TicketChat", tc.TicketChatId, t);

                m_iTicket.Update(new TTicket
                {
                    TicketId   = t.TicketId,
                    ActiveTime = t.CreateTime,
                    StatusId   = t.StatusId
                });

                scope.Complete();
            }
        }
Exemple #16
0
        private async Task <bool> savePagoAsync()
        {
            try
            {
                var pago      = Convert.ToDecimal(Input1.Pago);
                var deuda     = Convert.ToDecimal(clienteReport[0].Deuda.Replace("$", "")) - pago;
                var dataInput = new InputModel
                {
                    Nombre        = nombre,
                    Apellido      = apellido,
                    Email         = idGet,
                    ClienteReport = clienteReport
                };
                if (deuda.Equals(0) || deuda.Equals(0))
                {
                    Input = dataInput;

                    Input1 = new InputModel1
                    {
                        ErrorMessage = "El cliente no contiene ninguna deuda pendiente."
                    };
                    return(true);
                }

                if (deuda < pago)
                {
                    Input = dataInput;

                    Input1 = new InputModel1
                    {
                        ErrorMessage = "Pago incorrecto, Excede el monto adeudado."
                    };
                    return(true);
                }
                else
                {
                    _objeto._context.Update(cliente);
                    await _objeto._context.SaveChangesAsync();

                    var ticket   = new Codigos(_objeto._context).CodigoTicket();
                    var reportes = new TReportes_clientes
                    {
                        ReporteID  = clienteReport[0].ReporteID,
                        Deuda      = String.Format("${0:#,###,###,##0.00####}", deuda),
                        FechaDeuda = DateTime.Today,
                        Pago       = String.Format("${0:#,###,###,##0.00####}", pago),
                        FechaPago  = DateTime.Today,
                        Ticket     = ticket,
                        TClientes  = cliente
                    };
                    _objeto._context.Update(reportes);
                    await _objeto._context.SaveChangesAsync();

                    var ticketsReport = new TTicket
                    {
                        Propietario = "Cliente",
                        Deuda       = String.Format("${0:#,###,###,##0.00####}", deuda),
                        FechaDeuda  = DateTime.Today,
                        Pago        = String.Format("${0:#,###,###,##0.00####}", pago),
                        FechaPago   = DateTime.Today,
                        Ticket      = ticket,
                        Email       = idGet
                    };
                    _objeto._context.Add(ticketsReport);
                    await _objeto._context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Input = new InputModel
                {
                    Nombre        = nombre,
                    Apellido      = apellido,
                    Email         = idGet,
                    ErrorMessage  = ex.Message,
                    ClienteReport = new List <TReportes_clientes>()
                };
                return(false);
            }
        }