|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- 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"
- "applet/app/utils"
- "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.UserIdentityExistV1(req.EnterpriseId, req.Name)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if isHasUserIdentity == nil && identity == enum.UserIdentityForCentralKitchenForTeacher {
- isHasUserIdentity, err = userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, 1)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if isHasUserIdentity == nil {
- 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.IsOpenLimitTeacherRegister == 1 {
- e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
- return
- }
- }
- }
-
- now := time.Now()
- if isHasUserIdentity == nil {
- //2、新增身份信息
- userIdentity := &model.UserIdentity{
- Uid: user.Id,
- Name: req.Name,
- IdNo: req.IdNo,
- CertType: enum.UserIdentityCertTypeForIdCard,
- Kind: enum.UserIdentityKindForCommon,
- Identity: identity,
- EnterpriseId: req.EnterpriseId,
- State: enum.UserIdentityStateForNormal,
- Memo: "",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- 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.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
- }
- }
- } else {
- //4、修改身份信息
- isHasUserIdentity.Uid = user.Id
- isHasUserIdentity.Name = req.Name
- isHasUserIdentity.State = enum.UserIdentityStateForNormal
- _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- //5、修改 class_with_user 记录
- if !req.IsTeacher {
- 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.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- 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 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.Now()
- var identity = enum.UserIdentityForSelfSupportForStudent
- var kind = enum.UserIdentityKindForCommon
-
- if req.CertType == 0 {
- req.CertType = enum.UserIdentityCertTypeForIdCard
- }
-
- if req.Kind == enum.UserIdentityKindForWorker {
- kind = enum.UserIdentityKindForWorker
- identity = enum.UserIdentityForSelfSupportForWorker
- req.CertType = enum.UserIdentityCertTypeForIdCard
- } else {
- if req.IsTeacher {
- identity = enum.UserIdentityForCentralKitchenForTeacher
- }
- }
-
- //1、判断当前身份是否已绑定
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, req.CertType)
- 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,
- CertType: req.CertType,
- Kind: kind,
- Identity: identity,
- EnterpriseId: req.EnterpriseId,
- State: enum.UserIdentityStateForNormal,
- Memo: "",
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- 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()
- _, err1 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
- UserIdentityId: insertAffected,
- ClassId: req.ClassId,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- }
-
- //4、新增 self_support_for_user_face_info 记录
- selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
- selfSupportForSchoolInfoDb.Set(req.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
- }
- selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
- selfSupportForUserFaceInfoDb.Set(insertAffected)
- _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{
- EnterpriseId: req.EnterpriseId,
- UserIdentityId: insertAffected,
- CollectFaceType: 1,
- SchoolCode: selfSupportForSchoolInfo.SchoolCode,
- SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
- ParentUserId: "",
- ParentLogonId: "",
- UserId: "",
- SchoolFacePassStatus: "CLOSE",
- SchoolFacePaymentStatus: "CLOSE",
- ConcentrateSchoolFacePassStatus: 1,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- } else {
- if isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id {
- e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
- return
- }
- //4、修改身份信息
- isHasUserIdentity.Uid = user.Id
- isHasUserIdentity.Name = req.Name
- isHasUserIdentity.State = enum.UserIdentityStateForNormal
- _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
- 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.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- 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 SaveNursingHomeUserIdentity(c *gin.Context) {
- var req md.SaveNursingHomeUserIdentityReq
- 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.UserIdentityForNursingHome
-
- //1、判断当前身份是否已绑定
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, enum.UserIdentityCertTypeForIdCard)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- now := time.Now()
- if isHasUserIdentity == nil {
- //2、新增身份信息
- 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.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- 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
- }
- } else {
- //4、修改身份信息
- isHasUserIdentity.Uid = user.Id
- isHasUserIdentity.Name = req.Name
- isHasUserIdentity.State = enum.UserIdentityStateForNormal
- _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func UpdateCentralKitchenForSchoolUserIdentity(c *gin.Context) {
- var req md.UpdateCentralKitchenForSchoolUserIdentityReq
- 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.Now()
- //1、查询当前身份是否存在
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- 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
- }
- //2、修改身份信息
- userIdentity.Name = req.Name
- userIdentity.IdNo = req.IdNo
- _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- //3、修改 class_with_user 记录
- if userIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent {
- classWithUserDb := db.ClassWithUserDb{}
- classWithUserDb.Set()
- classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- if classWithUser == nil {
- _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
- UserIdentityId: userIdentity.Id,
- ClassId: req.ClassId,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- } else {
- classWithUser.ClassId = req.ClassId
- _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- }
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func UpdateSelfSupportForSchoolUserIdentity(c *gin.Context) {
- var req md.UpdateSelfSupportForSchoolUserIdentityReq
- 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.Now()
- //1、查询当前身份是否存在
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- 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
- }
- //2、修改身份信息
- userIdentity.Name = req.Name
- userIdentity.IdNo = req.IdNo
- _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- //3、修改 class_with_user 记录
- if userIdentity.Identity == enum.UserIdentityForSelfSupportForStudent {
- classWithUserDb := db.ClassWithUserDb{}
- classWithUserDb.Set()
- classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- if classWithUser == nil {
- _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
- UserIdentityId: userIdentity.Id,
- ClassId: req.ClassId,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- } else {
- classWithUser.ClassId = req.ClassId
- _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- }
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func UpdateNursingHomeUserIdentity(c *gin.Context) {
- var req md.UpdateNursingHomeUserIdentityReq
- 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)
- //1、查询当前身份是否存在
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- 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
- }
-
- //2、修改身份信息
- userIdentity.Name = req.Name
- userIdentity.IdNo = req.IdNo
- _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- func DeleteUserIdentity(c *gin.Context) {
- userIdentityId := utils.StrToInt(c.Param("id"))
-
- user := svc.GetUser(c)
- //1、查询当前身份是否存在
- userIdentityDb := db.UserIdentityDb{}
- userIdentityDb.Set(user.Id)
- userIdentity, err := userIdentityDb.GetUserIdentity(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
- }
-
- switch userIdentity.Identity {
- case enum.UserIdentityForCentralKitchenForStudent:
- err1 := svc.DeleteUserIdentityForCentralKitchenForStudent(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- case enum.UserIdentityForCentralKitchenForTeacher:
- err1 := svc.DeleteUserIdentityForCentralKitchenForTeacher(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- case enum.UserIdentityForCentralKitchenForWorker:
- break
- case enum.UserIdentityForSelfSupportForStudent:
- err1 := svc.DeleteUserIdentityForSelfSupportForStudent(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- case enum.UserIdentityForSelfSupportForTeacher:
- err1 := svc.DeleteUserIdentityForSelfSupportForTeacher(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- case enum.UserIdentityForSelfSupportForWorker:
- err1 := svc.DeleteUserIdentityForSelfSupportForWorker(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- case enum.UserIdentityForNursingHome:
- err1 := svc.DeleteUserIdentityForNursingHome(userIdentity.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- break
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
|