<?php
/**
 *  ╔═══════════════════════════════════════════════════╗
 *  ║                                                   ║
 *  ║     ██╗  ██╗   █████╗    ██████╗                  ║
 *  ║     ██║  ██║  ██╔══██╗  ██╔═══██╗                 ║
 *  ║     ███████║  ███████║  ██║   ██║                 ║
 *  ║     ██╔══██║  ██╔══██║  ██║   ██║                 ║
 *  ║     ██║  ██║  ██║  ██║  ╚██████╔╝   SNS           ║
 *  ║                                                   ║    
 *  ║                                                   ║    
 *  ║     © 2023 HaoSNS™ All Rights Reserved            ║
 *  ║     官方网站: https://www.haosns.com                *
 *  ║     本代码由赣州乐易网络科技有限公司®提供             *
 *  ║                                                    *
 *  ║   未经授权禁止复制、传播或用于其他商业目的            *
 *  ║                                                   ║
 *  ╚═══════════════════════════════════════════════════╝
 */


namespace app\adminapi\lists;

use app\common\lists\ListsSearchInterface;
use app\common\model\Circle;
use app\common\service\FileService;

class CircleLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索
     * @return \string[][]
     */
    public function setSearch(): array
    {
        return [
            '%like%' => [ 'name']
        ];
    }

    /**
     * @notes 自定义搜索
     */
    public function queryWhere()
    {
       // 状态搜索
       if(isset($this->params['status'])) {
            $this->searchWhere[] = ['status', '=', $this->params['status']];
        }
    }


    /**
     * @notes 文章/帮助列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
        $where = [];
        if(isset($_REQUEST['cate_id'])){
            $where[]=[
                ['cate_id','=',$_REQUEST['cate_id']]
            ];
        }
        $this->queryWhere();
        $lists = Circle::where($this->searchWhere)
            ->where($where)
            ->limit($this->limitOffset, $this->limitLength)
            ->select()
            ->toArray();
                    
        foreach($lists as &$item) {
            $item['icon'] = FileService::getFileUrl($item['icon']);

        }

        return $lists;
    }

    /**
     * @notes 文章/帮助总记录数
     * @return int
     */
    public function count(): int
    {
        $this->queryWhere();
        return Circle::where($this->searchWhere)->count();
    }

}