|
- 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
- }
-
- now := time.Now()
- 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 identity != enum.UserIdentityForCentralKitchenForStudent && set.IsOpenLimitTeacherRegister == 1 {
- e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
- return
- }
-
- //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
- }
|