talent_income.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. package youngee_talent_service
  2. import (
  3. "strconv"
  4. "youngmini_server/app/dao"
  5. "youngmini_server/app/model"
  6. "youngmini_server/app/model/youngee_talent_model"
  7. "youngmini_server/app/utils"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/net/ghttp"
  10. )
  11. func GetTalentIncomeInfo(r *ghttp.Request) *TalentHttpResult {
  12. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  13. if err != nil {
  14. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  15. }
  16. var getTalentIncomeReq *youngee_talent_model.GetTalentIncomeReq
  17. err = r.ParseForm(&getTalentIncomeReq)
  18. if err != nil {
  19. return &TalentHttpResult{Code: -2, Msg: "params error"}
  20. }
  21. var TalentIncomeInfoRes youngee_talent_model.TalentIncomeInfoAll
  22. g.DB().Model("youngee_talent_info").Where("id=?", tid).Scan(&TalentIncomeInfoRes.TalentInfo)
  23. var talentIncomeList []*youngee_talent_model.TalentIncomeInfo
  24. err = g.DB().Model("younggee_talent_income").Where("talent_id = ? and withdraw_status = ?", tid, getTalentIncomeReq.Type).Scan(&talentIncomeList)
  25. platformMap := make(map[string]model.InfoThirdPlatform)
  26. platformInfo := []*model.InfoThirdPlatform{}
  27. if len(talentIncomeList) != 0 {
  28. err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  29. if err != nil {
  30. return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  31. }
  32. for i, _ := range platformInfo {
  33. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  34. }
  35. }
  36. for _, v := range talentIncomeList {
  37. var platform model.InfoThirdPlatform
  38. switch v.Type {
  39. case 1:
  40. projectPlatform, err := g.Model(dao.ProjectInfo.Table).Fields("project_platform").Where("project_id = ?", v.ProjectId).Value()
  41. if err != nil {
  42. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  43. }
  44. platform = platformMap[projectPlatform.String()]
  45. talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
  46. Id: v.Id,
  47. ProjectId: v.ProjectId,
  48. TaskId: v.TaskId,
  49. Type: v.Type,
  50. BrandName: v.BrandName,
  51. TaskName: v.TaskName,
  52. PhotoUrl: v.PhotoUrl,
  53. TeamId: v.TeamId,
  54. Income: v.Income,
  55. IncomeType: v.IncomeType,
  56. WithdrawStatus: v.WithdrawStatus,
  57. IncomeAt: v.IncomeAt,
  58. WithdrawAt: v.WithdrawAt,
  59. PlatformIconUrl: platform.PlatformIcon,
  60. }
  61. TalentIncomeInfoRes.TalentIncomeInfos = append(TalentIncomeInfoRes.TalentIncomeInfos, &talentIncomeInfo)
  62. break
  63. case 2:
  64. platformId, err := g.Model(dao.YounggeeSelectionInfo.Table).Fields("platform").Where("selection_id = ?", v.SelectionId).Value()
  65. if err != nil {
  66. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  67. }
  68. platform = platformMap[platformId.String()]
  69. talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
  70. Id: v.Id,
  71. ProjectId: v.SelectionId,
  72. TaskId: v.SectaskId,
  73. Type: v.Type,
  74. BrandName: v.BrandName,
  75. TaskName: v.TaskName,
  76. PhotoUrl: v.PhotoUrl,
  77. TeamId: v.TeamId,
  78. Income: v.Income,
  79. IncomeType: v.IncomeType,
  80. WithdrawStatus: v.WithdrawStatus,
  81. IncomeAt: v.IncomeAt,
  82. WithdrawAt: v.WithdrawAt,
  83. PlatformIconUrl: platform.PlatformIcon,
  84. }
  85. TalentIncomeInfoRes.TalentIncomeInfos = append(TalentIncomeInfoRes.TalentIncomeInfos, &talentIncomeInfo)
  86. break
  87. default:
  88. }
  89. }
  90. return &TalentHttpResult{Code: 0, Msg: "success", Data: TalentIncomeInfoRes}
  91. }
  92. //func GetTalentIncomeInfo(r *ghttp.Request) *TalentHttpResult {
  93. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  94. // if err != nil {
  95. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  96. // }
  97. //
  98. // var getTalentIncomeReq *youngee_talent_model.GetTalentIncomeReq
  99. // err = r.ParseForm(&getTalentIncomeReq)
  100. // if err != nil {
  101. // return &TalentHttpResult{Code: -2, Msg: "params error"}
  102. // }
  103. //
  104. // var talentIncomerep []youngee_talent_model.TalentIncomeInfo
  105. // var talentIncomeList []*model.YounggeeTalentIncome
  106. // fmt.Println("222", getTalentIncomeReq.Type)
  107. // err = g.DB().Model(dao.YounggeeTalentIncome.Table).Where("talent_id = ? and withdraw_status = ?", tid, 2).Scan(&talentIncomeList)
  108. // if err != nil {
  109. // return &TalentHttpResult{Code: -3, Msg: err.Error()}
  110. // }
  111. //
  112. // platformMap := make(map[string]model.InfoThirdPlatform)
  113. // platformInfo := []*model.InfoThirdPlatform{}
  114. // if len(talentIncomeList) != 0 {
  115. // err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  116. // if err != nil {
  117. // return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  118. // }
  119. //
  120. // for i, _ := range platformInfo {
  121. // platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  122. // }
  123. // }
  124. //
  125. // for _, v := range talentIncomeList {
  126. // var platform model.InfoThirdPlatform
  127. // switch v.Type {
  128. // case 1:
  129. // projectPlatform, err := g.Model(dao.ProjectInfo.Table).Fields("project_platform").Where("project_id = ?", v.ProjectId).Value()
  130. // if err != nil {
  131. // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  132. // }
  133. // platform = platformMap[projectPlatform.String()]
  134. //
  135. // talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
  136. // Id: v.Id,
  137. // ProjectId: v.ProjectId,
  138. // TaskId: v.TaskId,
  139. // Type: v.Type,
  140. // BrandName: v.BrandName,
  141. // TaskName: v.TaskName,
  142. // PhotoUrl: v.PhotoUrl,
  143. // TeamId: v.TeamId,
  144. // Income: v.Income,
  145. // IncomeType: v.IncomeType,
  146. // WithdrawStatus: v.WithdrawStatus,
  147. // IncomeAt: v.IncomeAt,
  148. // WithdrawAt: v.WithdrawAt,
  149. // PlatformIconUrl: platform.PlatformIcon,
  150. // }
  151. //
  152. // talentIncomerep = append(talentIncomerep, talentIncomeInfo)
  153. // break
  154. // case 2:
  155. // platformId, err := g.Model(dao.YounggeeSelectionInfo.Table).Fields("platform").Where("selection_id = ?", v.SelectionId).Value()
  156. // if err != nil {
  157. // return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  158. // }
  159. // platform = platformMap[platformId.String()]
  160. //
  161. // talentIncomeInfo := youngee_talent_model.TalentIncomeInfo{
  162. // Id: v.Id,
  163. // ProjectId: v.SelectionId,
  164. // TaskId: v.SectaskId,
  165. // Type: v.Type,
  166. // BrandName: v.BrandName,
  167. // TaskName: v.TaskName,
  168. // PhotoUrl: v.PhotoUrl,
  169. // TeamId: v.TeamId,
  170. // Income: v.Income,
  171. // IncomeType: v.IncomeType,
  172. // WithdrawStatus: v.WithdrawStatus,
  173. // IncomeAt: v.IncomeAt,
  174. // WithdrawAt: v.WithdrawAt,
  175. // PlatformIconUrl: platform.PlatformIcon,
  176. // }
  177. //
  178. // talentIncomerep = append(talentIncomerep, talentIncomeInfo)
  179. // break
  180. // default:
  181. // }
  182. //
  183. // }
  184. //
  185. // return &TalentHttpResult{Code: 0, Msg: "success", Data: talentIncomerep}
  186. //}
  187. // 提现
  188. //func Withdraw(r *ghttp.Request) *TalentHttpResult {
  189. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  190. // if err != nil {
  191. // return &TalentHttpResult{Code: -1, Msg: err.Error()}
  192. // }
  193. //
  194. // var DataInfoReq *youngee_talent_model.WithdrawInfo
  195. // err = r.ParseForm(&DataInfoReq)
  196. // if err != nil {
  197. // return &TalentHttpResult{Code: -2, Msg: err.Error()}
  198. // }
  199. // incomeIdStrList := strings.Split(DataInfoReq.IncomeIdList, ",")
  200. // incomeIdList := utils.TypeTran.String2Int(incomeIdStrList)
  201. //
  202. // // 检验是否均处于可提现状态,且达人id是否对应
  203. // var incomeList []model.YounggeeTalentIncome
  204. // err = g.Model(dao.YounggeeTalentIncome.Table).Where("talent_id = ? and withdraw_status = 1", tid).And("id IN (?)", incomeIdList).Scan(&incomeList)
  205. // if err != nil {
  206. // return &TalentHttpResult{Code: -4, Msg: err.Error()}
  207. // }
  208. // if len(incomeIdList) != len(incomeList) {
  209. // return &TalentHttpResult{Code: -3, Msg: "Req IncomeIdList Error"}
  210. // }
  211. //
  212. // //// 检查达人积分是否足够
  213. // //totalPoint, err := g.Model(dao.YoungeeTalentInfo.Table).Fields("point").Where("id = ?", tid).Value()
  214. // //if err != nil {
  215. // // return &TalentHttpResult{Code: -5, Msg: err.Error()}
  216. // //}
  217. // //if totalPoint.Int() < DataInfoReq.Point {
  218. // // return &TalentHttpResult{Code: -3, Msg: "Req Point Error"}
  219. // //}
  220. //
  221. // // 查询达人提现到账账户信息
  222. // var talentBank model.YounggeeTalentBank
  223. // err = g.Model(dao.YounggeeTalentBank.Table).Where("talent_id = ?", tid).Scan(&talentBank)
  224. // if err != nil {
  225. // return &TalentHttpResult{Code: -6, Msg: err.Error()}
  226. // }
  227. // bankJsons, errs := json.Marshal(talentBank) //转换成JSON返回的是byte[]
  228. // if errs != nil {
  229. // return &TalentHttpResult{Code: -7, Msg: err.Error()}
  230. // }
  231. //
  232. // err = g.DB().Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  233. // s1 := tid[7:]
  234. // s2 := fmt.Sprintf("%d", gtime.Now().YearDay())
  235. // s3 := fmt.Sprintf("%02v", rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(100))
  236. // s := "6" + s1 + s2 + s3
  237. // // 插入提现记录
  238. // _, err1 := tx.Ctx(ctx).Model(dao.YounggeeWithdrawRecord.Table).Data(model.YounggeeWithdrawRecord{
  239. // WithdrawId: s,
  240. // TalentId: tid,
  241. // WithdrawAmount: float64(DataInfoReq.TotalAmount),
  242. // AmountPayable: float64(DataInfoReq.RealAmount),
  243. //
  244. // IncomeIdList: DataInfoReq.IncomeIdList,
  245. // //PayPoint: DataInfoReq.Point,
  246. // ReceiveInfo: string(bankJsons),
  247. // BankType: 2,
  248. // Status: 1,
  249. // SubmitAt: gtime.Now(),
  250. // }).InsertAndGetId()
  251. // if err1 != nil {
  252. // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
  253. // return err1
  254. // }
  255. //
  256. // // 更新income表中提现状态
  257. // _, err1 = tx.Ctx(ctx).Model(dao.YounggeeTalentIncome.Table).Where("id IN (?)", incomeIdList).Update(g.Map{"withdraw_status": 2, "withdraw_at": gtime.Now()})
  258. // if err1 != nil {
  259. // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
  260. // return err1
  261. // }
  262. //
  263. // // 更新talent表中提现金额
  264. // _, err1 = tx.Ctx(ctx).Model(dao.YoungeeTalentInfo.Table).Where("id = ?", tid).Increment("withdrawing", float64(DataInfoReq.TotalAmount))
  265. // if err1 != nil {
  266. // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
  267. // return err1
  268. // }
  269. // _, err1 = tx.Ctx(ctx).Model(dao.YoungeeTalentInfo.Table).Where("id = ?", tid).Decrement("canwithdraw", float64(DataInfoReq.TotalAmount))
  270. // if err1 != nil {
  271. // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err1)
  272. // return err1
  273. // }
  274. //
  275. // // 达人消息
  276. // for _, incomeInfo := range incomeList {
  277. // messageTypeId := [4]int{25, 26, 27, 28}
  278. // messageInfo := model.YounggeeMessageInfo{
  279. // MessageId: messageTypeId[incomeInfo.IncomeType-1],
  280. // MessageType: 2,
  281. // CreatedAt: gtime.Now(),
  282. // ProjectName: incomeInfo.TaskName,
  283. // IsReaded: 0,
  284. // IsDeleted: 0,
  285. // }
  286. // _, err = tx.Ctx(ctx).Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  287. // if err != nil {
  288. // fmt.Printf("[Withdraw Transaction] Error:%+v\n", err)
  289. // return err
  290. // }
  291. // }
  292. // return nil
  293. // })
  294. // if err != nil {
  295. // return &TalentHttpResult{Code: -8, Msg: "Add Withdraw Record failed: " + err.Error()}
  296. // }
  297. //
  298. // return &TalentHttpResult{Code: 0, Msg: "success"}
  299. //}
  300. // 查询积分明细
  301. func GetTalentPointInfo(r *ghttp.Request) *TalentHttpResult {
  302. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  303. if err != nil {
  304. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  305. }
  306. var talentPointList []*model.YounggeeTalentPointRecord
  307. err = g.DB().Model(dao.YounggeeTalentPointRecord.Table).Where("talent_id = ?", tid).Order("income_at").Scan(talentPointList)
  308. if err != nil {
  309. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  310. }
  311. point, err := g.DB().Model(dao.YoungeeTalentInfo.Table).Fields("point").Where("talent_id = ?", tid).Value()
  312. if err != nil {
  313. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  314. }
  315. TalentPointInfo := youngee_talent_model.TalentPointInfo{
  316. Point: point.Int(),
  317. TalentPointRecord: talentPointList,
  318. }
  319. return &TalentHttpResult{Code: 0, Msg: "success", Data: TalentPointInfo}
  320. }