Example #1
0
        /// <summary>
        /// 微信绑定
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateInsert(_User model, CreditsHistory history)
        {
            const string sql = @"INSERT INTO [dbo].[wechat] (objectId,openId,inopenId) VALUES (@objectId,@openId,@inopenId)";

            SqlParameter[] parms = { new SqlParameter("@objectId", model.authData.wechat.objectId.ToDBValue()), new SqlParameter("@openId", model.authData.wechat.openId.ToDBValue()), new SqlParameter("@inopenId", model.authData.wechat.inopenId.ToDBValue()) };

            const string sql1 = @"INSERT INTO [dbo].[authData] (objectId,wechatId) VALUES (@objectId,@wechatId)";

            //SqlParameter[] parms1 = { new SqlParameter("@objectId", model.authData.objectId.ToDBValue()), new SqlParameter("@weiboId", model.authData.weibo.objectId.ToDBValue()), new SqlParameter("@qqId", model.authData.qq.objectId.ToDBValue()), new SqlParameter("@alibabaId", model.authData.alibaba.objectId.ToDBValue()), new SqlParameter("@wechatId", model.authData.wechat.objectId.ToDBValue()) };
            SqlParameter[] parms1 = { new SqlParameter("@objectId", model.authData.objectId.ToDBValue()), new SqlParameter("@wechatId", model.authData.wechat.objectId.ToDBValue()) };

            const string sql2 = @"UPDATE _User set authDataId=@authDataId where username=@username";

            SqlParameter[] parms2 = { new SqlParameter("authDataId", model.authData.objectId), new SqlParameter("@username", model.username) };

            const string sql3 = @"UPDATE _User set credit+=@credit where username=@inopenId";

            SqlParameter[] parms3 = { new SqlParameter("@credit", history.change), new SqlParameter("@inopenId", model.authData.wechat.inopenId) };

            const string sql4 = @"INSERT INTO CreditsHistory (objectId,createdAt,updatedAt,userId,type,change,credit) values (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms4 = { new SqlParameter("@objectId", history.objectId), new SqlParameter("@createdAt", history.createdAt), new SqlParameter("@updatedAt", history.updatedAt), new SqlParameter("@userId", history.userId), new SqlParameter("@type", history.type), new SqlParameter("@change", history.change), new SqlParameter("@credit", history.credit) };

            int res = SqlHelper.ExecuteNonQuerysTransaction(sql, parms, sql1, parms1, sql2, parms2, sql3, parms3, sql4, parms4);

            return(res > 4);
        }
Example #2
0
///<summary>
///向数据库中添加一条记录
///</summary>
///<param name="model">要添加的实体</param>
        public bool Insert(CreditsHistory model)
        {
            const string sql = @"INSERT INTO [dbo].[CreditsHistory] (objectId,createdAt,updatedAt,userId,type,change,credit,orderNum,bizId) VALUES (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit,@orderNum,@bizId)";
            int          res = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@credit", model.credit.ToDBValue()), new SqlParameter("@orderNum", model.orderNum.ToDBValue()), new SqlParameter("@bizId", model.bizId.ToDBValue()));

            return(res > 0);
        }
