Example #1
0
        public object getSegmentList(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string mobileToken = dicParas.ContainsKey("mobileToken") ? dicParas["mobileToken"].ToString() : string.Empty;
                string routerToken = dicParas.ContainsKey("routerToken") ? dicParas["routerToken"].ToString() : string.Empty;
                string groupId     = dicParas.ContainsKey("groupId") ? dicParas["groupId"].ToString() : string.Empty;

                Base_MerchInfo merch = MerchBusiness.GetMerchModel(mobileToken);
                if (merch.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户令牌无效"));
                }

                Base_DeviceInfo router = DeviceBusiness.GetDeviceModel(routerToken);
                if (router.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "控制器令牌无效"));
                }

                Data_GameInfo group = GameBusiness.GetGameInfoModel(Convert.ToInt32(groupId));
                if (group.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "分组参数无效"));
                }

                //分组集合
                var groupList = MerchSegmentBusiness.GetMerchSegmentList().Where(t => t.ParentID == router.ID && t.GroupID == group.GroupID).ToList();

                GroupInfoModel model = new GroupInfoModel();
                model.groupId   = group.GroupID;
                model.groupName = group.GroupName;

                List <Terminal> Terminals = new List <Terminal>();
                foreach (var item in groupList)
                {
                    Terminal        t       = new Terminal();
                    Base_DeviceInfo cDevice = DeviceBusiness.GetDeviceModelById((int)item.DeviceID);
                    t.terminalName  = cDevice.DeviceName ?? cDevice.SN;
                    t.terminalToken = cDevice.Token;
                    t.headAddress   = item.HeadAddress;
                    t.sn            = cDevice.SN;
                    t.deviceType    = ((DeviceTypeEnum)cDevice.DeviceType).ToDescription();
                    t.status        = DeviceStatusBusiness.GetDeviceState(cDevice.Token);

                    Terminals.Add(t);
                }
                model.Terminals = Terminals;

                return(ResponseModelFactory <GroupInfoModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #2
0
        public object getMerchDeviceInfo(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string mobileToken = dicParas.ContainsKey("mobileToken") ? dicParas["mobileToken"].ToString() : string.Empty;
                string deviceToken = dicParas.ContainsKey("deviceToken") ? dicParas["deviceToken"].ToString() : string.Empty;

                Base_MerchInfo merch = MerchBusiness.GetMerchModel(mobileToken);
                if (merch.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户令牌无效"));
                }

                Base_DeviceInfo device = DeviceBusiness.GetDeviceModel(deviceToken);
                if (device.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "设备令牌无效"));
                }

                //设备所属商户不是当前商户
                if (device.MerchID != merch.ID)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该设备属于其他商户,您没有权限查看该设备"));
                }

                DeviceTypeEnum currDeviceType = (DeviceTypeEnum)device.DeviceType;

                DeviceInfoModel model = new DeviceInfoModel();
                model.Router      = new Router();
                model.Group       = new Group();
                model.deviceName  = device.DeviceName ?? device.SN;
                model.deviceToken = device.Token;
                model.deviceType  = currDeviceType.ToDescription();
                model.deviceSN    = device.SN;
                model.status      = DeviceStatusBusiness.GetDeviceState(device.Token);

                switch (currDeviceType)
                {
                case DeviceTypeEnum.SlotMachines:
                case DeviceTypeEnum.DepositMachine:
                {
                    //获取外设绑定关系实体
                    Data_MerchDevice md = MerchDeviceBusiness.GetMerchDeviceModel(device.ID);
                    model.headAddress = md.HeadAddress;

                    //获取控制器实体
                    Base_DeviceInfo router = DeviceBusiness.GetDeviceModelById((int)md.ParentID);
                    model.Router.routerName  = router.DeviceName ?? router.SN;
                    model.Router.routerToken = router.Token;
                    model.Router.sn          = router.SN;
                }
                break;

                case DeviceTypeEnum.Clerk:
                case DeviceTypeEnum.Terminal:
                {
                    //获取终端绑定关系实体
                    Data_MerchSegment ms = MerchSegmentBusiness.GetMerchSegmentModel(device.ID);
                    model.headAddress = ms.HeadAddress;

                    //获取分组实体
                    Data_GameInfo group = GameBusiness.GetGameInfoModel(Convert.ToInt32(ms.GroupID));
                    model.Group.groupId   = group.GroupID;
                    model.Group.groupName = group.GroupName;
                    model.Group.groupType = ((GroupTypeEnum)(int)group.GroupType).ToDescription();
                }
                break;
                }
                return(ResponseModelFactory <DeviceInfoModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
        public object getDeviceInfo(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string mobileToken = dicParas.ContainsKey("mobileToken") ? dicParas["mobileToken"].ToString() : string.Empty;
                string deviceToken = dicParas.ContainsKey("deviceToken") ? dicParas["deviceToken"].ToString() : string.Empty;
                string routerToken = dicParas.ContainsKey("routerToken") ? dicParas["routerToken"].ToString().Trim().ToLower() : string.Empty;

                Base_MerchInfo merch = MerchBusiness.GetMerchModel(mobileToken);
                if (merch.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户令牌无效"));
                }

                Base_DeviceInfo device = DeviceBusiness.GetDeviceModel(deviceToken);
                if (device.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "设备令牌无效"));
                }

                string status = DeviceStatusBusiness.GetDeviceState(device.Token);

                //当前设备类型
                DeviceTypeEnum currDeviceType = (DeviceTypeEnum)device.DeviceType;

                DeviceInfoModel model = new DeviceInfoModel();
                model.Router      = new Router();
                model.Group       = new Group();
                model.deviceName  = device.DeviceName ?? device.SN;
                model.deviceToken = device.Token;
                model.deviceType  = currDeviceType.ToDescription();
                model.deviceSN    = device.SN;
                model.status      = DeviceStatusBusiness.GetDeviceState(device.Token);


                //设备未绑定
                if (device.MerchID == 0 || device.MerchID.IsNull())
                {
                    model.BindState = (int)DeviceBoundStateEnum.NotBound;
                    return(ResponseModelFactory <DeviceInfoModel> .CreateModel(isSignKeyReturn, model));
                }

                //判断设备绑定的商户是否与当前商户一致
                if (device.MerchID != merch.ID)
                {
                    //与当前商户不一致
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "没有权限查看该设备信息"));
                }

                //Base_DeviceInfo currRouter = null;
                //if (!string.IsNullOrWhiteSpace(routerToken))
                //{
                //    currRouter = DeviceBusiness.GetDeviceModel(routerToken);
                //}

                //1.如果设备绑定的商户与当前商户一致
                //2.判断设备是否已与当前商户建立绑定关系
                switch (currDeviceType)
                {
                case DeviceTypeEnum.Router:
                    model.BindState = (int)DeviceBoundStateEnum.Bound;
                    break;

                case DeviceTypeEnum.SlotMachines:
                case DeviceTypeEnum.DepositMachine:
                {
                    //获取外设绑定关系实体
                    Data_MerchDevice md = MerchDeviceBusiness.GetMerchDeviceModel(device.ID);
                    if (md.IsNull())
                    {
                        model.BindState = (int)DeviceBoundStateEnum.NotBound;
                    }
                    else
                    {
                        //获取控制器实体
                        Base_DeviceInfo router = DeviceBusiness.GetDeviceModelById((int)md.ParentID);

                        if (router.Token.Trim().ToLower() != routerToken)
                        {
                            //设备所属控制器与当前控制器不一致
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该设备不属于当前控制器"));
                        }

                        model.BindState   = (int)DeviceBoundStateEnum.Bound;
                        model.headAddress = md.HeadAddress;
                        //控制器信息
                        model.Router.routerName  = router.DeviceName ?? router.SN;
                        model.Router.routerToken = router.Token;
                        model.Router.sn          = router.SN;
                    }
                }
                break;

                case DeviceTypeEnum.Clerk:
                case DeviceTypeEnum.Terminal:
                {
                    //获取终端绑定关系实体
                    Data_MerchSegment ms = MerchSegmentBusiness.GetMerchSegmentModel(device.ID);
                    if (ms.IsNull())
                    {
                        model.BindState = (int)DeviceBoundStateEnum.NotBound;
                    }
                    else
                    {
                        //获取控制器实体
                        Base_DeviceInfo router = DeviceBusiness.GetDeviceModelById((int)ms.ParentID);

                        if (router.Token.Trim().ToLower() != routerToken)
                        {
                            //设备所属控制器与当前控制器不一致
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该设备不属于当前控制器"));
                        }

                        model.BindState   = (int)DeviceBoundStateEnum.Bound;
                        model.headAddress = ms.HeadAddress;

                        //控制器信息
                        model.Router.routerName  = router.DeviceName ?? router.SN;
                        model.Router.routerToken = router.Token;
                        model.Router.sn          = router.SN;

                        //获取分组实体
                        Data_GameInfo group = GameBusiness.GetGameInfoModel(Convert.ToInt32(ms.GroupID));
                        model.Group.groupId   = group.GroupID;
                        model.Group.groupName = group.GroupName;
                        model.Group.groupType = ((GroupTypeEnum)(int)group.GroupType).ToDescription();
                    }
                }
                break;
                }

                //返回设备信息
                return(ResponseModelFactory <DeviceInfoModel> .CreateModel(isSignKeyReturn, model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        public object bindDevice(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string mobileToken = dicParas.ContainsKey("mobileToken") ? dicParas["mobileToken"].ToString() : string.Empty;
                string deviceToken = dicParas.ContainsKey("deviceToken") ? dicParas["deviceToken"].ToString() : string.Empty;
                string deviceName  = dicParas.ContainsKey("deviceName") ? dicParas["deviceName"].ToString() : string.Empty;
                string level       = dicParas.ContainsKey("level") ? dicParas["level"].ToString() : string.Empty;
                string routerToken = dicParas.ContainsKey("routerToken") ? dicParas["routerToken"].ToString() : string.Empty;
                string groupId     = dicParas.ContainsKey("groupId") ? dicParas["groupId"].ToString() : string.Empty;

                Base_MerchInfo merch = MerchBusiness.GetMerchModel(mobileToken);
                if (merch.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "用户令牌无效"));
                }

                if (merch.State == 0)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "当前用户已被禁用"));
                }

                Base_DeviceInfo device = DeviceBusiness.GetDeviceModel(deviceToken);
                if (device.IsNull())
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "设备令牌无效"));
                }

                //设备已被绑定
                if (!device.MerchID.IsNull() && device.MerchID != 0 && device.MerchID != merch.ID)
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "该设备已被其他商户绑定"));
                }

                //设备未绑定,开始绑定
                device.MerchID    = merch.ID;
                device.DeviceName = deviceName;
                device.Status     = (int)DeviceStatusEnum.启用;

                if (string.IsNullOrWhiteSpace(level))
                {
                    return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "参数错误"));
                }

                DeviceTypeEnum currDeviceType = (DeviceTypeEnum)device.DeviceType;

                switch (level)
                {
                case "1":
                {
                    if (currDeviceType == DeviceTypeEnum.Router)
                    {
                        DeviceBusiness.UpdateDevice(device);
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, ""));
                    }
                    else if (currDeviceType == DeviceTypeEnum.SlotMachines || currDeviceType == DeviceTypeEnum.DepositMachine)
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请选定控制器后绑定该设备"));
                    }
                    else
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请在分组中绑定该设备"));
                    }
                }

                case "2":
                {
                    if (currDeviceType == DeviceTypeEnum.Router)
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请在返回上级绑定"));
                    }
                    else if (currDeviceType == DeviceTypeEnum.SlotMachines || currDeviceType == DeviceTypeEnum.DepositMachine)
                    {
                        if (string.IsNullOrWhiteSpace(routerToken))
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取控制器参数错误"));
                        }
                        //获取控制器实体
                        Base_DeviceInfo router = DeviceBusiness.GetDeviceModel(routerToken);
                        if (router.IsNull())
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取控制器参数错误"));
                        }

                        //获取当前控制器中的外设列表
                        var list = MerchDeviceBusiness.GetListByParentId(router.ID).OrderBy(m => m.HeadAddress).ToList();

                        if (list.Count >= 11)
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "超出最大绑定数量"));
                        }

                        Data_MerchDevice md = list.FirstOrDefault(m => m.DeviceID == device.ID);
                        if (md.IsNull())
                        {
                            md          = new Data_MerchDevice();
                            md.ParentID = router.ID;
                            md.DeviceID = device.ID;

                            int index = 0;
                            foreach (var item in list)
                            {
                                string currAddress = string.Format("A{0}", index);
                                //int currIndex = int.Parse(item.HeadAddress, System.Globalization.NumberStyles.AllowHexSpecifier);
                                if (currAddress != item.HeadAddress)
                                {
                                    break;
                                }
                                index++;
                                continue;
                            }
                            //md.HeadAddress = Convert.ToString(index, 16).PadLeft(2, '0').ToUpper();
                            md.HeadAddress = string.Format("A{0}", index);
                        }

                        using (var transactionScope = new System.Transactions.TransactionScope(
                                   TransactionScopeOption.RequiresNew))
                        {
                            DeviceBusiness.UpdateDevice(device);
                            MerchDeviceBusiness.AddMerchDevice(md);

                            transactionScope.Complete();
                        }

                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, ""));
                    }
                    else
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请在分组中绑定该设备"));
                    }
                }

                case "3":
                {
                    if (currDeviceType != DeviceTypeEnum.Clerk && currDeviceType != DeviceTypeEnum.Terminal)
                    {
                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "请在分组中绑定该设备"));
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(groupId))
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取分组参数错误"));
                        }

                        //获取分组实体
                        Data_GameInfo group = GameBusiness.GetGameInfoModel(Convert.ToInt32(groupId));
                        if (group.IsNull())
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取分组参数错误"));
                        }

                        //根据分组获取当前分组的控制器
                        Base_DeviceInfo router = DeviceBusiness.GetDeviceModelById((int)group.DeviceID);
                        if (router.IsNull())
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "获取控制器参数错误"));
                        }

                        //判断当前分组是否属于当前商户
                        if (router.MerchID != merch.ID)
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "分组信息与当前商户不匹配"));
                        }

                        //获取当前分组中的终端列表
                        var list = MerchSegmentBusiness.GetListByGroupId(group.GroupID).OrderBy(m => m.HeadAddress).ToList();

                        if (list.Count >= 99)
                        {
                            return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.F, "超出最大绑定数量"));
                        }

                        Data_MerchSegment ms = list.FirstOrDefault(m => m.ParentID == group.DeviceID && m.DeviceID == device.ID);
                        if (ms.IsNull())
                        {
                            ms          = new Data_MerchSegment();
                            ms.ParentID = group.DeviceID;
                            ms.GroupID  = group.GroupID;
                            ms.DeviceID = device.ID;

                            int index = 1;
                            foreach (var item in list)
                            {
                                int currIndex = int.Parse(item.HeadAddress, System.Globalization.NumberStyles.AllowHexSpecifier);
                                if (currIndex != index)
                                {
                                    break;
                                }
                                index++;
                                continue;
                            }
                            ms.HeadAddress = Convert.ToString(index, 16).PadLeft(2, '0').ToUpper();
                        }

                        using (var transactionScope = new System.Transactions.TransactionScope(
                                   TransactionScopeOption.RequiresNew))
                        {
                            DeviceBusiness.UpdateDevice(device);
                            MerchSegmentBusiness.AddMerchSegment(ms);

                            transactionScope.Complete();
                        }

                        return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, ""));
                    }
                }
                }

                DeviceStatusBusiness.SetDeviceState(device.Token, DeviceStatusEnum.离线.ToDescription());

                return(ResponseModelFactory.CreateModel(isSignKeyReturn, Return_Code.T, "", Result_Code.T, ""));
            }
            catch (Exception e)
            {
                throw e;
            }
        }