예제 #1
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(PayOrderEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[PayOrder] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
            }
            else
            {
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (entity.Id > 0)
            {
                db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            }
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
예제 #2
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <PayOrderEntity> GetPayOrderAll()
        {
            string sql = @"SELECT    [Id],[PayOrderCode],[SysOrderCode],[SysType],[NeedPayPrice],[PayMethod],[CreateTime],[CreateManId],[Status],[PayTime] from dbo.[PayOrder] WITH(NOLOCK)	";
            IList <PayOrderEntity> entityList = new List <PayOrderEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PayOrderEntity entity = new PayOrderEntity();
                    entity.Id           = StringUtils.GetDbInt(reader["Id"]);;
                    entity.PayOrderCode = StringUtils.GetDbString(reader["PayOrderCode"]);;
                    entity.SysOrderCode = StringUtils.GetDbString(reader["SysOrderCode"]);;
                    entity.SysType      = StringUtils.GetDbInt(reader["SysType"]);;
                    entity.NeedPayPrice = StringUtils.GetDbDecimal(reader["NeedPayPrice"]);;
                    entity.PayMethod    = StringUtils.GetDbInt(reader["PayMethod"]);;
                    entity.CreateTime   = StringUtils.GetDbDateTime(reader["CreateTime"]);;
                    entity.CreateManId  = StringUtils.GetDbInt(reader["CreateManId"]);;
                    entity.Status       = StringUtils.GetDbInt(reader["Status"]);;
                    entity.PayTime      = StringUtils.GetDbDateTime(reader["PayTime"]);;
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
예제 #3
0
        public PayOrderEntity GetPayOrderBySysCode(int systype, string syscode, int paytype)
        {
            string    sql = @"SELECT  [Id],[PayOrderCode],[SysOrderCode],[SysType],[NeedPayPrice],[PayMethod],[CreateTime],[CreateManId],[Status],[PayTime]
							FROM
							dbo.[PayOrder] WITH(NOLOCK)	
							WHERE [SysOrderCode]=@SysOrderCode and SysType=@SysType and PayMethod=@PayMethod "                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@SysOrderCode", DbType.String, syscode);
            db.AddInParameter(cmd, "@SysType", DbType.Int32, systype);
            db.AddInParameter(cmd, "@PayMethod", DbType.Int32, paytype);
            PayOrderEntity entity = new PayOrderEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id           = StringUtils.GetDbInt(reader["Id"]);
                    entity.PayOrderCode = StringUtils.GetDbString(reader["PayOrderCode"]);
                    entity.SysOrderCode = StringUtils.GetDbString(reader["SysOrderCode"]);
                    entity.SysType      = StringUtils.GetDbInt(reader["SysType"]);
                    entity.NeedPayPrice = StringUtils.GetDbDecimal(reader["NeedPayPrice"]);
                    entity.PayMethod    = StringUtils.GetDbInt(reader["PayMethod"]);
                    entity.CreateTime   = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.CreateManId  = StringUtils.GetDbInt(reader["CreateManId"]);
                    entity.Status       = StringUtils.GetDbInt(reader["Status"]);
                    entity.PayTime      = StringUtils.GetDbDateTime(reader["PayTime"]);
                }
            }
            return(entity);
        }
예제 #4
0
        public string PaySelectSubmit()
        {
            ResultObj _result  = new ResultObj();
            long      _syscode = FormString.LongIntSafeQ("syscode");
            int       _paytype = FormString.IntSafeQ("paytype");
            int       _systype = FormString.IntSafeQ("systype");

            if (_systype == 0)
            {
                _systype = (int)SystemType.B2B;
            }
            OrderEntity order      = OrderBLL.Instance.GetOrderByCode(_syscode);
            string      payconfirm = "";

            if (_paytype == (int)PayType.OutLine)
            {
                payconfirm = StringUtils.GetRandomString(12);
            }
            PayOrderEntity payen = PayOrderBLL.Instance.GetPayOrderBySysCode(_systype, _syscode.ToString(), _paytype);

            if (payen.Id > 0 && payen.Status == 1)
            {
                _result.Status = (int)CommonStatus.HasPayed;
                _result.Obj    = payen;
            }
            else
            {
                payen          = PayOrderBLL.Instance.CreatePayOrder(_systype, _syscode.ToString(), order.ActPrice, _paytype, memid, payconfirm);
                _result.Status = (int)CommonStatus.Success;
                _result.Obj    = payen;
            }
            return(JsonJC.ObjectToJson(_result));
        }
예제 #5
0
 public void SubmitRechargeMoney(ReadTaskEntity readTaskEntity, PayOrderEntity payOrderEntity)
 {
     using (var db = new RepositoryBase().BeginTrans())
     {
         db.Update(readTaskEntity);
         db.Update(payOrderEntity);
         db.Commit();
     }
 }
예제 #6
0
        public void CheckEntity(PayOrderEntity payOrderEntity)
        {
            var wait  = ((int)PayStateEnum.Wait).ToString();
            var write = ((int)PayStateEnum.Write).ToString();

            if (_service.IQueryable(x => x.F_ArchiveId == payOrderEntity.F_ArchiveId && (x.F_State == wait || x.F_State == write)).Any())
            {
                throw new Exception("当前表计存在未到账或未圈存充值记录");
            }
        }
예제 #7
0
        /// <summary>
        /// 账户充值支付结果
        /// </summary>
        /// <param name="payOrder"></param>
        /// <returns></returns>
        private NormalResult ProcessDepositPayNotify(PayOrderEntity payOrder)
        {
            NormalResult result = ProcessPayNotify(payOrder);

            if (result.Success)
            {
                FinishPayOrder(payOrder.Id);
            }

            return(result);
        }
