예제 #1
0
        public bool Pay()
        {
            Tnet_Recharge daRecharge = new Tnet_Recharge();

            if (!daRecharge.SelectByOrderNo(this._orderNo))
            {
                Alert("订单号不存在");
                return(false);
            }
            Currency rechargeCurrency = new Currency(CurrencyType.RMB, daRecharge.Amount);
            Currency diff             = rechargeCurrency - this._currency;
            decimal  absAmt           = Math.Abs(diff.ConvertTo(CurrencyType.RMB, 2).Amount);

            if (absAmt != 0)
            {
                Alert("支付金额与订单金额不匹配,差额:" + absAmt + "元");
                return(false);
            }
            int transferId;

            BeginTransaction();
            if (!DoRechargeTransfer(daRecharge.User_Id, rechargeCurrency, (eBankAccountType)daRecharge.Recharge_Type, daRecharge.Subject, out transferId))
            {
                Rollback();
                return(false);
            }
            var alter = new Dictionary <Tnet_RechargeCollection.Field, object>
            {
                { Tnet_RechargeCollection.Field.Deal_Time, DateTime.Now },
                { Tnet_RechargeCollection.Field.Pay_Status, (int)(this._isSuccess?OrderStatus.支付成功:OrderStatus.支付失败) },
                { Tnet_RechargeCollection.Field.Transfer_Id, transferId }
            };
            var condition = new Dictionary <Tnet_RechargeCollection.Field, object>
            {
                { Tnet_RechargeCollection.Field.Recharge_Id, daRecharge.Recharge_Id },
                { Tnet_RechargeCollection.Field.Pay_Status, (int)OrderStatus.等待支付 }
            };

            daRecharge.ReferenceTransactionFrom(Transaction);
            if (!daRecharge.Update(alter, condition))
            {
                Rollback();
                Alert("订单信息更新失败");
                return(false);
            }
            Commit();
            return(true);
        }
예제 #2
0
        public bool CreateOrder()
        {
            if (!xUtils.IsCashPayment(this._payType))
            {
                Alert("不支持的支付方式");
                return(false);
            }
            var   fac  = UserModuleFactory.GetUserModuleInstance();
            IUser user = fac?.GetUserByID(this._userId);

            if (user == null)
            {
                Alert("用户账号数据有误");
                return(false);
            }
            string subject = string.Concat(this._rechargeType.ToString(), "充值");

            BeginTransaction();
            Tnet_Recharge daRecharge = new Tnet_Recharge();

            daRecharge.ReferenceTransactionFrom(Transaction);
            daRecharge.Amount        = this._amount;
            daRecharge.Pay_Status    = (int)OrderStatus.等待支付;
            daRecharge.Pay_Type      = (int)this._payType;
            daRecharge.Recharge_Type = (int)this._rechargeType;
            daRecharge.User_Id       = this._userId;
            daRecharge.Subject       = subject;
            string orderNo;

            if (!daRecharge.Insert("R", out orderNo))
            {
                Rollback();
                Alert("创建订单失败");
                return(false);
            }

            Currency currency = new Currency(CurrencyType.RMB, this._amount);
            GpuQuickPaymentProvider provider = new GpuQuickPaymentProvider(user, subject, orderNo, currency, (GpuPayType)this._payType, TransferReason.充值金币, _notifyUrl);

            provider.SetPrivateValue(AppConfig.RECHARGE_PRIVATE_VALUE);
            GpuOrder order = provider.CreateOrder();

            if (order == null)
            {
                Rollback();
                Alert(provider.PromptInfo);
                return(false);
            }
            daRecharge.Voucher = order.Voucher;
            if (!daRecharge.Update())
            {
                Rollback();
                Alert("保存订单凭证失败");
                return(false);
            }
            Commit();
            this.Voucher = order.Voucher;
            this.Amount  = this._amount;
            this.OrderNo = orderNo;
            this.PayUrl  = order.PayUrl;
            return(true);
        }