闫增涛
2025-04-14 4a0006c0b8df5befabf7403c0702f4429cf244e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?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);
        }
    }
}