示例#1
0
        public bool NotifyForPay(long log_id, out string msg)
        {
            msg = "";
            if (log_id == 0)
            {
                msg = "ID不能为空";
                return(false);
            }
            v4_pay_logVModel payView = dal.GetV4_pay_log(log_id);

            if (payView.Log_id == 0)
            {
                msg = "没有此缴费记录";
                return(false);
            }
            if (string.IsNullOrEmpty(msg) && payView.ErrCode != 0)
            {
                msg = "已处理";
            }
            if (string.IsNullOrEmpty(msg) && payView.Co_id == 0)
            {
                msg = "请选择组织";
            }
            if (payView.IsWrong != 1)
            {
                if (string.IsNullOrEmpty(msg) && payView.PayVal == 0)
                {
                    msg = "请输入电量";
                }
                if (string.IsNullOrEmpty(msg) && payView.PayAmt == 0)
                {
                    msg = "请输入金额";
                }
            }
            if (string.IsNullOrEmpty(msg) && payView.PayType != 1 && payView.PayType != 2 && payView.PayType != 3 && payView.PayType != 4)
            {
                msg = "类型错误:" + payView.PayType;
            }
            if ((payView.PayStartTime.Year == 1900 || payView.PayEndTime.Year == 1900 || payView.PayStartTime > payView.PayEndTime))
            {
                msg = "预付费日期错误";
            }
            if (!string.IsNullOrEmpty(msg))
            {
                return(false);
            }
            //
            payView.ErrCode = 1;
            payView.ErrTxt  = "";
            dal.UpV4_pay_log(payView);
            return(true);
        }
示例#2
0
        //生成二维码地址
        private string GetPayUrl(v4_pay_logVModel pay)
        {
            //pay.IsPay = 1;
            string body         = string.Format("【{0}{1}】电费充值", pay.ModuleAddr, "");//商品描述;
            int    total_fee    = (int)(pay.PayAmt * 100);
            string out_trade_no = "";
            string productId    = pay.Co_id.ToString() + "-" + pay.Module_id.ToString() + "-" + pay.ModuleAddr;
            string urlPay       = "";

            urlPay       = new WxPayAPI.WxPay().GetPayUrl(productId, body, total_fee, out out_trade_no);
            pay.Trade_no = out_trade_no;
            return(urlPay);
        }
示例#3
0
        /// <summary>
        /// 赠送电(临时使用,又是一个演示的坑)
        /// </summary>
        /// <param name="pay"></param>
        /// <returns></returns>
        public long YdPrePayInMdOnTmp(v4_pay_logVModel pay)
        {
            object params01 = new
            {
                Ledger     = this.Ledger,
                Co_id      = pay.Co_id,
                Module_id  = pay.Module_id,
                ModuleAddr = pay.ModuleAddr,
                Fun_id     = pay.Fun_id,
                PayVal     = pay.PayVal,
                SysUid     = this.SysUid,
            };
            long          cmd_log_id = 0;
            StringBuilder strSql     = new StringBuilder();

            using (var conn1 = SQLHelper.GetDBConnection())
            {//更新数据库
                try
                {
                    conn1.Open();
                    using (var trans = conn1.BeginTransaction())
                    {
                        strSql.Clear();
                        if (pay.PayType == 3)
                        {/*赠电*/
                            strSql.Append("update v2_info set BaseVal=BaseVal+@PayVal,RaVal=RaVal+@PayVal where Ledger=@Ledger and Co_id=@Co_id and Module_id=@Module_id and ModuleAddr=@ModuleAddr and Fun_id=@Fun_id");
                        }
                        else if (pay.PayType == 4)
                        {
                            strSql.Append("update v2_info set BaseVal=case when BaseVal-@PayVal < 0 then 0 else BaseVal-@PayVal end,");
                            strSql.Append("RaVal = case when RaVal-@PayVal<0 then 0 else RaVal-@PayVal end where Ledger=@Ledger and Co_id=@Co_id and Module_id=@Module_id and ModuleAddr=@ModuleAddr and Fun_id=@Fun_id");
                        }
                        conn1.Execute(strSql.ToString(), params01, trans);

                        this.YdPrePayInMdOnChangePayLog(conn1, trans, pay);
                        trans.Commit();
                    }
                    conn1.Close();
                }
                catch (Exception ex)
                {
                    pay.ErrCode = -1;
                    pay.ErrTxt  = ex.Message;
                    this.UpV4_pay_log(pay);
                    throw ex;
                }
            }
            return(cmd_log_id);
        }
