public ActionResult GetStatisticalData(string startTime = null, string endTime = null, long costChannel = 0)
        {
            var resultMode = new ResponseBaseModel <dynamic>
            {
                ResultCode = ResponceCodeEnum.Fail,
                Message    = ""
            };
            var userId = CurrentModel.UserId;

            if (userId < 1)
            {
                resultMode.Message = "登录失效,请重新登录";
            }
            else
            {
                var beginTime = DataTypeConvertHelper.ToDateTime(startTime);
                var closeTime = DataTypeConvertHelper.ToDateTime(endTime);
                var server    = new CostContentService();
                var data      = server.GetStatisticsCanPay(userId, beginTime, closeTime, costChannel);
                resultMode.Data       = data;
                resultMode.ResultCode = ResponceCodeEnum.Success;
            }

            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetCostPage()
        {
            var resultMode = new ResponseBaseModel <dynamic>
            {
                ResultCode = ResponceCodeEnum.Fail,
                Message    = ""
            };
            int      pageIndex   = System.Web.HttpContext.Current.GetIntFromParameters("pageindex");
            int      pageSize    = System.Web.HttpContext.Current.GetIntFromParameters("pagesize");
            string   costaddress = System.Web.HttpContext.Current.GetStringFromParameters("costaddress");
            DateTime starttime   = System.Web.HttpContext.Current.GetDateTimeFromParameters("starttime");
            DateTime endtime     = System.Web.HttpContext.Current.GetDateTimeFromParameters("endtime");
            int      costtype    = System.Web.HttpContext.Current.GetIntFromParameters("costtype");
            int      spendtype   = System.Web.HttpContext.Current.GetIntFromParameters("spendtype");
            string   costthing   = System.Web.HttpContext.Current.GetStringFromParameters("costthing");
            long     costchannel = System.Web.HttpContext.Current.GetIntFromParameters("costchannel");
            var      userId      = CurrentModel.UserId;

            if (userId < 1)
            {
                resultMode.Message = "登录失效,请重新登录";
            }
            else
            {
                var server   = new CostContentService();
                var dataList = server.GetList(new List <long> {
                    userId
                }, spendtype, costaddress, costthing, costtype, costchannel, starttime, endtime,
                                              pageIndex, pageSize, out var count);
                var dic = server.GetStatisticsCost(new List <long> {
                    userId
                }, spendtype, costaddress, costthing, costtype, costchannel, starttime, endtime);
                var allOutCost = dic.ContainsKey(CostInOrOutEnum.Out.GetHashCode())
                    ? dic[CostInOrOutEnum.Out.GetHashCode()]
                    : 0;
                var allInCost = dic.ContainsKey(CostInOrOutEnum.In.GetHashCode())
                    ? dic[CostInOrOutEnum.In.GetHashCode()]
                    : 0;
                var statisticsModel = new
                {
                    allCouldCost = $"{allInCost - allOutCost:N2}",
                    allOutCost   = $"{allOutCost:N2}",
                    allInCost    = $"{allInCost:N2}"
                };
                resultMode.Data       = new { count, dataList, statisticsModel };
                resultMode.ResultCode = ResponceCodeEnum.Success;
            }

            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetCostModel(long id)
        {
            var resultMode = new ResponseBaseModel <dynamic>
            {
                ResultCode = ResponceCodeEnum.Fail,
                Message    = ""
            };
            var server = new CostContentService();
            var userId = CurrentModel.UserId;
            var data   = server.GetContentModel(id);

            if (data != null && data.UserId == userId)
            {
                resultMode.Data       = data;
                resultMode.ResultCode = ResponceCodeEnum.Success;
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            resultMode.Message = "查询失败";
            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddCostInfo(CostContentModel model)
        {
            var resultMode = new ResponseBaseModel <dynamic>
            {
                ResultCode = ResponceCodeEnum.Fail,
            };

            if (model == null)
            {
                resultMode.Message = "参数错误";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            var userId = CurrentModel.UserId;
            var server = new CostContentService();
            CostContentModel newModel = new CostContentModel();

            if (model.Id > 0)
            {
                newModel = server.GetContentModel(model.Id);
                //验证权限
                if (newModel == null || newModel.UserId != userId)
                {
                    resultMode.Message = "非法访问";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }

                if (newModel.SpendType == 2 && (model.SpendType != 2 || model.LinkCostId < 0))
                {
                    resultMode.Message = "转移记录类型不能修改或无关联入账信息";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }

                if (newModel.SpendType == 2 && newModel.CostInOrOut == CostInOrOutEnum.In)
                {
                    resultMode.Message = "转移记录入账信息不能修改";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }
            }
            //验证参数
            newModel.Cost            = Math.Round(Math.Abs(model.Cost), 2);
            newModel.CostAddress     = model.CostAddress;
            newModel.CostChannel     = model.CostChannel;
            newModel.CostType        = model.SpendType == 2 ? -1 : model.CostType;
            newModel.UserId          = userId;
            newModel.CostInOrOut     = model.CostInOrOut;
            newModel.CostThing       = model.CostThing;
            newModel.CostTime        = model.CostTime;
            newModel.CostMonth       = newModel.CostTime.Month;
            newModel.CostYear        = newModel.CostTime.Year;
            newModel.CreateTime      = newModel.Id > 0 ? newModel.CreateTime : DateTime.Now;
            newModel.CreateUserId    = userId;
            newModel.SpendType       = model.SpendType;
            newModel.UpdateTime      = DateTime.Now;
            newModel.UpdateUserId    = userId;
            newModel.LinkCostChannel = model.LinkCostChannel;
            newModel.IsDel           = FlagEnum.HadZore;
            if (newModel.Cost < (decimal)0.01)
            {
                resultMode.Message = "金额设置错误";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }

            if (model.SpendType != 2)
            {
                var costTypeInfo = new CostTypeService().Get(newModel.CostType);
                if (costTypeInfo == null ||
                    costTypeInfo.UserId != userId ||
                    costTypeInfo.IsDel == FlagEnum.HadOne ||
                    costTypeInfo.IsValid == FlagEnum.HadZore)
                {
                    resultMode.Message = "类型选择无效";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }
                newModel.CostTypeName = costTypeInfo.Name;
            }

            var costChannelServer = new CostChannelService();
            var costChannelInfo   = costChannelServer.Get(newModel.CostChannel);

            if (costChannelInfo == null ||
                costChannelInfo.UserId != userId ||
                costChannelInfo.IsDel == FlagEnum.HadOne ||
                costChannelInfo.IsValid == FlagEnum.HadZore)
            {
                resultMode.Message = "账户选择无效";
                return(Json(resultMode, JsonRequestBehavior.AllowGet));
            }
            newModel.CostChannelName = costChannelInfo.CostChannelName;
            newModel.CostChannelNo   = costChannelInfo.CostChannelNo;
            newModel.CostInOrOut     = newModel.SpendType == 1 ? CostInOrOutEnum.In : CostInOrOutEnum.Out;

            if (newModel.SpendType == 2)
            {
                if (newModel.LinkCostChannel < 1)
                {
                    resultMode.Message = "转入账户无效";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }
                var linkChannelInfo = costChannelServer.Get(newModel.LinkCostChannel);
                if (linkChannelInfo == null ||
                    linkChannelInfo.UserId != userId ||
                    linkChannelInfo.IsDel == FlagEnum.HadOne ||
                    linkChannelInfo.IsValid == FlagEnum.HadZore)
                {
                    resultMode.Message = "转入账户无效";
                    return(Json(resultMode, JsonRequestBehavior.AllowGet));
                }

                newModel.LinkCostChannelName = linkChannelInfo.CostChannelName;
                newModel.LinkCostChannelNo   = linkChannelInfo.CostChannelNo;
            }
            else
            {
                newModel.LinkCostChannel     = 0;
                newModel.LinkCostId          = 0;
                newModel.LinkCostChannelNo   = "";
                newModel.LinkCostChannelName = "";
            }
            var costContentServer = new CostContentService();

            costContentServer.AddAndUpdateContentInfo(newModel);
            resultMode.ResultCode = ResponceCodeEnum.Success;
            return(Json(resultMode, JsonRequestBehavior.AllowGet));
        }