package youngee_talent_service import ( "fmt" "youngmini_server/app/dao" "youngmini_server/app/model/youngee_talent_model" "youngmini_server/app/utils" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" ) func OnPostTalentInfo(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } var infos *youngee_talent_model.TalentSelfInputInfo err = r.ParseForm(&infos) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } infos.IsBindInfo = 1 _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Update(infos, "id", tid) if err != nil { return &TalentHttpResult{Code: -4, Msg: "update failed"} } return &TalentHttpResult{Code: 0, Msg: "success"} } func IsSecCollection(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } selectionId := r.GetQueryString("selection_id") collectionInfo := []youngee_talent_model.SelectionCollection{} err = g.DB().Model("younggee_selection_collect_info").Where("selection_id=? and talent_id = ?", selectionId, tid).Scan(&collectionInfo) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } //已被收藏 if len(collectionInfo) != 0 && collectionInfo[0].Deleted == 0 { //有数据 且 没取消收藏 return &TalentHttpResult{Code: 0, Msg: "此选品已被收藏", Data: 0} } else { return &TalentHttpResult{Code: 0, Msg: "此选品没有被收藏", Data: 1} //没数据 或 有数据但取消了收藏 } //返回的data作为收藏接口的is_collect字段传入 } func OnUpdateTalentInfo(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } var infos *youngee_talent_model.TalentSelfInputInfo err = r.ParseForm(&infos) fmt.Println("头像地址---->:", infos.Avatar) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Data(g.Map{"talent_wx_nickname": infos.TalentWxNickname, "avatar": infos.Avatar}).Where("id = ?", tid).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "update failed"} } return &TalentHttpResult{Code: 0, Msg: "success"} } func UpdateTalentName(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } var infos *youngee_talent_model.UpdateNameReq err = r.ParseForm(&infos) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Data(g.Map{"talent_nickname": infos.TalentNickname}).Where("id = ?", tid).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "update failed"} } return &TalentHttpResult{Code: 0, Msg: "success"} } func UpdateTalentWxnum(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } var infos *youngee_talent_model.UpdateWxNameReq err = r.ParseForm(&infos) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } _, err = g.DB().Model("youngee_talent_info").Data(g.Map{"wx_num": infos.WxNum}).Where("id = ?", tid).Update() if err != nil { return &TalentHttpResult{Code: -4, Msg: "update failed"} } return &TalentHttpResult{Code: 0, Msg: "success"} } func GetTalentInfo(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } talentInfo := youngee_talent_model.TalentInfo{} //结构体实例化 err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo) if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get talent info failed"} } return &TalentHttpResult{Code: 0, Msg: "success", Data: talentInfo} } // // 查询任务数量、young之团数量、选品任务数量 // // func GetMyInfoNum(r *ghttp.Request) *TalentHttpResult { // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) // if err != nil { // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} // } // talentInfoNum := &youngee_talent_model.TalentInfoNum{} // // 查询任务相关数量 // var endTaskStageList = [3]int{3, 5, 16} // // //种草 // fmt.Println("1") // talentInfoNum.AllTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id=?", tid).Count() // fmt.Println("talentInfoNum.AllTaskNum111", talentInfoNum.AllTaskNum) // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ApplyTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 1", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ExeTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.EndTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage in (?)", tid, endTaskStageList).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ToDealNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 15", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // // //带货任务相关数量 // fmt.Println("2") // talentInfoNum.AllSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ?", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.GetSampleSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage in (3,4, 5)", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ExeSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and sale_num_all > 0", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.EndSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and task_ddl < NOW() ", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.InSampleProcessNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage = 1 ", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ToGetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 1 ", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.GetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 2 ", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // //本地生活 // fmt.Println("3") // talentInfoNum.AllTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id=?", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ApplyTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 1", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ToBookLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 4", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ExeTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.ToDealLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // talentInfoNum.EndTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage in (?)", tid, endTaskStageList).Count() // if err != nil { // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} // } // // return &TalentHttpResult{Code: 0, Msg: "success1", Data: &talentInfoNum} // } func GetMyInfoNum(r *ghttp.Request) *TalentHttpResult { // 获取 talentId tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } taskType := r.GetInt("task_type", 0) if taskType == 0 { return &TalentHttpResult{Code: -1, Msg: "task_type is null"} } // 初始化 talentInfoNum talentInfoNum := &youngee_talent_model.TalentInfoNum{ TaskCountNum: &youngee_talent_model.TaskCountNum{}, SecTaskCountNum: &youngee_talent_model.SecTaskCountNum{}, LocalTaskCountNum: &youngee_talent_model.LocalTaskCountNum{}, } // 查询任务相关数量 var endTaskStageList = [3]int{3, 5, 16} // 种草任务相关数量 fmt.Println("1") talentInfoNum.TaskCountNum.AllTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id=? AND project_type = ? ", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.TaskCountNum.ApplyTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 1 AND project_type = ? ", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.TaskCountNum.ExeTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and project_type = ? ", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.TaskCountNum.EndTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage in (?) and project_type = ? ", tid, endTaskStageList, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.TaskCountNum.ToDealNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 15 and project_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } // 带货任务相关数量 fmt.Println("2") talentInfoNum.SecTaskCountNum.AllSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ?", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.GetSampleSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage in (3,4, 5)", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.ExeSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and sale_num_all > 0", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.EndSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and task_ddl < NOW() ", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.InSampleProcessNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage = 1 ", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.ToGetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 1 ", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.SecTaskCountNum.GetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 2 ", tid).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } // 本地生活任务相关数量 fmt.Println("3") talentInfoNum.LocalTaskCountNum.AllLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id=? and local_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.LocalTaskCountNum.ApplyLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 1 and local_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.LocalTaskCountNum.ToBookLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 4 and local_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.LocalTaskCountNum.ExeLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and local_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.LocalTaskCountNum.ToDealLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and local_type = ?", tid, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } talentInfoNum.LocalTaskCountNum.EndLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage in (?) and local_type = ?", tid, endTaskStageList, taskType).Count() if err != nil { return &TalentHttpResult{Code: -2, Msg: "Get task num failed"} } // 返回填充好的 talentInfoNum return &TalentHttpResult{Code: 0, Msg: "success1", Data: talentInfoNum} } func AddTalentSkill(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } skills := r.GetQueryString("skills", "") openId := r.GetQueryString("open_id") _, err = g.DB().Model("platform_kuaishou_user_info").Where("open_id=? and talent_id=?", openId, tid).Data(g.Map{"skill": skills}).Update() if err != nil { return &TalentHttpResult{Code: -1, Msg: "Update talent info failed"} } return &TalentHttpResult{Code: 0, Msg: "success", Data: skills} }