Exemple #1
0
        private StackTradeResult TradeOneBuyOrder(StoneDelegateBuyOrderInfo buyOrder)
        {
            List <StoneDelegateSellOrderInfo> listTradeSucceedSellOrders = new List <StoneDelegateSellOrderInfo>();
            StackTradeResult buyOrderResult = TradeSell1Orders(buyOrder, listTradeSucceedSellOrders);

            if (buyOrderResult.State == StackTradeState.Failed)
            {
                return(buyOrderResult);
            }

            CustomerMySqlTransaction myTrans = null;

            try
            {
                myTrans = MyDBHelper.Instance.CreateTrans();
                foreach (var item in listTradeSucceedSellOrders)
                {
                    DBProvider.StoneStackDBProvider.SaveFinishedStoneDelegateSellOrderInfo(item);
                    PlayerController.Instance.PayDelegateBuyStonesUpdateSellerInfo(item, myTrans);
                }

                int selfSellHandCount = 0;
                foreach (var item in listTradeSucceedSellOrders)
                {
                    if (item.UserID == buyOrder.UserID)
                    {
                        selfSellHandCount += item.FinishedStoneTradeHandCount;
                    }
                }
                decimal allNeedRMB = (buyOrder.FinishedStoneTradeHandCount - selfSellHandCount) * buyOrder.BuyUnit.Price;
                buyOrder.AwardGoldCoin = (int)((allNeedRMB * GlobalConfig.GameConfig.StoneBuyerAwardGoldCoinMultiple) * GlobalConfig.GameConfig.RMB_GoldCoin);
                DBProvider.StoneStackDBProvider.SaveFinishedStoneDelegateBuyOrderInfo(buyOrder);
                PlayerController.Instance.PayDelegateBuyStonesUpdateBuyerInfo(buyOrder, myTrans);

                myTrans.Commit();

                //计算成交价
                this._todayTradeInfo.ComputeTradePrice(buyOrder.BuyUnit.Price, listTradeSucceedSellOrders[0].SellUnit.Price, buyOrder.FinishedStoneTradeHandCount);
                foreach (var item in listTradeSucceedSellOrders)
                {
                    AddLogNotifySeller(item);
                    LogHelper.Instance.AddInfoLog("委卖矿石交易成功:" + item.ToString());
                }
                AddLogNotifyBuyer(buyOrder);

                LogHelper.Instance.AddInfoLog("委买矿石交易成功:" + buyOrder.ToString());
            }
            catch (Exception exc)
            {
                LogHelper.Instance.AddErrorLog("ThreadStoneStackTrade.SaveStoneSellOrderHandler Exception", exc);
                myTrans.Rollback();
            }
            finally
            {
                myTrans.Dispose();
            }

            return(buyOrderResult);
        }
Exemple #2
0
        public int AlipayCallback(AlipayRechargeRecord alipayRecord)
        {
            int result = OperResult.RESULTCODE_FALSE;

            var alipayRecordFromDB = DBProvider.AlipayRecordDBProvider.GetAlipayRechargeRecordByOrderNumber_OR_Alipay_trade_no(alipayRecord.out_trade_no, alipayRecord.alipay_trade_no);

            if (alipayRecordFromDB != null)
            {
                return(OperResult.RESULTCODE_ORDER_BUY_SUCCEED);
            }

            StoneDelegateBuyOrderInfo buyOrder = null;

            lock (_lockTempAlipayList)
            {
                for (int i = 0; i < _listTempAlipayBuyOrders.Count; i++)
                {
                    if (_listTempAlipayBuyOrders[i].OrderNumber == alipayRecord.out_trade_no)
                    {
                        buyOrder = _listTempAlipayBuyOrders[i];
                        decimal valueRMB = buyOrder.BuyUnit.Price * buyOrder.BuyUnit.TradeStoneHandCount;
                        if (alipayRecord.value_rmb < valueRMB)
                        {
                            buyOrder.BuyState = StoneDelegateBuyState.Exception;
                            LogHelper.Instance.AddErrorLog(alipayRecord.ToString() + "  充值的灵币小于需要的灵币:" + valueRMB, null);
                        }
                        else
                        {
                            buyOrder.BuyState = StoneDelegateBuyState.Waiting;
                        }

                        this._listTempAlipayBuyOrders.RemoveAt(i);
                        break;
                    }
                }
            }

            if (buyOrder == null)
            {
                LogHelper.Instance.AddErrorLog("委托挂单购买矿石,支付宝回调,没有找到订单。" + alipayRecord.ToString(), null);
            }
            CustomerMySqlTransaction myTrans = MyDBHelper.Instance.CreateTrans();

            try
            {
                DBProvider.AlipayRecordDBProvider.SaveAlipayRechargeRecord(alipayRecord, myTrans);
                if (buyOrder != null)
                {
                    DBProvider.StoneStackDBProvider.UpdateWaitingStoneDelegateBuyOrderState(buyOrder.OrderNumber, buyOrder.BuyState, myTrans);
                }

                myTrans.Commit();

                result = OperResult.RESULTCODE_TRUE;
            }
            catch (Exception exc)
            {
                myTrans.Rollback();
                LogHelper.Instance.AddErrorLog("StoneStackControl.AlipayCallback.SaveAlipayRechargeRecord Exception. " + alipayRecord.ToString()
                                               + ". buyOrder: " + (buyOrder == null ? "NULL" : buyOrder.ToString()), exc);
            }
            finally
            {
                myTrans.Dispose();
            }

            if (result == OperResult.RESULTCODE_TRUE)
            {
                if (buyOrder != null)
                {
                    this.InsertToBuyQueue(buyOrder, null);
                }
                //PlayerActionController.Instance.AddLog(alipayRecord.user_name, MetaData.ActionLog.ActionType.DelegateBuyStone, buyOrder.BuyUnit.TradeStoneHandCount, "");
                BuyOrderAlipayPaySucceedNotify(alipayRecord.user_name, alipayRecord.out_trade_no);
            }

            return(result);
        }
