<?php
namespace app\workerapi\lists;

use app\common\model\works\ReturnWork;
use app\common\lists\ListsSearchInterface;

/**
 * ReturnWork列表
 * Class ReturnWorkLists
 * @package app\workerapi\listsworks
 */
class ReturnWorkLists extends BaseWorkerDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author whitef
     * @date 2024/07/10 15:06
     */
    public function setSearch(): array
    {
        return [
            '=' => ['work_sn', 'service_work_id', 'issue_work_id', 'return_work_status', 'dispatch_time', 'appointment_time', 'finished_time', 'master_worker_id', 'create_time', 'update_time'],

        ];
    }

    public function querySearch(): array
    {
        $where['master_worker_id'] = ['=',$this->userId];
        return $where;
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author whitef
     * @date 2024/07/10 15:06
     */
    public function lists(): array
    {
        return ReturnWork::with(['service_work'=>function ($query) {
            $query->field(['id', 'work_sn', 'address', 'title', 'work_status', 'service_status', 'work_pay_status','appointment_time','receive_time','base_service_fee','service_fee'])->append(['work_status_text','service_status_text']);
        }])
        ->where($this->searchWhere)
            ->where($this->querySearch())
            ->field(['id', 'work_sn', 'service_work_id', 'issue_work_id', 'return_work_status', 'dispatch_time', 'appointment_time', 'finished_images', 'finished_time', 'master_worker_id', 'create_time', 'update_time'])
            ->append(['return_work_status_text'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取数量
     * @return int
     * @author whitef
     * @date 2024/07/10 15:06
     */
    public function count(): int
    {
        return ReturnWork::where($this->searchWhere)->where($this->querySearch())->count();
    }

}