123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- package youngee_sectask_service
- import (
- "context"
- "encoding/json"
- "fmt"
- "github.com/gogf/gf/database/gdb"
- "reflect"
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- "youngmini_server/app/utils"
- "github.com/gogf/gf/encoding/gjson"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/gtime"
- )
- const (
- selectionStatusCreating = iota + 1
- selectionStatusReviewing
- selectionStatusReviewed
- selectionStatusPaying
- selectionStatusPaid
- selectionStatusInProgress
- selectionStatusInvalid
- selectionStatusClosed
- )
- // 获取项目信息列表service
- func GetSelectionList(r *ghttp.Request) *TalentHttpResult {
- pageIndex := r.GetQueryInt("idx", -1)
- cntPerPage := r.GetQueryInt("cnt", -1)
- //platform := r.Get("platform")
- secForm := r.Get("secform")
- taskForm := r.Get("taskform")
- categoryForm := r.Get("categoryform")
- searchValue := r.Get("searchvalue")
- if pageIndex == -1 || cntPerPage == -1 || cntPerPage == 0 {
- return &TalentHttpResult{Code: -1, Msg: "参数错误"}
- }
- // 如果有领样形式的过滤条件,则将过滤条件保存于secFormList
- var secFormList []interface{}
- if secForm != nil {
- if reflect.TypeOf(secForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件领样形式错误"}
- }
- secFormList = make([]interface{}, 0)
- secFormList = secForm.([]interface{})
- }
- // 如果有任务形式的过滤条件,则将过滤条件保存于taskFormList
- var taskFormList []interface{}
- if taskForm != nil {
- if reflect.TypeOf(taskForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- taskFormList = make([]interface{}, 0)
- taskFormList = taskForm.([]interface{})
- }
- // 如果有商品类目的过滤条件,则将过滤条件保存于categoryFormList
- var categoryFormList []interface{}
- if categoryForm != nil {
- if reflect.TypeOf(categoryForm).Kind() != reflect.Slice {
- return &TalentHttpResult{Code: -2, Msg: "搜索条件任务形式错误"}
- }
- categoryFormList = make([]interface{}, 0)
- categoryFormList = categoryForm.([]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("(selection_status >= %d)", selectionStatusInProgress)
- /* if platformList != nil {
- whereStr = whereStr + " and platform in ("
- for _, v := range platformList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }*/
- if taskFormList != nil {
- whereStr += " and task_mode in ("
- for _, v := range taskFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- if secFormList != nil {
- whereStr += " and sample_mode in ("
- for _, v := range secFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- if categoryFormList != nil {
- whereStr += " and product_category in ("
- for _, v := range categoryFormList {
- whereStr += v.(string) + ", "
- }
- whereStr = whereStr[0 : len(whereStr)-2]
- whereStr += ")"
- }
- //搜索栏
- if searchValue != nil {
- whereStr += " and selection_name like '%" + searchValue.(string) + "%'"
- }
- // 查询所有selection
- //YounggeeSelectionInfo含有表中的所有属性
- var selectionList = []model.YounggeeSelectionInfo{}
- //err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Scan(&selectionList)
- //展示带货商品的排序规则 预估赚、ddl未处理
- err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Order("commission_rate DESC , task_reward DESC ").Scan(&selectionList)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "查询数据库失败"}
- }
- fmt.Println("****searchValue:", searchValue)
- fmt.Println("****secFormList:", secFormList)
- fmt.Println("****taskFormList:", taskFormList)
- fmt.Println("****whereStr: ", whereStr)
- // 判断请求页面是否超过最大页面
- c, err := g.DB().Model(dao.YounggeeSelectionInfo.Table).Where(whereStr).Count()
- if err != nil {
- return &TalentHttpResult{Code: -4, Msg: err.Error(), Data: nil}
- }
- maxPage := c / cntPerPage
- if c%cntPerPage > 0 {
- maxPage += 1
- }
- if pageIndex+1 > maxPage {
- return &TalentHttpResult{Code: -5, Msg: "over max page"}
- }
- var selectionInfoList = youngee_talent_model.SelectionInfoList{
- Count: c,
- }
- err = g.DB().Model(dao.YounggeeSelectionInfo.Table).WithAll().Where(whereStr).
- Order("selection_status ASC , task_ddl DESC , commission_rate DESC , task_reward DESC, selection_id").Limit(startId, cntPerPage).Scan(&selectionInfoList.SelectionDetail)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: "查询数据库失败"}
- }
- selectionInfoList.MaxPage = maxPage
- return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionInfoList}
- }
- // 获取单个选品详情service
- func GetSelectionDetail(r *ghttp.Request) *TalentHttpResult {
- sid := r.GetQueryString("selectionid", 0)
- pid := r.GetQueryString("productid", 0)
- if sid == "" {
- return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- }
- var selectionDetail *youngee_talent_model.SelectionDetail
- err := g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", sid).Scan(&selectionDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- // 查询younggee_product表数据
- var younggeeProduct []*youngee_talent_model.YounggeeProduct
- err = g.DB().Model(youngee_talent_model.YounggeeProduct{}).WithAll().Where("product_id", pid).Scan(&younggeeProduct)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //查询younggee_product_photo表数据
- var younggeeProductPhoto []*youngee_talent_model.YounggeeProductPhoto
- err = g.DB().Model(youngee_talent_model.YounggeeProductPhoto{}).WithAll().Where("product_id", pid).Scan(&younggeeProductPhoto)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //selectionDetail.FreeStrategy = freeStrategy
- //selectionDetail.RewardStrategy = rewardStrategy
- selectionDetail.YounggeeProduct = younggeeProduct
- selectionDetail.YounggeeProductPhoto = younggeeProductPhoto
- //selectionDetail.SelectionBrief = selectionBrief
- //selectionDetail.SelectionExample = selectionExample
- return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionDetail}
- }
- func GetProductDetail(r *ghttp.Request) *TalentHttpResult {
- pid := r.GetQueryString("productid", 0)
- if pid == "" {
- return &TalentHttpResult{Code: -2, Msg: "data query failed"}
- }
- var productDetail *youngee_talent_model.YounggeeProduct
- err := g.DB().Model(youngee_talent_model.YounggeeProduct{}).WithAll().Where("product_id", pid).Scan(&productDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: productDetail}
- }
- func GetProductPhoto(r *ghttp.Request) *TalentHttpResult {
- //访问表,获取图片
- return nil
- }
- // 判断是否已报名任务,如果是提供免费领样(按钮既然有肯定是免费领样),sectask中的sample_mode==3,或者没有数据。表示还没报名,只是添加橱窗了
- func IsSignUpSecTask(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- selectionId := r.GetQueryInt("selection_id", -1)
- //定义接口存该达人所有的报名任务
- //1.查task表全部数据
- var task []youngee_talent_model.SecTaskInfoDetail
- err = g.DB().Model(youngee_talent_model.SecTaskInfoDetail{}).WithAll().
- Where("talent_id = ? AND selection_id = ? ", tid, selectionId).
- Scan(&task)
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error(), Data: nil}
- }
- isSign := youngee_talent_model.IsSignSecTask{}
- //有数据且sample_mode==1说明报名了,否则没报名 &&左边为false就不执行了 free_stage!=0
- if len(task) != 0 && task[0].FreeStage != 0 {
- isSign.IsSign = 1
- isSign.SecTaskInfo = &task[0]
- } else {
- isSign.IsSign = 0
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
- }
- func IsCreateSecTask(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- selectionId := r.GetQueryInt("selection_id", -1)
- //定义接口存该达人所有的报名任务
- //1.查task表全部数据
- var task []youngee_talent_model.SecTaskInfoDetail
- err = g.DB().Model(youngee_talent_model.SecTaskInfoDetail{}).WithAll().
- Where("talent_id = ? AND selection_id = ? ", tid, selectionId).
- Scan(&task)
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error(), Data: nil}
- }
- isSign := youngee_talent_model.IsSignSecTask{}
- //添加橱窗时,有task了就不再创建
- if len(task) != 0 {
- isSign.IsSign = 1
- isSign.SecTaskInfo = &task[0]
- } else {
- isSign.IsSign = 0
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: isSign}
- }
- // 选品任务报名service
- func SignUpSecTask(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- // 解析前端传来的参数
- var signSecTaskReq *youngee_talent_model.SignSecTaskReq
- err = r.ParseForm(&signSecTaskReq)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- // 查得的selectionDetail包含product、photo、策略表等综合数据
- var selectionDetail *youngee_talent_model.SelectionDetail
- err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //获取选品表中的ddl
- var selectionInfo *model.YounggeeSelectionInfo
- err = g.DB().Model("younggee_selection_info").Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionInfo)
- var product model.YounggeeProduct
- err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
- }
- // 查询达人详情
- 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, selectionDetail.Platform).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, signSecTaskReq.AddressId)
- if err != nil {
- return &TalentHttpResult{Code: -6, Msg: err.Error()}
- }
- var newTaskId string
- // 首先生成任务id
- newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.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"}
- }
- secTaskInfo := youngee_talent_model.SecTaskInfoDetail{
- TaskId: newTaskId,
- SelectionId: signSecTaskReq.SelectionId,
- ProductId: signSecTaskReq.ProductId,
- SaleNum: signSecTaskReq.SaleNum,
- FansNum: signSecTaskReq.FansNum,
- TalentId: tid,
- AccountId: accountInfo.AccountId,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- TalentPostAddrSnap: string(addrSnap),
- TaskReward: selectionDetail.TaskReward,
- TalentPayment: product.ProductPrice,
- IsPayPayment: 0,
- IsPayReward: 0,
- TaskMode: selectionDetail.TaskMode,
- SampleMode: selectionDetail.SampleMode,
- FreeStage: 1, //领样状态:已申请 悬赏状态默认为0
- PlatformId: 4, //快手平台
- TaskStage: 3,
- TaskStatus: 1,
- CreateDate: gtime.Now(),
- CompleteStatus: 1,
- LogisticsStatus: 1,
- AssignmentStatus: 1,
- UpdateAt: gtime.Now(),
- WithdrawStatus: 1,
- LeadTeamId: signSecTaskReq.LeadTeamId,
- TeamId: signSecTaskReq.TeamId,
- TeamIncome: 0,
- TeamPoint: 0,
- TaskDdl: selectionInfo.TaskDdl,
- }
- //删除添加橱窗时创建的不完整的数据
- _, err = g.DB().Model("younggee_sec_task_info").
- Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
- Delete()
- if err != nil {
- return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // young之团收益计算
- var rewardConfig *model.YounggeeTeamRewardConfig
- whereCondition := g.Map{
- dao.YounggeeTeamRewardConfig.Columns.ProjectType: 2,
- dao.YounggeeTeamRewardConfig.Columns.TaskForm: selectionDetail.TaskMode + 3,
- dao.YounggeeTeamRewardConfig.Columns.ContentForm: selectionDetail.ContentType,
- dao.YounggeeTeamRewardConfig.Columns.RewardReason: talentInfo.UserType,
- }
- err = tx.Model(dao.YounggeeTeamRewardConfig.Table).Where(whereCondition).Scan(&rewardConfig)
- if err != nil {
- fmt.Println(err)
- return err
- }
- if rewardConfig != nil {
- secTaskInfo.TeamPoint = rewardConfig.Point
- secTaskInfo.TeamIncome = rewardConfig.Money
- whereCondition = g.Map{
- dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.LeadTeamId,
- }
- whereCondition1 := g.Map{
- dao.YounggeeTalentTeam.Columns.TeamId: signSecTaskReq.TeamId,
- }
- updateData := g.Map{
- dao.YounggeeTalentTeam.Columns.PointIncome: gdb.Raw(fmt.Sprintf("%s + %d", dao.YounggeeTalentTeam.Columns.PointIncome, rewardConfig.Point)),
- dao.YounggeeTalentTeam.Columns.MoneyIncome: gdb.Raw(fmt.Sprintf("%s + %f", dao.YounggeeTalentTeam.Columns.MoneyIncome, float64(rewardConfig.Money)*secTaskInfo.TaskReward/100)),
- }
- _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition).Update()
- if err != nil {
- return err
- }
- _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Data(updateData).Where(whereCondition1).Update()
- if err != nil {
- return err
- }
- // young之团状态变更
- if signSecTaskReq.LeadTeamId != "" {
- // 更新young之团状态
- whereCondition2 := g.Map{
- dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
- }
- updateData = g.Map{
- dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
- }
- _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition).Where(whereCondition2).Data(updateData).Update()
- if err != nil {
- return err
- }
- }
- if signSecTaskReq.TeamId != "" {
- // 更新young之团状态
- whereCondition2 := g.Map{
- dao.YounggeeTalentTeam.Columns.TeamStatus: 1,
- }
- updateData = g.Map{
- dao.YounggeeTalentTeam.Columns.TeamStatus: 2,
- }
- _, err = tx.Ctx(ctx).Model(dao.YounggeeTalentTeam.Table).Where(whereCondition1).Where(whereCondition2).Data(updateData).Update()
- if err != nil {
- return err
- }
- }
- }
- if selectionDetail.SampleMode == 2 {
- // 减少选品库存
- whereCondition1 := g.Map{
- dao.YounggeeSelectionInfo.Columns.SelectionId: selectionDetail.SelectionId,
- }
- updateData := g.Map{
- dao.YounggeeSelectionInfo.Columns.RemainNum: gdb.Raw(fmt.Sprintf("%s - 1", dao.YounggeeSelectionInfo.Columns.RemainNum)),
- }
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Data(updateData).Update()
- if err != nil {
- return err
- }
- // 新建任务,初始化状态为待发货
- secTaskInfo.TaskStage = 6
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
- if err != nil {
- return err
- }
- } else {
- // 新建任务,初始化状态为待确认
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
- if err != nil {
- return err
- }
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- }
- signSecTaskResp := youngee_talent_model.SignSecTaskResp{
- TaskId: newTaskId,
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
- //return &TalentHttpResult{Code: 0, Msg: "success", Data: selectionDetail}
- }
- func SignUpSecTaskFromWindow(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- // 解析body/json参数
- var signSecTaskReq *youngee_talent_model.SignSecTaskReq
- err = r.ParseForm(&signSecTaskReq)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- // 查询选品详情
- var selectionDetail *youngee_talent_model.SelectionDetail
- err = g.DB().Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionDetail)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: err.Error()}
- }
- //获取选品表中的ddl
- var selectionInfo *model.YounggeeSelectionInfo
- err = g.DB().Model("younggee_selection_info").Where("selection_id", signSecTaskReq.SelectionId).Scan(&selectionInfo)
- var product model.YounggeeProduct
- err = json.Unmarshal([]byte(selectionDetail.ProductSnap), &product)
- if err != nil {
- return &TalentHttpResult{Code: -3, Msg: "json Unmarshal failed"}
- }
- // 查询达人详情
- 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, selectionDetail.Platform).Scan(&accountInfo)
- if err != nil {
- return &TalentHttpResult{Code: -5, Msg: err.Error()}
- }
- var newTaskId string
- // 首先生成任务id
- newTaskId = utils.GetUuid.GetTaskId(selectionDetail.SelectionId, selectionDetail.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"}
- }
- secTaskInfo := youngee_talent_model.SecTaskInfoWindowDetail{
- TaskId: newTaskId,
- SelectionId: signSecTaskReq.SelectionId,
- ProductId: signSecTaskReq.ProductId,
- SaleNum: signSecTaskReq.SaleNum,
- FansNum: signSecTaskReq.FansNum,
- TalentId: tid,
- AccountId: accountInfo.AccountId,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- //TalentPostAddrSnap: string(addrSnap),
- TaskReward: selectionInfo.TaskReward,
- TalentPayment: product.ProductPrice,
- IsPayPayment: 0,
- IsPayReward: 0,
- TaskMode: selectionInfo.TaskMode,
- SampleMode: 3, //添加橱窗,当作不提供领样处理
- PlatformId: 4, //快手平台
- TaskStage: 3,
- TaskStatus: 1,
- CreateDate: gtime.Now(),
- CompleteStatus: 1,
- LogisticsStatus: 1,
- AssignmentStatus: 1,
- UpdateAt: gtime.Now(),
- WithdrawStatus: 1,
- LeadTeamId: signSecTaskReq.LeadTeamId,
- TeamId: signSecTaskReq.TeamId,
- TeamIncome: 0,
- TeamPoint: 0,
- TaskDdl: selectionInfo.TaskDdl,
- }
- //如果已经有数据了,删除。模拟在快手侧里把橱窗商品删了,想再加回来
- //1.查task表全部数据
- var secTaskInfoList []youngee_talent_model.SecTaskInfoDetail
- err = g.DB().Model(youngee_talent_model.SecTaskInfoDetail{}).WithAll().
- Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
- Scan(&secTaskInfoList)
- if err != nil {
- return &TalentHttpResult{Code: 0, Msg: err.Error(), Data: nil}
- }
- //2.如果task不为空。取出free_stage的值。插入的值含有删除数据的free_stage
- if len(secTaskInfoList) != 0 {
- free_stage := secTaskInfoList[0].FreeStage
- //删除旧的,
- _, err = g.DB().Model("younggee_sec_task_info").
- Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
- Delete()
- if err != nil {
- return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
- }
- //插入新的(含free_stage)
- secTaskInfo_new := youngee_talent_model.SecTaskInfoWindowDetail{
- TaskId: newTaskId,
- SelectionId: signSecTaskReq.SelectionId,
- ProductId: signSecTaskReq.ProductId,
- SaleNum: signSecTaskReq.SaleNum,
- FansNum: signSecTaskReq.FansNum,
- TalentId: tid,
- AccountId: accountInfo.AccountId,
- TalentPlatformInfoSnap: string(accountSnap),
- TalentPersonalInfoSnap: string(talentSnap),
- //TalentPostAddrSnap: string(addrSnap),
- TaskReward: selectionInfo.TaskReward,
- TalentPayment: product.ProductPrice,
- IsPayPayment: 0,
- IsPayReward: 0,
- TaskMode: selectionInfo.TaskMode,
- SampleMode: 3, //添加橱窗,当作不提供领样处理
- PlatformId: 4, //快手平台
- TaskStage: 3,
- TaskStatus: 1,
- CreateDate: gtime.Now(),
- CompleteStatus: 1,
- LogisticsStatus: 1,
- AssignmentStatus: 1,
- UpdateAt: gtime.Now(),
- WithdrawStatus: 1,
- LeadTeamId: signSecTaskReq.LeadTeamId,
- TeamId: signSecTaskReq.TeamId,
- TeamIncome: 0,
- TeamPoint: 0,
- TaskDdl: selectionInfo.TaskDdl,
- FreeStage: free_stage,
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // 新建任务,初始化状态为待确认
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo_new).Insert()
- if err != nil {
- return err
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- }
- signSecTaskResp := youngee_talent_model.SignSecTaskResp{
- TaskId: newTaskId,
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
- } else {
- //3.如果已经报过名了需要传递给新的数据。删除添加橱窗时创建的不完整的数据
- _, err = g.DB().Model("younggee_sec_task_info").
- Where("talent_id = ? AND selection_id = ? ", tid, signSecTaskReq.SelectionId).
- Delete()
- if err != nil {
- return &TalentHttpResult{Code: -17, Msg: "younggee_sec_task_info delete failed"}
- }
- err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // 新建任务,初始化状态为待确认
- _, err = tx.Ctx(ctx).Model(dao.YounggeeSecTaskInfo.Table).Data(&secTaskInfo).Insert()
- if err != nil {
- return err
- }
- return nil
- })
- if err != nil {
- return &TalentHttpResult{Code: -18, Msg: "add Task data failed"}
- }
- signSecTaskResp := youngee_talent_model.SignSecTaskResp{
- TaskId: newTaskId,
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: signSecTaskResp}
- }
- }
|