2016-02-28 110 views
0

我有一個網站laravel和nodejs蒸汽交易機器人。在交易報價中,nodejs bot觸發site.com/api/checkOffer。我想在網站上向用戶顯示一個確認框。如果用戶點擊確認接受交易報價。Laravel確認控制器方法並繼續執行任務

它我checkoffer功能

public function checkOffer() 
{ 
    $data = $this->redis->lrange('check.list', 0, -1); 
    foreach($data as $offerJson) { 
     $offer = json_decode($offerJson); 
     $accountID = $offer->accountid; 
     $items = json_decode($offer->items, true); 
     $itemsCount = count($items); 

     $user = User::where('steamid64', $accountID)->first(); 
     if (is_null($user)) { 
      $this->redis->lrem('usersQueue.list', 1, $accountID); 
      $this->redis->lrem('check.list', 0, $offerJson); 
      $this->redis->rpush('decline.list', $offer->offerid); 
      continue; 
     }else{ 
      if(empty($user->accessToken)){ 
       $this->redis->lrem('usersQueue.list', 1, $accountID); 
       $this->redis->lrem('check.list', 0, $offerJson); 
       $this->redis->rpush('decline.list', $offer->offerid); 
       $this->_responseErrorToSite('Введите трейд ссылку!', $accountID, self::BET_DECLINE_CHANNEL); 
       continue; 
      } 
     } 
     $totalItems = $user->itemsCountByGame($this->game); 
     if ($itemsCount > self::MAX_ITEMS || $totalItems > self::MAX_ITEMS || ($itemsCount+$totalItems) > self::MAX_ITEMS) { 
      $this->_responseErrorToSite('Максимальное кол-во предметов для депозита - ' . self::MAX_ITEMS, $accountID, self::BET_DECLINE_CHANNEL); 
      $this->redis->lrem('usersQueue.list', 1, $accountID); 
      $this->redis->lrem('check.list', 0, $offerJson); 
      $this->redis->rpush('decline.list', $offer->offerid); 
      continue; 
     } 

     $total_price = $this->_parseItems($items, $missing, $price); 

     if ($missing) { 
      $this->_responseErrorToSite('Принимаются только предметы из CS:GO', $accountID, self::BET_DECLINE_CHANNEL); 
      $this->redis->lrem('usersQueue.list', 1, $accountID); 
      $this->redis->lrem('check.list', 0, $offerJson); 
      $this->redis->rpush('decline.list', $offer->offerid); 
      continue; 
     } 

     if ($price) { 
      $this->_responseErrorToSite('Невозможно определить цену одного из предметов', $accountID, self::BET_DECLINE_CHANNEL); 
      $this->redis->lrem('usersQueue.list', 1, $accountID); 
      $this->redis->lrem('check.list', 0, $offerJson); 
      $this->redis->rpush('decline.list', $offer->offerid); 
      continue; 
     } 

     if ($total_price < self::MIN_PRICE) { 
      $this->_responseErrorToSite('Минимальная сумма депозита ' . self::MIN_PRICE . 'р.', $accountID, self::BET_DECLINE_CHANNEL); 
      $this->redis->lrem('usersQueue.list', 1, $accountID); 
      $this->redis->lrem('check.list', 0, $offerJson); 
      $this->redis->rpush('decline.list', $offer->offerid); 
      continue; 
     } 

     $returnValue = [ 
      'offerid' => $offer->offerid, 
      'userid' => $user->id, 
      'steamid64' => $user->steamid64, 
      'avatar' => $user->avatar, 
      'gameid' => $this->game->id, 
      'items' => $items, 
      'price' => $total_price, 
      'success' => true 
     ]; 

     if ($this->game->status == Game::STATUS_PRE_FINISH || $this->game->status == Game::STATUS_FINISHED) { 
      $this->_responseMessageToSite('Ваша ставка пойдёт на следующую игру.', $accountID); 
      $returnValue['gameid'] = $returnValue['gameid'] + 1; 
     } 

     $this->redis->rpush('checked.list', json_encode($returnValue)); 
     $this->redis->lrem('check.list', 0, $offerJson); 
    } 
    return response()->json(['success' => true]); 
} 

回答

-1

您應該創建兩條路線,如:

Route::get('api/showForm', '[email protected]'); 
Route::post('api/checkOffer', '[email protected]'); 

那麼你應該創建OfferController控制器,把你的方法,並創造方法showForm()它返回一個視圖與你的形式。

然後只需用簡單的形式在您查看或使用Laravel集體Form::來創建它:

{!! Form::open(array('route' => 'api/checkOffer', 'class' => 'form')) !!} 
    // 
{!! Form::close() !!}