<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台(PHP版)
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用,可去除界面版权logo
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
// | github下载:https://github.com/likeshop-github/likeadmin
// | 访问官网:https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\lists\project;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\Project;
use app\common\model\project\ProjectAttendanceDetail;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectPersonnel;


/**
 * 考勤明细列表
 * Class ProjectAttendanceDetailLists
 * @package app\adminapi\listsproject
 */
class ProjectAttendanceDetailLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2023/12/26 10:54
     */
    public function setSearch(): array
    {
        return [
			'=' => ['project_id']
        ];
    }


    /**
     * @notes 获取考勤明细列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author likeadmin
     * @date 2023/12/26 10:54
     */
    public function lists(): array
    {
        return ProjectAttendanceDetail::where($this->searchWhere)
            ->field(['id', 'attendance_code', 'project_id', 'person_id', 'attendance_date', 'work_start_time', 'work_end_time', 'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income', 'remark'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()->each(function($item){
		        $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
		        $person = ProjectPersonnel::field('name,idcard,work_type')->where('id',$item['person_id'])->findOrEmpty();
		        $item['project_name'] = $project['name'];
		        $item['project_code'] = $project['project_code'];
		        $item['person_name'] = $person['name'];
		        $item['person_idcard'] = $person['idcard'];
		        $item['work_type_text'] = $person->work_type_text;
				return $item;
	        })
            ->toArray();
    }


    /**
     * @notes 获取考勤明细数量
     * @return int
     * @author likeadmin
     * @date 2023/12/26 10:54
     */
    public function count(): int
    {
        return ProjectAttendanceDetail::where($this->searchWhere)->count();
    }

}