protected override void OnInit(IServerConfig config)
    {
        Debug.Log("开始连接数据库~~~");
        long time = ServiceTime.GetServiceTime();

        DbConfig dConfig = new DbConfig();

        dConfig.Server   = config.Options.Get("DataBaseURL");
        dConfig.User     = config.Options.Get("DataBaseUser");
        dConfig.Password = config.Options.Get("DataBasePassword");
        dConfig.Database = config.Options.Get("DataBaseName");

        database = DatabaseFactory.CreateDatabase(dConfig, DbConfig.DbType.MYSQL);

        try
        {
            database.Open();

            time = ServiceTime.GetServiceTime() - time;

            Debug.Log("数据库连接成功 用时" + time + "ms");
        }
        catch (DatabaseException e)
        {
            Debug.LogError("错误代码:" + e.GetErrorCode() + ",错误信息:" + e.GetErrorMsg());
        }
    }
Esempio n. 2
0
    public static void Init()
    {
        Debug.Log("开始连接数据库~~~");
        long time = ServiceTime.GetServiceTime();

        DbConfig config = new DbConfig();

        config.Server   = "54.191.174.49";
        config.User     = "******";
        config.Password = "******";
        config.Database = "ElementCraft";

        database = DatabaseFactory.CreateDatabase(config, DbConfig.DbType.MYSQL);

        try
        {
            database.Open();

            time = ServiceTime.GetServiceTime() - time;

            Debug.Log("数据库连接成功 用时" + time + "ms");
        }
        catch (DatabaseException e)
        {
            Debug.LogError("错误代码:" + e.GetErrorCode() + ",错误信息:" + e.GetErrorMsg());
        }
    }
Esempio n. 3
0
    public override void BeforeFixedUpdate(int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();
            comp.m_isInframe = true;

            T cmd = (T)comp.GetCommand(m_world.FrameCount);
            cmd.id    = list[i].ID;
            cmd.frame = m_world.FrameCount;

            list[i].ChangeComp(cmd);

            //Debug.Log("USE cmd id "+ list[i].ID + " frame " + cmd.frame + " content " + Serializer.Serialize(cmd));

            //到了这一帧还没有发送命令的,给预测一个并广播给所有前端
            //if (comp.LastInputFrame < m_world.FrameCount)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    cmd.time = ServiceTime.GetServiceTime();

                    ConnectionComponent conn = list[j].GetComp <ConnectionComponent>();
                    ProtocolAnalysisService.SendMsg(conn.m_session, cmd);
                    //Debug.Log("预测并广播 " + cmd.frame);
                }
            }
        }
    }
Esempio n. 4
0
            internal void StartServiceSynchronous(CustomerSynchronous customer)
            {
                TellerState.ToState(Basic.TellerState.Busy);
                DateTime completeWhen = m_model.Executive.Now + TimeSpan.FromMinutes(ServiceTime.GetNext());

                m_model.Executive.RequestEvent(CompleteServiceSynchronous, completeWhen, customer); // Using userData to pass the customer to the event recipient.
                Console.WriteLine("{0} : {1} starting service of customer {2}.", m_model.Executive.Now, Name, customer.GetHashCode());
            }
Esempio n. 5
0
    static void ReceviceAffirmMsg(SyncSession session, AffirmMsg msg)
    {
        ConnectionComponent commandComp = session.m_connect;

        int nowTime = ServiceTime.GetServiceTime();

        commandComp.rtt = nowTime - msg.time;

        //Debug.Log(" 收到确认消息 frame: " + msg.index + " id: " + commandComp.Entity.ID + " rtt " + commandComp.rtt);
    }
    static void BroadcastSameCommand(WorldBase world, ConnectionComponent connectComp, SameCommand cmd, bool includeSelf)
    {
        cmd.time = ServiceTime.GetServiceTime();

        List <EntityBase> list = world.GetEntiyList(new string[] { "ConnectionComponent" });

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cp = list[i].GetComp <ConnectionComponent>();
            ProtocolAnalysisService.SendMsg(cp.m_session, cmd);
        }
    }
    static void ReceviceAffirmMsg(SyncSession session, AffirmMsg msg)
    {
        ConnectionComponent commandComp = session.m_connect;

        commandComp.ClearForecast(msg.frame);

        int nowTime = ServiceTime.GetServiceTime();

        commandComp.rtt = nowTime - msg.time;

        //Debug.Log("rtt " + commandComp.rtt);
    }