예제 #8
0
 public void SubmitForm(PayOrderEntity payOrderEntity, string keyValue = "")
 {
     if (string.IsNullOrEmpty(keyValue))
     {
         _service.Insert(payOrderEntity);
     }
     else
     {
         _service.Update(payOrderEntity);
     }
 }
예제 #9
0
        private NormalResult ProcessPayNotify(PayOrderEntity payOrder)
        {
            NormalResult result = new NormalResult();

            List <CommandParameter> parameterList = new List <CommandParameter>();

            parameterList.Add(new CommandParameter("@domainId", payOrder.Domain));
            parameterList.Add(new CommandParameter("@appId", payOrder.AppId));
            parameterList.Add(new CommandParameter("@memberId", payOrder.Member));
            parameterList.Add(new CommandParameter("@fee", payOrder.TotalFee));
            parameterList.Add(new CommandParameter("@remark", DBNull.Value));
            parameterList.Add(new CommandParameter("@type", EnumCashAccountTrackType.Deposit));
            parameterList.Add(new CommandParameter("@operatorUser", DBNull.Value));
            parameterList.Add(new CommandParameter("@ip", DBNull.Value));

            DataSet dsResult = _dataBase.ExecuteDataSet(CommandType.StoredProcedure, "TrackMemberCash",
                                                        parameterList, new string[] { "result" });

            result.Reason = int.Parse(dsResult.Tables[0].Rows[0]["Result"].ToString());

            if (result.Reason == 0)
            {
                result.Success = true;
            }
            else
            {
                switch (result.Reason)
                {
                case 1:
                    result.Message = "账户余额不足。";
                    break;

                case 2:
                    result.Message = "指定的会员不存在。";
                    break;

                case 3:
                case 4:
                    result.Message = "无权限。";
                    break;

                default:
                    result.Message = "未知错误:" + result.Reason;
                    break;
                }
                result.Success = false;
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// 插入一条记录到表PayOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="payOrder">要添加的PayOrder数据实体对象</param>
        public int AddPayOrder(PayOrderEntity payOrder)
        {
            if (payOrder.Id > 0)
            {
                return(UpdatePayOrder(payOrder));
            }

            else if (PayOrderBLL.Instance.IsExist(payOrder))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(PayOrderDA.Instance.AddPayOrder(payOrder));
            }
        }
        /// <summary>
        /// action:1 页面加载后直接发起支付
        /// </summary>
        /// <param name="domainId"></param>
        /// <returns></returns>
        public ActionResult PayOrderDetail(string domainId)
        {
            string strId = Request.QueryString["id"];
            Guid   id    = Guid.Empty;

            if (String.IsNullOrEmpty(strId) || Guid.TryParse(strId, out id) == false)
            {
                return(RedirectToAction("PayOrderList", new { domainId = domainId }));
            }

            PayOrderEntity payOrder = _payManager.GetPayOrder(id);

            if (payOrder == null)
            {
                return(RedirectToAction("PayOrderList", new { domainId = domainId }));
            }
            return(View(payOrder));
        }
예제 #12
0
        /// <summary>
        /// 处理积分商城支付结果
        /// 先把钱存到账户余额,然后再从余额中下帐成单
        /// 防止订单过期,状态不对等各种原因导致钱丢失
        /// </summary>
        /// <param name="payOrder"></param>
        /// <returns></returns>
        private NormalResult ProcessPointCommodityPayNotify(PayOrderEntity payOrder)
        {
            NormalResult result = ProcessPayNotify(payOrder);

            if (result.Success == false)
            {
                return(result);
            }

            result = PointCommodityManager.Instance.ProcessWeixinPayNotify(payOrder);

            if (result.Success)
            {
                FinishPayOrder(payOrder.Id);
            }

            return(result);
        }
예제 #13
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="payOrder">待更新的实体对象</param>
        public int UpdatePayOrder(PayOrderEntity entity)
        {
            string    sql = @" UPDATE dbo.[PayOrder] SET
                       [PayOrderCode]=@PayOrderCode,[SysOrderCode]=@SysOrderCode,[SysType]=@SysType,[NeedPayPrice]=@NeedPayPrice,[PayMethod]=@PayMethod,[CreateTime]=@CreateTime,[CreateManId]=@CreateManId,[Status]=@Status,[PayTime]=@PayTime
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@PayOrderCode", DbType.String, entity.PayOrderCode);
            db.AddInParameter(cmd, "@SysOrderCode", DbType.String, entity.SysOrderCode);
            db.AddInParameter(cmd, "@SysType", DbType.Int32, entity.SysType);
            db.AddInParameter(cmd, "@NeedPayPrice", DbType.Decimal, entity.NeedPayPrice);
            db.AddInParameter(cmd, "@PayMethod", DbType.Int32, entity.PayMethod);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId);
            db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status);
            db.AddInParameter(cmd, "@PayTime", DbType.DateTime, entity.PayTime);
            return(db.ExecuteNonQuery(cmd));
        }
        /// <summary>
        /// 获取前端 WeixinJSBridge.invoke 使用的支付参数的 json 字符串
        /// </summary>
        /// <returns></returns>
        public ActionResult GetBrandWCPayRequestArgs()
        {
            string strPayOrderId = Request.QueryString["payOrderId"];
            Guid   payOrderId    = Guid.Empty;

            if (String.IsNullOrEmpty(strPayOrderId) || Guid.TryParse(strPayOrderId, out payOrderId) == false)
            {
                return(RespondResult(false, "参数无效。"));
            }

            PayOrderEntity payOrder = _payManager.GetPayOrder(payOrderId);

            if (payOrder == null)
            {
                return(RespondResult(false, "指定的支付订单不存在。"));
            }

            if (payOrder.Member != MemberContext.Member.Id)
            {
                return(RespondResult(false, "订单不属于您。"));
            }

            if (payOrder.TradeState != EnumPayTradeState.NOTPAY)
            {
                return(RespondResult(false, "订单状态不是待支付状态。"));
            }

            WxPayData jsApiParam = new WxPayData(DomainContext.AuthorizerPay.Key);

            jsApiParam.SetValue("appId", DomainContext.AppId);
            jsApiParam.SetValue("timeStamp", WeixinApiHelper.GetTimesTamp().ToString());
            jsApiParam.SetValue("nonceStr", WeixinApiHelper.GetNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + payOrder.PrepayId);
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string parameters = jsApiParam.ToJson();

            return(RespondDataResult(parameters));
        }
