Exemple #1
0
        public JsonResult ConfirmUploadFeedback(int id)
        {
            CustomJsonResult result = new CustomJsonResult();

            List <WithdrawCutOffDetails> updateCutOffDetails = new List <WithdrawCutOffDetails>();
            FeedbackCheckErrorPoint      checkErrorPoint     = new FeedbackCheckErrorPoint();


            if (Session["UploadFeedback"] == null)
            {
                return(Json(ResultType.Failure, "操作超时,请再次上传文件后操作"));
            }


            DataTable table = Session["UploadFeedback"] as DataTable;

            if (table.Rows.Count == 0)
            {
                return(Json(ResultType.Failure, "没有可截单的数据"));
            }

            #region   前检查
            foreach (DataRow row in table.Rows)
            {
                WithdrawCutOffDetails cutOffDetail = new WithdrawCutOffDetails();
                cutOffDetail.WithdrawSn = row["WithdrawSn"].ToString().Trim();
                if (cutOffDetail.WithdrawSn.Length == 0)
                {
                    return(Json(ResultType.Failure, "检查到有为空的提现流水号,请完善后再次上传"));
                }

                DataRow[] dr = table.Select("WithdrawSn='" + cutOffDetail.WithdrawSn + "'");
                if (dr.Length > 1)
                {
                    return(Json(ResultType.Failure, "检查到有重复的提现流水号:" + cutOffDetail.WithdrawSn + ",请检查后再次上传"));
                }

                var isExistCutOffDetail = CurrentDb.WithdrawCutOffDetails.Where(m => m.WithdrawSn == cutOffDetail.WithdrawSn && m.WithdrawCutOffId == id).FirstOrDefault();
                if (isExistCutOffDetail == null)
                {
                    checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现流水号不存在或不在同一批次");
                }
                else
                {
                    string withdrawFailureReason = row["WithdrawFailureReason"].ToString().Trim();
                    string withdrawStatus        = row["WithdrawStatus"].ToString().Trim();

                    if (withdrawStatus == "成功")
                    {
                        if (isExistCutOffDetail.WithdrawStatus == Enumeration.WithdrawStatus.Failure)
                        {
                            checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现状态已经为失败,不能改为成功");
                        }
                    }
                    else if (withdrawStatus == "失败")
                    {
                        if (isExistCutOffDetail.WithdrawStatus == Enumeration.WithdrawStatus.Success)
                        {
                            checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现结果已经为成功,不能改为失败");
                        }

                        if (withdrawFailureReason.Length == 0 || withdrawFailureReason.Length >= 500)
                        {
                            checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现结果为失败,必须填写失败原因,且小于或等于500个字符");
                        }

                        cutOffDetail.WithdrawFailureReason = withdrawFailureReason;
                    }
                    else if (withdrawStatus == "处理中")
                    {
                        if (isExistCutOffDetail.WithdrawStatus == Enumeration.WithdrawStatus.Success || isExistCutOffDetail.WithdrawStatus == Enumeration.WithdrawStatus.Failure)
                        {
                            checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现结果已经为" + isExistCutOffDetail.WithdrawStatus.GetCnName() + ",不能更改");
                        }
                    }
                    else
                    {
                        checkErrorPoint.AddPoint(cutOffDetail.WithdrawSn, "提现状态不正确,可选择为(处理中,成功,失败)");
                    }
                }
            }
            #endregion

            if (checkErrorPoint.ErrorPoint.Count > 0)
            {
                return(Json(ResultType.Failure, checkErrorPoint.ErrorPoint, "更新数据失败,检查到无效的数据"));
            }

            #region 更新的数据
            foreach (DataRow row in table.Rows)
            {
                WithdrawCutOffDetails cutOffDetail = new WithdrawCutOffDetails();
                cutOffDetail.WithdrawSn = row["WithdrawSn"].ToString().Trim();


                string withdrawStatus = row["WithdrawStatus"].ToString().Trim();
                if (withdrawStatus == "处理中")
                {
                    cutOffDetail.WithdrawStatus = Enumeration.WithdrawStatus.Handing;
                }
                else if (withdrawStatus == "成功")
                {
                    cutOffDetail.WithdrawStatus = Enumeration.WithdrawStatus.Success;
                }
                else if (withdrawStatus == "失败")
                {
                    cutOffDetail.WithdrawStatus        = Enumeration.WithdrawStatus.Failure;
                    cutOffDetail.WithdrawFailureReason = row["WithdrawFailureReason"].ToString().Trim();
                }
                updateCutOffDetails.Add(cutOffDetail);
            }
            #endregion

            result = BizFactory.Withdraw.Feedback(this.CurrentUserId, id, updateCutOffDetails);
            return(result);
        }
        public CustomJsonResult BuildCutOffData(int operater, DateTime startTime, DateTime endTime)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var withdrawList = CurrentDb.Withdraw.Where(m => m.Status == Enumeration.WithdrawStatus.SendRequest && m.UserId > 0 & m.SettlementStartTime >= startTime && m.SettlementStartTime <= endTime).ToList();

                if (withdrawList == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "没有可截单的数据"));
                }

                if (withdrawList.Count == 0)
                {
                    return(new CustomJsonResult(ResultType.Failure, "没有可截单的数据"));
                }

                var sumAmount           = (from s in withdrawList select s.Amount).Sum();
                var sumAmountByAfterFee = (from s in withdrawList select s.AmountByAfterFee).Sum();

                DateTime dateNow = DateTime.Now;
                DateTime?d1      = CommonUtils.ConverToStartTime(dateNow.ToString("yyyy-MM-dd"));
                DateTime?d2      = CommonUtils.ConverToEndTime(dateNow.ToString("yyyy-MM-dd"));

                var cutOffCountByDay = (from s in CurrentDb.WithdrawCutOff where s.CreateTime >= d1 && s.CreateTime <= d2 select s.Id).Distinct().Count();

                WithdrawCutOff withdrawCutOff = new WithdrawCutOff();
                withdrawCutOff.BatchNo          = dateNow.ToString("yyyy-MM-dd") + "-" + (cutOffCountByDay + 1).ToString("d4");
                withdrawCutOff.CreateTime       = dateNow;
                withdrawCutOff.Creator          = operater;
                withdrawCutOff.Amount           = sumAmount;
                withdrawCutOff.AmountByAfterFee = sumAmountByAfterFee;
                withdrawCutOff.CutOffTime       = endTime;
                CurrentDb.WithdrawCutOff.Add(withdrawCutOff);
                CurrentDb.SaveChanges();



                foreach (var m in withdrawList)
                {
                    var withdrawAccount = CurrentDb.BankCard.Where(q => q.Id == m.BankCardId).FirstOrDefault();


                    WithdrawCutOffDetails cutOffDetail = new WithdrawCutOffDetails();
                    cutOffDetail.UserId                      = m.UserId;
                    cutOffDetail.WithdrawCutOffId            = withdrawCutOff.Id;
                    cutOffDetail.MerchantId                  = m.MerchantId;
                    cutOffDetail.WithdrawBankCardId          = m.BankCardId;
                    cutOffDetail.WithdrawId                  = m.Id;
                    cutOffDetail.WithdrawBankAccountName     = withdrawAccount.BankAccountName;
                    cutOffDetail.WithdrawBankAccountNo       = withdrawAccount.BankAccountNo;
                    cutOffDetail.WithdrawBankName            = withdrawAccount.BankName;
                    cutOffDetail.WithdrawSn                  = m.Sn;
                    cutOffDetail.WithdrawAmount              = m.Amount;
                    cutOffDetail.WithdrawFeeRateRule         = m.FeeRateRule;
                    cutOffDetail.WithdrawFee                 = m.Fee;
                    cutOffDetail.WithdrawAmountByAfterFee    = m.AmountByAfterFee;
                    cutOffDetail.WithdrawStartTime           = m.SettlementStartTime;
                    cutOffDetail.WithdrawExpectArriveTime    = m.ExpectArriveTime;
                    cutOffDetail.WithdrawSettlementStartTime = dateNow;
                    cutOffDetail.WithdrawStatus              = Enumeration.WithdrawStatus.Handing;
                    cutOffDetail.WithdrawCutoffTime          = this.DateTime;
                    cutOffDetail.CreateTime                  = dateNow;
                    cutOffDetail.Creator                     = operater;
                    cutOffDetail.WithdrawCutoffTime          = this.DateTime;

                    CurrentDb.WithdrawCutOffDetails.Add(cutOffDetail);

                    m.WithdrawCutoffTime = this.DateTime;
                    m.WithdrawCutoffId   = withdrawCutOff.Id;
                    m.Status             = Enumeration.WithdrawStatus.Handing;
                    m.LastUpdateTime     = dateNow;
                    m.Mender             = operater;
                }

                CurrentDb.SaveChanges();

                ts.Complete();


                result = new CustomJsonResult(ResultType.Success, "截单成功");
            }

            return(result);
        }