|
- 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 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,
- },
- {
- "name": enum.EnterprisePvd.String(enum.EnterprisePvdByNursingHome),
- "value": enum.EnterprisePvdByNursingHome,
- },
- },
- }, nil)
- return
- }
-
- func CentralKitchenForSchoolUserList(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
- }
-
- resp, err := svc2.EnterpriseUserListByCentralKitchenForSchoolV2(req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- e.OutSuc(c, resp, nil)
- return
- }
-
- func CentralKitchenForSchoolUserUpdate(c *gin.Context) {
- var req md.CentralKitchenForSchoolUserUpdateReqV2
- 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.CentralKitchenForSchoolUserUpdateV2(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
- }
-
- err = svc2.CentralKitchenForSchoolUserDeleteV2(req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- e.OutSuc(c, "success", 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
- }
|