<?php
namespace app\workerapi\lists;
use app\common\model\finance\MasterWorkerCaseOutLog;

/**
 * @author 林海涛
 * @date 2024/7/23 下午2:17
 */
class MasterWorkerCaseOutLogLists extends BaseWorkerDataLists
{
    public function queryWhere()
    {
        $where = [];
        if(isset($this->params['month'])){
            $firstDay = date("Y-m-d 00:00:00", strtotime("first day of {$this->params['month']}"));
            $lastDay = date("Y-m-d 23:59:59", strtotime("{$this->params['month']} +1 month -1 day"));
            $firstTime = strtotime($firstDay);
            $lastTime = strtotime($lastDay);
            $where[] = ['create_time','between',[$firstTime,$lastTime]];
        }
        $where[] = ['worker_id', '=', $this->userId];
        return $where;
    }

    public function lists():array
    {
        return MasterWorkerCaseOutLog::where($this->searchWhere)
            ->where($this->queryWhere())
            ->field('sn,title,change_amount,review_status,create_time')
            ->append(['review_status_text'])
            //->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }
    public function count(): int
    {
        return MasterWorkerCaseOutLog::where($this->queryWhere())->count();
    }
}