public IHttpActionResult SaveSSOAcount(User user)
        {
            if (string.IsNullOrEmpty(user.id.Trim()) ||
                string.IsNullOrEmpty(user.password.Trim()))
            {
                return(BadRequest("账号或密码为空"));
            }


            user.id       = user.id.Trim();
            user.password = user.password.Trim();


            var u = service.Find(user.id);

            if (u == null)
            {
                //新增用户
                var newUser = new data.users
                {
                    id       = user.id,
                    name     = user.name,
                    email    = user.email,
                    exp      = 1,
                    phone    = user.phone,
                    points   = 500,
                    password = user.password,
                    sso      = user.sso
                };
                service.Add(newUser);
                return(Ok <User>(new User
                {
                    id = newUser.id,
                    name = newUser.name,
                    email = newUser.email,
                    exp = newUser.exp ?? 0,
                    phone = newUser.phone,
                    points = newUser.points ?? 0,
                    password = newUser.password,
                    sso = newUser.sso
                }));
            }
            else
            {
                return(Ok <User>(new User
                {
                    id = u.id,
                    name = u.name,
                    email = u.email,
                    exp = u.exp ?? 0,
                    phone = u.phone,
                    points = u.points ?? 0,
                    password = u.password,
                    sso = u.sso
                }));
            }
        }
        public IHttpActionResult Regist(User user)
        {
            if (string.IsNullOrEmpty(user.id.Trim()) ||
                string.IsNullOrEmpty(user.password.Trim()))
            {
                return(BadRequest("账号或密码为空"));
            }
            Regex emailRx = new Regex(@"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");
            Regex phoneRx = new Regex(@"^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$");

            if (string.IsNullOrEmpty(user.sso))
            {
                if (!emailRx.IsMatch(user.id) && !phoneRx.IsMatch(user.id))
                {
                    return(BadRequest("账号应为邮箱或者手机号"));
                }
            }
            user.id       = user.id.Trim();
            user.password = user.password.Trim();
            var u = service.Find(user.id);

            if (u == null)
            {
                //新增用户
                var newUser = new data.users
                {
                    id       = user.id,
                    name     = user.name,
                    email    = user.email,
                    exp      = 1,
                    phone    = user.phone,
                    points   = 500,
                    password = user.password,
                    sso      = user.sso
                };
                service.Add(newUser);
                //新增用户版本数据
                //if(user.id
                // /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/
                //^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$

                UserConfigItem ci = new UserConfigItem();
                if (emailRx.IsMatch(user.id))
                {
                    ci.email = user.id;
                }

                if (phoneRx.IsMatch(user.id))
                {
                    ci.phone = user.id;
                }

                service.SaveUserConfig(new sys_userconfig
                {
                    code   = user.id,
                    config = JsonConvert.SerializeObject(ci)
                });

                IList <data.userdataversion> dvlist = new List <data.userdataversion>();

                dvlist.Add(new data.userdataversion
                {
                    code        = data.DataVersionCode.my_stock.ToString(),
                    user_id     = user.id,
                    version     = 1,
                    update_time = DateTime.Now
                });
                //dvlist.Add(new data.userdataversion
                //  {
                //      code = data.DataVersionCode.my_category.ToString(),
                //      user_id = user.id,
                //      version = 1,
                //      update_time = DateTime.Now
                //  });

                versionService.AddRange(dvlist);

                return(Ok <User>(new User
                {
                    id = newUser.id,
                    name = newUser.name,
                    email = newUser.email,
                    exp = newUser.exp ?? 0,
                    phone = user.phone,
                    points = newUser.points ?? 0,
                    password = newUser.password,
                    sso = newUser.sso
                }));
            }
            else
            {
                return(new StatusCodeResult(HttpStatusCode.NoContent, this));
            }
        }