Esempio n. 8
0
        public ModelTime(Device aDevice, IEventUpnpProvider aEventServer)
        {
            iDevice = aDevice;

            try
            {
                iServiceTime = new ServiceTime(aDevice, aEventServer);
            }
            catch (ServiceException)
            {
                throw new ModelSourceException(301, "Service failure");
            }
        }
        public static void SendMsg(this SyncSession session, string key, Dictionary <string, object> data)
        {
            if (session == null)
            {
                //Debug.LogError("Session 已经断开连接!");
                return;
            }

            ByteArray ba = new ByteArray();

            List <byte> message = GetSendByte(key, data);

            int len    = 3 + message.Count;
            int method = GetMethodIndex(key);

            ba.WriteShort(len);
            ba.WriteByte((byte)(method / 100));
            ba.WriteShort(method);

            if (message != null)
            {
                ba.bytes.AddRange(message);
            }
            else
            {
                ba.WriteInt(0);
            }

            byte[] buffer = ba.Buffer;

            //Debug.Log("消息头 " + method + " 消息名 " + key + " --> " + BitConverter.ToString(buffer));

            try
            {
                int  time   = ServiceTime.GetServiceTime();
                bool result = session.TrySend(buffer, 0, buffer.Length);
                if (!result)
                {
                    session.Close();
                }

                if (ServiceTime.GetServiceTime() - time > 10)
                {
                    Debug.Log("发送时间 " + (ServiceTime.GetServiceTime() - time));
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Send Messge Exception " + e.ToString());
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Берет фрагмент из очереди и начинает его обслуживание
        /// </summary>
        protected void StartService()
        {
            //Берем фрагмент из очереди
            var new_f = InBuffer.Take();

            //Направляем этот фрагмент на свободный обслуживающий прибор, определив время обслуживания
            new_f.TimeStartService = Info.GetCurentTime();
            new_f.TimeLeave        = new_f.TimeStartService + ServiceTime.NextValue();
            //Увеличиваем число поступивших на прибор требований
            NumberOfArrivedDemads++;
            //Добавление фрагмента на прибор
            ListOfFragments.Add(new Label(new_f.TimeLeave, NumberOfArrivedDemads), new_f);

            UpdateActionTime();
        }
Esempio n. 11
0
    void SendReconnectMsg(ConnectionComponent comp)
    {
        float time = ServiceTime.GetServiceTime();

        //发送游戏全部数据
        PushAllEnityData(comp);

        //发送单例数据
        PushSingleComponentData(comp);

        //发送游戏开始消息
        StartSyncMsg startMsg = CreateStartMsg(m_world);

        ProtocolAnalysisService.SendMsg(comp.m_session, startMsg);

        Debug.Log("重连时间 " + (ServiceTime.GetServiceTime() - time));
    }
Esempio n. 12
0
    static void BroadcastCommand(WorldBase world, ConnectionComponent connectComp, T cmd, bool includeSelf)
    {
        cmd.time = ServiceTime.GetServiceTime();

        //TODO 与预测一致不广播节约带宽;
        List <EntityBase> list = world.GetEntityList(new string[] { "ConnectionComponent" });

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent cp = list[i].GetComp <ConnectionComponent>();
            if (cp.m_session != null)
            {
                ProtocolAnalysisService.SendMsg(cp.m_session, cmd);
                //Debug.Log("BroadcastCommand " + cmd.frame);
            }
        }
    }
    static void ReceviceSyncMsg(SyncSession session, T msg)
    {
        //Debug.Log("ReceviceSyncMsg " + msg.id);

        ConnectionComponent connectComp = session.m_connect;
        WorldBase           world       = session.m_connect.Entity.World;

        if (connectComp != null)
        {
            if (msg.frame > world.FrameCount)
            {
                //消息确认
                AffirmMsg amsg = new AffirmMsg();
                amsg.frame = msg.frame;
                amsg.time  = msg.time;

                BroadcastCommand(world, connectComp, msg, false);

                ProtocolAnalysisService.SendMsg(session, amsg);

                connectComp.m_commandList.Add(msg);
                connectComp.lastInputFrame = msg.frame;
            }
            else
            {
                //把玩家的这次上报当做最新的操作并转发
                Debug.Log("帧数落后  world.FrameCount: " + world.FrameCount + " msg frame:" + msg.frame + " 预测列表计数 " + connectComp.m_forecastList.Count);
                //Debug.Log("接收玩家数据 " + Serializer.Serialize(msg));
                connectComp.m_lastInputCache = msg;
                connectComp.lastInputFrame   = world.FrameCount;

                //并且让这个玩家提前
                PursueMsg pmsg = new PursueMsg();
                pmsg.id           = msg.id;
                pmsg.recalcFrame  = msg.frame;
                pmsg.frame        = world.FrameCount;
                pmsg.advanceCount = CalcAdvanceFrame(connectComp);
                pmsg.serverTime   = ServiceTime.GetServiceTime();

                ProtocolAnalysisService.SendMsg(session, pmsg);
            }
        }
    }
Esempio n. 14
0
    static void UpdateLogic()
    {
        int time     = ServiceTime.GetServiceTime();
        int lastTime = ServiceTime.GetServiceTime();

        while (true)
        {
            lastTime = ServiceTime.GetServiceTime();

            UpdateWorld(s_intervalTime);

            time = ServiceTime.GetServiceTime();

            int sleepTime = s_intervalTime - (time - lastTime);

            if (sleepTime > 0)
            {
                Thread.Sleep(sleepTime);
            }
        }
    }
Esempio n. 15
0
        /// <summary>
        /// 足浴版退款
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public bool ZYReFundQueue(string appId, EntGoodsOrder orderInfo, ServiceTime serviceTime)
        {
            bool result = false;

            if (orderInfo == null || orderInfo.Id <= 0)
            {
                return(result);
            }
            orderInfo.outOrderDate = DateTime.Now;
            if (orderInfo.BuyMode == (int)miniAppBuyMode.储值支付)
            {
                var saveMoneyUser = new SaveMoneySetUser();
                saveMoneyUser = SaveMoneySetUserBLL.SingleModel.getModelByUserId(appId, orderInfo.UserId);
                if (saveMoneyUser == null || saveMoneyUser.Id <= 0)
                {
                    return(result);
                }

                TransactionModel tran = new TransactionModel();
                tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog()
                {
                    AppId          = saveMoneyUser.AppId,
                    UserId         = orderInfo.UserId,
                    MoneySetUserId = saveMoneyUser.Id,
                    Type           = 1,
                    BeforeMoney    = saveMoneyUser.AccountMoney,
                    AfterMoney     = saveMoneyUser.AccountMoney + orderInfo.BuyPrice,
                    ChangeMoney    = orderInfo.BuyPrice,
                    ChangeNote     = $" 购买商品,订单号:{orderInfo.OrderNum} ",
                    CreateDate     = DateTime.Now,
                    State          = 1
                }));
                saveMoneyUser.AccountMoney += orderInfo.BuyPrice;
                tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {orderInfo.BuyPrice} where id =  {saveMoneyUser.Id} ; ");
                tran.Add($" update EntGoodsOrder set state = {(int)MiniAppEntOrderState.退款成功 },outOrderDate = '{orderInfo.outOrderDate.ToString("yyyy-MM-dd HH:mm:ss")}',Remark = @Remark where Id = {orderInfo.Id} and state <> {(int)MiniAppEntOrderState.退款成功 } ; ", new MySqlParameter[] { new MySqlParameter("@Remark", orderInfo.Remark) });//防止重复退款
                if (serviceTime != null)
                {
                    tran.Add($"update servicetime set time='{serviceTime.time}' where id={serviceTime.Id}");//取消已预订的技师服务时间
                }
                //记录订单退款日志
                tran.Add(EntGoodsOrderLogBLL.SingleModel.BuildAddSql(new EntGoodsOrderLog()
                {
                    GoodsOrderId = orderInfo.Id, UserId = orderInfo.UserId, LogInfo = $" 订单储值支付,退款成功:{orderInfo.BuyPrice * 0.01} 元 ", CreateDate = DateTime.Now
                }));
                result = ExecuteTransaction(tran.sqlArray, tran.ParameterArray);
                if (result)
                {
                    object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴退款通知);
                    TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴退款通知, TmpType.小程序足浴模板, objData);
                }
                return(result);
            }

            if (orderInfo.BuyMode == (int)miniAppBuyMode.微信支付)
            {
                CityMorders order = new CityMordersBLL().GetModel(orderInfo.OrderId);
                orderInfo.State = (int)MiniAppEntOrderState.退款中;

                if (order == null)
                {
                    orderInfo.State = (int)MiniAppEntOrderState.退款失败;
                    EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate,Remark");
                    return(result);
                }

                //微信支付
                ReFundQueue reModel = new ReFundQueue
                {
                    minisnsId = -5,
                    money     = orderInfo.BuyPrice,
                    orderid   = order.Id,
                    traid     = order.trade_no,
                    addtime   = DateTime.Now,
                    note      = "小程序足浴版退款",
                    retype    = 1
                };
                try
                {
                    base.Add(reModel);
                    result = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate");
                    return(result);
                }
                catch (Exception ex)
                {
                    log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序足浴退款订单插入队列失败 ID={orderInfo.Id}");
                }
            }
            return(result);
        }
        /// <summary>
        /// 取消预订
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateState()
        {
            int appId = Context.GetRequestInt("appId", 0);

            if (appId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet));
            }
            if (dzaccount == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙auth_null" }));
            }
            XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString());

            if (appAcountRelation == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙relation_null" }));
            }
            FootBath storeModel = FootBathBLL.SingleModel.GetModel($"appId={appId}");

            if (storeModel == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            int id = Context.GetRequestInt("id", 0);

            if (id <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙orderId_null" }));
            }
            int state = Context.GetRequestInt("state", -7);

            if (state <= -7)
            {
                return(Json(new { isok = false, msg = "系统繁忙state_null" }));
            }
            EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByAidAndId(appId, id, 1);

            if (orderInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            //是否是要直接取消的订单<未支付的订单取消订单都是直接取消>
            bool isCanncleOrder = orderInfo.PayDate == Convert.ToDateTime("0001-01-01 00:00:00");

            if (isCanncleOrder)
            {
                orderInfo.State = (int)MiniAppEntOrderState.已取消;
            }
            else
            {
                orderInfo.State = state;
            }
            EntGoodsCart cart = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(orderInfo.Id);

            if (cart == null)
            {
                return(Json(new { isok = false, msg = "服务项目不存在" }));
            }
            ServiceTime serviceTime = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, cart.technicianId, storeModel.Id, cart.reservationTime.ToShortDateString());

            //取消已预订的技师服务时间
            if (serviceTime != null && !string.IsNullOrEmpty(serviceTime.time))
            {
                List <string> timeList = serviceTime.time.Split(',').ToList();
                timeList.Remove(cart.reservationTime.ToString("HH:mm"));
                serviceTime.time = string.Join(",", timeList);
            }
            bool isok = false;

            if (isCanncleOrder)
            {
                isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State");
            }
            else
            {
                isok = EntGoodsOrderBLL.SingleModel.outOrder(appAcountRelation.AppId, orderInfo, serviceTime);
            }

            #region 取消预约通知 模板消息
            if (isok && !isCanncleOrder)
            {
                object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴预约取消通知);
                TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴预约取消通知, TmpType.小程序足浴模板, objData);
            }
            #endregion

            string msg = isok ? "操作成功" : "操作失败";
            return(Json(new { isok = isok, msg = msg }));
        }
