123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package youngee_task_service
- import (
- "fmt"
- "reflect"
- "strings"
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/wxnacy/wgo/arrays"
- )
- type projectStatus int
- const (
- projectStatusCreating = iota + 1
- projectStatusReviewing
- projectStatusReviewed
- projectStatusRecruiting
- projectStatusRecruited
- projectStatusPaying
- projectStatusPaid
- projectStatusInvalid
- projectStatusInProgress
- projectStatusClosed
- )
- // 获取项目信息列表service
- func GetProjectInfoList(r *ghttp.Request) *TalentHttpResult {
- pageIndex := r.GetQueryInt("idx", -1)
- cntPerPage := r.GetQueryInt("cnt", -1)
- platform := r.Get("platform")
- projectForm := r.Get("projectform")
- feeForm := r.Get("feeform")
- searchValue := r.Get("searchvalue")
- if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数错误"}
- }
- // 如果有稿费形式的过滤条件,则将过滤条件保存于taskModeList
- var feeFormList []interface{}
- if feeForm != nil {
- if reflect.TypeOf(feeForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件稿费形式错误"}
- }
- feeFormList = make([]interface{}, 0)
- feeFormList = feeForm.([]interface{})
- }
- // 如果有任务形式的过滤条件,则将过滤条件保存于taskModeList
- var projectFormList []interface{}
- if projectForm != nil {
- if reflect.TypeOf(projectForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- projectFormList = make([]interface{}, 0)
- projectFormList = projectForm.([]interface{})
- }
- // 如果有平台的过滤条件,则将平台列表保存于platformList
- var platformList []interface{}
- if platform != nil {
- if reflect.TypeOf(platform).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件平台类型错误"}
- }
- platformList = make([]interface{}, 0)
- platformList = platform.([]interface{})
- }
- // 构造查询的条件
- startId := pageIndex * cntPerPage
- // whereStr := fmt.Sprintf("(project_status >= %d and project_status <> %d and project_type = 1)", projectStatusRecruiting, projectStatusInvalid)
- whereStr := fmt.Sprintf("(project_status >= %d and fail_reason <> 2 and project_type = 1)", projectStatusRecruiting)
- if platformList != nil {
- whereStr = whereStr + " and project_platform in ("
- for _, v := range platformList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- if projectFormList != nil {
- whereStr += " and project_form in ("
- for _, v := range projectFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- if searchValue != nil {
- whereStr += " and project_name like '%" + searchValue.(string) + "%'"
- }
- // 查询所有project
- var projectList = []model.ProjectInfo{}
- var projectIdList []string
- err := g.Model(dao.ProjectInfo.Table).Where(whereStr).Scan(&projectList)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
- }
- fmt.Println("searchValue:", searchValue)
- fmt.Println("feeFormList:", feeFormList)
- fmt.Println("projectList:", projectList)
- // 筛选出满足稿费形式条件的项目id列表
- for _, v := range projectList {
- string_slice := strings.Split(v.FeeForm, ",")
- // fmt.Println("str:", string_slice)
- tmp := 0
- for _, w := range feeFormList {
- i := arrays.ContainsString(string_slice, w.(string))
- if i < 0 {
- tmp = 0
- break
- }
- tmp = 1
- }
- if tmp == 1 {
- projectIdList = append(projectIdList, v.ProjectId)
- }
- }
- if projectIdList != nil {
- whereStr += " and project_id in ("
- for _, v := range projectIdList {
- whereStr += v + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- } else if feeForm != nil {
- return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
- }
- fmt.Println("whereStr: ", whereStr)
- // 判断请求页面是否超过最大页面
- c, err := g.DB().Model(dao.ProjectInfo.Table).Fields("project_id").Where(whereStr).Count()
- if c <= 0 {
- return &TalentHttpResult{Code: -4, Msg: "has no fullproject", Data: nil}
- }
- maxPage := c / cntPerPage
- if c%cntPerPage > 0 {
- maxPage += 1
- }
- if pageIndex+1 > maxPage {
- return &TalentHttpResult{Code: -5, Msg: "over max page"}
- }
- var projectInfoList = youngee_talent_model.ProjectInfoList{}
- err = g.DB().Model("project_info").WithAll().Where(whereStr).
- Order("project_status ASC,recruit_ddl ASC, project_id").Limit(startId, cntPerPage).Scan(&projectInfoList.ProjectInfos)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
- }
- projectInfoList.MaxPage = maxPage
- return &TalentHttpResult{Code: 0, Msg: "success", Data: projectInfoList}
- }
- // 获取单个项目详情service
- func GetProjectDetail(r *ghttp.Request) *TalentHttpResult {
- pid := r.GetQueryInt("projectid", 0)
- if pid == 0 {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- var ProjectDetail *youngee_talent_model.ProjectDetail
- err := g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", pid).Scan(&ProjectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "data query failed"}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: ProjectDetail}
- }
|