@@ -1,17 +1,46 @@ | |||
# ---> Go | |||
# Binaries for programs and plugins | |||
*.exe | |||
*.exe~ | |||
*.dll | |||
*.so | |||
*.dylib | |||
# Test binary, built with `go test -c` | |||
*.test | |||
# Output of the go coverage tool, specifically when used with LiteIDE | |||
*.out | |||
# Dependency directories (remove the comment below to include it) | |||
# vendor/ | |||
.idea | |||
.vscode | |||
*.log | |||
.DS_Store | |||
Thumbs.db | |||
*.swp | |||
*.swn | |||
*.swo | |||
*.swm | |||
*.7z | |||
*.zip | |||
*.rar | |||
*.tar | |||
*.tar.gz | |||
go.sum | |||
/etc/cfg.yaml | |||
images | |||
test/test.json | |||
etc/cfg.yml | |||
t.json | |||
t1.json | |||
t2.json | |||
t3.json | |||
t.go | |||
wait-for-it.sh | |||
test.go | |||
xorm | |||
test.csv | |||
nginx.conf | |||
.devcontainer | |||
.devcontainer/Dockerfile | |||
.devcontainer/sources.list | |||
/t1.go | |||
/tmp/* | |||
.idea/* | |||
/.idea/modules.xml |
@@ -0,0 +1,32 @@ | |||
.PHONY: build clean tool lint help | |||
APP=applet | |||
all: build | |||
build: | |||
go build -o ./bin/$(APP) ./cmd/main.go | |||
lite: | |||
go build -ldflags "-s -w" -o ./bin/$(APP) ./cmd/main.go | |||
install: | |||
#@go build -v . | |||
go install ./cmd/... | |||
tool: | |||
go vet ./...; true | |||
gofmt -w . | |||
lint: | |||
golint ./... | |||
clean: | |||
rm -rf go-gin-example | |||
go clean -i . | |||
help: | |||
@echo "make: compile packages and dependencies" | |||
@echo "make tool: run specified go tool" | |||
@echo "make lint: golint ./..." | |||
@echo "make clean: remove object files and cached files" |
@@ -1,3 +1,50 @@ | |||
# smart_canteen | |||
智慧食堂 | |||
- 智慧食堂 | |||
## 要看 nginx.conf 和 wap conf | |||
## 层级介绍 | |||
- hdl 做接收数据的报错, 数据校验 | |||
- svc 做数据处理的报错, 数据转换 | |||
- lib 只抛出错误给hdl或者svc进行处理, 不做数据校验 | |||
- db 可以处理db错误,其它错误返回给svc进行处理 | |||
- mw 中间件 | |||
- md 结构体 | |||
#### 介绍 | |||
基于gin的接口小程序 | |||
#### 软件架构 | |||
软件架构说明 | |||
#### 安装教程 | |||
1. xxxx | |||
2. xxxx | |||
3. xxxx | |||
#### 使用说明 | |||
1. xxxx | |||
2. xxxx | |||
3. xxxx | |||
#### 参与贡献 | |||
1. Fork 本仓库 | |||
2. 新建 Feat_xxx 分支 | |||
3. 提交代码 | |||
4. 新建 Pull Request | |||
## swagger | |||
``` | |||
// 参考:https://segmentfault.com/a/1190000013808421 | |||
// 安装命令行 | |||
go get -u github.com/swaggo/swag/cmd/swag | |||
// 生成 | |||
swag init | |||
``` |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type AdminState int32 | |||
const ( | |||
AdminStateForNormal = 1 | |||
AdminStateForFreeze = 2 | |||
) | |||
func (gt AdminState) String() string { | |||
switch gt { | |||
case AdminStateForNormal: | |||
return "正常" | |||
case AdminStateForFreeze: | |||
return "冻结" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type CompanyState int32 | |||
const ( | |||
CompanyStateForNormal = 1 | |||
CompanyStateForFreeze = 2 | |||
) | |||
func (gt CompanyState) String() string { | |||
switch gt { | |||
case CompanyStateForNormal: | |||
return "正常" | |||
case CompanyStateForFreeze: | |||
return "冻结" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type PermissionGroupState int32 | |||
const ( | |||
PermissionGroupStateForNormal = 1 | |||
PermissionGroupStateForDiscard = 2 | |||
) | |||
func (gt PermissionGroupState) String() string { | |||
switch gt { | |||
case PermissionGroupStateForNormal: | |||
return "正常" | |||
case PermissionGroupStateForDiscard: | |||
return "废弃" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
package enum | |||
type QrcodeBatchState int32 | |||
const ( | |||
QrcodeBatchStateForUseIng = 1 | |||
QrcodeBatchStateForUseAlready = 2 | |||
QrcodeBatchStateForExpire = 3 | |||
QrcodeBatchStateForCancel = 4 | |||
) | |||
func (gt QrcodeBatchState) String() string { | |||
switch gt { | |||
case QrcodeBatchStateForUseIng: | |||
return "使用中" | |||
case QrcodeBatchStateForUseAlready: | |||
return "使用完" | |||
case QrcodeBatchStateForExpire: | |||
return "已过期" | |||
case QrcodeBatchStateForCancel: | |||
return "已作废" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type QrcodeWithBatchRecordsSate int32 | |||
const ( | |||
QrcodeWithBatchRecordsStateForWait = 1 | |||
QrcodeWithBatchRecordsStateForAlready = 2 | |||
QrcodeWithBatchRecordsStateForExpire = 3 | |||
QrcodeWithBatchRecordsStateForCancel = 4 | |||
) | |||
func (gt QrcodeWithBatchRecordsSate) String() string { | |||
switch gt { | |||
case QrcodeWithBatchRecordsStateForWait: | |||
return "待使用" | |||
case QrcodeWithBatchRecordsStateForAlready: | |||
return "已使用" | |||
case QrcodeWithBatchRecordsStateForExpire: | |||
return "已过期" | |||
case QrcodeWithBatchRecordsStateForCancel: | |||
return "已作废" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type QrcodeSate int32 | |||
const ( | |||
QrcodeSateAllowUse = 1 | |||
QrcodeSateAllowNotUse = 2 | |||
) | |||
func (gt QrcodeSate) String() string { | |||
switch gt { | |||
case QrcodeSateAllowUse: | |||
return "可使用" | |||
case QrcodeSateAllowNotUse: | |||
return "不可用" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type RoleState int32 | |||
const ( | |||
RoleStateForNormal = 1 | |||
RoleStateForFreeze = 2 | |||
) | |||
func (gt RoleState) String() string { | |||
switch gt { | |||
case RoleStateForNormal: | |||
return "正常" | |||
case RoleStateForFreeze: | |||
return "冻结" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type WxOfficialAccountRequest string | |||
const ( | |||
GetAccessToken = "cgi-bin/token" | |||
QrcodeCreate = "cgi-bin/qrcode/create" | |||
) | |||
func (gt WxOfficialAccountRequest) String() string { | |||
switch gt { | |||
case GetAccessToken: | |||
return "获取 Access token" | |||
case QrcodeCreate: | |||
return "生成带参二维码" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,844 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
svc2 "applet/app/admin/svc/enterprise_manage" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func CentralKitchenForSchoolUserUpdate(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolUserUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolUserUpdate(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolUserDelete(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolUserDeleteReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolUserDelete(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolStudentListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
resp, total, err := svc2.CentralKitchenForSchoolStudentList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
"total": total, | |||
"admission_list": []map[string]string{ | |||
{ | |||
"name": "按班级", | |||
"value": "admission_type_by_class", | |||
}, | |||
{ | |||
"name": "按年级", | |||
"value": "admission_type_by_grade", | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolTeacherList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolTeacherListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
resp, total, err := svc2.CentralKitchenForSchoolTeacherList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
"total": total, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolTeacherUpdate(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolTeacherUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if userIdentity == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
userIdentity.IdNo = req.IdNo | |||
userIdentity.Name = req.Name | |||
_, err = userIdentityDb.UserIdentityUpdate(req.UserIdentityId, userIdentity, "id_no", "name") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentUpdate(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolStudentUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolStudentUpdate(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentAdmission(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolStudentAdmissionReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolStudentAdmission(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentDelete(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolStudentDeleteReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolStudentDelete(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolTeacherDelete(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolTeacherDeleteReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
//删除 user_identity | |||
_, err = db.Db.Where("enterprise_id =?", req.EnterpriseId).In("id", req.UserIdentityIds).Delete(model.UserIdentity{}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func GetCentralKitchenForSchoolWithSpec(c *gin.Context) { | |||
enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0")) | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(enterpriseId) | |||
data, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"data": data, | |||
}, nil) | |||
return | |||
} | |||
func SetCentralKitchenForSchoolWithSpec(c *gin.Context) { | |||
var req md.SetCentralKitchenForSchoolWithSpecReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(req.EnterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
_, err = centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecDelete() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
if spec != nil { | |||
insertConfirm, err1 := centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{ | |||
IsOpenBreakfast: spec.IsOpenBreakfast, | |||
IsOpenLunch: spec.IsOpenLunch, | |||
IsOpenDinner: spec.IsOpenDinner, | |||
EnterpriseId: req.EnterpriseId, | |||
BreakfastUnitPrice: req.BreakfastUnitPrice, | |||
LunchUnitPrice: req.LunchUnitPrice, | |||
DinnerUnitPrice: req.DinnerUnitPrice, | |||
BreakfastUnitPriceForTeacher: req.BreakfastUnitPriceForTeacher, | |||
LunchUnitPriceForTeacher: req.LunchUnitPriceForTeacher, | |||
DinnerUnitPriceForTeacher: req.DinnerUnitPriceForTeacher, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
if insertConfirm <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增数据失败") | |||
return | |||
} | |||
} else { | |||
insertConfirm, err1 := centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{ | |||
EnterpriseId: req.EnterpriseId, | |||
BreakfastUnitPrice: req.BreakfastUnitPrice, | |||
LunchUnitPrice: req.LunchUnitPrice, | |||
DinnerUnitPrice: req.DinnerUnitPrice, | |||
BreakfastUnitPriceForTeacher: req.BreakfastUnitPriceForTeacher, | |||
LunchUnitPriceForTeacher: req.LunchUnitPriceForTeacher, | |||
DinnerUnitPriceForTeacher: req.DinnerUnitPriceForTeacher, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
if insertConfirm <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增数据失败") | |||
return | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func ListCentralKitchenForSchoolPackage(c *gin.Context) { | |||
var req md.ListCentralKitchenForSchoolPackageReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
centralKitchenForSchoolPackageDb := db.CentralKitchenForSchoolPackageDb{} | |||
centralKitchenForSchoolPackageDb.Set() | |||
list, total, err := centralKitchenForSchoolPackageDb.CentralKitchenForSchoolPackageList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"total": total, | |||
"state_list": []map[string]interface{}{ | |||
{ | |||
"name": "可用", | |||
"value": 1, | |||
}, | |||
{ | |||
"name": "不可用", | |||
"value": 2, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func DetailCentralKitchenForSchoolPackage(c *gin.Context) { | |||
packageId := utils.StrToInt(c.DefaultQuery("package_id", "")) | |||
centralKitchenForSchoolPackageDb := db.CentralKitchenForSchoolPackageDb{} | |||
centralKitchenForSchoolPackageDb.Set() | |||
centralKitchenForSchoolPackage, err := centralKitchenForSchoolPackageDb.GetCentralKitchenForSchoolPackage(packageId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if centralKitchenForSchoolPackage == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
centralKitchenForSchoolPackageWithDayDb := db.CentralKitchenForSchoolPackageWithDayDb{} | |||
centralKitchenForSchoolPackageWithDayDb.Set(packageId) | |||
centralKitchenForSchoolPackageWithDay, err := centralKitchenForSchoolPackageWithDayDb.FindCentralKitchenForSchoolPackageWithDay() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var resp = md.SaveCentralKitchenForSchoolPackageReq{ | |||
PackageId: centralKitchenForSchoolPackage.Id, | |||
EnterpriseId: centralKitchenForSchoolPackage.EnterpriseId, | |||
Year: centralKitchenForSchoolPackage.Year, | |||
Month: centralKitchenForSchoolPackage.Month, | |||
StartDate: centralKitchenForSchoolPackage.StartDate, | |||
EndDate: centralKitchenForSchoolPackage.EndDate, | |||
DateList: nil, | |||
} | |||
for _, v := range *centralKitchenForSchoolPackageWithDay { | |||
resp.DateList = append(resp.DateList, struct { | |||
Date string `json:"date"` | |||
IsOpenBreakfast int32 `json:"is_open_breakfast"` | |||
IsOpenLunch int32 `json:"is_open_lunch"` | |||
IsOpenDinner int32 `json:"is_open_dinner"` | |||
IsOpenReplenish int32 `json:"is_open_replenish"` | |||
}{Date: v.Date, IsOpenBreakfast: int32(v.IsOpenBreakfast), IsOpenLunch: int32(v.IsOpenLunch), IsOpenDinner: int32(v.IsOpenDinner), IsOpenReplenish: int32(v.IsOpenReplenish)}) | |||
} | |||
e.OutSuc(c, resp, nil) | |||
return | |||
} | |||
func SaveCentralKitchenForSchoolPackage(c *gin.Context) { | |||
var req md.SaveCentralKitchenForSchoolPackageReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
//判断是新增 / 编辑 | |||
if req.PackageId > 0 { | |||
err = svc.UpdateCentralKitchenForSchoolPackage(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} else { | |||
err = svc.AddCentralKitchenForSchoolPackage(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func DeleteCentralKitchenForSchoolPackage(c *gin.Context) { | |||
packageId := c.Param("id") | |||
err := svc.DeleteCentralKitchenForSchoolPackage(utils.StrToInt(packageId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func SetBasicCentralKitchenForSchool(c *gin.Context) { | |||
var req md.SetBasicCentralKitchenForSchoolReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
//1、更新 central_kitchen_for_school_set | |||
centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{} | |||
centralKitchenForSchoolSetDb.Set(req.EnterpriseId) | |||
set, err := centralKitchenForSchoolSetDb.GetCentralKitchenForSchoolSet() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if set != nil { | |||
set.IsOpenTeacherReportMeal = req.IsOpenTeacherReportMeal | |||
set.IsOpenReportMealForDay = req.IsOpenReportMealForDay | |||
set.IsOpenReportMealForMonth = req.IsOpenReportMealForMonth | |||
set.IsOpenReportMealForSemester = req.IsOpenReportMealForSemester | |||
set.UpdateAt = now | |||
_, err2 := centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetUpdate(set.Id, set, "is_open_teacher_report_meal", "is_open_report_meal_for_day", "is_open_report_meal_for_month", "is_open_report_meal_for_semester", "update_at") | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} else { | |||
_, err2 := centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{ | |||
EnterpriseId: req.EnterpriseId, | |||
IsOpenTeacherReportMeal: req.IsOpenTeacherReportMeal, | |||
IsOpenReportMealForDay: req.IsOpenReportMealForDay, | |||
IsOpenReportMealForMonth: req.IsOpenReportMealForMonth, | |||
IsOpenReportMealForSemester: req.IsOpenReportMealForSemester, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
//2、更新 central_kitchen_for_school_with_spec | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(req.EnterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if spec != nil { | |||
spec.IsOpenBreakfast = req.IsOpenBreakfast | |||
spec.IsOpenLunch = req.IsOpenLunch | |||
spec.IsOpenDinner = req.IsOpenDinner | |||
spec.UpdateAt = now | |||
_, err2 := centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecUpdate(spec.Id, spec, "is_open_breakfast", "is_open_lunch", "is_open_dinner", "update_at") | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} else { | |||
_, err2 := centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{ | |||
EnterpriseId: req.EnterpriseId, | |||
IsOpenBreakfast: req.IsOpenBreakfast, | |||
IsOpenLunch: req.IsOpenLunch, | |||
IsOpenDinner: req.IsOpenDinner, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
//3、更新 `enterprise` | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
enterprise.Name = req.Name | |||
enterprise.State = req.State | |||
enterprise.UpdateAt = now | |||
_, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "state", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func GetBasicCentralKitchenForSchool(c *gin.Context) { | |||
enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0")) | |||
//1、获取 central_kitchen_for_school_set | |||
centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{} | |||
centralKitchenForSchoolSetDb.Set(enterpriseId) | |||
set, err := centralKitchenForSchoolSetDb.GetCentralKitchenForSchoolSet() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if set == nil { | |||
set = &model.CentralKitchenForSchoolSet{ | |||
EnterpriseId: enterpriseId, | |||
IsOpenTeacherReportMeal: 0, | |||
IsOpenReportMealForDay: 0, | |||
IsOpenReportMealForMonth: 0, | |||
IsOpenReportMealForSemester: 0, | |||
CreateAt: time.Time{}, | |||
UpdateAt: time.Time{}, | |||
} | |||
_, err2 := centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(set) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
//2、获取 central_kitchen_for_school_with_spec | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(enterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if spec == nil { | |||
spec = &model.CentralKitchenForSchoolWithSpec{ | |||
EnterpriseId: enterpriseId, | |||
IsOpenBreakfast: 0, | |||
IsOpenLunch: 0, | |||
IsOpenDinner: 0, | |||
BreakfastUnitPrice: "0", | |||
LunchUnitPrice: "0", | |||
DinnerUnitPrice: "0", | |||
BreakfastUnitPriceForTeacher: "0", | |||
LunchUnitPriceForTeacher: "0", | |||
DinnerUnitPriceForTeacher: "0", | |||
CreateAt: time.Time{}, | |||
UpdateAt: time.Time{}, | |||
} | |||
_, err2 := centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(spec) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
//3、更新 `enterprise` | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"central_kitchen_for_school_set": set, | |||
"central_kitchen_for_school_with_spec": spec, | |||
"enterprise": enterprise, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrdList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrdListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
resp, total, err := svc2.CentralKitchenForSchoolOrdList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
"total": total, | |||
"kind_list": []map[string]string{ | |||
{ | |||
"name": "按学期购买", | |||
"value": "1", | |||
}, | |||
{ | |||
"name": "按月购买", | |||
"value": "2", | |||
}, | |||
{ | |||
"name": "按天购买", | |||
"value": "3", | |||
}, | |||
}, | |||
"state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdState.String(enum.CentralKitchenForSchoolPackageOrdStateForWait), | |||
"value": enum.CentralKitchenForSchoolPackageOrdStateForWait, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdState.String(enum.CentralKitchenForSchoolPackageOrdStateForSuccess), | |||
"value": enum.CentralKitchenForSchoolPackageOrdStateForSuccess, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdState.String(enum.CentralKitchenForSchoolPackageOrdStateForFail), | |||
"value": enum.CentralKitchenForSchoolPackageOrdStateForFail, | |||
}, | |||
}, | |||
"ord_state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForWait, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrdRefund(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrdRefundReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolOrdRefund(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrdDetail(c *gin.Context) { | |||
outTradeNo := c.DefaultQuery("out_trade_no", "") | |||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if ord == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") | |||
return | |||
} | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByOrdNo(ord.OutTradeNo) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForLunch, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForDinner, | |||
}, | |||
}, | |||
"state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayState.String(enum.CentralKitchenForSchoolUserWithDayStateForWait), | |||
"value": enum.CentralKitchenForSchoolUserWithDayStateForWait, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayState.String(enum.CentralKitchenForSchoolUserWithDayStateForAlready), | |||
"value": enum.CentralKitchenForSchoolUserWithDayStateForAlready, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayState.String(enum.CentralKitchenForSchoolUserWithDayStateForCanceling), | |||
"value": enum.CentralKitchenForSchoolUserWithDayStateForCanceling, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayState.String(enum.CentralKitchenForSchoolUserWithDayStateForCancel), | |||
"value": enum.CentralKitchenForSchoolUserWithDayStateForCancel, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,107 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
svc2 "applet/app/admin/svc/enterprise_manage" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func EnterpriseManageInfo(c *gin.Context) { | |||
enterpriseId := c.DefaultQuery("enterprise_id", "") | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(utils.StrToInt(enterpriseId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
var resp interface{} | |||
switch enterprise.Kind { | |||
case enum.EnterprisePvdByCentralKitchenForSchool: | |||
err, resp = svc.CentralKitchenForSchoolInfo(utils.StrToInt(enterpriseId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
break | |||
case enum.EnterprisePvdByCentralKitchenForFactory: | |||
break | |||
case enum.EnterprisePvdBySelfSupportForSchool: | |||
break | |||
case enum.EnterprisePvdBySelfSupportForFactory: | |||
break | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": resp, | |||
"kind": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForSchool).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForFactory).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForFactory, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForSchool).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForFactory).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForFactory, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func UserIdentityList(c *gin.Context) { | |||
var req md.EnterpriseUserListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
var resp interface{} | |||
switch enterprise.Kind { | |||
case enum.EnterprisePvdByCentralKitchenForSchool: | |||
resp, err = svc2.EnterpriseUserListByCentralKitchenForSchool(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
break | |||
case enum.EnterprisePvdByCentralKitchenForFactory: | |||
break | |||
case enum.EnterprisePvdBySelfSupportForSchool: | |||
break | |||
case enum.EnterprisePvdBySelfSupportForFactory: | |||
break | |||
} | |||
e.OutSuc(c, resp, nil) | |||
return | |||
} |
@@ -0,0 +1,13 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/svc" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func UserInfo(c *gin.Context) { | |||
admInfo := svc.GetUser(c) | |||
e.OutSuc(c, admInfo, nil) | |||
return | |||
} |
@@ -0,0 +1,91 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
svc2 "applet/app/admin/svc/order" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func CentralKitchenForSchoolOrderRefundList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrderRefundListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
list, total, err := svc2.CentralKitchenForSchoolOrderRefundList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"total": total, | |||
"audit_kind_list": []map[string]interface{}{ | |||
{ | |||
"name": "同意", | |||
"value": 1, | |||
}, | |||
{ | |||
"name": "拒绝", | |||
"value": 2, | |||
}, | |||
}, | |||
"kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForLunch, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForDinner, | |||
}, | |||
}, | |||
"state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefundAudit(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrderRefundAuditReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc2.CentralKitchenForSchoolOrderRefundAudit(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,135 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func BannerList(c *gin.Context) { | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
banners, err := bannerDb.FindBanner(0, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": banners, | |||
}, nil) | |||
return | |||
} | |||
func BannerSort(c *gin.Context) { | |||
var args struct { | |||
Ids []string `json:"ids" binding:"required"` | |||
} | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
banners, err := bannerDb.FindBannerById(args.Ids) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
for k, v := range *banners { | |||
v.Sort = k | |||
_, err1 := bannerDb.BannerUpdate(&v, "sort") | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
} | |||
func BannerAdd(c *gin.Context) { | |||
var req md.BannerAddReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
now := time.Now() | |||
banner := model.Banner{ | |||
Name: req.Name, | |||
ImgUrl: req.ImgUrl, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
_, err = bannerDb.BannerInsert(&banner) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func BannerUpdate(c *gin.Context) { | |||
var req md.BannerUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
banner, err := bannerDb.GetBanner(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if banner == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
now := time.Now() | |||
banner.Name = req.Name | |||
banner.ImgUrl = req.ImgUrl | |||
banner.UpdateAt = now | |||
_, err = bannerDb.BannerUpdate(banner, "name", "content", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func BannerDelete(c *gin.Context) { | |||
id := c.Param("id") | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
company, err := bannerDb.GetBanner(utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if company == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
_, err = bannerDb.BannerDelete(id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,127 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/enum" | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func CompanyList(c *gin.Context) { | |||
companyDb := db.CompanyDb{} | |||
companyDb.Set() | |||
companies, err := companyDb.FindCompany(0, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": companies, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": "正常", | |||
"value": enum.CompanyStateForNormal, | |||
}, | |||
{ | |||
"name": "冻结", | |||
"value": enum.CompanyStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CompanyAdd(c *gin.Context) { | |||
var req md.CompanyAddReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
companyDb := db.CompanyDb{} | |||
companyDb.Set() | |||
now := time.Now() | |||
company := model.Company{ | |||
Name: req.Name, | |||
State: enum.CompanyStateForNormal, | |||
Memo: req.Memo, | |||
LeadName: req.LeadName, | |||
LeadPhone: req.LeadPhone, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
_, err = companyDb.CompanyInsert(&company) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CompanyUpdate(c *gin.Context) { | |||
var req md.CompanyUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
companyDb := db.CompanyDb{} | |||
companyDb.Set() | |||
company, err := companyDb.GetCompany(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if company == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
now := time.Now() | |||
company.Name = req.Name | |||
company.LeadName = req.LeadName | |||
company.LeadPhone = req.LeadPhone | |||
if req.State != 0 { | |||
company.State = req.State | |||
} | |||
company.UpdateAt = now | |||
_, err = companyDb.CompanyUpdate(company, "name", "memo", "state", "lead_name", "lead_phone", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CompanyDelete(c *gin.Context) { | |||
id := c.Param("id") | |||
companyDb := db.CompanyDb{} | |||
companyDb.Set() | |||
company, err := companyDb.GetCompany(utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if company == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
_, err = companyDb.CompanyDelete(id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,19 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// Demo 测试 | |||
func Demo(c *gin.Context) { | |||
qrcodeWithBatchRecordsDb := db.AdminDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
data, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(1001) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, data, nil) | |||
} |
@@ -0,0 +1,323 @@ | |||
package hdl | |||
import ( | |||
enum2 "applet/app/admin/enum" | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func EnterpriseList(c *gin.Context) { | |||
var req md.EnterpriseListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
if req.Limit == 0 { | |||
req.Limit = 10 | |||
} | |||
if req.Page == 0 { | |||
req.Page = 10 | |||
} | |||
enterprises, total, err := svc.EnterpriseList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": enterprises, | |||
"total": total, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterpriseState(enum.EnterpriseStateForNormal).String(), | |||
"value": enum.EnterpriseStateForNormal, | |||
}, | |||
{ | |||
"name": enum.EnterpriseState(enum.EnterpriseStateForFreeze).String(), | |||
"value": enum.EnterpriseStateForFreeze, | |||
}, | |||
}, | |||
"kind": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForSchool).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForFactory).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForFactory, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForSchool).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForFactory).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForFactory, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func Detail(c *gin.Context) { | |||
enterpriseId := c.DefaultQuery("id", "") | |||
detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, detail, nil) | |||
return | |||
} | |||
func SchoolBelowGrade(c *gin.Context) { | |||
enterpriseId := c.DefaultQuery("enterprise_id", "") | |||
gradeDb := db.GradeDb{} | |||
gradeDb.Set(utils.StrToInt(enterpriseId)) | |||
gradeList, err := gradeDb.FindGrade() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": gradeList, | |||
}, nil) | |||
return | |||
} | |||
func SchoolGradeBelowClass(c *gin.Context) { | |||
gradeId := c.DefaultQuery("grade_id", "") | |||
classDb := db.ClassDb{} | |||
classDb.Set(utils.StrToInt(gradeId)) | |||
classList, err := classDb.FindClass() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": classList, | |||
}, nil) | |||
return | |||
} | |||
func EnterpriseAdd(c *gin.Context) { | |||
var req md.EnterpriseAddReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
now := time.Now() | |||
var pvd = 2 | |||
if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory { | |||
pvd = 1 | |||
} | |||
enterprise := model.Enterprise{ | |||
Name: req.Name, | |||
Pvd: int32(pvd), | |||
Kind: req.Kind, | |||
CompanyId: req.CompanyId, | |||
State: enum2.CompanyStateForNormal, | |||
Memo: req.Memo, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
_, err = enterpriseDb.EnterpriseInsert(&enterprise) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func EnterpriseDelete(c *gin.Context) { | |||
var req md.EnterpriseDeleteReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.EnterpriseDelete(req.EnterpriseIds) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func EnterpriseUpdate(c *gin.Context) { | |||
var req md.EnterpriseUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
//1、更新 enterprise | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
var pvd = 2 | |||
if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory { | |||
pvd = 1 | |||
} | |||
now := time.Now() | |||
enterprise.Name = req.Name | |||
enterprise.Memo = req.Memo | |||
enterprise.Pvd = int32(pvd) | |||
enterprise.Kind = req.Kind | |||
enterprise.CompanyId = req.CompanyId | |||
enterprise.UpdateAt = now | |||
_, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//2、删除 grade && class 数据 | |||
gradeDb := db.GradeDb{} | |||
gradeDb.Set(req.Id) | |||
_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
classDb := db.ClassDb{} | |||
classDb.Set(0) | |||
_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//新增 grade 数据 && class 数据 | |||
for _, v := range req.GradeList { | |||
insertId, err1 := gradeDb.GradeInsert(&model.Grade{ | |||
EnterpriseId: req.Id, | |||
Name: v.Name, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
var classes []*model.Class | |||
for _, v1 := range v.ClassList { | |||
classes = append(classes, &model.Class{ | |||
Name: v1.Name, | |||
Memo: "", | |||
GradeId: insertId, | |||
EnterpriseId: req.Id, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
} | |||
if len(classes) > 0 { | |||
_, err2 := classDb.BatchAddClass(classes) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func EnterpriseAddGrade(c *gin.Context) { | |||
var req md.EnterpriseUpdateStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
now := time.Now() | |||
enterprise.State = req.State | |||
enterprise.UpdateAt = now | |||
_, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func EnterpriseUpdateState(c *gin.Context) { | |||
var req md.EnterpriseUpdateStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
now := time.Now() | |||
enterprise.State = req.State | |||
enterprise.UpdateAt = now | |||
_, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,50 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"github.com/mcuadros/go-defaults" | |||
) | |||
func ImgReqUpload(c *gin.Context) { | |||
var args struct { | |||
DirName string `json:"dir_name,omitempty" default:"0"` | |||
FileName string `json:"file_name" binding:"required" label:"文件名"` | |||
FileSize int64 `json:"file_size" binding:"gt=1" label:"文件大小"` // 文件大小, 单位byte | |||
} | |||
defaults.SetDefaults(&args) | |||
err := c.ShouldBindJSON(&args) | |||
if err != nil { | |||
err = svc.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
scheme := "http" | |||
if c.Request.TLS != nil { | |||
scheme = "https" | |||
} | |||
// 拼装回调地址 | |||
callbackUrl := scheme + "://" + c.Request.Host + "/api/file/upload/callback" | |||
if true { // 本地使用内网穿透地址测试 | |||
callbackUrl = "" | |||
} | |||
res, err := svc.ImgReqUpload("", args.DirName, args.FileName, callbackUrl, args.FileSize) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_BAD_REQUEST, err.Error()) | |||
return | |||
} | |||
my := utils.SerializeStr(res) | |||
var my1 map[string]interface{} | |||
utils.Unserialize([]byte(my), &my1) | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
my1["host"] = sysCfgDb.SysCfgGetWithDb(enum.FileBucketRegion) | |||
e.OutSuc(c, my1, nil) | |||
} |
@@ -0,0 +1,45 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
md2 "applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func Login(c *gin.Context) { | |||
var req md2.LoginReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
admin, err := adminDb.GetAdminByUserName(req.UserName) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err) | |||
return | |||
} | |||
if utils.Md5(req.PassWord) != admin.Password { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, "密码错误") | |||
return | |||
} | |||
ip := utils.GetIP(c.Request) | |||
key := fmt.Sprintf(md2.AdminJwtTokenKey, ip, utils.AnyToString(admin.AdmId)) | |||
token, err := svc.HandleLoginToken(key, admin) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, md2.LoginResponse{ | |||
Token: token, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,135 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func NoticeList(c *gin.Context) { | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
notices, err := noticeDb.FindNotice(0, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": notices, | |||
}, nil) | |||
return | |||
} | |||
func NoticeSort(c *gin.Context) { | |||
var args struct { | |||
Ids []string `json:"ids" binding:"required"` | |||
} | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
notices, err := noticeDb.FindNoticeById(args.Ids) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
for k, v := range *notices { | |||
v.Sort = k | |||
_, err1 := noticeDb.NoticeUpdate(&v, "sort") | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
} | |||
func NoticeAdd(c *gin.Context) { | |||
var req md.NoticeAddReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
now := time.Now() | |||
notice := model.Notice{ | |||
Name: req.Name, | |||
Content: req.Content, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
_, err = noticeDb.NoticeInsert(¬ice) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func NoticeUpdate(c *gin.Context) { | |||
var req md.NoticeUpdateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
notice, err := noticeDb.GetNotice(req.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if notice == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
now := time.Now() | |||
notice.Name = req.Name | |||
notice.Content = req.Content | |||
notice.UpdateAt = now | |||
_, err = noticeDb.NoticeUpdate(notice, "name", "content", "update_at") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func NoticeDelete(c *gin.Context) { | |||
id := c.Param("id") | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
company, err := noticeDb.GetNotice(utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if company == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
_, err = noticeDb.NoticeDelete(id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,479 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/enum" | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func PermissionGroupList(c *gin.Context) { | |||
roleId := c.DefaultQuery("role_id", "") | |||
qrcodeWithBatchRecordsDb := db.PermissionGroupDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(0) | |||
list, _, err := roleDb.FindPermissionGroupByRole(utils.StrToInt(roleId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var isHasPermissionGroupId []string | |||
for _, v := range list { | |||
isHasPermissionGroupId = append(isHasPermissionGroupId, utils.IntToStr(v.PermissionGroup.Id)) | |||
} | |||
var tempResp = map[string]*md.PermissionGroupListResp{} | |||
for _, v := range *groupList { | |||
isCheck := false | |||
if utils.InArr(utils.IntToStr(v.Id), isHasPermissionGroupId) { | |||
isCheck = true | |||
} | |||
tempResp[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{ | |||
Id: v.Id, | |||
Name: v.Name, | |||
State: v.State, | |||
ParentId: v.ParentId, | |||
CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"), | |||
UpdateAt: v.UpdateAt.Format("2006-01-02 15:04:05"), | |||
IsCheck: isCheck, | |||
} | |||
} | |||
var resp []md.PermissionGroupListResp | |||
for _, v := range tempResp { | |||
if v.ParentId != 0 { | |||
tempResp[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempResp[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v) | |||
} else { | |||
resp = append(resp, *v) | |||
} | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(), | |||
"value": enum.PermissionGroupStateForNormal, | |||
}, | |||
{ | |||
"name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(), | |||
"value": enum.PermissionGroupStateForDiscard, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func RoleList(c *gin.Context) { | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(0) | |||
roleList, err := roleDb.FindRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
adminRoleDb := db.AdminRoleDb{} | |||
adminRoleDb.Set() | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
var result []*md.RoleListResp | |||
for _, v := range *roleList { | |||
var temp md.RoleListResp | |||
temp.Data = v | |||
adminRole, err := adminRoleDb.GetAdminRoleByRole(v.Id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if adminRole != nil { | |||
admin, err := adminDb.GetAdmin(adminRole.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
temp.AdminList = append(temp.AdminList, struct { | |||
Name string `json:"name"` | |||
}{ | |||
Name: admin.Username, | |||
}) | |||
} | |||
result = append(result, &temp) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": result, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func AddRole(c *gin.Context) { | |||
var req md.AddRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(0) | |||
now := time.Now() | |||
_, err = roleDb.RoleInsert(&model.Role{ | |||
Name: req.Name, | |||
State: enum.RoleStateForNormal, | |||
Memo: req.Memo, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func UpdateRole(c *gin.Context) { | |||
var req md.UpdateRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(req.RoleId) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
role.Name = req.Name | |||
role.Memo = req.Memo | |||
_, err = roleDb.UpdateRole(role, "name", "memo") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func RoleBindPermissionGroup(c *gin.Context) { | |||
var req md.RoleBindPermissionGroupReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.RoleBindPermissionGroup(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func UpdateRoleState(c *gin.Context) { | |||
var req md.UpdateRoleStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(req.RoleId) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
role.State = req.State | |||
_, err = roleDb.UpdateRole(role, "state") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func DeleteRole(c *gin.Context) { | |||
id := c.Param("id") | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(utils.StrToInt(id)) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
err = svc.DeleteRole(utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func AdminList(c *gin.Context) { | |||
var req md.AdminListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
if req.Limit == 0 { | |||
req.Limit = 10 | |||
} | |||
if req.Page == 0 { | |||
req.Page = 10 | |||
} | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
adminList, total, err := adminDb.FindAdmin(req.UserName, req.State, req.Page, req.Limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var result []md.AdminListResp | |||
for _, v := range adminList { | |||
permissionGroupList, _, err1 := adminDb.FindAdminRolePermissionGroup(v.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
var roleList []string | |||
for _, v1 := range permissionGroupList { | |||
roleList = append(roleList, v1.Role.Name) | |||
} | |||
result = append(result, md.AdminListResp{ | |||
AdmId: v.AdmId, | |||
Username: v.Username, | |||
State: v.State, | |||
IsSuperAdministrator: v.IsSuperAdministrator, | |||
Memo: v.Memo, | |||
CreateAt: v.CreateAt, | |||
UpdateAt: v.UpdateAt, | |||
RoleList: roleList, | |||
}) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": result, | |||
"total": total, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func UpdateAdminState(c *gin.Context) { | |||
var req md.UpdateAdminStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
admDb := db.AdminDb{} | |||
admDb.Set() | |||
admin, err := admDb.GetAdmin(req.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if admin == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
admin.State = req.State | |||
_, err = admDb.UpdateAdmin(admin, "state") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func UpdateAdmin(c *gin.Context) { | |||
var req md.UpdateAdminReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
admDb := db.AdminDb{} | |||
admDb.Set() | |||
admin, err := admDb.GetAdmin(req.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if admin == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
admin.Username = req.Username | |||
admin.Memo = req.Memo | |||
admin.Password = utils.Md5(req.Password) | |||
_, err = admDb.UpdateAdmin(admin, "username", "memo", "password") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func AddAdmin(c *gin.Context) { | |||
var req md.AddAdminReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
admDb := db.AdminDb{} | |||
admDb.Set() | |||
admId, err := admDb.CreateAdminId() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
admin := model.Admin{ | |||
AdmId: admId, | |||
Username: req.Username, | |||
Password: utils.Md5(req.Password), | |||
State: enum.AdminStateForNormal, | |||
IsSuperAdministrator: 0, | |||
Memo: req.Memo, | |||
CreateAt: time.Now().Format("2006-01-02 15:04:05"), | |||
UpdateAt: time.Now().Format("2006-01-02 15:04:05"), | |||
} | |||
_, err = admDb.AdminInsert(&admin) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func DeleteAdmin(c *gin.Context) { | |||
admId := c.Param("adm_id") | |||
admDb := db.AdminDb{} | |||
admDb.Set() | |||
err := svc.AdminDelete([]int{utils.StrToInt(admId)}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func BindAdminRole(c *gin.Context) { | |||
var req md.BindAdminRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.BindAdminRole(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func AdminInfo(c *gin.Context) { | |||
admId := c.DefaultQuery("adm_id", "") | |||
admDb := db.AdminDb{} | |||
admDb.Set() | |||
admin, err := admDb.GetAdmin(utils.StrToInt(admId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
admin.Password = "" | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": admin, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,36 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func SetCenter(c *gin.Context) { | |||
var req md.SetCenterReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
sysCfgDb.SysCfgUpdate(enum.AdministratorContactInfo, req.AdministratorContactInfo) | |||
sysCfgDb.SysCfgUpdate(enum.CentralKitchenForSchoolReserveMealTime, req.CentralKitchenForSchoolReserveMealTime) | |||
sysCfgDb.SysCfgUpdate(enum.CentralKitchenForSchoolCancelMealTime, req.CentralKitchenForSchoolCancelMealTime) | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func GetCenter(c *gin.Context) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
res := sysCfgDb.SysCfgFindWithDb(enum.AdministratorContactInfo, enum.CentralKitchenForSchoolReserveMealTime, enum.CentralKitchenForSchoolCancelMealTime) | |||
e.OutSuc(c, res, nil) | |||
return | |||
} |
@@ -0,0 +1,17 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GetSysCfg(c *gin.Context) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
res := sysCfgDb.SysCfgFindWithDb(enum.AppName, enum.OpenAppletPublicKey, enum.OpenAppletAppPublicKey, enum.OpenAppletAppPrivateKey, enum.OpenAppletAesKey, | |||
enum.FileBucket, enum.FileExt, enum.FileAccessKey, enum.FileUserUploadMaxSize, enum.FileSecretKey, enum.FileBucketScheme, enum.FileBucketRegion, enum.FileBucketHost) | |||
e.OutSuc(c, res, nil) | |||
return | |||
} |
@@ -0,0 +1,122 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func UserList(c *gin.Context) { | |||
var req md.UserListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
list, err := svc.UserList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"user_identity_kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent), | |||
"value": enum.UserIdentityForCentralKitchenForStudent, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher), | |||
"value": enum.UserIdentityForCentralKitchenForTeacher, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker), | |||
"value": enum.UserIdentityForCentralKitchenForWorker, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent), | |||
"value": enum.UserIdentityForSelfSupportForStudent, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher), | |||
"value": enum.UserIdentityForSelfSupportForTeacher, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker), | |||
"value": enum.UserIdentityForSelfSupportForWorker, | |||
}, | |||
}, | |||
"enterprise_kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForSchool), | |||
"value": enum.EnterprisePvdByCentralKitchenForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForFactory), | |||
"value": enum.EnterprisePvdByCentralKitchenForFactory, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForSchool), | |||
"value": enum.EnterprisePvdBySelfSupportForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForFactory), | |||
"value": enum.EnterprisePvdBySelfSupportForFactory, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func UserUpdate(c *gin.Context) { | |||
var req md.UserList | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.UserUpdate(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func UserDelete(c *gin.Context) { | |||
id := c.Param("id") | |||
//TODO::判断当前用户下是否还绑定了身份 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(utils.StrToInt(id)) | |||
identity, err := userIdentityDb.FindUserIdentity() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if len(*identity) > 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "当前用户下存在未解绑身份") | |||
return | |||
} | |||
userDb := db.UserDb{} | |||
userDb.Set() | |||
_, err = userDb.DeleteUser(utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,39 @@ | |||
package auth | |||
import ( | |||
"errors" | |||
"github.com/dgrijalva/jwt-go" | |||
"time" | |||
) | |||
// GenToken 生成JWT | |||
func GenToken(admId int, username string) (string, error) { | |||
// 创建一个我们自己的声明 | |||
c := JWTUser{ | |||
AdmId: admId, | |||
Username: username, | |||
StandardClaims: jwt.StandardClaims{ | |||
ExpiresAt: time.Now().Add(TokenExpireDuration).Unix(), // 过期时间 | |||
Issuer: "smart_canteen", // 签发人 | |||
}, | |||
} | |||
// 使用指定的签名方法创建签名对象 | |||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, c) | |||
// 使用指定的secret签名并获得完整的编码后的字符串token | |||
return token.SignedString(Secret) | |||
} | |||
// ParseToken 解析JWT | |||
func ParseToken(tokenString string) (*JWTUser, error) { | |||
// 解析token | |||
token, err := jwt.ParseWithClaims(tokenString, &JWTUser{}, func(token *jwt.Token) (i interface{}, err error) { | |||
return Secret, nil | |||
}) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if claims, ok := token.Claims.(*JWTUser); ok && token.Valid { // 校验token | |||
return claims, nil | |||
} | |||
return nil, errors.New("invalid token") | |||
} |
@@ -0,0 +1,19 @@ | |||
package auth | |||
import ( | |||
"time" | |||
"github.com/dgrijalva/jwt-go" | |||
) | |||
// TokenExpireDuration is jwt 过期时间 | |||
const TokenExpireDuration = time.Hour * 4380 | |||
var Secret = []byte("smart_canteen_admin") | |||
// JWTUser 如果想要保存更多信息,都可以添加到这个结构体中 | |||
type JWTUser struct { | |||
AdmId int `json:"adm_id"` | |||
Username string `json:"username"` | |||
jwt.StandardClaims | |||
} |
@@ -0,0 +1,33 @@ | |||
package validate | |||
import ( | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/go-playground/validator/v10" | |||
) | |||
func HandleValidateErr(err error) error { | |||
switch err.(type) { | |||
case *json.UnmarshalTypeError: | |||
return e.NewErr(e.ERR_UNMARSHAL, "参数格式错误") | |||
case validator.ValidationErrors: | |||
errs := err.(validator.ValidationErrors) | |||
transMsgMap := errs.Translate(utils.ValidatorTrans) // utils.ValidatorTrans \app\utils\validator_err_trans.go::ValidatorTransInit初始化获得 | |||
transMsgOne := transMsgMap[GetOneKeyOfMapString(transMsgMap)] | |||
return e.NewErr(e.ERR_INVALID_ARGS, transMsgOne) | |||
default: | |||
_ = logx.Error(err) | |||
return e.NewErr(e.ERR, fmt.Sprintf("validate request params, err:%v\n", err)) | |||
} | |||
} | |||
// GetOneKeyOfMapString 取出Map的一个key | |||
func GetOneKeyOfMapString(collection map[string]string) string { | |||
for k := range collection { | |||
return k | |||
} | |||
return "" | |||
} |
@@ -0,0 +1,85 @@ | |||
package wx | |||
import ( | |||
"applet/app/admin/db" | |||
enum2 "applet/app/admin/enum" | |||
md2 "applet/app/admin/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"encoding/json" | |||
"errors" | |||
) | |||
type OfficialAccount struct { | |||
AccessToken string `json:"access_token"` | |||
Appid string `json:"appid"` | |||
Secret string `json:"secret"` | |||
} | |||
func (officialAccount *OfficialAccount) Set() { // set方法 | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
officialAccount.Appid = sysCfgDb.SysCfgGetWithDb(enum2.WxOfficialAccountAppId) | |||
officialAccount.Secret = sysCfgDb.SysCfgGetWithDb(enum2.WxOfficialAccountAppSecret) | |||
officialAccount.AccessToken = officialAccount.createToken() | |||
} | |||
func (officialAccount *OfficialAccount) createToken() (accessToken string) { | |||
cacheKey := md2.WxOfficialAccountCacheKey | |||
accessToken, _ = cache.GetString(cacheKey) | |||
if accessToken != "" { | |||
return | |||
} | |||
url := md2.WxOfficialAccountRequestBaseUrl + enum2.GetAccessToken | |||
post, err := utils.CurlPost(url, map[string]string{ | |||
"appid": officialAccount.Appid, | |||
"secret": officialAccount.Secret, | |||
"grant_type": "client_credential", | |||
}, nil) | |||
utils.FilePutContents("wx_official_account_create_token", "resp"+string(post)) | |||
var data md2.CreateTokenResp | |||
err = json.Unmarshal(post, &data) | |||
if err != nil { | |||
return | |||
} | |||
if data.AccessToken == "" { | |||
panic(errors.New("获取 access_token 失败")) | |||
} | |||
accessToken = data.AccessToken | |||
cache.SetEx(cacheKey, accessToken, int(data.ExpiresIn-3600)) | |||
return | |||
} | |||
func (officialAccount *OfficialAccount) QrcodeCreate(sceneStr string) (qrcodeUrl string, err error) { | |||
url := md2.WxOfficialAccountRequestBaseUrl + enum2.QrcodeCreate + "?access_token=" + officialAccount.AccessToken | |||
//post, err := utils.CurlPost(url, map[string]interface{}{ | |||
// "action_name": "QR_LIMIT_STR_SCENE", | |||
// "action_info": map[string]interface{}{ | |||
// "scene": map[string]string{ | |||
// "scene_str": sceneStr, | |||
// }, | |||
// }, | |||
//}, nil) | |||
requestBody, _ := json.Marshal(map[string]interface{}{ | |||
"action_name": "QR_STR_SCENE", | |||
"expire_seconds": "6000", | |||
"action_info": map[string]interface{}{ | |||
"scene": map[string]string{ | |||
"scene_str": sceneStr, | |||
}, | |||
}, | |||
}) | |||
post, err := utils.CurlPost(url, requestBody, nil) | |||
utils.FilePutContents("wx_official_account_qrcode_create", "resp"+string(post)) | |||
var data md2.CreateQrcodeResp | |||
err = json.Unmarshal(post, &data) | |||
if err != nil { | |||
return | |||
} | |||
qrcodeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + data.Ticket | |||
return | |||
} |
@@ -0,0 +1,12 @@ | |||
package md | |||
// 缓存key统一管理 | |||
const ( | |||
AdminJwtTokenKey = "%s:smart_canteen_admin_jwt_token:%s" // jwt, 占位符:ip, admin:id | |||
JwtTokenCacheTime = 3600 * 24 | |||
AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id | |||
AdminRolePermissionCacheTime = 3600 * 24 * 0.5 | |||
CfgCacheTime = 86400 | |||
AppCfgCacheKey = "one_item_one_code:%s" // 占位符: key的第一个字母 | |||
WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 | |||
) |
@@ -0,0 +1,12 @@ | |||
package md | |||
type BannerAddReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
ImgUrl string `json:"img_url" label:"内容"` | |||
} | |||
type BannerUpdateReq struct { | |||
Id int `json:"id" binding:"required" label:"公司id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
ImgUrl string `json:"img_url" label:"内容"` | |||
} |
@@ -0,0 +1,18 @@ | |||
package md | |||
type CentralKitchenForSchoolInfoResp struct { | |||
Name string `json:"name" label:"名称"` | |||
Memo string `json:"memo" label:"备注"` | |||
Kind string `json:"kind" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂)"` | |||
State string `json:"state" label:"状态(1:正常 2:冻结)"` | |||
IsOpenTeacherReportMeal int `json:"is_open_teacher_report_meal" label:"教师报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForDay int `json:"is_open_report_meal_for_day" label:"开启按天报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForMonth int `json:"is_open_report_meal_for_month" label:"开启按月报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForSemester int `json:"is_open_report_meal_for_semester" label:"开启按学期报餐(1:开启 2:关闭)"` | |||
IsOpenBreakfast int `json:"is_open_breakfast" label:"是否开启早餐(1:开启 0:关闭)"` | |||
IsOpenLunch int `json:"is_open_lunch" label:"是否开启午餐(1:开启 0:关闭)"` | |||
IsOpenDinner int `json:"is_open_dinner" label:"是否开启晚餐(1:开启 0:关闭)"` | |||
TeacherNum int64 `json:"teacher_num" label:"教师数量"` | |||
StudentNum int64 `json:"student_num" label:"学生数量"` | |||
ClassNum int64 `json:"class_num" label:"班级数量"` | |||
} |
@@ -0,0 +1,39 @@ | |||
package md | |||
type CentralKitchenForSchoolOrderRefundListResp struct { | |||
Id int `json:"id" label:"退款id"` | |||
OutTradeNo string `json:"out_trade_no" label:"订单号"` | |||
OutRequestNo string `json:"out_request_no" label:"退款请求号"` | |||
Name string `json:"name" label:"姓名"` | |||
Phone string `json:"phone" label:"用户电话"` | |||
EnterpriseName string `json:"enterprise_name" label:"学校名称"` | |||
ClassName string `json:"class_name" label:"班级名称"` | |||
GradeName string `json:"grade_name" label:"年纪名称"` | |||
Kind int `json:"kind" label:"订餐类型"` | |||
Amount string `json:"amount" label:"退款金额"` | |||
State int `json:"state" label:"退款订单状态"` | |||
CreateAt string `json:"create_at" label:"申请时间"` | |||
Memo string `json:"memo" label:"备注"` | |||
} | |||
type CentralKitchenForSchoolOrderRefundListReq struct { | |||
EnterpriseId int `json:"enterprise_id" label:"单位id"` | |||
Phone string `json:"phone" label:"用户电话"` | |||
Name string `json:"name" label:"名称"` | |||
Kind int `json:"kind" label:"订餐类型"` | |||
State int `json:"state" label:"退款订单状态"` | |||
StartDate string `json:"start_date" label:"开始时间"` | |||
EndDate string `json:"end_date" label:"截止时间"` | |||
OutTradeNo string `json:"out_trade_no" label:"订单号"` | |||
OutRequestNo string `json:"out_request_no" label:"退款请求号"` | |||
GradeId int `json:"grade_id" label:"年级"` | |||
ClassId int `json:"class_id" label:"班级"` | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
} | |||
type CentralKitchenForSchoolOrderRefundAuditReq struct { | |||
Ids []string `json:"ids" label:"退款记录id"` | |||
State int `json:"state" label:"审核状态"` | |||
Memo string `json:"memo" label:"备注"` | |||
} |
@@ -0,0 +1,6 @@ | |||
package md | |||
const ( | |||
OpenReplenish = 1 //开启-补餐 | |||
CloseReplenish = 0 //关闭-补餐 | |||
) |
@@ -0,0 +1,10 @@ | |||
package md | |||
const ( | |||
OpenBreakfast = 1 //开启-早餐 | |||
CloseBreakfast = 0 //关闭-早餐 | |||
OpenLunch = 1 //开启-午餐 | |||
CloseLunch = 0 //关闭-午餐 | |||
OpenDinner = 1 //开启-晚餐 | |||
CloseDinner = 0 //关闭-晚餐 | |||
) |
@@ -0,0 +1,17 @@ | |||
package md | |||
type CompanyAddReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" label:"备注"` | |||
LeadName string `json:"lead_name" label:"负责人姓名"` | |||
LeadPhone string `json:"lead_phone" label:"负责人手机号"` | |||
} | |||
type CompanyUpdateReq struct { | |||
Id int `json:"id" binding:"required" label:"公司id"` | |||
State int32 `json:"state" label:"状态"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
LeadName string `json:"lead_name" label:"负责人姓名"` | |||
LeadPhone string `json:"lead_phone" label:"负责人手机号"` | |||
} |
@@ -0,0 +1,53 @@ | |||
package md | |||
import "applet/app/db/model" | |||
type EnterpriseAddReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Pvd int32 `json:"pvd" label:"场景"` | |||
Kind int32 `json:"kind" binding:"required" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂)"` | |||
CompanyId int `json:"company_id" binding:"required" label:"所属公司id"` | |||
Memo string `json:"memo" label:"备注"` | |||
} | |||
type EnterpriseUpdateReq struct { | |||
Id int `json:"id" binding:"required" label:"企业id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Pvd int32 `json:"pvd" label:"场景"` | |||
Kind int32 `json:"kind" binding:"required" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂)"` | |||
CompanyId int `json:"company_id" binding:"required" label:"所属公司id"` | |||
Memo string `json:"memo" label:"备注"` | |||
State int32 `json:"state" label:"状态"` | |||
GradeList []struct { | |||
Name string `json:"name" label:"名称"` | |||
ClassList []struct { | |||
Name string `json:"name" label:"名称"` | |||
} `json:"class_list" label:"班级"` | |||
} `json:"grade_list" label:"年级"` | |||
} | |||
type EnterpriseDeleteReq struct { | |||
EnterpriseIds []int `json:"enterprise_ids"` | |||
} | |||
type EnterpriseUpdateStateReq struct { | |||
Id int `json:"id" binding:"required" label:"企业id"` | |||
State int32 `json:"state" label:"状态"` | |||
} | |||
type EnterpriseListReq struct { | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
Name string `json:"name" label:"名称"` | |||
Kind int `json:"kind" label:"种类"` | |||
} | |||
type EnterpriseDetailResp struct { | |||
Enterprise model.Enterprise `json:"enterprise"` | |||
GradeList []GradeListStruct `json:"grade_list"` | |||
} | |||
type GradeListStruct struct { | |||
Grade model.Grade `json:"grade"` | |||
ClassList []model.Class `json:"class_list"` | |||
} |
@@ -0,0 +1,206 @@ | |||
package md | |||
type EnterpriseUserListReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Limit int `json:"limit" binding:"required"` | |||
Page int `json:"page" binding:"required"` | |||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||
Phone string `json:"phone" label:"手机号"` | |||
IsTeacher int `json:"is_teacher" label:"是否教师"` | |||
} | |||
type EnterpriseUserListByCentralKitchenForSchoolStruct struct { | |||
Id int `json:"id" label:"支付宝昵称"` | |||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||
Phone string `json:"phone" label:"手机号"` | |||
Avatar string `json:"avatar" label:"头像"` | |||
IsTeacher int `json:"is_teacher" label:"是否教师"` | |||
CreateAt string `json:"create_at" label:"创建时间"` | |||
UserIdentities []struct { | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
SchoolName string `json:"school_name" label:"学校名"` | |||
Name string `json:"name" label:"姓名"` | |||
Grade string `json:"grade" label:"年级"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
Class string `json:"class" label:"班级"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} `json:"user_identities" label:"身份列表"` | |||
} | |||
type EnterpriseUserListByCentralKitchenForSchoolResp struct { | |||
List []EnterpriseUserListByCentralKitchenForSchoolStruct `json:"list"` | |||
Total int64 `json:"total"` | |||
} | |||
type CentralKitchenForSchoolUserUpdateReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Uid int `json:"uid" binding:"required" label:"用户id"` | |||
Nickname string `json:"nickname" binding:"required" label:"支付宝昵称"` | |||
Phone string `json:"phone" binding:"required" label:"手机号"` | |||
BindUserIdentities []struct { | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Name string `json:"name" label:"姓名"` | |||
GradeId int `json:"grade_id" label:"年级"` | |||
ClassId int `json:"class_id" label:"班级"` | |||
} `json:"user_identities" label:"身份列表"` | |||
} | |||
type CentralKitchenForSchoolUserDeleteReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Uids []int `json:"uids" binding:"required" label:"用户id"` | |||
} | |||
type CentralKitchenForSchoolStudentListReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Limit int `json:"limit" binding:"required"` | |||
Page int `json:"page" binding:"required"` | |||
Name string `json:"name" label:"姓名"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Phone string `json:"phone" label:"手机号"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} | |||
type CentralKitchenForSchoolTeacherListReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Limit int `json:"limit" binding:"required"` | |||
Page int `json:"page" binding:"required"` | |||
Name string `json:"name" label:"姓名"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
} | |||
type CentralKitchenForSchoolStudentListResp struct { | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
ParentPhone string `json:"parent_phone" label:"家长电话"` | |||
Name string `json:"name" label:"姓名"` | |||
Grade string `json:"grade" label:"年级"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
Class string `json:"class" label:"班级"` | |||
ClassId int `json:"class_id" label:"班级"` | |||
UserIdentityId int `json:"user_identity_id" label:"用户身份id"` | |||
} | |||
type CentralKitchenForSchoolTeacherListResp struct { | |||
UserIdentityId int `json:"user_identity_id" label:"用户身份id"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Phone string `json:"parent_phone" label:"电话"` | |||
Name string `json:"name" label:"姓名"` | |||
} | |||
type CentralKitchenForSchoolTeacherUpdateReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
UserIdentityId int `json:"user_identity_id" binding:"required" label:"用户身份id"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Name string `json:"name" label:"姓名"` | |||
} | |||
type CentralKitchenForSchoolStudentUpdateReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
UserIdentityId int `json:"user_identity_id" binding:"required" label:"用户身份id"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Name string `json:"name" label:"姓名"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} | |||
type CentralKitchenForSchoolStudentDeleteReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
UserIdentityIds []int `json:"user_identity_ids" binding:"required" label:"用户身份id"` | |||
} | |||
type CentralKitchenForSchoolTeacherDeleteReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
UserIdentityIds []int `json:"user_identity_ids" binding:"required" label:"用户身份id"` | |||
} | |||
type CentralKitchenForSchoolStudentAdmissionReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
ClassId int `json:"class_id" binding:"required" label:"班级id"` | |||
GradeId int `json:"grade_id" binding:"required" label:"年级id"` | |||
} | |||
type SetCentralKitchenForSchoolWithSpecReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
BreakfastUnitPrice string `json:"breakfast_unit_price" binding:"required" label:"早餐-单价"` | |||
BreakfastUnitPriceForTeacher string `json:"breakfast_unit_price_for_teacher" binding:"required" label:"教师-早餐-单价"` | |||
LunchUnitPrice string `json:"lunch_unit_price" binding:"required" label:"午餐-单价"` | |||
LunchUnitPriceForTeacher string `json:"lunch_unit_price_for_teacher" binding:"required" label:"教师-午餐-单价"` | |||
DinnerUnitPrice string `json:"dinner_unit_price" binding:"required" label:"晚餐-单价"` | |||
DinnerUnitPriceForTeacher string `json:"dinner_unit_price_for_teacher" binding:"required" label:"教师-晚餐-单价"` | |||
} | |||
type SaveCentralKitchenForSchoolPackageReq struct { | |||
PackageId int `json:"package_id" label:"套餐ID"` | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Year string `json:"year" binding:"required" label:"年份"` | |||
Month string `json:"month" binding:"required" label:"月份"` | |||
StartDate string `json:"start_date" binding:"required" label:"开始时间"` | |||
EndDate string `json:"end_date" binding:"required" label:"截止时间"` | |||
State int `json:"state" label:"状态(1:可用 2:不可用)"` | |||
DateList []struct { | |||
Date string `json:"date"` | |||
IsOpenBreakfast int32 `json:"is_open_breakfast"` | |||
IsOpenLunch int32 `json:"is_open_lunch"` | |||
IsOpenDinner int32 `json:"is_open_dinner"` | |||
IsOpenReplenish int32 `json:"is_open_replenish"` | |||
} `json:"date_list" binding:"required" label:"日期"` | |||
} | |||
type SetBasicCentralKitchenForSchoolReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
State int32 `json:"state" label:"状态(1:正常 2:冻结)"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
IsOpenBreakfast int `json:"is_open_breakfast" label:"是否开启早餐"` | |||
IsOpenLunch int `json:"is_open_lunch" label:"是否开启午餐"` | |||
IsOpenDinner int `json:"is_open_dinner" label:"是否开启晚餐"` | |||
IsOpenReportMealForDay int `json:"is_open_report_meal_for_day" label:"开启按天报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForMonth int `json:"is_open_report_meal_for_month" label:"开启按月报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForSemester int `json:"is_open_report_meal_for_semester" label:"开启按学期报餐(1:开启 2:关闭)"` | |||
IsOpenTeacherReportMeal int `json:"is_open_teacher_report_meal" label:"'教师报餐(1:开启 2:关闭)"` | |||
} | |||
type ListCentralKitchenForSchoolPackageReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Page int `json:"page" label:"页码"` | |||
Limit int `json:"limit" label:"每页数量"` | |||
Year string `json:"year" label:"年份"` | |||
Month string `json:"month" label:"月份"` | |||
} | |||
type CentralKitchenForSchoolOrdRefundReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Ids []string `json:"ids" label:"ids" binding:"required"` | |||
} | |||
type CentralKitchenForSchoolOrdListResp struct { | |||
EnterpriseId int `json:"enterprise_id" ` | |||
Uid int `json:"uid" ` | |||
UserIdentityId int `json:"user_identity_id" ` | |||
TotalPrice string `json:"total_price" ` | |||
Kind int `json:"kind" ` | |||
OutTradeNo string `json:"out_trade_no" ` | |||
TradeNo string `json:"trade_no"` | |||
State int `json:"state"` | |||
OrdState int `json:"ord_state"` | |||
CreateAt string `json:"create_at"` | |||
Name string `json:"name" label:"姓名"` | |||
Grade string `json:"grade" label:"年级"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
Class string `json:"class" label:"班级"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} | |||
type CentralKitchenForSchoolOrdListReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Limit int `json:"limit" binding:"required"` | |||
Page int `json:"page" binding:"required"` | |||
Name string `json:"name" label:"姓名"` | |||
OutTradeNo string `json:"out_trade_no" label:"订单号"` | |||
Kind int `json:"kind" label:"预定类型"` | |||
Sate int `json:"state" label:"支付状态"` | |||
OrdSate int `json:"ord_state" label:"订单状态"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
StartDate string `json:"start_date" label:"开始时间"` | |||
EndDate string `json:"end_date" label:"截止时间"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package md | |||
type LoginReq struct { | |||
UserName string `json:"username" binding:"required" label:"登录账号"` | |||
PassWord string `json:"password" binding:"required" label:"登录密码"` | |||
} | |||
type LoginResponse struct { | |||
Token string `json:"token"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package md | |||
type NoticeAddReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Content string `json:"content" label:"内容"` | |||
} | |||
type NoticeUpdateReq struct { | |||
Id int `json:"id" binding:"required" label:"公司id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Content string `json:"content" label:"内容"` | |||
} |
@@ -0,0 +1,31 @@ | |||
package md | |||
const ( | |||
QrcodeTotalNums = 100000 | |||
) | |||
type QrcodeBatchListReq struct { | |||
Page int `json:"page"` | |||
Limit int `json:"limit"` | |||
} | |||
type QrcodeBatchAddReq struct { | |||
Name string `json:"name"` | |||
ExpireDate string `json:"expire_date"` | |||
List []QrcodeBatchAddReqList `json:"list"` | |||
Memo string `json:"memo"` | |||
} | |||
type QrcodeBatchAddReqList struct { | |||
Num int `json:"num"` | |||
Amount string `json:"amount"` | |||
} | |||
type QrcodeBatchAddReqListDetail struct { | |||
Num int `json:"num"` | |||
WaitUseNum int `json:"wait_use_num"` | |||
UsedNum int `json:"used_num"` | |||
ExpiredNum int `json:"expired_num"` | |||
CancelNum int `json:"cancel_num"` | |||
Amount string `json:"amount"` | |||
} |
@@ -0,0 +1,85 @@ | |||
package md | |||
import ( | |||
"applet/app/db/model" | |||
) | |||
type RoleListResp struct { | |||
Data model.Role `json:"data"` | |||
AdminList []struct { | |||
Name string `json:"name"` | |||
} `json:"admin_list"` | |||
} | |||
type UpdateRoleStateReq struct { | |||
RoleId int `json:"role_id" binding:"required" label:"id"` | |||
State int `json:"state" binding:"required" label:"状态"` | |||
} | |||
type AddRoleReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
} | |||
type UpdateRoleReq struct { | |||
RoleId int `json:"role_id" binding:"required" label:"id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
} | |||
type RoleBindPermissionGroupReq struct { | |||
RoleId int `json:"role_id" binding:"required" label:"id"` | |||
PermissionIds []int `json:"permission_ids" label:"权限组id"` | |||
} | |||
type PermissionGroupListResp struct { | |||
Id int `json:"id"` | |||
Name string `json:"name"` | |||
State int `json:"state"` | |||
ParentId int `json:"parent_id"` | |||
CreateAt string `json:"create_at"` | |||
UpdateAt string `json:"update_at"` | |||
IsCheck bool `json:"is_check"` | |||
SubPermissionGroupList []PermissionGroupListResp `json:"sub_permission_group_list"` | |||
} | |||
type AdminListReq struct { | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
UserName string `json:"username"` | |||
State int `json:"state"` | |||
} | |||
type AdminListResp struct { | |||
AdmId int `json:"adm_id"` | |||
Username string `json:"username"` | |||
State int32 `json:"state"` | |||
IsSuperAdministrator int32 `json:"is_super_administrator"` | |||
Memo string `json:"memo"` | |||
CreateAt string `json:"create_at"` | |||
UpdateAt string `json:"update_at"` | |||
RoleList []string `json:"role_list"` | |||
} | |||
type UpdateAdminStateReq struct { | |||
AdmId int `json:"adm_id" binding:"required" label:"管理员id"` | |||
State int32 `json:"state" binding:"required" label:"状态"` | |||
} | |||
type AddAdminReq struct { | |||
Username string `json:"username" binding:"required" label:"名称"` | |||
Password string `json:"password" binding:"required" label:"密码"` | |||
Memo string `json:"memo" label:"备注"` | |||
} | |||
type UpdateAdminReq struct { | |||
AdmId int `json:"adm_id" binding:"required" label:"管理员id"` | |||
Username string `json:"username" binding:"required" label:"名称"` | |||
Password string `json:"password" binding:"required" label:"密码"` | |||
Memo string `json:"memo" label:"备注"` | |||
} | |||
type BindAdminRoleReq struct { | |||
AdmId int `json:"adm_id" binding:"required" label:"管理员id"` | |||
RoleIds []int `json:"role_ids" label:"角色id"` | |||
} |
@@ -0,0 +1,7 @@ | |||
package md | |||
type SetCenterReq struct { | |||
AdministratorContactInfo string `json:"administrator_contact_info" binding:"required" label:"管理员联系方式"` | |||
CentralKitchenForSchoolReserveMealTime string `json:"central_kitchen_for_school_reserve_meal_time" binding:"required" label:"央厨预定用餐时间"` | |||
CentralKitchenForSchoolCancelMealTime string `json:"central_kitchen_for_school_cancel_meal_time" binding:"required" label:"央厨取消用餐时间"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package md | |||
type SetSysCfgReq struct { | |||
WxMchApiV3Key string `json:"wx_mch_api_v3_key" label:"微信商户APIv3密钥"` | |||
WxMchCertificateSerialNumber string `json:"wx_mch_certificate_serial_number" label:"微信商户证书序列号"` | |||
WxMchId string `json:"wx_mch_id" label:"微信商户号"` | |||
WxOfficialAccountAppId string `json:"wx_official_account_app_id" label:"微信公众号appId"` | |||
WxOfficialAccountAppSecret string `json:"wx_official_account_app_secret" label:"微信公众号appSecret"` | |||
} |
@@ -0,0 +1,30 @@ | |||
package md | |||
type UserListReq struct { | |||
Limit int `json:"limit" binding:"required"` | |||
Page int `json:"page" binding:"required"` | |||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||
Phone string `json:"phone" label:"手机号"` | |||
CreateTimeStart string `json:"create_time_start" label:"创建时间-起始"` | |||
CreateTimeEnd string `json:"create_time_end" label:"创建时间-截止"` | |||
} | |||
type UserListResp struct { | |||
List []UserList `json:"list"` | |||
Total int64 `json:"total"` | |||
} | |||
type UserList struct { | |||
Id int `json:"id" label:"id"` | |||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||
Phone string `json:"phone" label:"联系电话"` | |||
Avatar string `json:"avatar" label:"头像"` | |||
CreateAt string `json:"create_at" label:"创建时间"` | |||
BindUserIdentity []struct { | |||
Id int `json:"id" label:"id"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Name string `json:"name" label:"姓名"` | |||
EnterpriseName string `json:"enterprise_name" label:"企业名"` | |||
EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"` | |||
Kind int `json:"kind" label:"身份类型"` | |||
} `json:"bind_user_identity" label:"绑定身份"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package md | |||
const WxOfficialAccountRequestBaseUrl = "https://api.weixin.qq.com/" | |||
type CreateTokenResp struct { | |||
AccessToken string `json:"access_token"` | |||
ExpiresIn int64 `json:"expires_in"` | |||
} | |||
type CreateQrcodeResp struct { | |||
Ticket string `json:"ticket"` | |||
ExpireSeconds int64 `json:"expire_seconds"` | |||
Url string `json:"url"` | |||
} |
@@ -0,0 +1,26 @@ | |||
package mw | |||
import ( | |||
svc2 "applet/app/admin/svc" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// Auth 检查签名 | |||
func Auth(c *gin.Context) { | |||
admin, err := svc2.CheckUser(c) | |||
if err != nil { | |||
switch err.(type) { | |||
case e.E: | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
default: | |||
e.OutErr(c, e.ERR_TOKEN_AUTH, err.Error()) | |||
return | |||
} | |||
} | |||
// 将当前请求的username信息保存到请求的上下文c上 | |||
c.Set("admin", admin) | |||
c.Next() | |||
} |
@@ -0,0 +1,26 @@ | |||
package mw | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/admin/svc" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// CheckPermission 检查权限 | |||
func CheckPermission(c *gin.Context) { | |||
admin := svc.GetUser(c) | |||
rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, utils.GetIP(c.Request), utils.AnyToString(admin.AdmId)) | |||
isHasPermission, err := svc.CheckUserRole(rolePermissionKey, c.Request.RequestURI, admin.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
if !isHasPermission { | |||
e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员") | |||
return | |||
} | |||
c.Next() | |||
} |
@@ -0,0 +1,29 @@ | |||
package mw | |||
import ( | |||
"github.com/gin-gonic/gin" | |||
) | |||
// cors跨域 | |||
func Cors(c *gin.Context) { | |||
// 放行所有OPTIONS方法 | |||
if c.Request.Method == "OPTIONS" { | |||
c.AbortWithStatus(204) | |||
return | |||
} | |||
origin := c.Request.Header.Get("Origin") // 请求头部 | |||
if origin != "" { | |||
c.Header("Access-Control-Allow-Origin", origin) // 这是允许访问来源域 | |||
c.Header("Access-Control-Allow-Methods", "POST,GET,OPTIONS,PUT,DELETE,UPDATE") // 服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求 | |||
// header的类型 | |||
c.Header("Access-Control-Allow-Headers", "Authorization,Content-Length,X-CSRF-Token,Token,session,X_Requested_With,Accept,Origin,Host,Connection,Accept-Encoding,Accept-Language,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Pragma,X-Mx-ReqToken") | |||
// 允许跨域设置,可以返回其他子段 | |||
// 跨域关键设置 让浏览器可以解析 | |||
c.Header("Access-Control-Expose-Headers", "Content-Length,Access-Control-Allow-Origin,Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") | |||
c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒 | |||
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true | |||
c.Set("Content-Type", "Application/json") // 设置返回格式是json | |||
} | |||
c.Next() | |||
} |
@@ -0,0 +1,58 @@ | |||
package mw | |||
import ( | |||
"bytes" | |||
"io/ioutil" | |||
"github.com/gin-gonic/gin" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
) | |||
// 限流器 | |||
func Limiter(c *gin.Context) { | |||
limit := 100 // 限流次数 | |||
ttl := 1 // 限流过期时间 | |||
ip := c.ClientIP() | |||
// 读取token或者ip | |||
token := c.GetHeader("Authorization") | |||
// 判断是否已经超出限额次数 | |||
method := c.Request.Method | |||
host := c.Request.Host | |||
uri := c.Request.URL.String() | |||
buf := make([]byte, 2048) | |||
num, _ := c.Request.Body.Read(buf) | |||
body := buf[:num] | |||
// Write body back | |||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) | |||
Md5 := utils.Md5(ip + token + method + host + uri + string(body)) | |||
if cache.Exists(Md5) { | |||
c.AbortWithStatusJSON(429, gin.H{ | |||
"code": 429, | |||
"msg": "don't repeat the request", | |||
"data": struct{}{}, | |||
}) | |||
return | |||
} | |||
// 2s后没返回自动释放 | |||
go cache.SetEx(Md5, "0", ttl) | |||
key := "LIMITER_" + ip | |||
reqs, _ := cache.GetInt(key) | |||
if reqs >= limit { | |||
c.AbortWithStatusJSON(429, gin.H{ | |||
"code": 429, | |||
"msg": "too many requests", | |||
"data": struct{}{}, | |||
}) | |||
return | |||
} | |||
if reqs > 0 { | |||
go cache.Incr(key) | |||
} else { | |||
go cache.SetEx(key, 1, ttl) | |||
} | |||
c.Next() | |||
go cache.Del(Md5) | |||
} |
@@ -0,0 +1,57 @@ | |||
package mw | |||
import ( | |||
"net" | |||
"net/http" | |||
"net/http/httputil" | |||
"os" | |||
"runtime/debug" | |||
"strings" | |||
"github.com/gin-gonic/gin" | |||
"go.uber.org/zap" | |||
) | |||
func Recovery(logger *zap.Logger, stack bool) gin.HandlerFunc { | |||
return func(c *gin.Context) { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
var brokenPipe bool | |||
if ne, ok := err.(*net.OpError); ok { | |||
if se, ok := ne.Err.(*os.SyscallError); ok { | |||
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") { | |||
brokenPipe = true | |||
} | |||
} | |||
} | |||
httpRequest, _ := httputil.DumpRequest(c.Request, false) | |||
if brokenPipe { | |||
logger.Error(c.Request.URL.Path, | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
) | |||
// If the connection is dead, we can't write a status to it. | |||
c.Error(err.(error)) | |||
c.Abort() | |||
return | |||
} | |||
if stack { | |||
logger.Error("[Recovery from panic]", | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
zap.String("stack", string(debug.Stack())), | |||
) | |||
} else { | |||
logger.Error("[Recovery from panic]", | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
) | |||
} | |||
c.AbortWithStatus(http.StatusInternalServerError) | |||
} | |||
}() | |||
c.Next() | |||
} | |||
} |
@@ -0,0 +1,531 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
enum2 "applet/app/enum" | |||
"errors" | |||
"fmt" | |||
"strings" | |||
"time" | |||
) | |||
func CentralKitchenForSchoolUserUpdate(req md.CentralKitchenForSchoolUserUpdateReq) (err error) { | |||
//1、删除当前用户&&当前单位下的所有身份对应的 `class_with_user` 记录 | |||
var userIdentities []model.UserIdentity | |||
err = db.Db.Where("uid =? AND enterprise_id =?", req.Uid, req.EnterpriseId).Find(&userIdentities) | |||
if err != nil { | |||
return | |||
} | |||
var userIdentityIds []int | |||
for _, v := range userIdentities { | |||
userIdentityIds = append(userIdentityIds, v.Id) | |||
} | |||
_, err = db.Db.In("user_identity_id", userIdentityIds).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
return | |||
} | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//2、删除当前用户&&当前单位下的所有身份 | |||
_, err = session.Where("uid =? and enterprise_id =?", req.Uid, req.EnterpriseId).Delete(model.UserIdentity{}) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//3、新增数据 | |||
now := time.Now() | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(req.Uid) | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
for _, v := range req.BindUserIdentities { | |||
if v.ClassId == -1 { | |||
//TODO::为老师身份 | |||
_, err3 := userIdentityDb.UserIdentityInsertBySession(session, &model.UserIdentity{ | |||
Uid: req.Uid, | |||
Name: v.Name, | |||
IdNo: v.IdNo, | |||
Kind: enum2.UserIdentityKindForCommon, | |||
Identity: enum2.UserIdentityForCentralKitchenForTeacher, | |||
EnterpriseId: req.EnterpriseId, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err3 != nil { | |||
_ = session.Rollback() | |||
return err3 | |||
} | |||
continue | |||
} | |||
insertId, err1 := userIdentityDb.UserIdentityInsertBySession(session, &model.UserIdentity{ | |||
Uid: req.Uid, | |||
Name: v.Name, | |||
IdNo: v.IdNo, | |||
Kind: enum2.UserIdentityKindForCommon, | |||
Identity: enum2.UserIdentityForCentralKitchenForStudent, | |||
EnterpriseId: req.EnterpriseId, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err1 != nil { | |||
_ = session.Rollback() | |||
return err1 | |||
} | |||
_, err2 := classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{ | |||
UserIdentityId: insertId, | |||
ClassId: v.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err2 != nil { | |||
_ = session.Rollback() | |||
return err1 | |||
} | |||
} | |||
return session.Commit() | |||
} | |||
func CentralKitchenForSchoolUserDelete(req md.CentralKitchenForSchoolUserDeleteReq) (err error) { | |||
//1、删除 class_with_user | |||
var userIdentities []model.UserIdentity | |||
err = db.Db.Where("enterprise_id =?", req.EnterpriseId).In("uid", req.Uids).Find(&userIdentities) | |||
if err != nil { | |||
return | |||
} | |||
var userIdentityIds []int | |||
for _, v := range userIdentities { | |||
userIdentityIds = append(userIdentityIds, v.Id) | |||
} | |||
_, err = db.Db.In("user_identity_id", userIdentityIds).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
return | |||
} | |||
//2、删除 user_identity | |||
_, err = db.Db.Where("enterprise_id =?", req.EnterpriseId).In("uid", req.Uids).Delete(model.UserIdentity{}) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentList(req md.CentralKitchenForSchoolStudentListReq) (resp []md.CentralKitchenForSchoolStudentListResp, count int64, err error) { | |||
var classWithUserIdentityIdsOne []int | |||
var classWithUserIdentityIdsTwo []int | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
if req.ClassId != 0 { | |||
classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) | |||
if err2 != nil { | |||
return nil, 0, err2 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) | |||
} | |||
} | |||
if req.GradeId != 0 { | |||
classDb := db.ClassDb{} | |||
classDb.Set(req.GradeId) | |||
classes, err3 := classDb.FindClass() | |||
if err3 != nil { | |||
return nil, 0, err3 | |||
} | |||
var classesId []int | |||
for _, v := range *classes { | |||
classesId = append(classesId, v.Id) | |||
} | |||
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) | |||
if err4 != nil { | |||
return nil, 0, err4 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | |||
} | |||
} | |||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId).And("identity =?", enum2.UserIdentityForCentralKitchenForStudent) | |||
if req.Name != "" { | |||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | |||
} | |||
if req.IdNo != "" { | |||
sess.And("user_identity.id_no like ?", "%"+req.IdNo+"%") | |||
} | |||
if len(classWithUserIdentityIdsOne) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsOne) | |||
} | |||
if len(classWithUserIdentityIdsTwo) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsTwo) | |||
} | |||
var m []*db.UserIdentityWithUser | |||
count, err = sess. | |||
Join("LEFT", "user", "user_identity.uid = user.id"). | |||
Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). | |||
Join("LEFT", "class", "class_with_user.class_id = class.id"). | |||
Join("LEFT", "grade", "class.grade_id = grade.id"). | |||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
for _, v := range m { | |||
resp = append(resp, md.CentralKitchenForSchoolStudentListResp{ | |||
IdNo: v.UserIdentity.IdNo, | |||
ParentPhone: v.User.Phone, | |||
Name: v.UserIdentity.Name, | |||
Grade: v.Grade.Name, | |||
GradeId: v.Grade.Id, | |||
Class: v.Class.Name, | |||
ClassId: v.Class.Id, | |||
UserIdentityId: v.UserIdentity.Id, | |||
}) | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolTeacherList(req md.CentralKitchenForSchoolTeacherListReq) (resp []md.CentralKitchenForSchoolTeacherListResp, count int64, err error) { | |||
var classWithUserIdentityIdsOne []int | |||
var classWithUserIdentityIdsTwo []int | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
sess := db.Db.Where("user_identity.enterprise_id =?", req.EnterpriseId).And("user_identity.identity =?", enum2.UserIdentityForCentralKitchenForTeacher) | |||
if req.Name != "" { | |||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | |||
} | |||
if req.IdNo != "" { | |||
sess.And("user_identity.id_no like ?", "%"+req.IdNo+"%") | |||
} | |||
if len(classWithUserIdentityIdsOne) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsOne) | |||
} | |||
if len(classWithUserIdentityIdsTwo) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsTwo) | |||
} | |||
var m []*db.UserIdentityWithUser | |||
count, err = sess. | |||
Join("LEFT", "user", "user_identity.uid = user.id"). | |||
Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). | |||
Join("LEFT", "class", "class_with_user.class_id = class.id"). | |||
Join("LEFT", "grade", "class.grade_id = grade.id"). | |||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
for _, v := range m { | |||
resp = append(resp, md.CentralKitchenForSchoolTeacherListResp{ | |||
UserIdentityId: v.UserIdentity.Id, | |||
IdNo: v.UserIdentity.IdNo, | |||
Phone: v.User.Phone, | |||
Name: v.UserIdentity.Name, | |||
}) | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentUpdate(req md.CentralKitchenForSchoolStudentUpdateReq) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、修改 `user_identity` | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId) | |||
if err != nil { | |||
return | |||
} | |||
if userIdentity == nil { | |||
return errors.New("未查询到对应记录") | |||
} | |||
userIdentity.IdNo = req.IdNo | |||
userIdentity.Name = req.Name | |||
_, err = userIdentityDb.UserIdentityUpdate(req.UserIdentityId, userIdentity, "id_no", "name") | |||
if err != nil { | |||
return | |||
} | |||
//2、更新 `class_with_user` | |||
_, err = session.Where("user_identity_id =?", req.UserIdentityId).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
_, err = classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{ | |||
UserIdentityId: req.UserIdentityId, | |||
ClassId: req.ClassId, | |||
CreateAt: time.Time{}, | |||
UpdateAt: time.Time{}, | |||
}) | |||
return session.Commit() | |||
} | |||
func CentralKitchenForSchoolStudentDelete(req md.CentralKitchenForSchoolStudentDeleteReq) (err error) { | |||
//1、删除 class_with_user | |||
_, err = db.Db.In("user_identity_id", req.UserIdentityIds).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
return | |||
} | |||
//2、删除 user_identity | |||
_, err = db.Db.Where("enterprise_id =?", req.EnterpriseId).In("id", req.UserIdentityIds).Delete(model.UserIdentity{}) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolStudentAdmission(req md.CentralKitchenForSchoolStudentAdmissionReq) (err error) { | |||
//1、判断 "按年级" / "按班级" 升级 | |||
if req.ClassId != 0 { | |||
// 删除 class_with_user 记录 | |||
_, err = db.Db.Where("class_id = ?", req.ClassId).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
return | |||
} | |||
} | |||
if req.GradeId != 0 { | |||
// 查找班级记录 | |||
classDb := db.ClassDb{} | |||
classDb.Set(req.GradeId) | |||
classes, err1 := classDb.FindClass() | |||
if err1 != nil { | |||
return err1 | |||
} | |||
var classesIds []int | |||
for _, v := range *classes { | |||
classesIds = append(classesIds, v.Id) | |||
} | |||
// 删除 class_with_user 记录 | |||
_, err = db.Db.In("class_id", classesIds).Delete(model.ClassWithUser{}) | |||
if err != nil { | |||
return | |||
} | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolOrdList(req md.CentralKitchenForSchoolOrdListReq) (resp []md.CentralKitchenForSchoolOrdListResp, count int64, err error) { | |||
var classWithUserIdentityIdsOne []int | |||
var classWithUserIdentityIdsTwo []int | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
if req.ClassId != 0 { | |||
classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) | |||
if err2 != nil { | |||
return nil, 0, err2 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) | |||
} | |||
} | |||
if req.GradeId != 0 { | |||
classDb := db.ClassDb{} | |||
classDb.Set(req.GradeId) | |||
classes, err3 := classDb.FindClass() | |||
if err3 != nil { | |||
return nil, 0, err3 | |||
} | |||
var classesId []int | |||
for _, v := range *classes { | |||
classesId = append(classesId, v.Id) | |||
} | |||
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) | |||
if err4 != nil { | |||
return nil, 0, err4 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | |||
} | |||
} | |||
sess := db.Db.Where("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) | |||
if req.StartDate != "" { | |||
sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) | |||
} | |||
if req.EndDate != "" { | |||
sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) | |||
} | |||
if req.Kind != 0 { | |||
sess.And("central_kitchen_for_school_package_ord.kind = ", req.Kind) | |||
} | |||
if req.Sate != 0 { | |||
sess.And("central_kitchen_for_school_package_ord.state = ", req.Sate) | |||
} | |||
if req.OrdSate != 0 { | |||
sess.And("central_kitchen_for_school_package_ord.ord_state = ", req.OrdSate) | |||
} | |||
if req.OutTradeNo != "" { | |||
sess.And("central_kitchen_for_school_package_ord.out_trade_no like ?", "%"+req.OutTradeNo+"%") | |||
} | |||
if req.Name != "" { | |||
sess.And("user_identity.name like ?", "%"+req.Name+"%") | |||
} | |||
if len(classWithUserIdentityIdsOne) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsOne) | |||
} | |||
if len(classWithUserIdentityIdsTwo) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsTwo) | |||
} | |||
var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity | |||
count, err = sess. | |||
Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). | |||
Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). | |||
Join("LEFT", "class", "class_with_user.class_id = class.id"). | |||
Join("LEFT", "grade", "class.grade_id = grade.id"). | |||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
for _, v := range m { | |||
resp = append(resp, md.CentralKitchenForSchoolOrdListResp{ | |||
EnterpriseId: req.EnterpriseId, | |||
Uid: v.UserIdentity.Uid, | |||
UserIdentityId: v.UserIdentity.Id, | |||
TotalPrice: v.CentralKitchenForSchoolPackageOrd.TotalPrice, | |||
Kind: v.CentralKitchenForSchoolPackageOrd.Kind, | |||
OutTradeNo: v.CentralKitchenForSchoolPackageOrd.OutTradeNo, | |||
TradeNo: v.CentralKitchenForSchoolPackageOrd.TradeNo, | |||
State: v.CentralKitchenForSchoolPackageOrd.State, | |||
OrdState: v.CentralKitchenForSchoolPackageOrd.OrdState, | |||
CreateAt: v.CentralKitchenForSchoolPackageOrd.CreateAt, | |||
Name: v.UserIdentity.Name, | |||
Grade: v.Grade.Name, | |||
GradeId: v.Grade.Id, | |||
Class: v.Class.Name, | |||
ClassId: v.Class.Id, | |||
}) | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolOrdRefund(req md.CentralKitchenForSchoolOrdRefundReq) (err error) { | |||
//1、查询出所有 `central_kitchen_for_school_user_with_day` 记录 | |||
var m []model.CentralKitchenForSchoolUserWithDay | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
err = centralKitchenForSchoolUserWithDayDb.Db.In("id", req.Ids).Find(&m) | |||
if err != nil { | |||
return err | |||
} | |||
//2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 | |||
sql := "update central_kitchen_for_school_user_with_day set status = %s where id In (%s)" | |||
idsStr := strings.Join(req.Ids, ",") | |||
sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr) | |||
fmt.Println(sql) | |||
_, err = db.ExecuteOriginalSql(db.Db, sql) | |||
if err != nil { | |||
return err | |||
} | |||
//3、循环处理数据 | |||
var dealOutTradeNo map[string]string | |||
var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay | |||
now := time.Now() | |||
for _, v := range m { | |||
dealOutTradeNo[v.OrdNo] = v.OrdNo | |||
centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ | |||
Uid: v.Uid, | |||
IdentityId: v.IdentityId, | |||
RecordsId: v.Id, | |||
State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, | |||
Amount: v.Amount, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
} | |||
//4、处理 `central_kitchen_for_school_package_ord` 的 订单状态(ord_state) | |||
for _, v := range dealOutTradeNo { | |||
err1 := JudgePackageOrdOrdState(v) | |||
if err1 != nil { | |||
return err1 | |||
} | |||
} | |||
//5、新增 `central_kitchen_for_school_user_refund_day` 数据 | |||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | |||
centralKitchenForSchoolUserRefundDayDb.Set(0) | |||
_, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) | |||
return | |||
} | |||
// JudgePackageOrdOrdState 判断订单状态 | |||
func JudgePackageOrdOrdState(outTradeNo string) (err error) { | |||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||
if err != nil { | |||
return | |||
} | |||
var ordState, oldOrdState int | |||
oldOrdState = ord.OrdState | |||
ordState = oldOrdState | |||
var m model.CentralKitchenForSchoolUserWithDay | |||
total, err := db.Db.Where("ord_no =?", outTradeNo).Count(&m) | |||
if err != nil { | |||
return | |||
} | |||
//1、判断是否有 `待就餐` | |||
count, err := db.Db.Where("ord_no =?", outTradeNo).And("state =?", enum2.CentralKitchenForSchoolUserWithDayStateForWait).Count(&m) | |||
if err != nil { | |||
return | |||
} | |||
if count == 0 { | |||
ordState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForComplete | |||
} | |||
//2、判断是否有 `已退款` / `部分退款` | |||
count, err = db.Db.Where("ord_no =?", outTradeNo).And("state =?", enum2.CentralKitchenForSchoolUserWithDayStateForCancel).Count(&m) | |||
if err != nil { | |||
return | |||
} | |||
if count > 0 && count < total { | |||
ordState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded | |||
} | |||
if count > 0 && count != total { | |||
ordState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForRefunded | |||
} | |||
//3、判断是否有 `退款中` | |||
count, err = db.Db.Where("ord_no =?", outTradeNo).And("state =?", enum2.CentralKitchenForSchoolUserWithDayStateForCanceling).Count(&m) | |||
if err != nil { | |||
return | |||
} | |||
if count > 0 { | |||
ordState = enum2.CentralKitchenForSchoolPackageOrdOrdStateForRefunding | |||
} | |||
if ordState != oldOrdState { | |||
ord.OrdState = ordState | |||
_, err2 := centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(ord, "ord_state") | |||
if err2 != nil { | |||
return err2 | |||
} | |||
} | |||
return | |||
} |
@@ -0,0 +1,102 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
enum2 "applet/app/enum" | |||
"applet/app/utils" | |||
"fmt" | |||
) | |||
func EnterpriseUserListByCentralKitchenForSchool(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) { | |||
//1、判断是否过滤 "教师" | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
teacherUserIdentities, err := userIdentityDb.FindUserIdentityForEnterpriseByIdentity(req.EnterpriseId, enum2.UserIdentityForCentralKitchenForTeacher) | |||
if err != nil { | |||
return | |||
} | |||
userIdentities, err := userIdentityDb.FindUserIdentityForEnterprise(req.EnterpriseId) | |||
if err != nil { | |||
return | |||
} | |||
var teacherUserIdentitiesMap = map[string][]model.UserIdentity{} | |||
var userIdentitiesMap = map[string][]model.UserIdentity{} | |||
var uids, teacherUids []int | |||
for _, v := range *teacherUserIdentities { | |||
teacherUserIdentitiesMap[utils.IntToStr(v.Uid)] = append(teacherUserIdentitiesMap[utils.IntToStr(v.Uid)], v) | |||
teacherUids = append(teacherUids, v.Uid) | |||
} | |||
for _, v := range *userIdentities { | |||
userIdentitiesMap[utils.IntToStr(v.Uid)] = append(userIdentitiesMap[utils.IntToStr(v.Uid)], v) | |||
uids = append(uids, v.Uid) | |||
} | |||
var m []model.User | |||
sess := db.Db.In("id", uids) | |||
if req.IsTeacher == 1 { | |||
sess.In("id", teacherUids) | |||
} | |||
if req.IsTeacher == 2 { | |||
sess.NotIn("id", teacherUids) | |||
} | |||
if req.Nickname != "" { | |||
sess.And("nickname like ?", "%"+req.Nickname+"%") | |||
} | |||
if req.Phone != "" { | |||
sess.And("phone like ?", "%"+req.Phone+"%") | |||
} | |||
count, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return | |||
} | |||
resp.Total = count | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
for _, v := range m { | |||
temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{ | |||
Id: v.Id, | |||
Nickname: v.Nickname, | |||
Phone: v.Phone, | |||
Avatar: v.Avatar, | |||
IsTeacher: 0, | |||
CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"), | |||
} | |||
for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] { | |||
fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)]) | |||
//TODO::判断是否为老师 | |||
if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher { | |||
temp.UserIdentities = append(temp.UserIdentities, struct { | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
SchoolName string `json:"school_name" label:"学校名"` | |||
Name string `json:"name" label:"姓名"` | |||
Grade string `json:"grade" label:"年级"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
Class string `json:"class" label:"班级"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
}{IdNo: v1.IdNo, SchoolName: "教师", Name: v1.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0}) | |||
temp.IsTeacher = 1 | |||
} else { | |||
data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id) | |||
if err2 != nil { | |||
return resp, err2 | |||
} | |||
if data == nil { | |||
continue | |||
} | |||
temp.UserIdentities = append(temp.UserIdentities, struct { | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
SchoolName string `json:"school_name" label:"学校名"` | |||
Name string `json:"name" label:"姓名"` | |||
Grade string `json:"grade" label:"年级"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
Class string `json:"class" label:"班级"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
}{IdNo: data.UserIdentity.IdNo, SchoolName: data.Enterprise.Name, Name: data.UserIdentity.Name, Grade: data.Grade.Name, Class: data.Class.Name, GradeId: data.Grade.Id, ClassId: data.Class.Id}) | |||
} | |||
} | |||
resp.List = append(resp.List, temp) | |||
} | |||
return | |||
} |
@@ -0,0 +1,210 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
svc "applet/app/admin/svc/enterprise_manage" | |||
md2 "applet/app/customer/md" | |||
svc2 "applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"errors" | |||
) | |||
func CentralKitchenForSchoolOrderRefundList(req md.CentralKitchenForSchoolOrderRefundListReq) (resp []md.CentralKitchenForSchoolOrderRefundListResp, total int64, err error) { | |||
var m []*db.CentralKitchenForSchoolUserRefundDayWithData | |||
sess := db.Db.Where("1=1") | |||
if req.EnterpriseId != 0 { | |||
sess.And("enterprise.id =?", req.EnterpriseId) | |||
} | |||
if req.Phone != "" { | |||
sess.And("user.phone like ?", "%"+req.Name+"%") | |||
} | |||
if req.Name != "" { | |||
sess.And("user_identity.name like ?", "%"+req.Phone+"%") | |||
} | |||
if req.Kind != 0 { | |||
sess.And("central_kitchen_for_school_user_with_day.kind = ?", req.Kind) | |||
} | |||
if req.State != 0 { | |||
sess.And("central_kitchen_for_school_user_refund_day.state = ?", req.State) | |||
} | |||
if req.StartDate != "" { | |||
sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) | |||
} | |||
if req.EndDate != "" { | |||
sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) | |||
} | |||
if req.OutTradeNo != "" { | |||
sess.And("central_kitchen_for_school_user_refund_day.out_trade_no like ?", "%"+req.OutTradeNo+"%") | |||
} | |||
if req.OutRequestNo != "" { | |||
sess.And("central_kitchen_for_school_user_refund_day.out_request_no like ?", "%"+req.OutRequestNo+"%") | |||
} | |||
var classWithUserIdentityIdsOne []int | |||
var classWithUserIdentityIdsTwo []int | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
if req.ClassId != 0 { | |||
classWithUsers, err2 := classWithUserDb.FindUserIdentity(req.ClassId) | |||
if err2 != nil { | |||
return nil, 0, err2 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsOne = append(classWithUserIdentityIdsOne, v.UserIdentityId) | |||
} | |||
} | |||
if req.GradeId != 0 { | |||
classDb := db.ClassDb{} | |||
classDb.Set(req.GradeId) | |||
classes, err3 := classDb.FindClass() | |||
if err3 != nil { | |||
return nil, 0, err3 | |||
} | |||
var classesId []int | |||
for _, v := range *classes { | |||
classesId = append(classesId, v.Id) | |||
} | |||
classWithUsers, err4 := classWithUserDb.FindUserIdentity(classesId) | |||
if err4 != nil { | |||
return nil, 0, err4 | |||
} | |||
for _, v := range *classWithUsers { | |||
classWithUserIdentityIdsTwo = append(classWithUserIdentityIdsTwo, v.UserIdentityId) | |||
} | |||
} | |||
if len(classWithUserIdentityIdsOne) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsOne) | |||
} | |||
if len(classWithUserIdentityIdsTwo) > 0 { | |||
sess.In("user_identity.id", classWithUserIdentityIdsTwo) | |||
} | |||
total, err = sess. | |||
Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). | |||
Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). | |||
Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). | |||
Join("LEFT", "user", "user_identity.uid = user.id"). | |||
Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). | |||
Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). | |||
Join("LEFT", "class", "class_with_user.class_id = class.id"). | |||
Join("LEFT", "grade", "class.grade_id = grade.id"). | |||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
for _, v := range m { | |||
resp = append(resp, md.CentralKitchenForSchoolOrderRefundListResp{ | |||
Id: v.CentralKitchenForSchoolUserRefundDay.Id, | |||
OutTradeNo: v.CentralKitchenForSchoolUserRefundDay.OutTradeNo, | |||
OutRequestNo: v.CentralKitchenForSchoolUserRefundDay.OutRequestNo, | |||
Name: v.UserIdentity.Name, | |||
Phone: v.User.Phone, | |||
EnterpriseName: v.Enterprise.Name, | |||
ClassName: v.Class.Name, | |||
GradeName: v.Grade.Name, | |||
Kind: v.CentralKitchenForSchoolUserWithDay.Kind, | |||
Amount: v.CentralKitchenForSchoolUserRefundDay.Amount, | |||
State: v.CentralKitchenForSchoolUserRefundDay.State, | |||
CreateAt: v.CentralKitchenForSchoolUserRefundDay.CreateAt.Format("2006-01-02 15:04:05"), | |||
Memo: v.CentralKitchenForSchoolUserRefundDay.Memo, | |||
}) | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefundAudit(req md.CentralKitchenForSchoolOrderRefundAuditReq) (err error) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
sysCfg, err := sysCfgDb.SysCfgGetOne(enum.JsapiPayAppAutToken) | |||
if err != nil { | |||
return | |||
} | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//限制30条 | |||
if len(req.Ids) > 30 { | |||
err = errors.New("受理数据过长,请分批次处理") | |||
_ = session.Rollback() | |||
return | |||
} | |||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | |||
centralKitchenForSchoolUserRefundDayDb.Set(0) | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
for _, v := range req.Ids { | |||
returnDay, err1 := centralKitchenForSchoolUserRefundDayDb.GetCentralKitchenForSchoolUserRefundDay(utils.StrToInt(v)) | |||
if err1 != nil { | |||
_ = session.Rollback() | |||
return err1 | |||
} | |||
if returnDay.State != enum.CentralKitchenForSchoolUserRefundDayStateForAuditing { | |||
_ = session.Rollback() | |||
return errors.New("请勿重复审核申请单!") | |||
} | |||
userWithDay, err3 := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(returnDay.RecordsId) | |||
if err3 != nil { | |||
_ = session.Rollback() | |||
return err3 | |||
} | |||
//1、更新状态 | |||
if req.State == 1 { | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass | |||
userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForCancel | |||
} else { | |||
returnDay.State = enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject | |||
userWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForWait | |||
} | |||
returnDay.Memo = req.Memo | |||
updateAck, err2 := centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayUpdate(returnDay.Id, returnDay, "state", "memo") | |||
if err2 != nil { | |||
_ = session.Rollback() | |||
return err2 | |||
} | |||
if updateAck <= 0 { | |||
_ = session.Rollback() | |||
err = errors.New("更新退款订单记录状态失败") | |||
return | |||
} | |||
updateAck1, err4 := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(userWithDay.Id, userWithDay, "state") | |||
if err4 != nil { | |||
_ = session.Rollback() | |||
return err4 | |||
} | |||
if updateAck1 <= 0 { | |||
_ = session.Rollback() | |||
err = errors.New("更新退款就餐记录状态失败") | |||
return | |||
} | |||
//2、处理订单状态 | |||
err5 := svc.JudgePackageOrdOrdState(returnDay.OutTradeNo) | |||
if err5 != nil { | |||
_ = session.Rollback() | |||
return err5 | |||
} | |||
//3、调用支付宝进行退款 | |||
if req.State == 1 { | |||
err6, _ := svc2.CurlAlipayTradeRefund(md2.CurlAlipayTradeRefundReq{ | |||
OutTradeNo: returnDay.OutTradeNo, | |||
RefundAmount: returnDay.Amount, | |||
RefundReason: "央厨订餐退款", | |||
OutRequestNo: returnDay.OutRequestNo, | |||
AppAuthToken: sysCfg.Val, | |||
}) | |||
if err6 != nil { | |||
_ = session.Rollback() | |||
return err6 | |||
} | |||
} | |||
} | |||
return session.Commit() | |||
} |
@@ -0,0 +1,30 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
) | |||
func AdminDelete(admIds []int) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除 `admin` | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
_, err = adminDb.AdminDeleteBySession(session, admIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、删除 `admin_role` | |||
adminRoleDb := db.AdminRoleDb{} | |||
adminRoleDb.Set() | |||
_, err = adminRoleDb.AdminDeleteBySessionForAdmId(session, admIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} |
@@ -0,0 +1,51 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/lib/auth" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"errors" | |||
"github.com/gin-gonic/gin" | |||
"strings" | |||
) | |||
func GetUser(c *gin.Context) *model.Admin { | |||
user, _ := c.Get("admin") | |||
if user == nil { | |||
return &model.Admin{ | |||
AdmId: 0, | |||
Username: "", | |||
Password: "", | |||
State: 0, | |||
CreateAt: "", | |||
UpdateAt: "", | |||
} | |||
} | |||
return user.(*model.Admin) | |||
} | |||
func CheckUser(c *gin.Context) (*model.Admin, error) { | |||
token := c.GetHeader("Authorization") | |||
if token == "" { | |||
return nil, errors.New("token not exist") | |||
} | |||
// 按空格分割 | |||
parts := strings.SplitN(token, " ", 2) | |||
if !(len(parts) == 2 && parts[0] == "Bearer") { | |||
return nil, errors.New("token format error") | |||
} | |||
// parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它 | |||
mc, err := auth.ParseToken(parts[1]) | |||
if err != nil { | |||
return nil, err | |||
} | |||
// 获取admin | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
admin, err := adminDb.GetAdmin(mc.AdmId) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return admin, nil | |||
} |
@@ -0,0 +1,67 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/enum" | |||
) | |||
func CentralKitchenForSchoolInfo(enterpriseId int) (err error, resp md.CentralKitchenForSchoolInfoResp) { | |||
//1、查询`enterprise` | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) | |||
if err != nil { | |||
return | |||
} | |||
resp.Name = enterprise.Name | |||
resp.Memo = enterprise.Memo | |||
resp.Kind = enum.EnterprisePvd(enterprise.Kind).String() | |||
resp.State = enum.EnterpriseState(enterprise.State).String() | |||
//2、查询`central_kitchen_for_school_with_spec` | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(enterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
return | |||
} | |||
if spec != nil { | |||
resp.IsOpenBreakfast = spec.IsOpenBreakfast | |||
resp.IsOpenLunch = spec.IsOpenLunch | |||
resp.IsOpenDinner = spec.IsOpenDinner | |||
} | |||
//3、查询`central_kitchen_for_school_set` | |||
centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{} | |||
centralKitchenForSchoolSetDb.Set(enterpriseId) | |||
set, err := centralKitchenForSchoolSetDb.GetCentralKitchenForSchoolSet() | |||
if err != nil { | |||
return | |||
} | |||
if set != nil { | |||
resp.IsOpenTeacherReportMeal = set.IsOpenTeacherReportMeal | |||
resp.IsOpenReportMealForDay = set.IsOpenReportMealForDay | |||
resp.IsOpenReportMealForMonth = set.IsOpenReportMealForMonth | |||
resp.IsOpenReportMealForSemester = set.IsOpenReportMealForSemester | |||
} | |||
//4、统计 "教师"、 "学生"、 "班级" 数量 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
resp.StudentNum, err = userIdentityDb.CountUserIdentityForEnterprise(enterpriseId, enum.UserIdentityForCentralKitchenForStudent) | |||
if err != nil { | |||
return | |||
} | |||
resp.TeacherNum, err = userIdentityDb.CountUserIdentityForEnterprise(enterpriseId, enum.UserIdentityForCentralKitchenForTeacher) | |||
if err != nil { | |||
return | |||
} | |||
classDb := db.ClassDb{} | |||
classDb.Set(0) | |||
resp.ClassNum, err = classDb.CountClassForEnterprise(enterpriseId) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} |
@@ -0,0 +1,187 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"errors" | |||
"time" | |||
) | |||
func AddCentralKitchenForSchoolPackage(req md.SaveCentralKitchenForSchoolPackageReq) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
now := time.Now() | |||
//1、查询`central_kitchen_for_school_with_spec` | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(req.EnterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
//1、新增`central_kitchen_for_school_package` | |||
centralKitchenForSchoolPackageDb := db.CentralKitchenForSchoolPackageDb{} | |||
packageId, err := centralKitchenForSchoolPackageDb.CentralKitchenForSchoolPackageInsertBySession(session, &model.CentralKitchenForSchoolPackage{ | |||
EnterpriseId: req.EnterpriseId, | |||
Year: req.Year, | |||
Month: req.Month, | |||
TotalPrice: "", | |||
StartDate: req.StartDate, | |||
EndDate: req.EndDate, | |||
State: 1, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
//2、批量新增 `central_kitchen_for_school_package_with_day` | |||
var centralKitchenForSchoolPackageWithDays []*model.CentralKitchenForSchoolPackageWithDay | |||
for _, v := range req.DateList { | |||
var isOpenBreakfast, isOpenLunch, isOpenDinner, isOpenReplenish = md.CloseBreakfast, md.CloseLunch, md.CloseDinner, md.CloseReplenish | |||
if spec.IsOpenBreakfast == md.OpenBreakfast && v.IsOpenBreakfast == md.OpenBreakfast { | |||
isOpenBreakfast = md.OpenBreakfast | |||
} | |||
if spec.IsOpenLunch == md.OpenLunch && v.IsOpenLunch == md.OpenLunch { | |||
isOpenLunch = md.OpenLunch | |||
} | |||
if spec.IsOpenDinner == md.OpenDinner && v.IsOpenDinner == md.OpenDinner { | |||
isOpenDinner = md.OpenDinner | |||
} | |||
if v.IsOpenReplenish == md.OpenReplenish { | |||
isOpenReplenish = md.OpenReplenish | |||
} | |||
centralKitchenForSchoolPackageWithDays = append(centralKitchenForSchoolPackageWithDays, &model.CentralKitchenForSchoolPackageWithDay{ | |||
Date: v.Date, | |||
PackageId: packageId, | |||
IsOpenBreakfast: isOpenBreakfast, | |||
IsOpenLunch: isOpenLunch, | |||
IsOpenDinner: isOpenDinner, | |||
IsOpenReplenish: isOpenReplenish, | |||
}) | |||
} | |||
centralKitchenForSchoolPackageWithDayDb := db.CentralKitchenForSchoolPackageWithDayDb{} | |||
centralKitchenForSchoolPackageWithDayDb.Set(packageId) | |||
_, err = centralKitchenForSchoolPackageWithDayDb.BatchAddCentralKitchenForSchoolPackageWithDaysBySession(session, centralKitchenForSchoolPackageWithDays) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
return session.Commit() | |||
} | |||
func UpdateCentralKitchenForSchoolPackage(req md.SaveCentralKitchenForSchoolPackageReq) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
now := time.Now() | |||
//1、查询`central_kitchen_for_school_with_spec` | |||
centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{} | |||
centralKitchenForSchoolWithSpec.Set(req.EnterpriseId) | |||
spec, err := centralKitchenForSchoolWithSpec.GetCentralKitchenForSchoolWithSpec() | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
//2、修改`central_kitchen_for_school_package` | |||
centralKitchenForSchoolPackageDb := db.CentralKitchenForSchoolPackageDb{} | |||
centralKitchenForSchoolPackageDb.Set() | |||
centralKitchenForSchoolPackage, err := centralKitchenForSchoolPackageDb.GetCentralKitchenForSchoolPackage(req.PackageId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
if centralKitchenForSchoolPackage == nil { | |||
_ = session.Rollback() | |||
return errors.New("未查询到对应套餐记录") | |||
} | |||
centralKitchenForSchoolPackage.Year = req.Year | |||
centralKitchenForSchoolPackage.Month = req.Month | |||
centralKitchenForSchoolPackage.StartDate = req.StartDate | |||
centralKitchenForSchoolPackage.EndDate = req.EndDate | |||
centralKitchenForSchoolPackage.State = req.State | |||
centralKitchenForSchoolPackage.UpdateAt = now.Format("2006-01-02 15:04:05") | |||
affected, err := centralKitchenForSchoolPackageDb.CentralKitchenForSchoolPackageUpdateBySession(session, centralKitchenForSchoolPackage.Id, centralKitchenForSchoolPackage) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
if affected == 0 { | |||
_ = session.Rollback() | |||
return errors.New("更新套餐记录失败") | |||
} | |||
//3、删除 `central_kitchen_for_school_package_with_day` 旧数据 | |||
centralKitchenForSchoolPackageWithDayDb := db.CentralKitchenForSchoolPackageWithDayDb{} | |||
centralKitchenForSchoolPackageWithDayDb.Set(centralKitchenForSchoolPackage.Id) | |||
_, err = centralKitchenForSchoolPackageWithDayDb.CentralKitchenForSchoolPackageWithDayDeleteBySession(session) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//4、批量新增 `central_kitchen_for_school_package_with_day` | |||
var centralKitchenForSchoolPackageWithDays []*model.CentralKitchenForSchoolPackageWithDay | |||
for _, v := range req.DateList { | |||
var isOpenBreakfast, isOpenLunch, isOpenDinner, isOpenReplenish = md.CloseBreakfast, md.CloseLunch, md.CloseDinner, md.CloseReplenish | |||
if spec.IsOpenBreakfast == md.OpenBreakfast && v.IsOpenBreakfast == md.OpenBreakfast { | |||
isOpenBreakfast = md.OpenBreakfast | |||
} | |||
if spec.IsOpenLunch == md.OpenLunch && v.IsOpenLunch == md.OpenLunch { | |||
isOpenLunch = md.OpenLunch | |||
} | |||
if spec.IsOpenDinner == md.OpenDinner && v.IsOpenDinner == md.OpenDinner { | |||
isOpenDinner = md.OpenDinner | |||
} | |||
if v.IsOpenReplenish == md.OpenReplenish { | |||
isOpenReplenish = md.OpenReplenish | |||
} | |||
centralKitchenForSchoolPackageWithDays = append(centralKitchenForSchoolPackageWithDays, &model.CentralKitchenForSchoolPackageWithDay{ | |||
Date: v.Date, | |||
PackageId: centralKitchenForSchoolPackage.Id, | |||
IsOpenBreakfast: isOpenBreakfast, | |||
IsOpenLunch: isOpenLunch, | |||
IsOpenDinner: isOpenDinner, | |||
IsOpenReplenish: isOpenReplenish, | |||
}) | |||
} | |||
_, err = centralKitchenForSchoolPackageWithDayDb.BatchAddCentralKitchenForSchoolPackageWithDaysBySession(session, centralKitchenForSchoolPackageWithDays) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
return session.Commit() | |||
} | |||
func DeleteCentralKitchenForSchoolPackage(packageId int) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除`central_kitchen_for_school_package` | |||
centralKitchenForSchoolPackageDb := db.CentralKitchenForSchoolPackageDb{} | |||
centralKitchenForSchoolPackageDb.Set() | |||
centralKitchenForSchoolPackage, err := centralKitchenForSchoolPackageDb.GetCentralKitchenForSchoolPackage(packageId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return err | |||
} | |||
if centralKitchenForSchoolPackage == nil { | |||
_ = session.Rollback() | |||
return errors.New("未查询到对应套餐记录") | |||
} | |||
centralKitchenForSchoolPackage.IsDelete = 1 | |||
affected, err := centralKitchenForSchoolPackageDb.CentralKitchenForSchoolPackageUpdateBySession(session, centralKitchenForSchoolPackage.Id, centralKitchenForSchoolPackage, "is_delete") | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
if affected == 0 { | |||
_ = session.Rollback() | |||
return errors.New("删除套餐记录失败") | |||
} | |||
return session.Commit() | |||
} |
@@ -0,0 +1,91 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
) | |||
func EnterpriseList(req md.EnterpriseListReq) (m []model.Enterprise, total int64, err error) { | |||
sess := db.Db.Desc("id").Limit(req.Limit, (req.Page-1)*req.Limit) | |||
if req.Name != "" { | |||
sess.And("name like ?", "%"+req.Name+"%") | |||
} | |||
if req.Kind != 0 { | |||
sess.And("kind = ?", req.Kind) | |||
} | |||
total, err = sess.FindAndCount(&m) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} | |||
func EnterpriseDetail(enterpriseId int) (data md.EnterpriseDetailResp, err error) { | |||
//1、查找所在单位 | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) | |||
if err != nil { | |||
return | |||
} | |||
data.Enterprise = *enterprise | |||
//2、查找对应年级 | |||
gradeDb := db.GradeDb{} | |||
gradeDb.Set(enterpriseId) | |||
gradeList, err := gradeDb.FindGrade() | |||
if err != nil { | |||
return | |||
} | |||
for _, v := range *gradeList { | |||
//3、查找对应班级 | |||
classDb := db.ClassDb{} | |||
classDb.Set(v.Id) | |||
classes, err1 := classDb.FindClass() | |||
if err1 != nil { | |||
err = err1 | |||
return | |||
} | |||
data.GradeList = append(data.GradeList, md.GradeListStruct{ | |||
Grade: v, | |||
ClassList: *classes, | |||
}) | |||
} | |||
return | |||
} | |||
func EnterpriseDelete(enterpriseIds []int) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除所在单位 | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
_, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、删除年级 | |||
gradeDb := db.GradeDb{} | |||
gradeDb.Set(0) | |||
_, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//3、删除班级 | |||
classDb := db.ClassDb{} | |||
classDb.Set(0) | |||
_, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} |
@@ -0,0 +1,33 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/lib/auth" | |||
"applet/app/admin/md" | |||
"applet/app/db/model" | |||
"applet/app/utils/cache" | |||
"applet/app/utils/logx" | |||
) | |||
func HandleLoginToken(cacheKey string, admin *model.Admin) (string, error) { | |||
// 获取之前生成的token | |||
token, err := cache.GetString(cacheKey) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
} | |||
// 没有获取到 | |||
if err != nil || token == "" { | |||
// 生成token | |||
token, err = auth.GenToken(admin.AdmId, admin.Username) | |||
if err != nil { | |||
return "", err | |||
} | |||
// 缓存token | |||
_, err = cache.SetEx(cacheKey, token, md.JwtTokenCacheTime) | |||
if err != nil { | |||
return "", err | |||
} | |||
return token, nil | |||
} | |||
return token, nil | |||
} |
@@ -0,0 +1 @@ | |||
package svc |
@@ -0,0 +1,183 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"encoding/json" | |||
"errors" | |||
"regexp" | |||
"strings" | |||
"time" | |||
) | |||
func CheckUserRole(cacheKey, uri string, admId int) (isHasPermission bool, err error) { | |||
uri = utils.UriFilterExcludeQueryString(uri) //去除uri中?后的query参数 | |||
isHasPermission = false | |||
var rolePermission []string | |||
var rolePermissionString string | |||
rolePermissionString, _ = cache.GetString(cacheKey) | |||
//if rolePermissionString != "" { | |||
if false { | |||
if err = json.Unmarshal([]byte(rolePermissionString), &rolePermission); err != nil { | |||
return | |||
} | |||
} else { | |||
qrcodeWithBatchRecordsDb := db.AdminDb{} | |||
qrcodeWithBatchRecordsDb.Set() | |||
list, _, err := qrcodeWithBatchRecordsDb.GetAdminRolePermission(admId) | |||
if err != nil { | |||
return isHasPermission, err | |||
} | |||
for _, v := range list { | |||
rolePermission = append(rolePermission, v.Permission.Action) | |||
} | |||
marshal, err := json.Marshal(rolePermission) | |||
if err != nil { | |||
return isHasPermission, err | |||
} | |||
rolePermissionString = string(marshal) | |||
_, err = cache.SetEx(cacheKey, rolePermissionString, md.AdminRolePermissionCacheTime) | |||
} | |||
if utils.InArr(uri, rolePermission) { | |||
isHasPermission = true | |||
} else { | |||
//正则匹配占位符情况 | |||
compileRegex := regexp.MustCompile("[0-9]+") | |||
matchArr := compileRegex.FindAllString(uri, -1) | |||
if len(matchArr) > 0 { | |||
uri = strings.Replace(uri, matchArr[len(matchArr)-1], ":id", 1) | |||
if utils.InArr(uri, rolePermission) { | |||
isHasPermission = true | |||
} | |||
} | |||
} | |||
return | |||
} | |||
func DeleteRole(roleId int) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除 `role` | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(roleId) | |||
_, err = roleDb.RoleDeleteBySession(session, roleId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、删除 `role_permission_group` | |||
rolePermissionGroupDb := db.RolePermissionGroupDb{} | |||
rolePermissionGroupDb.Set() | |||
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, roleId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//3、删除 `admin_role` | |||
adminRoleDb := db.AdminRoleDb{} | |||
adminRoleDb.Set() | |||
_, err = adminRoleDb.AdminRoleDeleteForRoleBySession(session, roleId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} | |||
func RoleBindPermissionGroup(req md.RoleBindPermissionGroupReq) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、查询 `role` | |||
roleDb := db.RoleDb{} | |||
roleDb.Set(req.RoleId) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
return | |||
} | |||
if role == nil { | |||
return errors.New("未查询到相应记录") | |||
} | |||
//1、删除 `role_permission_group` | |||
rolePermissionGroupDb := db.RolePermissionGroupDb{} | |||
rolePermissionGroupDb.Set() | |||
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, req.RoleId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、新增 `role_permission_group`` | |||
var mm []*model.RolePermissionGroup | |||
now := time.Now() | |||
for _, v := range req.PermissionIds { | |||
mm = append(mm, &model.RolePermissionGroup{ | |||
RoleId: role.Id, | |||
GroupId: v, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
} | |||
_, err = rolePermissionGroupDb.BatchAddRolePermissionGroupBySession(session, mm) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} | |||
func BindAdminRole(req md.BindAdminRoleReq) (err error) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、查询 `role` | |||
adminDb := db.AdminDb{} | |||
adminDb.Set() | |||
role, err := adminDb.GetAdmin(req.AdmId) | |||
if err != nil { | |||
return | |||
} | |||
if role == nil { | |||
return errors.New("未查询到相应记录") | |||
} | |||
//1、删除 `admin_role` | |||
adminRoleDb := db.AdminRoleDb{} | |||
adminRoleDb.Set() | |||
_, err = adminRoleDb.AdminRoleDeleteBySession(session, req.AdmId) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、新增 `删除 `admin_role`` | |||
var mm []*model.AdminRole | |||
now := time.Now() | |||
for _, v := range req.RoleIds { | |||
mm = append(mm, &model.AdminRole{ | |||
AdmId: req.AdmId, | |||
RoleId: v, | |||
State: 1, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
} | |||
_, err = adminRoleDb.BatchAddAdminRoleBySession(session, mm) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} |
@@ -0,0 +1,97 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"errors" | |||
) | |||
func UserList(req md.UserListReq) (resp md.UserListResp, err error) { | |||
var m []model.User | |||
userDb := db.UserDb{} | |||
userDb.Set() | |||
sess := userDb.Db.Join("LEFT", "user_identity", "user.id = user_identity.uid"). | |||
Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").Limit(req.Limit, (req.Page-1)*req.Limit) | |||
sess.Where("1=1") | |||
if req.Phone != "" { | |||
sess.And("user.phone like ?", "%"+req.Phone+"%") | |||
} | |||
if req.Nickname != "" { | |||
sess.And("user.nickname like ?", "%"+req.Nickname+"%") | |||
} | |||
if req.CreateTimeStart != "" { | |||
sess.And("user.create_at >= ?", req.CreateTimeStart) | |||
} | |||
if req.CreateTimeEnd != "" { | |||
sess.And("user.create_at <= ?", req.CreateTimeEnd) | |||
} | |||
resp.Total, err = sess.Desc("user.id").FindAndCount(&m) | |||
if err != nil { | |||
return | |||
} | |||
for _, v := range m { | |||
//获取用户身份信息 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(v.Id) | |||
identity, err1 := userIdentityDb.FindUserIdentity() | |||
if err1 != nil { | |||
err = err1 | |||
return | |||
} | |||
var temp = md.UserList{ | |||
Id: v.Id, | |||
Nickname: v.Nickname, | |||
Phone: v.Phone, | |||
Avatar: v.Avatar, | |||
CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"), | |||
} | |||
for _, v1 := range *identity { | |||
temp.BindUserIdentity = append(temp.BindUserIdentity, struct { | |||
Id int `json:"id" label:"id"` | |||
IdNo string `json:"id_no" label:"身份证号"` | |||
Name string `json:"name" label:"姓名"` | |||
EnterpriseName string `json:"enterprise_name" label:"企业名"` | |||
EnterpriseKind int32 `json:"enterprise_kind" label:"企业类型"` | |||
Kind int `json:"kind" label:"身份类型"` | |||
}{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, Name: v1.UserIdentity.Name, EnterpriseName: v1.Enterprise.Name, EnterpriseKind: v1.Enterprise.Kind, Kind: v1.UserIdentity.Kind}) | |||
} | |||
resp.List = append(resp.List, temp) | |||
} | |||
return | |||
} | |||
func UserUpdate(req md.UserList) (err error) { | |||
userDb := db.UserDb{} | |||
userDb.Set() | |||
user, err := userDb.GetUser(req.Id) | |||
if err != nil { | |||
return err | |||
} | |||
if user == nil { | |||
return errors.New("未获取到用户信息记录") | |||
} | |||
for _, v := range req.BindUserIdentity { | |||
//获取用户身份信息 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(v.Id) | |||
identity, err1 := userIdentityDb.GetUserIdentity(v.Id) | |||
if err1 != nil { | |||
err = err1 | |||
return | |||
} | |||
if user == nil { | |||
return errors.New("未获取到用户身份信息记录") | |||
} | |||
identity.Name = v.Name | |||
identity.IdNo = v.IdNo | |||
_, err2 := userIdentityDb.UserIdentityUpdate(identity.Id, identity, "name", "id_no") | |||
if err2 != nil { | |||
err = err2 | |||
return | |||
} | |||
} | |||
return | |||
} |
@@ -0,0 +1,43 @@ | |||
package cfg | |||
import ( | |||
"time" | |||
) | |||
type Config struct { | |||
Debug bool `yaml:"debug"` | |||
Prd bool `yaml:"prd"` | |||
SrvAddr string `yaml:"srv_addr"` | |||
RedisAddr string `yaml:"redis_addr"` | |||
SmartCanteenPay string `yaml:"smart_canteen_pay"` | |||
DB DBCfg `yaml:"db"` | |||
Log LogCfg `yaml:"log"` | |||
} | |||
//数据库配置结构体 | |||
type DBCfg struct { | |||
Host string `yaml:"host"` //ip及端口 | |||
Name string `yaml:"name"` //库名 | |||
User string `yaml:"user"` //用户 | |||
Psw string `yaml:"psw"` //密码 | |||
ShowLog bool `yaml:"show_log"` //是否显示SQL语句 | |||
MaxLifetime time.Duration `yaml:"max_lifetime"` | |||
MaxOpenConns int `yaml:"max_open_conns"` | |||
MaxIdleConns int `yaml:"max_idle_conns"` | |||
Path string `yaml:"path"` //日志文件存放路径 | |||
} | |||
//日志配置结构体 | |||
type LogCfg struct { | |||
AppName string `yaml:"app_name" ` | |||
Level string `yaml:"level"` | |||
IsStdOut bool `yaml:"is_stdout"` | |||
TimeFormat string `yaml:"time_format"` // second, milli, nano, standard, iso, | |||
Encoding string `yaml:"encoding"` // console, json | |||
IsFileOut bool `yaml:"is_file_out"` | |||
FileDir string `yaml:"file_dir"` | |||
FileName string `yaml:"file_name"` | |||
FileMaxSize int `yaml:"file_max_size"` | |||
FileMaxAge int `yaml:"file_max_age"` | |||
} |
@@ -0,0 +1,3 @@ | |||
package cfg | |||
// 统一管理缓存 |
@@ -0,0 +1,9 @@ | |||
package cfg | |||
import ( | |||
"applet/app/utils/cache" | |||
) | |||
func InitCache() { | |||
cache.NewRedis(RedisAddr) | |||
} |
@@ -0,0 +1,48 @@ | |||
package cfg | |||
import ( | |||
"flag" | |||
"io/ioutil" | |||
"gopkg.in/yaml.v2" | |||
) | |||
//配置文件数据,全局变量 | |||
var ( | |||
Debug bool | |||
Prd bool | |||
SrvAddr string | |||
SmartCanteenPay string | |||
RedisAddr string | |||
DB *DBCfg | |||
Log *LogCfg | |||
) | |||
//初始化配置文件,将cfg.yml读入到内存 | |||
func InitCfg() { | |||
//用指定的名称、默认值、使用信息注册一个string类型flag。 | |||
path := flag.String("c", "etc/cfg.yml", "config file") | |||
//解析命令行参数写入注册的flag里。 | |||
//解析之后,flag的值可以直接使用。 | |||
flag.Parse() | |||
var ( | |||
c []byte | |||
err error | |||
conf *Config | |||
) | |||
if c, err = ioutil.ReadFile(*path); err != nil { | |||
panic(err) | |||
} | |||
//yaml.Unmarshal反序列化映射到Config | |||
if err = yaml.Unmarshal(c, &conf); err != nil { | |||
panic(err) | |||
} | |||
//数据读入内存 | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
DB = &conf.DB | |||
Log = &conf.Log | |||
RedisAddr = conf.RedisAddr | |||
SmartCanteenPay = conf.SmartCanteenPay | |||
SrvAddr = conf.SrvAddr | |||
} |
@@ -0,0 +1,20 @@ | |||
package cfg | |||
import "applet/app/utils/logx" | |||
func InitLog() { | |||
logx.InitDefaultLogger(&logx.LogConfig{ | |||
AppName: Log.AppName, | |||
Level: Log.Level, | |||
StacktraceLevel: "error", | |||
IsStdOut: Log.IsStdOut, | |||
TimeFormat: Log.TimeFormat, | |||
Encoding: Log.Encoding, | |||
IsFileOut: Log.IsFileOut, | |||
FileDir: Log.FileDir, | |||
FileName: Log.FileName, | |||
FileMaxSize: Log.FileMaxSize, | |||
FileMaxAge: Log.FileMaxAge, | |||
Skip: 2, | |||
}) | |||
} |
@@ -0,0 +1,42 @@ | |||
package cfg | |||
import ( | |||
"flag" | |||
"io/ioutil" | |||
"gopkg.in/yaml.v2" | |||
mc "applet/app/utils/cache/cache" | |||
"applet/app/utils/logx" | |||
) | |||
func InitTaskCfg() { | |||
path := flag.String("c", "etc/task.yml", "config file") | |||
flag.Parse() | |||
var ( | |||
c []byte | |||
err error | |||
conf *Config | |||
) | |||
if c, err = ioutil.ReadFile(*path); err != nil { | |||
panic(err) | |||
} | |||
if err = yaml.Unmarshal(c, &conf); err != nil { | |||
panic(err) | |||
} | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
DB = &conf.DB | |||
Log = &conf.Log | |||
RedisAddr = conf.RedisAddr | |||
} | |||
var MemCache mc.Cache | |||
func InitMemCache() { | |||
var err error | |||
MemCache, err = mc.NewCache("memory", `{"interval":60}`) | |||
if err != nil { | |||
logx.Fatal(err.Error()) | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
package enum | |||
type QrcodeBatchState int32 | |||
const ( | |||
QrcodeBatchStateForUseIng = 1 | |||
QrcodeBatchStateForUseAlready = 2 | |||
QrcodeBatchStateForExpire = 3 | |||
QrcodeBatchStateForCancel = 4 | |||
) | |||
func (gt QrcodeBatchState) String() string { | |||
switch gt { | |||
case QrcodeBatchStateForUseIng: | |||
return "使用中" | |||
case QrcodeBatchStateForUseAlready: | |||
return "使用完" | |||
case QrcodeBatchStateForExpire: | |||
return "已过期" | |||
case QrcodeBatchStateForCancel: | |||
return "已作废" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type QrcodeWithBatchRecordsSate int32 | |||
const ( | |||
QrcodeWithBatchRecordsStateForWait = 1 | |||
QrcodeWithBatchRecordsStateForAlready = 2 | |||
QrcodeWithBatchRecordsStateForExpire = 3 | |||
QrcodeWithBatchRecordsStateForCancel = 4 | |||
) | |||
func (gt QrcodeWithBatchRecordsSate) String() string { | |||
switch gt { | |||
case QrcodeWithBatchRecordsStateForWait: | |||
return "待使用" | |||
case QrcodeWithBatchRecordsStateForAlready: | |||
return "已使用" | |||
case QrcodeWithBatchRecordsStateForExpire: | |||
return "已过期" | |||
case QrcodeWithBatchRecordsStateForCancel: | |||
return "已作废" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type QrcodeSate int32 | |||
const ( | |||
QrcodeSateAllowUse = 1 | |||
QrcodeSateAllowNotUse = 2 | |||
) | |||
func (gt QrcodeSate) String() string { | |||
switch gt { | |||
case QrcodeSateAllowUse: | |||
return "可使用" | |||
case QrcodeSateAllowNotUse: | |||
return "不可用" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package enum | |||
type WxOfficialAccountRequest string | |||
const ( | |||
GetAccessToken = "cgi-bin/token" | |||
QrcodeCreate = "cgi-bin/qrcode/create" | |||
) | |||
func (gt WxOfficialAccountRequest) String() string { | |||
switch gt { | |||
case GetAccessToken: | |||
return "获取 Access token" | |||
case QrcodeCreate: | |||
return "生成带参二维码" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/lib/validate" | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func AesDecrypt(c *gin.Context) { | |||
var req md.CurlAesDecrypt | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err, result := svc.AesDecrypt(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, result, nil) | |||
return | |||
} | |||
func SystemOauthToken(c *gin.Context) { | |||
var req md.SystemOauthTokenReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err, result := svc.SystemOauthToken(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, result, nil) | |||
return | |||
} |
@@ -0,0 +1,21 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func BannerList(c *gin.Context) { | |||
bannerDb := db.BannerDb{} | |||
bannerDb.Set() | |||
banners, err := bannerDb.FindBanner(0, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": banners, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,278 @@ | |||
package hdl | |||
import ( | |||
"applet/app/admin/lib/validate" | |||
"applet/app/customer/md" | |||
svc "applet/app/customer/svc/order" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func CentralKitchenForSchoolOrderList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrderListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
list, total, err := svc.OrderList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"total": total, | |||
"ord_state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForWait, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete, | |||
}, | |||
}, | |||
"kind_list": []map[string]string{ | |||
{ | |||
"name": "按学期购买", | |||
"value": "1", | |||
}, | |||
{ | |||
"name": "按月购买", | |||
"value": "2", | |||
}, | |||
{ | |||
"name": "按天购买", | |||
"value": "3", | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderDetail(c *gin.Context) { | |||
outTradeNo := c.DefaultQuery("out_trade_no", "") | |||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if ord == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") | |||
return | |||
} | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByOrdNo(ord.OutTradeNo) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var total, totalBreakfast, totalLunch, totalDinner int | |||
total = len(*list) | |||
for _, v := range *list { | |||
if v.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { | |||
totalBreakfast++ | |||
} | |||
if v.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { | |||
totalLunch++ | |||
} | |||
if v.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { | |||
totalDinner++ | |||
} | |||
} | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(ord.EnterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"enterprise": enterprise, | |||
"total": total, | |||
"ord_info": ord, | |||
"total_breakfast": totalBreakfast, | |||
"total_lunch": totalLunch, | |||
"total_dinner": totalDinner, | |||
"ord_state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForWait, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete), | |||
"value": enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete, | |||
}, | |||
}, | |||
"kind_list": []map[string]string{ | |||
{ | |||
"name": "按学期购买", | |||
"value": "1", | |||
}, | |||
{ | |||
"name": "按月购买", | |||
"value": "2", | |||
}, | |||
{ | |||
"name": "按天购买", | |||
"value": "3", | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderBelowWithDay(c *gin.Context) { | |||
outTradeNo := c.DefaultQuery("out_trade_no", "") | |||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if ord == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") | |||
return | |||
} | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
list, err := centralKitchenForSchoolUserWithDayDb.FindCentralKitchenForSchoolUserWithDayByOrdNoAndState(ord.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForWait) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"allow_refund_state": enum.CentralKitchenForSchoolUserWithDayStateForWait, | |||
"kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForLunch, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForDinner, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefund(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrderRefundReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.CentralKitchenForSchoolOrderRefund(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefundList(c *gin.Context) { | |||
var req md.CentralKitchenForSchoolOrderRefundListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
list, total, err := svc.CentralKitchenForSchoolOrderRefundList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": list, | |||
"total": total, | |||
"kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForBreakfast, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForLunch, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner), | |||
"value": enum.CentralKitchenForSchoolUserWithDayKindForDinner, | |||
}, | |||
}, | |||
"state_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditing, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject, | |||
}, | |||
{ | |||
"name": enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete), | |||
"value": enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,58 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func CentralKitchenForSchoolPackage(c *gin.Context) { | |||
enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "")) | |||
//1、查询出当前合适的package | |||
var m []model.CentralKitchenForSchoolPackage | |||
now := time.Now().Format("2006-01-02 15:04:05") | |||
err := db.Db.Where("enterprise_id =?", enterpriseId).Where("end_date > ?", now).And("is_delete = 0").And("state = 1").Desc("end_date").Find(&m) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//2、循环拼接数据 | |||
var resp []md.FindCentralKitchenForSchoolPackageReq | |||
for _, v := range m { | |||
centralKitchenForSchoolPackageWithDayDb := db.CentralKitchenForSchoolPackageWithDayDb{} | |||
centralKitchenForSchoolPackageWithDayDb.Set(v.Id) | |||
centralKitchenForSchoolPackageWithDay, err1 := centralKitchenForSchoolPackageWithDayDb.FindCentralKitchenForSchoolPackageWithDay() | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
var tempResp = md.FindCentralKitchenForSchoolPackageReq{ | |||
PackageId: v.Id, | |||
EnterpriseId: v.EnterpriseId, | |||
Year: v.Year, | |||
Month: v.Month, | |||
StartDate: v.StartDate, | |||
EndDate: v.EndDate, | |||
DateList: nil, | |||
} | |||
for _, v1 := range *centralKitchenForSchoolPackageWithDay { | |||
tempResp.DateList = append(tempResp.DateList, struct { | |||
Date string `json:"date"` | |||
IsOpenBreakfast int32 `json:"is_open_breakfast"` | |||
IsOpenLunch int32 `json:"is_open_lunch"` | |||
IsOpenDinner int32 `json:"is_open_dinner"` | |||
IsOpenReplenish int32 `json:"is_open_replenish"` | |||
}{Date: v1.Date, IsOpenBreakfast: int32(v1.IsOpenBreakfast), IsOpenLunch: int32(v1.IsOpenLunch), IsOpenDinner: int32(v1.IsOpenDinner), IsOpenReplenish: int32(v1.IsOpenReplenish)}) | |||
} | |||
resp = append(resp, tempResp) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,142 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/lib/validate" | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func EnterpriseList(c *gin.Context) { | |||
var req md.EnterpriseListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
if req.Limit == 0 { | |||
req.Limit = 10 | |||
} | |||
if req.Page == 0 { | |||
req.Page = 10 | |||
} | |||
enterprises, total, err := svc.EnterpriseList(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": enterprises, | |||
"total": total, | |||
"kind": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForSchool).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForFactory).String(), | |||
"value": enum.EnterprisePvdByCentralKitchenForFactory, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForSchool).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForFactory).String(), | |||
"value": enum.EnterprisePvdBySelfSupportForFactory, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func EnterpriseInfo(c *gin.Context) { | |||
enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "")) | |||
enterpriseDb := db.EnterpriseDb{} | |||
enterpriseDb.Set() | |||
enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if enterprise == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||
return | |||
} | |||
var resp interface{} | |||
//判断单位类型 | |||
switch enterprise.Kind { | |||
case enum.EnterprisePvdByCentralKitchenForSchool: | |||
err, resp = svc.CentralKitchenForSchoolInfo(enterpriseId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
break | |||
} | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
res := sysCfgDb.SysCfgFindWithDb(enum.AdministratorContactInfo, enum.CentralKitchenForSchoolReserveMealTime) | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": resp, | |||
"set_center": res, | |||
"enterprise_kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForSchool), | |||
"value": enum.EnterprisePvdByCentralKitchenForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdByCentralKitchenForFactory), | |||
"value": enum.EnterprisePvdByCentralKitchenForFactory, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForSchool), | |||
"value": enum.EnterprisePvdBySelfSupportForSchool, | |||
}, | |||
{ | |||
"name": enum.EnterprisePvd.String(enum.EnterprisePvdBySelfSupportForFactory), | |||
"value": enum.EnterprisePvdBySelfSupportForFactory, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
func SchoolBelowGrade(c *gin.Context) { | |||
enterpriseId := c.DefaultQuery("enterprise_id", "") | |||
gradeDb := db.GradeDb{} | |||
gradeDb.Set(utils.StrToInt(enterpriseId)) | |||
gradeList, err := gradeDb.FindGrade() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": gradeList, | |||
}, nil) | |||
return | |||
} | |||
func SchoolGradeBelowClass(c *gin.Context) { | |||
gradeId := c.DefaultQuery("grade_id", "") | |||
classDb := db.ClassDb{} | |||
classDb.Set(utils.StrToInt(gradeId)) | |||
classList, err := classDb.FindClass() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": classList, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,118 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/lib/validate" | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
svc2 "applet/app/svc" | |||
"applet/app/utils" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func Login(c *gin.Context) { | |||
var req md.LoginReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
userDb := db.UserDb{} | |||
userDb.Set() | |||
user, err := userDb.GetUserByPhone(req.Phone) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err) | |||
return | |||
} | |||
if user == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "用户信息不存在") | |||
return | |||
} | |||
ip := utils.GetIP(c.Request) | |||
key := fmt.Sprintf(md.UserJwtTokenKey, ip, utils.AnyToString(user.Id)) | |||
token, err := svc.HandleLoginToken(key, user) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, md.LoginResponse{ | |||
Token: token, | |||
}, nil) | |||
return | |||
} | |||
func Register(c *gin.Context) { | |||
var req md.RegisterReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = svc2.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
userDb := db.UserDb{} | |||
userDb.Set() | |||
user, err := userDb.GetUserByPhone(req.Phone) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err) | |||
return | |||
} | |||
if user == nil { | |||
user = &model.User{ | |||
UserId: req.UserId, | |||
Nickname: req.Nickname, | |||
Avatar: req.Avatar, | |||
Phone: req.Phone, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
insertAffected, err1 := userDb.UserInsert(user) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1) | |||
return | |||
} | |||
if insertAffected <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增用户数据失败") | |||
return | |||
} | |||
} else { | |||
user.UserId = req.UserId | |||
if req.Nickname != "" { | |||
user.Nickname = req.Nickname | |||
} | |||
if req.Avatar != "" { | |||
user.Avatar = req.Avatar | |||
} | |||
user.UpdateAt = now | |||
updateAffected, err1 := userDb.UpdateUser(user, "user_id", "nickname", "avatar", "update_at") | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1) | |||
return | |||
} | |||
if updateAffected <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "更新用户数据失败") | |||
return | |||
} | |||
} | |||
ip := utils.GetIP(c.Request) | |||
key := fmt.Sprintf(md.UserJwtTokenKey, ip, utils.AnyToString(user.Id)) | |||
token, err := svc.HandleLoginToken(key, user) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, md.LoginResponse{ | |||
Token: token, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,21 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func NoticeList(c *gin.Context) { | |||
noticeDb := db.NoticeDb{} | |||
noticeDb.Set() | |||
notices, err := noticeDb.FindNotice(0, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": notices, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,107 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/lib/validate" | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"encoding/json" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func BuyPackage(c *gin.Context) { | |||
var req md.BuyPackageReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
outTradeNo, tradeNo, total, err := svc.BuyPackage(c, req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"out_trade_no": outTradeNo, | |||
"trade_no": tradeNo, | |||
"total": total, | |||
}, nil) | |||
return | |||
} | |||
func OrdState(c *gin.Context) { | |||
outTradeNo := c.DefaultQuery("out_trade_no", "") | |||
centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} | |||
centralKitchenForSchoolPackageOrd.Set(outTradeNo) | |||
ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if ord == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") | |||
return | |||
} | |||
if ord.State == enum.CentralKitchenForSchoolPackageOrdStateForWait { | |||
//处于待支付状态,请求支付宝同步订单状态 | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
sysCfg, err1 := sysCfgDb.SysCfgGetOne(enum.JsapiPayAppAutToken) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
err2, result := svc.CurlAlipayTradeQuery(md.CurlAlipayTradeQueryReq{ | |||
OutTradeNo: outTradeNo, | |||
AppAuthToken: sysCfg.Val, | |||
}) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR, err2.Error()) | |||
return | |||
} | |||
if result.TradeStatus == "TRADE_CLOSED" { | |||
ord.State = enum.CentralKitchenForSchoolPackageOrdStateForFail | |||
} | |||
if result.TradeStatus == "TRADE_SUCCESS" { | |||
ord.State = enum.CentralKitchenForSchoolPackageOrdStateForSuccess | |||
ord.OrdState = enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess | |||
//TODO::将预留数据插入到 `central_kitchen_for_school_user_with_day` | |||
var data []*model.CentralKitchenForSchoolUserWithDay | |||
err4 := json.Unmarshal([]byte(ord.WithDayData), &data) | |||
if err4 != nil { | |||
e.OutErr(c, e.ERR, err4.Error()) | |||
return | |||
} | |||
for _, v := range data { | |||
v.OrdNo = outTradeNo | |||
} | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
_, err5 := centralKitchenForSchoolUserWithDayDb.BatchAddCentralKitchenForSchoolUserWithDays(data) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err5.Error()) | |||
return | |||
} | |||
} | |||
_, err3 := centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdUpdate(ord, "state", "ord_state") | |||
if err3 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) | |||
return | |||
} | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"sate": ord.State, | |||
"sate_zh": enum.CentralKitchenForSchoolPackageOrdState.String(enum.CentralKitchenForSchoolPackageOrdState(ord.State)), | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,17 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GetSysCfg(c *gin.Context) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
res := sysCfgDb.SysCfgFindWithDb(enum.AppName, enum.OpenAppletAppid, enum.OpenAppletPublicKey, enum.OpenAppletAppPublicKey, enum.OpenAppletAppPrivateKey, enum.OpenAppletAesKey, | |||
enum.FileBucket, enum.FileExt, enum.FileAccessKey, enum.FileUserUploadMaxSize, enum.FileSecretKey, enum.FileBucketScheme, enum.FileBucketRegion, enum.FileBucketHost) | |||
e.OutSuc(c, res, nil) | |||
return | |||
} |
@@ -0,0 +1,61 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func UserInfo(c *gin.Context) { | |||
//1、获取用户信息 | |||
userInfo := svc.GetUser(c) | |||
//2、获取用户身份信息 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(userInfo.Id) | |||
identity, err := userIdentityDb.FindUserIdentity() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var identityList []map[string]interface{} | |||
for _, v := range *identity { | |||
identityList = append(identityList, map[string]interface{}{ | |||
"identity": v.UserIdentity, | |||
"enterprise": v.Enterprise, | |||
}) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"user_info": userInfo, | |||
"user_identity": identityList, | |||
"user_identity_kind_list": []map[string]interface{}{ | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent), | |||
"value": enum.UserIdentityForCentralKitchenForStudent, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher), | |||
"value": enum.UserIdentityForCentralKitchenForTeacher, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker), | |||
"value": enum.UserIdentityForCentralKitchenForWorker, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent), | |||
"value": enum.UserIdentityForSelfSupportForStudent, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher), | |||
"value": enum.UserIdentityForSelfSupportForTeacher, | |||
}, | |||
{ | |||
"name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker), | |||
"value": enum.UserIdentityForSelfSupportForWorker, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} |
@@ -0,0 +1,327 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/lib/validate" | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func SaveCentralKitchenForSchoolUserIdentity(c *gin.Context) { | |||
var req md.SaveCentralKitchenForSchoolUserIdentityReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
user := svc.GetUser(c) | |||
var identity = enum.UserIdentityForCentralKitchenForStudent | |||
if req.IsTeacher { | |||
identity = enum.UserIdentityForCentralKitchenForTeacher | |||
} | |||
//1、判断当前身份是否已绑定 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(user.Id) | |||
isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if isHasUserIdentity != nil { | |||
e.OutErr(c, e.ERR, "当前身份信息已被绑定使用") | |||
return | |||
} | |||
//2、新增身份信息 | |||
now := time.Time{} | |||
userIdentity := &model.UserIdentity{ | |||
Uid: user.Id, | |||
Name: req.Name, | |||
IdNo: req.IdNo, | |||
Kind: enum.UserIdentityKindForCommon, | |||
Identity: identity, | |||
EnterpriseId: req.EnterpriseId, | |||
State: enum.UserIdentityStateForNormal, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if insertAffected <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败") | |||
return | |||
} | |||
//3、新增 class_with_user 记录 | |||
if !req.IsTeacher { | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
_, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ | |||
UserIdentityId: insertAffected, | |||
ClassId: req.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) { | |||
var req md.SaveSelfSupportForSchoolUserIdentityReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
user := svc.GetUser(c) | |||
now := time.Time{} | |||
var identity = enum.UserIdentityForSelfSupportForStudent | |||
var kind = enum.UserIdentityKindForCommon | |||
if req.Kind == enum.UserIdentityKindForWorker { | |||
kind = enum.UserIdentityKindForWorker | |||
identity = enum.UserIdentityForSelfSupportForWorker | |||
} else { | |||
if req.IsTeacher { | |||
identity = enum.UserIdentityForCentralKitchenForTeacher | |||
} | |||
} | |||
//1、判断当前身份是否已绑定 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(user.Id) | |||
isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if isHasUserIdentity == nil { | |||
if identity != enum.UserIdentityForSelfSupportForStudent { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在") | |||
return | |||
} | |||
//2、新增身份信息 | |||
userIdentity := &model.UserIdentity{ | |||
Uid: user.Id, | |||
Name: req.Name, | |||
IdNo: req.IdNo, | |||
Kind: kind, | |||
Identity: identity, | |||
EnterpriseId: req.EnterpriseId, | |||
State: enum.UserIdentityStateForNormal, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if insertAffected <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败") | |||
return | |||
} | |||
//3、新增 class_with_user 记录 | |||
if !req.IsTeacher { | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
_, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ | |||
UserIdentityId: insertAffected, | |||
ClassId: req.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
} | |||
} else { | |||
if isHasUserIdentity.Uid != 0 { | |||
e.OutErr(c, e.ERR, "当前身份信息已被绑定使用") | |||
return | |||
} | |||
//4、修改身份信息 | |||
isHasUserIdentity.Uid = user.Id | |||
isHasUserIdentity.Name = req.Name | |||
_, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if identity == enum.UserIdentityForSelfSupportForStudent { | |||
//5、修改 class_with_user 记录 | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
if classWithUser == nil { | |||
_, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ | |||
UserIdentityId: isHasUserIdentity.Id, | |||
ClassId: req.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} else { | |||
classWithUser.ClassId = req.ClassId | |||
_, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id") | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CentralKitchenForSchoolMyReserve(c *gin.Context) { | |||
//user := svc.GetUser(c) | |||
var req md.SaveSelfSupportForSchoolUserIdentityReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
user := svc.GetUser(c) | |||
now := time.Time{} | |||
var identity = enum.UserIdentityForSelfSupportForStudent | |||
var kind = enum.UserIdentityKindForCommon | |||
if req.Kind == enum.UserIdentityKindForWorker { | |||
kind = enum.UserIdentityKindForWorker | |||
identity = enum.UserIdentityForSelfSupportForWorker | |||
} else { | |||
if req.IsTeacher { | |||
identity = enum.UserIdentityForCentralKitchenForTeacher | |||
} | |||
} | |||
//1、判断当前身份是否已绑定 | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(user.Id) | |||
isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if isHasUserIdentity == nil { | |||
if identity != enum.UserIdentityForSelfSupportForStudent { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在") | |||
return | |||
} | |||
//2、新增身份信息 | |||
userIdentity := &model.UserIdentity{ | |||
Uid: user.Id, | |||
Name: req.Name, | |||
IdNo: req.IdNo, | |||
Kind: kind, | |||
Identity: identity, | |||
EnterpriseId: req.EnterpriseId, | |||
State: enum.UserIdentityStateForNormal, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
} | |||
insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if insertAffected <= 0 { | |||
e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败") | |||
return | |||
} | |||
//3、新增 class_with_user 记录 | |||
if !req.IsTeacher { | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
_, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ | |||
UserIdentityId: insertAffected, | |||
ClassId: req.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
} | |||
} else { | |||
if isHasUserIdentity.Uid != 0 { | |||
e.OutErr(c, e.ERR, "当前身份信息已被绑定使用") | |||
return | |||
} | |||
//4、修改身份信息 | |||
isHasUserIdentity.Uid = user.Id | |||
isHasUserIdentity.Name = req.Name | |||
_, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if identity == enum.UserIdentityForSelfSupportForStudent { | |||
//5、修改 class_with_user 记录 | |||
classWithUserDb := db.ClassWithUserDb{} | |||
classWithUserDb.Set() | |||
classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
if classWithUser == nil { | |||
_, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ | |||
UserIdentityId: isHasUserIdentity.Id, | |||
ClassId: req.ClassId, | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} else { | |||
classWithUser.ClassId = req.ClassId | |||
_, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id") | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
} | |||
} | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} |
@@ -0,0 +1,169 @@ | |||
package hdl | |||
import ( | |||
"applet/app/customer/md" | |||
"applet/app/customer/svc" | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func EducateSceneTokenQuery(c *gin.Context) { | |||
userIdentityId := c.DefaultQuery("user_identity_id", "") | |||
userToken := c.DefaultQuery("user_token", "") | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
identity, err := userIdentityDb.GetUserIdentity(utils.StrToInt(userIdentityId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} | |||
selfSupportForSchoolInfoDb.Set(identity.EnterpriseId) | |||
selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if selfSupportForSchoolInfo == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》") | |||
return | |||
} | |||
//请求支付宝 alipay.commerce.educate.scene.token.query(查询刷脸用户开通详细信息) | |||
err, info := svc.CurlEducateSceneTokenQuery(md.CurlEducateSceneTokenReq{ | |||
CertNo: identity.IdNo, | |||
StudentName: identity.Name, | |||
OutUserId: utils.IntToStr(identity.Id), | |||
SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode, | |||
}, identity.Id, userToken) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, info, nil) | |||
return | |||
} | |||
func EducateSceneTokenCreateForApplet(c *gin.Context) { | |||
userIdentityId := c.DefaultQuery("user_identity_id", "") | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
identity, err := userIdentityDb.GetUserIdentity(utils.StrToInt(userIdentityId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} | |||
selfSupportForSchoolInfoDb.Set(identity.EnterpriseId) | |||
selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if selfSupportForSchoolInfo == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》") | |||
return | |||
} | |||
//请求支付宝 alipay.commerce.educate.scene.token.query(查询刷脸用户开通详细信息) | |||
err, info := svc.CurlEducateSceneTokenCreateForApplet(md.CurlEducateSceneTokenReq{ | |||
CertNo: identity.IdNo, | |||
StudentName: identity.Name, | |||
OutUserId: utils.IntToStr(identity.Id), | |||
SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, info, nil) | |||
return | |||
} | |||
func EducateFacepayApply(c *gin.Context) { | |||
faceOpenId := c.DefaultQuery("face_open_id", "") | |||
userIdentityId := c.DefaultQuery("user_identity_id", "") | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
identity, err := userIdentityDb.GetUserIdentity(utils.StrToInt(userIdentityId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} | |||
selfSupportForSchoolInfoDb.Set(identity.EnterpriseId) | |||
selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if selfSupportForSchoolInfo == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》") | |||
return | |||
} | |||
//请求支付宝 alipay.commerce.educate.scene.token.query(查询刷脸用户开通详细信息) | |||
selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} | |||
selfSupportForUserFaceInfoDb.Set(utils.StrToInt(userIdentityId)) | |||
faceInfo, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if faceInfo == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前用户身份未查询到一脸通行相关数据") | |||
return | |||
} | |||
err, info := svc.CurlEducateFacepayApply(md.CurlEducateFacepayApplyReq{ | |||
FaceUid: faceInfo.UserId, | |||
FaceOpenId: faceOpenId, | |||
SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, info, nil) | |||
return | |||
} | |||
func EducateSceneTokenCreateForConcentratedCollectApplet(c *gin.Context) { | |||
user := svc.GetUser(c) | |||
userIdentityId := c.DefaultQuery("user_identity_id", "") | |||
userIdentityDb := db.UserIdentityDb{} | |||
userIdentityDb.Set(0) | |||
identity, err := userIdentityDb.GetUserIdentity(utils.StrToInt(userIdentityId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} | |||
selfSupportForSchoolInfoDb.Set(identity.EnterpriseId) | |||
selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if selfSupportForSchoolInfo == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》") | |||
return | |||
} | |||
//请求支付宝 alipay.commerce.educate.scene.token.query(查询刷脸用户开通详细信息) | |||
err, info := svc.CurlEducateSceneTokenCreateForConcentratedCollectApplet(md.CurlEducateSceneTokenReq{ | |||
CertNo: identity.IdNo, | |||
StudentName: identity.Name, | |||
OutUserId: utils.IntToStr(identity.Id), | |||
SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode, | |||
OperatorUserId: user.UserId, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, info, nil) | |||
return | |||
} |
@@ -0,0 +1,39 @@ | |||
package auth | |||
import ( | |||
"errors" | |||
"github.com/dgrijalva/jwt-go" | |||
"time" | |||
) | |||
// GenToken 生成JWT | |||
func GenToken(userId int, username string) (string, error) { | |||
// 创建一个我们自己的声明 | |||
c := JWTUser{ | |||
UserId: userId, | |||
Username: username, | |||
StandardClaims: jwt.StandardClaims{ | |||
ExpiresAt: time.Now().Add(TokenExpireDuration).Unix(), // 过期时间 | |||
Issuer: "smart_canteen", // 签发人 | |||
}, | |||
} | |||
// 使用指定的签名方法创建签名对象 | |||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, c) | |||
// 使用指定的secret签名并获得完整的编码后的字符串token | |||
return token.SignedString(Secret) | |||
} | |||
// ParseToken 解析JWT | |||
func ParseToken(tokenString string) (*JWTUser, error) { | |||
// 解析token | |||
token, err := jwt.ParseWithClaims(tokenString, &JWTUser{}, func(token *jwt.Token) (i interface{}, err error) { | |||
return Secret, nil | |||
}) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if claims, ok := token.Claims.(*JWTUser); ok && token.Valid { // 校验token | |||
return claims, nil | |||
} | |||
return nil, errors.New("invalid token") | |||
} |
@@ -0,0 +1,19 @@ | |||
package auth | |||
import ( | |||
"time" | |||
"github.com/dgrijalva/jwt-go" | |||
) | |||
// TokenExpireDuration is jwt 过期时间 | |||
const TokenExpireDuration = time.Hour * 4380 | |||
var Secret = []byte("smart_canteen_customer") | |||
// JWTUser 如果想要保存更多信息,都可以添加到这个结构体中 | |||
type JWTUser struct { | |||
UserId int `json:"user_id"` | |||
Username string `json:"username"` | |||
jwt.StandardClaims | |||
} |
@@ -0,0 +1,33 @@ | |||
package validate | |||
import ( | |||
"applet/app/e" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/go-playground/validator/v10" | |||
) | |||
func HandleValidateErr(err error) error { | |||
switch err.(type) { | |||
case *json.UnmarshalTypeError: | |||
return e.NewErr(e.ERR_UNMARSHAL, "参数格式错误") | |||
case validator.ValidationErrors: | |||
errs := err.(validator.ValidationErrors) | |||
transMsgMap := errs.Translate(utils.ValidatorTrans) // utils.ValidatorTrans \app\utils\validator_err_trans.go::ValidatorTransInit初始化获得 | |||
transMsgOne := transMsgMap[GetOneKeyOfMapString(transMsgMap)] | |||
return e.NewErr(e.ERR_INVALID_ARGS, transMsgOne) | |||
default: | |||
_ = logx.Error(err) | |||
return e.NewErr(e.ERR, fmt.Sprintf("validate request params, err:%v\n", err)) | |||
} | |||
} | |||
// GetOneKeyOfMapString 取出Map的一个key | |||
func GetOneKeyOfMapString(collection map[string]string) string { | |||
for k := range collection { | |||
return k | |||
} | |||
return "" | |||
} |
@@ -0,0 +1,7 @@ | |||
package md | |||
// 缓存key统一管理 | |||
const ( | |||
UserJwtTokenKey = "%s:smart_canteen_user_jwt_token:%s" // jwt, 占位符:ip, user:id | |||
JwtTokenCacheTime = 3600 * 24 * 1 | |||
) |
@@ -0,0 +1,76 @@ | |||
package md | |||
type CurlAesDecrypt struct { | |||
Content string `json:"content" binding:"required" label:"解密内容"` | |||
} | |||
type SystemOauthTokenReq struct { | |||
Code string `json:"code" binding:"required" label:"授权码"` | |||
} | |||
type CurlAlipayTradeCreateReq struct { | |||
Config struct { | |||
PayAliAppId string `json:"pay_ali_app_id" binding:"required" label:"支付宝开放平台-第三方应用-appid"` | |||
PayAliPrivateKey string `json:"pay_ali_private_key" binding:"required" label:"支付宝开放平台-第三方应用-接口加签-应用私钥"` | |||
PayAliPublicKey string `json:"pay_ali_public_key" binding:"required" label:"支付宝开放平台-第三方应用-接口加签-支付宝公钥"` | |||
} `json:"config" binding:"required" label:"配置信息"` | |||
BuyerId string `json:"buyer_id" binding:"required" label:"买家支付宝用户ID"` | |||
TotalAmount string `json:"total_amount" binding:"required" label:"订单总金额"` | |||
OutTradeNo string `json:"out_trade_no" binding:"required" label:"商户订单号"` | |||
Subject string `json:"subject" binding:"required" label:"订单标题"` | |||
AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | |||
} | |||
type CurlAlipayTradeCreateResp struct { | |||
Code string `json:"code" label:"响应码"` | |||
Msg string `json:"msg" label:"响应消息"` | |||
OutTradeNo string `json:"out_trade_no" label:"商户订单号"` | |||
TradeNo string `json:"trade_no" label:"支付宝交易号"` | |||
} | |||
type CurlAlipayTradeQueryReq struct { | |||
OutTradeNo string `json:"out_trade_no" label:"商户订单号"` | |||
AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | |||
} | |||
type CurlAlipayTradeQueryResp struct { | |||
Code string `json:"code" label:"响应码"` | |||
Msg string `json:"msg" label:"响应消息"` | |||
OutTradeNo string `json:"out_trade_no" label:"商户订单号"` | |||
TradeNo string `json:"trade_no" label:"支付宝交易号"` | |||
TradeStatus string `json:"trade_status" label:"交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款)"` | |||
} | |||
type CurlAlipayTradeRefundReq struct { | |||
OutTradeNo string `json:"out_trade_no" label:"商户订单号"` | |||
RefundAmount string `json:"refund_amount" label:"退款金额"` | |||
RefundReason string `json:"refund_reason" label:"退款原因"` | |||
OutRequestNo string `json:"out_request_no" label:"退款订单号"` | |||
AppAuthToken string `json:"app_auth_token" binding:"required" label:"应用授权token"` | |||
} | |||
type CurlEducateSceneTokenReq struct { | |||
CertNo string `json:"cert_no" label:"身份证号码"` | |||
StudentName string `json:"student_name" label:"姓名"` | |||
OutUserId string `json:"out_user_id" label:"服务商内部用户唯一ID,用于与支付宝用户 ID 进行关联"` | |||
SchoolStdCode string `json:"school_std_code" label:"学校外标"` | |||
OperatorUserId string `json:"operator_user_id" label:"采集人员的支付宝会员标识。(当sub_code为SCHOOL_PAYMENT_REMOTE_OPEN_ACCOUNT时,当前参数必选)"` | |||
} | |||
type CurlEducateFacepayApplyReq struct { | |||
FaceUid string `json:"face_uid" label:"刷脸用户id"` | |||
FaceOpenId string `json:"face_open_id" label:"刷脸用户openId"` | |||
SchoolStdCode string `json:"school_std_code" label:"学校外标"` | |||
} | |||
type CurlAlipayPlanetEcocampusApiRosterSignUpInfoReq struct { | |||
FaceUid string `json:"face_uid" label:"学生刷脸编号(不可修改)"` | |||
ParentUid string `json:"parent_uid" label:"家长uid(可修改)"` | |||
ParentLogonId string `json:"parent_logon_id" label:"家长支付宝账号脱敏信息(可修改)"` | |||
RosterName string `json:"roster_name" label:"学生姓名(可修改)"` | |||
OutRosterCode string `json:"out_roster_code" label:"外部花名册编号(不可修改)"` | |||
SchoolCode string `json:"school_code" label:"学校内标(不可修改)"` | |||
SchoolName string `json:"school_name" label:"学校名称(不可修改)"` | |||
ScanFacePayStatus string `json:"scan_face_pay_status" label:"刷脸支付开通状态(可修改) 开通状态:ON,关闭状态:OFF(新增时,不传值默认OFF)"` | |||
FaceOpenStatus string `json:"face_open_status" label:"刷脸开通状态(可修改)"` | |||
} |
@@ -0,0 +1,43 @@ | |||
package md | |||
type EnterpriseListReq struct { | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
Name string `json:"name" ` | |||
} | |||
type CentralKitchenForSchoolInfoResp struct { | |||
Name string `json:"name" label:"名称"` | |||
Memo string `json:"memo" label:"备注"` | |||
Kind int32 `json:"kind" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂)"` | |||
State int32 `json:"state" label:"状态(1:正常 2:冻结)"` | |||
IsOpenTeacherReportMeal int `json:"is_open_teacher_report_meal" label:"教师报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForDay int `json:"is_open_report_meal_for_day" label:"开启按天报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForMonth int `json:"is_open_report_meal_for_month" label:"开启按月报餐(1:开启 2:关闭)"` | |||
IsOpenReportMealForSemester int `json:"is_open_report_meal_for_semester" label:"开启按学期报餐(1:开启 2:关闭)"` | |||
IsOpenBreakfast int `json:"is_open_breakfast" label:"是否开启早餐(1:开启 0:关闭)"` | |||
IsOpenLunch int `json:"is_open_lunch" label:"是否开启午餐(1:开启 0:关闭)"` | |||
IsOpenDinner int `json:"is_open_dinner" label:"是否开启晚餐(1:开启 0:关闭)"` | |||
BreakfastUnitPrice string `json:"breakfast_unit_price" label:"早餐-单价"` | |||
BreakfastUnitPriceForTeacher string `json:"breakfast_unit_price_for_teacher" label:"教师-早餐-单价"` | |||
LunchUnitPrice string `json:"lunch_unit_price" label:"午餐-单价"` | |||
LunchUnitPriceForTeacher string `json:"lunch_unit_price_for_teacher" label:"教师-午餐-单价"` | |||
DinnerUnitPrice string `json:"dinner_unit_price" label:"晚餐-单价"` | |||
DinnerUnitPriceForTeacher string `json:"dinner_unit_price_for_teacher" label:"教师-晚餐-单价"` | |||
} | |||
type FindCentralKitchenForSchoolPackageReq struct { | |||
PackageId int `json:"package_id" label:"套餐ID"` | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Year string `json:"year" binding:"required" label:"年份"` | |||
Month string `json:"month" binding:"required" label:"月份"` | |||
StartDate string `json:"start_date" binding:"required" label:"开始时间"` | |||
EndDate string `json:"end_date" binding:"required" label:"截止时间"` | |||
DateList []struct { | |||
Date string `json:"date"` | |||
IsOpenBreakfast int32 `json:"is_open_breakfast"` | |||
IsOpenLunch int32 `json:"is_open_lunch"` | |||
IsOpenDinner int32 `json:"is_open_dinner"` | |||
IsOpenReplenish int32 `json:"is_open_replenish"` | |||
} `json:"date_list" binding:"required" label:"日期"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package md | |||
type LoginReq struct { | |||
Phone string `json:"phone" binding:"required" label:"登录手机号"` | |||
} | |||
type LoginResponse struct { | |||
Token string `json:"token"` | |||
} | |||
type RegisterReq struct { | |||
UserId string `json:"user_id" binding:"required" label:"支付宝用户的唯一userId"` | |||
Nickname string `json:"nickname" label:"支付宝昵称"` | |||
Avatar string `json:"avatar" label:"支付宝头像"` | |||
Phone string `json:"phone" binding:"required" label:"手机号"` | |||
} |
@@ -0,0 +1,31 @@ | |||
package md | |||
type CentralKitchenForSchoolOrderListReq struct { | |||
UserIdentityId int `json:"user_identity_id" label:"用户身份id"` | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
OrdState int `json:"ord_state" ` | |||
} | |||
type CentralKitchenForSchoolOrderRefundReq struct { | |||
OutTradeNo string `json:"out_trade_no" label:"订单号"` | |||
Id int `json:"id" binding:"required" label:"就餐记录id"` | |||
} | |||
type CentralKitchenForSchoolOrderRefundListReq struct { | |||
UserIdentityId int `json:"user_identity_id" label:"用户身份id"` | |||
Limit int `json:"limit"` | |||
Page int `json:"page" ` | |||
State int `json:"state" ` | |||
} | |||
type CentralKitchenForSchoolOrderRefundListResp struct { | |||
OutTradeNo string `json:"out_trade_no" label:"订单号"` | |||
OutRequestNo string `json:"out_request_no" label:"退款请求号"` | |||
Kind int `json:"kind" label:"预定类型"` | |||
CreateAt string `json:"create_at" label:"退款时间"` | |||
Date string `json:"date" label:"预定时间"` | |||
State int `json:"state" label:"退款状态"` | |||
Memo string `json:"memo" label:"备注"` | |||
Amount string `json:"amount" label:"退款金额"` | |||
} |
@@ -0,0 +1,17 @@ | |||
package md | |||
type BuyPackageReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
UserIdentityId int `json:"user_identity_id" binding:"required" label:"用户身份id"` | |||
PackageId int `json:"package_id" label:"套餐ID"` | |||
Kind int `json:"kind" binding:"required" label:"购买类型(1:按学期购买 2:按月购买 3:按天购买)"` | |||
IsBuyBreakfast int `json:"is_buy_breakfast" label:"是否购买早餐(1:是 2:否)"` | |||
IsBuyLunch int `json:"is_buy_lunch" label:"是否购买午餐(1:是 2:否)"` | |||
IsBuyDinner int `json:"is_buy_dinner" label:"是否购买晚餐(1:是 2:否)"` | |||
WithDays []struct { | |||
Date string `json:"date" label:"日期"` | |||
IsBuyBreakfast int `json:"is_buy_breakfast" label:"是否购买早餐(1:是 2:否)"` | |||
IsBuyLunch int `json:"is_buy_lunch" label:"是否购买午餐(1:是 2:否)"` | |||
IsBuyDinner int `json:"is_buy_dinner" label:"是否购买晚餐(1:是 2:否)"` | |||
} `json:"with_days" label:"包含天数"` | |||
} |
@@ -0,0 +1,31 @@ | |||
package md | |||
const ( | |||
QrcodeTotalNums = 100000 | |||
) | |||
type QrcodeBatchListReq struct { | |||
Page int `json:"page"` | |||
Limit int `json:"limit"` | |||
} | |||
type QrcodeBatchAddReq struct { | |||
Name string `json:"name"` | |||
ExpireDate string `json:"expire_date"` | |||
List []QrcodeBatchAddReqList `json:"list"` | |||
Memo string `json:"memo"` | |||
} | |||
type QrcodeBatchAddReqList struct { | |||
Num int `json:"num"` | |||
Amount string `json:"amount"` | |||
} | |||
type QrcodeBatchAddReqListDetail struct { | |||
Num int `json:"num"` | |||
WaitUseNum int `json:"wait_use_num"` | |||
UsedNum int `json:"used_num"` | |||
ExpiredNum int `json:"expired_num"` | |||
CancelNum int `json:"cancel_num"` | |||
Amount string `json:"amount"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package md | |||
type SetSysCfgReq struct { | |||
WxMchApiV3Key string `json:"wx_mch_api_v3_key" label:"微信商户APIv3密钥"` | |||
WxMchCertificateSerialNumber string `json:"wx_mch_certificate_serial_number" label:"微信商户证书序列号"` | |||
WxMchId string `json:"wx_mch_id" label:"微信商户号"` | |||
WxOfficialAccountAppId string `json:"wx_official_account_app_id" label:"微信公众号appId"` | |||
WxOfficialAccountAppSecret string `json:"wx_official_account_app_secret" label:"微信公众号appSecret"` | |||
} |
@@ -0,0 +1,20 @@ | |||
package md | |||
type SaveCentralKitchenForSchoolUserIdentityReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
IsTeacher bool `json:"is_teacher" label:"是否教师"` | |||
Name string `json:"name" binding:"required" label:"姓名"` | |||
IdNo string `json:"id_no" binding:"required" label:"身份证号码"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} | |||
type SaveSelfSupportForSchoolUserIdentityReq struct { | |||
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` | |||
Kind int `json:"kind" binding:"required" label:"类型(1:普通用户 2:工作人员)"` | |||
IsTeacher bool `json:"is_teacher" label:"是否教师"` | |||
Name string `json:"name" binding:"required" label:"姓名"` | |||
IdNo string `json:"id_no" binding:"required" label:"身份证号码"` | |||
GradeId int `json:"grade_id" label:"年级id"` | |||
ClassId int `json:"class_id" label:"班级id"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package md | |||
const WxOfficialAccountRequestBaseUrl = "https://api.weixin.qq.com/" | |||
type CreateTokenResp struct { | |||
AccessToken string `json:"access_token"` | |||
ExpiresIn int64 `json:"expires_in"` | |||
} | |||
type CreateQrcodeResp struct { | |||
Ticket string `json:"ticket"` | |||
ExpireSeconds int64 `json:"expire_seconds"` | |||
Url string `json:"url"` | |||
} |
@@ -0,0 +1,29 @@ | |||
package mw | |||
import ( | |||
"github.com/gin-gonic/gin" | |||
) | |||
// cors跨域 | |||
func Cors(c *gin.Context) { | |||
// 放行所有OPTIONS方法 | |||
if c.Request.Method == "OPTIONS" { | |||
c.AbortWithStatus(204) | |||
return | |||
} | |||
origin := c.Request.Header.Get("Origin") // 请求头部 | |||
if origin != "" { | |||
c.Header("Access-Control-Allow-Origin", origin) // 这是允许访问来源域 | |||
c.Header("Access-Control-Allow-Methods", "POST,GET,OPTIONS,PUT,DELETE,UPDATE") // 服务器支持的所有跨域请求的方法,为了避免浏览次请求的多次'预检'请求 | |||
// header的类型 | |||
c.Header("Access-Control-Allow-Headers", "Authorization,Content-Length,X-CSRF-Token,Token,session,X_Requested_With,Accept,Origin,Host,Connection,Accept-Encoding,Accept-Language,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Pragma,X-Mx-ReqToken") | |||
// 允许跨域设置,可以返回其他子段 | |||
// 跨域关键设置 让浏览器可以解析 | |||
c.Header("Access-Control-Expose-Headers", "Content-Length,Access-Control-Allow-Origin,Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") | |||
c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒 | |||
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true | |||
c.Set("Content-Type", "Application/json") // 设置返回格式是json | |||
} | |||
c.Next() | |||
} |
@@ -0,0 +1,26 @@ | |||
package mw | |||
import ( | |||
"applet/app/customer/svc" | |||
"applet/app/e" | |||
"github.com/gin-gonic/gin" | |||
) | |||
// 检查权限, 签名等等 | |||
func Auth(c *gin.Context) { | |||
user, err := svc.CheckUser(c) | |||
if err != nil { | |||
switch err.(type) { | |||
case e.E: | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
default: | |||
e.OutErr(c, e.ERR_UNAUTHORIZED, err.Error()) | |||
return | |||
} | |||
} | |||
// 将当前请求的username信息保存到请求的上下文c上 | |||
c.Set("user", user) | |||
c.Next() | |||
} |
@@ -0,0 +1,58 @@ | |||
package mw | |||
import ( | |||
"bytes" | |||
"io/ioutil" | |||
"github.com/gin-gonic/gin" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
) | |||
// 限流器 | |||
func Limiter(c *gin.Context) { | |||
limit := 100 // 限流次数 | |||
ttl := 1 // 限流过期时间 | |||
ip := c.ClientIP() | |||
// 读取token或者ip | |||
token := c.GetHeader("Authorization") | |||
// 判断是否已经超出限额次数 | |||
method := c.Request.Method | |||
host := c.Request.Host | |||
uri := c.Request.URL.String() | |||
buf := make([]byte, 2048) | |||
num, _ := c.Request.Body.Read(buf) | |||
body := buf[:num] | |||
// Write body back | |||
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) | |||
Md5 := utils.Md5(ip + token + method + host + uri + string(body)) | |||
if cache.Exists(Md5) { | |||
c.AbortWithStatusJSON(429, gin.H{ | |||
"code": 429, | |||
"msg": "don't repeat the request", | |||
"data": struct{}{}, | |||
}) | |||
return | |||
} | |||
// 2s后没返回自动释放 | |||
go cache.SetEx(Md5, "0", ttl) | |||
key := "LIMITER_" + ip | |||
reqs, _ := cache.GetInt(key) | |||
if reqs >= limit { | |||
c.AbortWithStatusJSON(429, gin.H{ | |||
"code": 429, | |||
"msg": "too many requests", | |||
"data": struct{}{}, | |||
}) | |||
return | |||
} | |||
if reqs > 0 { | |||
go cache.Incr(key) | |||
} else { | |||
go cache.SetEx(key, 1, ttl) | |||
} | |||
c.Next() | |||
go cache.Del(Md5) | |||
} |
@@ -0,0 +1,57 @@ | |||
package mw | |||
import ( | |||
"net" | |||
"net/http" | |||
"net/http/httputil" | |||
"os" | |||
"runtime/debug" | |||
"strings" | |||
"github.com/gin-gonic/gin" | |||
"go.uber.org/zap" | |||
) | |||
func Recovery(logger *zap.Logger, stack bool) gin.HandlerFunc { | |||
return func(c *gin.Context) { | |||
defer func() { | |||
if err := recover(); err != nil { | |||
var brokenPipe bool | |||
if ne, ok := err.(*net.OpError); ok { | |||
if se, ok := ne.Err.(*os.SyscallError); ok { | |||
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") { | |||
brokenPipe = true | |||
} | |||
} | |||
} | |||
httpRequest, _ := httputil.DumpRequest(c.Request, false) | |||
if brokenPipe { | |||
logger.Error(c.Request.URL.Path, | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
) | |||
// If the connection is dead, we can't write a status to it. | |||
c.Error(err.(error)) | |||
c.Abort() | |||
return | |||
} | |||
if stack { | |||
logger.Error("[Recovery from panic]", | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
zap.String("stack", string(debug.Stack())), | |||
) | |||
} else { | |||
logger.Error("[Recovery from panic]", | |||
zap.Any("error", err), | |||
zap.String("request", string(httpRequest)), | |||
) | |||
} | |||
c.AbortWithStatus(http.StatusInternalServerError) | |||
} | |||
}() | |||
c.Next() | |||
} | |||
} |
@@ -0,0 +1,122 @@ | |||
package svc | |||
import ( | |||
"applet/app/admin/svc/enterprise_manage" | |||
"applet/app/customer/md" | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/enum" | |||
"applet/app/utils" | |||
"errors" | |||
"time" | |||
) | |||
func OrderList(req md.CentralKitchenForSchoolOrderListReq) (m []model.CentralKitchenForSchoolPackageOrd, total int64, err error) { | |||
sess := db.Db.Desc("id").Where("user_identity_id =?", req.UserIdentityId).Limit(req.Limit, (req.Page-1)*req.Limit) | |||
if req.OrdState != 0 { | |||
sess.And("ord_state = ?", req.OrdState) | |||
} | |||
total, err = sess.FindAndCount(&m) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefund(req md.CentralKitchenForSchoolOrderRefundReq) (err error) { | |||
sysCfgDb := db.SysCfgDb{} | |||
sysCfgDb.Set() | |||
cfg, err := sysCfgDb.SysCfgGetOne(enum.CentralKitchenForSchoolReserveMealTime) | |||
if err != nil { | |||
return | |||
} | |||
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} | |||
centralKitchenForSchoolUserWithDayDb.Set(0) | |||
centralKitchenForSchoolUserWithDay, err := centralKitchenForSchoolUserWithDayDb.GetCentralKitchenForSchoolUserWithDay(req.Id) | |||
if err != nil { | |||
return err | |||
} | |||
if centralKitchenForSchoolUserWithDay == nil { | |||
err = errors.New("未查询到订餐记录") | |||
return | |||
} | |||
//1、判断是否为“待就餐”状态 | |||
if centralKitchenForSchoolUserWithDay.State != enum.CentralKitchenForSchoolUserWithDayStateForWait { | |||
err = errors.New("当前订餐不可退订") | |||
return | |||
} | |||
//2、判断是否为可退餐时间段 | |||
now := time.Now() | |||
today, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02")) | |||
centralKitchenForSchoolReserveMealTime, _ := time.Parse("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00") | |||
date, _ := time.Parse("2006-01-02", centralKitchenForSchoolUserWithDay.Date) | |||
if today.Equal(date) { | |||
//2.2、判断是否过了今日可订餐时间 | |||
if now.After(centralKitchenForSchoolReserveMealTime) { | |||
err = errors.New("当前订餐不在可退订时间范围内") | |||
return | |||
} | |||
} | |||
//3、处理订餐记录状态 | |||
centralKitchenForSchoolUserWithDay.State = enum.CentralKitchenForSchoolUserWithDayStateForCanceling | |||
updateAck, err := centralKitchenForSchoolUserWithDayDb.CentralKitchenForSchoolUserWithDayUpdate(centralKitchenForSchoolUserWithDay.Id, centralKitchenForSchoolUserWithDay, "state") | |||
if err != nil { | |||
return err | |||
} | |||
if updateAck <= 0 { | |||
err = errors.New("更新订餐记录状态失败") | |||
return | |||
} | |||
//4、处理订单状态 | |||
err = svc.JudgePackageOrdOrdState(req.OutTradeNo) | |||
if err != nil { | |||
return err | |||
} | |||
//5、新增退款记录 central_kitchen_for_school_user_refund_day | |||
outRequestNo := utils.OrderUUID(centralKitchenForSchoolUserWithDay.Uid) | |||
centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} | |||
centralKitchenForSchoolUserRefundDayDb.Set(0) | |||
_, err = centralKitchenForSchoolUserRefundDayDb.CentralKitchenForSchoolUserRefundDayInsert(&model.CentralKitchenForSchoolUserRefundDay{ | |||
OutTradeNo: req.OutTradeNo, | |||
OutRequestNo: outRequestNo, | |||
Uid: centralKitchenForSchoolUserWithDay.Uid, | |||
IdentityId: centralKitchenForSchoolUserWithDay.IdentityId, | |||
RecordsId: centralKitchenForSchoolUserWithDay.Id, | |||
State: enum.CentralKitchenForSchoolUserRefundDayStateForAuditing, | |||
Amount: centralKitchenForSchoolUserWithDay.Amount, | |||
Memo: "", | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}) | |||
return | |||
} | |||
func CentralKitchenForSchoolOrderRefundList(req md.CentralKitchenForSchoolOrderRefundListReq) (resp []md.CentralKitchenForSchoolOrderRefundListResp, total int64, err error) { | |||
var m []*db.CentralKitchenForSchoolUserRefundDayWithCentralKitchenForSchoolUserWithDay | |||
sess := db.Db.Where("central_kitchen_for_school_user_refund_day.identity_id =?", req.UserIdentityId) | |||
total, err = sess. | |||
Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). | |||
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
for _, v := range m { | |||
resp = append(resp, md.CentralKitchenForSchoolOrderRefundListResp{ | |||
OutTradeNo: v.CentralKitchenForSchoolUserRefundDay.OutTradeNo, | |||
OutRequestNo: v.CentralKitchenForSchoolUserRefundDay.OutRequestNo, | |||
Kind: v.CentralKitchenForSchoolUserWithDay.Kind, | |||
CreateAt: v.CentralKitchenForSchoolUserRefundDay.CreateAt.Format("2006-01-02 15:04:05"), | |||
Date: v.CentralKitchenForSchoolUserWithDay.Date, | |||
State: v.CentralKitchenForSchoolUserRefundDay.State, | |||
Memo: v.CentralKitchenForSchoolUserRefundDay.Memo, | |||
Amount: v.CentralKitchenForSchoolUserRefundDay.Amount, | |||
}) | |||
} | |||
return | |||
} |