예제 #15
0
        public PayOrderEntity CreatePayOrder(int systemtype, string ordercode, decimal amountprice, int paymethod, int memid, string externalcode)
        {
            PayOrderEntity entity = new PayOrderEntity();

            entity = GetPayOrderBySysCode(systemtype, ordercode, paymethod);

            if (entity.Id > 0 && !string.IsNullOrEmpty(entity.PayOrderCode))
            {
                return(entity);
            }
            Random rd = new Random();

            entity.PayOrderCode = XTCodeBLL.Instance.GetCodeFromProc(XTCodeType.PayOrderDayNo) + rd.Next(100, 999).ToString();
            entity.CreateManId  = memid;
            entity.CreateTime   = DateTime.Now;
            entity.NeedPayPrice = amountprice;
            entity.PayMethod    = paymethod;
            entity.Status       = 0;
            entity.SysOrderCode = ordercode;
            entity.SysType      = systemtype;
            entity.ExternalCode = externalcode;
            entity.Id           = PayOrderDA.Instance.AddPayOrder(entity);
            return(entity);
        }
예제 #16
0
        /// <summary>
        /// 插入一条记录到表PayOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="payOrder">待插入的实体对象</param>
        public int AddPayOrder(PayOrderEntity entity)
        {
            string    sql = @"insert into PayOrder( [PayOrderCode],[SysOrderCode],[SysType],[NeedPayPrice],[PayMethod],[CreateTime],[CreateManId],[Status],ExternalCode )VALUES
			            ( @PayOrderCode,@SysOrderCode,@SysType,@NeedPayPrice,@PayMethod,@CreateTime,@CreateManId,@Status,@ExternalCode );
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@PayOrderCode", DbType.String, entity.PayOrderCode);
            db.AddInParameter(cmd, "@SysOrderCode", DbType.String, entity.SysOrderCode);
            db.AddInParameter(cmd, "@SysType", DbType.Int32, entity.SysType);
            db.AddInParameter(cmd, "@NeedPayPrice", DbType.Decimal, entity.NeedPayPrice);
            db.AddInParameter(cmd, "@PayMethod", DbType.Int32, entity.PayMethod);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId);
            db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status);
            db.AddInParameter(cmd, "@ExternalCode", DbType.String, entity.ExternalCode);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
예제 #17
0
 /// <summary>
 /// 更新一条PayOrder记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="payOrder">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdatePayOrder(PayOrderEntity payOrder)
 {
     return(PayOrderDA.Instance.UpdatePayOrder(payOrder));
 }
예제 #18
0
        /// <summary>
        /// 创建一个微信支付订单
        /// 默认在2小时后过期
        /// </summary>
        /// <param name="args"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public NormalResult <CreatePayOrderResult> CreatePayOrder(CreatePayOrderArgs args, AuthorizerPayConfig config)
        {
            NormalResult <CreatePayOrderResult> result = new NormalResult <CreatePayOrderResult>(false);

            if (config == null)
            {
                result.Message = "当前公众号没有微信支付所需配置信息。";
                return(result);
            }

            //TODO:这里只判断了 Deposit
            if (ExistUnfinishedOrder(config.Domain, config.AppId, args.MemberId, EnumPayOrderType.Deposit))
            {
                result.Message = "存在尚未结束的订单,请先完成当前订单的支付或将其关闭。";
                return(result);
            }

            //string outTradeNo =Guid.NewGuid().ToString().Replace("-", "");
            DateTime timeStart  = DateTime.Now;
            DateTime timeExpire = DateTime.Now.AddHours(2);

            Guid payOrderId = Guid.NewGuid();

            WeixinPayUnifiedOrderArgs unifiedOrderArgs = new WeixinPayUnifiedOrderArgs();

            unifiedOrderArgs.AppId      = config.AppId;
            unifiedOrderArgs.MchId      = config.MchId;
            unifiedOrderArgs.DeviceInfo = "WEB";
            unifiedOrderArgs.Body       = args.Body;       //"会员充值";
            unifiedOrderArgs.OutTradeNo = args.OutTradeNo; // outTradeNo;
            unifiedOrderArgs.TotalFee   = (int)args.Fee;

            unifiedOrderArgs.SpbillCreateIp = args.SpbillCreateIp;
            if (unifiedOrderArgs.SpbillCreateIp == "::1")
            {
                unifiedOrderArgs.SpbillCreateIp = "127.0.0.1";
            }

            unifiedOrderArgs.TimeStart  = timeStart.ToString("yyyyMMddHHmmss");
            unifiedOrderArgs.TimeExpire = timeExpire.ToString("yyyyMMddHHmmss");
            unifiedOrderArgs.NotifyUrl  = "";
            unifiedOrderArgs.TradeType  = "JSAPI";
            unifiedOrderArgs.OpenId     = args.OpenId;
            unifiedOrderArgs.NotifyUrl  =
                SettingsManager.Instance.GetClientAddress(config.AppId) + "Api/Pay/PayNotify/" + config.Domain;
            unifiedOrderArgs.Attach = payOrderId.ToString();

            WxPayArgs wxPayArgs = config.GetWxPayArgs(false);

            RequestPayApiResult <WeixinPayUnifiedOrderResult> unifiedOrderResult =
                WxPayApi.UnifiedOrder(unifiedOrderArgs, wxPayArgs);

            if (unifiedOrderResult.Success == false)
            {
                _log.Write("UnifiedOrder 失败",
                           unifiedOrderResult.Message + "\r\n"
                           + JsonHelper.Serializer(unifiedOrderArgs) + " "
                           + JsonHelper.Serializer(unifiedOrderResult),
                           TraceEventType.Warning);

                result.Success = false;
                result.Message = unifiedOrderResult.Message;
                return(result);
            }

            PayOrderEntity orderEntity = new PayOrderEntity();

            orderEntity.Id             = payOrderId;
            orderEntity.Domain         = config.Domain;
            orderEntity.Member         = args.MemberId;
            orderEntity.Type           = args.OrderType;
            orderEntity.AppId          = config.AppId;
            orderEntity.MchId          = config.MchId;
            orderEntity.DeviceInfo     = unifiedOrderArgs.DeviceInfo;
            orderEntity.Body           = unifiedOrderArgs.Body;
            orderEntity.OutTradeNo     = args.OutTradeNo;//outTradeNo;
            orderEntity.TotalFee       = unifiedOrderArgs.TotalFee;
            orderEntity.SpbillCreateIp = unifiedOrderArgs.SpbillCreateIp;
            orderEntity.TimeStart      = timeStart;
            orderEntity.TimeExpire     = timeExpire;
            orderEntity.TradeType      = unifiedOrderArgs.TradeType;
            orderEntity.OpenId         = unifiedOrderArgs.OpenId;

            orderEntity.PrepayId = unifiedOrderResult.ApiResult.PrepayId;

            orderEntity.TradeState = EnumPayTradeState.NOTPAY;

            _dataBase.Insert(orderEntity);

            CreatePayOrderResult depositPayResult = new CreatePayOrderResult();

            depositPayResult.PayOrderId = orderEntity.Id;
            depositPayResult.PrepayId   = unifiedOrderResult.ApiResult.PrepayId;
            result.Data    = depositPayResult;
            result.Success = true;
            return(result);
        }
