예제 #1
0
 /// <summary>
 /// 获取短信验证码
 /// </summary>
 /// <param name="strTel"></param>
 /// <returns></returns>
 public ActionResult getValidSMS(string strTel)
 {
     try
     {
         //List<WxUserEntity> list = null;
         //校验次手机号是否已注册
         var list = new WxUserBC().GetWxUserListByCondition(null, strTel, null, null).ToList();
         if (list.Count > 0)
         {
             return(Json("该手机号已注册", JsonRequestBehavior.AllowGet));
         }
         else
         {
             string yzmCode = CommonHelper.CreateNumber(4, true);
             //Session["RegisterCode"] = new SMSCodes { Code = yzmCode, CreteTime = DateTime.Now, IsUsered = false };
             Session["RegisterCode"] = "1234";
             //SendMessageHelper.SmsSend(strTel, SendMessageHelper.YZMMBContent(yzmCode));
             return(Json("Success", JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         LogHelp.WriteLog("getValidSMS:" + ex.Message);
     }
     return(Json("Error", JsonRequestBehavior.AllowGet));
 }
예제 #2
0
        /// <summary>
        /// 新增砍价数据
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="classid"></param>
        /// <param name="price"></param>
        /// <returns></returns>
        public ActionResult AddBargain(string openid, string classid, string price)
        {
            try
            {
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(classid) || string.IsNullOrEmpty(price))
                {
                    return(Json(string.Empty));
                }


                //判断是否注册
                var userInfo = new WxUserBC().GetWxUserByOpenid(openid);
                if (string.IsNullOrEmpty(userInfo.Phone))
                {
                    string url = CommonHelper.GetRedirect("WxMy%2fRegistered");
                    //Response.Redirect(url);
                    return(Json(url, JsonRequestBehavior.AllowGet));
                }

                var result = new OrderBC().GetBargainByOpenIdAndClassId(classid, openid);
                if (result != null)
                {
                    return(Json("/WxOrder/Bargain?bargainid=" + result.BargainId, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string bargainId = Guid.NewGuid().ToString();

                    BargainEntity entity = new BargainEntity()
                    {
                        BargainId = bargainId,
                        OpenId    = openid,
                        ClassId   = classid,
                        PrePrice  = Convert.ToDecimal(price),
                        NowPrice  = Convert.ToDecimal(price),
                    };

                    var addResult = new OrderBC().AddBargain(entity, openid);
                    if (addResult > 0)
                    {
                        string okUrl = "/WxOrder/Bargain?bargainid=" + bargainId;
                        return(Json(okUrl, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(string.Empty, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
        public ActionResult GroupBuy(string code, string classId)
        {
            string openid = "";

            if (new AppSetting().IsDebug != null &&
                new AppSetting().IsDebug.ToLower() == "true")
            {
                openid = "123";
            }
            else
            {
                if (Request.Cookies[SystemConfig.WXOpenIDCookieKey] != null)
                {
                    openid = Request.Cookies[SystemConfig.WXOpenIDCookieKey].Value;
                }

                if (string.IsNullOrWhiteSpace(openid) && code == null)
                {
                    Response.Redirect(CommonHelper.GetRedirect("WxMy%2fGroupBuy"));
                }
                try
                {
                    if (string.IsNullOrWhiteSpace(openid))
                    {
                        openid = GetOpenId(code).openid;


                        // 合法用户,允许访问
                        Response.Cookies[SystemConfig.WXOpenIDCookieKey].Value   = openid;
                        Response.Cookies[SystemConfig.WXOpenIDCookieKey].Path    = "/";
                        Response.Cookies[SystemConfig.WXOpenIDCookieKey].Expires = DateTime.Now.AddDays(1);
                    }
                }
                catch (Exception ex)
                {
                }
            }


            //判断是否注册
            var userInfo = new WxUserBC().GetWxUserByOpenid(openid);

            if (string.IsNullOrEmpty(userInfo.Phone))
            {
                Response.Redirect(CommonHelper.GetRedirect("WxMy%2fRegistered"));
            }



            ViewBag.Openid  = openid;
            ViewBag.ClassId = classId;
            return(View());
        }
예제 #4
0
        /// <summary>
        /// 1.根据classid找到课程助力配置
        /// 2.根据openid判断是否助力过
        /// 3.生成该openid该课程助力数据
        /// 4.更新助力人的助力人数
        /// 5.插入助力人员表
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="classid"></param>
        /// <returns></returns>
        public ActionResult HelpClass(string code, string state, string classid, string ownOpenid, string helpId)
        {
            string msg      = string.Empty;
            string link     = string.Empty;
            string fileName = string.Empty;
            string openid   = "";

            try
            {
                if (new AppSetting().IsDebug != null &&
                    new AppSetting().IsDebug.ToLower() == "true")
                {
                    openid = "123";
                }
                else
                {
                    if (Request.Cookies[SystemConfig.WXOpenIDCookieKey] != null)
                    {
                        openid = Request.Cookies[SystemConfig.WXOpenIDCookieKey].Value;
                    }
                    if (string.IsNullOrEmpty(openid) && string.IsNullOrEmpty(code))
                    {
                        Response.Redirect(CommonHelper.GetRedirect("WxOrder%2fHelpClass?helpId=" + helpId));
                    }
                    try
                    {
                        if (string.IsNullOrWhiteSpace(openid))
                        {
                            openid = GetOpenId(code).openid;


                            // 合法用户,允许访问
                            Response.Cookies[SystemConfig.WXOpenIDCookieKey].Value   = openid;
                            Response.Cookies[SystemConfig.WXOpenIDCookieKey].Path    = "/";
                            Response.Cookies[SystemConfig.WXOpenIDCookieKey].Expires = DateTime.Now.AddDays(1);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }



                OrderBC bc = new OrderBC();

                HelpInfoEntity entity = new HelpInfoEntity();
                if (!string.IsNullOrEmpty(helpId))
                {
                    entity    = bc.GetHelpByHelpInfoId(helpId);
                    ownOpenid = entity.OpenId;
                    classid   = entity.ClassId;
                }
                var config = bc.GetHelpConfigByClassId(classid);
                if (!string.IsNullOrEmpty(ownOpenid) && !string.IsNullOrEmpty(classid))
                {
                    entity = bc.GetHelpByOpenIdAndClassId(classid, ownOpenid);
                }


                if (ownOpenid != openid)//非发起用户进入
                {
                    var helpinfo = bc.GetHelpMemberByOpenid(openid);
                    if (helpinfo != null)
                    {
                        msg = "该用户已助力";
                        return(Json(msg, JsonRequestBehavior.AllowGet));
                    }

                    helpId = Guid.NewGuid().ToString();

                    //生成二维码
                    SaveIamge QR = CreateQR(helpId);
                    //添加文字水印
                    string WxName = new WxUserBC().GetWxUserByOpenid(openid).Nickname;

                    string path = HttpContext.Server.MapPath("/Images/upload/");

                    string[] sArray = Regex.Split(config.ImageUrl, "Images/upload/", RegexOptions.IgnoreCase);

                    string    filename = sArray[1].ToString();
                    SaveIamge WordsPic = new WaterImageManager().DrawWordsForSaveIamge(filename, path, WxName, 1, FontFamilys.宋体, FontStyle.Bold, ImagePosition.TopMiddle);
                    //添加二维码水印
                    string QrPic = new WaterImageManager().DrawImage(WordsPic.filename, WordsPic.showImg, QR.filename, QR.showImg, 1, ImagePosition.BottomMiddle);
                    LogHelp.WriteLog("QrPic:::" + QrPic);
                    fileName = QrPic;
                    link     = CommonHelper.LinkImageUrl("/Images/upload/" + QrPic);

                    HelpInfoEntity help = new HelpInfoEntity()
                    {
                        HelpInfoId = helpId,
                        ClassId    = classid,
                        OpenId     = openid,
                        NowCount   = 0,
                        imgUrl     = link
                    };

                    var addResult = bc.AddHelpInfo(help, openid);
                    //增加助力记录
                    HelpMemberEntity member = new HelpMemberEntity()
                    {
                        HelpInfoId = entity.HelpInfoId,
                        OpenId     = openid,
                    };
                    var addMember = bc.AddHelpMember(member, openid);
                    //更新助力信息人数
                    var updateInfo = bc.UpdateHelpNowCount(entity.HelpInfoId, entity.NowCount + 1);

                    entity = bc.GetHelpByHelpInfoId(entity.HelpInfoId);

                    int diff   = config.HelpCount - entity.NowCount;
                    var wxUser = new WxUserBC().GetWxUserByOpenid(entity.OpenId);
                    if (diff <= 0)
                    {
                        string      OrderNo = CommonHelper.CreateOrderNo();
                        OrderEntity order   = new OrderEntity()
                        {
                            OrderNo     = OrderNo,
                            Openid      = entity.OpenId,
                            PayPrice    = 0,
                            OrderSource = "4",
                            Nickname    = wxUser.Nickname
                        };
                        List <OrderGoodsEntity> goods = new List <OrderGoodsEntity>();

                        var classEntity       = new ClassBC().GetClassByKey(classid);
                        OrderGoodsEntity good = new OrderGoodsEntity()
                        {
                            ClassId   = classEntity.ClassId,
                            ClassName = classEntity.ClassName,
                            Price     = 0
                        };
                        goods.Add(good);

                        var result = new OrderBC().SaveOrder(order, goods, entity.OpenId);


                        msg = "助力成功";
                    }
                }
                else//发起用户进入
                {
                    LogHelp.WriteLog("HelpClass:::22222");
                    if (entity != null)//如果主力已存在,展示助力情况
                    {
                        link = entity.imgUrl;
                        int diff = config.HelpCount - entity.NowCount;
                        if (diff > 0)
                        {
                            msg = string.Format("还差 {0} 人助力成功", diff);
                            //return Json(msg, JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            msg = string.Format("已助力成功");
                            //return Json(msg, JsonRequestBehavior.AllowGet);
                        }
                    }
                    else //如果助力不存在,新增助力
                    {
                        helpId = Guid.NewGuid().ToString();
                        //生成二维码
                        SaveIamge QR = CreateQR(helpId);
                        //添加文字水印
                        string WxName = new WxUserBC().GetWxUserByOpenid(ownOpenid).Nickname;
                        string path   = HttpContext.Server.MapPath("/Images/upload/");

                        string[]  sArray   = Regex.Split(config.ImageUrl, "Images/upload/", RegexOptions.IgnoreCase);
                        string    filename = sArray[1].ToString();
                        SaveIamge WordsPic = new WaterImageManager().DrawWordsForSaveIamge(filename, path, WxName, 1, FontFamilys.宋体, FontStyle.Bold, ImagePosition.TopMiddle);
                        //添加二维码水印
                        string QrPic = new WaterImageManager().DrawImage(WordsPic.filename, WordsPic.showImg, QR.filename, QR.showImg, 1, ImagePosition.BottomMiddle);
                        fileName = QrPic;
                        link     = CommonHelper.LinkImageUrl("/Images/upload/" + QrPic);

                        HelpInfoEntity help = new HelpInfoEntity()
                        {
                            HelpInfoId = helpId,
                            ClassId    = classid,
                            OpenId     = ownOpenid,
                            NowCount   = 0,
                            imgUrl     = link
                        };
                        var addResult = bc.AddHelpInfo(help, ownOpenid);

                        msg = "分享图片,请好友帮忙助力吧";
                    }
                }

                //string media_id = Util.uploadMedia(HttpContext.Server.MapPath("/Images/upload/") + fileName, fileName);
                //Util.SendCustomMessage(openid, media_id);
            }
            catch (Exception ex)
            {
                LogHelp.WriteLog("HelpClass:::" + ex.Message);
            }


            ViewBag.Message = msg;
            ViewBag.Link    = link;

            return(View());
        }
예제 #5
0
        public ActionResult AddOrder(OrderParam param)
        {
            try
            {
                if (param == null)
                {
                    return(Json(string.Empty));
                }

                //判断是否注册
                var userInfo = new WxUserBC().GetWxUserByOpenid(param.openid);

                if (string.IsNullOrEmpty(userInfo.Phone))
                {
                    string url = CommonHelper.GetRedirect("WxMy%2fRegistered");
                    //Response.Redirect(url);
                    return(Json(url, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string      OrderNo = CommonHelper.CreateOrderNo();
                    OrderEntity order   = new OrderEntity()
                    {
                        OrderNo     = OrderNo,
                        Openid      = param.openid,
                        PayPrice    = param.price,
                        OrderSource = param.source,
                        Nickname    = new WxUserBC().GetWxUserByOpenid(param.openid).Nickname
                    };

                    List <OrderGoodsEntity> goods = new List <OrderGoodsEntity>();

                    var paramList = param.classids.ToString().Split('|').ToList();
                    if (paramList != null && paramList.Count > 0)
                    {
                        foreach (var item in paramList)
                        {
                            if (!string.IsNullOrEmpty(item))
                            {
                                var entity            = new ClassBC().GetClassByKey(item);
                                OrderGoodsEntity good = new OrderGoodsEntity()
                                {
                                    ClassId   = entity.ClassId,
                                    ClassName = entity.ClassName,
                                    Price     = param.source != "1" ? param.price : entity.ClassPrice
                                };
                                goods.Add(good);
                            }
                        }
                    }

                    var result = new OrderBC().SaveOrder(order, goods, param.openid);
                    if (result == "true")
                    {
                        string okUrl = "/WxOrder/Index?orderNo=" + OrderNo;
                        return(Json(okUrl, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(string.Empty, JsonRequestBehavior.AllowGet));
                    }
                }

                //var orderResult = new OrderBC().GetOrderByOpenIdandClassId(param.openid,);
            }
            catch (Exception ex)
            {
                LogHelp.WriteLog(DateTime.Now + ":::AddOrderError:::" + ex.Message);
                return(Json(string.Empty, JsonRequestBehavior.AllowGet));
            }
        }
예제 #6
0
        public ActionResult Register(RegisterModel model)
        {
            string ErrMsg;

            try
            {
                //数据校验
                if (string.IsNullOrEmpty(model.openid))
                {
                    ErrMsg = "OpenId不能为空";
                    return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(model.phone))
                {
                    ErrMsg = "手机号不能为空";
                    return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(model.code))
                {
                    ErrMsg = "验证码不能为空";
                    return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //SMSCodes smsCode = Session["RegisterCode"] as SMSCodes;
                    if (Session["RegisterCode"] == null)
                    {
                        ErrMsg = "未获取验证码";
                        return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //if (!smsCode.IsExpired && smsCode.IsUsered == false)
                        //{

                        if (model.code != "1234")
                        {
                            ErrMsg = "验证码不正确";
                            return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            //string access_token = "";

                            //access_token = Util.GetAccessTokenOpen();
                            //LogHelp.WriteLog(DateTime.Now + "GetAccessTokenOpen:" +model.openid+ access_token);
                            //var userInfo = GetUserInfo(model.openid, access_token);

                            var userInfo = new WxUserBC().GetWxUserByOpenid(model.openid);
                            LogHelp.WriteLog(DateTime.Now + "GetWxUserByOpenid:" + model.openid);
                            //实体赋值
                            WxUserEntity Entry = new WxUserEntity();

                            //List<WxUserEntity> list = null;
                            //校验次手机号是否已注册
                            var list = new WxUserBC().GetWxUserListByCondition(null, model.phone, null, null).ToList();
                            if (list.Count > 0)
                            {
                                ErrMsg = "手机号已被注册";
                                return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                Entry.WxUserId     = userInfo.WxUserId;
                                Entry.Openid       = userInfo.Openid;
                                Entry.Nickname     = userInfo.Nickname;
                                Entry.Sex          = userInfo.Sex;
                                Entry.City         = userInfo.City;
                                Entry.Country      = userInfo.Country;
                                Entry.Province     = userInfo.Province;
                                Entry.UserLanguage = userInfo.UserLanguage;
                                Entry.Headimgurl   = userInfo.Headimgurl;
                                Entry.Phone        = model.phone;
                                int d = new WxUserBC().SaveWxUser(Entry, userInfo.Openid);

                                if (d == 0)
                                {
                                    ErrMsg = "插入数据库失败";
                                    return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                                }
                                else
                                {
                                    //Session["DELIVERYMANCODE"] = new SMSCodes { Code = smsCode.Code, CreteTime = smsCode.CreteTime, IsUsered = true };
                                    ErrMsg = "Success";
                                    return(Json(ErrMsg, JsonRequestBehavior.AllowGet));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrMsg = ex.Message.ToString();
                return(Json("Error"));
            }
        }