Example #3
0
        /// <summary>
        /// 有邀请人
        /// </summary>
        /// <param name="model"></param>
        /// <param name="history">注册用户记录</param>
        /// <param name="history1">邀请者记录</param>
        /// <returns></returns>
        public bool Insert(_User model, CreditsHistory history, CreditsHistory history1)
        {
            const string sql = @"INSERT INTO [dbo].[wechat] (objectId,openId,inopenId) VALUES (@objectId,@openId,@inopenId)";

            SqlParameter[] parms = { new SqlParameter("@objectId", model.authData.wechat.objectId.ToDBValue()), new SqlParameter("@openId", model.authData.wechat.openId.ToDBValue()), new SqlParameter("@inopenId", model.authData.wechat.inopenId.ToDBValue()) };

            const string sql1 = @"INSERT INTO [dbo].[authData] (objectId,wechatId) VALUES (@objectId,@wechatId)";

            //SqlParameter[] parms1 = { new SqlParameter("@objectId", model.authData.objectId.ToDBValue()), new SqlParameter("@weiboId", model.authData.weibo.objectId.ToDBValue()), new SqlParameter("@qqId", model.authData.qq.objectId.ToDBValue()), new SqlParameter("@alibabaId", model.authData.alibaba.objectId.ToDBValue()), new SqlParameter("@wechatId", model.authData.wechat.objectId.ToDBValue()) };
            SqlParameter[] parms1 = { new SqlParameter("@objectId", model.authData.objectId.ToDBValue()), new SqlParameter("@wechatId", model.authData.wechat.objectId.ToDBValue()) };

            const string sql2 = @"INSERT INTO [dbo].[_User] (objectId,updatedAt,createdAt,username,password,transaction_password,sessionToken,nickname,credit,overage,avatar,sign_in,shake_times,authDataId) VALUES (@objectId,@updatedAt,@createdAt,@username,@password,@transaction_password,@sessionToken,@nickname,@credit,@overage,@avatar,@sign_in,@shake_times,@authDataId)";

            SqlParameter[] parms2 = { new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@username", model.username.ToDBValue()), new SqlParameter("@password", model.password.ToDBValue()), new SqlParameter("@transaction_password", model.transaction_password.ToDBValue()), new SqlParameter("@sessionToken", model.sessionToken.ToDBValue()), new SqlParameter("@nickname", model.nickname.ToDBValue()), new SqlParameter("@credit", model.credit.ToDBValue()), new SqlParameter("@overage", model.overage.ToDBValue()), new SqlParameter("@avatar", model.avatar.ToDBValue()), new SqlParameter("@sign_in", model.sign_in.ToDBValue()), new SqlParameter("@shake_times", model.shake_times.ToDBValue()), new SqlParameter("@authDataId", model.authData.objectId.ToDBValue()) };

            const string sql3 = @"UPDATE _User set credit+=@credit where username=@inopenId";

            SqlParameter[] parms3 = { new SqlParameter("@credit", history1.change), new SqlParameter("@inopenId", model.authData.wechat.inopenId) };

            const string sql4 = @"INSERT INTO CreditsHistory (objectId,createdAt,updatedAt,userId,type,change,credit) values (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms4 = { new SqlParameter("@objectId", history.objectId), new SqlParameter("@createdAt", history.createdAt), new SqlParameter("@updatedAt", history.updatedAt), new SqlParameter("@userId", model.objectId), new SqlParameter("@type", history.type), new SqlParameter("@change", history.change), new SqlParameter("@credit", history.credit) };

            const string sql5 = @"INSERT INTO CreditsHistory (objectId,createdAt,updatedAt,userId,type,change,credit) values (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms5 = { new SqlParameter("@objectId", history1.objectId), new SqlParameter("@createdAt", history1.createdAt), new SqlParameter("@updatedAt", history1.updatedAt), new SqlParameter("@userId", history1.userId), new SqlParameter("@type", history1.type), new SqlParameter("@change", history1.change), new SqlParameter("@credit", history1.credit) };

            int res = SqlHelper.ExecuteNonQuerysTransaction(sql, parms, sql1, parms1, sql2, parms2, sql3, parms3, sql4, parms4, sql5, parms5);

            return(res > 5);
        }
Example #4
0
        /// <summary>
        /// 手机端,没有邀请人注册
        /// </summary>
        /// <param name="model"></param>
        /// <param name="history"></param>
        /// <returns></returns>
        public bool Insert1(_User model, CreditsHistory history)
        {
            const string sql = @"INSERT INTO [dbo].[_User] (objectId,updatedAt,createdAt,username,password,transaction_password,sessionToken,nickname,credit,overage,avatar,sign_in,shake_times) VALUES (@objectId,@updatedAt,@createdAt,@username,@password,@transaction_password,@sessionToken,@nickname,@credit,@overage,@avatar,@sign_in,@shake_times)";

            SqlParameter[] parms = { new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@username", model.username.ToDBValue()), new SqlParameter("@password", model.password.ToDBValue()), new SqlParameter("@transaction_password", model.transaction_password.ToDBValue()), new SqlParameter("@sessionToken", model.sessionToken.ToDBValue()), new SqlParameter("@nickname", model.nickname.ToDBValue()), new SqlParameter("@credit", model.credit.ToDBValue()), new SqlParameter("@overage", model.overage.ToDBValue()), new SqlParameter("@avatar", model.avatar.ToDBValue()), new SqlParameter("@sign_in", model.sign_in.ToDBValue()), new SqlParameter("@shake_times", model.shake_times.ToDBValue()) };
            const string   sql1  = @"INSERT INTO CreditsHistory (objectId,createdAt,updatedAt,userId,type,change,credit) values (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms1 = { new SqlParameter("@objectId", history.objectId), new SqlParameter("@createdAt", history.createdAt), new SqlParameter("@updatedAt", history.updatedAt), new SqlParameter("@userId", model.objectId), new SqlParameter("@type", history.type), new SqlParameter("@change", history.change), new SqlParameter("@credit", history.credit) };
            int            res    = SqlHelper.ExecuteNonQuerysTransaction(sql, parms, sql1, parms1);

            return(res > 1);
        }
Example #5
0
        ///<summary>
        ///向数据库中添加一条记录
        ///</summary>
        ///<param name="model">要添加的实体</param>
        public bool shake(CreditsHistory model, string userId)
        {
            const string sql = @"INSERT INTO [dbo].[CreditsHistory] (objectId,createdAt,updatedAt,userId,type,change,credit) VALUES (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms = { new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@credit", model.credit.ToDBValue()) };

            const string sql1 = @"UPDATE [dbo].[_User] SET shake_times=shake_times-1,credit=credit+@number WHERE [objectId] = @objectId";

            SqlParameter[] pams1 = { new SqlParameter("@objectId", userId), new SqlParameter("@number", model.change) };
            int            res   = SqlHelper.ExecuteNonQuerysTransaction(sql, parms, sql1, pams1);

            return(res > 0);
        }
