蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_go_routine.go 1.8 KiB

пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
пре 1 месец
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils/logx"
  5. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  7. "fmt"
  8. "time"
  9. )
  10. // RoutineInsertUserRelate is 协程 当关联上级用户时,需要查询当前用户的所有关联下级,并新增关联上级与当前用户下级关系
  11. func RoutineInsertUserRelate(puid, uid int64, addlv int) {
  12. userRelateDb := implement.NewUserRelateDb(db.Db)
  13. defer Rev()
  14. urs, err := userRelateDb.UserRelatesByPuid(uid, 0, 0)
  15. if err != nil {
  16. logx.Warn(err)
  17. }
  18. // fmt.Println(*urs)
  19. for _, item := range *urs {
  20. _, err = userRelateDb.UserRelateInsert(
  21. &model.UserRelate{
  22. ParentUid: puid,
  23. Uid: item.Uid,
  24. Level: item.Level + addlv,
  25. InviteTime: time.Now().Format("2006-01-02 15:04:05"),
  26. })
  27. if err != nil {
  28. continue
  29. }
  30. logx.Info(fmt.Sprintf("关联pid(%v) -> uid(%v) ,lv:%v", puid, item.Uid, item.Level+addlv))
  31. }
  32. }
  33. // RoutineMultiRelate is 多级关联
  34. func RoutineMultiRelate(pid, uid int64, lv int) {
  35. userDb := implement.NewUserDb(db.Db)
  36. userRelateDb := implement.NewUserRelateDb(db.Db)
  37. defer Rev()
  38. for {
  39. if pid == 0 {
  40. break
  41. }
  42. m, err := userDb.GetUser(pid)
  43. if err != nil || m == nil {
  44. logx.Warn(err)
  45. break
  46. }
  47. if m.ParentUid == 0 {
  48. break
  49. }
  50. lv++
  51. ur := new(model.UserRelate)
  52. ur.ParentUid = m.ParentUid
  53. ur.Uid = uid
  54. ur.Level = lv
  55. ur.InviteTime = time.Now().Format("2006-01-02 15:04:05")
  56. _, err = userRelateDb.UserRelateInsert(ur)
  57. if err != nil {
  58. logx.Warn(err)
  59. break
  60. }
  61. // 还要关联当前的用户的所有下级,注意关联等级
  62. RoutineInsertUserRelate(m.ParentUid, uid, lv)
  63. // 下级关联上上级
  64. // 继续查询
  65. logx.Info(fmt.Sprintf("关联pid(%v) -> uid(%v),lv:%v", ur.ParentUid, ur.Uid, lv))
  66. logx.Info("继续查询")
  67. pid = m.ParentUid
  68. }
  69. }