/// <summary>
        /// 新增图片
        /// </summary>
        protected void AddImgInfo()
        {
            try
            {
                string filename = System.Guid.NewGuid().ToString().Replace("-", "");
                string imgData  = _ct.Request.Form["img"];
                string imgType  = "";
                string tid      = _ct.Request.Form["tid"];
                string stopid   = _ct.Request.Form["stopid"];
                int    fid      = 0;
                int.TryParse(tid, out fid);
                if (fid == 0)
                {
                    string jsonstrlist = JsonHelper.GetJsonString(new jsonResult {
                        code = "faile", result = "", count = 0
                    });
                    _ct.Response.Write(jsonstrlist);
                }
                else
                {
                    using (WXDBEntities db = new WXDBEntities())
                    {
                        var model1 = db.lotterUserInfo.Where(s => s.OpenId.Equals(stopid) && s.Type.Equals(14)).FirstOrDefault();
                        if (model1 != null)
                        {
                            if (imgData != "")
                            {
                                imgType = imgData.IndexOf("image/jpeg") != -1 ? "jpg" : "png";
                                MemoryStream stream = new MemoryStream(Convert.FromBase64String(imgData.Replace("data:image/jpeg;base64,", "").Replace("data:image/png;base64,", "")));
                                Bitmap       img    = new Bitmap(stream);
                                img.Save(_ct.Server.MapPath(@"/zshmsg/images/" + filename + "." + imgType));
                            }
                            //图片
                            model1.LotterSN = filename + "." + imgType;
                            db.SaveChanges();
                            string jsonstrlist = JsonHelper.GetJsonString(new jsonResult {
                                code = "succ", result = filename + "." + imgType, count = 2
                            });
                            _ct.Response.Write(jsonstrlist);
                        }
                        else
                        {
                            if (imgData != "")
                            {
                                imgType = imgData.IndexOf("image/jpeg") != -1 ? "jpg" : "png";
                                MemoryStream stream = new MemoryStream(Convert.FromBase64String(imgData.Replace("data:image/jpeg;base64,", "").Replace("data:image/png;base64,", "")));
                                Bitmap       img    = new Bitmap(stream);
                                img.Save(_ct.Server.MapPath(@"/zshmsg/images/" + filename + "." + imgType));

                                model1 = new lotterUserInfo()
                                {
                                    NickName     = "",
                                    OpenId       = stopid,
                                    StartTime    = DateTime.Now,
                                    LotterNumber = 0,
                                    AddTime      = DateTime.Now,
                                    Updatetime   = DateTime.Now,
                                    LotterSN     = filename + "." + imgType,
                                    PriceName    = "",
                                    PriceNumber  = 0,
                                    Extend1      = "",
                                    Extend2      = "",
                                    Extend3      = "",
                                    Status       = 0,
                                    Orders       = 0,
                                    Type         = 14,
                                    lotDesc      = ""
                                };
                                db.lotterUserInfo.AddObject(model1);
                                db.SaveChanges();
                                string jsonstrlist = JsonHelper.GetJsonString(new jsonResult {
                                    code = "succ", result = filename + "." + imgType, count = 2
                                });
                                _ct.Response.Write(jsonstrlist);
                            }
                            else
                            {
                                string jsonstrlist = JsonHelper.GetJsonString(new jsonResult {
                                    code = "faile", result = "", count = 3
                                });
                                _ct.Response.Write(jsonstrlist);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string jsonstrlist = JsonHelper.GetJsonString(new jsonResult {
                    code = "faile", result = "", count = 3
                });
                _ct.Response.Write(jsonstrlist);
            }
        }
Exemple #2
0
        protected void AddYhQinfo(HttpContext context)
        {
            var tmpopid  = context.Request.Params["tmpopid"];
            var tmpqtype = context.Request.Params["qtype"];

            using (WXDBEntities db = new WXDBEntities())
            {
                var forms = db.Forms.Where(s => s.Type == 6 && s.Source == tmpopid).FirstOrDefault();
                if (forms != null)
                {
                    double xfi  = 0f;
                    string desc = string.Empty;
                    switch (tmpqtype)
                    {
                    case "YY":
                        xfi  = 210;
                        desc = "游泳优惠券";
                        break;

                    case "MN":
                        xfi  = 300;
                        desc = "迷你吧台优惠券";
                        break;

                    case "XWC":
                        xfi  = 408;
                        desc = "下午茶优惠券";
                        break;
                    }
                    if ((forms.JFCount - xfi) > 0)
                    {
                        var lotter = new lotterUserInfo();
                        lotter.AddTime      = DateTime.Now;
                        lotter.Type         = 0;//积分兑换优惠券
                        lotter.OpenId       = tmpopid;
                        lotter.lotDesc      = desc;
                        lotter.StartTime    = DateTime.Now;
                        lotter.LotterNumber = 0;
                        lotter.Updatetime   = DateTime.Now;
                        lotter.LotterSN     = "yh" + DateTime.Now.ToString("HHmmss") + Senparc.Weixin.MP.TenPayLib.TenPayUtil.BuildRandomStr(4) + "q";
                        lotter.PriceName    = "";
                        lotter.PriceNumber  = 0;
                        lotter.Extend1      = "";
                        lotter.Extend2      = "";
                        lotter.Status       = 0;
                        lotter.Orders       = 0;
                        lotter.Extend3      = "0";//是否使用
                        db.lotterUserInfo.AddObject(lotter);
                        UserPoinLog ml = new UserPoinLog()
                        {
                            UserPointDesc = "兑换优惠券消费",
                            WxOpenid      = tmpopid,
                            WxNickName    = "",
                            PointCode     = 7,//兑换优惠券消费
                            AddTime       = DateTime.Now,
                            Updatetime    = DateTime.Now,
                            Status        = 0,
                            Orders        = 0,
                            Extent1       = "-" + xfi.ToString(),
                            Extent2       = "",
                            Extent3       = ""
                        };
                        forms.JFCount = forms.JFCount - xfi;
                        db.UserPoinLog.AddObject(ml);
                        db.SaveChanges();
                        //计入lotteruserinfo中
                        context.Response.Write("{\"flag\":\"2\",\"desc\":\"兑换成功,优惠券信息请在我的优惠券中查询!\"}");
                        return;
                    }
                    else
                    {
                        context.Response.Write("{\"flag\":\"1\",\"desc\":\"您当前的积分不足以兑换!\"}");
                        return;
                    }
                }
                else
                {
                    context.Response.Write("{\"flag\":\"0\",\"desc\":\"请注册会员信息或者消费后进行兑换!\"}");
                    return;
                }
            }
        }