コード例 #1
0
        public static string SaveRoomFee(string tradeno, string Remark, string ChargeType, int OrderID = 0)
        {
            //var history_count = Foresight.DataAccess.RoomFeeHistory.GetRoomFeeHistoryCountByTradeNo(tradeno, OrderID: OrderID);
            //if (history_count > 0)
            //{
            //    return "历史账单已存在";
            //}
            List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();
            var request_list = Foresight.DataAccess.Payment_Request.GetPayment_RequestByTradeNo(tradeno, OrderID: OrderID);

            if (request_list.Length == 0)
            {
                return("Payment_Request不存在");
            }
            RoomFeeAnalysis viewroomfee   = null;
            decimal         TotalCost     = 0;
            int             RoomID        = 0;
            string          RoomFullName  = string.Empty;
            string          RoomOwnerName = string.Empty;
            string          AllParentID   = string.Empty;

            foreach (var item in request_list)
            {
                viewroomfee = RoomFeeAnalysis.GetRoomFeeAnalysisByEndTime(item.RoomFeeID, item.EndTime, relatedRequire: true);
                if (viewroomfee == null)
                {
                    continue;
                }
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic["ID"] = viewroomfee.ID;
                dic["CalculateStartTime"] = viewroomfee.CalculateStartTime;
                dic["CalculateEndTime"]   = viewroomfee.CalculateEndTime;
                dic["TotalCost"]          = viewroomfee.TotalCost;
                dic["CalculateUnitPrice"] = viewroomfee.CalculateUnitPrice;
                dic["CalculateUseCount"]  = viewroomfee.CalculateUseCount;
                list.Add(dic);
                TotalCost    += viewroomfee.TotalCost;
                RoomID        = viewroomfee.RoomID;
                RoomFullName  = viewroomfee.FullName + "-" + viewroomfee.RoomName;
                RoomOwnerName = viewroomfee.FinalCustomerName;
                AllParentID   = viewroomfee.AllParentID;
            }
            if (list.Count == 0)
            {
                return("ViewRoomFee不存在");
            }
            var    payment = Foresight.DataAccess.Payment.GetPaymentByTradeNo(tradeno);
            string OpenID  = payment.AddUser;
            var    wuser   = Foresight.DataAccess.Wechat_User.GetWechat_UserByUserOpenID(OpenID);
            string AddMan  = (wuser != null && !string.IsNullOrEmpty(wuser.NickName)) ? wuser.NickName : OpenID;
            PrintRoomFeeHistory printRoomFeeHistory = new PrintRoomFeeHistory();
            string ChargeMan            = AddMan;
            var    ConfigName           = SysConfigNameDefine.WeixinChargeMan;
            var    sysConfigList        = SysConfig.Get_SysConfigListByProjectIDList(MinProjectID: RoomID, MaxProjectID: RoomID, ConfigName: ConfigName);
            string defaultChargeManName = SysConfig.GetConfigValueByList(sysConfigList, ConfigName, AllParentID: AllParentID);

            if (!string.IsNullOrEmpty(defaultChargeManName))
            {
                ChargeMan = defaultChargeManName;
            }
            var ViewChargeSummaryList = ViewChargeSummary.GetViewChargeSummaries().ToArray();

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    SavePrintRoomFeeHistory(printRoomFeeHistory, RoomID, TotalCost, ChargeMan, helper, RoomFullName, RoomOwnerName, Remark, ChargeType, payment.AddTime);
                    foreach (var field in list)
                    {
                        int FeeID   = WebUtil.GetIntByStr(field["ID"].ToString());
                        var roomFee = Foresight.DataAccess.RoomFee.GetRoomFee(FeeID, helper);
                        if (roomFee == null)
                        {
                            continue;
                        }
                        DateTime CalculateStartTime = WebUtil.GetDateTimeByStr(field["CalculateStartTime"].ToString());
                        roomFee.StartTime = CalculateStartTime > DateTime.MinValue ? CalculateStartTime : DateTime.MinValue;
                        DateTime CalculateEndTime = WebUtil.GetDateTimeByStr(field["CalculateEndTime"].ToString());
                        roomFee.EndTime = CalculateEndTime > DateTime.MinValue ? CalculateEndTime : DateTime.MinValue;
                        decimal CalculateUseCount = WebUtil.GetDecimalByStr(field["CalculateUseCount"].ToString());
                        roomFee.UseCount = CalculateUseCount;
                        decimal CalculateTotalCost = WebUtil.GetDecimalByStr(field["TotalCost"].ToString());
                        roomFee.Cost      = CalculateTotalCost > 0 ? CalculateTotalCost : 0;
                        roomFee.IsCharged = true;
                        decimal CalculateUnitPrice = WebUtil.GetDecimalByStr(field["CalculateUnitPrice"].ToString());
                        roomFee.UnitPrice         = CalculateUnitPrice > 0 ? CalculateUnitPrice : 0;
                        roomFee.ChargeFee         = roomFee.ChargeFee > 0 ? roomFee.ChargeFee : 0;
                        roomFee.RealCost          = roomFee.ChargeFee > 0 ? roomFee.ChargeFee : (roomFee.Cost > decimal.MinValue ? roomFee.Cost : 0);
                        roomFee.Discount          = roomFee.Discount > 0 ? roomFee.Discount : 0;
                        roomFee.TotalRealCost     = (roomFee.TotalRealCost < 0 ? 0 : roomFee.TotalRealCost) + roomFee.RealCost;
                        roomFee.TotalDiscountCost = (roomFee.TotalDiscountCost < 0 ? 0 : roomFee.TotalDiscountCost) + roomFee.Discount;
                        decimal restcost = roomFee.Cost - roomFee.TotalDiscountCost - roomFee.TotalRealCost;
                        if (restcost < 0)
                        {
                            restcost = 0;
                        }
                        roomFee.RestCost = restcost;
                        roomFee.Remark   = Remark;
                        roomFee.Save(helper);
                        #region 收费后续操作
                        LogHelper.WriteInfo("Web.APPCode.HandlerHelper.SaveRoomFee", "收费后续操作开始");
                        Web.APPCode.HandlerHelper.SaveRoomFee(roomFee, ChargeMan, helper, printRoomFeeHistory, ViewChargeSummaryList, OpenID: OpenID);
                        LogHelper.WriteInfo("Web.APPCode.HandlerHelper.SaveRoomFee", "收费后续操作完成");
                        #endregion
                    }
                    Payment.CompletePayment(helper, TradeNo: tradeno, payment: payment);
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    helper.Rollback();
                    LogHelper.WriteError("PaymentHelper.SaveRoomFee", ChargeType, ex);
                    return(ex.Message);
                }
            }
            return("Success");
        }
