0

我有一个带有 laravel 和 nodejs 蒸汽贸易机器人的网站。交易报价来自 nodejs 机器人触发 site.com/api/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

您应该创建两条路线,例如:

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 回答