public ActionResult SaveDistributionContract(ViewDistributionContract model)
        {
            ViewBase b = new ViewBase();

            try
            {
                if (model.IsSignAgreement == false)
                {
                    b.Code    = 0;
                    b.Message = ConstantHelper.Failure;
                    return(Json(b, JsonRequestBehavior.AllowGet));
                }


                using (var db = new EFContext())
                {
                    var shopdistribution = db.selshopdistribution.FirstOrDefault(x => x.ShopID == ShopId);

                    if (shopdistribution == null)
                    {
                        shopdistribution = new selshopdistribution()
                        {
                            ShopID            = ShopId,
                            IsSignAgreement   = true,
                            SignAgreementTime = DateTime.Now,
                            IsOpen            = false,
                            IsSetPercentage   = false,
                            OperatorDateTime  = DateTime.Now,
                            Percentage        = 0,
                            SetPercentageTime = DateTime.Now
                        };
                        db.selshopdistribution.Add(shopdistribution);
                    }
                    else
                    {
                        shopdistribution.IsSignAgreement   = true;
                        shopdistribution.SignAgreementTime = DateTime.Now;
                    }

                    db.SaveChanges();
                    b.Code    = 1;
                    b.Message = "协议签署成功";
                    b.Url     = "/DistributionBank/DistributionContract";
                }
            }
            catch (Exception Exc)
            {
                b.Code        = 0;
                b.Message     = ConstantHelper.Failure;
                b.Description = Exc.ToString();
            }

            return(Json(b, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DistributionPercentage()
        {
            ViewDistributionPercentage model = new ViewDistributionPercentage();

            using (var db = new EFContext())
            {
                var shopdistribution = db.selshopdistribution.FirstOrDefault(x => x.ShopID == ShopId);

                if (shopdistribution == null)
                {
                    shopdistribution = new selshopdistribution();
                }

                model.Percentage      = Convert.ToInt16(shopdistribution.Percentage);
                model.IsSetPercentage = shopdistribution.IsSetPercentage;
                if (shopdistribution.IsSetPercentage)
                {
                    if (shopdistribution.SetPercentageTime.AddMonths(4) < DateTime.Now)
                    {
                        model.IsAllowSet = true;
                        model.SetPercentageTimeEndFormat = shopdistribution.SetPercentageTime.AddMonths(4).ToString(FormatHelper.DateFormat);
                    }
                    else
                    {
                        model.IsAllowSet = false;
                        model.Days       = (shopdistribution.SetPercentageTime.AddMonths(4) - DateTime.Now).Days;
                        model.SetPercentageTimeFormat = shopdistribution.SetPercentageTime.ToString(FormatHelper.DateFormat);
                    }
                }
                else
                {
                    model.SetPercentageTimeEndFormat = DateTime.Now.AddMonths(4).ToString(FormatHelper.DateFormat);

                    model.IsAllowSet = true;
                }
            }
            return(View(model));
        }
        public ActionResult SaveDistributionPercentage(ViewDistributionPercentage model)
        {
            ViewBase b = new ViewBase();

            try
            {
                if (model.Percentage > 100 || model.Percentage < 8)
                {
                    b.Code    = 0;
                    b.Message = "商家返利比例不正确";
                    return(Json(b, JsonRequestBehavior.AllowGet));
                }

                using (var db = new EFContext())
                {
                    var shopdistribution = db.selshopdistribution.FirstOrDefault(x => x.ShopID == ShopId);

                    if (shopdistribution == null)
                    {
                        shopdistribution = new selshopdistribution()
                        {
                            ShopID            = ShopId,
                            IsSignAgreement   = false,
                            IsOpen            = false,
                            IsSetPercentage   = true,
                            OperatorDateTime  = DateTime.Now,
                            Percentage        = model.Percentage,
                            SetPercentageTime = DateTime.Now.Date
                        };
                        db.selshopdistribution.Add(shopdistribution);
                    }
                    else
                    {
                        if (shopdistribution.IsSetPercentage)
                        {
                            model.SetPercentageTimeFormat = shopdistribution.SetPercentageTime.AddMonths(4).ToString(FormatHelper.DateFormat);
                            if (shopdistribution.SetPercentageTime.AddMonths(4) > DateTime.Now)
                            {
                                b.Message = string.Format("返佣比例提交后一个季度才可修改一次,上次提交时间为:{0}", shopdistribution.SetPercentageTime.ToString(FormatHelper.DateFormat));
                                return(Json(b, JsonRequestBehavior.AllowGet));
                            }
                        }
                        shopdistribution.Percentage        = model.Percentage;
                        shopdistribution.SetPercentageTime = DateTime.Now.Date;
                        shopdistribution.IsSetPercentage   = true;
                    }

                    db.SaveChanges();
                    b.Code    = 1;
                    b.Message = ConstantHelper.Success;
                    b.Url     = "/DistributionBank/DistributionPercentage";
                }
            }
            catch (Exception Exc)
            {
                b.Code        = 0;
                b.Message     = ConstantHelper.Failure;
                b.Description = Exc.ToString();
            }

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