蛋蛋星球-客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

hdl_user.go 9.1 KiB

vor 1 Monat
vor 1 Monat
vor 3 Wochen
vor 1 Monat
vor 3 Wochen
vor 3 Wochen
vor 3 Wochen
vor 1 Monat
vor 3 Wochen
vor 3 Wochen
vor 1 Monat
vor 1 Monat
vor 1 Monat
vor 3 Wochen
vor 3 Wochen
vor 3 Wochen
vor 3 Wochen
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/es/hdl"
  6. md2 "applet/app/es/md"
  7. "applet/app/md"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "applet/app/utils/qrcode"
  11. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  12. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  13. "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun"
  14. "code.fnuoos.com/EggPlanet/egg_system_rules.git/kuaizhan"
  15. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  16. "context"
  17. "github.com/gin-gonic/gin"
  18. "github.com/olivere/elastic/v7"
  19. "github.com/syyongx/php2go"
  20. "github.com/tidwall/gjson"
  21. "strings"
  22. )
  23. // UserInfo
  24. // @Summary 用户信息
  25. // @Tags 用户信息
  26. // @Description 用户信息
  27. // @Accept json
  28. // @Produce json
  29. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  30. // @Success 200 {object} md.UserInfoResp "具体数据"
  31. // @Failure 400 {object} md.Response "具体错误"
  32. // @Router /api/v1/userInfo [get]
  33. func UserInfo(c *gin.Context) {
  34. user := svc.GetUser(c)
  35. res := md.UserInfoResp{
  36. Id: utils.Int64ToStr(user.Id),
  37. Phone: user.Phone,
  38. Nickname: user.Phone,
  39. InviteCode: user.SystemInviteCode,
  40. IsBindExtend: "0",
  41. }
  42. if user.Avatar == "" {
  43. user.Avatar = svc.GetSysCfgStr("default_avatar")
  44. }
  45. if user.Avatar != "" {
  46. res.HeadImg = svc.GetOssUrl(user.Avatar)
  47. }
  48. if user.CustomInviteCode != "" {
  49. res.InviteCode = user.CustomInviteCode
  50. }
  51. if user.ParentUid > 0 {
  52. res.IsBindExtend = "1"
  53. }
  54. e.OutSuc(c, res, nil)
  55. return
  56. }
  57. // InviteCodeUserInfo
  58. // @Summary 邀请码获取用户信息
  59. // @Tags 登录注册
  60. // @Description 邀请码获取用户信息
  61. // @Accept json
  62. // @Produce json
  63. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  64. // @Success 200 {object} md.InviteCodeUserInfoResp "具体数据"
  65. // @Failure 400 {object} md.Response "具体错误"
  66. // @Router /api/v1/inviteCode/userInfo [post]
  67. func InviteCodeUserInfo(c *gin.Context) {
  68. var req md.InviteCodeUserInfoReq
  69. err := c.ShouldBindJSON(&req)
  70. if err != nil {
  71. err = svc.HandleValidateErr(err)
  72. err1 := err.(e.E)
  73. e.OutErr(c, err1.Code, err1.Error())
  74. return
  75. }
  76. if req.InviteCode == "" {
  77. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  78. return
  79. }
  80. userDb := implement.NewUserDb(db.Db)
  81. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  82. "key": "system_invite_code",
  83. "value": req.InviteCode,
  84. })
  85. if user == nil {
  86. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  87. "key": "custom_invite_code",
  88. "value": req.InviteCode,
  89. })
  90. if user == nil {
  91. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  92. return
  93. }
  94. }
  95. nickname := user.Nickname
  96. if nickname == "" {
  97. nickname = user.Phone
  98. }
  99. if php2go.IsNumeric(nickname) {
  100. nickname = utils.HideTrueName(user.Nickname)
  101. }
  102. user = svc.UserImg(user)
  103. res := md.InviteCodeUserInfoResp{
  104. Nickname: nickname,
  105. HeadImg: user.Avatar,
  106. }
  107. e.OutSuc(c, res, nil)
  108. return
  109. }
  110. // UserBindParent
  111. // @Summary 绑定上级-要登陆的
  112. // @Tags 登录注册
  113. // @Description 绑定上级
  114. // @Accept json
  115. // @Produce json
  116. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  117. // @Success 200 {string} "具体数据"
  118. // @Failure 400 {object} md.Response "具体错误"
  119. // @Router /api/v1/memberCenter/bindParent [post]
  120. func UserBindParent(c *gin.Context) {
  121. var req md.InviteCodeUserInfoReq
  122. err := c.ShouldBindJSON(&req)
  123. if err != nil {
  124. err = svc.HandleValidateErr(err)
  125. err1 := err.(e.E)
  126. e.OutErr(c, err1.Code, err1.Error())
  127. return
  128. }
  129. if req.InviteCode == "" {
  130. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  131. return
  132. }
  133. userDb := implement.NewUserDb(db.Db)
  134. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  135. "key": "system_invite_code",
  136. "value": req.InviteCode,
  137. })
  138. if user == nil {
  139. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  140. "key": "custom_invite_code",
  141. "value": req.InviteCode,
  142. })
  143. if user == nil {
  144. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  145. return
  146. }
  147. }
  148. ownUser := svc.GetUser(c)
  149. if ownUser.ParentUid > 0 {
  150. e.OutErr(c, 400, e.NewErr(400, "已有导师"))
  151. return
  152. }
  153. if user.Id == ownUser.Id {
  154. e.OutErr(c, 400, e.NewErr(400, "不能绑定自己"))
  155. return
  156. }
  157. ownUser.ParentUid = user.Id
  158. _, err = db.Db.Where("id=?", ownUser.Id).Cols("parent_uid").Update(ownUser)
  159. if err != nil {
  160. e.OutErr(c, 400, e.NewErr(400, "绑定失败,请重试"))
  161. return
  162. }
  163. initLV := 1
  164. ur := new(model.UserRelate)
  165. ur.ParentUid = user.Id
  166. ur.Uid = ownUser.Id
  167. ur.Level = initLV
  168. ur.InviteTime = ownUser.CreateAt
  169. userRelateDb := implement.NewUserRelateDb(db.Db)
  170. _, err = userRelateDb.UserRelateInsert(ur)
  171. if err != nil {
  172. e.OutErr(c, e.ERR_DB_ORM, err)
  173. return
  174. }
  175. // 插入多级关联
  176. go svc.RoutineMultiRelate(ur.ParentUid, ur.Uid, initLV)
  177. //TODO 绑定成功后 加群之类的怎么处理
  178. e.OutSuc(c, "success", nil)
  179. return
  180. }
  181. // UpdatePassword
  182. // @Summary 修改密码-不要原密码 换成验证码
  183. // @Tags 账号与安全
  184. // @Description 修改密码
  185. // @Accept json
  186. // @Produce json
  187. // @Param req body md.UpdatePasswordReq true "注册参数"
  188. // @Success 200 string "登录成功返回"
  189. // @Failure 400 {object} md.Response "具体错误"
  190. // @Router /api/v1/memberCenter/updatePassword [post]
  191. func UpdatePassword(c *gin.Context) {
  192. var req md.UpdatePasswordReq
  193. err := c.ShouldBindJSON(&req)
  194. if err != nil {
  195. err = svc.HandleValidateErr(err)
  196. err1 := err.(e.E)
  197. e.OutErr(c, err1.Code, err1.Error())
  198. return
  199. }
  200. user := svc.GetUser(c)
  201. data := svc.AliyunSmsBase(c, "")
  202. //校验短信
  203. err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
  204. if err != nil {
  205. e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
  206. return
  207. }
  208. user.Password = utils.Md5(req.Password)
  209. db.Db.Where("id=?", user.Id).Cols("password").Update(user)
  210. e.OutSuc(c, "success", nil)
  211. return
  212. }
  213. // UpdatePasscode
  214. // @Summary 修改支付宝密码
  215. // @Tags 账号与安全
  216. // @Description 修改支付宝密码
  217. // @Accept json
  218. // @Produce json
  219. // @Param req body md.UpdatePasscodeReq true "注册参数"
  220. // @Success 200 string "登录成功返回"
  221. // @Failure 400 {object} md.Response "具体错误"
  222. // @Router /api/v1/memberCenter/updatePasscode [post]
  223. func UpdatePasscode(c *gin.Context) {
  224. var req md.UpdatePasscodeReq
  225. err := c.ShouldBindJSON(&req)
  226. if err != nil {
  227. err = svc.HandleValidateErr(err)
  228. err1 := err.(e.E)
  229. e.OutErr(c, err1.Code, err1.Error())
  230. return
  231. }
  232. user := svc.GetUser(c)
  233. data := svc.AliyunSmsBase(c, "")
  234. //校验短信
  235. err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
  236. if err != nil {
  237. e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
  238. return
  239. }
  240. user.Passcode = utils.Md5(req.PassCode)
  241. db.Db.Where("id=?", user.Id).Cols("passcode").Update(user)
  242. e.OutSuc(c, "success", nil)
  243. return
  244. }
  245. // InviteUrl
  246. // @Summary 邀请链接
  247. // @Tags 邀请海报
  248. // @Description 邀请链接
  249. // @Accept json
  250. // @Produce json
  251. // @Success 200 {object} md.InviteUrl "登录成功返回"
  252. // @Failure 400 {object} md.Response "具体错误"
  253. // @Router /api/v1/memberCenter/inviteUrl [get]
  254. func InviteUrl(c *gin.Context) {
  255. user := svc.GetUser(c)
  256. link := svc.GetSysCfgStr("kuaizhan_url")
  257. res := md.InviteUrl{
  258. Link: "",
  259. InviteCode: user.SystemInviteCode,
  260. }
  261. if user.CustomInviteCode != "" {
  262. res.InviteCode = user.CustomInviteCode
  263. }
  264. link += "?inviteCode=" + res.InviteCode
  265. EggUserShortLink := md2.EggUserShortLink
  266. boolQueryToItem := elastic.NewBoolQuery() // 创建bool查询
  267. aggsMatch := elastic.NewMatchQuery("link", link) //设置查询条件
  268. boolQueryToItem.Must(aggsMatch)
  269. result, _ := hdl.EsSelectOne(context.Background(), EggUserShortLink, boolQueryToItem, false)
  270. isHas := 0
  271. if result != nil && len(result.Hits.Hits) > 0 {
  272. for _, hit := range result.Hits.Hits {
  273. if hit == nil {
  274. continue
  275. }
  276. jsonByte, _ := hit.Source.MarshalJSON()
  277. if gjson.Get(string(jsonByte), "short_link").String() != "" {
  278. isHas = 1
  279. link = gjson.Get(string(jsonByte), "short_link").String()
  280. }
  281. }
  282. }
  283. if isHas == 0 {
  284. send, _ := kuaizhan.KuaizhanSend(svc.GetSysCfgStr("kuaizhan_app_key"), svc.GetSysCfgStr("kuaizhan_app_secret"), link)
  285. if gjson.Get(send, "url").String() != "" {
  286. var uniqueId = php2go.Md5(link)
  287. oldLink := link
  288. link = gjson.Get(send, "url").String()
  289. tmp := map[string]interface{}{
  290. "uid": user.Id,
  291. "link": oldLink,
  292. "short_link": link,
  293. }
  294. doc, _ := es.FirstDoc(EggUserShortLink, uniqueId)
  295. if doc == nil {
  296. es.CreateDoc(EggUserShortLink, uniqueId, tmp)
  297. } else {
  298. es.UpdateDoc(EggUserShortLink, uniqueId, tmp)
  299. }
  300. }
  301. }
  302. res.Link = link
  303. QRcode := qrcode.GetPNGBase64(link)
  304. QRcode = strings.ReplaceAll(QRcode, "\u0000", "")
  305. res.Qrcode = QRcode
  306. e.OutSuc(c, res, nil)
  307. return
  308. }