Ejemplo n.º 1
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddUserInfo(AttendUserModel model)
        {
            string strSql = string.Format(@"insert into Hot_AttendUser(customerid,openid,nickname,headimgurl,unionid,city,couponcode,money,isattend,defmoney) values(@customerid,@openid,@nickname,@headimgurl,@unionid,@city,@couponcode,@money,@isattend,@defmoney);select @@IDENTITY");

            SqlParameter[] parameters =
            {
                new SqlParameter("@customerid", model.customerid),
                new SqlParameter("@openid",     model.openid),
                new SqlParameter("@nickname",   model.nickname),
                new SqlParameter("@headimgurl", model.headimgurl),
                new SqlParameter("@unionid",    model.unionId),
                new SqlParameter("@city",       model.city),
                new SqlParameter("@couponcode", model.couponCode),
                new SqlParameter("@money",      model.money),
                new SqlParameter("@isattend",   model.isAttend),
                new SqlParameter("@defmoney",   model.defmoney)
            };
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        private void GethelpUserList()
        {
            string          shareopenid = this.GetFormValue("shareopenid", "");//分享用户
            int             customerid  = this.GetFormValue("customerid", 0);
            int             pageIndex   = this.GetFormValue("pageIndex", 0);
            int             pageSize    = this.GetFormValue("pageSize", 0);
            AttendUserModel userModel   = UserService.Instance.GetAttendUserInfo(customerid, shareopenid);

            if (userModel != null)
            {
                List <HelpUserModel> lst = UserService.Instance.GethelpUserList(pageIndex, pageSize, customerid, userModel.id);
                this.Data["data"]  = lst;
                this.Data["count"] = lst.Count();
                this.code          = 1;
            }
            this.Data["pageIndex"] = pageIndex;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据优惠券码获取用户信息
        /// </summary>
        /// <param name="customerid"></param>
        /// <param name="couponCode"></param>
        /// <returns></returns>
        public AttendUserModel GetUserCouponInfo(int customerid, string couponCode)
        {
            string sql = "select top 1 id,customerid,openid,nickname,headimgurl,unionid,city,couponcode,money,isattend,defmoney,useStatus,shopUserId from Hot_AttendUser where  couponCode=@couponCode and customerid=@customerid";

            SqlParameter[] parameters =
            {
                new SqlParameter("@customerid", customerid),
                new SqlParameter("@couponCode", couponCode)
            };
            AttendUserModel model = new AttendUserModel();

            using (SqlDataReader dr = DbHelperSQL.ExecuteReader(sql, parameters))
            {
                model = DbHelperSQL.GetEntity <AttendUserModel>(dr);
            }
            return(model);
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int shopid = UserService.Instance.GetShopId(CurrentCustomerID, this.GetOpenIdVal());

            if (shopid > 0)
            {
                userModel = UserService.Instance.GetUserCouponInfo(CurrentCustomerID, couponCode);
                if (UserService.Instance.ShopUseCoupon(CurrentCustomerID, shopid, couponCode) > 0)
                {
                    isSuccess = true;
                    showText  = "使用成功";
                }
                else
                {
                    isSuccess = false;
                    showText  = "优惠券已使用";
                }
            }
            else
            {
                isSuccess = false;
                showText  = "您不是经销商,请去绑定账号!";
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="oauth"></param>
        /// <returns></returns>
        public int RegisterUser(int customerId, WeixinOAuthUserInfoModel oauth)
        {
            AttendUserModel model = new AttendUserModel()
            {
                customerid = customerId,
                headimgurl = oauth.Headimgurl,
                openid     = oauth.Openid,
                nickname   = oauth.Nickname,
                city       = oauth.City,
                isAttend   = 0,
                unionId    = oauth.UnionID,
                couponCode = StringHelper.RandomNo(new Random(Guid.NewGuid().GetHashCode()), 16)
            };
            string couponValue = ConfigHelper.GetConfigString("couponValue", "0");

            if (!string.IsNullOrEmpty(couponValue))
            {
                model.money = Convert.ToDecimal(couponValue);
            }

            model.defmoney = model.money;

            return(dal.AddUserInfo(model));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 帮忙砍价
        /// </summary>
        private void HelpBargain()
        {
            string  shareopenid = this.GetFormValue("shareopenid", ""); //分享用户
            string  openid      = this.GetFormValue("openid", "");      //当前用户
            int     customerid  = this.GetFormValue("customerid", 0);
            decimal money       = 0;

            string[] arr  = sectionVal.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            int      minV = Convert.ToInt32(arr[0]);
            int      maxV = Convert.ToInt32(arr[1]);

            string[] arr2  = sectionVal2.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            int      minV2 = Convert.ToInt32(arr2[0]);
            int      maxV2 = Convert.ToInt32(arr2[1]);

            try
            {
                AttendUserModel userModel = UserService.Instance.GetAttendUserInfo(customerid, shareopenid);
                if (userModel != null && userModel.isAttend == 1)
                {
                    bool isHelped = UserService.Instance.GethelpUser(customerid, openid, userModel.id);
                    if (isHelped)//已经助力过
                    {
                        this.code = 2;
                        msg       = getTipContent(customerid, 2);
                        return;
                    }
                    //已经砍到最大额度了
                    if (couponMaxValue <= userModel.money)
                    {
                        this.code = 3;
                        msg       = getTipContent(customerid, 3);
                        return;
                    }

                    if (userModel.useStatus == 1)
                    {
                        this.code = 5;
                        msg       = getTipContent(customerid, 5);
                        return;
                    }


                    string   endTime = ConfigHelper.GetConfigString("endTime", "2016-05-02");
                    DateTime outime;
                    DateTime.TryParse(endTime, out outime);
                    if (DateTime.Now > outime)//判断活动是否结束
                    {
                        this.code = 4;
                        msg       = getTipContent(customerid, 4);
                        return;
                    }



                    Random random = new Random(Guid.NewGuid().GetHashCode());
                    if (userModel.money < 500)
                    {
                        money = Convert.ToDecimal((random.Next(minV, maxV) - random.NextDouble()));
                    }
                    else //用户助力到500元后,取另外一个金额区间
                    {
                        money = Convert.ToDecimal((random.Next(minV2, maxV2) - random.NextDouble()));
                    }

                    //当前看的价格加当前的价格,大于优惠券最大价格时
                    if (couponMaxValue <= (userModel.money + money))
                    {
                        money = couponMaxValue - userModel.money;
                    }

                    //更新优惠券额度
                    UserService.Instance.UpdateAttendUserMoney(customerid, shareopenid, money);
                    //添加砍价记录
                    UserService.Instance.AddHelpUser(customerid, userModel.id, openid, money);

                    code = 1;
                }
                else
                {
                    msg = getTipContent(customerid, 1);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            finally
            {
                this.Data["money"] = money.ToString("f2");
            }
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(shareOpenId))
            {
                WriteLog("invalid URL");
            }

            DateTime outime;

            DateTime.TryParse(actEndTime, out outime);
            if (DateTime.Now < outime)
            {
                isEnd = false;
            }
            else
            {
                isEnd = true;
            }

            if (currentOpenid == shareOpenId)//当前是自己访问自己的页面
            {
                userModel = UserService.Instance.GetAttendUserInfo(CurrentCustomerID, currentOpenid);
                _self     = true;
                if (userModel != null)
                {
                    if (userModel.isAttend == 0 && !isEnd)
                    {
                        //修改用户参与状态
                        UserService.Instance.UpdateAttendUserStatus(CurrentCustomerID, currentOpenid);
                    }

                    if (userModel.isAttend == 0 && isEnd)
                    {
                        WriteLog("活动已结束");
                    }


                    if (userModel.useStatus == 0)
                    {
                        this.ShowText = "朋友已帮 <span style='color:red'>wo</span> 砍价" + (userModel.money - userModel.defmoney) + "元";
                    }
                    else
                    {
                        this.ShowText = "您的优惠券已使用!";
                    }
                }
            }
            else
            {
                _self     = false;
                userModel = UserService.Instance.GetAttendUserInfo(CurrentCustomerID, shareOpenId);
                if (userModel != null)
                {
                    if (userModel.useStatus == 0)
                    {
                        this.ShowText = "<span style='color:red'>" + userModel.nickname + "</span>邀请您帮TA砍价";
                    }
                    else
                    {
                        this.ShowText = "<span style='color:red'>" + userModel.nickname + "</span>的优惠券已使用";
                    }
                }
            }

            if (userModel != null)
            {
                myCouponCode.Value = userModel.couponCode;
                attendCount        = UserService.Instance.GetAttendActCount(CurrentCustomerID, userModel.id);
            }
        }