示例#4
0
        /// <summary>
        /// 获取付费历史记录
        /// </summary>
        /// <param name="log_id"></param>
        /// <returns></returns>
        public v4_pay_logVModel GetV4_pay_log(long log_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Log_id,CDate,Co_id,Module_id,ModuleAddr,Fun_id,PayVal,PayAmt,PayType,IsWrong,Create_by,Create_dt,IsPay,Trade_no,PayTxt,PayStartTime,PayEndTime,IsCharg");
            strSql.Append(" from v4_pay_log where Log_id=@Log_id");
            DataTable        dtSource = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Log_id = log_id });
            v4_pay_logVModel payView  = new v4_pay_logVModel();

            if (dtSource.Rows.Count == 1)
            {
                payView = ModelHandler <v4_pay_logVModel> .FillModel(dtSource.Rows[0]);
            }
            return(payView);
        }
示例#5
0
        public int UpV4_pay_log(v4_pay_logVModel pay)
        {
            object params01 = new
            {
                Log_id  = pay.Log_id,
                ErrCode = pay.ErrCode,
                ErrTxt  = pay.ErrTxt,
                PayTxt  = pay.PayTxt,
                SysUid  = this.SysUid,
            };
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update v4_pay_log set ErrCode=@ErrCode,ErrTxt=@ErrTxt,EndTime=now(),PayTxt=@PayTxt where Log_id=@Log_id");
            return(SQLHelper.Execute(strSql.ToString(), params01));
        }
