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.
156 lines
4.3 KiB
156 lines
4.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\api\apiService;
|
|
|
|
use app\model\attendance\Attendance;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 考勤管理服务层
|
|
* Class MemberService
|
|
* @package app\service\api\member
|
|
*/
|
|
class AttendanceService extends BaseApiService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = (new Attendance());
|
|
}
|
|
|
|
//列表
|
|
public function getList(array $where, string $field = '*')
|
|
{
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数
|
|
$page = $page_params['page'];
|
|
$limit = $page_params['limit'];
|
|
|
|
$model = $this->model;
|
|
|
|
if (!empty($where['campus_id'])) {
|
|
$model = $model->where('campus_id', $where['campus_id']);
|
|
}
|
|
if (!empty($where['staff_id'])) {
|
|
$model = $model->where('staff_id', $where['staff_id']);
|
|
}
|
|
if (!empty($where['attendance_date'])) {
|
|
$model = $model->where('attendance_date', $where['attendance_date']);
|
|
}
|
|
if (!empty($where['status'])) {
|
|
$model = $model->where('status', $where['status']);
|
|
}
|
|
if (!empty($where['status_arr'])) {
|
|
$model = $model->whereIn('status', $where['status_arr']);
|
|
}
|
|
|
|
$res = $model->with([
|
|
'campus',
|
|
'personnel',
|
|
])->append([
|
|
'status_name'
|
|
])
|
|
->order('created_at','desc')
|
|
->paginate([
|
|
'list_rows' => $limit,
|
|
'page' => $page,
|
|
])->toArray();
|
|
return $res;
|
|
}
|
|
|
|
//查询详情
|
|
public function info(array $where, string $field = '*')
|
|
{
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '操作失败',
|
|
'data' => [],
|
|
];
|
|
if (empty($where)) {
|
|
$res['msg'] = '筛选条件不能唯空';
|
|
return $res;
|
|
}
|
|
$model = $this->model;
|
|
if (!empty($where['id'])) {
|
|
$model = $model->where('id', $where['id']);
|
|
}
|
|
if (!empty($where['campus_id'])) {
|
|
$model = $model->where('campus_id', $where['campus_id']);
|
|
}
|
|
if (!empty($where['staff_id'])) {
|
|
$model = $model->where('staff_id', $where['staff_id']);
|
|
}
|
|
if (!empty($where['attendance_date'])) {
|
|
$model = $model->where('attendance_date', $where['attendance_date']);
|
|
}
|
|
$data = $model->field($field)->find();
|
|
if ($data) {
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => $data->toArray(),
|
|
];
|
|
} else {
|
|
$res['msg'] = '暂无数据';
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
//添加数据
|
|
public function addData(array $data)
|
|
{
|
|
|
|
$add = $this->model->create($data);
|
|
if ($add) {
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => [],
|
|
];
|
|
} else {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '操作失败',
|
|
'data' => [],
|
|
];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
//编辑数据
|
|
public function editData(array $where, array $data)
|
|
{
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
$model = $this->model;
|
|
if (!empty($where['id'])) {
|
|
$model = $model->where('id', $where['id']);
|
|
}
|
|
$edit = $model->update($data);
|
|
if ($edit) {
|
|
$res = [
|
|
'code' => 1,
|
|
'msg' => '操作成功',
|
|
'data' => [],
|
|
];
|
|
} else {
|
|
$res = [
|
|
'code' => 0,
|
|
'msg' => '操作失败',
|
|
'data' => [],
|
|
];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
|
|
}
|
|
|