123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- package youngee_talent_service
- import (
- "strconv"
- "youngmini_server/app/dao"
- "youngmini_server/app/model"
- "youngmini_server/app/model/youngee_talent_model"
- "youngmini_server/app/utils"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- )
- func GetTalentIncomeInfo(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- }
- var getTalentIncomeReq *youngee_talent_model.GetTalentIncomeReq
- err = r.ParseForm(&getTalentIncomeReq)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: "params error"}
- }
- var TalentIncomeInfoRes youngee_talent_model.TalentIncomeInfoAll
- g.DB().Model("youngee_talent_info").Where("id=?", tid).Scan(&TalentIncomeInfoRes.TalentInfo)
- var talentIncomeList []*youngee_talent_model.TalentIncomeInfo
- err = g.DB().Model("younggee_talent_income").Where("talent_id = ? and withdraw_status = ?", tid, getTalentIncomeReq.Type).Scan(&talentIncomeList)
- platformMap := make(map[string]model.InfoThirdPlatform)
- platformInfo := []*model.InfoThirdPlatform{}
- if len(talentIncomeList) != 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]
- }
- }
- for _, v := range talentIncomeList {
- var platform model.InfoThirdPlatform
- switch v.Type {
- case 1:
- projectPlatform, err := g.Model(dao.ProjectInfo.Table).Fields("project_platform").Where("project_id = ?", v.ProjectId).Value()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- }
- platform = platformMap[projectPlatform.String()]
- talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
- Id: v.Id,
- ProjectId: v.ProjectId,
- TaskId: v.TaskId,
- Type: v.Type,
- BrandName: v.BrandName,
- TaskName: v.TaskName,
- PhotoUrl: v.PhotoUrl,
- TeamId: v.TeamId,
- Income: v.Income,
- IncomeType: v.IncomeType,
- WithdrawStatus: v.WithdrawStatus,
- IncomeAt: v.IncomeAt,
- WithdrawAt: v.WithdrawAt,
- PlatformIconUrl: platform.PlatformIcon,
- }
- TalentIncomeInfoRes.TalentIncomeInfos = append(TalentIncomeInfoRes.TalentIncomeInfos, &talentIncomeInfo)
- break
- case 2:
- platformId, err := g.Model(dao.YounggeeSelectionInfo.Table).Fields("platform").Where("selection_id = ?", v.SelectionId).Value()
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- }
- platform = platformMap[platformId.String()]
- talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
- Id: v.Id,
- ProjectId: v.SelectionId,
- TaskId: v.SectaskId,
- Type: v.Type,
- BrandName: v.BrandName,
- TaskName: v.TaskName,
- PhotoUrl: v.PhotoUrl,
- TeamId: v.TeamId,
- Income: v.Income,
- IncomeType: v.IncomeType,
- WithdrawStatus: v.WithdrawStatus,
- IncomeAt: v.IncomeAt,
- WithdrawAt: v.WithdrawAt,
- PlatformIconUrl: platform.PlatformIcon,
- }
- TalentIncomeInfoRes.TalentIncomeInfos = append(TalentIncomeInfoRes.TalentIncomeInfos, &talentIncomeInfo)
- break
- default:
- }
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: TalentIncomeInfoRes}
- }
- //func GetTalentIncomeInfo(r *ghttp.Request) *TalentHttpResult {
- // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
- // }
- //
- // var getTalentIncomeReq *youngee_talent_model.GetTalentIncomeReq
- // err = r.ParseForm(&getTalentIncomeReq)
- // if err != nil {
- // return &TalentHttpResult{Code: -2, Msg: "params error"}
- // }
- //
- // var talentIncomerep []youngee_talent_model.TalentIncomeInfo
- // var talentIncomeList []*model.YounggeeTalentIncome
- // fmt.Println("222", getTalentIncomeReq.Type)
- // err = g.DB().Model(dao.YounggeeTalentIncome.Table).Where("talent_id = ? and withdraw_status = ?", tid, 2).Scan(&talentIncomeList)
- // if err != nil {
- // return &TalentHttpResult{Code: -3, Msg: err.Error()}
- // }
- //
- // platformMap := make(map[string]model.InfoThirdPlatform)
- // platformInfo := []*model.InfoThirdPlatform{}
- // if len(talentIncomeList) != 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]
- // }
- // }
- //
- // for _, v := range talentIncomeList {
- // var platform model.InfoThirdPlatform
- // switch v.Type {
- // case 1:
- // projectPlatform, err := g.Model(dao.ProjectInfo.Table).Fields("project_platform").Where("project_id = ?", v.ProjectId).Value()
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- // }
- // platform = platformMap[projectPlatform.String()]
- //
- // talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
- // Id: v.Id,
- // ProjectId: v.ProjectId,
- // TaskId: v.TaskId,
- // Type: v.Type,
- // BrandName: v.BrandName,
- // TaskName: v.TaskName,
- // PhotoUrl: v.PhotoUrl,
- // TeamId: v.TeamId,
- // Income: v.Income,
- // IncomeType: v.IncomeType,
- // WithdrawStatus: v.WithdrawStatus,
- // IncomeAt: v.IncomeAt,
- // WithdrawAt: v.WithdrawAt,
- // PlatformIconUrl: platform.PlatformIcon,
- // }
- //
- // talentIncomerep = append(talentIncomerep, talentIncomeInfo)
- // break
- // case 2:
- // platformId, err := g.Model(dao.YounggeeSelectionInfo.Table).Fields("platform").Where("selection_id = ?", v.SelectionId).Value()
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
- // }
- // platform = platformMap[platformId.String()]
- //
- // talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
- // Id: v.Id,
- // ProjectId: v.SelectionId,
- // TaskId: v.SectaskId,
- // Type: v.Type,
- // BrandName: v.BrandName,
- // TaskName: v.TaskName,
- // PhotoUrl: v.PhotoUrl,
- // TeamId: v.TeamId,
- // Income: v.Income,
- // IncomeType: v.IncomeType,
- // WithdrawStatus: v.WithdrawStatus,
- // IncomeAt: v.IncomeAt,
- // WithdrawAt: v.WithdrawAt,
- // PlatformIconUrl: platform.PlatformIcon,
- // }
- //
- // talentIncomerep = append(talentIncomerep, talentIncomeInfo)
- // break
- // default:
- // }
- //
- // }
- //
- // return &TalentHttpResult{Code: 0, Msg: "success", Data: talentIncomerep}
- //}
- // 提现
- //func Withdraw(r *ghttp.Request) *TalentHttpResult {
- // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- // if err != nil {
- // return &TalentHttpResult{Code: -1, Msg: err.Error()}
- // }
- //
- // var DataInfoReq *youngee_talent_model.WithdrawInfo
- // err = r.ParseForm(&DataInfoReq)
- // if err != nil {
- // return &TalentHttpResult{Code: -2, Msg: err.Error()}
- // }
- // incomeIdStrList := strings.Split(DataInfoReq.IncomeIdList, ",")
- // incomeIdList := utils.TypeTran.String2Int(incomeIdStrList)
- //
- // // 检验是否均处于可提现状态,且达人id是否对应
- // var incomeList []model.YounggeeTalentIncome
- // err = g.Model(dao.YounggeeTalentIncome.Table).Where("talent_id = ? and withdraw_status = 1", tid).And("id IN (?)", incomeIdList).Scan(&incomeList)
- // if err != nil {
- // return &TalentHttpResult{Code: -4, Msg: err.Error()}
- // }
- // if len(incomeIdList) != len(incomeList) {
- // return &TalentHttpResult{Code: -3, Msg: "Req IncomeIdList Error"}
- // }
- //
- // //// 检查达人积分是否足够
- // //totalPoint, err := g.Model(dao.YoungeeTalentInfo.Table).Fields("point").Where("id = ?", tid).Value()
- // //if err != nil {
- // // return &TalentHttpResult{Code: -5, Msg: err.Error()}
- // //}
- // //if totalPoint.Int() < DataInfoReq.Point {
- // // return &TalentHttpResult{Code: -3, Msg: "Req Point Error"}
- // //}
- //
- // // 查询达人提现到账账户信息
- // var talentBank model.YounggeeTalentBank
- // err = g.Model(dao.YounggeeTalentBank.Table).Where("talent_id = ?", tid).Scan(&talentBank)
- // if err != nil {
- // return &TalentHttpResult{Code: -6, Msg: err.Error()}
- // }
- // bankJsons, errs := json.Marshal(talentBank) //转换成JSON返回的是byte[]
- // if errs != nil {
- // return &TalentHttpResult{Code: -7, Msg: err.Error()}
- // }
- //
- // err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- // s1 := tid[7:]
- // s2 := fmt.Sprintf("%d", gtime.Now().YearDay())
- // s3 := fmt.Sprintf("%02v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(100))
- // s := "6" + s1 + s2 + s3
- // // 插入提现记录
- // _, err1 := tx.Ctx(ctx).Model(dao.YounggeeWithdrawRecord.Table).Data(model.YounggeeWithdrawRecord{
- // WithdrawId: s,
- // TalentId: tid,
- // WithdrawAmount: float64(DataInfoReq.TotalAmount),
- // AmountPayable: float64(DataInfoReq.RealAmount),
- //
- // IncomeIdList: DataInfoReq.IncomeIdList,
- // //PayPoint: DataInfoReq.Point,
- // ReceiveInfo: string(bankJsons),
- // BankType: 2,
- // Status: 1,
- // SubmitAt: gtime.Now(),
- // }).InsertAndGetId()
- // if err1 != nil {
- // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
- // return err1
- // }
- //
- // // 更新income表中提现状态
- // _, err1 = tx.Ctx(ctx).Model(dao.YounggeeTalentIncome.Table).Where("id IN (?)", incomeIdList).Update(g.Map{"withdraw_status": 2, "withdraw_at": gtime.Now()})
- // if err1 != nil {
- // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
- // return err1
- // }
- //
- // // 更新talent表中提现金额
- // _, err1 = tx.Ctx(ctx).Model(dao.YoungeeTalentInfo.Table).Where("id = ?", tid).Increment("withdrawing", float64(DataInfoReq.TotalAmount))
- // if err1 != nil {
- // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
- // return err1
- // }
- // _, err1 = tx.Ctx(ctx).Model(dao.YoungeeTalentInfo.Table).Where("id = ?", tid).Decrement("canwithdraw", float64(DataInfoReq.TotalAmount))
- // if err1 != nil {
- // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
- // return err1
- // }
- //
- // // 达人消息
- // for _, incomeInfo := range incomeList {
- // messageTypeId := [4]int{25, 26, 27, 28}
- // messageInfo := model.YounggeeMessageInfo{
- // MessageId: messageTypeId[incomeInfo.IncomeType-1],
- // MessageType: 2,
- // CreatedAt: gtime.Now(),
- // ProjectName: incomeInfo.TaskName,
- // IsReaded: 0,
- // IsDeleted: 0,
- // }
- // _, err = tx.Ctx(ctx).Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
- // if err != nil {
- // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err)
- // return err
- // }
- // }
- // return nil
- // })
- // if err != nil {
- // return &TalentHttpResult{Code: -8, Msg: "Add Withdraw Record failed: " + err.Error()}
- // }
- //
- // return &TalentHttpResult{Code: 0, Msg: "success"}
- //}
- // 查询积分明细
- func GetTalentPointInfo(r *ghttp.Request) *TalentHttpResult {
- tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: err.Error()}
- }
- var talentPointList []*model.YounggeeTalentPointRecord
- err = g.DB().Model(dao.YounggeeTalentPointRecord.Table).Where("talent_id = ?", tid).Order("income_at").Scan(talentPointList)
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: err.Error()}
- }
- point, err := g.DB().Model(dao.YoungeeTalentInfo.Table).Fields("point").Where("talent_id = ?", tid).Value()
- if err != nil {
- return &TalentHttpResult{Code: -2, Msg: err.Error()}
- }
- TalentPointInfo := youngee_talent_model.TalentPointInfo{
- Point: point.Int(),
- TalentPointRecord: talentPointList,
- }
- return &TalentHttpResult{Code: 0, Msg: "success", Data: TalentPointInfo}
- }
|