示例#6
0
        /// <summary>
        /// 增加记录log
        /// </summary>
        /// <param name="pay"></param>
        /// <returns></returns>
        public bool YdDbMidAddPayLog(v4_pay_logVModel pay, DateTime endatatime, long recno)
        {
            object params01 = new
            {
                Ledger       = this.Ledger,
                CDate        = DateTime.Now,
                Co_id        = pay.Co_id,
                Module_id    = pay.Module_id,
                ModuleAddr   = pay.ModuleAddr,
                Fun_id       = pay.Fun_id,
                PayVal       = pay.PayVal,
                PayAmt       = pay.PayAmt,
                PayType      = pay.PayType,
                IsWrong      = pay.IsWrong,
                IsPay        = pay.IsPay,
                Trade_no     = pay.Trade_no,
                PayStartTime = pay.PayStartTime,
                PayEndTime   = pay.PayEndTime,
                IsCharg      = pay.IsCharg,
                Price        = pay.Price,
                ErrCode      = pay.ErrCode,
                ErrTxt       = pay.ErrTxt,
                SysUid       = this.SysUid,
                Month        = endatatime,
                Recno        = recno,
            };
            StringBuilder strSql = new StringBuilder();

            //
            strSql.Clear();
            strSql.Append("insert into v4_pay_log(");
            strSql.Append("Ledger,CDate,Co_id,Module_id,ModuleAddr,Fun_id,PayVal,PayAmt,PayType,IsWrong,Create_by,Create_dt,IsPay,Trade_no,PayStartTime,PayEndTime,IsCharg,Price,ErrCode,ErrTxt,Month,Recno)");
            strSql.Append(" values (");
            strSql.Append("@Ledger,@CDate,@Co_id,@Module_id,@ModuleAddr,@Fun_id,@PayVal,@PayAmt,@PayType,@IsWrong,@SysUid,now(),@IsPay,@Trade_no,@PayStartTime,@PayEndTime,@IsCharg,@Price,@ErrCode,@ErrTxt,UNIX_TIMESTAMP(@Month),@Recno);");
            strSql.Append("select last_insert_id();");
            object obj = SQLHelper.ExecuteScalar(strSql.ToString(), params01);

            pay.Log_id = CommFunc.ConvertDBNullToLong(obj);
            if (pay.Log_id > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#7
0
文件: ChargeDAL.cs 项目: ZQuanLi/Test
        public int UpV4_pay_log(v4_pay_logVModel pay)
        {
            object params01 = new
            {
                Log_id  = pay.Log_id,
                Ledger  = this.Ledger,
                Co_id   = pay.Co_id,
                ErrCode = pay.ErrCode,
                ErrTxt  = pay.ErrTxt,
                PayTxt  = pay.PayTxt,
                SysUid  = this.SysUid,
                PayAmt  = pay.PayAmt,
            };
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update v4_pay_log set ErrCode=@ErrCode,ErrTxt=@ErrTxt,EndTime=now(),PayTxt=@PayTxt where Log_id=@Log_id;");
            strSql.Append("update v1_custinfo set Total=Total+@PayAmt,RdAmt=RdAmt+@PayAmt where Ledger=@Ledger and Co_id=@Co_id;");
            return(SQLHelper.Execute(strSql.ToString(), params01));
        }
示例#8
0
        /// <summary>
        /// 更新付款信息
        /// </summary>
        /// <param name="pay"></param>
        public long YdPrePayInMdOnChrg(v4_pay_logVModel pay, long recno)
        {
            long cmd_log_id = 0;

            using (var conn1 = SQLHelper.GetDBConnection())
            {//更新数据库
                try
                {
                    conn1.Open();
                    using (var trans = conn1.BeginTransaction())
                    {
                        if (pay.PayType == 1)
                        {
                            this.YdPrePayInMdOnChangeMthBill(conn1, trans, pay.Co_id, pay.PayVal); /*更新组织逐月用电*/
                            this.YdPrePayInMdOnChangeBill(conn1, trans, pay.Co_id, pay.PayVal);    /*更新组织用电*/
                        }
                        else if (pay.PayType == 2)
                        {
                            throw new Exception("类型错误");
                        }
                        cmd_log_id = this.YdPrePayInMdOnChangeV2Info(conn1, trans, pay.Co_id, pay.Module_id, pay.ModuleAddr, pay.PayVal, pay.PayType);/*更新设备用电信息*/
                        this.YdPrePayInMdOnChangePayLog(conn1, trans, pay);
                        this.UpdateDk_buy(conn1, trans, recno, pay.Co_id, pay.PayVal);
                        trans.Commit();
                    }
                    conn1.Close();
                }
                catch (Exception ex)
                {
                    pay.ErrCode = -1;
                    pay.ErrTxt  = ex.Message;
                    this.UpV4_pay_log(pay);
                    throw ex;
                }
            }
            return(cmd_log_id);
        }
示例#9
0
        private int YdPrePayInMdOnChangePayLog(IDbConnection conn1, IDbTransaction trans, v4_pay_logVModel pay)
        {
            object params01 = new
            {
                Log_id  = pay.Log_id,
                ErrCode = pay.ErrCode,
                ErrTxt  = pay.ErrTxt,
                PayTxt  = pay.PayTxt,
                SysUid  = this.SysUid,
            };
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update v4_pay_log set ErrCode=@ErrCode,ErrTxt=@ErrTxt,EndTime=now(),PayTxt=@PayTxt where Log_id=@Log_id");
            return(conn1.Execute(strSql.ToString(), params01, trans));
        }
示例#10
0
        // 充值
        public APIRst YdPrePayInMd_01OnChrg(decimal price, int payType, int co_id, int module_id, string moduleAddr, int fun_id, decimal payAmt, int isPay)
        {
            APIRst rst = new APIRst();

            if (price == 0)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "单价不能为零";
                return(rst);
            }
            v4_pay_logVModel pay = new v4_pay_logVModel();

            pay.Co_id      = co_id;
            pay.Module_id  = module_id;
            pay.ModuleAddr = moduleAddr;
            pay.Fun_id     = fun_id;
            pay.PayAmt     = payAmt;
            //pay.PayStartTime = CommFunc.ConvertDBNullToDateTime(Request["StartTime"]);
            //pay.PayEndTime = CommFunc.ConvertDBNullToDateTime(Request["EndTime"]);
            //pay.PayVal = (decimal)(((int)((pay.PayAmt / price) * 100)) / 100.00); /*不四舍五入*/ // Math.Round(pay.PayAmt / price, 2, MidpointRounding.AwayFromZero);
            pay.PayVal  = Math.Round(pay.PayAmt / price, 2, MidpointRounding.AwayFromZero);
            pay.PayType = payType;
            pay.IsWrong = 0;
            pay.IsPay   = isPay;
            if (pay.Co_id == 0 || pay.Module_id == 0 || pay.Fun_id == 0 || string.IsNullOrEmpty(pay.ModuleAddr))
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "信息缺失";
                return(rst);
            }
            if (pay.PayAmt == 0 || pay.PayVal == 0)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "金额不能为零";
                return(rst);
            }
            if (pay.PayStartTime.Year == 1900 || pay.PayEndTime.Year == 1900 || pay.PayEndTime < pay.PayStartTime)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "日期错误";
                return(rst);
            }
            if (pay.PayType != 1 && pay.PayType != 2 && pay.PayType != 3 && pay.PayType != 4)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "缴费类型错误";
                return(rst);
            }

            try
            {
                string urlPay = "";
                if (pay.IsPay != 0)
                {
                    urlPay = this.GetPayUrl(pay); //获取支付二维码
                }
                bll.AddV4_pay_log(pay);           /*先记录数据库*/
                object obj = new { Log_id = pay.Log_id, Trade_no = pay.Trade_no, UrlPay = urlPay };
                rst.data = obj;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("支付错误信息(YdPostPayInMd):", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#11
0
        // 回调
        public APIRst YdPrepPayInMdRecallPay(int pId, int pMid, string pTrade_no)
        {
            long     log_id       = CommFunc.ConvertDBNullToLong(pId);
            int      module_id    = CommFunc.ConvertDBNullToInt32(pMid);
            string   out_trade_no = CommFunc.ConvertDBNullToString(pTrade_no);
            APIRst   rst          = new APIRst();
            string   msg          = "";
            string   status       = "";
            bool     result       = false;
            bool     pass         = true;
            bool     upSb         = true;
            bool     upDb         = false;
            DateTime dtNow        = DateTime.Now;
            long     cmd_log_id   = 0;

            #region 检查支付结果并更新数据库
            System.Threading.Thread.Sleep(1000);/*一秒检查一次*/
            object row   = "";
            object osObj = new { upSb = false, upDb = false, msg = "" };
            try
            {
                if (string.IsNullOrEmpty(out_trade_no))
                {
                    result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id);
                }
                else
                {
                    lock (ObjLock)
                    {/*每次只能单独运行,目的是防止重复更新数据库的充值信息(重要事情)*/
                        pass = new WxPayAPI.WxPay().GetResult(out_trade_no, out status);
                        if (pass == true)
                        {
                            result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id);
                        }
                    }
                }
                //
                if (result == true)
                {
                    string msg2 = "";
                    if (cmd_log_id != 0) //立刻发送命令到网关
                    {                    /*充值命令*/
                        upSb = false;
                        upSb = new YdToGw(user.Ledger, user.Uid).YdToGwAgain(cmd_log_id, out upDb, out msg2);
                    }
                    else
                    {
                        upDb = true;/*是否下发命令网关*/
                    }
                    //#region 发送命令到网关(这款用于河北工业大学的SB设备,特殊定制化)
                    //DataTable cmdPay = bll.GetGwPayData(module_id);
                    //foreach (DataRow dr in cmdPay.Rows)
                    //{
                    //    decimal sbRdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
                    //    decimal sbSyZsVal = CommFunc.ConvertDBNullToDecimal(dr["SyZsVal"]);

                    //    CommandVModel cmd = ModelHandler<CommandVModel>.FillModel(dr);
                    //    cmd.Fun_id = 0;
                    //    cmd.FunType = "PaySb1";
                    //    cmd.FunName = "充电";
                    //    cmd.DataValue = (sbRdVal - sbSyZsVal).ToString("f2");
                    //    cmd.Descr = "充电";
                    //    cmd.IsUI = true;
                    //    cmd.IsNDb = true;
                    //    new YdToGw(user.Ledger, user.Uid).SendCmd(cmd);
                    //    //
                    //    cmd = ModelHandler<CommandVModel>.FillModel(dr);
                    //    cmd.Fun_id = 0;
                    //    cmd.FunType = "PaySb2";
                    //    cmd.FunName = "增电";
                    //    cmd.DataValue = sbSyZsVal.ToString("f2");
                    //    cmd.Descr = "增电";
                    //    cmd.IsUI = true;
                    //    cmd.IsNDb = true;
                    //    new YdToGw(user.Ledger, user.Uid).SendCmd(cmd);
                    //}
                    //#endregion


                    //#region 发送短信
                    //bll.SendSms(log_id);
                    //#endregion
                    v4_pay_logVModel vpay = bll.GetV4_pay_log(log_id);

                    osObj = new { upSb = upSb, upDb = upDb, msg = msg2 };
                    decimal   chrgVal = 0, useVal = 0, rdVal = 0, syZsVal = 0;
                    DataTable dtSource = bll.GetYdPostPayInMdOnList(module_id);
                    if (dtSource.Rows.Count > 0)
                    {
                        chrgVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["ChrgVal"]);
                        useVal  = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["UseVal"]);
                        rdVal   = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["RdVal"]);
                        syZsVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["SyZsVal"]);
                    }
                    row = new { ChrgVal = chrgVal.ToString("f2"), UseVal = useVal.ToString("f2"), RdVal = rdVal.ToString("f2"), SyVal = (rdVal - syZsVal).ToString("f2"), SyZsVal = syZsVal.ToString("f2") };

                    //判断是否拉闸
                    YDS6000.BLL.Exp.Syscont.ParameterBLL sysBll = new YDS6000.BLL.Exp.Syscont.ParameterBLL(user.Ledger, user.Uid);
                    var dt = sysBll.GetAlarmCfg();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        decimal odValue  = CommFunc.ConvertDBNullToDecimal(dt.Rows[0]["CfValue"]);
                        int     isClosed = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Rule"]);
                        if (isClosed == 1)
                        {
                            if (rdVal <= odValue)
                            {
                                if (!YdBatchControlOfSsr("Ssr", "1", module_id.ToString()))
                                {
                                    FileLog.WriteLog("拉闸失败(YdPrepPayInMdRecallPay)", "拉闸失败");
                                }
                            }
                            else
                            {
                                if (vpay.PayType == (int)PayType.pay)
                                {/*充值动作才能合闸*/
                                    if (!YdBatchControlOfSsr("Ssr", "0", module_id.ToString()))
                                    {
                                        FileLog.WriteLog("合闸失败(YdPrepPayInMdRecallPay)", "合闸失败");
                                    }
                                }
                            }
                        }
                    }
                }
                object obj = new { pass = pass, row = row, osObj = osObj };
                rst.rst     = result;
                rst.data    = obj;
                rst.err.msg = msg;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("预付费错误(YdPrepPayInMdRecallPay)", ex.Message + ex.StackTrace);
            }
            #endregion
            return(rst);
        }
