forked from lock-upme/OPMS
/
checkwork.go
executable file
·185 lines (150 loc) · 4.63 KB
/
checkwork.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package checkworks
import (
"fmt"
"opms/controllers"
. "opms/models/checkworks"
"opms/utils"
//"os"
//"strconv"
"strings"
"time"
"github.com/astaxie/beego"
//"github.com/astaxie/beego/utils/pagination"
)
//用户个人考勤
type ManageCheckworkController struct {
controllers.BaseController
}
func (this *ManageCheckworkController) Get() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "checkwork-manage") {
this.Abort("401")
}
typec := this.GetString("type")
date := this.GetString("date")
if "" == date {
date = time.Now().Format("2006-01")
}
condArr := make(map[string]string)
condArr["type"] = typec
condArr["date"] = date
condArr["userId"] = fmt.Sprintf("%d", this.BaseController.UserUserId)
_, _, checkworks := ListCheckwork(condArr)
this.Data["condArr"] = condArr
this.Data["checkworks"] = checkworks
this.Data["year"] = time.Now().Format("2006")
this.Data["month"] = time.Now().Format("1")
//统计
countCheckworks, _ := CountCheckwork(date, this.BaseController.UserUserId)
this.Data["countCheckworks"] = countCheckworks
_, _, countCheckTypes := CountCheckworkType(date, this.BaseController.UserUserId)
this.Data["countCheckTypes"] = countCheckTypes
cleaves, _ := CountCheck("leaves", date, this.BaseController.UserUserId)
this.Data["cleaves"] = cleaves
//cbusiness, _ := CountCheck("businesstrips", date, this.BaseController.UserUserId)
//this.Data["cbusiness"] = cbusiness
cgoouts, _ := CountCheck("goouts", date, this.BaseController.UserUserId)
this.Data["cgoouts"] = cgoouts
this.TplName = "checkworks/index.tpl"
}
//全部用户考勤
type ManageCheckworkAllController struct {
controllers.BaseController
}
func (this *ManageCheckworkAllController) Get() {
//权限检测
if !strings.Contains(this.GetSession("userPermission").(string), "checkwork-all") {
this.Abort("401")
}
date := this.GetString("date")
if "" == date {
date = time.Now().Format("2006-01")
}
userId, err := this.GetInt64("userid")
if err != nil {
userId = this.BaseController.UserUserId
}
condArr := make(map[string]string)
condArr["date"] = date
condArr["userId"] = fmt.Sprintf("%d", userId)
_, _, checkworks := ListCheckworkAll(condArr)
fmt.Println(checkworks)
this.Data["condArr"] = condArr
this.Data["checkworks"] = checkworks
this.Data["year"] = time.Now().Format("2006")
this.Data["month"] = time.Now().Format("1")
//统计
countCheckworks, _ := CountCheckwork(date, userId)
this.Data["countCheckworks"] = countCheckworks
_, _, countCheckTypes := CountCheckworkType(date, userId)
this.Data["countCheckTypes"] = countCheckTypes
cleaves, _ := CountCheck("leaves", date, userId)
this.Data["cleaves"] = cleaves
//cbusiness, _ := CountCheck("businesstrips", date, userId)
//this.Data["cbusiness"] = cbusiness
cgoouts, _ := CountCheck("goouts", date, userId)
this.Data["cgoouts"] = cgoouts
this.TplName = "checkworks/all.tpl"
}
//打卡
type AjaxClockUserController struct {
controllers.BaseController
}
func (this *AjaxClockUserController) Post() {
clock := this.GetString("clock")
if "" == clock {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "参数出错"}
this.ServeJSON()
return
}
checkNum := CountClock(this.BaseController.UserUserId)
if checkNum >= 2 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "你今天打卡次数超过了2次"}
this.ServeJSON()
return
}
//type 1正常2迟到3早退4加班
clockon := beego.AppConfig.String("clockon")
clockoff := beego.AppConfig.String("clockoff")
clockover := beego.AppConfig.String("clockover")
time1 := time.Now().Format("2006-01-02") + " " + clock
t1, _ := time.Parse("2006-01-02 15:04:05", time1)
var typec int
if checkNum <= 0 {
time2 := time.Now().Format("2006-01-02") + " " + clockon
t2, _ := time.Parse("2006-01-02 15:04:05", time2)
if t1.Before(t2) {
typec = 1
} else {
typec = 2
}
}
if checkNum == 1 {
time2 := time.Now().Format("2006-01-02") + " " + clockoff
t2, _ := time.Parse("2006-01-02 15:04:05", time2)
if t1.Before(t2) {
typec = 3
} else {
time2 := time.Now().Format("2006-01-02") + " " + clockover
t2, _ := time.Parse("2006-01-02 15:04:05", time2)
if t1.After(t2) {
typec = 4
} else {
typec = 1
}
}
}
var check Checkworks
check.Id = utils.SnowFlakeId()
check.Userid = this.BaseController.UserUserId
check.Clock = clock
check.Type = typec
check.Ip = this.Ctx.Input.IP()
err := AddCheckwork(check)
if err == nil {
this.Data["json"] = map[string]interface{}{"code": 1, "message": "打卡成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "打卡失败"}
}
this.ServeJSON()
}