<?php
namespace app\workerapi\lists\shops;


use app\common\lists\ListsSearchInterface;
use app\common\model\shops\ShopCategory;
use app\workerapi\lists\BaseWorkerDataLists;

/**
 * GoodsCategory列表
 * Class GoodsCategoryLists
 * @package app\api\lists\goods_category
 */
class ShopCategoryLists extends BaseWorkerDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/07/07 18:23
     */
    public function setSearch(): array
    {
        return [
            '=' => ['category_type', 'name', 'is_goods', 'status'],

        ];
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author whitef
     * @date 2024/07/07 18:23
     */
    public function lists(): array
    {
        $lists = ShopCategory::where($this->searchWhere)
            ->field(['id', 'pid' ,'picture', 'name'])
            ->order(['weigh' => 'desc'])
            ->select()
            ->toArray();

        return $lists;
    }


    /**
     * @notes 获取数量
     * @return int
     * @author whitef
     * @date 2024/07/07 18:23
     */
    public function count(): int
    {
        return ShopCategory::where($this->searchWhere)->count();
    }

}