package hdl import ( "applet/app/customer/svc" svc2 "applet/app/customer/svc/order" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/enum" "applet/app/utils" "github.com/gin-gonic/gin" "time" ) 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{} classWithUserDb := db.ClassWithUserDb{} classWithUserDb.Set() for _, v := range *identity { var tmp = map[string]interface{}{ "identity": v.UserIdentity, "enterprise": v.Enterprise, "grade": nil, "class": nil, } if v.UserIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent || v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForStudent { //央厨学生 or 自营学生 data, err1 := classWithUserDb.GetInfoByUserIdentityId(v.UserIdentity.Id) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } if data != nil { tmp["grade"] = data.Grade tmp["class"] = data.Class } } now := time.Now() if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForStudent || v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForTeacher { //TODO:: 自营-学生 or 自营-教职员工 sMDate := utils.GetFirstDateOfMonth(now).Format("2006-01-02 15:04:05") eMDate := utils.GetLastDateOfMonth(now).Format("2006-01-02 15:04:05") sTDate, eTDate := utils.GetDateTimeRangeStr("today") monthStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sMDate, eMDate) if err2 != nil { e.OutErr(c, e.ERR, err2.Error()) return } dayStatistic, err2 := svc2.SupportUserIdentityOrderStatistic(v.UserIdentity.Id, sTDate, eTDate) if err2 != nil { e.OutErr(c, e.ERR, err2.Error()) return } tmp["month_statistic"] = monthStatistic tmp["day_statistic"] = dayStatistic //统计是否存在欠费 arrearsStatistic, err2 := svc2.SupportUserIdentityOrderStatisticForArrears(v.UserIdentity.Id) if err2 != nil { e.OutErr(c, e.ERR, err2.Error()) return } tmp["arrears_statistic"] = arrearsStatistic //查询支付宝扣款账户 selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} selfSupportForUserFaceInfoDb.Set(v.UserIdentity.Id) info, err2 := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() if err2 != nil { e.OutErr(c, e.ERR, err2.Error()) return } if info == nil { selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{} selfSupportForSchoolInfoDb.Set(v.UserIdentity.EnterpriseId) selfSupportForSchoolInfo, err1 := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo() if err1 != nil { return } if selfSupportForSchoolInfo == nil { e.OutErr(c, e.ERR, "当前学校暂未完成《一脸通行入驻》") return } info = &model.SelfSupportForUserFaceInfo{ EnterpriseId: v.UserIdentity.EnterpriseId, UserIdentityId: v.UserIdentity.Id, 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"), } _, err3 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(info) if err3 != nil { e.OutErr(c, e.ERR, err3.Error()) return } } tmp["parent_logon_id"] = info.ParentLogonId tmp["collect_face_type"] = info.CollectFaceType tmp["concentrate_school_face_pass_status"] = info.ConcentrateSchoolFacePassStatus } if v.UserIdentity.Identity == enum.UserIdentityForSelfSupportForWorker { selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} selfSupportForUserFaceInfoDb.Set(0) tmp["school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePassStatus(v.EnterpriseId, "open") tmp["school_face_payment_num"], _ = selfSupportForUserFaceInfoDb.CountSchoolFacePaymentStatus(v.EnterpriseId, "open") tmp["concentrate_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 2) tmp["single_school_face_pass_num"], _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(v.EnterpriseId, 1) } identityList = append(identityList, tmp) } 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 }