|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/es/hdl"
- md2 "applet/app/es/md"
- "applet/app/lib/auth"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "applet/app/utils/cache"
- "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/baidu"
- md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
- md4 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
- es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
- "context"
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/olivere/elastic/v7"
- "github.com/syyongx/php2go"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- // 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 绑定成功后 加群之类的怎么处理
- if ownUser.ParentUid > 0 {
- //TODO::推入mq异步处理
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err != nil {
- e.OutErr(c, e.ERR_INIT_RABBITMQ, err.Error())
- return
- }
- defer ch.Release()
- ch.Publish(md4.EggAppExchange, md4.AddPublicPlatoonUserRelationCommissionReq{RecommendUid: utils.Int64ToStr(ownUser.ParentUid), Uid: utils.Int64ToStr(ownUser.Id)}, md4.EggRoutKeyForAddPublicPlatoonUserRelationCommission)
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // BindUserInfo
- // @Summary 绑定用户信息
- // @Tags 会员中心
- // @Description 绑定用户信息
- // @Accept json
- // @Produce json
- // @Param req body md.WechatAccountUserInfoReq true "注册参数"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/bindUserInfo [post]
- func BindUserInfo(c *gin.Context) {
- var req md.WechatAccountUserInfoReq
- 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.WechatAccount == "" {
- e.OutErr(c, 400, e.NewErr(400, "微信号不能为空"))
- return
- }
- ownUser := svc.GetUser(c)
- cols := ""
- if req.Nickname != "" {
- ownUser.Nickname = req.Nickname
- cols += ",nickname"
- }
- if req.HeadImg != "" {
- ownUser.Avatar = req.HeadImg
- cols += ",avatar"
- }
- if req.WechatAccount != "" {
- ownUser.WechatAccount = req.WechatAccount
- cols += ",wechat_account"
- }
- if cols == "" {
- e.OutErr(c, 400, e.NewErr(400, "修改失败"))
- return
- }
- _, err = db.Db.Where("id=?", ownUser.Id).Cols(cols[1:]).Update(ownUser)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "修改失败"))
- return
- }
- 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() != "" && gjson.Get(string(jsonByte), "date").Int() > time.Now().Unix() {
- isHas = 1
- link = gjson.Get(string(jsonByte), "short_link").String()
- }
- }
- }
- if isHas == 0 {
- url, _ := baidu.BaiduShortenUrl(svc.GetSysCfgStr("baidu_token"), link)
- if url != "" {
- var uniqueId = php2go.Md5(link)
- oldLink := link
- link = url
- tmp := map[string]interface{}{
- "uid": user.Id,
- "link": oldLink,
- "short_link": link,
- "date": time.Now().Unix() + 365*86400,
- }
- 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
- }
-
- // ParentInfo
- // @Summary 导师信息
- // @Tags 会员中心
- // @Description 导师信息
- // @Accept json
- // @Produce json
- // @Success 200 {object} md.ParentInfo "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/parentInfo [get]
- func ParentInfo(c *gin.Context) {
- ownUser := svc.GetUser(c)
- if ownUser.ParentUid == 0 {
- e.OutSuc(c, md.ParentInfo{}, nil)
- return
- }
- NewUserDb := implement.NewUserDb(db.Db)
- user, _ := NewUserDb.GetUser(ownUser.ParentUid)
- // 1. 获取会员等级名称
- userLevelDb := implement.NewUserLevelDb(db.Db)
- level, err := userLevelDb.UserLevelByID(user.Level)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, nil)
- return
- }
- code := user.SystemInviteCode
- if user.CustomInviteCode != "" {
- code = user.CustomInviteCode
- }
- res := md.ParentInfo{
- Nickname: user.Nickname,
- LevelName: level.LevelName,
- InviteCode: code,
- HeadImg: svc.GetOssUrl(user.Avatar),
- Id: utils.Int64ToStr(user.Id),
- Phone: user.Phone,
- WechatAccount: user.WechatAccount,
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- // Delete
- // @Summary 注销账号操作
- // @Tags 账号与安全
- // @Description 注销账号操作
- // @Accept json
- // @Produce json
- // @Param req body md.DeleteUserReq true "注册参数"
- // @Success 200 string "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/delete [post]
- func Delete(c *gin.Context) {
- var req md.DeleteUserReq
- 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.State = 3
- db.Db.Where("id=?", user.Id).Cols("state").Update(user)
- tmp := model.UserDeleteInfo{
- Uid: int(user.Id),
- Phone: user.Phone,
- CreateAt: time.Now(),
- }
- db.Db.Insert(&tmp)
- ch, err := rabbit.Cfg.Pool.GetChannel()
- if err == nil {
- defer ch.Release()
- err = ch.PublishV2(md.EggUserExchange, md.CommUserId{
- Uid: utils.Int64ToStr(user.Id),
- ParentUid: utils.Int64ToStr(user.ParentUid),
- }, md.EggUserDelete)
- if err != nil {
- ch.PublishV2(md.EggUserExchange, md.CommUserId{
- Uid: utils.Int64ToStr(user.Id),
- ParentUid: utils.Int64ToStr(user.ParentUid),
- }, md.EggUserDelete)
- }
- }
- // 清掉token
- cacheKey := fmt.Sprintf(auth.TokenKey, user.Id)
- _, err = cache.SetEx(cacheKey, "", 1)
- e.OutSuc(c, "success", nil)
- return
- }
-
- // DeleteInfo
- // @Summary 注销账号信息
- // @Tags 账号与安全
- // @Description 注销账号信息
- // @Accept json
- // @Produce json
- // @Success 200 {object} md.UserDeleteInfo "登录成功返回"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/delete/info [get]
- func DeleteInfo(c *gin.Context) {
- user := svc.GetUser(c)
- resp := md.UserDeleteInfo{
- Url: fmt.Sprintf("%s%s?id=%s&is_hide=1", svc.GetSysCfgStr("wap_host"), "/#/pages/course-detail-page/course-detail-page", "115"),
- }
- extendUserCount, _ := db.Db.Where("parent_uid=?", user.Id).Count(&model.User{})
- NewUserWalletDb := implement.NewUserWalletDb(db.Db)
- walletAmount := "0"
- wallet, _ := NewUserWalletDb.GetUserVirtualWallet(user.Id)
- if wallet != nil {
- walletAmount = wallet.Amount
- }
- NewUserVirtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
- virtualWallet, _ := NewUserVirtualAmountDb.GetUserVirtualAllWallets(user.Id)
- virtualAmount1 := "0"
- virtualAmount2 := "0"
- virtualAmount3 := "0"
- settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
- setting, _ := settingDb.EggEnergyBasicSettingGetOne()
- if virtualWallet != nil {
- for _, v := range *virtualWallet {
- if v.CoinId == setting.PersonEggPointsCoinId {
- virtualAmount3 = utils.Float64ToStrPrec8(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(virtualAmount3))
- }
- if v.CoinId == setting.TeamEggPointsCoinId {
- virtualAmount3 = utils.Float64ToStrPrec8(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(virtualAmount3))
- }
- if v.CoinId == setting.PersonEggEnergyCoinId {
- virtualAmount2 = utils.Float64ToStrPrec8(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(virtualAmount2))
- }
- if v.CoinId == setting.TeamEggEnergyCoinId {
- virtualAmount2 = utils.Float64ToStrPrec8(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(virtualAmount2))
- }
- if v.CoinId == setting.ContributionCoinId {
- virtualAmount1 = utils.Float64ToStrPrec8(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(virtualAmount1))
- }
- }
- }
- score := 60.00
- now := time.Now()
- esIndex := es2.GetLatestEffectiveIndexFromAlias(now)
- esIndexName := md3.EggEnergyUserEggScoreEsAlias + "_" + esIndex
- results, _ := es.FirstDoc(esIndexName, esIndex+"_"+utils.Int64ToStr(user.Id))
- if results != nil {
- var doc md.UserEggFlowReqRespList
- json.Unmarshal(results.Source, &doc)
- score = doc.ScoreValue
- }
- uid := user.Id
- sql := fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid1 = %d OR father_uid2= %d OR father_uid3= %d OR father_uid4= %d OR father_uid5= %d OR father_uid6= %d OR father_uid7= %d OR father_uid8= %d OR father_uid9= %d", uid, uid, uid, uid, uid, uid, uid, uid, uid)
- nativeString1, _ := db.QueryNativeString(db.Db, sql)
- hasUserCount := "0"
- if len(nativeString1) > 0 {
- hasUserCount = nativeString1[0]["total"]
- }
- info := []md.UserDeleteInfoList{
- {Title: "贡献值", Content: "贡献值 " + virtualAmount1},
- {Title: "能量值", Content: "能量值 " + virtualAmount2},
- {Title: "活跃值", Content: "活跃值 " + virtualAmount3},
- {Title: "蛋蛋分", Content: "蛋蛋分 " + utils.Float64ToStr(score)},
- {Title: "余额", Content: "余额 " + walletAmount},
- {Title: "直推好友", Content: "直推好友 " + utils.Int64ToStr(extendUserCount) + " 人"},
- {Title: "团队", Content: "团队 " + hasUserCount + " 人"},
- }
- resp.Info = info
- e.OutSuc(c, resp, nil)
- return
- }
|