Example #6
0
        ///// <summary>
        ///// 根据openId修改积分
        ///// </summary>
        ///// <param name="openId">OpenId</param>
        ///// <param name="credit">修改积分</param>
        ///// <returns></returns>
        //public bool UpdateCreditByOpenId(string openId,int credit)
        //{
        //    string sql = "UPDATE _User set credit+=@credit from _User,authData,wechat where _User.authDataId=authData.objectId and authData.wechatId=wechat.objectId and openId=@openId";
        //    SqlParameter[] paras = { new SqlParameter("@credit", credit), new SqlParameter("openId", openId) };
        //    int res = SqlHelper.ExecuteNonQuery(sql, paras);
        //    return res > 0;
        //}

        public bool UpdateCreditByObjectId(string objectId, CreditsHistory history)
        {
            const string sql = @"UPDATE _User set credit+=@credit where objectId = @objectId";

            SqlParameter[] parms = { new SqlParameter("@credit", history.change), new SqlParameter("@objectId", objectId) };

            const string sql1 = @"INSERT INTO CreditsHistory (objectId,createdAt,updatedAt,userId,type,change,credit) values (@objectId,@createdAt,@updatedAt,@userId,@type,@change,@credit)";

            SqlParameter[] parms1 = { new SqlParameter("@objectId", history.objectId), new SqlParameter("@createdAt", history.createdAt), new SqlParameter("@updatedAt", history.updatedAt), new SqlParameter("@userId", objectId), new SqlParameter("@type", history.type), new SqlParameter("@change", history.change), new SqlParameter("@credit", history.credit) };

            int res = SqlHelper.ExecuteNonQuerysTransaction(sql, parms, sql1, parms1);

            return(res > 1);
        }
        public IHttpActionResult Get(string v1, string objectId)
        {
            try
            {
                if (string.IsNullOrEmpty(objectId))
                {
                    return(invildRequest("用户ID不能为空"));
                }


                _User user = bll.QuerySingleById(objectId);
                if (user.shake_times < 1)
                {
                    return(ok(-1));
                }

                Random ran    = new Random();
                int    number = ran.Next(-3, 6);
                if (number < 1)
                {
                    return(ok(number));
                }
                CreditsHistory history = new CreditsHistory();
                history.change = number;
                history.type   = -1;
                Guid guid = Guid.NewGuid();
                history.objectId  = guid.ToString();
                history.updatedAt = DateTime.Now;
                history.createdAt = DateTime.Now;
                history.userId    = objectId;
                history.credit    = user.credit + history.change;

                if (historyBLL.shake(history, objectId))
                {
                    return(ok(number));
                }
                else
                {
                    return(notFound("发生错误"));
                }
            }
            catch (Exception e)
            {
                return(execept(e.Message));
            }
        }
