package youngee_talent_service import ( "encoding/json" "fmt" "github.com/gogf/gf/os/gtime" "youngmini_server/app/dao" "youngmini_server/app/model" "youngmini_server/app/model/youngee_talent_model" "youngmini_server/app/utils" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" ) func GetYounggeeTeamList(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } status := r.GetQueryInt("status", 0) if status == 0 { return &TalentHttpResult{Code: -2, Msg: "parse param error"} } whereCondition := g.Map{ dao.YounggeeTalentTeam.Columns.TalentId: tid, dao.YounggeeTalentTeam.Columns.TeamStatus: status, } num, err := g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Count() if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } var teamList []*model.YounggeeTalentTeam if num != 0 { err = g.DB().Model(dao.YounggeeTalentTeam.Table).Where("leader_tid = ? and team_status = ?", tid, status).Scan(&teamList) if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } } whereCondition1 := g.Map{ dao.YounggeeTalentTeam.Columns.TalentId: tid, dao.YounggeeTalentTeam.Columns.TeamStatus: 3, } point, err := g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition1).Sum(dao.YounggeeTalentTeam.Columns.PointIncome) if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } money, err := g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition1).Sum(dao.YounggeeTalentTeam.Columns.MoneyIncome) if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } GetYoungTeamListRsp := youngee_talent_model.GetYoungTeamListRsp{ YoungTeamList: teamList, Num: num, PointIncome: int(point), MoneyIncome: money, } return &TalentHttpResult{Code: 0, Msg: "success", Data: GetYoungTeamListRsp} } func GetYounggeeTeamDetail(r *ghttp.Request) *TalentHttpResult { // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) // if err != nil { // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} // } teamId := r.GetQueryString("id", "") projectType := r.GetQueryInt("type", 0) taskStage := r.GetQueryInt("stage", 0) if teamId == "" || projectType == 0 || taskStage == 0 { return &TalentHttpResult{Code: -2, Msg: "parse param error"} } if projectType == 1 { //全流程项目 // 构造查询条件 whereStr1 := "" switch taskStage { case 1: whereStr1 += fmt.Sprintf("") case 2: whereStr1 += fmt.Sprintf("task_stage > 3 and task_stage < 15") case 3: whereStr1 += fmt.Sprintf("task_stage = 15") case 4: whereStr1 += fmt.Sprintf("task_stage = 16") default: return &TalentHttpResult{Code: -2, Msg: "parse param error"} } whereStr2 := fmt.Sprintf("team_id = %s", teamId) whereStr3 := fmt.Sprintf("lead_team_id = %s", teamId) whereStr := whereStr1 + " and " + whereStr2 orStr := whereStr1 + " and " + whereStr3 // 查询 var taskList []*model.YoungeeTaskInfo var teamTaskList []youngee_talent_model.YounggeeTeamTaskInfo err := g.DB().Model(dao.YoungeeTaskInfo.Table).Where(whereStr).Or(orStr).Scan(&taskList) if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } for _, v := range taskList { var talentInfo *model.YoungeeTalentInfo jsonData := []byte(v.TalentPersonalInfoSnap) json.Unmarshal(jsonData, &talentInfo) teamTask := youngee_talent_model.YounggeeTeamTaskInfo{ Avatar: talentInfo.Avatar, TalentWxNickname: talentInfo.TalentWxNickname, MoneyIncome: v.TeamIncome, PointIncome: v.TeamPoint, TaskStage: v.TaskStage, CurDefaultStatus: v.CurDefaultType, } teamTaskList = append(teamTaskList, teamTask) } return &TalentHttpResult{Code: 0, Msg: "success", Data: teamTaskList} } else if projectType == 2 { //选品项目 // 构造查询条件 whereStr1 := "" switch taskStage { case 1: whereStr1 += fmt.Sprintf("") case 2: whereStr1 += fmt.Sprintf("task_stage > 4 and task_stage < 9") case 3: whereStr1 += fmt.Sprintf("task_stage = 9") case 4: return &TalentHttpResult{Code: -2, Msg: "parse param error"} default: return &TalentHttpResult{Code: -2, Msg: "parse param error"} } whereStr2 := fmt.Sprintf("team_id = %s", teamId) whereStr3 := fmt.Sprintf("lead_team_id = %s", teamId) whereStr := whereStr1 + " and " + whereStr2 orStr := whereStr1 + " and " + whereStr3 // 查询 var taskList []*model.YounggeeSecTaskInfo var teamTaskList []youngee_talent_model.YounggeeTeamTaskInfo err := g.DB().Model(dao.YounggeeSecTaskInfo.Table).Where(whereStr).Or(orStr).Scan(&taskList) if err != nil { return &TalentHttpResult{Code: -3, Msg: "mysql select failed"} } for _, v := range taskList { var talentInfo *model.YoungeeTalentInfo jsonData := []byte(v.TalentPersonalInfoSnap) json.Unmarshal(jsonData, &talentInfo) teamTask := youngee_talent_model.YounggeeTeamTaskInfo{ Avatar: talentInfo.Avatar, TalentWxNickname: talentInfo.TalentWxNickname, MoneyIncome: float64(v.TeamIncome) * v.TaskReward / 100, PointIncome: v.TeamPoint, TaskStage: v.TaskStage, } teamTaskList = append(teamTaskList, teamTask) } return &TalentHttpResult{Code: 0, Msg: "success", Data: teamTaskList} } else { return &TalentHttpResult{Code: -2, Msg: "parse param error"} } } // 创建young之团 func AddYoungTeam(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } var addYoungTeamReq *youngee_talent_model.AddYoungTeamReq err = r.ParseForm(&addYoungTeamReq) if err != nil { return &TalentHttpResult{Code: -2, Msg: "params error"} } var whereCondition g.Map if addYoungTeamReq.ProjectType == 1 { whereCondition = g.Map{ dao.YounggeeTalentTeam.Columns.ProjectId: addYoungTeamReq.ProjectId, dao.YounggeeTalentTeam.Columns.TalentId: tid, } } else { whereCondition = g.Map{ dao.YounggeeTalentTeam.Columns.SelectionId: addYoungTeamReq.SelectionId, dao.YounggeeTalentTeam.Columns.TalentId: tid, } } num, err := g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Count() if err != nil { return &TalentHttpResult{Code: -3, Msg: "data query failed"} } var youngTeam *model.YounggeeTalentTeam var teamId string if num == 0 { // 生成随机十位数作为young之团id teamId = utils.GetUuid.GetTeamId(addYoungTeamReq.ProjectId, addYoungTeamReq.SelectionId, tid) // 查询项目主图 var mainPhoto string var projectName string var platform int if addYoungTeamReq.ProjectType == 1 { whereCondition1 := g.Map{ dao.ProjectInfo.Columns.ProjectId: addYoungTeamReq.ProjectId, } var project *model.ProjectInfo err = g.DB().Model(dao.ProjectInfo.Table).Where(whereCondition1).Scan(&project) if err != nil { return &TalentHttpResult{Code: -3, Msg: "data query failed"} } projectName = project.ProjectName platform = project.ProjectPlatform var productPhotos []model.YounggeeProductPhoto err = json.Unmarshal([]byte(project.ProductPhotoSnap), &productPhotos) if err != nil { return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"} } fmt.Println("productPhotos: ", productPhotos) for _, v := range productPhotos { if v.Symbol == 1 { mainPhoto = v.PhotoUrl } } } else { whereCondition1 := g.Map{ dao.YounggeeSelectionInfo.Columns.SelectionId: addYoungTeamReq.SelectionId, } var selection *model.YounggeeSelectionInfo err = g.DB().Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Scan(&selection) if err != nil { return &TalentHttpResult{Code: -3, Msg: "data query failed"} } projectName = selection.SelectionName platform = selection.Platform var productPhotos []model.YounggeeProductPhoto fmt.Println("ProductPhotoSnap: ", selection.ProductPhotoSnap) err = json.Unmarshal([]byte(selection.ProductPhotoSnap), &productPhotos) if err != nil { return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"} } fmt.Println("productPhotos: ", productPhotos) for _, v := range productPhotos { if v.Symbol == 1 { mainPhoto = v.PhotoUrl } } } // 查询奖励机制id newYoungTeam := model.YounggeeTalentTeam{ TeamId: teamId, TalentId: tid, ProjectId: addYoungTeamReq.ProjectId, SelectionId: addYoungTeamReq.SelectionId, ProjectType: addYoungTeamReq.ProjectType, ProjectPhoto: mainPhoto, ProjectName: projectName, Platform: platform, TeamStatus: 1, NumApply: 0, NumApplySuccess: 0, MoneyIncome: 0, PointIncome: 0, CreateAt: gtime.Now(), } _, err = g.DB().Model(dao.YounggeeTalentTeam.Table).Insert(newYoungTeam) if err != nil { return &TalentHttpResult{Code: -4, Msg: "YounggeeTalentTeam Insert failed"} } } else { err = g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Scan(&youngTeam) if err != nil { return &TalentHttpResult{Code: -5, Msg: "data query failed"} } teamId = youngTeam.TeamId } return &TalentHttpResult{Code: 0, Msg: "success", Data: teamId} } // 获取团长young之团id func GetLeadYoungTeamId(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } projectType := r.GetQueryInt("project_type", -1) projectId := r.Get("project_id", "") selectionId := r.Get("selection_id", "") var whereCondition g.Map if projectType == 1 { whereCondition = g.Map{ dao.YounggeeTalentTeam.Columns.ProjectId: projectId, dao.YounggeeTalentTeam.Columns.TalentId: tid, } } else { whereCondition = g.Map{ dao.YounggeeTalentTeam.Columns.SelectionId: selectionId, dao.YounggeeTalentTeam.Columns.TalentId: tid, } } num, err := g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Count() if err != nil { return &TalentHttpResult{Code: -3, Msg: "data query failed"} } var youngTeam *model.YounggeeTalentTeam var teamId string if num != 0 { err = g.DB().Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Scan(&youngTeam) if err != nil { return &TalentHttpResult{Code: -5, Msg: "data query failed"} } teamId = youngTeam.TeamId } getLeadYoungTeamIdRsp := youngee_talent_model.GetLeadYoungTeamIdRsp{ teamId, num, } return &TalentHttpResult{Code: 0, Msg: "success", Data: getLeadYoungTeamIdRsp} }