<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------

namespace app\love\controller;

use app\love\model\UserSelectLogModel;
use cmf\controller\AdminBaseController;

class AdminSelectController extends AdminBaseController
{
    /**
     * 列表
     */
    public function index()
    {
        $list = UserSelectLogModel::with('user1,user2')->order('is_top asc,is_display desc')->paginate(10);

        // 获取分页显示
        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);

        // 渲染模板输出
        return $this->fetch();
    }

    /**
     * 置顶
     */
    public function top()
    {
        $id = $this->request->param('id');
        if (empty($id)) {
            $this->error('参数错误');
        }

        UserSelectLogModel::update(['is_top' => 2], ['is_top' => 1]);
        UserSelectLogModel::update(['is_top' => 1, 'is_display' => 1], ['id' => $id]);
        $this->success('操作成功');
    }

}
