talent_info.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package youngee_talent_service
  2. import (
  3. "fmt"
  4. "youngmini_server/app/dao"
  5. "youngmini_server/app/model/youngee_talent_model"
  6. "youngmini_server/app/utils"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/net/ghttp"
  9. )
  10. func OnPostTalentInfo(r *ghttp.Request) *TalentHttpResult {
  11. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  12. if err != nil {
  13. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  14. }
  15. var infos *youngee_talent_model.TalentSelfInputInfo
  16. err = r.ParseForm(&infos)
  17. if err != nil {
  18. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  19. }
  20. infos.IsBindInfo = 1
  21. _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Update(infos, "id", tid)
  22. if err != nil {
  23. return &TalentHttpResult{Code: -4, Msg: "update failed"}
  24. }
  25. return &TalentHttpResult{Code: 0, Msg: "success"}
  26. }
  27. func IsSecCollection(r *ghttp.Request) *TalentHttpResult {
  28. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  29. if err != nil {
  30. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  31. }
  32. selectionId := r.GetQueryString("selection_id")
  33. collectionInfo := []youngee_talent_model.SelectionCollection{}
  34. err = g.DB().Model("younggee_selection_collect_info").Where("selection_id=? and talent_id = ?", selectionId, tid).Scan(&collectionInfo)
  35. if err != nil {
  36. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  37. }
  38. //已被收藏
  39. if len(collectionInfo) != 0 && collectionInfo[0].Deleted == 0 { //有数据 且 没取消收藏
  40. return &TalentHttpResult{Code: 0, Msg: "此选品已被收藏", Data: 0}
  41. } else {
  42. return &TalentHttpResult{Code: 0, Msg: "此选品没有被收藏", Data: 1} //没数据 或 有数据但取消了收藏
  43. }
  44. //返回的data作为收藏接口的is_collect字段传入
  45. }
  46. func OnUpdateTalentInfo(r *ghttp.Request) *TalentHttpResult {
  47. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  48. if err != nil {
  49. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  50. }
  51. var infos *youngee_talent_model.TalentSelfInputInfo
  52. err = r.ParseForm(&infos)
  53. fmt.Println("头像地址---->:", infos.Avatar)
  54. if err != nil {
  55. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  56. }
  57. _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Data(g.Map{"talent_wx_nickname": infos.TalentWxNickname, "avatar": infos.Avatar}).Where("id = ?", tid).Update()
  58. if err != nil {
  59. return &TalentHttpResult{Code: -4, Msg: "update failed"}
  60. }
  61. return &TalentHttpResult{Code: 0, Msg: "success"}
  62. }
  63. func UpdateTalentName(r *ghttp.Request) *TalentHttpResult {
  64. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  65. if err != nil {
  66. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  67. }
  68. var infos *youngee_talent_model.UpdateNameReq
  69. err = r.ParseForm(&infos)
  70. if err != nil {
  71. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  72. }
  73. _, err = g.DB().Model(dao.YoungeeTalentInfo.Table).Data(g.Map{"talent_nickname": infos.TalentNickname}).Where("id = ?", tid).Update()
  74. if err != nil {
  75. return &TalentHttpResult{Code: -4, Msg: "update failed"}
  76. }
  77. return &TalentHttpResult{Code: 0, Msg: "success"}
  78. }
  79. func UpdateTalentWxnum(r *ghttp.Request) *TalentHttpResult {
  80. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  81. if err != nil {
  82. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  83. }
  84. var infos *youngee_talent_model.UpdateWxNameReq
  85. err = r.ParseForm(&infos)
  86. if err != nil {
  87. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  88. }
  89. _, err = g.DB().Model("youngee_talent_info").Data(g.Map{"wx_num": infos.WxNum}).Where("id = ?", tid).Update()
  90. if err != nil {
  91. return &TalentHttpResult{Code: -4, Msg: "update failed"}
  92. }
  93. return &TalentHttpResult{Code: 0, Msg: "success"}
  94. }
  95. func GetTalentInfo(r *ghttp.Request) *TalentHttpResult {
  96. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  97. if err != nil {
  98. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  99. }
  100. talentInfo := youngee_talent_model.TalentInfo{} //结构体实例化
  101. err = g.DB().Model("youngee_talent_info").WithAll().Where("id", tid).Scan(&talentInfo)
  102. if err != nil {
  103. return &TalentHttpResult{Code: -2, Msg: "Get talent info failed"}
  104. }
  105. return &TalentHttpResult{Code: 0, Msg: "success", Data: talentInfo}
  106. }
  107. func AddDouyinHomePage(r *ghttp.Request) *TalentHttpResult {
  108. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  109. if err != nil {
  110. return &TalentHttpResult{Code: -1, Msg: "Update talent address failed"}
  111. }
  112. var addReq *youngee_talent_model.AddDouyinReq
  113. err = r.ParseForm(&addReq)
  114. if err != nil {
  115. return &TalentHttpResult{Code: -2, Msg: "params error"}
  116. }
  117. //调用moreAPI获取粉丝数(follower_count)、点赞数(total_favorited)作品数(aweme_count),性别(gender),所在城市(ip_location)
  118. info := getDouyinInfo(addReq.HomePageUrl)
  119. _, err = g.DB().Model("platform_kuaishou_user_info").Where("talent_id = ? AND open_id = ?", tid, addReq.OpenId).Data(g.Map{
  120. "home_page_url": addReq.HomePageUrl,
  121. "fan": info.FollowerCount,
  122. "like_num": info.TotalFavorited,
  123. "video_num": info.AwemeCount,
  124. "gender": info.Gender,
  125. "city": info.IPLocation,
  126. }).Update()
  127. if err != nil {
  128. return &TalentHttpResult{Code: -3, Msg: "update failed", Data: err.Error()}
  129. }
  130. return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
  131. }
  132. // // 查询任务数量、young之团数量、选品任务数量
  133. //
  134. // func GetMyInfoNum(r *ghttp.Request) *TalentHttpResult {
  135. // tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  136. // if err != nil {
  137. // return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  138. // }
  139. // talentInfoNum := &youngee_talent_model.TalentInfoNum{}
  140. // // 查询任务相关数量
  141. // var endTaskStageList = [3]int{3, 5, 16}
  142. //
  143. // //种草
  144. // fmt.Println("1")
  145. // talentInfoNum.AllTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id=?", tid).Count()
  146. // fmt.Println("talentInfoNum.AllTaskNum111", talentInfoNum.AllTaskNum)
  147. // if err != nil {
  148. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  149. // }
  150. // talentInfoNum.ApplyTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 1", tid).Count()
  151. // if err != nil {
  152. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  153. // }
  154. // talentInfoNum.ExeTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count()
  155. // if err != nil {
  156. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  157. // }
  158. // talentInfoNum.EndTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage in (?)", tid, endTaskStageList).Count()
  159. // if err != nil {
  160. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  161. // }
  162. // talentInfoNum.ToDealNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 15", tid).Count()
  163. // if err != nil {
  164. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  165. // }
  166. //
  167. // //带货任务相关数量
  168. // fmt.Println("2")
  169. // talentInfoNum.AllSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ?", tid).Count()
  170. // if err != nil {
  171. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  172. // }
  173. // talentInfoNum.GetSampleSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage in (3,4, 5)", tid).Count()
  174. // if err != nil {
  175. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  176. // }
  177. // talentInfoNum.ExeSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and sale_num_all > 0", tid).Count()
  178. // if err != nil {
  179. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  180. // }
  181. // talentInfoNum.EndSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and task_ddl < NOW() ", tid).Count()
  182. // if err != nil {
  183. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  184. // }
  185. // talentInfoNum.InSampleProcessNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage = 1 ", tid).Count()
  186. // if err != nil {
  187. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  188. // }
  189. // talentInfoNum.ToGetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 1 ", tid).Count()
  190. // if err != nil {
  191. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  192. // }
  193. // talentInfoNum.GetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 2 ", tid).Count()
  194. // if err != nil {
  195. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  196. // }
  197. // //本地生活
  198. // fmt.Println("3")
  199. // talentInfoNum.AllTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id=?", tid).Count()
  200. // if err != nil {
  201. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  202. // }
  203. // talentInfoNum.ApplyTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 1", tid).Count()
  204. // if err != nil {
  205. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  206. // }
  207. // talentInfoNum.ToBookLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 4", tid).Count()
  208. // if err != nil {
  209. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  210. // }
  211. // talentInfoNum.ExeTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count()
  212. // if err != nil {
  213. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  214. // }
  215. // talentInfoNum.ToDealLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14", tid).Count()
  216. // if err != nil {
  217. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  218. // }
  219. // talentInfoNum.EndTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage in (?)", tid, endTaskStageList).Count()
  220. // if err != nil {
  221. // return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  222. // }
  223. //
  224. // return &TalentHttpResult{Code: 0, Msg: "success1", Data: &talentInfoNum}
  225. // }
  226. func GetMyInfoNum(r *ghttp.Request) *TalentHttpResult {
  227. // 获取 talentId
  228. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  229. if err != nil {
  230. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  231. }
  232. taskType := r.GetInt("task_type", 0)
  233. if taskType == 0 {
  234. return &TalentHttpResult{Code: -1, Msg: "task_type is null"}
  235. }
  236. // 初始化 talentInfoNum
  237. talentInfoNum := &youngee_talent_model.TalentInfoNum{
  238. TaskCountNum: &youngee_talent_model.TaskCountNum{},
  239. SecTaskCountNum: &youngee_talent_model.SecTaskCountNum{},
  240. LocalTaskCountNum: &youngee_talent_model.LocalTaskCountNum{},
  241. }
  242. // 查询任务相关数量
  243. var endTaskStageList = [3]int{3, 5, 16}
  244. // 种草任务相关数量
  245. fmt.Println("1")
  246. talentInfoNum.TaskCountNum.AllTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id=? AND project_type = ? ", tid, taskType).Count()
  247. if err != nil {
  248. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  249. }
  250. talentInfoNum.TaskCountNum.ApplyTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 1 AND project_type = ? ", tid, taskType).Count()
  251. if err != nil {
  252. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  253. }
  254. talentInfoNum.TaskCountNum.ExeTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and project_type = ? ", tid, taskType).Count()
  255. if err != nil {
  256. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  257. }
  258. talentInfoNum.TaskCountNum.EndTaskNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage in (?) and project_type = ? ", tid, endTaskStageList, taskType).Count()
  259. if err != nil {
  260. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  261. }
  262. talentInfoNum.TaskCountNum.ToDealNum, err = g.DB().Model("youngee_task_info").Where("talent_id = ? and task_stage = 15 and project_type = ?", tid, taskType).Count()
  263. if err != nil {
  264. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  265. }
  266. // 带货任务相关数量
  267. fmt.Println("2")
  268. talentInfoNum.SecTaskCountNum.AllSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ?", tid).Count()
  269. if err != nil {
  270. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  271. }
  272. talentInfoNum.SecTaskCountNum.GetSampleSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage in (3,4, 5)", tid).Count()
  273. if err != nil {
  274. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  275. }
  276. talentInfoNum.SecTaskCountNum.ExeSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and sale_num_all > 0", tid).Count()
  277. if err != nil {
  278. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  279. }
  280. talentInfoNum.SecTaskCountNum.EndSecTaskNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and task_ddl < NOW() ", tid).Count()
  281. if err != nil {
  282. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  283. }
  284. talentInfoNum.SecTaskCountNum.InSampleProcessNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and free_stage = 1 ", tid).Count()
  285. if err != nil {
  286. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  287. }
  288. talentInfoNum.SecTaskCountNum.ToGetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 1 ", tid).Count()
  289. if err != nil {
  290. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  291. }
  292. talentInfoNum.SecTaskCountNum.GetRewardNum, err = g.DB().Model("younggee_sec_task_info").Where("talent_id = ? and reward_stage = 2 ", tid).Count()
  293. if err != nil {
  294. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  295. }
  296. // 本地生活任务相关数量
  297. fmt.Println("3")
  298. talentInfoNum.LocalTaskCountNum.AllLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id=? and local_type = ?", tid, taskType).Count()
  299. if err != nil {
  300. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  301. }
  302. talentInfoNum.LocalTaskCountNum.ApplyLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 1 and local_type = ?", tid, taskType).Count()
  303. if err != nil {
  304. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  305. }
  306. talentInfoNum.LocalTaskCountNum.ToBookLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage = 4 and local_type = ?", tid, taskType).Count()
  307. if err != nil {
  308. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  309. }
  310. talentInfoNum.LocalTaskCountNum.ExeLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and local_type = ?", tid, taskType).Count()
  311. if err != nil {
  312. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  313. }
  314. talentInfoNum.LocalTaskCountNum.ToDealLocalNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage >= 4 and task_stage <= 14 and local_type = ?", tid, taskType).Count()
  315. if err != nil {
  316. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  317. }
  318. talentInfoNum.LocalTaskCountNum.EndLocalTaskNum, err = g.DB().Model("youngee_local_task_info").Where("talent_id = ? and task_stage in (?) and local_type = ?", tid, endTaskStageList, taskType).Count()
  319. if err != nil {
  320. return &TalentHttpResult{Code: -2, Msg: "Get task num failed"}
  321. }
  322. // 返回填充好的 talentInfoNum
  323. return &TalentHttpResult{Code: 0, Msg: "success1", Data: talentInfoNum}
  324. }
  325. func AddTalentSkill(r *ghttp.Request) *TalentHttpResult {
  326. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  327. if err != nil {
  328. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  329. }
  330. skills := r.GetQueryString("skills", "")
  331. openId := r.GetQueryString("open_id")
  332. _, err = g.DB().Model("platform_kuaishou_user_info").Where("open_id=? and talent_id=?", openId, tid).Data(g.Map{"skill": skills}).Update()
  333. if err != nil {
  334. return &TalentHttpResult{Code: -1, Msg: "Update talent info failed"}
  335. }
  336. return &TalentHttpResult{Code: 0, Msg: "success", Data: skills}
  337. }