Example #8
0
/// <summary>
/// 查询单个模型实体
/// </summary>
/// <param name="id">objectId</param>);
/// <returns>实体</returns>);
        public CreditsHistory QuerySingleById(string objectId)
        {
            const string sql = "SELECT TOP 1 objectId,createdAt,updatedAt,userId,type,change,credit,orderNum,bizId  from CreditsHistory WHERE [objectId] = @objectId";

            using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId)))
            {
                if (reader.HasRows)
                {
                    reader.Read();
                    CreditsHistory model = SqlHelper.MapEntity <CreditsHistory>(reader);
                    return(model);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #9
0
        // POST api/values  添加用户
        /// <summary>
        /// 手机端注册邀请接口
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="model"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        //public IHttpActionResult Post(string v1, [FromBody]_User model, string code)
        //{
        //    是否是手机端注册
        //    bool isPhone = false;
        //    try
        //    {
        //        表单验证
        //        if (isNUll(model.username, model.password, code))
        //        {
        //            return invildRequest("参数不能为空");
        //        }



        //        判断是否有openId
        //        if (model.authData == null || model.authData.wechat == null || isNUll(model.authData.wechat.openId))
        //        {
        //            无openId,手机端注册操作
        //            手机端短信验证


        //            string postUri = "sms/verify?appkey=1ad08332b2ac0&phone=" + model.username + "&zone=86&code=" + code;

        //            string userJson = @"{""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("验证码请求验证失败");
        //            }

        //            条件
        //            List<Wheres> list = new List<Wheres>();
        //            Wheres wh = new Wheres();
        //            wh.setField("username", "=", model.username, "");
        //            list.Add(wh);
        //            查询用户是否已经存在
        //            int num = bll.QueryCount(list);
        //            if (num > 0)
        //            {
        //                return notFound("用户名已存在");
        //            }
        //            isPhone = true;
        //        }
        //        else
        //        {
        //            有openId,微信端
        //            查询openId是否已经存在
        //            注册操作
        //            用户名已存在,则只更新记录

        //            微信端短信验证
        //            MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com");
        //            string postUri = "sms/checkcode?appkey=1077112ae0d07&phone=" + model.username + "&zone=86&code=" + code;

        //            string userJson = @"{""appkey"":""1ad08332b2ac0"",""phone"":" + model.username + @",""zone"":""86"",""code"":" + code + "}";
        //            请求验证
        //            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("验证码错误");
        //                }
        //            }
        //            else
        //            {
        //                return notFound("验证码请求验证失败");
        //            }


        //            if (bll.QueryExitByUsername(model.username) && wechat_bll.QueryExitByOpenId(model.authData.wechat.openId))
        //            {
        //                用户openId和username都已存在
        //                return notFound("用户已绑定过!");
        //            }
        //            else if (bll.QueryExitByUsername(model.username) && !wechat_bll.QueryExitByOpenId(model.authData.wechat.openId))
        //            {
        //                用户存在,openId不存在。微信绑定操作
        //                更新openId和inopenId

        //                model.authData.objectId = guid.ToString();
        //                model.authData.wechat.objectId = guid.ToString();

        //                邀请码选填
        //                if (isNUll(model.authData.wechat.inopenId))
        //                {
        //                    邀请码为空
        //                    if (bll.UpdateInsert1(model))
        //                    {
        //                        return ok(new { msg = "绑定成功" });
        //                    }
        //                    return notFound("绑定失败");
        //                }
        //                邀请码不为空
        //                if (!bll.QueryExitByUsername(model.authData.wechat.inopenId))
        //                {
        //                    inopenId无效
        //                    return notFound("您的邀请用户手机号无效!");
        //                }
        //                查询绑定记录表是否有注册用户和邀请人的组合。

        //                绑定只给邀请人积分,不给被邀请人积分
        //                邀请者记录
        //                条件
        //                List<Wheres> whs = new List<Wheres>() { new Wheres("username", "=", model.authData.wechat.inopenId) };
        //                _User user1 = bll.QuerySingleByWheres(whs);
        //                CreditsHistory history = new CreditsHistory();
        //                history.objectId = guid.ToString();
        //                history.createdAt = DateTime.Now;
        //                history.updatedAt = DateTime.Now;
        //                history.credit = user1.credit + 40;
        //                history.userId = user1.objectId;
        //                微信邀请好友
        //                history.type = 3;
        //                if (bll.UpdateInsert(model, history, 40))
        //                {
        //                    return ok(new { msg = "绑定成功" });
        //                }
        //                else
        //                {
        //                    return notFound("绑定失败");
        //                }
        //            }
        //            else if (!bll.QueryExitByUsername(model.username) && !wechat_bll.QueryExitByOpenId(model.authData.wechat.openId))
        //            {
        //                用户不存在,openId不存在,注册操作
        //                if (!isNUll(model.authData.wechat.inopenId))
        //                {
        //                    if (!bll.QueryExitByUsername(model.authData.wechat.inopenId))
        //                    {
        //                        inopenId无效
        //                        return notFound("您的邀请用户手机号无效!");
        //                    }
        //                }
        //                else
        //                {
        //                    model.authData.wechat.inopenId = "";
        //                }
        //                model.authData.objectId = guid.ToString();
        //                model.authData.wechat.objectId = guid.ToString();

        //            }
        //            else
        //            {
        //                return notFound("请检查数据是否正确");
        //            }
        //        }


        //        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 history2 = new CreditsHistory();
        //        history2.objectId = guid.ToString();
        //        history2.createdAt = dt;
        //        history2.updatedAt = dt;
        //        history2.change = 40;
        //        history2.credit = 40;
        //        history2.type = 4;//注册得积分

        //        bool result = false;

        //        if (isPhone)
        //        {
        //            result = bll.Insert1(model, history2);
        //        }
        //        else
        //        {
        //            if (isNUll(model.authData.wechat.inopenId))
        //            {
        //                没有邀请人
        //                result = bll.Insert(model, history2);
        //            }
        //            else
        //            {
        //                有邀请人
        //                条件
        //                List<Wheres> whs = new List<Wheres>() { new Wheres("username", "=", model.authData.wechat.inopenId) };
        //                _User user = bll.QuerySingleByWheres(whs);
        //                CreditsHistory history1 = new CreditsHistory();
        //                Guid guid1 = Guid.NewGuid();
        //                history1.objectId = guid1.ToString();
        //                history1.createdAt = dt;
        //                history1.updatedAt = dt;
        //                history1.type = 3;//邀请得积分
        //                history1.change = 40;
        //                history1.credit = user.credit + 40;
        //                history1.userId = user.objectId;
        //                result = bll.Insert(model, history2, history1);
        //            }

        //        }

        //        if (result)
        //        {
        //            return ok(new { msg = "注册成功" });
        //        }
        //        return notFound("注册失败");
        //    }
        //    catch (Exception e)
        //    {
        //        return execept(e.Message);
        //    }

        //}


        public IHttpActionResult PostUserCredits(string v1, string objectId, int credits, int type)
        {
            try
            {
                if (isNUll(objectId) || credits == 0 || type == 0)
                {
                    return(notFound("数据无效"));
                }
                //条件
                List <Wheres> whs = new List <Wheres>()
                {
                    new Wheres("objectId", "=", objectId)
                };
                var m = bll.QuerySingleById(objectId);
                if (m == null)
                {
                    return(notFound("数据无效"));
                }
                int            credit  = m.credit + credits;
                CreditsHistory history = new CreditsHistory();
                Guid           guid    = Guid.NewGuid();
                history.objectId  = guid.ToString();
                history.createdAt = DateTime.Now;
                history.updatedAt = DateTime.Now;
                history.type      = type;
                history.change    = credits;
                history.credit    = credit;
                if (bll.UpdateCreditByObjectId(objectId, history))
                {
                    //返回当前积分
                    return(ok(new { credit = credit }));
                }
                else
                {
                    return(notFound("修改失败"));
                }
            }
            catch (Exception e)
            {
                return(execept(e.Message));
            }
        }
Example #10
0
///<summary>
///分页查询一个集合
///</summary>
///<param name="index">页码</param>
///<param name="size">页大小</param>
///<param name="wheres">条件匿名类</param>
///<param name="orderField">排序字段</param>
///<param name="isDesc">是否降序排序</param>
///<returns>实体集合</returns>
        public IEnumerable <CreditsHistory> QueryList(int index, int size, object wheres = null, string orderField = "objectId", bool isDesc = true)
        {
            List <SqlParameter> list = null;

            string where = wheres.parseWheres(out list);
            orderField   = string.IsNullOrEmpty(orderField) ? "objectId" : orderField;
            var sql = SqlHelper.GenerateQuerySql("CreditsHistory", new string[] { "objectId", "createdAt", "updatedAt", "userId", "type", "change", "credit", "orderNum", "bizId" }, index, size, where, orderField, isDesc);

            using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray()))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CreditsHistory model = SqlHelper.MapEntity <CreditsHistory>(reader);
                        yield return(model);
                    }
                }
            }
        }