예제 #19
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(PayOrderEntity payOrder)
 {
     return(PayOrderDA.Instance.ExistNum(payOrder) > 0);
 }
        internal NormalResult ProcessWeixinPayNotify(PayOrderEntity payOrder)
        {
            NormalResult result = new NormalResult(false);

            Guid orderGuid;

            if (String.IsNullOrEmpty(payOrder.OutTradeNo) || Guid.TryParse(payOrder.OutTradeNo, out orderGuid) == false)
            {
                result.Reason  = 6;
                result.Message = "OutTradeNo 不存在或无效。" + (payOrder.OutTradeNo == null ? String.Empty : payOrder.OutTradeNo);
                return(result);
            }

            PointCommodityOrderEntity order = GetOrder(orderGuid);

            if (order == null)
            {
                result.Reason  = 6;
                result.Message = "该积分商城订单不存在。";
                return(result);
            }

            if (order.ExpireTime <= DateTime.Now)
            {
                InsertOrderLog(order, 5);
                result.Reason  = 5;
                result.Message = "该积分商城订单已过期。";
                return(result);
            }

            if (order.Status != PointCommodityOrderStatus.NoPayment)
            {
                InsertOrderLog(order, 4);
                result.Reason  = 4;
                result.Message = "该积分商城订单状态不是待支付。";
                return(result);
            }

            result = Checkout(order);

            switch (result.Reason)
            {
            case 0:
                result.Message = "微信支付成功。";
                result.Success = true;
                break;

            case 1:
                result.Message = "积分不足。";
                break;

            case 2:
                result.Message = "账户余额不足。";
                break;

            case 4:
                result.Message = "该积分商城订单状态不是待支付。";
                break;

            case 5:
                result.Message = "该积分商城订单已过期。";
                break;

            case 6:
                result.Message = "该积分商城订单不存在。";
                break;

            default:
                result.Message = "未知错误。";
                break;
            }

            return(result);
        }
