Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 取消充值记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //public Base CancelRecharge(int id)
        //{
        //    Base b = new Base();
        //    try
        //    {
        //        using (var db = new ncpEntities())
        //        {
        //            ncp_jinbirecharge recharge = db.ncp_jinbirecharge.FirstOrDefault(a => a.ID == id);
        //            if (recharge != null)
        //            {
        //                recharge.IsAvailable = false;
        //                db.SaveChanges();
        //            }
        //            b.Code = 1;
        //            b.Message = ConstantHelper.Success;
        //        }
        //    }
        //    catch (Exception Exc)
        //    {
        //        b.Code = 0;
        //        b.Message = ConstantHelper.Failure;
        //        b.Description = Exc.ToString();
        //    }
        //    return b;
        //}


        /// <summary>
        /// 获取充值记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //public Base RechargeDetail(int id)
        //{
        //    NewBase<ExJinbiCharge> b = new NewBase<ExJinbiCharge>();
        //    try
        //    {
        //        using (var db = new ncpEntities())
        //        {
        //            ncp_jinbirecharge recharge = db.ncp_jinbirecharge.FirstOrDefault(a => a.ID == id);
        //            if (recharge == null)
        //            {
        //                b.Code = 0;
        //                b.Message = "该充值记录不存在!";
        //            }
        //            else
        //            {
        //                b.Code = 1;
        //                b.Message = ConstantHelper.Success;

        //                ExJinbiCharge ex = new ExJinbiCharge();
        //                ex.ID = recharge.ID;
        //                ex.UserId = recharge.UserId;
        //                ex.Data = recharge.Data;
        //                ex.DT = recharge.DT;
        //                ex.Origin = recharge.Origin;
        //                ex.paytype = recharge.PayType;
        //                ex.RechargeType = recharge.RechargeType;
        //                ex.BatchId = recharge.BatchId;
        //                ex.UserName = string.Empty;
        //                b.Data = ex;
        //            }
        //        }
        //    }
        //    catch (Exception Exc)
        //    {
        //        b.Code = 0;
        //        b.Message = ConstantHelper.Failure;
        //        b.Description = Exc.ToString();
        //    }
        //    return b;
        //}


        /// <summary>
        /// 确认充值成功 支付宝充值回调使用
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Base ConfirmAddRechargeByBatchId(string batchid)
        {
            Base b = new Base();

            try
            {
                using (var db = new EFContext())
                {
                    selshopjinbirecharge recharge = db.selshopjinbirecharge.FirstOrDefault(a => a.BatchId == batchid);

                    if (recharge == null)
                    {
                        b.Code    = 0;
                        b.Message = "无效的充值记录!";
                        return(b);
                    }



                    selshopjinbiaccount jinbiaccount = db.selshopjinbiaccount.FirstOrDefault(a => a.ShopID == recharge.ShopID);

                    if (jinbiaccount == null)
                    {
                        b.Code    = 0;
                        b.Message = "无效的帐户,请联系管理员!";
                        return(b);
                    }

                    if (recharge.Status == 1)
                    {
                        b.Code    = 1;
                        b.Message = "充值成功!";
                        return(b);
                    }

                    decimal  oldjinbi    = 0;
                    decimal  jinbi       = 0;
                    decimal  newjinbi    = 0;
                    var      ordernumber = recharge.ID.ToString();
                    DateTime now         = DateTime.Now;

                    oldjinbi           = jinbiaccount.Jinbi;
                    jinbi              = recharge.Data;
                    newjinbi           = oldjinbi + jinbi;
                    jinbiaccount.Jinbi = newjinbi;

                    selshopjinbidetail jinbidetail = new selshopjinbidetail()
                    {
                        OrderNumber = ordernumber,
                        Type        = 1,
                        Before      = oldjinbi,
                        Data        = jinbi,
                        Sign        = 1,
                        After       = newjinbi,
                        BatchId     = batchid,
                        DT          = now,
                        ShopID      = recharge.ShopID,
                        IsAuto      = false,
                        Remark      = "用户在线充值",
                        Description = string.Format("用户在线充值,结余:{0}", newjinbi),
                    };


                    db.selshopjinbidetail.Add(jinbidetail);

                    ///充值成功
                    recharge.Status    = 1;
                    recharge.ConfirmDT = now;



                    db.SaveChanges();
                    b.Code    = 1;
                    b.Message = ConstantHelper.Success;
                }
            }
            catch (Exception Exc)
            {
                b.Code        = 0;
                b.Message     = ConstantHelper.Failure;
                b.Description = Exc.ToString();
            }
            return(b);
        }
Ejemplo n.º 3
0
        public ActionResult SaveDistributionTakeIn(ViewDistribution model)
        {
            ViewRecharge b = new ViewRecharge();

            if (model.Jinbi < 0)
            {
                b.Code    = 0;
                b.Message = "转入金额输入错误";
                return(Json(b, JsonRequestBehavior.AllowGet));
            }

            ///向数据库写入充值记录
            try
            {
                using (var db = new EFContext())
                {
                    decimal oldjinbi = 0;
                    decimal newjinbi = 0;

                    decimal  olddistributionjinbi = 0;
                    decimal  newdistributionjinbi = 0;
                    DateTime now   = DateTime.Now;
                    decimal  jinbi = model.Jinbi;

                    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 distributionaccount = db.selshopdistributionaccount.FirstOrDefault(x => x.ShopID == ShopId);
                    if (distributionaccount == null)
                    {
                        b.Code    = 0;
                        b.Message = "分销账户不存在";
                        return(Json(b, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        olddistributionjinbi = distributionaccount.Jinbi;
                    }


                    //余额判断
                    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;

                    newdistributionjinbi                 = olddistributionjinbi + jinbi;
                    distributionaccount.Jinbi            = newdistributionjinbi;
                    distributionaccount.OperatorDateTime = now;

                    string             ordernumber = BatchHelper.GetBatchId;
                    string             batchid     = BatchHelper.GetBatchId;
                    selshopjinbidetail jinbidetail = new selshopjinbidetail()
                    {
                        OrderNumber = ordernumber,
                        Type        = 130,
                        ShopID      = ShopId,
                        DT          = now,
                        Sign        = -1,
                        IsAuto      = true,
                        Before      = oldjinbi,
                        Data        = jinbi,
                        After       = newjinbi,
                        Remark      = "转入分销",
                        BatchId     = batchid
                    };
                    db.selshopjinbidetail.Add(jinbidetail);

                    selshopdistributiondetail distributiondetail = new selshopdistributiondetail()
                    {
                        OrderNumber = ordernumber,
                        Type        = 130,
                        ShopID      = ShopId,
                        DT          = now,
                        Sign        = 1,
                        IsAuto      = true,
                        Before      = olddistributionjinbi,
                        Data        = jinbi,
                        After       = newdistributionjinbi,
                        Remark      = "余额转入",
                        BatchId     = batchid
                    };

                    db.selshopdistributiondetail.Add(distributiondetail);
                    db.SaveChanges();
                    b.Code    = 1;
                    b.Message = "分销转入成功";
                    b.Url     = string.Format("/DistributionBank/DistributionBalance");
                }
            }
            catch (Exception Exc)
            {
                b.Code        = 0;
                b.Message     = ConstantHelper.Failure;
                b.Description = Exc.ToString();
            }

            return(Json(b, JsonRequestBehavior.AllowGet));
        }