Example #11
0
 //有邀请码绑定操作
 public bool UpdateInsert(_User model, CreditsHistory history)
 {
     return(_dao.UpdateInsert(model, history));
 }
Example #12
0
 /// <summary>
 /// APP端,有邀请人注册
 /// </summary>
 /// <param name="model"></param>
 /// <param name="history"></param>
 /// <returns></returns>
 public bool Insert1(_User model, CreditsHistory history, CreditsHistory history1, string inviteCode)
 {
     return(_dao.Insert1(model, history, history1, inviteCode));
 }
Example #13
0
 /// <summary>
 /// APP端,没有邀请人注册
 /// </summary>
 /// <param name="model"></param>
 /// <param name="history"></param>
 /// <returns></returns>
 public bool Insert1(_User model, CreditsHistory history)
 {
     return(_dao.Insert1(model, history));
 }
Example #14
0
/// <summary>
/// 微信端,有邀请人注册
/// </summary>
/// <param name="model"></param>
/// <param name="history"></param>
/// <param name="history1"></param>
/// <returns></returns>
        public bool Insert(_User model, CreditsHistory history, CreditsHistory history1)
        {
            return(_dao.Insert(model, history, history1));
        }
Example #15
0
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>是否成功</returns>
        public bool Update(CreditsHistory model)
        {
            const string sql = @"UPDATE [dbo].[CreditsHistory] SET  createdAt=@createdAt,updatedAt=@updatedAt,userId=@userId,type=@type,change=@change,credit=@credit,orderNum=@orderNum,bizId=@bizId   WHERE [objectId] = @objectId";

            return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@createdAt", model.createdAt.ToDBValue()), new SqlParameter("@updatedAt", model.updatedAt.ToDBValue()), new SqlParameter("@userId", model.userId.ToDBValue()), new SqlParameter("@type", model.type.ToDBValue()), new SqlParameter("@change", model.change.ToDBValue()), new SqlParameter("@credit", model.credit.ToDBValue()), new SqlParameter("@orderNum", model.orderNum.ToDBValue()), new SqlParameter("@bizId", model.bizId.ToDBValue())) > 0);
        }
 ///<summary>
 ///向数据库中添加一条记录
 ///</summary>
 ///<param name="model">要添加的实体</param>
 public bool SignIn(CreditsHistory model, string userId)
 {
     return(_dao.SignIn(model, userId));
 }