예제 #21
0
        public void ServiceSubmit(MeterRecord record, string imsi = "")
        {
            decimal balance = 0;

            //正在换表不记录数
            if (_readTaskApp.GetLastEntity((int)TaskTypeEnum.SetBaseDosage, record.MeterCode) != null)
            {
                return;
            }
            //获取表信息
            var meter = _meterApp.GetFormByMeterCode(record.MeterCode);

            if (meter == null)
            {
                return;
            }
            //表计倍率处理
            if (meter.F_MeterRate != null)
            {
                record.Value = (double.Parse(record.Value) * (double)meter.F_MeterRate).ToString(CultureInfo.InvariantCulture);
            }
            const int read       = (int)TaskTypeEnum.Read;
            const int task       = (int)TaskTypeEnum.Task;
            var       readTask   = _readTaskApp.GetLastEntity(task, record.MeterCode) ?? _readTaskApp.GetLastEntity(read, record.MeterCode);
            var       lastDosage = decimal.Parse(GetLastReadRecord(meter.F_Id, DateTime.Now));
            //本次用量
            var thisDosage = decimal.Parse(record.Value) - lastDosage;

            //过滤异常数据并加载到异常信息表内
            //if (lastDosage != 0 && (thisDosage > 2000 || thisDosage < -2000))
            if (1 > 1)
            {
                var readUnusualEntity = new ReadUnusualEntity()
                {
                    F_Id              = Common.GuId(),
                    F_CreatorTime     = DateTime.Now,
                    F_ErrorType       = ((int)ReadUnusualEnum.Read).ToString(),
                    F_MeterCode       = meter.F_MeterCode,
                    F_MeterType       = meter.F_MeterType,
                    F_Description     = meter.F_Description,
                    F_CustomerAddress = meter.F_CustomerAddress,
                    F_CustomerName    = meter.F_CustomerName,
                    F_Factor          = meter.F_Factor,
                    F_MobilePhone     = meter.F_MobilePhone,
                    F_OwnerId         = meter.F_OwnerId,
                    F_UserCard        = meter.F_UserCard,
                    F_Value           = thisDosage,
                };
                _readUnusualApp.SubmitForm(readUnusualEntity, "");
                return;
            }
            else
            {
                var readRecordEntity = new ReadRecordEntity
                {
                    F_TaskId      = readTask == null ? "" : readTask.F_Id,
                    F_ReadTime    = record.ReadingTime,
                    F_ArchiveId   = meter.F_Id,
                    F_ReadType    = readTask == null ? "-1" : readTask.F_TaskType.ToString(),
                    F_TotalDosage = decimal.Parse(record.Value),
                    F_CreatorTime = DateTime.Now,
                    F_Id          = Common.GuId(),
                    F_ThisDosage  = thisDosage,
                    F_Details     = record.Data == null ? "" : record.Data.ToJson(),
                    F_Settlement  = record.Settlement == null ? "" : record.Settlement.ToJson(),
                    F_Imsi        = imsi
                };
                ReadTaskEntity     controlTask        = null;
                PayOrderEntity     payOrderEntity     = null;
                ChargeRecordEntity chargeRecordEntity = null;
                MoneyAlarmEntity   moneyAlarmEntity   = null;
                //获取计费信息
                var meterCharging       = _meterChargingApp.GetForm(readRecordEntity.F_ArchiveId);
                var subsistenceCharging = _subsistenceSecurityApp.GetFormByArchiveId(readRecordEntity.F_ArchiveId);
                //0.判断表是否为IC卡预付费表
                //获取当前周期开始时间
                var cycleStartTime = _priceApp.GetCycleStartTime(subsistenceCharging != null && subsistenceCharging.F_PriceId != null ? subsistenceCharging.F_PriceId : meterCharging.F_PriceModel);
                //获取当前周期开始时间前一天最后一条抄表记录
                var cycleDosage = cycleStartTime == DateTime.MinValue
                    ? 0
                    : decimal.Parse(GetLastReadRecord(readRecordEntity.F_ArchiveId, cycleStartTime));
                //单位价格
                var uintPrice = _priceApp.GetPriceValue(subsistenceCharging != null && subsistenceCharging.F_PriceId != null ? subsistenceCharging.F_PriceId : meterCharging.F_PriceModel,
                                                        ((readRecordEntity.F_TotalDosage ?? 0) - cycleDosage).ToString(CultureInfo.InvariantCulture));
                if (meterCharging.F_MeterModel != "3")
                {
                    //扣费后的余额
                    balance = _meterChargingApp.UpdateBalance(readRecordEntity.F_ArchiveId, (readRecordEntity.F_ThisDosage ?? 0) * uintPrice);
                }
                else
                {
                    var count = _payOrderApp.GetPayOrderCount(record.MeterCode);
                    if (record.Data != null && record.Data.Keys.Contains("充值次数") && (count + 1).ToString() == record.Data["充值次数"])
                    {
                        payOrderEntity = _payOrderApp.GetLastPayOrder(record.MeterCode);
                        if (payOrderEntity != null)
                        {
                            payOrderEntity.F_State = "1";
                        }
                    }
                    if (record.Data != null && record.Data.Keys.Contains("余额"))
                    {
                        decimal money;
                        //上传的余额
                        balance = decimal.TryParse(record.Data["余额"], out money) ? _meterChargingApp.SetBalance(readRecordEntity.F_ArchiveId, money) : 0;
                    }
                }
                chargeRecordEntity = new ChargeRecordEntity
                {
                    F_ThisBill    = (readRecordEntity.F_ThisDosage ?? 0) * uintPrice,
                    F_ReadId      = readRecordEntity.F_Id,
                    F_UnitPrice   = uintPrice,
                    F_Description = "",
                    F_Balance     = balance,
                    F_ChargeTime  = DateTime.Now
                };
                //1.设备是否阀控,是否报警
                if (meterCharging.F_EnableClose == true && balance <= meterCharging.F_CloseAmount)
                {
                    //2. 判断设备类型+是否可以阀控
                    if (meter.F_MeterType == MeterTypeEnum.WattMeter.ToString()) //电表关阀命令
                    {
                        controlTask = new ReadTaskEntity
                        {
                            F_MeterCode   = meter.F_MeterCode,
                            F_Factor      = meter.F_Factor,
                            F_MeterType   = meter.F_MeterType,
                            F_State       = (int)TaskStateEnum.Wait,
                            F_Id          = Common.GuId(),
                            F_CreatorTime = DateTime.Now,
                            F_TaskType    = (int)TaskTypeEnum.TripSwitch
                        };
                    }
                    else //水表、燃气表、热表关阀命令
                    {
                        //判断是否应急或关阀状态
                        if (!IsEmergency(readRecordEntity))
                        {
                            controlTask = new ReadTaskEntity
                            {
                                F_MeterCode   = meter.F_MeterCode,
                                F_Factor      = meter.F_Factor,
                                F_MeterType   = meter.F_MeterType,
                                F_State       = (int)TaskStateEnum.Wait,
                                F_Id          = Common.GuId(),
                                F_CreatorTime = DateTime.Now,
                                F_TaskType    = (int)TaskTypeEnum.CloseValve
                            };
                        }
                    }
                }
                if (meterCharging.F_EnableClose == true && balance > meterCharging.F_CloseAmount)
                {
                    if (meter.F_MeterType == MeterTypeEnum.WattMeter.ToString()) //电表开阀命令
                    {
                        //电表充值自动开阀,不启用
                        //controlTask = new ReadTaskEntity
                        //{
                        //    F_MeterCode = meter.F_MeterCode,
                        //    F_Factor = meter.F_Factor,
                        //    F_MeterType = meter.F_MeterType,
                        //    F_State = (int)TaskStateEnum.Wait,
                        //    F_Id = Common.GuId(),
                        //    F_CreatorTime = DateTime.Now,
                        //    F_TaskType = (int)TaskTypeEnum.CloseSwitch
                        //};
                    }
                    else //水表、燃气表、热表开阀命令
                    {
                        //判断是否应急或关阀状态
                        if (IsEmergency(readRecordEntity))
                        {
                            controlTask = new ReadTaskEntity
                            {
                                F_MeterCode   = meter.F_MeterCode,
                                F_Factor      = meter.F_Factor,
                                F_MeterType   = meter.F_MeterType,
                                F_State       = (int)TaskStateEnum.Wait,
                                F_Id          = Common.GuId(),
                                F_CreatorTime = DateTime.Now,
                                F_TaskType    = (int)TaskTypeEnum.OpenValve
                            };
                        }
                    }
                }
                if (meterCharging.F_EnableAlarm == true && balance <= meterCharging.F_AlarmAmount)
                {
                    if (_moneyAlarmApp.IsCanSend(meter.F_Id))//判断是否可报警
                    {
                        var dataItems = (Dictionary <string, object>) new ItemsDetailApp().GetDataItemList();
                        var content   = SmsHelper.UrlEncode("#name#=" + meter.F_CustomerName + "&#time#=" + DateTime.Now.ToString("yyyy年MM月dd日") + "&#meter#=" + meter.F_CustomerAddress + ((Dictionary <string, string>)dataItems["DeviceType"])[meter.F_MeterType] + "&#balance#=" + balance.ToString("#0.00"));
                        var content2  = SmsHelper.UrlEncode("#name#=" + meter.F_CustomerName + "&#time#=" + DateTime.Now.ToString("yyyy年MM月dd日") + "&#meter#=" + ((Dictionary <string, string>)dataItems["DeviceType"])[meter.F_MeterType] + "&#balance#=" + balance.ToString("#0.00"));
                        moneyAlarmEntity = new MoneyAlarmEntity
                        {
                            F_Id          = Common.GuId(),
                            F_ArchiveId   = meter.F_Id,
                            F_AlarmMonry  = balance,
                            F_AlarmState  = (meter.F_OwnerId == "ff92def0-dabe-4878-915b-1b8cd0560ce4" && SmsHelper.Send(meter.F_MobilePhone, "58698", content, "c9eb4d0f54ad274842ef562d79f67e59")) || (meter.F_OwnerId == "bd602a97-eb06-4a5e-9c36-30eb45bc717b" && SmsHelper.Send(meter.F_MobilePhone, "96473", content2, "f73188115023c7e37955b095fefe0bb7")), //发送短信
                            F_SureState   = false,
                            F_CreatorTime = DateTime.Now,
                        };
                    }
                }
                else
                {
                    _moneyAlarmApp.SureAlarm(meter.F_Id);
                }
                //3.插入抄表信息、计费信息、阀控命令/报警命令
                _service.SubmitService(readRecordEntity, chargeRecordEntity, readTask, controlTask, payOrderEntity, moneyAlarmEntity);
            }
        }
