Ejemplo n.º 1
0
        public static void CreateICCard(string msg, Dictionary <string, Session> sessionPool, string sendIP)
        {
            string sRepeatCode   = (new Random()).Next(0, 255).ToString();
            string receiveIP     = string.Empty;
            string dogId         = string.Empty;
            string storePassword = string.Empty;
            string newICCardId   = string.Empty;
            string errMsg        = string.Empty;
            string answerMsgType = Convert.ToInt32(TCPMessageType.办理新IC卡).ToString();
            //解析消息对象
            SocketDataModel <UserSendObject, MemberRegisterModel> socketDataModel = Utils.DataContractJsonDeserializer <SocketDataModel <UserSendObject, MemberRegisterModel> >(msg);
            UserSendObject      sendObj             = socketDataModel.SendObject;
            MemberRegisterModel memberRegisterModel = (MemberRegisterModel)(socketDataModel.Data);

            newICCardId = memberRegisterModel.ICCardId;
            //接受信息方是否存在
            if (!GetIP(sessionPool, sendObj.UserToken, out receiveIP))
            {
                SendFailData(answerMsgType, sessionPool, sendIP, "用户未注册");
                return;
            }
            //获取店密码接口
            string userToken = sendObj.UserToken;

            if (!StoreBusiness.GetStorePassword(userToken, out storePassword, out errMsg))
            {
                SendFailData(answerMsgType, sessionPool, sendIP, "获取门店信息出错");
                return;
            }
            //验证是否可以办卡
            if (ICCardUtility.CheckNullCard(storePassword))
            {
                if (MemberBusiness.CheckMemberCanRegister(userToken, memberRegisterModel.StoreId, memberRegisterModel.Mobile, out errMsg))
                {
                    //办理新卡
                    if (ICCardUtility.CreateICCard(newICCardId, sRepeatCode, storePassword, out errMsg, true))
                    {
                        memberRegisterModel.RepeatCode = sRepeatCode;
                        object result_data = null;
                        int    repeatCode  = 0;
                        if (MemberBusiness.MemberRegister(memberRegisterModel, out repeatCode, out errMsg, ref result_data))
                        {
                            SendSuccessData(answerMsgType, sessionPool, sendIP, "会员卡开通成功", result_data);
                        }
                        else
                        {
                            SendFailData(answerMsgType, sessionPool, sendIP, errMsg);
                        }
                    }
                    else
                    {
                        SendFailData(answerMsgType, sessionPool, sendIP, errMsg);
                    }
                }
                else
                {
                    SendFailData(answerMsgType, sessionPool, sendIP, errMsg);
                }
            }
            else
            {
                SendFailData(answerMsgType, sessionPool, sendIP, "本卡已使用,请插入空卡");
            }
        }