示例#1
0
        public ActionResult MyPos(Pos pos)
        {
            //当前登录用户
            MpUser  mpUser  = _mpUserService.GetById(MpUserID);
            PosAuth posAuth = _posAuthService.GetUnique(p => p.MpUserId == mpUser.Id);

            //if (posAuth == null)
            //{
            //    return JsonMessage(false, "对不起,您还未申请POS,请先申请!");
            //}
            if (posAuth != null)
            {
                ViewBag.Name = posAuth.Name;
            }
            else
            {
                ViewBag.Name = mpUser.NickName;
            }

            if (mpUser.Sex == 1)
            {
                ViewBag.Sex = "先生";
            }
            else if (mpUser.Sex == 2)
            {
                ViewBag.Sex = "女士";
            }
            else
            {
                ViewBag.Sex = "";
            }

            int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 4);//当天使用次数

            if (useCount <= 5)
            {
                MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 4);//是否存在未使用的证码
                if (lastCode != null)
                {
                    //验证
                    MobileCode mobileCode = _mobileCodeService.GetMobileCode(RQuery["MobilePhone"], RQuery["Code"], MpUserID, 4);

                    if (mobileCode != null)
                    {
                        TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration();
                        mobileCode.Status = 1;
                        if (ts.Minutes > 10)
                        {
                            return(JsonMessage(false, "验证码已经失效,请重新获取"));
                        }
                        _mobileCodeService.Update(mobileCode);
                        if (_posService.PosBind(pos) == 1)
                        {
                            if (!string.IsNullOrEmpty(pos.MobilePhones) && pos.MobilePhones.Contains(RQuery["MobilePhone"]))
                            {
                                return(JsonMessage(false, "您已查询过当前POS信息,您可以点击我的POS查看详细!"));
                            }
                            else
                            {
                                _posService.ExcuteSql("update Pos set MobilePhones=isnull(MobilePhones,'')+'," + RQuery["MobilePhone"] + "',MpUserIds=isnull(MpUserIds,'')+'," + MpUserID.ToString() + "' where Id='" + pos.Id.ToString() + "'");
                                return(JsonMessage(true, pos.Id.ToString()));
                            }
                        }
                        else
                        {
                            return(JsonMessage(false, "-1"));
                        }
                    }
                    else
                    {
                        lastCode.Time += 1;
                        _mobileCodeService.Update(lastCode);
                        return(JsonMessage(false, "对不起,验证码有误,请检查!"));
                    }
                }
                else
                {
                    return(JsonMessage(false, "对不起,您还未点击发送验证码!"));
                }
            }
            else
            {
                return(JsonMessage(false, "对不起,您今天最多只能发起5次验证码"));
            }
        }