예제 #22
0
        private NormalResult ProcessDonationPayNotify(PayOrderEntity payOrder)
        {
            FinishPayOrder(payOrder.Id);

            return(new NormalResult());
        }
예제 #23
0
        public ActionResult SubmitForm(string F_UserCard, string F_Money, string F_Recharge)
        {
            var companyId = OperatorProvider.Provider.GetCurrent().CompanyId;
            var meter     = _meterApp.GetFormByUserCard(F_UserCard, companyId);

            if (meter == null)
            {
                throw new Exception("用户卡不存在");
            }
            var meterCharging = _meterChargingApp.GetForm(meter.F_Id);

            meterCharging.F_Balance += decimal.Parse(F_Money);
            var payOrder = new PayOrderEntity
            {
                F_CreatorUserName = OperatorProvider.Provider.GetCurrent().UserName,
                F_State           = ((int)PayStateEnum.Wait).ToString(),
                F_Balance         = meterCharging.F_Balance,
                F_ArchiveId       = meter.F_Id,
                F_OrderNumber     = Common.CreateNo(),
                F_OutOrder        = "",
                F_Money           = decimal.Parse(F_Money),
                F_OwnerId         = companyId,
                F_PaymentTime     = DateTime.Now,
                F_PayType         = ((int)PayTypeEnum.BusinessPay).ToString()
            };
            ReadTaskEntity controlTask = null;

            if (meterCharging.F_MeterModel != ((int)MeterModelEnum.CardPrepay).ToString())//非IC卡预付费
            {
                payOrder.F_State = ((int)PayStateEnum.Finish).ToString();
                if (meter.F_MeterType == MeterTypeEnum.WattMeter.ToString() && meterCharging.F_EnableClose == true &&
                    meterCharging.F_Balance > meterCharging.F_CloseAmount) //电表合闸命令
                {
                    controlTask = new ReadTaskEntity
                    {
                        F_Id          = Common.GuId(),
                        F_CreatorTime = DateTime.Now,
                        F_MeterCode   = meter.F_MeterCode,
                        F_Factor      = meter.F_Factor,
                        F_MeterType   = meter.F_MeterType,
                        F_State       = (int)TaskStateEnum.Wait,
                        F_TaskType    = (int)TaskTypeEnum.CloseSwitch,
                    };
                }
            }
            else if (F_Recharge == ((int)RechargeEnum.Card).ToString())//IC卡预付费卡充值
            {
                payOrder.F_State = ((int)PayStateEnum.Write).ToString();
            }
            else//IC卡预付费互联网充值
            {
                payOrder.F_State = ((int)PayStateEnum.Wait).ToString();
                controlTask      = new ReadTaskEntity
                {
                    F_Id          = Common.GuId(),
                    F_CreatorTime = DateTime.Now,
                    F_MeterCode   = meter.F_MeterCode,
                    F_Factor      = meter.F_Factor,
                    F_MeterType   = meter.F_MeterType,
                    F_Param       = decimal.Parse(F_Money).ToString("0.00"),
                    F_State       = (int)TaskStateEnum.Wait,
                    F_TaskType    = (int)TaskTypeEnum.Pay,
                };
            }
            if (companyId == "bd602a97-eb06-4a5e-9c36-30eb45bc717b")//临朐清源充值确认
            {
                _moneyAlarmApp.SureAlarm(meter.F_Id);
            }
            _payOrderApp.SubmitForm(payOrder, meterCharging, controlTask);
            return(Success("操作成功。"));
        }