Esempio n. 17
0
        public async Task <IHttpActionResult> GetEmplWithPosition([FromUri] TimesPar par)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!par.DontCare && !par.EmplId.HasValue) //ако го интересува служителя, но няма и служител
            {
                return(BadRequest(ModelState));
            }

            ResponseServiceTimes ret = new ResponseServiceTimes();

            int dayOfW = ((int)par.DateTimeRes.DayOfWeek == 0) ? 7 : (int)par.DateTimeRes.DayOfWeek;

            if (par.DontCare)
            {
                SalonSchedule startEndTime = new SalonSchedule();
                startEndTime = await db.SalonSchedules.Where(
                    x => x.SalonID == par.SalonId && x.DayOfWeek == dayOfW).FirstOrDefaultAsync();

                if (startEndTime != null)
                {
                    if (!startEndTime.Holiday && startEndTime.StartTime.HasValue && startEndTime.EndTime.HasValue)
                    {
                        TimeSpan           startTime        = startEndTime.StartTime.Value;
                        TimeSpan           endTime          = startEndTime.StartTime.Value.Add(par.ServiceDur);
                        TimeSpan           timeToAdd        = TimeSpan.FromMinutes(15);
                        TimeSpan           currentStartTime = startTime;
                        TimeSpan           currentEndTime   = endTime;
                        List <ServiceTime> times            = new List <ServiceTime>();

                        do
                        {
                            ServiceTime tempTime = new ServiceTime();
                            tempTime.StartTime = currentStartTime;
                            tempTime.EndTime   = currentEndTime;
                            times.Add(tempTime);

                            currentStartTime = currentStartTime.Add(timeToAdd);
                            currentEndTime   = currentEndTime.Add(timeToAdd);
                        }while (currentEndTime <= startEndTime.EndTime.Value);

                        ret.Result = "OK";
                        ret.times  = times;
                        return(Ok(ret));
                    }
                    else
                    {
                        ret.Result = "Holiday";
                        return(Ok(ret));
                    }
                }
                else
                {
                    ret.Result = "No schedule";
                    return(Ok(ret));
                }
            }
            else
            {
                EmployeeSchedule startEndTime = new EmployeeSchedule();
                startEndTime = await db.EmployeeSchedules.Where(
                    x => x.EmployeeID == par.EmplId && x.DayOfWeek == dayOfW).FirstOrDefaultAsync();

                if (startEndTime != null)
                {
                    if (!startEndTime.Holiday && startEndTime.StartTime.HasValue && startEndTime.EndTime.HasValue)
                    {
                        TimeSpan           startTime        = startEndTime.StartTime.Value;
                        TimeSpan           endTime          = startEndTime.StartTime.Value.Add(par.ServiceDur);
                        TimeSpan           timeToAdd        = TimeSpan.FromMinutes(15);
                        TimeSpan           currentStartTime = startTime;
                        TimeSpan           currentEndTime   = endTime;
                        List <ServiceTime> times            = new List <ServiceTime>();

                        do
                        {
                            ServiceTime tempTime = new ServiceTime();
                            tempTime.StartTime = currentStartTime;
                            tempTime.EndTime   = currentEndTime;
                            times.Add(tempTime);

                            currentStartTime = currentStartTime.Add(timeToAdd);
                            currentEndTime   = currentEndTime.Add(timeToAdd);
                        }while (currentEndTime <= startEndTime.EndTime.Value);

                        ret.Result = "OK";
                        ret.times  = times;
                        return(Ok(ret));
                    }
                    else
                    {
                        ret.Result = "Holiday";
                        return(Ok(ret));
                    }
                }
                else
                {
                    ret.Result = "No schedule";
                    return(Ok(ret));
                }
            }
        }
        /// <summary>
        /// 保存更改
        /// </summary>
        /// <returns></returns>
        public ActionResult SaveReserve()
        {
            #region 数据验证
            int appId = Context.GetRequestInt("appId", 0);
            if (appId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet));
            }
            if (dzaccount == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙auth_null" }));
            }
            XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString());
            if (appAcountRelation == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙relation_null" }));
            }
            FootBath storeModel = FootBathBLL.SingleModel.GetModelByAppId(appId);
            if (storeModel == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            string reservationTime = Context.GetRequest("ReservationTime", string.Empty);
            if (string.IsNullOrEmpty(reservationTime))
            {
                return(Json(new { isok = false, msg = "请选择服务时间" }));
            }

            string remark = Context.GetRequest("remark", string.Empty);
            if (remark.Length > 100)
            {
                return(Json(new { isok = false, msg = "备注内容不能超过100字" }));
            }
            int tid = Context.GetRequestInt("tid", 0);
            if (tid <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙tid_null" }));
            }
            TechnicianInfo technicianInfo = TechnicianInfoBLL.SingleModel.GetModelById(tid);
            if (technicianInfo == null)
            {
                return(Json(new { isok = false, msg = "该技师不存在" }));
            }
            int orderId = Context.GetRequestInt("orderId", 0);
            if (orderId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙orderId_null" }));
            }
            EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByOrderIdAndAid(orderId, appId, 1);
            if (orderInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙order_null" }));
            }
            #endregion
            orderInfo.Remark = remark;
            orderInfo.State  = (int)MiniAppEntOrderState.待服务;
            EntGoodsCart cartInfo = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(orderInfo.Id, 1);
            if (cartInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙cart_null" }));
            }
            //修改之前的服务时间,如果修改成功要将此时间从已预订时间表里取消
            DateTime beforeTime = cartInfo.reservationTime;
            try
            {
                cartInfo.reservationTime = Convert.ToDateTime(reservationTime);
            }
            catch
            {
                return(Json(new { isok = false, msg = "时间格式不合法" }));
            }
            //验证服务时间是否已经被选
            ServiceTime dates = ServiceTimeBLL.SingleModel.GetModelByDate(storeModel.appId, storeModel.Id, cartInfo.reservationTime.ToShortDateString());
            if (dates != null && !string.IsNullOrEmpty(dates.time))
            {
                List <string> list = dates.time.Split(',').ToList();;
                if (list.Contains(cartInfo.reservationTime.ToString("HH:mm")))
                {
                    return(Json(new { isok = -1, msg = "这个点已经被预订了" }, JsonRequestBehavior.AllowGet));
                }
            }
            //cartInfo.roomNo = roomNo;
            int beforeTid = cartInfo.technicianId;
            cartInfo.technicianId = tid;
            bool isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "remark,state") && EntGoodsCartBLL.SingleModel.Update(cartInfo, "roomNo,technicianId,reservationTime");
            if (isok)
            {
                if (DateTime.Compare(beforeTime, cartInfo.reservationTime) != 0 || cartInfo.technicianId != beforeTid)
                {
                    //取消已预订的技师服务时间
                    dates = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, beforeTid, storeModel.Id, beforeTime.ToShortDateString());
                    if (dates != null && !string.IsNullOrEmpty(dates.time))
                    {
                        List <string> timeList = dates.time.Split(',').ToList();
                        timeList.Remove(beforeTime.ToString("HH:mm"));
                        dates.time = string.Join(",", timeList);
                        ServiceTimeBLL.SingleModel.Update(dates, "time");
                    }
                    //修改成功后将选定的时间点添加到已服务时间表
                    dates = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, cartInfo.technicianId, storeModel.Id, beforeTime.ToShortDateString());
                    ServiceTimeBLL.SingleModel.AddSelServiceTime(storeModel, cartInfo, storeModel.switchModel);
                }
            }
            string msg = isok ? "操作成功" : "操作失败";
            return(Json(new { isok = isok, msg = msg }));
        }
        public ActionResult SaveOrderInfo()
        {
            #region 数据验证

            int appId = Context.GetRequestInt("appId", 0);
            if (appId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet));
            }
            if (dzaccount == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙auth_null" }));
            }
            XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString());
            if (appAcountRelation == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙relation_null" }));
            }
            FootBath storeModel = FootBathBLL.SingleModel.GetModelByAppId(appId);
            if (storeModel == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            string reservationTime = Context.GetRequest("ReservationTime", string.Empty);
            if (string.IsNullOrEmpty(reservationTime))
            {
                return(Json(new { isok = false, msg = "请选择服务时间" }));
            }

            string remark = Context.GetRequest("remark", string.Empty);
            if (remark.Length > 100)
            {
                return(Json(new { isok = false, msg = "备注内容不能超过100字" }));
            }
            int tid = Context.GetRequestInt("tid", 0);
            if (tid <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙tid_null" }));
            }
            TechnicianInfo technicianInfo = TechnicianInfoBLL.SingleModel.GetModel($"storeid={storeModel.Id} and state>=0 and id={tid}");
            if (technicianInfo == null)
            {
                return(Json(new { isok = false, msg = "该技师不存在" }));
            }
            int orderId = Context.GetRequestInt("orderId", 0);
            if (orderId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙orderId_null" }));
            }
            EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByOrderIdAndAid(orderId, appId, 0);
            if (orderInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙order_null" }));
            }
            int state = Context.GetRequestInt("state", 0);
            if (state <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙state_null" }));
            }

            EntGoodsCart cartInfo = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(orderInfo.Id, 1);
            if (cartInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙cart_null" }));
            }
            TechnicianInfo beforeTechnicianInfo = TechnicianInfoBLL.SingleModel.GetModelById(cartInfo.technicianId);
            if (beforeTechnicianInfo == null)
            {
                return(Json(new { isok = false, msg = "原订单技师不存在" }));
            }
            EntGoods serviceInfo = EntGoodsBLL.SingleModel.GetServiceById(cartInfo.aId, cartInfo.FoodGoodsId);
            if (serviceInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙serviceInfo_null" }));
            }

            #endregion 数据验证

            //假设没有修改技师
            if (technicianInfo.id == beforeTechnicianInfo.id)
            {
                //减少单数
                if ((orderInfo.State == (int)MiniAppEntOrderState.已完成 || orderInfo.State == (int)MiniAppEntOrderState.已超时) && (state != (int)MiniAppEntOrderState.已完成 && state != (int)MiniAppEntOrderState.已超时))
                {
                    technicianInfo.serviceCount--;
                    serviceInfo.salesCount--;
                }
                //增加单数
                else if ((orderInfo.State != (int)MiniAppEntOrderState.已完成 && orderInfo.State != (int)MiniAppEntOrderState.已超时) && (state == (int)MiniAppEntOrderState.已完成 || state == (int)MiniAppEntOrderState.已超时))
                {
                    technicianInfo.serviceCount++;
                    serviceInfo.salesCount++;
                }

                //同步技师工作状态
                if (state == (int)MiniAppEntOrderState.已完成 || state == (int)MiniAppEntOrderState.已超时)
                {
                    technicianInfo.state = (int)TechnicianState.空闲;
                }
                else if (state == (int)MiniAppEntOrderState.务中)
                {
                    technicianInfo.state = (int)TechnicianState.钟;
                }
                else if (state == (int)MiniAppEntOrderState.待服务)
                {
                    technicianInfo.state = (int)TechnicianState.空闲;
                }
            }
            else //前后技师不一致
            {
                //减少原先技师的接单数
                if ((orderInfo.State == (int)MiniAppEntOrderState.已完成 || orderInfo.State == (int)MiniAppEntOrderState.已超时) && (state != (int)MiniAppEntOrderState.已完成 && state != (int)MiniAppEntOrderState.已超时))
                {
                    beforeTechnicianInfo.serviceCount--;
                    serviceInfo.salesCount--;
                }
                //增加之后技师的接单数
                else if ((orderInfo.State != (int)MiniAppEntOrderState.已完成 && orderInfo.State != (int)MiniAppEntOrderState.已超时) && (state == (int)MiniAppEntOrderState.已完成 || state == (int)MiniAppEntOrderState.已超时))
                {
                    technicianInfo.serviceCount++;
                    serviceInfo.salesCount++;
                }
                //更换技师应该把接单数累计到更改后的技师上,减掉原技师接单数
                else if ((orderInfo.State == (int)MiniAppEntOrderState.已完成 || orderInfo.State == (int)MiniAppEntOrderState.已超时) && (state == (int)MiniAppEntOrderState.已完成 || state == (int)MiniAppEntOrderState.已超时))
                {
                    beforeTechnicianInfo.serviceCount--;
                    technicianInfo.serviceCount++;
                }

                //同步技师工作状态
                if (state == (int)MiniAppEntOrderState.已完成 || state == (int)MiniAppEntOrderState.已超时)
                {
                    technicianInfo.state       = (int)TechnicianState.空闲;
                    beforeTechnicianInfo.state = (int)TechnicianState.空闲;
                }
                else if (state == (int)MiniAppEntOrderState.务中)
                {
                    technicianInfo.state       = (int)TechnicianState.钟;
                    beforeTechnicianInfo.state = (int)TechnicianState.空闲;
                }
                else if (state == (int)MiniAppEntOrderState.待服务)
                {
                    //考虑如果被换过来的技师,其他项目还没完结,只是安排待服务,那么不能影响她原来的状态
                    //technicianInfo.state = (int)TechnicianState.休息中;
                    beforeTechnicianInfo.state = (int)TechnicianState.空闲;
                }
            }

            //修改之前的服务时间,如果修改成功要将此时间从已预订时间表里取消
            DateTime beforeTime = cartInfo.reservationTime;
            try
            {
                cartInfo.reservationTime = Convert.ToDateTime(reservationTime);
            }
            catch
            {
                return(Json(new { isok = false, msg = "时间格式不合法" }));
            }
            //ServiceTime dates = null;

            ServiceTime dates = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, technicianInfo.id, storeModel.Id, cartInfo.reservationTime.ToShortDateString());
            if (DateTime.Compare(beforeTime, cartInfo.reservationTime) != 0)
            {
                //验证服务时间是否已经被选
                if (dates != null && !string.IsNullOrEmpty(dates.time))
                {
                    List <string> list = dates.time.Split(',').ToList();;
                    if (list.Contains(cartInfo.reservationTime.ToString("HH:mm")))
                    {
                        return(Json(new { isok = -1, msg = "这个点已经被预订了" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            orderInfo.Remark = remark;
            orderInfo.State  = state;
            int beforeTid = cartInfo.technicianId;
            cartInfo.technicianId = tid;

            bool isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "remark,state") && EntGoodsCartBLL.SingleModel.Update(cartInfo, "roomNo,technicianId,reservationTime");
            if (isok)
            {
                if (DateTime.Compare(beforeTime, cartInfo.reservationTime) != 0 || cartInfo.technicianId != beforeTid)
                {
                    //修改成功后将选定的时间点添加到已服务时间表
                    ServiceTimeBLL.SingleModel.AddSelServiceTime(storeModel, cartInfo, storeModel.switchModel);
                    //取消已预订的技师服务时间
                    dates = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, beforeTid, storeModel.Id, beforeTime.ToShortDateString());
                    if (dates != null && !string.IsNullOrEmpty(dates.time))
                    {
                        List <string> timeList = dates.time.Split(',').ToList();
                        timeList.Remove(beforeTime.ToString("HH:mm"));
                        dates.time = string.Join(",", timeList);
                        ServiceTimeBLL.SingleModel.Update(dates, "time");
                    }
                }
                //前后技师不同时,才会去更新前者的状态
                if (beforeTechnicianInfo.id != technicianInfo.id)
                {
                    TechnicianInfoBLL.SingleModel.Update(beforeTechnicianInfo, "state,serviceCount");
                }
                TechnicianInfoBLL.SingleModel.Update(technicianInfo, "state,serviceCount");
                EntGoodsBLL.SingleModel.Update(serviceInfo, "salesCount");
            }
            string msg = isok ? "操作成功" : "操作失败";
            return(Json(new { isok = isok, msg = msg }));
        }