<?php
namespace backend\controllers;

use backend\helpers\PaginationHelper;
use backend\helpers\ValidatorHelper;
use backend\models\Signin;
use Yii;

class SigninController extends BaseController
{
    /**
     * 登录信息列表
     * @return \yii\web\Response
     */
    public function actionList()
    {
        $data = Yii::$app->getRequest()->get();
        $data['memberId'] = isset($data['memberId']) ? trim($data['memberId']) : '';
        $data['page'] = isset($data['page']) ? max(intval($data['page']), 1) : 1;
        $data['pageSize'] = isset($data['pageSize']) ? intval($data['pageSize']) : 10;
        $data['orderBy'] = isset($data['orderBy']) ? trim($data['orderBy']) : 'id desc';
        $data = ValidatorHelper::validateData($data, [
            ['memberId', 'integer'],
            ['page', 'integer', 'min' => 1],
            ['pageSize', 'integer', 'min' => 1],
            ['orderBy', 'string'],
        ], $errors);
        if ($data == false) {
            return $this->outJson(0, '', $errors);
        }
        $query = Signin::find()->orderBy($data['orderBy']);
        $query->andWhere(['member_id' => $data['memberId']]);
        $result = PaginationHelper::queryPage($query, $data['page'], $data['pageSize']);
        return $this->outJson(1, $result);
    }
}