예제 #24
0
        public NormalResult Notify(string xml, AuthorizerPayConfig config)
        {
            _log.Write("收到支付结果通知", xml, TraceEventType.Verbose);

            NormalResult result = new NormalResult();

            WxPayArgs wxPayArgs = config.GetWxPayArgs(false);

            RequestPayApiResult <WeixinPayNotify> notifyResult = WxPayApi.Notify(xml, wxPayArgs);

            if (notifyResult.Success == false)
            {
                _log.Write("支付结果通知显示失败", notifyResult.Message, TraceEventType.Verbose);

                result.Success = false;
                result.Message = notifyResult.Message;
                return(result);
            }

            WeixinPayNotify notify = notifyResult.ApiResult;

            Guid payOrderId;

            if (Guid.TryParse(notify.Attach, out payOrderId) == false)
            {
                string attacth = String.Empty;
                if (notify.Attach != null)
                {
                    attacth = notify.Attach;
                }
                _log.Write("Attach 无法转为本地订单Id" + attacth, notify.OutTradeNo, TraceEventType.Verbose);
                result.Success = false;
                result.Message = "Attach 无法转为本地订单Id。" + attacth;
                return(result);
            }

            bool updateNotifyStatus = UpdateNotifyStatus(payOrderId);

            if (updateNotifyStatus == false)
            {
                //已经处理过了
                //处理过的还是返回true,防止微信服务器反复推送通知
                //微信文档上说通知频率为15/15/30/180/1800/1800/1800/1800/3600,单位:秒
                //但是实测支付成功后连续推送通知过来
                result.Success = true;
                result.Message = "已经接收到过此订单的支付通知。";
                return(result);
            }

            SqlStructureBuild sqlBuild = new SqlStructureBuild();

            sqlBuild.Table = "PayOrder";
            sqlBuild.Type  = SqlExpressionType.Update;
            sqlBuild.AddParameter("Id", payOrderId, true);
            sqlBuild.AddParameter("Notify", true);
            if (notify.ReturnCode == "SUCCESS" && notify.ResultCode == "SUCCESS")
            {
                sqlBuild.AddParameter("TradeState", EnumPayTradeState.SUCCESS);
            }
            else
            {
                sqlBuild.AddParameter("TradeState", EnumPayTradeState.PAYERROR);
            }
            sqlBuild.AddParameter("BankType", notify.BankType);
            sqlBuild.AddParameter("FeeType", notify.FeeType);
            sqlBuild.AddParameter("CouponFee", notify.CouponFee);
            sqlBuild.AddParameter("CouponCount", notify.CouponCount);
            sqlBuild.AddParameter("TransactionId", notify.TransactionId);
            sqlBuild.AddParameter("TimeEnd", WeixinApiHelper.ConvertStringToDateTime(notify.TimeEnd));
            sqlBuild.AddParameter("Notify_ReturnCode", notify.ReturnCode);
            sqlBuild.AddParameter("Notify_ReturnMsg", notify.ReturnMsg);
            sqlBuild.AddParameter("Notify_ResultCode", notify.ResultCode);
            sqlBuild.AddParameter("Notify_ErrCode", notify.ErrCode);
            sqlBuild.AddParameter("Notify_ErrCodeDes", notify.ErrCodeDes);
            int affectedRowCount = _dataBase.ExcuteSqlExpression(sqlBuild.GetSqlExpression());

            if (affectedRowCount == 0)
            {
                _log.Write("本地订单不存在", notify.OutTradeNo, TraceEventType.Verbose);
                result.Success = false;
                result.Message = "本地订单不存在。";
                return(result);
            }

            PayOrderEntity payOrder = GetPayOrder(payOrderId);

            if (notify.CouponCount > 0)
            {
                foreach (WeixinPayNotify_Coupon coupon in notify.CouponList)
                {
                    coupon.PayOrderId = payOrder.Id;
                    _dataBase.Insert(coupon);
                }
            }

            if (notify.ReturnCode == "SUCCESS" && notify.ResultCode == "SUCCESS")
            {
                switch (payOrder.Type)
                {
                case EnumPayOrderType.Unknow:
                    _log.Write("收到支付结果通知", "未知订单类型", TraceEventType.Warning);
                    break;

                case EnumPayOrderType.Deposit:
                    ProcessDepositPayNotify(payOrder);
                    break;

                case EnumPayOrderType.PointCommodity:
                    ProcessPointCommodityPayNotify(payOrder);
                    break;

                case EnumPayOrderType.Donation:
                    ProcessDonationPayNotify(payOrder);
                    break;

                default:
                    _log.Write("收到支付结果通知", "订单类型未处理:" + payOrder.Type.ToString(), TraceEventType.Warning);
                    break;
                }
            }

            //更新一下订单状态
            RefreshPayOrder(payOrder.OutTradeNo, config);

            result.Success = true;
            return(result);
        }
