Ejemplo n.º 1
0
        /// <summary>
        /// 添加矿机运行分销拨款
        /// </summary>
        /// <param name="type"></param>
        /// <param name="borrowTransactions"></param>
        public static bool AddCloudMinerProduceDistribution(string type, int userId, int orderId, List <TransactionPayDetail> borrowTransactions)
        {
            TransactionInfo transactionInfo = new TransactionInfo();

            transactionInfo.No          = GetTransactionNo(type, userId);
            transactionInfo.Type        = type;
            transactionInfo.PayUserId   = 3;
            transactionInfo.PayeeUserId = userId;
            transactionInfo.OrderId     = orderId;
            //借方进账明细
            foreach (var item in borrowTransactions)
            {
                TransactionPayDetail borrowTransaction = new TransactionPayDetail();
                borrowTransaction.Amount     = item.Amount;
                borrowTransaction.CurrencyId = item.CurrencyId;
                transactionInfo.BorrowTransactions.Add(borrowTransaction);
            }
            //贷方支付明细
            foreach (var borrowTransaction in borrowTransactions)
            {
                TransactionPayDetail loansTransaction = new TransactionPayDetail();
                loansTransaction.Amount     = borrowTransaction.Amount;
                loansTransaction.CurrencyId = borrowTransaction.CurrencyId;
                //loansTransaction.LoansUserId = 3;
                transactionInfo.LoansTransactions.Add(loansTransaction);
            }

            transactionInfo.ExectionedAction = state =>
            {
                CloudMinerProductionDal.UpdateCloudMinerProductionRecord(orderId, state);
            };

            while (true)
            {
                if (TransactionQueue.AddQueue(transactionInfo))
                {
                    break;
                }
                Thread.Sleep(100);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加个人向个人转账订单
        /// </summary>
        public static bool AddTransactionB2C(string type, int payUserId, int payeeUserId, int orderId, List <TransactionPayDetail> transactionPayDetails)
        {
            TransactionInfo transactionInfo = new TransactionInfo();

            transactionInfo.No          = GetTransactionNo(type, payUserId);
            transactionInfo.Type        = type;
            transactionInfo.PayUserId   = payUserId;
            transactionInfo.PayeeUserId = payeeUserId;
            transactionInfo.OrderId     = orderId;

            //借方进账明细
            foreach (var item in transactionPayDetails)
            {
                TransactionPayDetail borrowTransaction = new TransactionPayDetail();
                borrowTransaction.Amount     = item.Amount;
                borrowTransaction.CurrencyId = item.CurrencyId;
                transactionInfo.BorrowTransactions.Add(borrowTransaction);
            }
            //贷方支付明细
            foreach (var borrowTransaction in transactionPayDetails)
            {
                TransactionPayDetail loansTransaction = new TransactionPayDetail();
                loansTransaction.Amount     = borrowTransaction.Amount;
                loansTransaction.CurrencyId = borrowTransaction.CurrencyId;
                transactionInfo.LoansTransactions.Add(loansTransaction);
            }

            transactionInfo.ExectionedAction = state =>
            {
                TransactionInfoDal.UpdateTransactionP2P(orderId, state);
            };
            while (true)
            {
                if (TransactionQueue.AddQueue(transactionInfo))
                {
                    break;
                }
                Thread.Sleep(100);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加商城自营交易
        /// </summary>
        /// <param name="payDetailModelGet"></param>
        /// <param name="countdownEvent"></param>
        /// <returns></returns>
        public static bool AddStoreOrder(PayDetailModelGet payDetailModelGet, CountdownEvent countdownEvent)
        {
            try
            {
                TransactionInfo transactionInfo = new TransactionInfo();
                transactionInfo.PayeeUserId = 5;
                DataTable dt = StoreOrderDal.QueryStoreOrderInfo(payDetailModelGet.OrderNo);
                if (dt.Rows.Count != 1)
                {
                    return(false);
                }
                decimal amount = Convert.ToDecimal(dt.Rows[0]["TotalPrice"]);
                if (amount != payDetailModelGet.PayDetailModels.Sum(n => n.Amount))
                {
                    StoreOrderDal.UpdateStoreOrderState(transactionInfo.OrderId, "5");
                    return(false);
                }
                transactionInfo.PayUserId = Convert.ToInt32(dt.Rows[0]["BuyUserId"]);
                int consignorUserId = Convert.ToInt32(dt.Rows[0]["ConsignorUserId"]);
                transactionInfo.Type = "00";

                transactionInfo.OrderId = Convert.ToInt32(dt.Rows[0]["Id"]);
                int commodityId = Convert.ToInt32(dt.Rows[0]["CommodityId"]);
                int count       = Convert.ToInt32(dt.Rows[0]["Count"]);
                if (count < 1)
                {
                    throw new Exception("订单中云矿机数量有误 OrderId:" + transactionInfo.OrderId);
                }

                transactionInfo.No = GetTransactionNo(transactionInfo.Type, payDetailModelGet.UserId);
                transactionInfo.ExectionedAction += (state) =>
                {
                    StoreOrderDal.UpdateStoreOrderState(transactionInfo.OrderId, state);
                    if (state == "1")
                    {
                        UserCloudMinerDal.InsertUserCloudMiner(transactionInfo.OrderId, payDetailModelGet.OrderNo,
                                                               transactionInfo.No, consignorUserId, commodityId, count);
                        foreach (var item in payDetailModelGet.PayDetailModels)
                        {
                            StoreOrderDal.InsertPayDetail(transactionInfo.OrderId, item.CurrencyId, item.Amount);
                        }
                        DataTable dtUserVipInfo = UserInfoDal.QueryUserVipInfo(consignorUserId);
                        if (dtUserVipInfo.Rows.Count == 1)
                        {
                            //用户当前的VIP等级
                            int       userRank = Convert.ToInt32(dtUserVipInfo.Rows[0]["Rank"]);
                            DataTable dtVipUrCloudminerInfo = VipInfoDal.QueryVipUrCloudminerUpgrade(commodityId);
                            if (dtVipUrCloudminerInfo.Rows.Count <= 0)
                            {
                                return;
                            }
                            int commodityUrRank = Convert.ToInt32(dtVipUrCloudminerInfo.Rows[0]["Rank"]);
                            if (userRank < commodityUrRank)
                            {
                                int commodityUrVipId = Convert.ToInt32(dtVipUrCloudminerInfo.Rows[0]["Id"]);
                                UserInfoDal.UpdateUserVip(consignorUserId, commodityUrVipId);
                            }
                        }
                    }
                    if (countdownEvent != null)
                    {
                        countdownEvent.Signal();
                    }
                };

                foreach (var item in payDetailModelGet.PayDetailModels)
                {
                    TransactionPayDetail loansTransaction = new TransactionPayDetail();
                    loansTransaction.CurrencyId = item.CurrencyId;
                    loansTransaction.Amount     = item.Amount;
                    transactionInfo.LoansTransactions.Add(loansTransaction);
                    TransactionPayDetail borrowTransaction = new TransactionPayDetail();
                    borrowTransaction.CurrencyId = item.CurrencyId;
                    borrowTransaction.Amount     = item.Amount;
                    transactionInfo.BorrowTransactions.Add(borrowTransaction);
                }
                if (TransactionQueue.AddQueue(transactionInfo))
                {
                    StoreOrderDal.UpdateStoreOrderState(transactionInfo.OrderId, "4");
                    return(true);
                }
                return(false);
            }
            catch (Exception exception)
            {
                LogHelper.error("添加支付订单时错误:" + exception.Message);
                return(false);
            }
        }
        /// <summary>
        /// 商户对个人交易
        /// </summary>
        /// <param name="modelGet"></param>
        /// <returns></returns>
        public IHttpActionResult TransactionB2C(TransactionB2CModelGet modelGet)
        {
            if (string.IsNullOrEmpty(modelGet.PayOpenId) || string.IsNullOrEmpty(modelGet.PayeeOpenId) || string.IsNullOrEmpty(modelGet.ExternalOrderNo) ||
                string.IsNullOrEmpty(modelGet.ExternalOrderName) || string.IsNullOrEmpty(modelGet.ExternalOrderType))
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = 4010, Messages = "数据参数有误",
                }));
            }

            if (modelGet.PayCurrencyList.Count(n => n.Amount <= 0) > 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "交易金额有误,通证数量不能小于等于0",
                }));
            }
            if (modelGet.PayCurrencyList.Count(n => n.Amount * 0.1M != n.ServiceCharge) > 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "转账通证数量不能小于等于0",
                }));
            }
            //检查付款账号是否存在
            DataTable dtPayAuthorizeUserInfo = _authorizeUserInfoDal.QueryCommodityInfo(modelGet.AppId, modelGet.PayOpenId);
            IList <AuthorizeUserInfoModelGet> listPayAuthorizeUserInfo =
                ModelConvertHelper <AuthorizeUserInfoModelGet> .ConvertToModel(dtPayAuthorizeUserInfo);

            AuthorizeUserInfoModelGet authorizePayUserInfoModelGet = listPayAuthorizeUserInfo.FirstOrDefault(n => n.State == "0");

            if (authorizePayUserInfoModelGet == null)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "付款账户未绑定个人钱包",
                }));
            }
            //检查收款账户是否存在
            DataTable dtPayeeAuthorizeUserInfo = _authorizeUserInfoDal.QueryCommodityInfo(modelGet.AppId, modelGet.PayeeOpenId);
            IList <AuthorizeUserInfoModelGet> listPayeeAuthorizeUserInfo = ModelConvertHelper <AuthorizeUserInfoModelGet> .ConvertToModel(dtPayeeAuthorizeUserInfo);

            AuthorizeUserInfoModelGet authorizePayeeUserInfoModelGet = listPayeeAuthorizeUserInfo.FirstOrDefault(n => n.State == "0");;

            if (authorizePayeeUserInfoModelGet == null)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "收款账户未绑定个人钱包",
                }));
            }
            //检查付款方是否实名认证
            string idCard = _userInfoDal.CheckBindIdCard(authorizePayUserInfoModelGet.UserId);

            if (string.IsNullOrEmpty(idCard))
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = 4204, Messages = "付款账号未实名认证,请先提交实名认证",
                }));
            }
            //检查支付密码是否正确
            bool checkPayPassword = _userInfoDal.CheckPayPassowrd(authorizePayeeUserInfoModelGet.UserId, modelGet.PayPassword);

            if (!checkPayPassword)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4106, Messages = "支付密码错误"
                }));
            }
            //不能给自己转账
            if (authorizePayUserInfoModelGet.UserId == authorizePayeeUserInfoModelGet.UserId)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4303, Messages = "不能转账给自己"
                }));
            }
            //查询用户钱包
            DataTable dtWalletInfo = _walletInfoDal.QueryWalletInfo(authorizePayUserInfoModelGet.UserId);
            IList <WalletInfoModelResult> currencyInfoModelResults =
                ModelConvertHelper <WalletInfoModelResult> .ConvertToModel(dtWalletInfo);

            if (currencyInfoModelResults.Count <= 0)
            {
                LogHelper.error("P2P交易时,查询用户钱包信息失败");
                throw new Exception();
            }
            //检查余额
            foreach (var item in modelGet.PayCurrencyList)
            {
                var first = currencyInfoModelResults.FirstOrDefault(n => n.CurrencyId == item.CurrencyId);

                if (first == null)
                {
                    continue;
                }
                decimal amount = first.CanUseAmount;
                if (amount < item.Amount + item.Amount * 0.5M)
                {
                    return(Json(new ResultDataModel <StoreOrderModelResult> {
                        Code = 4302, Messages = "余额不足"
                    }));
                }
            }
            //获取支付金额
            string orderNo = GetTransactionNo("01", authorizePayUserInfoModelGet.UserId);
            List <TransactionServerDal.PayCurrencyEntity> payCurrencyEntities = new List <TransactionServerDal.PayCurrencyEntity>();
            List <TransactionPayDetail> transactionPayDetails = new List <TransactionPayDetail>();

            foreach (var model in modelGet.PayCurrencyList)
            {
                TransactionServerDal.PayCurrencyEntity payCurrencyEntity = new TransactionServerDal.PayCurrencyEntity();
                payCurrencyEntity.Amount     = model.Amount;
                payCurrencyEntity.CurrencyId = model.CurrencyId;
                payCurrencyEntities.Add(payCurrencyEntity);

                TransactionPayDetail transactionPayDetail = new TransactionPayDetail();
                transactionPayDetail.Amount     = model.Amount;
                transactionPayDetail.CurrencyId = model.CurrencyId;
                transactionPayDetails.Add(transactionPayDetail);
            }
            //添加B2C交易订单
            int orderId = _transactionInfoDal.CreateTransactionB2C(orderNo, authorizePayUserInfoModelGet.UserId, authorizePayeeUserInfoModelGet.UserId, modelGet.Remark, payCurrencyEntities);

            if (orderId <= 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult>()
                {
                    Code = -1,
                    Messages = "当前服务器繁忙,请您稍后再试!",
                    Data = new TransactionP2PModelResult()
                    {
                        OrderNo = ""
                    }
                }));
            }

            //将订单添加到交易服务并执行交易
            bool reslut = TransactionService.AddTransactionB2C("02", authorizePayUserInfoModelGet.UserId, authorizePayeeUserInfoModelGet.UserId, orderId, transactionPayDetails);

            return(Json(new ResultDataModel <TransactionP2PModelResult>()
            {
                Code = reslut ? 0 : -1,
                Messages = reslut ? "" : "当前服务器繁忙,请您稍后再试!",
                Data = new TransactionP2PModelResult()
                {
                    OrderId = orderId,
                    OrderNo = orderNo,
                    OrderTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                }
            }));

            return(Json(new object()));
        }
        /// <summary>
        /// 个人对个人交易
        /// </summary>
        /// <param name="modelGet"></param>
        /// <returns></returns>
        public IHttpActionResult TransactionP2P(TransactionP2PModelGet modelGet)
        {
            if (modelGet.PayUserId <= 0 || string.IsNullOrEmpty(modelGet.PayeeWalletAddress) || string.IsNullOrEmpty(modelGet.PayPassword) || modelGet.PayCurrencyList.Count <= 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = 4010, Messages = "数据参数有误",
                }));
            }
            if (modelGet.PayCurrencyList.Count(n => n.Amount <= 0) > 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "转账通证数量不能小于等于0",
                }));
            }
            if (modelGet.PayCurrencyList.Count(n => n.ServiceCharge <= 0) > 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "转账手续费通证数量有误"
                }));
            }
            if (modelGet.PayCurrencyList.Count(n => n.Amount * 0.1M != n.ServiceCharge) > 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = -1, Messages = "转账通证数量不能小于等于0",
                }));
            }
            string idCard = _userInfoDal.CheckBindIdCard(modelGet.PayUserId);

            if (string.IsNullOrEmpty(idCard))
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult> {
                    Code = 4204, Messages = "该账号未实名认证,请先提交实名认证",
                }));
            }
            bool checkPayPassword = _userInfoDal.CheckPayPassowrd(modelGet.PayUserId, modelGet.PayPassword);

            if (!checkPayPassword)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4106, Messages = "支付密码错误"
                }));
            }
            int payeeUserId = _userInfoDal.QueryUserIdByWalletAddress(modelGet.PayeeWalletAddress);

            if (payeeUserId == 0)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4304, Messages = "钱包地址不存在"
                }));
            }
            if (payeeUserId < 0)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4001, Messages = "服务器繁忙,请稍后再试"
                }));
            }
            DataTable dtWalletInfo = _walletInfoDal.QueryWalletInfo(modelGet.PayUserId);
            IList <WalletInfoModelResult> currencyInfoModelResults =
                ModelConvertHelper <WalletInfoModelResult> .ConvertToModel(dtWalletInfo);

            if (currencyInfoModelResults.Count <= 0)
            {
                LogHelper.error("P2P交易时,检测用户钱包信息失败");
                throw new Exception();
            }
            foreach (var item in modelGet.PayCurrencyList)
            {
                var first = currencyInfoModelResults.FirstOrDefault(n => n.CurrencyId == item.CurrencyId);
                if (first == null)
                {
                    continue;
                }
                decimal amount = first.CanUseAmount;
                if (amount < item.Amount + item.Amount * 0.1M)
                {
                    return(Json(new ResultDataModel <StoreOrderModelResult> {
                        Code = 4302, Messages = "余额不足"
                    }));
                }
            }
            if (currencyInfoModelResults.First().WalletAddress == modelGet.PayeeWalletAddress)
            {
                return(Json(new ResultDataModel <StoreOrderModelResult> {
                    Code = 4303, Messages = "收款账户不能为当前登录账户"
                }));
            }

            string orderNo = GetTransactionNo("02", modelGet.PayUserId);
            List <TransactionServerDal.PayCurrencyEntity> payCurrencyEntities = new List <TransactionServerDal.PayCurrencyEntity>();
            List <TransactionPayDetail> transactionPayDetails = new List <TransactionPayDetail>();

            foreach (var model in modelGet.PayCurrencyList)
            {
                TransactionServerDal.PayCurrencyEntity payCurrencyEntity = new TransactionServerDal.PayCurrencyEntity();
                payCurrencyEntity.Amount     = model.Amount;
                payCurrencyEntity.CurrencyId = model.CurrencyId;
                payCurrencyEntities.Add(payCurrencyEntity);

                TransactionPayDetail transactionPayDetail = new TransactionPayDetail();
                transactionPayDetail.Amount     = model.Amount;
                transactionPayDetail.CurrencyId = model.CurrencyId;
                transactionPayDetails.Add(transactionPayDetail);
            }

            //添加P2P交易订单
            int orderId = _transactionInfoDal.CreateTransactionP2P(orderNo, modelGet.PayUserId, payeeUserId, modelGet.Remark, payCurrencyEntities);

            if (orderId <= 0)
            {
                return(Json(new ResultDataModel <TransactionP2PModelResult>()
                {
                    Code = -1,
                    Messages = "当前服务器繁忙,请您稍后再试!",
                    Data = new TransactionP2PModelResult()
                    {
                        OrderNo = ""
                    }
                }));
            }

            //将订单添加到交易服务并执行交易
            bool reslut = TransactionService.AddTransactionP2P("02", modelGet.PayUserId, payeeUserId, orderId, transactionPayDetails);

            return(Json(new ResultDataModel <TransactionP2PModelResult>()
            {
                Code = reslut ? 0 : -1,
                Messages = reslut ? "" : "当前服务器繁忙,请您稍后再试!",
                Data = new TransactionP2PModelResult()
                {
                    OrderId = orderId,
                    OrderNo = orderNo,
                    OrderTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                }
            }));
        }