Example #17
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));
            }
        }
Example #18
0
        //public bool UpdateCreditByOpenId(string openId,int credit)
        //{
        //    return _dao.UpdateCreditByOpenId(openId, credit);
        //}

        public bool UpdateCreditByObjectId(string objectId, CreditsHistory history)
        {
            return(_dao.UpdateCreditByObjectId(objectId, history));
        }
/// <summary>
/// 向数据库中添加一条记录
/// </summary>
/// <param name="model">要添加的实体</param>
/// <returns>是否成功</returns>
        public bool Insert(CreditsHistory model)
        {
            return(_dao.Insert(model));
        }
 public bool InsertWithOrderInfo(CreditsHistory model)
 {
     return(_dao.InsertWithOrderInfo(model));
 }
/// <summary>
/// 根据主键更新一条记录
/// </summary>
/// <param name="model">更新后的实体</param>
/// <returns>执行结果受影响行数</returns>
        public bool Update(CreditsHistory model)
        {
            return(_dao.Update(model));
        }
Example #22
0
        public IHttpActionResult Get(string v1, string objectId, int type)
        {
            try
            {
                if (string.IsNullOrEmpty(objectId))
                {
                    return(invildRequest("用户ID不能为空"));
                }

                _User user = userbll.QuerySingleById(objectId);
                if (user == null)
                {
                    return(notFound("用户不纯在"));
                }
                if (!user.sign_in)
                {
                    return(notFound("已签到"));
                }



                CreditsHistory history = new CreditsHistory();
                if (type == 0)
                {
                    history.type   = 0;
                    history.change = 2;
                }
                else if (type == 1)
                {
                    Random ran = new Random();
                    history.change = ran.Next(0, 6);
                    history.type   = 1;
                }
                else
                {
                    Random ran = new Random();
                    history.change = ran.Next(-2, 9);
                    history.type   = 2;
                }
                Guid guid = Guid.NewGuid();
                history.objectId = guid.ToString();

                history.updatedAt = DateTime.Now;
                history.createdAt = DateTime.Now;
                history.userId    = objectId;
                history.credit    = user.credit + history.change;

                if (historyBLL.SignIn(history, objectId))
                {
                    return(ok(history));
                }
                else
                {
                    return(notFound("发生错误"));
                }
            }
            catch (Exception e)
            {
                return(execept(e.Message));
            }
        }
