|
- package public_platoon
-
- import (
- "applet/app/db"
- "applet/app/e"
- md "applet/app/md/institutional_management/public_platoon"
- svc "applet/app/svc/public_platoon"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "errors"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- // GetPublicPlatoonBasic
- // @Summary 制度中心-公排管理-公排基础设置(获取)
- // @Tags 公排管理
- // @Description 公排基础设置(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetPublicPlatoonBasicResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/getBasic [get]
- func GetPublicPlatoonBasic(c *gin.Context) {
- publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
- publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- now := time.Now()
- if publicPlatoonBasic == nil {
- publicPlatoonBasic = &model.PublicPlatoonBasicSetting{
- IsOpen: 1,
- OriginatorUid: 0,
- SeveralTimes: 0,
- SeveralRows: 0,
- SystemPunishReplace: 0,
- SystemPunishReplaceValue: 0,
- IsSelfActiveGetTeamRevenue: 0,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- _, err1 := publicPlatoonBasicDb.PublicPlatoonBasicSettingInsert(publicPlatoonBasic)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
-
- }
- var resp md.GetPublicPlatoonBasicResp
- resp = md.GetPublicPlatoonBasicResp{
- IsOpen: publicPlatoonBasic.IsOpen,
- OriginatorUid: publicPlatoonBasic.OriginatorUid,
- SeveralTimes: publicPlatoonBasic.SeveralTimes,
- SeveralRows: publicPlatoonBasic.SeveralRows,
- SystemPunishReplace: publicPlatoonBasic.SystemPunishReplace,
- SystemPunishReplaceValue: publicPlatoonBasic.SystemPunishReplaceValue,
- IsSelfActiveGetTeamRevenue: publicPlatoonBasic.IsSelfActiveGetTeamRevenue,
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // UpdatePublicPlatoonBasic
- // @Summary 制度中心-公排管理-公排基础设置(修改)
- // @Tags 公排管理
- // @Description 公排基础设置(修改)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.UpdatePublicPlatoonBasicReq true "公排设置表单内容"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/updateBasic [put]
- func UpdatePublicPlatoonBasic(c *gin.Context) {
- var req *md.UpdatePublicPlatoonBasicReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
-
- publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
-
- publicPlatoonBasic, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- setting := &model.PublicPlatoonBasicSetting{
- Id: publicPlatoonBasic.Id,
- IsOpen: req.IsOpen,
- OriginatorUid: req.OriginatorUid,
- SeveralTimes: req.SeveralTimes,
- SeveralRows: req.SeveralRows,
- SystemPunishReplace: req.SystemPunishReplace,
- SystemPunishReplaceValue: req.SystemPunishReplaceValue,
- IsSelfActiveGetTeamRevenue: req.IsSelfActiveGetTeamRevenue,
- CreateAt: "",
- UpdateAt: "",
- }
-
- updateAffected, err := publicPlatoonBasicDb.PublicPlatoonBasicSettingUpdate(publicPlatoonBasic.Id, setting, "")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if updateAffected <= 0 {
- e.OutErr(c, e.ERR_DB_ORM, "更新数据表失败")
- return
- }
- e.OutSuc(c, "success", nil)
- }
-
- // GetRelationshipMap
- // @Summary 制度中心-公排管理-关系分布图(获取)
- // @Tags 公排管理
- // @Description 关系分布图(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @param phone query string true "phone"
- // @param uid query string true "uid"
- // @Success 200 {object} md.TreeNode "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/relationshipMap [get]
- func GetRelationshipMap(c *gin.Context) {
- phone := c.Query("phone")
- uid := c.Query("uid")
- userDb := implement.NewUserDb(db.Db)
-
- userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
- var relation *model.PublicPlatoonUserRelation
- var err error
- if phone != "" {
- user, err1 := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": phone,
- })
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- }
- relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "uid",
- "value": user.Id,
- })
- } else if uid != "" {
- relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "uid",
- "value": uid,
- })
- } else {
- relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "level_total",
- "value": 1,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- }
-
- var list *md.TreeNode
- list, err = svc.GetTrees(db.Db, relation, 3)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, list, nil)
- }
-
- // FindUserRelationshipMap
- // @Summary 制度中心-公排管理-关系分布图(获取指定用户下级)
- // @Tags 公排管理
- // @Description 关系分布图(获取指定用户下级)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户ID"
- // @Success 200 {object} md.TreeNode "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/findUserRelationshipMap [get]
- func FindUserRelationshipMap(c *gin.Context) {
- uid := c.Query("uid")
-
- userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
- var err error
- var relation *model.PublicPlatoonUserRelation
- relation, err = userRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "uid",
- "value": uid,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- var list *md.TreeNode
- list, err = svc.GetTrees(db.Db, relation, 3)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, list, nil)
- }
-
- // FindSubUserRelationshipMap
- // @Summary 制度中心-公排管理-关系分布图(获取指定用户上级)
- // @Tags 公排管理
- // @Description 关系分布图(获取指定用户上级)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param uid query string true "用户ID"
- // @Success 200 {object} md.TreeNode "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/findSubUserRelationshipMap [get]
- func FindSubUserRelationshipMap(c *gin.Context) {
- uid := c.Query("uid")
-
- RelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
- sonRelation, err1 := RelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "uid",
- "value": uid,
- })
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
-
- parentRelation, err2 := RelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
- "key": "uid",
- "value": sonRelation.FatherUid1,
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
-
- userDb := implement.NewUserDb(db.Db)
- son, err3 := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": sonRelation.Uid,
- })
- if err3 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err3.Error())
- return
- }
-
- parent, err4 := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": parentRelation.Uid,
- })
- if err4 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err4.Error())
- return
- }
-
- var sonNode []*md.TreeNode
- sonNode = append(sonNode, &md.TreeNode{
- AvatarURL: son.Avatar,
- Phone: son.Phone,
- Nickname: son.Nickname,
- Uid: son.Id,
- PID: sonRelation.RecommendUid,
- Level: sonRelation.Level1,
- Position: sonRelation.Position1,
- SystemID: sonRelation.Id,
- Son: nil,
- })
- res := md.TreeNode{
- AvatarURL: parent.Avatar,
- Phone: parent.Phone,
- Nickname: parent.Nickname,
- Uid: parent.Id,
- PID: parentRelation.RecommendUid,
- Level: parentRelation.Level1,
- Position: parentRelation.Position1,
- SystemID: parentRelation.Id,
- Son: sonNode,
- }
- e.OutSuc(c, res, nil)
- }
-
- // ExchangeUserPosition
- // @Summary 制度中心-公排管理-关系分布图(位置转换)
- // @Tags 公排管理
- // @Description 关系分布图(位置转换)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.ExchangeUserPositionReq true "需要交换的两个位置"
- // @Success 200 {} "成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/exchangeUserPosition [post]
- func ExchangeUserPosition(c *gin.Context) {
- var req *md.ExchangeUserPositionReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- userRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
- relation1, err2 := userRelationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- if relation1 == nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_1 位置有误"))
- return
- }
-
- relation2, err3 := userRelationDb.PublicPlatoonUserRelationGetOneByPosition(req.Position1)
- if err3 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err3.Error())
- return
- }
- if relation2 == nil {
- e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("position_2 位置有误"))
- return
- }
-
- if relation1.Uid == 1 || relation2.Uid == 1 {
- e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("创始人位置不能被修改"))
- }
-
- err4 := svc.ExchangeUserPosition(db.Db, relation1, relation2)
- if err4 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err4.Error())
- return
- }
-
- e.OutSuc(c, nil, nil)
- }
-
- // GetFreePublishUser
- // @Summary 制度中心-公排管理-免罚用户(查询)
- // @Tags 公排管理
- // @Description 免罚用户(查询)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.GetFreePublishUserReq true "页数和行数必填,uid选填"
- // @Success 200 {object} md.GetFreePublishUserResp "成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/index [post]
- func GetFreePublishUser(c *gin.Context) {
- var req *md.GetFreePublishUserReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
- var m []model.PublicPlatoonFreePunishWithUser
- var err error
- var total int64
- if req.Uid != 0 {
- m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, map[string]interface{}{
- "key": "uid",
- "value": req.Uid,
- })
- } else {
- m, total, err = freePunishWithUserDb.PublicPlatoonFreePunishWithUserCountAndGetPageByParams(req.Page, req.Limit, nil)
- }
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- userDb := implement.NewUserDb(db.Db)
- var ids []int64
- for _, item := range m {
- ids = append(ids, item.Uid)
- }
- users, err2 := userDb.UserFindByParams(map[string]interface{}{
- "key": "id",
- "value": ids,
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- }
-
- var nodes []md.FreePublishUserNode
- for _, user := range users {
- nodes = append(nodes, md.FreePublishUserNode{
- UID: user.Id,
- Phone: user.Phone,
- Nickname: user.Nickname,
- })
- }
- var paginate md.Paginate
- paginate = md.Paginate{
- Limit: req.Limit,
- Page: req.Page,
- Total: total,
- }
- var resp md.GetFreePublishUserResp
- resp = md.GetFreePublishUserResp{
- Paginate: paginate,
- List: nodes,
- }
- e.OutSuc(c, resp, nil)
- }
-
- // AddFreePublishUser
- // @Summary 制度中心-公排管理-免罚用户(新增)
- // @Tags 公排管理
- // @Description 免罚用户(新增)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.AddFreePublishUserReq true "页数和行数必填,uid选填"
- // @Success 200 {int} "插入数据 ID"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/publicPlatoonUserFreePunish/save [post]
- func AddFreePublishUser(c *gin.Context) {
- var req *md.AddFreePublishUserReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- userDb := implement.NewUserDb(db.Db)
- user, err2 := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": req.Uid,
- })
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- if user == nil {
- e.OutErr(c, e.ERR_DB_ORM, errors.New("该用户不存在"))
- }
-
- freePunishWithUserDb := implement.NewPublicPlatoonFreePunishWithUserDb(db.Db)
- var m model.PublicPlatoonFreePunishWithUser
- m = model.PublicPlatoonFreePunishWithUser{
- Uid: req.Uid,
- }
- id, err3 := freePunishWithUserDb.PublicPlatoonFreePunishWithUserInsert(&m)
- if err3 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err3.Error())
- return
- }
- e.OutSuc(c, id, nil)
- }
-
- // AddCommunityDividends
- // @Summary 制度中心-公排管理-社区分红(新增)
- // @Tags 公排管理
- // @Description 社区分红(新增)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.AddCommunityDividendsReq true "分红名称、分红总量"
- // @Success 200 {int} "插入数据 ID"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsAdd [post]
- func AddCommunityDividends(c *gin.Context) {
- var req *md.AddCommunityDividendsReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- // todo 判断分红数量是否大于社区分红钱包余额
-
- now := time.Now()
- var m model.EggEnergyCommunityDividends
- m = model.EggEnergyCommunityDividends{
- Name: req.Name,
- CoinId: 0,
- PersonsNum: 0,
- IsOver: 0,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
- dividendsDb := implement.NewEggEnergyCommunityDividendsDb(db.Db)
- id, err := dividendsDb.EggEnergyCommunityDividendsInsert(&m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, id, nil)
- }
-
- // AddCommunityDividendsWithUser
- // @Summary 制度中心-公排管理-社区长列表(新增)
- // @Tags 公排管理
- // @Description 社区长列表(新增)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Param req body md.AddCommunityDividendsWithUserReq true "新增社区长 ID、备注"
- // @Success 200 {int} "插入数据 ID"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/institutionalManagement/publicPlatoon/communityDividends/communityDividendsWithUserAdd [post]
- func AddCommunityDividendsWithUser(c *gin.Context) {
- var req *md.AddCommunityDividendsWithUserReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- now := time.Now()
- var m model.EggEnergyCommunityDividendsWithUser
- m = model.EggEnergyCommunityDividendsWithUser{
- Uid: req.Uid,
- Memo: req.Memo,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- }
-
- communityDividendsWithUserDb := implement.NewEggEnergyCommunityDividendsWithUserDb(db.Db)
- id, err := communityDividendsWithUserDb.EggEnergyCommunityDividendsWithUserInsert(&m)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, id, nil)
- }
|