コード例 #2
0
ファイル: return.aspx.cs プロジェクト: sd009896/CustomerMall
        private bool WxPayComplete(HuiShouYin.Domain.Pay_Option PayOption, out string errormsg)
        {
            errormsg = string.Empty;
            string OpenID = PayOption.openid;
            var    wuser  = Foresight.DataAccess.Wechat_User.GetWechat_UserByUserOpenID(OpenID);
            string AddMan = (wuser != null && !string.IsNullOrEmpty(wuser.NickName)) ? wuser.NickName : OpenID;
            PrintRoomFeeHistory printRoomFeeHistory = new PrintRoomFeeHistory();
            var ModelList = PayOption.idlist;

            if (ModelList.Count == 0)
            {
                errormsg = "需要支付的费项不存在";
                return(false);
            }
            int    RoomID      = 0;
            string AllParentID = string.Empty;
            var    list        = new List <RoomFeeAnalysis>();

            foreach (var item in ModelList)
            {
                var viewRoomFee = RoomFeeAnalysis.GetRoomFeeAnalysisByEndTime(item.ID, Convert.ToDateTime(item.EndTime));
                if (viewRoomFee == null)
                {
                    continue;
                }
                list.Add(viewRoomFee);
                RoomID      = viewRoomFee.RoomID;
                AllParentID = viewRoomFee.AllParentID;
            }
            if (list.Count == 0)
            {
                errormsg = "需要支付的费项不存在";
                return(false);
            }
            var     ConfigName            = SysConfigNameDefine.WeixinChargeMan;
            var     sysConfigList         = SysConfig.Get_SysConfigListByProjectIDList(MinProjectID: RoomID, MaxProjectID: RoomID, ConfigName: ConfigName);
            string  ChargeMan             = SysConfig.GetConfigValueByList(sysConfigList, ConfigName, AllParentID: AllParentID);
            decimal TotalCost             = list.Sum(p => p.TotalCost);
            var     ViewChargeSummaryList = ViewChargeSummary.GetViewChargeSummaries().ToArray();

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    SavePrintRoomFeeHistory(printRoomFeeHistory, list[0].RoomID, TotalCost, ChargeMan, helper, list[0].FullName + "-" + list[0].RoomName, list[0].FinalCustomerName);
                    foreach (var field in list)
                    {
                        var roomFee = Foresight.DataAccess.RoomFee.GetRoomFee(field.ID, helper);
                        if (roomFee == null)
                        {
                            continue;
                        }
                        roomFee.StartTime         = field.CalculateStartTime > DateTime.MinValue ? field.CalculateStartTime : DateTime.MinValue;
                        roomFee.EndTime           = field.CalculateEndTime > DateTime.MinValue ? field.CalculateEndTime : DateTime.MinValue;
                        roomFee.NewEndTime        = field.NewEndTime > DateTime.MinValue ? field.NewEndTime : DateTime.MinValue;
                        roomFee.OutDays           = roomFee.OutDays;
                        roomFee.UseCount          = field.UseCount;
                        roomFee.Cost              = field.TotalCost;
                        roomFee.Remark            = roomFee.Remark;
                        roomFee.IsCharged         = true;
                        roomFee.UnitPrice         = field.CalculateUnitPrice > decimal.MinValue ? field.CalculateUnitPrice : 0;
                        roomFee.ChargeFee         = roomFee.ChargeFee > decimal.MinValue ? roomFee.ChargeFee : 0;
                        roomFee.RealCost          = roomFee.ChargeFee > 0 ? roomFee.ChargeFee : (field.TotalCost > decimal.MinValue ? field.TotalCost : 0);
                        roomFee.Discount          = field.Discount > decimal.MinValue ? field.Discount : 0;
                        roomFee.TotalRealCost     = (roomFee.TotalRealCost < 0 ? 0 : roomFee.TotalRealCost) + roomFee.RealCost;
                        roomFee.TotalDiscountCost = (roomFee.TotalDiscountCost < 0 ? 0 : roomFee.TotalDiscountCost) + roomFee.Discount;
                        decimal restcost = roomFee.Cost - roomFee.TotalDiscountCost - roomFee.TotalRealCost;
                        if (restcost < 0)
                        {
                            restcost = 0;
                        }
                        roomFee.RestCost             = restcost;
                        roomFee.ContractID           = field.ContractID;
                        roomFee.DiscountID           = roomFee.DiscountID;
                        roomFee.CuiShouStartTime     = field.CuiShouStartTime > DateTime.MinValue ? field.CuiShouStartTime : DateTime.MinValue;
                        roomFee.CuiShouEndTime       = field.CuiShouEndTime > DateTime.MinValue ? field.CuiShouEndTime : DateTime.MinValue;
                        roomFee.RelatedFeeID         = field.RelatedFeeID;
                        roomFee.ChongDiChargeID      = roomFee.ChongDiChargeID;
                        roomFee.DefaultChargeManID   = roomFee.DefaultChargeManID;
                        roomFee.DefaultChargeManName = field.DefaultChargeManName;
                        roomFee.Remark = "汇收银支付";
                        roomFee.Save(helper);
                        #region 收费后续操作
                        Web.APPCode.HandlerHelper.SaveRoomFee(roomFee, ChargeMan, helper, printRoomFeeHistory, ViewChargeSummaryList);
                        #endregion
                    }
                    helper.Commit();
                    var items = new { status = true, PrintID = printRoomFeeHistory.ID };
                    return(true);
                }
                catch (Exception ex)
                {
                    helper.Rollback();
                    LogHelper.WriteError("WechatHandler", "visit: wxpayroomfeecomplete", ex);
                    errormsg = ex.Message;
                    return(false);
                }
            }
        }