Example #23
0
        public HttpResponseMessage parseCreditNotify(
            string appKey,
            string timestamp,
            bool success,
            string errormessage,
            string orderNum,
            string bizId,
            string sign
            )
        {
            Hashtable hshTable = duiba.GetUrlParams(HttpUtility.UrlDecode(Request.RequestUri.AbsoluteUri));
            string    newSign;

            if (appKey.Equals(APP_KEY) && timestamp != null && duiba.SignVerify(APP_SECRET, hshTable, out newSign))
            {
                //return creditError("appKey not match", userCredit);
                //return creditError("timestamp can't be null", userCredit);
                //return creditError("sign verify fail", userCredit);

                //CreditsHistory ch = chBll.QuerySingleByWheres(
                //    new List<Wheres> {
                //        new Wheres("objectId", "=", bizId),
                //        new Wheres("orderNum", "=", orderNum)
                //    });
                //if (ch == null)
                //{

                //}

                if (!success)
                {
                    CreditsHistory ch = chBll.QuerySingleByWheres(
                        new List <Wheres> {
                        //new Wheres("bizId", "=", bizId)
                        new Wheres("orderNum", "=", orderNum)
                    });

                    int    change     = ch.change;
                    int    userCredit = ch.credit;
                    string userId     = ch.userId;
                    userBll.UpdateById(userId, new Dictionary <string, object> {
                        { "credit", userCredit - change }
                    });

                    CreditsHistory ch2 = new CreditsHistory();
                    ch2.objectId  = "test" + Guid.NewGuid().ToString();
                    ch2.orderNum  = orderNum;
                    ch2.createdAt = DateTime.Now;
                    ch2.updatedAt = DateTime.Now;
                    ch2.userId    = userId;
                    ch2.type      = -2;
                    ch2.change    = (int)-change;
                    ch2.credit    = userBll.QuerySingleById(userId).credit;
                    ch2.orderNum  = orderNum;
                    ch2.bizId     = bizId;
                    chBll.Insert(ch2);
                }
            }

            return(new HttpResponseMessage {
                Content = new StringContent("ok", Encoding.GetEncoding("UTF-8"), "text/plain")
            });
        }
Example #24
0
        public IHttpActionResult parseCreditConsume(
            string uid,
            long credits,
            string appKey,
            string timestamp,
            string orderNum,
            string type,
            bool waitAudit,
            string sign,
            string description = null,
            int facePrice      = 0,
            int actualPrice    = 0,
            string ip          = null,
            string @params     = null
            )
        {
            _User user = userBll.QuerySingleById(uid);

            if (user == null)
            {
                return(creditError("no such user", 0));
            }
            long userCredit = user.credit;

            if (!appKey.Equals(APP_KEY))
            {
                return(creditError("appKey not match", userCredit));
            }

            if (timestamp == null)
            {
                return(creditError("timestamp can't be null", userCredit));
            }

            Hashtable hshTable = duiba.GetUrlParams(HttpUtility.UrlDecode(Request.RequestUri.AbsoluteUri));

            string newSign;
            bool   verify = duiba.SignVerify(APP_SECRET, hshTable, out newSign);

            if (!verify)
            {
                return(creditError("sign verify fail", userCredit));
            }
            else
            {
                if (userCredit < credits)
                {
                    return(creditError("credits not enough!", userCredit));
                }
                userBll.UpdateById(uid, new Dictionary <string, object> {
                    { "credit", userCredit - credits }
                });

                CreditsHistory ch = new CreditsHistory();
                ch.objectId  = "test" + Guid.NewGuid().ToString();
                ch.orderNum  = orderNum;
                ch.createdAt = DateTime.Now;
                ch.updatedAt = DateTime.Now;
                ch.userId    = uid;
                ch.type      = getCreditType(type);
                ch.change    = (int)-credits;
                ch.credit    = userBll.QuerySingleById(uid).credit;
                ch.orderNum  = orderNum;
                ch.bizId     = duiba.GetMd5(orderNum);

                bool flag = chBll.Insert(ch);

                return(flag ? creditOK(ch.bizId, ch.credit) : creditError("Unexpected Error, data roll back", userCredit));;
            }
        }
 ///<summary>
 ///向数据库中添加一条记录
 ///</summary>
 ///<param name="model">要添加的实体</param>
 public bool shake(CreditsHistory model, string userId)
 {
     return(_dao.shake(model, userId));
 }
