<?php

namespace app\common\lists;

use app\admin\lists\BaseAdminDataLists;
use app\common\model\system_store\SystemStoreStaff;

class StoreStaffLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author admin
     * @date 2024/05/31 16:02
     */
    public function setSearch(): array
    {
        return [
        ];
    }


    /**
     * @notes 获取订单列表列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author admin
     * @date 2024/05/31 16:02
     */
    public function lists(): array
    {
        return SystemStoreStaff::field('id,staff_name,avatar,account,phone,is_admin,is_manager,status')
            ->when(!empty($this->request->adminInfo['store_id']), function ($query) {
                $query->where('store_id', '=', $this->request->adminInfo['store_id']);
            })
            ->when(!empty($this->params['keyword']), function ($query) {
                $query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%");
            })
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取订单列表数量
     * @return int
     * @author admin
     * @date 2024/05/31 16:02
     */
    public function count(): int
    {
        return SystemStoreStaff::when(!empty($this->request->adminInfo['store_id']), function ($query) {
                $query->where('store_id', '=', $this->request->adminInfo['store_id']);
            })
            ->when(!empty($this->params['keyword']), function ($query) {
                $query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%");
            })
            ->count();
    }

}