<?php
namespace app\workerapi\lists;

use app\common\model\works\GroupServiceWork;
use app\common\lists\ListsSearchInterface;
use DateTime;

/**
 * GroupServiceWork列表
 * Class GroupServiceWorkLists
 * @package app\workerapi\listsworks
 */
class GroupServiceWorkLists  extends BaseWorkerDataLists implements ListsSearchInterface
{
    protected $count = 0;
    public function setSearch(): array
    {
        return [];
    }
    /**
     * @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
    {
        $where = [
            'master_worker_id'=>$this->userId,
        ];
     
        //条件搜索
        $status = $this->params['status'] ?? 0;
        switch ($status){
            case 0:
                //今日上门
                $startOfDayTimestamp = strtotime(date("Y-m-d"));
                $endOfDayTimestamp = strtotime(date("Y-m-d 23:59:59"));
                $where[] = ['appointment_time','between',[$startOfDayTimestamp, $endOfDayTimestamp]];
                break;
            case 1:
                //待完成
                $where[] = ['work_status','<>',1];
                $where[] = ['service_status','in','0,1,2'];
                break;
            case 2:
                //已完成
                $where[] = ['service_status','=','3'];
                break;
        }
        $list = GroupServiceWork::where($where)
            ->field(['id', 'work_sn', 'address', 'title', 'work_status', 'service_status','appointment_time'])
            ->append(['work_status_text','service_status_text'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['appointment_time' => 'asc'])//上门时间排序
            ->select()
            ->toArray();
        $this->count = GroupServiceWork::where($where)->count();

        return $list;
    }


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

}