|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/es/hdl"
- md2 "applet/app/es/md"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "applet/app/utils/qrcode"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/kuaizhan"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "context"
- "github.com/gin-gonic/gin"
- "github.com/olivere/elastic/v7"
- "github.com/syyongx/php2go"
- "github.com/tidwall/gjson"
- "strings"
- )
-
- // UserInfo
- // @Summary 用户信息
- // @Tags 用户信息
- // @Description 用户信息
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.UserInfoResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/userInfo [get]
- func UserInfo(c *gin.Context) {
- user := svc.GetUser(c)
- res := md.UserInfoResp{
- Id: utils.Int64ToStr(user.Id),
- Phone: user.Phone,
- Nickname: user.Phone,
- InviteCode: user.SystemInviteCode,
- IsBindExtend: "0",
- }
- if user.Avatar == "" {
- user.Avatar = svc.GetSysCfgStr("default_avatar")
- }
- if user.Avatar != "" {
- res.HeadImg = svc.GetOssUrl(user.Avatar)
- }
- if user.CustomInviteCode != "" {
- res.InviteCode = user.CustomInviteCode
- }
- if user.ParentUid > 0 {
- res.IsBindExtend = "1"
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- // InviteCodeUserInfo
- // @Summary 邀请码获取用户信息
- // @Tags 登录注册
- // @Description 邀请码获取用户信息
- // @Accept json
- // @Produce json
- // @Param req body md.InviteCodeUserInfoReq true "注册参数"
- // @Success 200 {object} md.InviteCodeUserInfoResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/inviteCode/userInfo [post]
- func InviteCodeUserInfo(c *gin.Context) {
- var req md.InviteCodeUserInfoReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- if req.InviteCode == "" {
- e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
- return
- }
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "system_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- user, _ = userDb.UserGetOneByParams(map[string]interface{}{
- "key": "custom_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
- return
- }
- }
- nickname := user.Nickname
- if nickname == "" {
- nickname = user.Phone
- }
- if php2go.IsNumeric(nickname) {
- nickname = utils.HideTrueName(user.Nickname)
- }
- user = svc.UserImg(user)
- res := md.InviteCodeUserInfoResp{
- Nickname: nickname,
- HeadImg: user.Avatar,
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- // UserBindParent
- // @Summary 绑定上级-要登陆的
- // @Tags 登录注册
- // @Description 绑定上级
- // @Accept json
- // @Produce json
- // @Param req body md.InviteCodeUserInfoReq true "注册参数"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/bindParent [post]
- func UserBindParent(c *gin.Context) {
- var req md.InviteCodeUserInfoReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- if req.InviteCode == "" {
- e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
- return
- }
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "system_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- user, _ = userDb.UserGetOneByParams(map[string]interface{}{
- "key": "custom_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
- return
- }
- }
- ownUser := svc.GetUser(c)
- if ownUser.ParentUid > 0 {
- e.OutErr(c, 400, e.NewErr(400, "已有导师"))
- return
- }
- if user.Id == ownUser.Id {
- e.OutErr(c, 400, e.NewErr(400, "不能绑定自己"))
- return
- }
- ownUser.ParentUid = user.Id
- _, err = db.Db.Where("id=?", ownUser.Id).Cols("parent_uid").Update(ownUser)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "绑定失败,请重试"))
- return
- }
- initLV := 1
- ur := new(model.UserRelate)
- ur.ParentUid = user.Id
- ur.Uid = ownUser.Id
- ur.Level = initLV
- ur.InviteTime = ownUser.CreateAt
- userRelateDb := implement.NewUserRelateDb(db.Db)
- _, err = userRelateDb.UserRelateInsert(ur)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- // 插入多级关联
- go svc.RoutineMultiRelate(ur.ParentUid, ur.Uid, initLV)
- //TODO 绑定成功后 加群之类的怎么处理
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UpdatePassword
- // @Summary 修改密码-不要原密码 换成验证码
- // @Tags 账号与安全
- // @Description 修改密码
- // @Accept json
- // @Produce json
- // @Param req body md.UpdatePasswordReq true "注册参数"
- // @Success 200 string "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/updatePassword [post]
- func UpdatePassword(c *gin.Context) {
- var req md.UpdatePasswordReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- user := svc.GetUser(c)
- data := svc.AliyunSmsBase(c, "")
- //校验短信
- err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
- return
- }
- user.Password = utils.Md5(req.Password)
- db.Db.Where("id=?", user.Id).Cols("password").Update(user)
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UpdatePasscode
- // @Summary 修改支付宝密码
- // @Tags 账号与安全
- // @Description 修改支付宝密码
- // @Accept json
- // @Produce json
- // @Param req body md.UpdatePasscodeReq true "注册参数"
- // @Success 200 string "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/updatePasscode [post]
- func UpdatePasscode(c *gin.Context) {
- var req md.UpdatePasscodeReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- user := svc.GetUser(c)
- data := svc.AliyunSmsBase(c, "")
- //校验短信
- err = aliyun.AliyunCheckSms(data["aliyun_sms_id"], data["aliyun_sms_secret"], user.Phone, req.Code)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "验证码错误,请重试"))
- return
- }
- user.Passcode = utils.Md5(req.PassCode)
- db.Db.Where("id=?", user.Id).Cols("passcode").Update(user)
- e.OutSuc(c, "success", nil)
- return
- }
-
- // InviteUrl
- // @Summary 邀请链接
- // @Tags 邀请海报
- // @Description 邀请链接
- // @Accept json
- // @Produce json
- // @Success 200 {object} md.InviteUrl "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/inviteUrl [get]
- func InviteUrl(c *gin.Context) {
- user := svc.GetUser(c)
-
- link := svc.GetSysCfgStr("kuaizhan_url")
- res := md.InviteUrl{
- Link: "",
- InviteCode: user.SystemInviteCode,
- }
- if user.CustomInviteCode != "" {
- res.InviteCode = user.CustomInviteCode
- }
- link += "?inviteCode=" + res.InviteCode
- EggUserShortLink := md2.EggUserShortLink
- boolQueryToItem := elastic.NewBoolQuery() // 创建bool查询
- aggsMatch := elastic.NewMatchQuery("link", link) //设置查询条件
- boolQueryToItem.Must(aggsMatch)
- result, _ := hdl.EsSelectOne(context.Background(), EggUserShortLink, boolQueryToItem, false)
- isHas := 0
- if result != nil && len(result.Hits.Hits) > 0 {
- for _, hit := range result.Hits.Hits {
- if hit == nil {
- continue
- }
- jsonByte, _ := hit.Source.MarshalJSON()
- if gjson.Get(string(jsonByte), "short_link").String() != "" {
- isHas = 1
- link = gjson.Get(string(jsonByte), "short_link").String()
- }
- }
- }
- if isHas == 0 {
- send, _ := kuaizhan.KuaizhanSend(svc.GetSysCfgStr("kuaizhan_app_key"), svc.GetSysCfgStr("kuaizhan_app_secret"), link)
- if gjson.Get(send, "url").String() != "" {
- var uniqueId = php2go.Md5(link)
- oldLink := link
- link = gjson.Get(send, "url").String()
- tmp := map[string]interface{}{
- "uid": user.Id,
- "link": oldLink,
- "short_link": link,
- }
- doc, _ := es.FirstDoc(EggUserShortLink, uniqueId)
- if doc == nil {
- es.CreateDoc(EggUserShortLink, uniqueId, tmp)
- } else {
- es.UpdateDoc(EggUserShortLink, uniqueId, tmp)
- }
- }
- }
- res.Link = link
- QRcode := qrcode.GetPNGBase64(link)
- QRcode = strings.ReplaceAll(QRcode, "\u0000", "")
- res.Qrcode = QRcode
- e.OutSuc(c, res, nil)
- return
- }
|