<?php 
namespace backend\modules\admin\controllers;

use backend\models\ActivityApi;
use Yii;

class ActivityController extends BaseController
{
    
    public function actionIndex()
    {
        return $this->actionApril();
    }
    
    /**
     * 四月活动
     */
    public function actionApril()
    {
        return $this->render('april');
    }
    
    /**
     * AJAX获取数据
     */
    public function actionAprilAjax()
    {
        $get = Yii::$app->request->get();
        $orderInt = isset($get['order'][0]['column']) ? (int) $get['order'][0]['column'] : 1;
        $order = isset($get['columns'][$orderInt]['data']) ? $get['columns'][$orderInt]['data'] : '';
        $orderBy = isset($get['order'][0]['dir']) ? $get['order'][0]['dir'] : 'desc';
        $search = isset($get['search']['value']) ? trim($get['search']['value']) : '';

        $start = isset($get['start']) ? (int) $get['start'] : 0;
        $length = isset($get['length']) ? (int) $get['length'] : 20;
        $draw = isset($get['draw']) ? $get['draw'] : 1;

        $params = [
            'order' => $order,
            'orderBy' => $orderBy,
            'search' => $search,
            'start' => $start,
            'length' => $length,
            'draw' => $draw,
        ];

        $api = new ActivityApi();
        $result = $api->getAprilList($params);
        echo json_encode($result['data']);
    }
}