<?php

namespace frontend\modules\cp\controllers;

use Yii;
use frontend\models\LottoRecordApi;

/**
 *
 */
class LottoRecordController extends BaseController
{
    public $layout = false;
    
    /**
     * 展会中奖记录
     */
    public function actionList()
    {
        return $this->render('list', ['activityType' => 1, 'title' => '展会中奖记录']);
    }

    /**
     * PC中奖记录，同一个页面，调用数据也是actionGetLottoRecordListAjax，只不过activityType不同
     */
    public function actionListPc()
    {
        return $this->render('list', ['activityType' => 2, 'title' => 'PC中奖记录']);
    }

    /**
     * AJAX获取数据
     */
    public function actionAjax()
    {
        $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']) ? $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;
        $activityType = isset($get['activityType']) ? $get['activityType'] : 0;

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

        $api = new LottoRecordApi();
        $result = $api->getList($params);
        return json_encode($result['data']);
    }
    
    /**
     * 删除中奖记录
     */
    public function actionDelete()
    {
        $id = (int) Yii::$app->request->get('id');
        if (!$id) {
            return $this->outJson(0, [], '参数错误');
        }
        $api = new LottoRecordApi();
        $result = $api->deleteLottoRecord(['id' => $id]);
        return json_encode($result);
    }
    
}