示例#12
0
 /// <summary>
 /// 增加记录log
 /// </summary>
 /// <param name="pay"></param>
 /// <returns></returns>
 public bool AddPayLog(v4_pay_logVModel pay, decimal rdAmt)
 {
     return(dal.AddPayLog(pay, rdAmt));
 }
示例#13
0
文件: EnergyBLL.cs 项目: ZQuanLi/Test
 /// <summary>
 /// 增加记录log
 /// </summary>
 /// <param name="pay"></param>
 /// <returns></returns>
 public bool AddPayLog(v4_pay_logVModel pay)
 {
     return(dal.AddPayLog(pay));
 }
示例#14
0
        public bool PayVal(long log_id, long recno, int errCode, string errTxt, out string msg, out long cmd_log_id)
        {
            msg        = "";
            cmd_log_id = 0;
            if (log_id == 0)
            {
                msg = "ID不能为空";
                return(false);
            }
            v4_pay_logVModel payView = dal.GetV4_pay_log(log_id);

            if (payView.Log_id == 0)
            {
                msg = "没有此缴费记录";
                return(false);
            }
            if (string.IsNullOrEmpty(msg) && payView.ErrCode != 0)
            {
                msg = "已处理";
            }
            if (string.IsNullOrEmpty(msg) && payView.Co_id == 0)
            {
                msg = "请选择房间";
            }
            if (string.IsNullOrEmpty(msg) && payView.PayVal == 0)
            {
                msg = "请输入电量";
            }
            if (string.IsNullOrEmpty(msg) && payView.PayAmt == 0)
            {
                msg = "请输入金额";
            }
            if (string.IsNullOrEmpty(msg) && payView.PayType != 1 && payView.PayType != 2 && payView.PayType != 3 && payView.PayType != 4 && payView.PayType != 5)
            {
                msg = "类型错误:" + payView.PayType;
            }

            if (!string.IsNullOrEmpty(msg))
            {
                return(false);
            }
            //
            if (errCode > 0)
            {
                payView.ErrCode = errCode;
                payView.ErrTxt  = "";
                if (payView.PayType == 1 || payView.PayType == 2 || payView.PayType == 5)
                {
                    cmd_log_id = dal.YdPrePayInMdOnChrg(payView, recno);
                }
                else if (payView.PayType == 3 || payView.PayType == 4)
                {
                    throw new Exception("类型错误");
                }
            }
            else
            {
                payView.ErrCode = errCode;
                payView.ErrTxt  = errTxt;
                dal.UpV4_pay_log(payView);
            }
            return(true);
        }
