示例#1
0
        public CouponPrizeDTO GetCouponDetail(string openId, int id)
        {
            CouponPrizeDTO result = null;

            var model = _ubll.GetModel(id);

            if (model != null)
            {
                if (model.openid == openId)
                {
                    var data = new CouponPrizeDTO()
                    {
                        id     = id,
                        status = model.hasLingQu,
                        jpname = model.jpName,
                        jxname = model.jxName,
                        sn     = model.sn
                    };

                    if (model.actId != null)
                    {
                        var aModel = _actBll.GetModel(model.actId.Value);
                        if (aModel.beginDate != null)
                        {
                            data.beginDate = aModel.beginDate.Value.ToString("yyyy-MM-dd");
                        }
                        if (aModel.endDate != null)
                        {
                            data.endDate = aModel.endDate.Value.ToString("yyyy-MM-dd");
                        }
                    }

                    result = data;
                }
            }

            return(result);
        }
示例#2
0
        public void GetRandomCoupon(int aid, int wid, string openid)
        {
            OAuthUserInfo user = null;

            try
            {
                var thisOpenid = string.Empty;
                if (Session["OAuthUser"] == null)
                {
                    thisOpenid = openid;
                }
                else
                {
                    user       = Session["OAuthUser"] as OAuthUserInfo;
                    thisOpenid = user.openid;
                }

                if (Session["openid"] == null)
                {
                    if (!string.IsNullOrEmpty(thisOpenid))
                    {
                        Session["openid"] = thisOpenid;
                    }
                }



                var service = new CouponService();

                var couponDto = service.GetRandomCoupon(thisOpenid, aid, wid);
                var data      = new
                {
                    coupon = couponDto,
                    user   = user
                };
                Context.Response.Write(AjaxResult.Success(data));
            }
            catch (JsonException jsEx)
            {
                CouponPrizeDTO dto = null;
                //可以摇时显示没奖时候消息
                var arr = new[] { "nomore", "notimes" };
                if (arr.Contains(jsEx.ErrorType))
                {
                    string jpname = ConfigurationManager.AppSettings["shakeLuckyMoney_defaultNulljpname"];
                    string jxname = ConfigurationManager.AppSettings["shakeLuckyMoney_defaultNulljxname"];
                    dto = new CouponPrizeDTO()
                    {
                        jpname  = jpname,
                        jxname  = jxname,
                        getTime = DateTime.Now.ToString("yy-MM-dd HH-mm-ss")
                    };
                }

                var data = new
                {
                    coupon = dto,
                    user   = user
                };
                var result = AjaxResult.Error(jsEx.Message, jsEx.ErrorType);
                result.Data = data;
                Context.Response.Write(result);
            }
            catch (Exception ex)
            {
                var s = "";
                if (ex.InnerException != null)
                {
                    s = ex.InnerException.Message;
                }
                Context.Response.Write(AjaxResult.Error(s));
            }
        }