Exemple #3
0
        public int CancelDelegateBuyStone(string token, MetaData.Game.StoneStack.StoneDelegateBuyOrderInfo buyOrder)
        {
            if (RSAProvider.LoadRSA(token))
            {
                string userName = "";
                try
                {
                    userName = ClientManager.GetClientUserName(token);
                    var playerRunner = PlayerController.Instance.GetRunnable(userName);
                    if (playerRunner == null)
                    {
                        return(OperResult.RESULTCODE_USER_NOT_EXIST);
                    }

                    StoneDelegateBuyOrderInfo canceledBuyOrder = null;
                    CustomerMySqlTransaction  myTrans          = MyDBHelper.Instance.CreateTrans();
                    try
                    {
                        var resultObj = OrderController.Instance.StoneStackController.PlayerCancelBuyStone(buyOrder.OrderNumber, buyOrder.BuyUnit.Price, myTrans, out canceledBuyOrder);
                        if (resultObj.OperResultCode != OperResult.RESULTCODE_TRUE)
                        {
                            return(resultObj.OperResultCode);
                        }
                        if (canceledBuyOrder == null)
                        {
                            return(OperResult.RESULTCODE_FALSE);
                        }
                        playerRunner.CancelDelegateBuyStoneOrder(canceledBuyOrder, myTrans);

                        myTrans.Commit();

                        LogHelper.Instance.AddInfoLog("玩家[" + userName + "], 撤消矿石委托买单。Order: " + canceledBuyOrder.ToString());
                        return(OperResult.RESULTCODE_TRUE);
                    }
                    catch (Exception exc)
                    {
                        myTrans.Rollback();
                        string errorMsg = "ServiceToClient.CancelDelegateBuyStone Exception userName: "******", buyOrder : " + buyOrder.ToString();
                        LogHelper.Instance.AddErrorLog(errorMsg, exc);
                        return(OperResult.RESULTCODE_FALSE);
                    }
                    finally
                    {
                        myTrans.Dispose();
                    }
                }
                catch (Exception exc)
                {
                    LogHelper.Instance.AddErrorLog("玩家[" + userName + "] DelegateSellStone Exception", exc);
                    return(OperResult.RESULTCODE_EXCEPTION);
                }
            }
            else
            {
                throw new Exception();
            }
        }
