12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457 |
- package youngee_task_service
- import (
- "context"
- "fmt"
- "strconv"
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- "youngmini_server/app/service/youngee_talent_service"
- "youngmini_server/app/utils"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/encoding/gjson"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/gtime"
- )
- // 新建任务service
- //func SignUpTask(r *ghttp.Request) *TalentHttpResult {
- // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- // }
- //
- // var signTaskInfo *youngee_talent_model.SignTaskInfo
- // err = r.ParseForm(&signTaskInfo)
- // if err != nil {
- // return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- // }
- // var projectDetail *youngee_talent_model.ProjectDetail
- // err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
- // if err != nil {
- // return &TalentHttpResult{Code: -3, Msg: err.Error()}
- // }
- //
- // var talentInfo *youngee_talent_model.TalentInfo
- // err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
- // if err != nil {
- // return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
- // }
- //
- // var accountInfo *youngee_talent_model.PlatformAccountInfo
- // err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
- // if err != nil {
- // return &TalentHttpResult{Code: -5, Msg: err.Error()}
- // }
- //
- // address, err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).One("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId)
- // if err != nil {
- // return &TalentHttpResult{Code: -6, Msg: err.Error()}
- // }
- //
- // var newTaskId string
- // // 首先生成任务id
- // newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
- //
- // //// 生成达人平台账号信息快照
- // accountSnap, err := gjson.Encode(accountInfo)
- // //if err != nil {
- // // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
- // //}
- //
- // // 生成达人信息快照
- // talentSnap, err := gjson.Encode(talentInfo)
- // if err != nil {
- // return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
- // }
- //
- // // 生成收货地址快照
- // addrSnap, err := gjson.Encode(address)
- // if err != nil {
- // return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
- // }
- // taskInfo := model.YoungeeTaskInfo{}
- // if projectDetail.ProjectType == 1 {
- // // 全流程任务
- //
- // // 计算平台服务费
- // // 1. 先获取稿费形式
- // var strategy *youngee_talent_model.RecruitStrategy
- // err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- // if err != nil {
- // return &TalentHttpResult{Code: -10, Msg: err.Error()}
- // }
- //
- // // 2. 根据稿费形式、平台、粉丝数获取服务费最高的定价策略
- // // 2.1 查询所有对应定价策略
- // whereStr1 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up > %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersLow)
- // orStr1 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low < %d and fans_up >= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersUp, strategy.FollowersUp)
- // orStr2 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low >= %d and fans_up <= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersUp)
- // orStr3 := fmt.Sprintf("fee_form = %d and platform = %d and fans_low <= %d and fans_up >= %d", strategy.FeeForm, projectDetail.ProjectPlatform, strategy.FollowersLow, strategy.FollowersUp)
- // var pricings []*model.InfoPricingStrategy
- // err = g.DB().Model("recruit_strategy").WithAll().Where(whereStr1).Or(orStr1).Or(orStr2).Or(orStr3).Scan(&pricings)
- // if err != nil {
- // return &TalentHttpResult{Code: -11, Msg: err.Error()}
- // } else if pricings == nil {
- // return &TalentHttpResult{Code: -12, Msg: "无相关定价策略"}
- // }
- // var pricing *model.InfoPricingStrategy
- // // 2.2 从对应定价策略中选取服务费率最高
- // if strategy.FeeForm == 1 {
- // var maxCharge float64 = 0
- // for _, v := range pricings {
- // if v.ServiceCharge >= maxCharge {
- // maxCharge = v.ServiceCharge
- // pricing = v
- // }
- // }
- // } else {
- // var maxRate int = 0
- // for _, v := range pricings {
- // if v.ServiceRate >= maxRate {
- // maxRate = v.ServiceRate
- // pricing = v
- // }
- // }
- // }
- // var serviceCharge = 0.0
- // var serviceRate = 0
- // var allReward = 0.0
- // var allPayment = 0.0
- // switch strategy.FeeForm {
- // case 1: // 产品置换,服务费固定,在项目生成时确定
- // serviceCharge = float64(strategy.ServiceCharge)
- // allPayment = serviceCharge
- // break
- // case 2: // 固定稿费,m2 = y2 * r2
- // allPayment = float64(strategy.Offer)
- // serviceRate = pricing.ServiceRate
- // serviceCharge = allPayment * float64(serviceRate) / 1000
- // allReward = allPayment - serviceCharge
- // break
- // case 3: // 自报价,m3 = x3 * r3
- // allReward = float64(signTaskInfo.Offer)
- // serviceRate = pricing.ServiceRate
- // var tmpRate = float64(1000-serviceRate) / 1000
- // allPayment = allReward / tmpRate
- // serviceCharge = allPayment - allReward
- // break
- // default:
- // break
- // }
- // taskInfo = model.YoungeeTaskInfo{
- // TaskId: newTaskId,
- // ProjectId: signTaskInfo.ProjectId,
- // TalentId: tid,
- // AccountId: accountInfo.AccountId,
- // TalentPlatformInfoSnap: string(accountSnap),
- // TalentPersonalInfoSnap: string(talentSnap),
- // TalentPostAddrSnap: string(addrSnap),
- // StrategyId: signTaskInfo.StrategyId,
- // TaskReward: allReward,
- // SettleAmount: allReward,
- // AllPayment: allPayment,
- // TaskStage: 1,
- // RealPayment: allPayment,
- // FeeForm: strategy.FeeForm,
- // ServiceCharge: serviceCharge,
- // ServiceRate: serviceRate,
- // CreateDate: gtime.Now(),
- // TaskStatus: 1,
- // LogisticsStatus: 1,
- // LinkStatus: 1,
- // DataStatus: 1,
- // ScriptStatus: 1,
- // SketchStatus: 1,
- // CompleteStatus: 1,
- // CurDefaultType: 0,
- // WithdrawStatus: 1,
- // SettleStatus: 1,
- // }
- // } else {
- // // 专项任务
- // taskInfo = model.YoungeeTaskInfo{
- // TaskId: newTaskId,
- // ProjectId: signTaskInfo.ProjectId,
- // TalentId: tid,
- // AccountId: accountInfo.AccountId,
- // //TalentPlatformInfoSnap: string(accountSnap),
- // TalentPersonalInfoSnap: string(talentSnap),
- // TalentPostAddrSnap: string(addrSnap),
- // TaskStage: 1,
- // CreateDate: gtime.Now(),
- // TaskStatus: 1,
- // LogisticsStatus: 1,
- // LinkStatus: 1,
- // DataStatus: 1,
- // ScriptStatus: 1,
- // SketchStatus: 1,
- // CompleteStatus: 1,
- // CurDefaultType: 0,
- // WithdrawStatus: 1,
- // }
- // }
- // err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // // 在task_info表中插入任务
- // _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
- // if err != nil {
- // return err
- // }
- //
- // // 对应项目的报名人数自增
- // _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
- // if err != nil {
- // return err
- // }
- // return nil
- // })
- // if err != nil {
- // return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- // }
- //
- // return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
- //}
- // 判断是否已报名任务,快手平台账号选择时,已经判断过
- func IsSignUpTask(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- projectId := r.GetQueryInt("project_id", -1)
- fmt.Printf("%+v\n", projectId)
- task := []model.YoungeeTaskInfo{}
- err = g.Model(dao.YoungeeTaskInfo.Table).Where("project_id = ? and talent_id = ?", projectId, tid).Scan(&task)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- isSign := youngee_talent_model.IsSign{}
- if len(task) != 0 {
- isSign.TaskInfo = &task[0]
- isSign.IsSign = 1
- isSign.IsAgree = task[0].TaskStatus
- } else {
- isSign.IsSign = 0
- isSign.IsAgree = 0
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
- }
- // 查询所有任务
- func GetTaskBriefList(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- // 构造查询条件
- whereStr := fmt.Sprintf("talent_id = '%s'", tid)
- // 获取任务列表
- var taskList []*youngee_talent_model.YoungeeTaskInfo
- //此达人下,所有账号的任务都展示
- err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr).Order("create_date desc").Scan(&taskList)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get task list failed", Data: err.Error()}
- }
- //后续根据 PlatformId 快速查找平台信息。platformMap的key是PlatformId,value是平台具体描述
- platformMap := make(map[string]model.InfoThirdPlatform)
- platformInfo := []*model.InfoThirdPlatform{}
- if len(taskList) != 0 {
- err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
- }
- for i, _ := range platformInfo {
- platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
- }
- }
- //为每个任务根据项目id查询项目名称和主图
- //taskBriefList存了各个阶段的tasklist
- taskBriefList := youngee_talent_model.TaskInfoBriefList{}
- fmt.Println("taskList----的长度为:", len(taskList))
- for _, v := range taskList { //taskList含所有任务
- //获取具体的招募策略,taskInfo中
- fmt.Println("遍历tasklist---", v)
- var projectDetail *youngee_talent_model.ProjectDetail
- fmt.Println("v.ProjectId:", v.ProjectId)
- err := g.Model("project_info").WithAll().Where("project_id = ?", v.ProjectId).Scan(&projectDetail)
- fmt.Println("projectDetail-----", projectDetail)
- //各阶段扣款比例
- one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", projectDetail.AutoDefaultId).One()
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error()}
- } else {
- projectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
- projectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
- projectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
- }
- //各阶段扣款时间
- one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", projectDetail.AutoTaskId).One()
- if err2 != nil {
- return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
- } else {
- projectDetail.DraftBreakTime = one2["draft_default"].Int()
- projectDetail.LinkBreakTime = one2["link_breach"].Int()
- projectDetail.DataBreakTime = one2["case_close_default"].Int()
- }
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- }
- var account *youngee_talent_model.KuaishouUserInfo
- fmt.Println("openid---->", v.OpenId)
- err = g.DB().Model("platform_kuaishou_user_info").Where("platform_id = ? and talent_id = ? and open_id = ?", v.PlatformId, tid, v.OpenId).Scan(&account)
- //拿快手平台验证是否过期
- if v.PlatformId == 8 || v.PlatformId == 4 {
- expired := youngee_talent_service.CheckKuaishouTokenExp(account.OpenId)
- account.Expired = expired
- } else if v.PlatformId == 2 {
- expired := youngee_talent_service.CheckDouyinTokenExp(account.OpenId)
- account.Expired = expired
- }
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- }
- //taskInfoBrief含需要展示在页面的内容,被加入各阶段List
- taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
- TaskId: v.TaskId,
- //PlatformIconUrl: platformMap[strconv.Itoa(projectDetail.PlatformInfo.PlatformId)].PlatformIcon,
- //PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
- //PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
- ProjectName: projectDetail.ProjectName,
- ProductPhotoSnap: projectDetail.ProductPhotoSnap,
- TaskStatus: v.TaskStatus,
- TaskStage: v.TaskStage,
- LinkStatus: v.LinkStatus,
- DataStatus: v.DataStatus,
- ScriptStatus: v.ScriptStatus,
- SketchStatus: v.SketchStatus,
- TaskReward: v.TaskReward,
- BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
- CurBreakAt: v.CurBreakAt,
- FeeForm: v.FeeForm,
- ProjectDetail: projectDetail,
- TaskInfo: v,
- AccountInfo: account, //含是否过期,粉丝数,作品数目
- }
- taskBriefList.AllTaskInfoList = append(taskBriefList.AllTaskInfoList, taskInfoBrief)
- if v.TaskStage <= 2 {
- taskBriefList.SignUpTaskInfoList = append(taskBriefList.SignUpTaskInfoList, taskInfoBrief)
- } else if v.TaskStage <= 14 && v.TaskStage >= 4 {
- taskBriefList.GoingOnTaskInfoList = append(taskBriefList.GoingOnTaskInfoList, taskInfoBrief)
- } else if v.TaskStage == 15 {
- taskBriefList.WaitToPayInfoList = append(taskBriefList.WaitToPayInfoList, taskInfoBrief)
- } else {
- taskBriefList.CompletedTaskInfoList = append(taskBriefList.CompletedTaskInfoList, taskInfoBrief)
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
- }
- // 查询执行中所有任务
- //func GetExeTaskBriefList(r *ghttp.Request) *TalentHttpResult {
- // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- // }
- // var taskStageList = [5]int{0, 7, 9, 11, 13}
- // taskStageKey := r.GetQueryInt("taskStage", 0)
- // if taskStageKey == 0 {
- // return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- // }
- // taskStage := taskStageList[taskStageKey+1]
- //
- // // 获取任务列表
- // //这是一个切片,其中的每个元素都是指向 model.YoungeeTaskInfo 结构体的指针。通常用于存储多个任务信息的列表。
- // var taskList []*model.YoungeeTaskInfo
- // whereCondition := g.Map{
- // dao.YoungeeTaskInfo.Columns.TalentId: tid,
- // dao.YoungeeTaskInfo.Columns.TaskStage: taskStage,
- // }
- // err = g.Model(dao.YoungeeTaskInfo.Table).Where(whereCondition).Scan(&taskList)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
- // }
- //
- // platformMap := make(map[string]model.InfoThirdPlatform)
- // var platformInfo []*model.InfoThirdPlatform
- // if len(taskList) != 0 {
- // err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
- // }
- //
- // for i, _ := range platformInfo {
- // platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
- // }
- // }
- //
- // // 为每个任务根据项目id查询项目名称和主图
- // var taskBriefList []*youngee_talent_model.TaskInfoBrief
- // for _, v := range taskList {
- // whereCondition = g.Map{
- // dao.ProjectInfo.Columns.ProjectId: v.ProjectId,
- // }
- // projectInfo, err := g.Model(dao.ProjectInfo.Table).Where(whereCondition).One()
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- // }
- // whereCondition = g.Map{
- // dao.YoungeePlatformAccountInfo.Columns.PlatformId: projectInfo[dao.ProjectInfo.Columns.ProjectPlatform],
- // dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
- // }
- // account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One()
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- // }
- // taskInfoBrief := &youngee_talent_model.TaskInfoBrief{
- // TaskId: v.TaskId,
- // PlatformIconUrl: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformIcon,
- // PlatformName: platformMap[projectInfo[dao.ProjectInfo.Columns.ProjectPlatform].String()].PlatformName,
- // PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
- // ProjectName: projectInfo[dao.ProjectInfo.Columns.ProjectName].String(),
- // ProductPhotoSnap: projectInfo[dao.ProjectInfo.Columns.ProductPhotoSnap].String(),
- // TaskStatus: v.TaskStatus,
- // TaskStage: v.TaskStage,
- // LinkStatus: v.LinkStatus,
- // DataStatus: v.DataStatus,
- // ScriptStatus: v.ScriptStatus,
- // SketchStatus: v.SketchStatus,
- // TaskReward: v.TaskReward,
- // BreakRate: v.ScriptBreakRate + v.SketchBreakRate + v.LinkBreakRate + v.DataBreakRate,
- // CurBreakAt: v.CurBreakAt,
- // FeeForm: v.FeeForm,
- // }
- // taskBriefList = append(taskBriefList, taskInfoBrief)
- // }
- //
- // return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
- //}
- // 查询执行中所有任务
- func GetExeTaskNum(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- nums, err := g.Model("youngee_task_info").Where("talent_id = ?", tid).Fields("COUNT(*) ,task_stage").Group("task_stage").All()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: nums}
- }
- func GetTaskNum(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- // 构造查询条件
- whereStr1 := fmt.Sprintf("talent_id = '%s'", tid)
- whereStr2 := fmt.Sprintf("talent_id = '%s' and task_stage <= 2", tid)
- whereStr3 := fmt.Sprintf("talent_id = '%s' and task_stage <= 14 and task_stage >= 4", tid)
- whereStr4 := fmt.Sprintf("talent_id = '%s' and (task_stage = 3 or task_stage >= 15)", tid)
- num1, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr1).Count()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- }
- num2, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr2).Count()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- }
- num3, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr3).Count()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- }
- num4, err := g.Model(dao.YoungeeTaskInfo.Table).Where(whereStr4).Count()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
- }
- TaskNum := &youngee_talent_model.TaskNum{
- AllNum: num1,
- SignUpNum: num2,
- GoingOnNum: num3,
- CompletedNum: num4,
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: TaskNum}
- }
- // 获取任务详情
- func GetTaskDetail(r *ghttp.Request) *TalentHttpResult {
- taskId := r.GetQueryString("task_id", -1)
- var task *youngee_talent_model.YoungeeTaskInfo
- err := g.Model("youngee_task_info").Where("task_id = ?", taskId).Scan(&task)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
- }
- var projectDetail *youngee_talent_model.ProjectDetail
- err = g.Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", task.ProjectId).Scan(&projectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "data query failed"}
- }
- //各阶段扣款比例
- one, err := g.DB().Model("info_auto_default_handle").Where("auto_default_id=?", projectDetail.AutoDefaultId).One()
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error()}
- } else {
- projectDetail.DraftBreakPercent = one["sketch_replace_not_upload"].Int()
- projectDetail.LinkBreakPercent = one["link_replace_not_upload"].Int()
- projectDetail.DataBreakPercent = one["data_replace_not_upload"].Int()
- }
- //各阶段扣款时间
- one2, err2 := g.DB().Model("info_auto_task").Where("auto_task_id=?", projectDetail.AutoTaskId).One()
- if err2 != nil {
- return &TalentHttpResult{Code: 0, Msg: "one2 is nil"}
- } else {
- projectDetail.DraftBreakTime = one2["draft_default"].Int()
- projectDetail.LinkBreakTime = one2["link_breach"].Int()
- projectDetail.DataBreakTime = one2["case_close_default"].Int()
- }
- var productPhoto *youngee_talent_model.YounggeeProductPhoto
- err = g.Model(dao.YounggeeProductPhoto.Table).Where("product_id = ? and symbol = 1", projectDetail.ProductId).Scan(&productPhoto)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "data query failed"}
- }
- var withdrawStatus = 1
- var taskIncome *model.YounggeeTalentIncome
- err = g.Model(dao.YounggeeTalentIncome.Table).Where("task_id = ? and income_type = 1", taskId).Scan(&taskIncome)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "Get task income detail failed."}
- }
- if taskIncome != nil {
- withdrawStatus = taskIncome.WithdrawStatus + 1
- }
- taskDetail := &youngee_talent_model.TaskDetail{}
- if projectDetail.ProjectType == 1 {
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.Model("recruit_strategy").Where("project_id = ? and strategy_id = ?", task.ProjectId, task.StrategyId).Scan(&strategy)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "data query failed"}
- }
- taskDetail = &youngee_talent_model.TaskDetail{
- TaskInfo: task,
- ProjectDetail: projectDetail,
- ProductPhoto: productPhoto,
- Strategy: strategy,
- WithdrawStatus: withdrawStatus,
- }
- } else {
- taskDetail = &youngee_talent_model.TaskDetail{
- TaskInfo: task,
- ProjectDetail: projectDetail,
- ProductPhoto: productPhoto,
- WithdrawStatus: withdrawStatus,
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
- }
- // 匹配种草策略,含是否可选属性
- func GetProjRecruitList(r *ghttp.Request) *TalentHttpResult {
- fanNum := r.GetQueryInt("fan_num", -1)
- projectId := r.GetQueryString("project_id", -1)
- SProjectId := r.GetQueryInt("s_project_id", 0)
- var recruitStrategies []*youngee_talent_model.RecruitStrategy
- //不经过服务商
- if SProjectId == 0 {
- err := g.DB().Model("recruit_strategy").Where("project_id = ? and strategy_type=?", projectId, 1).Scan(&recruitStrategies)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else { //经过服务商
- _ = g.DB().Model("recruit_strategy").Where("s_project_id = ?", SProjectId).Scan(&recruitStrategies)
- }
- for _, strategy := range recruitStrategies {
- // 判断粉丝数是否满足当前策略的要求
- if fanNum >= strategy.FollowersLow {
- // 如果粉丝数满足策略的范围,设置 is_fit 为 1
- strategy.IsFit = 1
- } else {
- // 否则设置 is_fit 为 0
- strategy.IsFit = 0
- }
- }
- //根据projectId获取招募策略表多条策略,
- return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
- }
- // 匹配种草策略,含是否可选属性
- //func GetLocalRecruitList(r *ghttp.Request) *TalentHttpResult {
- // fanNum := r.GetQueryInt("fan_num", -1)
- // projectId := r.GetQueryString("project_id", -1)
- // SProjectId := r.GetQueryInt("s_project_id", 0)
- // var recruitStrategies []*youngee_talent_model.RecruitStrategy
- // //不经过服务商
- // if SProjectId == 0 {
- // err := g.DB().Model("recruit_strategy").Where("project_id = ? and strategy_type=?", projectId, 1).Scan(&recruitStrategies)
- // if err != nil {
- // fmt.Println(err.Error())
- // }
- // } else { //经过服务商
- // _ = g.DB().Model("recruit_strategy").Where("s_project_id = ?", SProjectId).Scan(&recruitStrategies)
- // }
- // for _, strategy := range recruitStrategies {
- // // 判断粉丝数是否满足当前策略的要求
- // if fanNum >= strategy.FollowersLow {
- // // 如果粉丝数满足策略的范围,设置 is_fit 为 1
- // strategy.IsFit = 1
- // } else {
- // // 否则设置 is_fit 为 0
- // strategy.IsFit = 0
- // }
- // }
- //
- // //根据projectId获取招募策略表多条策略,
- // return &TalentHttpResult{Code: 0, Msg: "success", Data: recruitStrategies}
- //}
- // 报名种草任务
- func SignUpTaskWithKsAccount(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- //POST请求体信息
- var signTaskInfo *youngee_talent_model.SignTaskInfo
- err = r.ParseForm(&signTaskInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- }
- //种草详情信息
- var projectDetail *youngee_talent_model.ProjectDetail
- err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //达人用户信息
- var talentInfo *youngee_talent_model.TalentInfo
- err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
- }
- //达人快手信息
- var accountInfo *youngee_talent_model.KuaishouUserInfo
- err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, 8).Scan(&accountInfo)
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: err.Error()}
- }
- //var accountInfo *youngee_talent_model.PlatformAccountInfo
- //err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
- //if err != nil {
- // return &TalentHttpResult{Code: -5, Msg: err.Error()}
- //}
- //project_form=1寄拍需要填写地址
- var address *model.YoungeeTalentDeliveryAddress
- if projectDetail.ProjectForm == 1 {
- err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: err.Error()}
- }
- } else {
- address = new(model.YoungeeTalentDeliveryAddress) //赋空值
- }
- var newTaskId string
- // 首先生成任务id
- newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
- //// 生成达人平台账号信息快照
- accountSnap, err := gjson.Encode(accountInfo)
- //if err != nil {
- // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
- //}
- // 生成达人信息快照
- talentSnap, err := gjson.Encode(talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
- }
- // 生成收货地址快照
- addrSnap, err := gjson.Encode(address)
- if err != nil {
- return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
- }
- taskInfo := youngee_talent_model.YoungeeTaskInfo{}
- // 公开任务
- if projectDetail.ProjectType == 1 {
- //经过服务商
- if signTaskInfo.SProjectId != 0 {
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- var ServiceChargePrice = 0.0 //服务费
- var SupporPricer = 0.0 //提报价
- if signTaskInfo.StrategyId == 3 { //自报价
- ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if signTaskInfo.StrategyId == 2 { //一口价
- ServiceChargePrice = strategy.ServiceCharge
- SupporPricer = signTaskInfo.Offer
- } else { //无费置换
- ServiceChargePrice = 0.0
- SupporPricer = 0.0
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- SProjectId: signTaskInfo.SProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
- ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
- SupportFee: SupporPricer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- SupplierStatus: 1,
- WxNum: signTaskInfo.WxNum,
- }
- } else {
- //不经过服务商
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: 0, //不经过服务商则为0
- ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
- SupportFee: signTaskInfo.Offer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- WxNum: signTaskInfo.WxNum,
- }
- }
- } else if projectDetail.ProjectType == 2 { //定向任务
- //经过服务商
- if signTaskInfo.SProjectId != 0 {
- //查找服务商定义的策略
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- ServiceCharge: 0, //不经过服务商,无服务费
- ServiceRate: 0, //服务费率
- SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- }
- } else {
- //不经过服务商
- }
- //定向任务,服务费在哪设置
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- }
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // 在task_info表中插入任务
- _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
- if err != nil {
- return err
- }
- // 对应项目的报名人数自增
- _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
- if err != nil {
- return err
- }
- //如果经过服务商,服务younggee_s_project_info中报名人数加一
- if signTaskInfo.SProjectId != 0 {
- _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
- if err != nil {
- return err
- }
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
- }
- func SignUpTaskWithAccount(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- //POST请求体信息
- var signTaskInfo *youngee_talent_model.SignTaskInfo
- err = r.ParseForm(&signTaskInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- }
- //种草详情信息
- var projectDetail *youngee_talent_model.ProjectDetail
- err = g.DB().Model(youngee_talent_model.ProjectDetail{}).WithAll().Where("project_id", signTaskInfo.ProjectId).Scan(&projectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //达人用户信息
- var talentInfo *youngee_talent_model.TalentInfo
- err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
- }
- //达人社媒信息
- var platform_id = projectDetail.ProjectPlatform
- var accountInfo *youngee_talent_model.KuaishouUserInfo
- err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, platform_id).Scan(&accountInfo)
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: err.Error()}
- }
- //var accountInfo *youngee_talent_model.PlatformAccountInfo
- //err = g.DB().Model("youngee_platform_account_info").WithAll().Where("talent_id = ? and platform_id = ?", tid, projectDetail.ProjectPlatform).Scan(&accountInfo)
- //if err != nil {
- // return &TalentHttpResult{Code: -5, Msg: err.Error()}
- //}
- //project_form=1寄拍需要填写地址
- var address *model.YoungeeTalentDeliveryAddress
- if projectDetail.ProjectForm == 1 {
- err := g.DB().Model(dao.YoungeeTalentDeliveryAddress.Table).Where("talent_id = ? and address_id = ?", tid, signTaskInfo.AddressId).Scan(&address)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: err.Error()}
- }
- } else {
- address = new(model.YoungeeTalentDeliveryAddress) //赋空值
- }
- var newTaskId string
- // 首先生成任务id
- newTaskId = utils.GetUuid.GetTaskId(projectDetail.ProjectId, projectDetail.EnterpriseId, tid)
- //// 生成达人平台账号信息快照
- accountSnap, err := gjson.Encode(accountInfo)
- //if err != nil {
- // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
- //}
- // 生成达人信息快照
- talentSnap, err := gjson.Encode(talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
- }
- // 生成收货地址快照
- addrSnap, err := gjson.Encode(address)
- if err != nil {
- return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
- }
- taskInfo := youngee_talent_model.YoungeeTaskInfo{}
- // 公开任务
- if projectDetail.ProjectType == 1 {
- //经过服务商
- if signTaskInfo.SProjectId != 0 {
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- var ServiceChargePrice = 0.0 //服务费
- var SupporPricer = 0.0 //提报价
- if signTaskInfo.StrategyId == 3 { //自报价
- ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if signTaskInfo.StrategyId == 2 { //一口价
- ServiceChargePrice = strategy.ServiceCharge
- SupporPricer = signTaskInfo.Offer
- } else { //无费置换
- ServiceChargePrice = 0.0
- SupporPricer = 0.0
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- SProjectId: signTaskInfo.SProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
- ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
- SupportFee: SupporPricer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- SupplierStatus: 1,
- WxNum: signTaskInfo.WxNum,
- TalentName: talentInfo.TalentNickname,
- PlatformId: platform_id,
- }
- } else {
- //不经过服务商
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- var ServiceChargePrice = 0.0 //服务费
- var SupporPricer = 0.0 //提报价
- if strategy.FeeForm == 3 { //自报价
- ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if strategy.FeeForm == 2 { //一口价
- ServiceChargePrice = strategy.ServiceCharge
- SupporPricer = signTaskInfo.Offer
- } else if strategy.FeeForm == 1 { //无费置换
- ServiceChargePrice = 0.0
- SupporPricer = 0.0
- } else {
- return &TalentHttpResult{Code: -10, Msg: "策略设置错误"}
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: ServiceChargePrice,
- ServiceRate: projectDetail.ServiceChargeRate,
- SupportFee: SupporPricer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- WxNum: signTaskInfo.WxNum,
- TalentName: talentInfo.TalentNickname,
- PlatformId: platform_id,
- }
- }
- } else if projectDetail.ProjectType == 2 { //定向任务
- //经过服务商
- if signTaskInfo.SProjectId != 0 {
- ////查找服务商定义的策略
- //var strategy *youngee_talent_model.RecruitStrategy
- //err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- var ServiceChargePrice = 0.0 //服务费
- var SupporPricer = 0.0 //提报价
- if signTaskInfo.StrategyId == 3 { //自报价
- ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if signTaskInfo.StrategyId == 2 { //一口价
- ServiceChargePrice = strategy.ServiceCharge
- SupporPricer = signTaskInfo.Offer
- } else { //无费置换
- ServiceChargePrice = 0.0
- SupporPricer = 0.0
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- ServiceCharge: ServiceChargePrice, //经过服务商,有服务费
- ServiceRate: strategy.ServiceRate, //服务费率
- SupportFee: SupporPricer, //经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- PlatformId: platform_id,
- }
- } else {
- //不经过服务商
- ////查找服务商定义的策略
- //var strategy *youngee_talent_model.RecruitStrategy
- //err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SProjectId).Scan(&strategy)
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.ProjectId).Scan(&strategy)
- var SupporPricer = 0.0 //提报价
- if signTaskInfo.StrategyId == 3 { //自报价
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if signTaskInfo.StrategyId == 2 { //一口价
- SupporPricer = signTaskInfo.Offer
- } else { //无费置换
- SupporPricer = 0.0
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- ServiceCharge: 0, //不经过服务商,无服务费
- ServiceRate: strategy.ServiceRate, //服务费率
- SupportFee: SupporPricer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- PlatformId: platform_id,
- }
- }
- //定向任务,服务费在哪设置
- taskInfo = youngee_talent_model.YoungeeTaskInfo{
- TaskId: newTaskId,
- ProjectId: signTaskInfo.ProjectId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- }
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // 在task_info表中插入任务
- _, err = tx.Ctx(ctx).Model(dao.YoungeeTaskInfo.Table).Data(&taskInfo).Insert()
- if err != nil {
- return err
- }
- // 对应项目的报名人数自增
- _, err = tx.Ctx(ctx).Model(dao.ProjectInfo.Table).Where(dao.ProjectInfo.Columns.ProjectId, projectDetail.ProjectId).Increment(dao.ProjectInfo.Columns.ApplyNum, 1)
- if err != nil {
- return err
- }
- //如果经过服务商,服务younggee_s_project_info中报名人数加一
- if signTaskInfo.SProjectId != 0 {
- _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SProjectId).Increment("apply_num", 1)
- if err != nil {
- return err
- }
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
- }
- // 本地生活报名
- func SignUpLocalWithKsAccount(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- //POST请求体信息
- var signTaskInfo *youngee_talent_model.SignLocalTaskInfo
- err = r.ParseForm(&signTaskInfo)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- }
- var projectDetail *youngee_talent_model.LocalInfoDetail
- err = g.DB().Model(youngee_talent_model.LocalInfoDetail{}).WithAll().Where("local_id", signTaskInfo.LocalId).Scan(&projectDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //达人用户信息
- var talentInfo *youngee_talent_model.TalentInfo
- err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: "Get talent info failed"}
- }
- //达人快手信息
- var accountInfo *youngee_talent_model.KuaishouUserInfo
- err = g.DB().Model("platform_kuaishou_user_info").WithAll().Where("talent_id = ? AND open_id = ? AND platform_id = ? ", tid, signTaskInfo.OpenID, projectDetail.LocalPlatform).Scan(&accountInfo)
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: err.Error()}
- }
- var newTaskId string
- // 首先生成任务id
- newTaskId = utils.GetUuid.GetTaskId(projectDetail.LocalId, projectDetail.EnterpriseId, tid)
- //// 生成达人平台账号信息快照
- accountSnap, err := gjson.Encode(accountInfo)
- //if err != nil {
- // return &TalentHttpResult{Code: -7, Msg: "encode platform snap failed"}
- //}
- // 生成达人信息快照
- talentSnap, err := gjson.Encode(talentInfo)
- if err != nil {
- return &TalentHttpResult{Code: -8, Msg: "encode talent info snap failed"}
- }
- if err != nil {
- return &TalentHttpResult{Code: -9, Msg: "encode delivery address snap failed"}
- }
- taskInfo := youngee_talent_model.YoungeeLocalTaskInfo{}
- // 公开任务
- if projectDetail.LocalType == 1 {
- //经过服务商
- if signTaskInfo.SLocalId != 0 {
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
- var ServiceChargePrice = 0.0 //服务费
- var SupporPricer = 0.0 //提报价
- if strategy.FeeForm == 3 { //自报价
- ServiceChargePrice = signTaskInfo.Offer * strategy.ServiceRate * 0.01
- SupporPricer = signTaskInfo.Offer * (1 + strategy.ServiceRate*0.01)
- } else if strategy.FeeForm == 2 { //一口价
- ServiceChargePrice = strategy.ServiceCharge
- SupporPricer = signTaskInfo.Offer
- } else if strategy.FeeForm == 1 { //无费置换
- ServiceChargePrice = 0.0
- SupporPricer = 0.0
- }
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
- TaskId: newTaskId,
- PlatformId: projectDetail.LocalPlatform,
- SProjectId: signTaskInfo.SLocalId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: ServiceChargePrice, //服务费(自报价要计算,一口价直接从strategy中取得,无非置换为0)
- ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率,projectinfo和recruit 表中是一样的
- SupportFee: SupporPricer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- //ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- SupplierStatus: 1,
- WxNum: signTaskInfo.WxNum,
- }
- } else {
- //不经过服务商
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and project_id= ?", signTaskInfo.StrategyId, signTaskInfo.LocalId).Scan(&strategy)
- if err != nil {
- return &TalentHttpResult{Code: -10, Msg: err.Error()}
- }
- taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
- TaskId: newTaskId,
- LocalId: signTaskInfo.LocalId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- StrategyId: signTaskInfo.StrategyId,
- TaskStage: 1,
- FeeForm: strategy.FeeForm,
- ServiceCharge: 0, //不经过服务商则为0
- ServiceRate: projectDetail.ServiceChargeRate, //公开服务费率
- SupportFee: signTaskInfo.Offer,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- //ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- SettleStatus: 1,
- DraftFee: signTaskInfo.Offer, //商家或者服务商可以看到的稿费价格,无非置换为空,一口价为策略表中的t_offer,自报价是达人添加的也是t_offer,
- SettleAmount: signTaskInfo.Offer,
- WxNum: signTaskInfo.WxNum,
- }
- }
- } else if projectDetail.LocalType == 2 { //定向任务
- //经过服务商
- if signTaskInfo.SLocalId != 0 {
- //查找服务商定义的策略
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_local_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
- taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
- TaskId: newTaskId,
- LocalId: signTaskInfo.LocalId,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- //ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- ServiceCharge: 0, //不经过服务商,无服务费
- ServiceRate: 0, //服务费率
- SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- }
- } else {
- //不经过服务商
- //查找服务商定义的策略
- var strategy *youngee_talent_model.RecruitStrategy
- err = g.DB().Model("recruit_strategy").WithAll().Where("strategy_id = ? and s_project_id= ?", signTaskInfo.StrategyId, signTaskInfo.SLocalId).Scan(&strategy)
- taskInfo = youngee_talent_model.YoungeeLocalTaskInfo{
- TaskId: newTaskId,
- LocalId: signTaskInfo.LocalId,
- PlatformId: projectDetail.LocalPlatform,
- TalentId: tid,
- OpenId: signTaskInfo.OpenID,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TaskStage: 1,
- CreateDate: gtime.Now(),
- TaskStatus: 1,
- LogisticsStatus: 1,
- LinkStatus: 1,
- DataStatus: 1,
- //ScriptStatus: 1,
- SketchStatus: 1,
- CompleteStatus: 1,
- CurDefaultType: 0,
- WithdrawStatus: 1,
- ServiceCharge: 0, //不经过服务商,无服务费
- ServiceRate: 0, //服务费率
- SupportFee: signTaskInfo.Offer, //不经过服务商, 提报价格=一口价*(1+服务费率)
- DraftFee: signTaskInfo.Offer, //稿费价格,一口价
- WxNum: signTaskInfo.WxNum,
- }
- }
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // 在task_info表中插入任务
- _, err = tx.Ctx(ctx).Model("youngee_local_task_info").Data(&taskInfo).Insert()
- if err != nil {
- return err
- }
- // 对应项目的报名人数自增
- _, err = tx.Ctx(ctx).Model("younggee_local_life_info").Where("local_id=?", projectDetail.LocalId).Increment("apply_num", 1)
- if err != nil {
- return err
- }
- //如果经过服务商,服务younggee_s_project_info中报名人数加一
- if signTaskInfo.SLocalId != 0 {
- _, err = tx.Ctx(ctx).Model("younggee_s_project_info").Where("s_project_id = ? ", signTaskInfo.SLocalId).Increment("apply_num", 1)
- if err != nil {
- return err
- }
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: err.Error()}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: newTaskId}
- }
|