示例#3
0
        //public CouponDTO GetCoupon(string openId, Guid couponUsageId)
        //{
        //    CouponDTO result = null;

        //    if (!string.IsNullOrEmpty(openId))
        //    {
        //        var coupon = _repository.GetCouponByUser(couponUsageId, openId);
        //        if (coupon != null)
        //        {
        //            result = TransformCoupon(coupon);
        //        }
        //    }

        //    return result;
        //}



        /// <summary>
        /// 获取随机优惠券
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="aid"></param>
        /// <param name="wid"></param>
        /// <returns></returns>
        public CouponPrizeDTO GetRandomCoupon(string openid, int aid, int wid)
        {
            CouponPrizeDTO result = null;

            //抽奖
            #region 判断活动

            if (aid == 0 || wid == 0 || openid.Trim() == "")
            {
                throw new JsonException("参数错误!", "system");
            }
            var dzpAction = _actBll.GetModel(aid);
            if (dzpAction == null)
            {
                throw new JsonException("参数错误!", "system");
            }

            if (dzpAction.endDate <= DateTime.Now)
            {
                throw new JsonException("活动已结束", "end");
            }
            else if (dzpAction.beginDate > DateTime.Now)
            {
                throw new JsonException("活动未开始", "nostart");
            }



            int dayMaxTimes = dzpAction.dayMaxTimes ?? 0;
            //int perMaxTimes = dzpAction.personMaxTimes ?? 0;
            //判断每人最大抽奖次数,是否超过了
            if (personCJTimes(openid, aid) >= dzpAction.personMaxTimes)
            {
                throw new JsonException("您已抽过奖了,欢迎下次再来!", "notimes");
            }
            if (isTodayOverSum(aid, openid, dayMaxTimes))
            {
                throw new JsonException("每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会。", "notimes");
            }
            Model.wx_dzpAwardUser award = _ubll.getZJinfoByOpenid(aid, openid);
            if (award != null)
            {
                throw new JsonException("您中奖了,欢迎下次再来!", "notimes");
            }


            #endregion

            //#region 保存用户信息

            //if (wxUser != null)
            //{
            //    //保存微信用户信息
            //    var user = new UserInfoEntity()
            //    {
            //        openid = wxUser.openid,
            //        // groupid = wxUser.groupid,
            //        headimgurl = wxUser.headimgurl,
            //        // language = wxUser.language,
            //        province = wxUser.province,
            //        // remark = wxUser.remark,
            //        // subscribe = wxUser.subscribe,
            //        //  subscribe_time = wxUser.subscribe_time,
            //        nickname = wxUser.nickname,
            //        sex = wxUser.sex,
            //        city = wxUser.country,
            //        country = wxUser.country
            //    };
            //    user.SaveUser();
            //}

            //#endregion

            #region 计算中奖信息

            /// 处理是否中奖
            /// hidStatus 状态为-1:不能抽奖,直接跳转到end.aspx页面;
            /// 0:抽奖次数超过设置的最高次数;
            /// 1:还可以继续抽奖;
            /// 2:中奖了;

            List <Model.wx_dzpAwardItem> itemlist = _itemBll.GetModelList("actId=" + aid);//该活动的所有奖项信息
            int ttJpNum = 0;
            for (int i = 0; i < itemlist.Count; i++)
            {
                ttJpNum += itemlist[i].jpRealNum.Value;
            }


            IList <Model.wx_dzpAwardUser> auserlist = _ubll.getHasZJList(aid);//已经中奖的人列表
            int ZhongJiangNum = 0;
            if (auserlist != null)
            {
                ZhongJiangNum = auserlist.Count; //已经中奖的人数
            }

            int syZjNum = ttJpNum - ZhongJiangNum; //剩余的奖品数量
            if (syZjNum <= 0)
            {
                //说明已经没有奖品了
                throw new JsonException(dzpAction.cfcjhf, "nomore");
            }
            dzpAction.personNum      = MyCommFun.Obj2Int(dzpAction.personNum, 1);
            dzpAction.personMaxTimes = MyCommFun.Obj2Int(dzpAction.personMaxTimes, 1);
            int fenmo = dzpAction.personNum.Value * dzpAction.personMaxTimes.Value;

            Random rd     = new Random((int)DateTime.Now.Ticks);
            int    radNum = rd.Next(0, fenmo);//从0到fenmo里随机出一个值
            if (radNum < syZjNum)
            {
                //中奖了,再从剩余奖品里抽取一个奖品
                Model.wx_dzpAwardItem dajiang = getZJItem(itemlist, auserlist);
                if (dajiang != null)
                {
                    //这是中的中奖了
                    string snumber = Get_snumber(aid);
                    int    uId     = _ubll.Add(aid, "", "", openid, dajiang.jxName, dajiang.jpName, snumber);
                    result = new CouponPrizeDTO()
                    {
                        sortid  = dajiang.sort_id.Value,
                        jxname  = dajiang.jxName,
                        jpname  = dajiang.jpName,
                        id      = uId,
                        sn      = snumber,
                        getTime = DateTime.Now.ToString("yy-MM-dd HH-mm-ss")
                    };
                }
                else
                {
                    //说明已经没有奖品了
                    throw new JsonException(dzpAction.cfcjhf, "nomore");
                }
            }
            else
            {
                //这个条件说明:未中奖
                //抛出未中奖的数据
                //说明已经没有奖品了
                throw new JsonException(dzpAction.cfcjhf, "nomore");
            }



            #endregion
            return(result);
        }