-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
134 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package counterName | ||
|
||
// 定义要统计的字段 | ||
|
||
const ( | ||
// QrcodeScan 权益码扫描次数 | ||
QrcodeScan string = "qrcode_scan" | ||
// Feedback 问题反馈数量 | ||
Feedback string = "feedback_scan" | ||
// FeedbackHandle 处理问题反馈数量 | ||
FeedbackHandle string = "feedback_handle" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package feedbackType | ||
|
||
// FeedbackType | ||
const ( | ||
Activities uint = iota // 校园活动 | ||
DiningAndShops // 食堂及商铺 | ||
Dormitories // 宿舍 | ||
Academic // 教学服务(选课、转专业等) | ||
Facilities // 校园设施 | ||
Classrooms // 教室 | ||
Library // 图书馆 | ||
Transportation // 交通 | ||
Security // 安保 | ||
HealthCare // 医疗服务 | ||
Policies // 学院相关政策(如综测等) | ||
Others // 其他服务 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package qrcodeController | ||
|
||
import ( | ||
"4u-go/app/apiException" | ||
"4u-go/app/services/qrcodeService" | ||
"4u-go/app/utils" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type scanCountData struct { | ||
ID uint `form:"id" binding:"required"` | ||
} | ||
|
||
// ScanCount 更新权益码扫码次数 | ||
func ScanCount(c *gin.Context) { | ||
var data scanCountData | ||
if err := c.ShouldBind(&data); err != nil { | ||
apiException.AbortWithException(c, apiException.ParamError, err) | ||
return | ||
} | ||
if err := qrcodeService.AddScanCount(data.ID); err != nil { | ||
apiException.AbortWithException(c, apiException.ServerError, err) | ||
return | ||
} | ||
utils.JsonSuccessResponse(c, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package models | ||
|
||
// Counter 用于记录每天相关字段的增量 | ||
type Counter struct { | ||
ID uint | ||
Day int64 // 基于时间戳计算当前天数 `time.Now()/86400` | ||
Name string // 统计的字段名 | ||
Count int64 // 计数器 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package qrcodeService | ||
|
||
import ( | ||
"4u-go/app/common/counterName" | ||
trackService "4u-go/app/services/trackService/counter" | ||
) | ||
|
||
// AddScanCount 用于更新ScanCount | ||
func AddScanCount(id uint) error { | ||
// 1. 更新新增量 | ||
err := trackService.AddCount(counterName.QrcodeScan) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// 2. 更新总量 | ||
qrcode, err := GetQrcodeById(id) | ||
if err != nil { | ||
return err | ||
} | ||
qrcode.ScanCount++ | ||
return SaveQrcode(qrcode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package trackService | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"4u-go/app/models" | ||
"4u-go/config/database" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// AddCount 用于更新某一字段在某一天的增量 | ||
func AddCount(name string) error { | ||
day := time.Now().Unix() / 86400 | ||
counter, err := getCounter(name, day) | ||
|
||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
// 记录不存在则创建 | ||
counter.Name = name | ||
counter.Day = day | ||
counter.Count = 1 | ||
return saveCounter(counter) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
counter.Count++ | ||
return saveCounter(counter) | ||
} | ||
|
||
func getCounter(name string, day int64) (counter models.Counter, err error) { | ||
err = database.DB.Where("name=? AND day=?", name, day).First(&counter).Error | ||
return counter, err | ||
} | ||
|
||
func saveCounter(counter models.Counter) error { | ||
return database.DB.Save(&counter).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters