0

laravel と nodejs の蒸気取引ボットを含む Web サイトを持っています。トレード オファーで、nodejs ボットが site.com/api/checkOffer を起動しました。ウェブサイトの確認ボックスをユーザーに表示したい。ユーザーが確認をクリックすると、トレードオファーを受け入れます。

その私の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]);
}
4

1 に答える 1

-1

次のような 2 つのルートを作成する必要があります。

Route::get('api/showForm', 'OfferController@showForm');
Route::post('api/checkOffer', 'OfferController@checkOffer');

次に、コントローラーを作成し、その中にメソッドを入れて、フォームでビューを返すOfferControllerメソッドを作成する必要があります。showForm()

次に、ビューで単純なフォームを使用するか、Laravel CollectiveForm::を使用して作成します。

{!! Form::open(array('route' => 'api/checkOffer', 'class' => 'form'))  !!}
    //
{!! Form::close() !!}
于 2016-02-28T16:57:02.647 に答える