示例#15
0
 /// <summary>
 /// 增加记录log
 /// </summary>
 /// <param name="pay"></param>
 /// <returns></returns>
 public bool YdDbMidAddPayLog(v4_pay_logVModel pay, DateTime endatatime, long recno)
 {
     return(dal.YdDbMidAddPayLog(pay, endatatime, recno));
 }
示例#16
0
        /// <summary>
        /// 支付购电
        /// </summary>
        /// <param name="co_id">房间ID号</param>
        /// <param name="payAmt">充值金额</param>
        /// <returns></returns>
        public APIRst ForPay(int co_id, decimal payAmt)
        {
            APIRst rst = new APIRst();

            if (co_id == 0)
            {
                rst.rst = false;
                rst.err = new APIErr()
                {
                    code = 100, msg = "设备编号不能为空"
                };
                return(rst);
            }
            if (payAmt <= 0)
            {
                rst.rst = false;
                rst.err = new APIErr()
                {
                    code = 100, msg = "充值金额不能为零"
                };
                return(rst);
            }
            //App支付预处理
            try
            {
                v4_pay_logVModel pay = new v4_pay_logVModel();
                #region 登记付款log记录
                DataTable dtSource = bll.GetUserInfo();
                int       nRows    = dtSource.Rows.Count;
                if (nRows == 0)
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "没有此用户,请重新登陆";
                    return(rst);
                }
                string  uName      = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["CrmName"]);
                string  code       = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["Contract"]);
                string  roomName   = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["CoFullName"]);
                string  moduleName = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["ModuleName"]);
                decimal rdAmt      = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["RdAmt"]);

                pay.Co_id        = co_id;
                pay.Module_id    = 0;
                pay.ModuleAddr   = ""; // CommFunc.ConvertDBNullToString(Request["ModuleAddr"]);
                pay.Fun_id       = 0;
                pay.PayAmt       = payAmt;
                pay.PayVal       = payAmt; //Math.Round(pay.PayAmt / pay.Price, 2, MidpointRounding.AwayFromZero);
                pay.PayType      = 1;
                pay.IsWrong      = 0;
                pay.IsPay        = 10;
                pay.PayStartTime = DateTime.Now;
                pay.PayEndTime   = DateTime.Now;
                if (pay.Co_id == 0)
                {
                    rst.rst = false;
                    rst.err = new APIErr()
                    {
                        code = 100, msg = "充值信息缺失"
                    };
                    return(rst);
                }
                if (pay.PayAmt <= 0 || pay.PayVal <= 0)
                {
                    rst.rst = false;
                    rst.err = new APIErr()
                    {
                        code = 100, msg = "充值金额" + pay.PayAmt + "单价:" + pay.Price + "转换电量:" + pay.PayVal + "不能为零"
                    };
                    return(rst);
                }
                if (pay.PayStartTime.Year == 1900 || pay.PayEndTime.Year == 1900 || pay.PayEndTime < pay.PayStartTime)
                {
                    rst.rst = false;
                    rst.err = new APIErr()
                    {
                        code = 100, msg = "充值日期错误"
                    };
                    return(rst);
                }
                #endregion

                #region 发起微信支付
                string strBody     = string.Format("【{0}{1}】充值", roomName, pay.ModuleAddr); //商品描述
                string out_tran_no = "";
                new WxPayAPI.WxPay();                                                       /*初始下微信支付环境*/
                JsApiPay jsApiPay = new JsApiPay();
                jsApiPay.openid    = "";
                jsApiPay.total_fee = (int)(payAmt * 100);
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(strBody, "附件信息:智能用电", "APP", out out_tran_no);
                //FileLog.WriteLog("步骤一:", "单号:" + out_tran_no);
                WxPayData wxJsApiParam = jsApiPay.GetAppApiParameters();//获取H5调起JS API参数
                object    order        = new
                {
                    appid     = wxJsApiParam.GetValue("appid").ToString(),
                    partnerid = wxJsApiParam.GetValue("partnerid").ToString(),
                    prepayid  = wxJsApiParam.GetValue("prepayid").ToString(),
                    package   = "Sign=WXPay",
                    noncestr  = wxJsApiParam.GetValue("noncestr").ToString(),
                    timestamp = CommFunc.ConvertDBNullToInt32(wxJsApiParam.GetValue("timestamp")),
                    sign      = wxJsApiParam.GetValue("sign").ToString(),
                };
                pay.Trade_no = out_tran_no;
                #endregion

                if (string.IsNullOrEmpty(pay.Trade_no))
                {
                    rst.rst = false;
                    rst.err = new APIErr()
                    {
                        code = 100, msg = "微信支付产生单号为空"
                    };
                    return(rst);
                }
                bll.AddPayLog(pay, rdAmt);

                rst.rst  = true;
                rst.data = order;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("支付失败:", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#17
0
        /// <summary>
        /// 回调付款
        /// </summary>
        /// <param name="log_id"></param>
        /// <param name="nAct"></param>
        /// <param name="rMsg"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool YdPrePayInMdOnRecallPay(long log_id, int ErrCode, string rMsg, out string msg, out long cmd_log_id)
        {
            msg        = "";
            cmd_log_id = 0;
            if (log_id == 0)
            {
                msg = "ID不能为空";
                return(false);
            }
            v4_pay_logVModel payView = dal.GetV4_pay_log(log_id);

            if (payView.Log_id == 0)
            {
                msg = "没有此缴费记录";
                return(false);
            }
            if (string.IsNullOrEmpty(msg) && payView.ErrCode != 0)
            {
                msg = "已处理";
            }
            if (string.IsNullOrEmpty(msg) && payView.Co_id == 0)
            {
                msg = "请选择组织";
            }
            if (payView.IsWrong != 1)
            {
                if (string.IsNullOrEmpty(msg) && payView.PayVal == 0)
                {
                    msg = "请输入电量";
                }
                if (string.IsNullOrEmpty(msg) && payView.PayAmt == 0)
                {
                    msg = "请输入金额";
                }
            }
            if (string.IsNullOrEmpty(msg) && payView.PayType != 1 && payView.PayType != 2 && payView.PayType != 3 && payView.PayType != 4)
            {
                msg = "类型错误:" + payView.PayType;
            }
            if ((payView.PayStartTime.Year == 1900 || payView.PayEndTime.Year == 1900 || payView.PayStartTime > payView.PayEndTime))
            {
                msg = "预付费日期错误";
            }
            if (!string.IsNullOrEmpty(msg))
            {
                return(false);
            }
            //
            if (ErrCode > 0)
            {
                payView.ErrCode = ErrCode;
                payView.ErrTxt  = "";
                if (payView.PayType == 1 || payView.PayType == 2)
                {
                    cmd_log_id = dal.YdPrePayInMdOnChrg(payView);
                }
                else if (payView.PayType == 3 || payView.PayType == 4)
                {
                    cmd_log_id = dal.YdPrePayInMdOnTmp(payView);
                }
            }
            else
            {
                payView.ErrCode = ErrCode;
                payView.ErrTxt  = rMsg;
                dal.UpV4_pay_log(payView);
            }
            return(true);
        }
示例#18
0
        private bool YdDbMidRun()
        {
            DataTable dtSource = bll.GetDk_buy();

            if (dtSource == null)
            {
                return(false);
            }

            foreach (DataRow dr in dtSource.Rows)
            {
                long     recno      = CommFunc.ConvertDBNullToLong(dr["recno"]);
                int      co_id      = CommFunc.ConvertDBNullToInt32(dr["FJID"]);
                decimal  payAmt     = CommFunc.ConvertDBNullToDecimal(dr["tranamt"]) / 100;
                DateTime endatatime = CommFunc.ConvertDBNullToDateTime(dr["endatatime"]);

                if (co_id == 0)
                {
                    FileLog.WriteLog("中间库房间ID号为空");
                    continue;
                }
                if (payAmt == 0)
                {
                    FileLog.WriteLog("中间库充值金额为0");
                    continue;
                }
                DataTable dtPay = bll.GetPayInfo(co_id);
                if (dtPay.Rows.Count == 0)
                {
                    FileLog.WriteLog("中间库的房间ID:" + co_id + "没有表信息存在");
                    continue;
                }
                if (dtPay.Rows.Count > 1)
                {
                    FileLog.WriteLog("中间库的房间ID:" + co_id + "存在多个表");
                    continue;
                }
                decimal price = CommFunc.ConvertDBNullToDecimal(dtPay.Rows[0]["Price"]);
                if (price == 0)
                {
                    FileLog.WriteLog("中间库的房间ID:" + co_id + "单价不能为零");
                    continue;
                }
                v4_pay_logVModel pay = new v4_pay_logVModel();
                pay.Co_id        = CommFunc.ConvertDBNullToInt32(dtPay.Rows[0]["Co_id"]);
                pay.Module_id    = CommFunc.ConvertDBNullToInt32(dtPay.Rows[0]["Module_id"]);
                pay.ModuleAddr   = CommFunc.ConvertDBNullToString(dtPay.Rows[0]["ModuleAddr"]);; // CommFunc.ConvertDBNullToString(Request["ModuleAddr"]);
                pay.Fun_id       = CommFunc.ConvertDBNullToInt32(dtPay.Rows[0]["Fun_id"]);
                pay.PayAmt       = payAmt;
                pay.PayVal       = Math.Round(pay.PayAmt / price, 2, MidpointRounding.AwayFromZero);
                pay.PayType      = 1;
                pay.IsWrong      = 0;
                pay.IsPay        = 30;
                pay.PayStartTime = DateTime.Now;
                pay.PayEndTime   = DateTime.Now;
                pay.Price        = price;
                bll.YdDbMidAddPayLog(pay, endatatime, recno);
                string msg        = "";
                long   cmd_log_id = 0;
                bll.PayVal(pay.Log_id, recno, 1, "", out msg, out cmd_log_id);
                if (cmd_log_id != 0)//立刻发送命令到网关
                {
                    CommandVModel cmd = bll.GetYdToGwOfSendCmd(cmd_log_id);
                    DataProcess.YdDrive.Collection.CollectionHelper.Instance(cmd);
                }
                DataTable dtMM = bll.GetYdPostPayInMdOnList(pay.Module_id);
                decimal   chrgVal = 0, useVal = 0, rdVal = 0, syZsVal = 0;
                if (dtMM.Rows.Count > 0)
                {
                    chrgVal = CommFunc.ConvertDBNullToDecimal(dtMM.Rows[0]["ChrgVal"]);
                    useVal  = CommFunc.ConvertDBNullToDecimal(dtMM.Rows[0]["UseVal"]);
                    rdVal   = CommFunc.ConvertDBNullToDecimal(dtMM.Rows[0]["RdVal"]);
                    syZsVal = CommFunc.ConvertDBNullToDecimal(dtMM.Rows[0]["SyZsVal"]);
                }

                //判断是否拉闸
                YDS6000.BLL.Exp.Syscont.ParameterBLL sysBll = new YDS6000.BLL.Exp.Syscont.ParameterBLL(0, 1);
                var dt = sysBll.GetAlarmCfg();
                if (dt != null && dt.Rows.Count > 0)
                {
                    decimal odValue  = CommFunc.ConvertDBNullToDecimal(dt.Rows[0]["CfValue"]);
                    int     isClosed = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Rule"]);
                    if (isClosed == 1)
                    {
                        if (rdVal <= odValue)
                        {
                            this.YdBatchControlOfSsr(pay.Module_id, "Ssr", "1", 30);
                        }
                        else
                        {
                            this.YdBatchControlOfSsr(pay.Module_id, "Ssr", "0", 30);
                        }
                    }
                }
            }
            return(true);
        }