You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.4 KiB
147 lines
3.4 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model\attendance;
|
|
|
|
use app\model\dict\Dict;
|
|
use core\base\BaseModel;
|
|
use think\model\concern\SoftDelete;
|
|
use think\model\relation\HasMany;
|
|
use think\model\relation\HasOne;
|
|
|
|
use app\model\campus\Campus;
|
|
|
|
use app\model\personnel\Personnel;
|
|
|
|
/**
|
|
* 考勤模型
|
|
* Class Attendance
|
|
* @package app\model\attendance
|
|
*/
|
|
class Attendance extends BaseModel
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
* 数据表主键
|
|
* @var string
|
|
*/
|
|
protected $pk = 'id';
|
|
|
|
/**
|
|
* 模型名称
|
|
* @var string
|
|
*/
|
|
protected $name = 'attendance';
|
|
|
|
//状态类型
|
|
const STATUS = [
|
|
'present'=>'出勤',
|
|
'absent'=>'缺勤',
|
|
'late'=>'迟到',
|
|
'leave_early'=>'早退',
|
|
'leave'=>'请假'
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
* 搜索器:考勤校区
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchCampusIdAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("campus_id", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:考勤人员
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchStaffIdAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("staff_id", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:考勤考勤日期
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchAttendanceDateAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("attendance_date", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:考勤考勤状态
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchStatusAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("status", $value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 获取考勤状态状态类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getStatusNameAttr($value, $data)
|
|
{
|
|
$key = 'kq_status';
|
|
$val = (String)$data['status'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ? json_decode(json_decode($dict['dictionary'],true),true) : [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function campus(){
|
|
return $this->hasOne(Campus::class, 'id', 'campus_id')->joinType('left')->withField('campus_name,id')->bind(['campus_id_name'=>'campus_name']);
|
|
}
|
|
|
|
public function personnel(){
|
|
return $this->hasOne(Personnel::class, 'id', 'staff_id')->joinType('left')->withField('name,id')->bind(['staff_id_name'=>'name']);
|
|
}
|
|
|
|
}
|
|
|