Exemple #4
0
        private void AddLogNotifyBuyer(StoneDelegateBuyOrderInfo buyOrder)
        {
            //PlayerActionController.Instance.AddLog(buyOrder.UserName, MetaData.ActionLog.ActionType.DelegateBuyStoneSucceed, buyOrder.FinishedStoneTradeHandCount * GlobalConfig.GameConfig.HandStoneCount, buyOrder.AwardGoldCoin.ToString());

            string tokenBuyer = ClientManager.GetToken(buyOrder.UserName);

            if (!string.IsNullOrEmpty(tokenBuyer))
            {
                if (DelegateStoneOrderTradeSucceedNotifyPlayer != null)
                {
                    DelegateStoneOrderTradeSucceedNotifyPlayer(tokenBuyer, buyOrder.OrderNumber, AlipayTradeInType.StackStoneBuy);
                    LogHelper.Instance.AddInfoLog("委托买单。订单号: " + buyOrder.OrderNumber + " 矿石交易成功,Order:" + buyOrder.ToString());
                }
            }
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="token"></param>
        /// <param name="buyStoneHandsCount"></param>
        /// <param name="price"></param>
        /// <param name="paytype"></param>
        /// <returns></returns>
        public OperResultObject DelegateBuyStone(string token, int buyStoneHandsCount, decimal price, MetaData.Trade.PayType paytype)
        {
            if (RSAProvider.LoadRSA(token))
            {
                OperResultObject resultObj = new OperResultObject();
                string           userName  = "";
                try
                {
                    if (buyStoneHandsCount <= 0)
                    {
                        resultObj.OperResultCode = OperResult.RESULTCODE_PARAM_INVALID;
                        return(resultObj);
                    }

                    userName = ClientManager.GetClientUserName(token);
                    var playerRunner = PlayerController.Instance.GetRunnable(userName);
                    if (playerRunner == null)
                    {
                        resultObj.OperResultCode = OperResult.RESULTCODE_USER_NOT_EXIST;
                        return(resultObj);
                    }

                    decimal allNeedRMB = buyStoneHandsCount * price;
                    if (paytype == MetaData.Trade.PayType.RMB)
                    {
                        if (playerRunner.BasePlayer.FortuneInfo.RMB < allNeedRMB)
                        {
                            resultObj.OperResultCode = OperResult.RESULTCODE_LACK_OF_BALANCE;
                            return(resultObj);
                        }
                    }
                    else if (paytype == MetaData.Trade.PayType.Diamand)
                    {
                        if (playerRunner.BasePlayer.FortuneInfo.StockOfDiamonds < allNeedRMB * GlobalConfig.GameConfig.Diamonds_RMB)
                        {
                            resultObj.OperResultCode = OperResult.RESULTCODE_LACK_OF_BALANCE;
                            return(resultObj);
                        }
                    }

                    DateTime timenow = DateTime.Now;
                    StoneDelegateBuyOrderInfo buyOrder = new StoneDelegateBuyOrderInfo()
                    {
                        UserID       = playerRunner.BasePlayer.SimpleInfo.UserID,
                        UserName     = playerRunner.BasePlayer.SimpleInfo.UserName,
                        DelegateTime = new MyDateTime(timenow),
                        OrderNumber  = OrderController.Instance.CreateOrderNumber(userName, timenow, MetaData.Trade.AlipayTradeInType.StackStoneBuy),
                        BuyState     = StoneDelegateBuyState.Waiting,
                        IsSubOrder   = false,
                        PayType      = paytype,
                        BuyUnit      = new StackTradeUnit()
                        {
                            Price = price,
                            TradeStoneHandCount = buyStoneHandsCount
                        }
                    };

                    if (paytype == MetaData.Trade.PayType.Alipay)
                    {
                        string payLink = OrderController.Instance.CreateAlipayLink(userName, buyOrder.OrderNumber, "矿石", allNeedRMB, "迅灵矿石");
                        buyOrder.AlipayLink = payLink;
                    }

                    CustomerMySqlTransaction myTrans = MyDBHelper.Instance.CreateTrans();
                    try
                    {
                        resultObj = OrderController.Instance.StoneStackController.PlayerDelegateBuyStone(buyOrder, myTrans);
                        if (resultObj.OperResultCode != OperResult.RESULTCODE_TRUE)
                        {
                            //卖单提交失败,不再进行数据库操作
                            return(resultObj);
                        }

                        playerRunner.AddNewBuyStonesByDelegate(buyOrder, myTrans);

                        myTrans.Commit();

                        if (paytype != MetaData.Trade.PayType.Alipay)
                        {
                            //PlayerActionController.Instance.AddLog(userName, MetaData.ActionLog.ActionType.DelegateBuyStone, buyStoneHandsCount, "");
                        }
                        LogHelper.Instance.AddInfoLog("玩家[" + userName + "] 挂单委托买入 " + buyStoneHandsCount + " 手矿石:" + buyOrder.ToString());

                        resultObj.OperResultCode = OperResult.RESULTCODE_TRUE;
                        resultObj.Message        = buyOrder.AlipayLink;

                        return(resultObj);
                    }
                    catch (Exception exc)
                    {
                        myTrans.Rollback();
                        LogHelper.Instance.AddErrorLog("ServiceToClient.DelegateBuyStone Exception userName: "******"玩家[" + userName + "] DelegateBuyStone Exception", exc);
                    resultObj.OperResultCode = OperResult.RESULTCODE_EXCEPTION;
                    return(resultObj);
                }
            }
            else
            {
                throw new Exception();
            }
        }