diff --git a/app/admin/hdl/enterprise_manage/hdl_enterprise.go b/app/admin/hdl/enterprise_manage/hdl_enterprise.go index 4ab6b88..9b8cd1a 100644 --- a/app/admin/hdl/enterprise_manage/hdl_enterprise.go +++ b/app/admin/hdl/enterprise_manage/hdl_enterprise.go @@ -98,6 +98,11 @@ func UserIdentityList(c *gin.Context) { case enum.EnterprisePvdByCentralKitchenForFactory: break case enum.EnterprisePvdBySelfSupportForSchool: + resp, err = svc2.EnterpriseUserListByCentralKitchenForSchool(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } break case enum.EnterprisePvdBySelfSupportForFactory: break diff --git a/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go b/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go new file mode 100644 index 0000000..bcdcfab --- /dev/null +++ b/app/admin/hdl/enterprise_manage/hdl_self_support_for_school.go @@ -0,0 +1,320 @@ +package hdl + +import ( + "applet/app/admin/lib/validate" + "applet/app/admin/md" + svc2 "applet/app/admin/svc/enterprise_manage" + "applet/app/db" + "applet/app/db/model" + "applet/app/e" + "github.com/gin-gonic/gin" +) + +func SelfSupportForSchoolUserUpdate(c *gin.Context) { + var req md.SelfSupportForSchoolUserUpdateReq + 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.SelfSupportForSchoolUserUpdate(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolUserDelete(c *gin.Context) { + var req md.SelfSupportForSchoolUserDeleteReq + 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.SelfSupportForSchoolUserDelete(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolStudentList(c *gin.Context) { + var req md.SelfSupportForSchoolStudentListReq + 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.SelfSupportForSchoolStudentList(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", + }, + }, + "collect_face_type_list": []map[string]interface{}{ + { + "name": "个采", + "value": 1, + }, + { + "name": "集采", + "value": 2, + }, + }, + }, nil) + return +} + +func SelfSupportForSchoolTeacherList(c *gin.Context) { + var req md.SelfSupportForSchoolTeacherListReq + 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.SelfSupportForSchoolTeacherList(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "list": resp, + "total": total, + "collect_face_type_list": []map[string]interface{}{ + { + "name": "个采", + "value": 1, + }, + { + "name": "集采", + "value": 2, + }, + }, + }, nil) + return +} + +func SelfSupportForSchoolTeacherUpdate(c *gin.Context) { + var req md.SelfSupportForSchoolTeacherUpdateReq + 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 + } + + //更新 self_support_for_user_face_info + selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} + selfSupportForUserFaceInfoDb.Set(req.UserIdentityId) + info, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + info.CollectFaceType = req.CollectFaceType + _, err = selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "collect_face_type") + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolStudentUpdate(c *gin.Context) { + var req md.SelfSupportForSchoolStudentUpdateReq + 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.SelfSupportForSchoolStudentUpdate(req) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolStudentAdmission(c *gin.Context) { + var req md.SelfSupportForSchoolStudentAdmissionReq + 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.SelfSupportForSchoolStudentAdmission(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolStudentDelete(c *gin.Context) { + var req md.SelfSupportForSchoolStudentDeleteReq + 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.SelfSupportForSchoolStudentDelete(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + +func SelfSupportForSchoolTeacherDelete(c *gin.Context) { + var req md.SelfSupportForSchoolTeacherDeleteReq + 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 + } + + //删除 self_support_for_user_face_info + _, err = db.Db.In("user_identity_id =?", req.UserIdentityIds).Delete(model.SelfSupportForUserFaceInfo{}) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + e.OutSuc(c, "success", nil) + return +} diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index ff5fcbb..8c9b65a 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -208,3 +208,93 @@ type CentralKitchenForSchoolOrdListReq struct { StartDate string `json:"start_date" label:"开始时间"` EndDate string `json:"end_date" label:"截止时间"` } + +type SelfSupportForSchoolUserUpdateReq 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 { + UserIdentityId int `json:"user_identity_id" label:"用户身份id"` + 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 SelfSupportForSchoolUserDeleteReq struct { + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + Uids []int `json:"uids" binding:"required" label:"用户id"` +} + +type SelfSupportForSchoolStudentListReq 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 SelfSupportForSchoolStudentListResp 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 SelfSupportForSchoolTeacherListReq 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 SelfSupportForSchoolTeacherListResp 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 SelfSupportForSchoolStudentUpdateReq 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"` + CollectFaceType int `json:"collect_face_type" label:"采集人脸方式(1:个采 2:集采)"` +} + +type SelfSupportForSchoolStudentDeleteReq struct { + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + UserIdentityIds []int `json:"user_identity_ids" binding:"required" label:"用户身份id"` +} + +type SelfSupportForSchoolStudentAdmissionReq 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 SelfSupportForSchoolTeacherUpdateReq 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:"姓名"` + CollectFaceType int `json:"collect_face_type" label:"采集人脸方式(1:个采 2:集采)"` +} + +type SelfSupportForSchoolTeacherDeleteReq struct { + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + UserIdentityIds []int `json:"user_identity_ids" binding:"required" label:"用户身份id"` +} diff --git a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go new file mode 100644 index 0000000..8fe7c6b --- /dev/null +++ b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go @@ -0,0 +1,431 @@ +package svc + +import ( + "applet/app/admin/md" + "applet/app/db" + "applet/app/db/model" + enum2 "applet/app/enum" + "applet/app/utils" + "errors" + "time" +) + +func SelfSupportForSchoolUserUpdate(req md.SelfSupportForSchoolUserUpdateReq) (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、新增 / 编辑 数据 + now := time.Now() + selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} + selfSupportForSchoolInfoDb.Set(req.EnterpriseId) + selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() + if err != nil { + return + } + if selfSupportForSchoolInfo == nil { + return errors.New("当前学校暂未完成《一脸通行入驻》") + } + + userIdentityDb := db.UserIdentityDb{} + userIdentityDb.Set(req.Uid) + + classWithUserDb := db.ClassWithUserDb{} + classWithUserDb.Set() + + selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} + var newUserIdentityIds []string + for _, v := range req.BindUserIdentities { + if v.UserIdentityId == 0 { + // 新增 + 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.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + 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.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err1 != nil { + _ = session.Rollback() + return err1 + } + + _, err2 := classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{ + UserIdentityId: insertId, + ClassId: v.ClassId, + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err2 != nil { + _ = session.Rollback() + return err1 + } + + selfSupportForUserFaceInfoDb.Set(insertId) + _, err = selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{ + UserIdentityId: insertId, + 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 err != nil { + return err + } + + newUserIdentityIds = append(newUserIdentityIds, utils.IntToStr(insertId)) + } else { + //编辑 + identity, err2 := userIdentityDb.GetUserIdentity(v.UserIdentityId) + if err != nil { + _ = session.Rollback() + return err2 + } + if identity == nil { + _ = session.Rollback() + return errors.New("未查询到对应的身份信息记录") + } + identity.IdNo = v.IdNo + identity.Name = v.Name + if v.ClassId == -1 { + //TODO::为老师身份 + identity.Identity = enum2.UserIdentityForCentralKitchenForTeacher + } else { + _, err3 := classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{ + UserIdentityId: v.UserIdentityId, + ClassId: v.ClassId, + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err3 != nil { + _ = session.Rollback() + return err3 + } + } + _, err3 := userIdentityDb.UserIdentityUpdateBySession(session, v.UserIdentityId, identity, "id_no", "name", "identity") + if err3 != nil { + _ = session.Rollback() + return err3 + } + + newUserIdentityIds = append(newUserIdentityIds, utils.IntToStr(v.UserIdentityId)) + } + } + + //3、删除需要删除的身份信息 + for _, v := range userIdentityIds { + if !utils.InArr(utils.IntToStr(v), newUserIdentityIds) { + _, err = session.Where("id = ?", v).Delete(model.UserIdentity{}) + if err != nil { + _ = session.Rollback() + return + } + + _, err = session.Where("user_identity_id = ?", v).Delete(model.SelfSupportForUserFaceInfo{}) + if err != nil { + _ = session.Rollback() + return + } + } + } + return session.Commit() +} + +func SelfSupportForSchoolUserDelete(req md.SelfSupportForSchoolUserDeleteReq) (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 + } + + //3、删除 self_support_for_user_face_info + _, err = db.Db.In("user_identity_id =?", userIdentityIds).Delete(model.SelfSupportForUserFaceInfo{}) + if err != nil { + return + } + + return +} + +func SelfSupportForSchoolStudentList(req md.SelfSupportForSchoolStudentListReq) (resp []md.SelfSupportForSchoolStudentListResp, 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.SelfSupportForSchoolStudentListResp{ + 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 SelfSupportForSchoolTeacherList(req md.SelfSupportForSchoolTeacherListReq) (resp []md.SelfSupportForSchoolTeacherListResp, 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.SelfSupportForSchoolTeacherListResp{ + UserIdentityId: v.UserIdentity.Id, + IdNo: v.UserIdentity.IdNo, + Phone: v.User.Phone, + Name: v.UserIdentity.Name, + }) + } + return +} + +func SelfSupportForSchoolStudentUpdate(req md.SelfSupportForSchoolStudentUpdateReq) (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{}.Format("2006-01-02 15:04:05"), + UpdateAt: time.Time{}.Format("2006-01-02 15:04:05"), + }) + + //3、更新 self_support_for_user_face_info + selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} + selfSupportForUserFaceInfoDb.Set(req.UserIdentityId) + info, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() + if err != nil { + _ = session.Rollback() + return + } + info.CollectFaceType = req.CollectFaceType + _, err = selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "collect_face_type") + if err != nil { + _ = session.Rollback() + } + return session.Commit() +} + +func SelfSupportForSchoolStudentDelete(req md.SelfSupportForSchoolStudentDeleteReq) (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 + } + + //3、删除 self_support_for_user_face_info + _, err = db.Db.In("user_identity_id =?", req.UserIdentityIds).Delete(model.SelfSupportForUserFaceInfo{}) + if err != nil { + return + } + return +} + +func SelfSupportForSchoolStudentAdmission(req md.SelfSupportForSchoolStudentAdmissionReq) (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 +} diff --git a/app/customer/hdl/hdl_user_identity.go b/app/customer/hdl/hdl_user_identity.go index 02cd8f7..a0d8da5 100644 --- a/app/customer/hdl/hdl_user_identity.go +++ b/app/customer/hdl/hdl_user_identity.go @@ -189,17 +189,50 @@ func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) { if !req.IsTeacher { classWithUserDb := db.ClassWithUserDb{} classWithUserDb.Set() - _, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{ + _, 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 err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) + 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{ + 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 != nil && isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id { e.OutErr(c, e.ERR, "当前身份信息已被绑定使用") diff --git a/app/customer/svc/svc_curl_smart_pay.go b/app/customer/svc/svc_curl_smart_pay.go index 4097e6c..d1069c6 100644 --- a/app/customer/svc/svc_curl_smart_pay.go +++ b/app/customer/svc/svc_curl_smart_pay.go @@ -282,7 +282,7 @@ func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId info.SchoolFacePassStatus = res["school_face_pass_status"] info.SchoolFacePaymentStatus = res["school_face_payment_status"] info.UpdateAt = now - _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "create_at") + _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "update_at") if err2 != nil { return err2, nil } diff --git a/app/db/model/self_support_for_user_face_info.go b/app/db/model/self_support_for_user_face_info.go index db6607c..a83d570 100644 --- a/app/db/model/self_support_for_user_face_info.go +++ b/app/db/model/self_support_for_user_face_info.go @@ -1,16 +1,17 @@ package model type SelfSupportForUserFaceInfo struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` - CollectFaceType int `json:"collect_face_type" xorm:"not null default 1 comment('采集人脸方式(1:个采 2:集采)') TINYINT(1)"` - SchoolCode string `json:"school_code" xorm:"not null default '' comment('学校内标') VARCHAR(255)"` - SchoolStdCode string `json:"school_std_code" xorm:"not null default '' comment('学校外标') VARCHAR(255)"` - ParentUserId string `json:"parent_user_id" xorm:"not null default '' comment('用于开通一脸通行的支付宝账户uid(如果是父母为孩子开通,则为父母支付宝uid;如果是用户为本人开通,则为本人支付宝uid)') VARCHAR(255)"` - ParentLogonId string `json:"parent_logon_id" xorm:"not null default '' comment('家长支付宝账户的脱敏信息') VARCHAR(255)"` - UserId string `json:"user_id" xorm:"not null default '' comment('刷脸用户id') VARCHAR(255)"` - SchoolFacePassStatus string `json:"school_face_pass_status" xorm:"not null default '' comment('校园一脸通行开通状态(开通:OPEN 关闭:CLOSE)') CHAR(50)"` - SchoolFacePaymentStatus string `json:"school_face_payment_status" xorm:"not null default '' comment('校园一脸通行刷脸支付开通状态(开通:OPEN 关闭:CLOSE)') CHAR(50)"` - CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` - UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` + CollectFaceType int `json:"collect_face_type" xorm:"not null default 1 comment('采集人脸方式(1:个采 2:集采)') TINYINT(1)"` + SchoolCode string `json:"school_code" xorm:"not null default '' comment('学校内标') VARCHAR(255)"` + SchoolStdCode string `json:"school_std_code" xorm:"not null default '' comment('学校外标') VARCHAR(255)"` + ParentUserId string `json:"parent_user_id" xorm:"not null default '' comment('用于开通一脸通行的支付宝账户uid(如果是父母为孩子开通,则为父母支付宝uid;如果是用户为本人开通,则为本人支付宝uid)') VARCHAR(255)"` + ParentLogonId string `json:"parent_logon_id" xorm:"not null default '' comment('家长支付宝账户的脱敏信息') VARCHAR(255)"` + UserId string `json:"user_id" xorm:"not null default '' comment('刷脸用户id') VARCHAR(255)"` + SchoolFacePassStatus string `json:"school_face_pass_status" xorm:"not null default '' comment('校园一脸通行开通状态(开通:OPEN 关闭:CLOSE)') CHAR(50)"` + SchoolFacePaymentStatus string `json:"school_face_payment_status" xorm:"not null default '' comment('校园一脸通行刷脸支付开通状态(开通:OPEN 关闭:CLOSE)') CHAR(50)"` + ConcentrateSchoolFacePassStatus int `json:"concentrate_school_face_pass_status" xorm:"not null default 1 comment('校园一脸通行集采状态(1:待采集 2:待确认 3:已确认)') TINYINT(1)"` + CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } diff --git a/app/router/admin_router.go b/app/router/admin_router.go index f72aa77..36dba3d 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -135,7 +135,15 @@ func rEnterpriseManage(r *gin.RouterGroup) { r.POST("/saveCentralKitchenForSchoolPackage", hdl.SaveCentralKitchenForSchoolPackage) //新增/编辑 "央厨-学校-套餐" r.DELETE("/deleteCentralKitchenForSchoolPackage/:id", hdl.DeleteCentralKitchenForSchoolPackage) //删除 "央厨-学校-套餐" - r.POST("/selfSupportForSchool/studentList", hdl.CentralKitchenForSchoolStudentList) //"央厨-学校"学生列表 + r.POST("/selfSupportForSchool/userUpdate", hdl.SelfSupportForSchoolUserUpdate) //"自营-学校"用户编辑 + r.POST("/selfSupportForSchool/userDelete", hdl.SelfSupportForSchoolUserDelete) //"自营-学校"用户删除 + r.POST("/selfSupportForSchool/studentList", hdl.SelfSupportForSchoolStudentList) //"自营-学校"学生列表 + r.POST("/selfSupportForSchool/studentUpdate", hdl.SelfSupportForSchoolStudentUpdate) //"自营-学校"学生编辑 + r.POST("/selfSupportForSchool/studentDelete", hdl.SelfSupportForSchoolStudentDelete) //"自营-学校"学生删除 + r.POST("/selfSupportForSchool/studentAdmission", hdl.SelfSupportForSchoolStudentAdmission) //"自营-学校"学生升学 + r.POST("/selfSupportForSchool/teacherList", hdl.SelfSupportForSchoolTeacherList) //"自营-学校"教师列表 + r.POST("/selfSupportForSchool/teacherUpdate", hdl.SelfSupportForSchoolTeacherUpdate) //"自营-学校"教师编辑 + r.POST("/selfSupportForSchool/teacherDelete", hdl.SelfSupportForSchoolTeacherDelete) //"自营-学校"教师删除 }