/// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add(Musercoupon model)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                DateTime dateTimeNow = System.DateTime.Now;
                model.isDelete    = "0";
                model.isEffective = "1";
                model.great_time  = dateTimeNow;
                model.modify_time = dateTimeNow;
                model.id          = PublicTools.GetRandomNumberByTime();
                if (new UserCouponService().Add(model))
                {
                    mwxResult.errcode = 0;
                    mwxResult.errmsg  = "操作成功!";
                }
                else
                {
                    mwxResult.errmsg = "操作失败!";
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 新增产品分类方法接口
 /// </summary>
 /// <returns></returns>
 public string AddUserGroupMeth(Musercoupon model)
 {
     if (!base.CheckIsLogin())
     {
         return("-1");
     }
     return(new UserCouponBus().Add(model));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(Musercoupon model)
        {
            //// sql语句
            string sql = "INSERT INTO usercoupon (id,userId,userName,couponId,name,price,consumAmount,effectiveStart,effectiveEnd,receiveTime,isUse,useTime,orderId,isDelete,isEffective,great_time,modify_time) " +
                         "VALUES (?id,?userId,?userName,?couponId,?name,?price,?consumAmount,?effectiveStart,?effectiveEnd,?receiveTime,?isUse,?useTime,?orderId,?isDelete,?isEffective,?great_time,?modify_time)";

            List <MySqlParameter> parameterList = GetMySqlParameterListByModel(model);

            //// 执行操作
            return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据id获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Musercoupon GetById(string id)
        {
            Musercoupon model = null;

            string sql = "  SELECT  id,userId,userName,couponId,name,price,consumAmount,effectiveStart,effectiveEnd,receiveTime,isUse,useTime,orderId,isDelete,isEffective,great_time,modify_time " +
                         $" FROM usercoupon WHERE id=?id ; ";


            MySqlParameter[] parameterList = new MySqlParameter[1];
            MySqlParameter   parameter     = new MySqlParameter("?id", MySqlDbType.VarChar, 25);

            parameter.Value  = id;
            parameterList[0] = parameter;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList))
            {
                if (sqlDataReader.Read())
                {
                    model    = new Musercoupon();
                    model.id = sqlDataReader["id"] != DBNull.Value ? sqlDataReader["id"].ToString() : string.Empty;

                    model.userId = sqlDataReader["userId"] != DBNull.Value ? sqlDataReader["userId"].ToString() : string.Empty;

                    model.userName = sqlDataReader["userName"] != DBNull.Value ? sqlDataReader["userName"].ToString() : string.Empty;

                    model.userName = Base64.DecodeBase64(model.userName);

                    model.couponId     = sqlDataReader["couponId"] != DBNull.Value ? sqlDataReader["couponId"].ToString() : string.Empty;
                    model.name         = sqlDataReader["name"] != DBNull.Value ? sqlDataReader["name"].ToString() : string.Empty;
                    model.price        = sqlDataReader["price"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["price"].ToString()) : 0M;
                    model.consumAmount = sqlDataReader["consumAmount"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["consumAmount"].ToString()) : 0M;

                    model.effectiveStart = sqlDataReader["effectiveStart"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["effectiveStart"].ToString()) : DateTime.MinValue;
                    model.effectiveEnd   = sqlDataReader["effectiveEnd"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["effectiveEnd"].ToString()) : DateTime.MinValue;

                    model.receiveTime = sqlDataReader["receiveTime"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["receiveTime"].ToString()) : DateTime.MinValue;

                    model.useTime = sqlDataReader["useTime"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["useTime"].ToString()) : DateTime.MinValue;

                    model.isUse   = sqlDataReader["isUse"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["isUse"].ToString()) : 0;
                    model.orderId = sqlDataReader["orderId"] != DBNull.Value ? sqlDataReader["orderId"].ToString() : string.Empty;

                    model.isEffective = sqlDataReader["isEffective"] != DBNull.Value ? sqlDataReader["isEffective"].ToString() : string.Empty;
                    model.isDelete    = sqlDataReader["isDelete"] != DBNull.Value ? sqlDataReader["isDelete"].ToString() : string.Empty;

                    model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                    model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;
                }
            }

            return(model);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Add(Musercoupon model)
 {
     return(opertService.Add(model));
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获取参数化查询对象
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private List <MySqlParameter> GetMySqlParameterListByModel(Musercoupon model)
        {
            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = new MySqlParameter("?id", MySqlDbType.VarChar, 25);

            parameter.Value = model.id;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?userId", MySqlDbType.VarChar, 25);
            parameter.Value = model.userId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?userName", MySqlDbType.VarChar, 500);
            parameter.Value = Base64.EncodeBase64(model.userName);
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?couponId", MySqlDbType.VarChar, 25);
            parameter.Value = model.couponId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?name", MySqlDbType.VarChar, 100);
            parameter.Value = model.name;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?price", MySqlDbType.Decimal);
            parameter.Value = model.price;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?consumAmount", MySqlDbType.Decimal);
            parameter.Value = model.consumAmount;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?effectiveStart", MySqlDbType.DateTime);
            parameter.Value = model.effectiveStart;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?effectiveEnd", MySqlDbType.DateTime);
            parameter.Value = model.effectiveEnd;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?receiveTime", MySqlDbType.DateTime);
            parameter.Value = model.receiveTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isUse", MySqlDbType.Int16, 1);
            parameter.Value = model.isUse;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?useTime", MySqlDbType.DateTime);
            parameter.Value = model.useTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?couponId", MySqlDbType.VarChar, 25);
            parameter.Value = model.couponId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?orderId", MySqlDbType.VarChar, 25);
            parameter.Value = model.orderId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isDelete", MySqlDbType.Int16, 1);
            parameter.Value = model.isDelete;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isEffective", MySqlDbType.Int16, 1);
            parameter.Value = model.isEffective;
            parameterList.Add(parameter);

            DateTime dateTime = System.DateTime.Now;

            parameter       = new MySqlParameter("?great_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?modify_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            return(parameterList);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 分页获取新闻信息
        /// </summary>
        /// <param name="pagIndex">页码(第一页从1 开始)</param>
        /// <param name="pagCount">每页数据条数</param>
        /// <returns></returns>
        public List <Musercoupon> GetPagList(string userId, int isUse, int pagIndex, int pagCount)
        {
            // 查询条件
            StringBuilder sqlWhere = new StringBuilder(" 1=1 ");

            if (!string.IsNullOrEmpty(userId))
            {
                sqlWhere.Append(" and userId = ?userId");
            }

            if (isUse >= 0)
            {
                sqlWhere.Append(" and isUse = ?isUse");
            }

            string sql = "  SELECT  id,userId,userName,couponId,name,price,consumAmount,effectiveStart,effectiveEnd,receiveTime,isUse,useTime,orderId,isDelete,isEffective,great_time,modify_time " +
                         $" FROM usercoupon WHERE {sqlWhere.ToString()} and isDelete=0 ORDER BY 1 desc ,1 desc limit {((pagIndex - 1) * pagCount)}, {pagCount}; ";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = new MySqlParameter("?userId", MySqlDbType.VarChar);

            parameter.Value = userId;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isUse", MySqlDbType.Int32);
            parameter.Value = isUse;
            parameterList.Add(parameter);

            List <Musercoupon> listModel = null;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList.ToArray()))
            {
                if (sqlDataReader != null)
                {
                    listModel = new List <Musercoupon>();
                    while (sqlDataReader.Read())
                    {
                        Musercoupon model = new Musercoupon();
                        model.id = sqlDataReader["id"] != DBNull.Value ? sqlDataReader["id"].ToString() : string.Empty;

                        model.userId = sqlDataReader["userId"] != DBNull.Value ? sqlDataReader["userId"].ToString() : string.Empty;

                        model.userName = sqlDataReader["userName"] != DBNull.Value ? sqlDataReader["userName"].ToString() : string.Empty;

                        model.userName = Base64.DecodeBase64(model.userName);

                        model.couponId     = sqlDataReader["couponId"] != DBNull.Value ? sqlDataReader["couponId"].ToString() : string.Empty;
                        model.name         = sqlDataReader["name"] != DBNull.Value ? sqlDataReader["name"].ToString() : string.Empty;
                        model.price        = sqlDataReader["price"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["price"].ToString()) : 0M;
                        model.consumAmount = sqlDataReader["consumAmount"] != DBNull.Value ? Convert.ToDecimal(sqlDataReader["consumAmount"].ToString()) : 0M;

                        model.effectiveStart = sqlDataReader["effectiveStart"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["effectiveStart"].ToString()) : DateTime.MinValue;
                        model.effectiveEnd   = sqlDataReader["effectiveEnd"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["effectiveEnd"].ToString()) : DateTime.MinValue;

                        model.receiveTime = sqlDataReader["receiveTime"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["receiveTime"].ToString()) : DateTime.MinValue;

                        model.useTime = sqlDataReader["useTime"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["useTime"].ToString()) : DateTime.MinValue;

                        model.isUse   = sqlDataReader["isUse"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["isUse"].ToString()) : 0;
                        model.orderId = sqlDataReader["orderId"] != DBNull.Value ? sqlDataReader["orderId"].ToString() : string.Empty;

                        model.isEffective = sqlDataReader["isEffective"] != DBNull.Value ? sqlDataReader["isEffective"].ToString() : string.Empty;
                        model.isDelete    = sqlDataReader["isDelete"] != DBNull.Value ? sqlDataReader["isDelete"].ToString() : string.Empty;

                        model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                        model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;

                        listModel.Add(model);
                    }
                }
            }

            return(listModel);
        }