<?php
namespace app\workerapi\lists;

use app\common\model\works\ServiceWork;

/**
 * HistoryWork列表
 * Class HistoryWorkLists
 * @package app\workerapi\listsworks
 */
class HistoryWorkLists 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
    {
        $service_status = $this->params['service_status'] ?? 3;
        $service_status = $service_status == 4 ? '4,5':$service_status;

        $where[] =  ['master_worker_id','=',$this->userId];
        $where[] =  ['approval','=',1];
        $where[] =  ['service_status','in',$service_status];

        //查询月数
        $create_month = !empty($this->params['create_month'])?$this->params['create_month']:date('Y-m');
        $list = ServiceWork::where($where)
            ->field(['id', 'work_sn', 'address', 'title', 'work_status', 'service_status','work_pay_status','finished_time','base_service_fee','service_fee','work_total','create_time','work_amount'])
            ->append(['work_status_text','service_status_text'])
            ->whereMonth('create_time', $create_month)
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();

        $this->count = ServiceWork::where($where)->whereMonth('create_time', $create_month)->count();

        return $list;
    }


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

}