public StoneDelegateBuyOrderInfo DeleteOrder(string orderNumber) { StoneDelegateBuyOrderInfo sellOrder = null; lock (_lockList) { if (ListOrders.Count > 0) { int index = -1; for (int i = 0; i < ListOrders.Count; i++) { if (ListOrders[i].OrderNumber == orderNumber) { index = i; break; } } if (index >= 0) { sellOrder = ListOrders[index]; ListOrders.RemoveAt(index); } } } return(sellOrder); }
public void Enqueue(StoneDelegateBuyOrderInfo sellOrder) { lock (_lockList) { ListOrders.Add(sellOrder); } }
private void InsertToBuyQueue(StoneDelegateBuyOrderInfo item, CustomerMySqlTransaction myTrans) { //需要分别处理Waiting和Splited两种情况 if (item.BuyState != StoneDelegateBuyState.Waiting && item.BuyState != StoneDelegateBuyState.Splited) { return; } int index = this._todayTradeInfo.InsertBuyUnit(item.BuyUnit); ListStoneDelegateBuyOrderInfoCollection queueBuy = null; if (_dicWaitingBuyInfos.ContainsKey(item.BuyUnit.Price)) { queueBuy = _dicWaitingBuyInfos[item.BuyUnit.Price]; } else { queueBuy = new ListStoneDelegateBuyOrderInfoCollection(); _dicWaitingBuyInfos[item.BuyUnit.Price] = queueBuy; } queueBuy.Enqueue(item); if (myTrans != null) { DBProvider.StoneStackDBProvider.SaveWaitingStoneDelegateBuyOrderInfo(item, myTrans); } }
/// <summary> /// 付款方式为支付宝的订单,添加到临时集合中 /// </summary> /// <param name="buyOrder"></param> /// <returns></returns> public OperResultObject PlayerDelegateBuyStone(StoneDelegateBuyOrderInfo buyOrder, CustomerMySqlTransaction myTrans) { OperResultObject result = new OperResultObject(); //只有开市期间才可挂单,间休期间暂时也不可挂单 if (this._todayTradeInfo.MarketState != StackMarketState.Opening) { result.OperResultCode = OperResult.RESULTCODE_STACK_DELEGATEORDER_FAILED_MARKETISCLOSED; return(result); } if (buyOrder.PayType == PayType.Alipay) { //也要保存到数据库里 buyOrder.BuyState = StoneDelegateBuyState.NotPayed; DBProvider.StoneStackDBProvider.SaveWaitingStoneDelegateBuyOrderInfo(buyOrder, myTrans); lock (_lockTempAlipayList) { this._listTempAlipayBuyOrders.Add(buyOrder); } } else { InsertToBuyQueue(buyOrder, myTrans); } result.OperResultCode = OperResult.RESULTCODE_TRUE; return(result); }
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); }
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(); } }
public void AsyncCancelDelegateBuyStoneOrder(StoneDelegateBuyOrderInfo buyOrder) { if (GlobalData.Client == null || !GlobalData.Client.IsEnable) { return; } App.BusyToken.ShowBusyWindow("正在提交数据..."); GlobalData.Client.CancelDelegateBuyStone(buyOrder, null); }
/// <summary> /// 保存到完成表 /// </summary> /// <param name="buyOrder"></param> /// <returns></returns> public bool SaveFinishedStoneDelegateBuyOrderInfo(StoneDelegateBuyOrderInfo buyOrder) { MySqlConnection myconn = MyDBHelper.Instance.CreateConnection(); MySqlCommand mycmd = null; try { mycmd = myconn.CreateCommand(); string cmdTextA = "insert into finishedstonedelegatebuyorderinfo " + "(`OrderNumber`, `UserID`, `Price`, `TradeStoneHandCount`, `PayType`, `FinishedStoneTradeHandCount`, `BuyState`, `DelegateTime`, `IsSubOrder`, `ParentOrderNumber`, `FinishedTime`, `AwardGoldCoin` ) " + " values " + "(@OrderNumber, @UserID, @Price, @TradeStoneHandCount, @PayType, @FinishedStoneTradeHandCount, @BuyState, @DelegateTime, @IsSubOrder, @ParentOrderNumber, @FinishedTime, @AwardGoldCoin); "; string cmdTextB = "delete from notfinishedstonedelegatebuyorderinfo where `OrderNumber` = @OrderNumber ;"; mycmd.CommandText = cmdTextA + cmdTextB; mycmd.Parameters.AddWithValue("@OrderNumber", buyOrder.OrderNumber); mycmd.Parameters.AddWithValue("@UserID", buyOrder.UserID); mycmd.Parameters.AddWithValue("@Price", buyOrder.BuyUnit.Price); mycmd.Parameters.AddWithValue("@TradeStoneHandCount", buyOrder.BuyUnit.TradeStoneHandCount); mycmd.Parameters.AddWithValue("@PayType", (int)buyOrder.PayType); mycmd.Parameters.AddWithValue("@FinishedStoneTradeHandCount", buyOrder.FinishedStoneTradeHandCount); mycmd.Parameters.AddWithValue("@BuyState", (int)buyOrder.BuyState); mycmd.Parameters.AddWithValue("@DelegateTime", buyOrder.DelegateTime.ToDateTime()); mycmd.Parameters.AddWithValue("@IsSubOrder", buyOrder.IsSubOrder); if (buyOrder.ParentOrderNumber == null) { mycmd.Parameters.AddWithValue("@ParentOrderNumber", DBNull.Value); } else { mycmd.Parameters.AddWithValue("@ParentOrderNumber", buyOrder.ParentOrderNumber); } mycmd.Parameters.AddWithValue("@FinishedTime", buyOrder.FinishedTime.ToDateTime()); mycmd.Parameters.AddWithValue("@AwardGoldCoin", buyOrder.AwardGoldCoin); myconn.Open(); mycmd.ExecuteNonQuery(); return(true); } finally { if (mycmd != null) { mycmd.Dispose(); } MyDBHelper.Instance.DisposeConnection(myconn); } }
public StoneDelegateBuyOrderInfo Dequeue() { StoneDelegateBuyOrderInfo buyOrder = null; lock (_lockList) { if (ListOrders.Count > 0) { buyOrder = ListOrders[0]; ListOrders.RemoveAt(0); } } return(buyOrder); }
private StackTradeResult TradeSell1Orders(StoneDelegateBuyOrderInfo buyOrder, List <StoneDelegateSellOrderInfo> listTradeSucceedSellOrders) { StackTradeResult buyOrderResult = new StackTradeResult(); decimal buyPrice = buyOrder.BuyUnit.Price; StackTradeUnit buyUnit = new StackTradeUnit() { Price = buyOrder.BuyUnit.Price, TradeStoneHandCount = buyOrder.BuyUnit.TradeStoneHandCount }; //只处理卖1 var sellUnit = this._todayTradeInfo.GetSell1Unit(); if (sellUnit == null) { return(buyOrderResult); } if (sellUnit.TradeStoneHandCount == 0 || !this._dicWaitingSellInfos.ContainsKey(sellUnit.Price) || this._dicWaitingSellInfos[sellUnit.Price] == null) { return(buyOrderResult); } if (buyPrice >= sellUnit.Price) { //成交,按量处理 buyOrderResult = TradeSamePriceSellOrder(sellUnit.Price, this._dicWaitingSellInfos[sellUnit.Price], listTradeSucceedSellOrders, buyUnit, buyOrder.UserName); if (buyOrderResult.State == StackTradeState.Succeed) { //买单 被全部消化 //暂时不清理卖单集合,被拆分的卖单,剩余部分在外部会重新加回卖单集合 buyOrder.BuyState = StoneDelegateBuyState.Succeed; buyOrder.FinishedStoneTradeHandCount = buyOrder.BuyUnit.TradeStoneHandCount; buyOrder.FinishedTime = new MyDateTime(DateTime.Now); } else if (buyOrderResult.State == StackTradeState.Splited) { //买单没有被全部消化,需要再对比处理上一级卖价。等所有卖价都对比完时,再返回 buyUnit.TradeStoneHandCount -= buyOrderResult.SucceedStoneHandCount; buyOrder.BuyState = StoneDelegateBuyState.Splited; buyOrder.FinishedStoneTradeHandCount = buyOrder.BuyUnit.TradeStoneHandCount - buyUnit.TradeStoneHandCount; buyOrder.FinishedTime = new MyDateTime(DateTime.Now); } } return(buyOrderResult); }
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()); } } }
/// <summary> /// 保存到未完成表 /// </summary> /// <param name="buyOrder"></param> /// <returns></returns> public bool SaveWaitingStoneDelegateBuyOrderInfo(StoneDelegateBuyOrderInfo buyOrder, CustomerMySqlTransaction myTrans) { MySqlCommand mycmd = null; try { mycmd = myTrans.CreateCommand(); string cmdTextA = "insert into notfinishedstonedelegatebuyorderinfo " + "(`OrderNumber`, `UserID`, `Price`, `TradeStoneHandCount`, `PayType`, `FinishedStoneTradeHandCount`, `BuyState`, `DelegateTime`, `IsSubOrder`, `ParentOrderNumber`, `AlipayLink` ) " + " values " + "(@OrderNumber, @UserID, @Price, @TradeStoneHandCount, @PayType, @FinishedStoneTradeHandCount, @BuyState, @DelegateTime, @IsSubOrder, @ParentOrderNumber, @AlipayLink ); "; mycmd.CommandText = cmdTextA; mycmd.Parameters.AddWithValue("@OrderNumber", buyOrder.OrderNumber); mycmd.Parameters.AddWithValue("@UserID", buyOrder.UserID); mycmd.Parameters.AddWithValue("@Price", buyOrder.BuyUnit.Price); mycmd.Parameters.AddWithValue("@TradeStoneHandCount", buyOrder.BuyUnit.TradeStoneHandCount); mycmd.Parameters.AddWithValue("@PayType", (int)buyOrder.PayType); mycmd.Parameters.AddWithValue("@FinishedStoneTradeHandCount", buyOrder.FinishedStoneTradeHandCount); mycmd.Parameters.AddWithValue("@BuyState", (int)buyOrder.BuyState); mycmd.Parameters.AddWithValue("@DelegateTime", buyOrder.DelegateTime.ToDateTime()); mycmd.Parameters.AddWithValue("@IsSubOrder", buyOrder.IsSubOrder); if (buyOrder.ParentOrderNumber == null) { mycmd.Parameters.AddWithValue("@ParentOrderNumber", DBNull.Value); } else { mycmd.Parameters.AddWithValue("@ParentOrderNumber", buyOrder.ParentOrderNumber); } mycmd.Parameters.AddWithValue("@AlipayLink", buyOrder.AlipayLink == null ? DBNull.Value : (object)buyOrder.AlipayLink); mycmd.ExecuteNonQuery(); return(true); } finally { if (mycmd != null) { mycmd.Dispose(); } } }
/// <summary> /// 保存到未完成表 /// </summary> /// <param name="buyOrder"></param> /// <returns></returns> public bool SaveWaitingStoneDelegateBuyOrderInfo(StoneDelegateBuyOrderInfo buyOrder) { CustomerMySqlTransaction myTrans = MyDBHelper.Instance.CreateTrans(); try { SaveWaitingStoneDelegateBuyOrderInfo(buyOrder, myTrans); myTrans.Commit(); return(true); } catch (Exception exc) { myTrans.Rollback(); throw exc; } finally { if (myTrans != null) { myTrans.Dispose(); } } }
public void CancelDelegateBuyStone(StoneDelegateBuyOrderInfo buyOrder, object userState) { this._invoker.InvokeUserState <int>(this._context, "CancelDelegateBuyStone", this.CancelDelegateBuyStoneCompleted, userState, GlobalData.Token, buyOrder); }
private void TradeBuy1Orders() { var buy1Unit = this._todayTradeInfo.GetBuy1Unit(); if (buy1Unit == null) { return; } decimal buyPrice = buy1Unit.Price; if (buy1Unit.TradeStoneHandCount == 0 || !this._dicWaitingBuyInfos.ContainsKey(buyPrice) || this._dicWaitingBuyInfos[buyPrice] == null) { return; } //循环取出买价对应的买单 StoneDelegateBuyOrderInfo buyOrder = this._dicWaitingBuyInfos[buyPrice].Dequeue(); while (buyOrder != null) { int FinishedStoneHandCount = 0; if (buyOrder.BuyState == StoneDelegateBuyState.Waiting) { var result = TradeOneBuyOrder(buyOrder); if (result.State == StackTradeState.Failed) { //没有找到价格合适的卖单,把买单再加回集合中. this._dicWaitingBuyInfos[buyPrice].Enqueue(buyOrder); break; } else if (result.State == StackTradeState.Succeed) { FinishedStoneHandCount += buyOrder.FinishedStoneTradeHandCount; } else if (result.State == StackTradeState.Splited) { DateTime nowtime = DateTime.Now; //此时,卖1订单已经全部被吞掉。而当前买单没有消化完,需要将剩余部分拆分,拆分后的订单保存到数据库,并添加到集合中 StoneDelegateBuyOrderInfo newBuyOrder = new StoneDelegateBuyOrderInfo() { UserID = buyOrder.UserID, IsSubOrder = true, BuyState = StoneDelegateBuyState.Waiting, OrderNumber = OrderController.Instance.CreateOrderNumber(buyOrder.UserName, nowtime, AlipayTradeInType.StackStoneBuy), ParentOrderNumber = buyOrder.IsSubOrder ? buyOrder.ParentOrderNumber : buyOrder.OrderNumber, UserName = buyOrder.UserName, PayType = buyOrder.PayType, DelegateTime = new MyDateTime(nowtime), BuyUnit = new StackTradeUnit() { Price = buyOrder.BuyUnit.Price, TradeStoneHandCount = buyOrder.BuyUnit.TradeStoneHandCount - buyOrder.FinishedStoneTradeHandCount }, }; try { DBProvider.StoneStackDBProvider.SaveWaitingStoneDelegateBuyOrderInfo(newBuyOrder); this._dicWaitingBuyInfos[buyPrice].Enqueue(newBuyOrder); } catch (Exception exc) { LogHelper.Instance.AddErrorLog("Save Sub Buy Order Exception. UserName:"******", ParentOrderNumber: " + buyOrder.OrderNumber, exc); } FinishedStoneHandCount += buyOrder.FinishedStoneTradeHandCount; } if (FinishedStoneHandCount > 0) { var operResult = this._todayTradeInfo.DecreaseBuyUnit(buyPrice, FinishedStoneHandCount); if (operResult.OperResultCode != OperResult.RESULTCODE_TRUE) { LogHelper.Instance.AddErrorLog("TradeBuy1Orders DecreaseBuyUnit Error. " + operResult.Message, null); } } } buyOrder = this._dicWaitingBuyInfos[buyPrice].Dequeue(); } }
public StoneDelegateBuyOrderInfoUIModel(StoneDelegateBuyOrderInfo parent) { this.ParentObject = parent; }
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); }
public OperResultObject PlayerCancelBuyStone(string orderNumber, decimal buyPrice, CustomerMySqlTransaction myTrans, out StoneDelegateBuyOrderInfo canceledBuyOrder) { canceledBuyOrder = null; OperResultObject result = new OperResultObject(); ////开市期间不可撤单 //if (this._todayTradeInfo.MarketState == StackMarketState.Opening) //{ // result.OperResultCode = OperResult.RESULTCODE_STACK_CANCELORDER_FAILED_MARKETISOPENING; // return result; //} if (this._dicWaitingBuyInfos.ContainsKey(buyPrice)) { canceledBuyOrder = this._dicWaitingBuyInfos[buyPrice].DeleteOrder(orderNumber); } if (canceledBuyOrder != null) { result = this._todayTradeInfo.DeleteBuyUnit(canceledBuyOrder.BuyUnit); if (result.OperResultCode != OperResult.RESULTCODE_TRUE) { return(result); } canceledBuyOrder.BuyState = StoneDelegateBuyState.Cancel; canceledBuyOrder.FinishedTime = new MyDateTime(DateTime.Now); DBProvider.StoneStackDBProvider.CancelBuyStoneOrder(canceledBuyOrder, myTrans); result.OperResultCode = OperResult.RESULTCODE_TRUE; } else { canceledBuyOrder = this._listTempAlipayBuyOrders.FirstOrDefault(s => s.OrderNumber == orderNumber); if (canceledBuyOrder != null) { canceledBuyOrder.BuyState = StoneDelegateBuyState.Cancel; canceledBuyOrder.FinishedTime = new MyDateTime(DateTime.Now); DBProvider.StoneStackDBProvider.CancelBuyStoneOrder(canceledBuyOrder, myTrans); this._listTempAlipayBuyOrders.Remove(canceledBuyOrder); result.OperResultCode = OperResult.RESULTCODE_TRUE; } else { result.OperResultCode = OperResult.RESULTCODE_FALSE; } } return(result); }
/// <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(); } }