<?php
namespace app\workerapi\lists;

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

/**
 * ServiceAssignWork列表
 * Class ServiceAssignWorkLists
 * @package app\workerapi\listsworks
 */
class ServiceAssignWorkLists extends BaseWorkerDataLists
{
    protected $count = 0;

    /**
     * @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,
            'approval'=>1,//派单的时候默认审核了
            'work_status'=>1,
        ];

        $list = ServiceWork::where($where)
            ->where('work_pay_status','>',0)
            ->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'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['appointment_time' => 'asc'])//上门时间排序
            ->select()
            ->toArray();

        $this->count = ServiceWork::where($where)->count();

        return $list;
    }


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

}