talent_info.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package talent_service
  2. import (
  3. "github.com/gogf/gf/frame/g"
  4. "github.com/gogf/gf/net/ghttp"
  5. "youngmini_server/app/dao"
  6. "youngmini_server/app/model/talent_model"
  7. "youngmini_server/app/utils"
  8. )
  9. func OnGetTalentBriefInfo(r *ghttp.Request) *TalentHttpResult {
  10. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  11. if err != nil {
  12. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  13. }
  14. isComplete := false
  15. rec, err := g.DB().Model(dao.TalentInfo.Table).One("id", tid)
  16. test := rec[dao.TalentInfo.Columns.TalentWxNumber].Val()
  17. if err != nil || rec == nil || test == nil {
  18. isComplete = false
  19. } else {
  20. isComplete = true
  21. }
  22. platCnt, err := g.DB().Model(dao.RTalentPlatformTable.Table).
  23. Where("tid = ? and (examine_state = 1 or examine_state = 2)", tid).Count()
  24. if err != nil {
  25. platCnt = 0
  26. }
  27. boboCoin, err := g.DB().Model(dao.BobocoinIncomeRecord.Table).
  28. Where("talent_id", tid).
  29. Sum(dao.BobocoinIncomeRecord.Columns.BobocoinValue)
  30. if err != nil {
  31. boboCoin = 0
  32. }
  33. drawMoney, err := g.DB().Model(dao.BobocoinWithdrawalRecord.Table).
  34. Where("talent_id = ? and (pay_state = 1 or pay_state = 2)", tid).
  35. Sum(dao.BobocoinWithdrawalRecord.Columns.DrawAmount)
  36. if err != nil {
  37. drawMoney = 0
  38. }
  39. hasAddr := false
  40. addrCnt, err := g.DB().Model(dao.TalentDeliveryAddress.Table).
  41. Where(dao.TalentDeliveryAddress.Columns.TalentId, tid).Count(dao.TalentDeliveryAddress.Columns.AddressId)
  42. if err != nil {
  43. hasAddr = false
  44. } else {
  45. hasAddr = addrCnt > 0
  46. }
  47. briefInfo := talent_model.TalentBriefInfo{
  48. IsInfoComplete: isComplete,
  49. PlatformCount: platCnt,
  50. BoBoCoinValue: int64(boboCoin - drawMoney),
  51. HasDeliveryAddr: hasAddr,
  52. }
  53. return &TalentHttpResult{Code: 0, Msg: "success", Data: briefInfo}
  54. }
  55. // OnGetTalentDetailInfo 获取达人详细信息
  56. func OnGetTalentDetailInfo(r *ghttp.Request) *TalentHttpResult {
  57. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  58. if err != nil {
  59. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  60. }
  61. rec, err := g.DB().Model(dao.TalentInfo.Table).Fields(dao.TalentInfo.Columns.TalentAgeBracket,
  62. dao.TalentInfo.Columns.TalentSkinType, dao.TalentInfo.Columns.TalentWxNumber,
  63. dao.TalentInfo.Columns.TalentNationality, dao.TalentInfo.Columns.VisitStoreRegion,
  64. dao.TalentInfo.Columns.TalentGender, dao.TalentInfo.Columns.TalentPhoneNumber).One("id", tid)
  65. if err != nil {
  66. return &TalentHttpResult{Code: -2, Msg: "can not found talent info"}
  67. }
  68. return &TalentHttpResult{Code: 0, Msg: "success", Data: rec}
  69. }
  70. // OnPostTalentDetailInfo 修改达人详细信息
  71. func OnPostTalentDetailInfo(r *ghttp.Request) *TalentHttpResult {
  72. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  73. if err != nil {
  74. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  75. }
  76. var infos *talent_model.TalentSelfInputInfo
  77. err = r.ParseForm(&infos)
  78. if err != nil {
  79. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  80. }
  81. _, err = g.DB().Model(dao.TalentInfo.Table).Update(infos, "id", tid)
  82. if err != nil {
  83. return &TalentHttpResult{Code: -4, Msg: "update failed"}
  84. }
  85. return &TalentHttpResult{Code: 0, Msg: "success"}
  86. }