예제 #25
0
        public NormalResult RefreshPayOrder(string outTradeNo, AuthorizerPayConfig config)
        {
            NormalResult result = new NormalResult();

            if (config == null)
            {
                result.Success = false;
                result.Message = "当前公众号没有微信支付所需配置信息。";
                return(result);
            }

            WeixinPayOrderQueryArgs orderQueryArgs = new WeixinPayOrderQueryArgs();

            orderQueryArgs.AppId      = config.AppId;
            orderQueryArgs.MchId      = config.MchId;
            orderQueryArgs.OutTradeNo = outTradeNo;

            WxPayArgs wxPayArgs = config.GetWxPayArgs(false);

            RequestPayApiResult <WeixinPayOrderQueryResult> orderQueryResult =
                WxPayApi.OrderQuery(orderQueryArgs, wxPayArgs);

            if (orderQueryResult.Success == false)
            {
                _log.Write("OrderQuery 失败",
                           orderQueryResult.Message + "\r\n"
                           + JsonHelper.Serializer(orderQueryArgs) + " "
                           + JsonHelper.Serializer(orderQueryResult),
                           TraceEventType.Warning);

                result.Success = false;
                result.Message = orderQueryResult.Message;
                return(result);
            }

            WeixinPayOrderQueryResult orderQuery = orderQueryResult.ApiResult;

            Guid payOrderId;

            if (Guid.TryParse(orderQuery.Attach, out payOrderId) == false)
            {
                string attacth = String.Empty;
                if (orderQuery.Attach != null)
                {
                    attacth = orderQuery.Attach;
                }
                _log.Write("Attach 无法转为本地订单Id" + attacth, orderQuery.OutTradeNo, TraceEventType.Verbose);
                result.Success = false;
                result.Message = "Attach 无法转为本地订单Id。" + attacth;
                return(result);
            }

            PayOrderEntity payOrder = GetPayOrder(payOrderId);

            SqlStructureBuild sqlBuild = new SqlStructureBuild();

            sqlBuild.Table = "PayOrder";
            sqlBuild.Type  = SqlExpressionType.Update;
            sqlBuild.AddParameter("Id", payOrderId, true);
            sqlBuild.AddParameter("TradeState", EnumHelper.GetEnumFieldByValue <EnumPayTradeState>(orderQuery.TradeState));
            sqlBuild.AddParameter("TradeStateDesc", orderQuery.TradeStateDesc);
            sqlBuild.AddParameter("BankType", orderQuery.BankType);
            sqlBuild.AddParameter("FeeType", orderQuery.FeeType);
            sqlBuild.AddParameter("CouponFee", orderQuery.CouponFee);
            sqlBuild.AddParameter("CouponCount", orderQuery.CouponCount);
            sqlBuild.AddParameter("TransactionId", orderQuery.TransactionId);
            if (orderQuery.TimeEnd != null)
            {
                sqlBuild.AddParameter("TimeEnd", WeixinApiHelper.ConvertStringToDateTime(orderQuery.TimeEnd));
            }
            sqlBuild.AddParameter("Notify_ReturnCode", orderQuery.ReturnCode);
            sqlBuild.AddParameter("Notify_ReturnMsg", orderQuery.ReturnMsg);
            sqlBuild.AddParameter("Notify_ResultCode", orderQuery.ResultCode);
            sqlBuild.AddParameter("Notify_ErrCode", orderQuery.ErrCode);
            sqlBuild.AddParameter("Notify_ErrCodeDes", orderQuery.ErrCodeDes);
            int affectedRowCount = _dataBase.ExcuteSqlExpression(sqlBuild.GetSqlExpression());

            if (affectedRowCount == 0)
            {
                _log.Write("本地订单不存在", orderQuery.OutTradeNo, TraceEventType.Warning);
                result.Success = false;
                result.Message = "本地订单不存在。";
                return(result);
            }

            if (orderQuery.CouponCount > 0)
            {
                List <CommandParameter> parameterList = new List <CommandParameter>();
                parameterList.Add(new CommandParameter("@payOrderId", payOrder.Id));

                _dataBase.ExecuteNonQuery(
                    "DELETE FROM [PayOrderCoupon] WHERE [PayOrderId] = @payOrderId", parameterList);

                foreach (WeixinPayOrderQueryResult_Coupon coupon in orderQuery.CouponList)
                {
                    coupon.PayOrderId = payOrder.Id;
                    _dataBase.Insert(coupon);
                }
            }

            result.Success = true;
            return(result);
        }
예제 #26
0
 public void SubmitForm(PayOrderEntity payOrderEntity, MeterChargingEntity meterChargingEntity, ReadTaskEntity readTaskEntity)
 {
     payOrderEntity.Create();
     CheckEntity(payOrderEntity);
     _service.SubmitForm(payOrderEntity, meterChargingEntity, readTaskEntity);
 }
예제 #27
0
 public void SubmitService(ReadRecordEntity readRecordEntity, ChargeRecordEntity chargeRecordEntity, ReadTaskEntity readTaskEntity, ReadTaskEntity controlTask, PayOrderEntity payOrderEntity, MoneyAlarmEntity moneyAlarmEntity)
 {
     using (var db = new RepositoryBase().BeginTrans())
     {
         db.Insert(readRecordEntity);
         if (chargeRecordEntity != null)
         {
             db.Insert(chargeRecordEntity);
         }
         if (readTaskEntity != null)
         {
             readTaskEntity.F_State       = (int)TaskStateEnum.Finish;
             readTaskEntity.F_ExecuteTime = DateTime.Now;
             db.Update(readTaskEntity);
         }
         if (controlTask != null)
         {
             db.Insert(controlTask);
         }
         if (payOrderEntity != null)
         {
             db.Update(payOrderEntity);
         }
         if (moneyAlarmEntity != null)
         {
             db.Insert(moneyAlarmEntity);
         }
         db.Commit();
     }
 }