diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index 39d1a5e..4f49932 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -38,10 +38,11 @@ type CentralKitchenForSchoolUserUpdateReq struct { Nickname string `json:"nickname" binding:"required" label:"支付宝昵称"` Phone string `json:"phone" binding:"required" label:"手机号"` BindUserIdentities []struct { - IdNo string `json:"id_no" label:"身份证号"` - Name string `json:"name" label:"姓名"` - GradeId int `json:"grade_id" label:"年级"` - ClassId int `json:"class_id" label:"班级"` + 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:"身份列表"` } @@ -173,21 +174,22 @@ type CentralKitchenForSchoolOrdRefundReq struct { } type CentralKitchenForSchoolOrdListResp struct { - EnterpriseId int `json:"enterprise_id" ` - Uid int `json:"uid" ` - UserIdentityId int `json:"user_identity_id" ` - TotalPrice string `json:"total_price" ` - Kind int `json:"kind" ` - OutTradeNo string `json:"out_trade_no" ` - TradeNo string `json:"trade_no"` - State int `json:"state"` - OrdState int `json:"ord_state"` - CreateAt string `json:"create_at"` - 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:"班级id"` + EnterpriseId int `json:"enterprise_id" ` + Uid int `json:"uid" ` + UserIdentityId int `json:"user_identity_id" ` + UserIdentityName string `json:"user_identity_name" ` + TotalPrice string `json:"total_price" ` + Kind int `json:"kind" ` + OutTradeNo string `json:"out_trade_no" ` + TradeNo string `json:"trade_no"` + State int `json:"state"` + OrdState int `json:"ord_state"` + CreateAt string `json:"create_at"` + 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:"班级id"` } type CentralKitchenForSchoolOrdListReq struct { diff --git a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go index 45ca339..81e7fbc 100644 --- a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go @@ -5,6 +5,7 @@ import ( "applet/app/db" "applet/app/db/model" enum2 "applet/app/enum" + "applet/app/utils" "errors" "fmt" "strings" @@ -30,69 +31,115 @@ func CentralKitchenForSchoolUserUpdate(req md.CentralKitchenForSchoolUserUpdateR session := db.Db.NewSession() defer session.Close() session.Begin() - //2、删除当前用户&&当前单位下的所有身份 - _, err = session.Where("uid =? and enterprise_id =?", req.Uid, req.EnterpriseId).Delete(model.UserIdentity{}) - if err != nil { - _ = session.Rollback() - return - } - //3、新增数据 + //2、新增 / 编辑 数据 now := time.Now() userIdentityDb := db.UserIdentityDb{} userIdentityDb.Set(req.Uid) classWithUserDb := db.ClassWithUserDb{} classWithUserDb.Set() + + var newUserIdentityIds []string for _, v := range req.BindUserIdentities { - if v.ClassId == -1 { - //TODO::为老师身份 - _, err3 := userIdentityDb.UserIdentityInsertBySession(session, &model.UserIdentity{ + 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.UserIdentityForCentralKitchenForTeacher, + 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 + } + + 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 } - 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 + newUserIdentityIds = append(newUserIdentityIds, utils.IntToStr(v.UserIdentityId)) } + } - _, 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 + //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 + } } } - return session.Commit() } @@ -403,21 +450,22 @@ func CentralKitchenForSchoolOrdList(req md.CentralKitchenForSchoolOrdListReq) (r for _, v := range m { resp = append(resp, md.CentralKitchenForSchoolOrdListResp{ - EnterpriseId: req.EnterpriseId, - Uid: v.UserIdentity.Uid, - UserIdentityId: v.UserIdentity.Id, - TotalPrice: v.CentralKitchenForSchoolPackageOrd.TotalPrice, - Kind: v.CentralKitchenForSchoolPackageOrd.Kind, - OutTradeNo: v.CentralKitchenForSchoolPackageOrd.OutTradeNo, - TradeNo: v.CentralKitchenForSchoolPackageOrd.TradeNo, - State: v.CentralKitchenForSchoolPackageOrd.State, - OrdState: v.CentralKitchenForSchoolPackageOrd.OrdState, - CreateAt: v.CentralKitchenForSchoolPackageOrd.CreateAt, - Name: v.UserIdentity.Name, - Grade: v.Grade.Name, - GradeId: v.Grade.Id, - Class: v.Class.Name, - ClassId: v.Class.Id, + EnterpriseId: v.UserIdentity.EnterpriseId, + Uid: v.UserIdentity.Uid, + UserIdentityId: v.UserIdentity.Id, + UserIdentityName: v.CentralKitchenForSchoolPackageOrd.UserIdentityName, + TotalPrice: v.CentralKitchenForSchoolPackageOrd.TotalPrice, + Kind: v.CentralKitchenForSchoolPackageOrd.Kind, + OutTradeNo: v.CentralKitchenForSchoolPackageOrd.OutTradeNo, + TradeNo: v.CentralKitchenForSchoolPackageOrd.TradeNo, + State: v.CentralKitchenForSchoolPackageOrd.State, + OrdState: v.CentralKitchenForSchoolPackageOrd.OrdState, + CreateAt: v.CentralKitchenForSchoolPackageOrd.CreateAt, + Name: v.UserIdentity.Name, + Grade: v.Grade.Name, + GradeId: v.Grade.Id, + Class: v.Class.Name, + ClassId: v.Class.Id, }) } return diff --git a/app/customer/hdl/hdl_user_identity.go b/app/customer/hdl/hdl_user_identity.go index b7760c0..c26763c 100644 --- a/app/customer/hdl/hdl_user_identity.go +++ b/app/customer/hdl/hdl_user_identity.go @@ -400,17 +400,41 @@ func DeleteUserIdentity(c *gin.Context) { 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 } diff --git a/app/customer/md/md_user_identity.go b/app/customer/md/md_user_identity.go index 96ab15c..7a056cc 100644 --- a/app/customer/md/md_user_identity.go +++ b/app/customer/md/md_user_identity.go @@ -22,9 +22,7 @@ type SaveSelfSupportForSchoolUserIdentityReq struct { type UpdateCentralKitchenForSchoolUserIdentityReq struct { IdNo string `json:"id_no" 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"` } @@ -32,9 +30,7 @@ type UpdateCentralKitchenForSchoolUserIdentityReq struct { type UpdateSelfSupportForSchoolUserIdentityReq struct { IdNo string `json:"id_no" 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"` } diff --git a/app/customer/svc/svc_pay.go b/app/customer/svc/svc_pay.go index 7adede2..b68432e 100644 --- a/app/customer/svc/svc_pay.go +++ b/app/customer/svc/svc_pay.go @@ -99,19 +99,20 @@ func BuyPackage(c *gin.Context, req md.BuyPackageReq) (outTradeNo, tradeNo, tota centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} centralKitchenForSchoolPackageOrd.Set(outTradeNo) _, err = centralKitchenForSchoolPackageOrd.CentralKitchenForSchoolPackageOrdInsertBySession(session, &model.CentralKitchenForSchoolPackageOrd{ - EnterpriseId: req.EnterpriseId, - Uid: user.Id, - UserIdentityId: req.UserIdentityId, - TotalPrice: total, - Kind: req.Kind, - OutTradeNo: outTradeNo, - TradeNo: resp.TradeNo, - State: enum2.CentralKitchenForSchoolPackageOrdStateForWait, - OrdState: enum2.CentralKitchenForSchoolPackageOrdOrdStateForWait, - ReqContent: string(utils.Serialize(req)), - WithDayData: string(utils.Serialize(data)), - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), + EnterpriseId: req.EnterpriseId, + Uid: user.Id, + UserIdentityId: req.UserIdentityId, + UserIdentityName: userIdentity.Name, + TotalPrice: total, + Kind: req.Kind, + OutTradeNo: outTradeNo, + TradeNo: resp.TradeNo, + State: enum2.CentralKitchenForSchoolPackageOrdStateForWait, + OrdState: enum2.CentralKitchenForSchoolPackageOrdOrdStateForWait, + ReqContent: string(utils.Serialize(req)), + WithDayData: string(utils.Serialize(data)), + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err != nil { _ = session.Rollback() diff --git a/app/customer/svc/svc_user_identity.go b/app/customer/svc/svc_user_identity.go new file mode 100644 index 0000000..cceb216 --- /dev/null +++ b/app/customer/svc/svc_user_identity.go @@ -0,0 +1,63 @@ +package svc + +import ( + "applet/app/db" + "applet/app/db/model" +) + +func DeleteUserIdentityForCentralKitchenForStudent(userIdentityId int) (err error) { + //1、删除 class_with_user + _, err = db.Db.In("user_identity_id", userIdentityId).Delete(model.ClassWithUser{}) + if err != nil { + return + } + + //2、删除 user_identity + _, err = db.Db.Where("id =?", userIdentityId).Delete(model.UserIdentity{}) + if err != nil { + return + } + return nil +} + +func DeleteUserIdentityForCentralKitchenForTeacher(userIdentityId int) (err error) { + //删除 user_identity + _, err = db.Db.Where("id =?", userIdentityId).Delete(model.UserIdentity{}) + if err != nil { + return + } + return nil +} + +func DeleteUserIdentityForSelfSupportForStudent(userIdentityId int) (err error) { + //1、删除 class_with_user + _, err = db.Db.In("user_identity_id", userIdentityId).Delete(model.ClassWithUser{}) + if err != nil { + return + } + + //2、删除 user_identity + _, err = db.Db.Where("id =?", userIdentityId).Delete(model.UserIdentity{}) + if err != nil { + return + } + return nil +} + +func DeleteUserIdentityForSelfSupportForTeacher(userIdentityId int) (err error) { + //删除 user_identity + _, err = db.Db.Where("id =?", userIdentityId).Delete(model.UserIdentity{}) + if err != nil { + return + } + return nil +} + +func DeleteUserIdentityForSelfSupportForWorker(userIdentityId int) (err error) { + //删除 user_identity + _, err = db.Db.Where("id =?", userIdentityId).Delete(model.UserIdentity{}) + if err != nil { + return + } + return nil +} diff --git a/app/db/db_user_identity.go b/app/db/db_user_identity.go index d64716f..e2b134a 100644 --- a/app/db/db_user_identity.go +++ b/app/db/db_user_identity.go @@ -99,6 +99,22 @@ func (userIdentityDb *UserIdentityDb) UserIdentityUpdate(id interface{}, m *mode return affected, nil } +func (userIdentityDb *UserIdentityDb) UserIdentityUpdateBySession(session *xorm.Session, id interface{}, m *model.UserIdentity, forceColums ...string) (int64, error) { + var ( + affected int64 + err error + ) + if forceColums != nil { + affected, err = session.Where("id=?", id).Cols(forceColums...).Update(m) + } else { + affected, err = session.Where("id=?", id).Update(m) + } + if err != nil { + return 0, err + } + return affected, nil +} + func (userIdentityDb *UserIdentityDb) CountUserIdentityForEnterprise(enterpriseId, identity int) (total int64, err error) { var m model.UserIdentity total, err = userIdentityDb.Db.Where("enterprise_id =? AND identity =?", enterpriseId, identity).Count(&m) diff --git a/app/db/model/central_kitchen_for_school_package_ord.go b/app/db/model/central_kitchen_for_school_package_ord.go index 5cfb60b..8338e80 100644 --- a/app/db/model/central_kitchen_for_school_package_ord.go +++ b/app/db/model/central_kitchen_for_school_package_ord.go @@ -1,18 +1,19 @@ package model type CentralKitchenForSchoolPackageOrd struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('所属单位id') INT(11)"` - Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` - UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` - TotalPrice string `json:"total_price" xorm:"not null default 0.00 comment('总价') DECIMAL(8,2)"` - Kind int `json:"kind" xorm:"not null default 1 comment('购买类型(1:按学期购买 2:按月购买 3:按天购买 4:补餐)') TINYINT(1)"` - OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('商户订单号') VARCHAR(255)"` - TradeNo string `json:"trade_no" xorm:"not null default '' comment('支付宝交易号') VARCHAR(255)"` - State int `json:"state" xorm:"not null default 0 comment('支付状态(0:待支付 1:支付成功 2:支付失败)') TINYINT(1)"` - OrdState int `json:"ord_state" xorm:"not null default 0 comment('订单状态(0:待支付 1:预约成功 2:退款中 3:部分退款 4:已退款 5:已完成)') TINYINT(1)"` - ReqContent string `json:"req_content" xorm:"comment('请求内容') TEXT"` - WithDayData string `json:"with_day_data" xorm:"comment('待支付成功插入 central_kitchen_for_school_user_with_day') TEXT"` - CreateAt string `json:"create_at" xorm:"not null pk 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)"` + EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('所属单位id') INT(11)"` + Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` + UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` + UserIdentityName string `json:"user_identity_name" xorm:"not null default 0.00 comment('用户身份名称(起备份作用)') CHAR(50)"` + TotalPrice string `json:"total_price" xorm:"not null default 0.00 comment('总价') DECIMAL(8,2)"` + Kind int `json:"kind" xorm:"not null default 1 comment('购买类型(1:按学期购买 2:按月购买 3:按天购买 4:补餐)') TINYINT(1)"` + OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('商户订单号') VARCHAR(255)"` + TradeNo string `json:"trade_no" xorm:"not null default '' comment('支付宝交易号') VARCHAR(255)"` + State int `json:"state" xorm:"not null default 0 comment('支付状态(0:待支付 1:支付成功 2:支付失败)') TINYINT(1)"` + OrdState int `json:"ord_state" xorm:"not null default 0 comment('订单状态(0:待支付 1:预约成功 2:退款中 3:部分退款 4:已退款 5:已完成)') TINYINT(1)"` + ReqContent string `json:"req_content" xorm:"comment('请求内容') TEXT"` + WithDayData string `json:"with_day_data" xorm:"comment('待支付成功插入 central_kitchen_for_school_user_with_day') TEXT"` + CreateAt string `json:"create_at" xorm:"not null pk default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } diff --git a/app/router/customer_router.go b/app/router/customer_router.go index eef48d2..45ad6a2 100644 --- a/app/router/customer_router.go +++ b/app/router/customer_router.go @@ -72,6 +72,6 @@ func rSelfSupportForSchool(r *gin.RouterGroup) { //自营学校 func rUserIdentity(r *gin.RouterGroup) { //用户身份 r.Use(mw.Auth) //检测登录状态 r.DELETE("/deleteUserIdentity/:id", hdl.DeleteUserIdentity) // 删除身份信息 - r.POST("/updateCentralKitchenForSchoolUserIdentity", hdl.UpdateCentralKitchenForSchoolUserIdentity) // 修改"央厨-学校"身份信息 - r.POST("/updateSelfSupportForSchoolUserIdentity", hdl.UpdateSelfSupportForSchoolUserIdentity) // 修改"自营-学校"身份信息 + r.POST("/updateCentralKitchenForSchoolUserIdentity", hdl.UpdateCentralKitchenForSchoolUserIdentity) // 修改"央厨-学校"学生身份信息 + r.POST("/updateSelfSupportForSchoolUserIdentity", hdl.UpdateSelfSupportForSchoolUserIdentity) // 修改"自营-学校"学生身份信息 }