예제 #1
0
        /// <summary>
        /// 手机端注册邀请接口
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="model"></param>
        /// <param name="code"></param>
        /// <param name="inviteCode">邀请人手机号码</param>
        /// <returns></returns>
        public IHttpActionResult Post(string v1, [FromBody] _User model, string code, string inviteCode = "")
        {
            bool isInvited = false;

            try
            {
                //表单验证
                if (isNUll(model.username, model.password, code))
                {
                    return(invildRequest("参数不能为空"));
                }

                //判断是否有邀请码
                if (!string.IsNullOrEmpty(inviteCode))
                {
                    //邀请人手机号码是否存在
                    if (!bll.QueryExitByUsername(inviteCode))
                    {
                        return(notFound("邀请人手机号码不存在哦!"));
                    }
                    isInvited = true;
                }

                //手机端短信验证
                string postUri = "sms/verify?appkey=1ad08332b2ac0&phone=" + model.username + "&zone=86&code=" + code;
                //短信验证
                MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com");
                //请求验证
                string postResponse = client.Get(postUri);
                if (!string.IsNullOrEmpty(postResponse))
                {
                    JObject jo     = JsonHelper.DeserializeObject(postResponse);
                    string  status = jo["status"].ToString();
                    if (!status.Equals("200"))
                    {
                        return(notFound("验证码错误" + postResponse));
                    }
                }
                else
                {
                    return(notFound("验证码请求验证失败"));
                }

                //查询用户是否已经存在
                if (bll.QueryExitByUsername(model.username))
                {
                    return(notFound("用户名已存在"));
                }
                bool result = false;
                //主键
                Guid     guid = Guid.NewGuid();
                DateTime dt   = DateTime.Now;
                model.objectId = guid.ToString();
                //密码加盐保存
                model.password = (model.password + model.objectId).Md5();
                //初始化数据
                model.nickname    = "口袋爆料人";
                model.credit      = 40;
                model.overage     = 0;
                model.sign_in     = true;
                model.shake_times = 3;
                model.createdAt   = dt;
                model.updatedAt   = dt;
                string initPassword = "******";
                model.transaction_password = (initPassword.Md5() + model.objectId).Md5();
                //注册积分记录
                CreditsHistory history1 = new CreditsHistory();
                history1.objectId  = guid.ToString();
                history1.createdAt = dt;
                history1.updatedAt = dt;
                history1.change    = 40;
                history1.credit    = 40;
                history1.type      = 4;//注册得积分
                result             = bll.Insert1(model, history1);
                if (isInvited)
                {
                    List <Wheres> whs = new List <Wheres>()
                    {
                        new Wheres("username", "=", inviteCode)
                    };
                    _User user = bll.QuerySingleByWheres(whs);
                    //邀请积分记录
                    CreditsHistory history2 = new CreditsHistory();
                    Guid           guid1    = Guid.NewGuid();
                    history2.objectId  = guid1.ToString();
                    history2.createdAt = dt;
                    history2.updatedAt = dt;
                    history2.type      = 3;//邀请得积分
                    history2.change    = 30;
                    history2.credit    = user.credit + 30;
                    history2.userId    = user.objectId;
                    result             = bll.Insert1(model, history1, history2, inviteCode);
                }
                if (result)
                {
                    return(ok(new { msg = "注册成功" }));
                }
                return(notFound("注册失败"));
            }
            catch (Exception e)
            {
                return(execept(e.Message));
            }
        }