Example #26
0
        /// <summary>
        /// 微信端注册与绑定接口
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="model"></param>
        /// <param name="code"></param>
        /// <param name="wechat"></param>
        /// <returns></returns>
        public IHttpActionResult Post(string v1, [FromBody] _User model, string code, bool wechat)
        {
            try
            {
                //表单验证
                if (isNUll(model.username, model.password, code))
                {
                    return(invildRequest("参数不能为空"));
                }
                //注册流程
                wechat chat = new wechat();
                //主键
                Guid guid = Guid.NewGuid();
                //判断是否有openId
                if (model.authData == null || model.authData.wechat == null || isNUll(model.authData.wechat.openId))
                {
                    return(invildRequest("参数有误"));
                }

                //微信端短信验证
                MvcApplication1.Utility.HttpClient client = new MvcApplication1.Utility.HttpClient("https://webapi.sms.mob.com");
                string postUri = "sms/checkcode?appkey=1077112ae0d07&phone=" + model.username + "&zone=86&code=" + code;

                //string userJson = @"{""appkey"":""1ad08332b2ac0"",""phone"":" + model.username + @",""zone"":""86"",""code"":" + code + "}";
                //请求验证
                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("验证码错误"));
                    }
                }
                else
                {
                    return(notFound("验证码请求验证失败"));
                }

                //判断微信号是否绑定过
                if (wechat_bll.QueryExitByOpenId(model.authData.wechat.openId))
                {
                    return(notFound("此微信号已经绑定过了哦!"));
                }
                //注册与绑定逻辑
                model.authData.objectId        = guid.ToString();
                model.authData.wechat.objectId = guid.ToString();

                //判断用户是否存在
                if (bll.QueryExitByUsername(model.username))
                {
                    //用户已存在
                    //微信绑定操作
                    //更新openId和inopenId
                    //邀请码选填
                    if (isNUll(model.authData.wechat.inopenId))
                    {
                        //邀请码为空,绑定
                        if (bll.UpdateInsert1(model))
                        {
                            return(ok(new { msg = "绑定成功" }));
                        }
                        return(notFound("绑定失败"));
                    }
                    //邀请码不为空
                    if (!bll.QueryExitByUsername(model.authData.wechat.inopenId))
                    {
                        //inopenId无效
                        return(notFound("您的邀请用户手机号无效!"));
                    }

                    //判断用户是否在APP端被邀请过
                    if (invite_bll.QueryExitByUsername(model.username))
                    {
                        //用户在APP端被邀请过,邀请用户不再获得积分,只进行微信信息绑定,双方均不得积分。
                        if (bll.UpdateInsert1(model))
                        {
                            return(ok(new { msg = "绑定成功" }));
                        }
                        return(notFound("绑定失败"));
                    }

                    //绑定只给邀请人积分,不给被邀请人积分
                    //邀请者记录
                    //条件
                    List <Wheres> whs = new List <Wheres>()
                    {
                        new Wheres("username", "=", model.authData.wechat.inopenId)
                    };
                    _User          user    = bll.QuerySingleByWheres(whs);
                    CreditsHistory history = new CreditsHistory();
                    history.objectId  = guid.ToString();
                    history.createdAt = DateTime.Now;
                    history.updatedAt = DateTime.Now;
                    history.change    = 30;
                    history.credit    = user.credit + 30;
                    history.userId    = user.objectId;
                    //微信邀请好友
                    history.type = 3;
                    if (bll.UpdateInsert(model, history))
                    {
                        return(ok(new { msg = "绑定成功" }));
                    }
                    else
                    {
                        return(notFound("绑定失败"));
                    }
                }
                //用户不存在
                //微信注册操作

                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 history2 = new CreditsHistory();
                history2.objectId  = guid.ToString();
                history2.createdAt = dt;
                history2.updatedAt = dt;
                history2.change    = 40;
                history2.credit    = 40;
                history2.type      = 4;//注册得积分
                bool result = false;
                if (isNUll(model.authData.wechat.inopenId))
                {
                    //没有邀请人
                    result = bll.Insert(model, history2);
                }
                else
                {
                    //有邀请人
                    //条件
                    List <Wheres> whs = new List <Wheres>()
                    {
                        new Wheres("username", "=", model.authData.wechat.inopenId)
                    };
                    _User          user     = bll.QuerySingleByWheres(whs);
                    CreditsHistory history1 = new CreditsHistory();
                    Guid           guid1    = Guid.NewGuid();
                    history1.objectId  = guid1.ToString();
                    history1.createdAt = dt;
                    history1.updatedAt = dt;
                    history1.type      = 3;//邀请得积分
                    history1.change    = 30;
                    history1.credit    = user.credit + 30;
                    history1.userId    = user.objectId;
                    result             = bll.Insert(model, history2, history1);
                }
                if (result)
                {
                    return(ok(new { msg = "注册成功" }));
                }
                return(notFound("注册失败"));
            }
            catch (Exception e)
            {
                return(execept(e.Message));
            }
        }