<?php
|
/**
|
+-----------------------------------------------------------------------------------------------
|
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
|
+-----------------------------------------------------------------------------------------------
|
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
|
+-----------------------------------------------------------------------------------------------
|
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
|
+-----------------------------------------------------------------------------------------------
|
* @Author 勾股工作室 <hdm58@qq.com>
|
+-----------------------------------------------------------------------------------------------
|
*/
|
namespace app\user\model;
|
use think\model;
|
use think\facade\Db;
|
class Attendance extends Model
|
{
|
/**
|
* 插入用户关联表
|
*
|
* @param int $groupId 组ID
|
* @param string $userIdString 用户ID字符串
|
* @param int $type 类型
|
*/
|
public function insertUserLinks(int $groupId, string $userIdString, int $type): void
|
{
|
$userIds = explode(",", $userIdString);
|
$mappingData = [];
|
foreach ($userIds as $userId) {
|
if (!empty($userId)) {
|
$mappingData[] = [
|
'group_id' => $groupId,
|
'user_id' => intval($userId),
|
'type' => $type,
|
];
|
}
|
}
|
if (!empty($mappingData)) {
|
Db::name('AttendanceUserLink')->strict(false)->field(true)->insertAll($mappingData);
|
}
|
}
|
|
/**
|
* 插入特殊日期
|
*
|
* @param int $groupId 组ID
|
* @param array $dates 日期数组
|
* @param int $type 类型
|
*/
|
public function insertSpecialDates(int $groupId, array $dates, int $type): void
|
{
|
$timeIds = [];
|
foreach ($dates as $date) {
|
$timeData = [
|
'begin_data' => $date . " 00:00:00",
|
'end_data' => $date . " 23:59:59",
|
'type' => $type,
|
];
|
$timeIds[] = Db::name('AttendanceSpecialDate')->strict(false)->field(true)->insertGetId($timeData);
|
}
|
|
$mappingData = [];
|
foreach ($timeIds as $timeId) {
|
$mappingData[] = [
|
'group_id' => $groupId,
|
'special_date_id' => $timeId,
|
];
|
}
|
if (!empty($mappingData)) {
|
Db::name('AttendanceGroupSpecialDateLink')->strict(false)->field(true)->insertAll($mappingData);
|
}
|
}
|
}
|