Esempio n. 1
0
        public ActionResult AddMessageRecharge(string id)
        {
            ViewAddMessageRecharge model = new ViewAddMessageRecharge();

            using (var db = new EFContext())
            {
                model.ListSmsPackagePrice = db.syssmspackageprice.OrderBy(x => x.ID).ToList();
            }

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult SaveMessageRecharge(ViewAddMessageRecharge model)
        {
            ViewRecharge b          = new ViewRecharge();
            var          totalprice = model.Price;
            var          totalcount = model.SmsCount;

            if (totalprice < 0)
            {
                b.Code    = 0;
                b.Message = "总价格格式不正确";
                return(Json(b, JsonRequestBehavior.AllowGet));
            }
            if (totalcount < 0)
            {
                b.Code    = 0;
                b.Message = "总条数格式不正确";
                return(Json(b, JsonRequestBehavior.AllowGet));
            }

            var resultCheckPayPassword = ShopPayPasswordHelper.CheckPassword(ShopId, model.PayPassword);

            if (resultCheckPayPassword.Code == 0)
            {
                b.Code    = 0;
                b.Message = "支付密码不正确";
                return(Json(b, JsonRequestBehavior.AllowGet));
            }
            try
            {
                using (var db = new EFContext())
                {
                    decimal oldjinbi = 0;
                    decimal newjinbi = 0;

                    int      oldsmscount = 0;
                    int      newsmscount = 0;
                    DateTime now         = DateTime.Now;
                    decimal  jinbi       = totalprice;

                    var ts = totalcount.ToString();

                    var f = db.syssmspackageprice.FirstOrDefault(x => x.ID == ts && x.Price == totalprice);
                    if (f == null)
                    {
                        b.Code    = 0;
                        b.Message = "短信条数格式不正确";
                        return(Json(b, JsonRequestBehavior.AllowGet));
                    }

                    var jinbiaccount = db.selshopjinbiaccount.FirstOrDefault(x => x.ShopID == ShopId);
                    if (jinbiaccount == null)
                    {
                        b.Code    = 0;
                        b.Message = "金币账户不存在";
                        return(Json(b, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        oldjinbi = jinbiaccount.Jinbi;
                    }

                    var smsaccount = db.selshopsmsaccount.FirstOrDefault(x => x.ShopID == ShopId);
                    if (smsaccount == null)
                    {
                        b.Code    = 0;
                        b.Message = "短信账户不存在";
                        return(Json(b, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        oldsmscount = smsaccount.SmsCount;
                    }


                    //余额判断
                    if (jinbiaccount.Jinbi < jinbi)
                    {
                        b.Code    = 0;
                        b.Message = string.Format("账号{0}余额{1}不足", ShopId, jinbiaccount.Jinbi);
                        return(Json(b, JsonRequestBehavior.AllowGet));
                    }


                    //余额减少

                    newjinbi                      = oldjinbi - jinbi;
                    jinbiaccount.Jinbi            = newjinbi;
                    jinbiaccount.OperatorDateTime = now;


                    newsmscount                 = oldsmscount + totalcount;
                    smsaccount.SmsCount         = newsmscount;
                    smsaccount.OperatorDateTime = now;


                    selshopsmsrecharge recharge = new selshopsmsrecharge()
                    {
                        ID          = WebTools.getGUID(),
                        ShopID      = ShopId,
                        SmsCount    = totalcount,
                        Price       = jinbi,
                        DT          = now,
                        Status      = 1,
                        IsAvailable = true,
                        ManagerID   = ManagerId,
                        BatchId     = WebTools.getGUID(),
                        ConfirmDT   = now
                    };

                    db.selshopsmsrecharge.Add(recharge);

                    selshopjinbidetail jinbidetail = new selshopjinbidetail()
                    {
                        OrderNumber = recharge.ID,
                        Type        = 120,
                        ShopID      = ShopId,
                        DT          = now,
                        Sign        = -1,
                        IsAuto      = true,
                        Before      = oldjinbi,
                        Data        = jinbi,
                        After       = newjinbi,
                        Remark      = "购买短信",
                        BatchId     = recharge.BatchId
                    };
                    db.selshopjinbidetail.Add(jinbidetail);

                    selshopsmsdetail smsdetail = new selshopsmsdetail()
                    {
                        OrderNumber = recharge.ID,
                        Type        = 120,
                        ShopID      = ShopId,
                        DT          = now,
                        Sign        = 1,
                        IsAuto      = true,
                        Before      = oldsmscount,
                        Data        = totalcount,
                        After       = newsmscount,
                        Remark      = "购买短信",
                        BatchId     = recharge.BatchId
                    };

                    db.selshopsmsdetail.Add(smsdetail);
                    db.SaveChanges();
                    b.Code    = 1;
                    b.Message = "购买短信成功";
                    b.Url     = string.Format("/MessageBank/RechargeDetail");
                }
            }
            catch (Exception Exc)
            {
                b.Code        = 0;
                b.Message     = ConstantHelper.Failure;
                b.Description = Exc.ToString();
            }
            return(Json(b, JsonRequestBehavior.AllowGet));
        }