印度包网
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.

221 lines
5.8 KiB

1 year ago
package handler
import (
"fmt"
"reflect"
"server/call"
"server/common"
"server/db"
"server/modules/web/app"
"server/modules/web/values"
"time"
"github.com/gin-gonic/gin"
"github.com/liangdas/mqant/log"
"gorm.io/gorm"
)
func GetUserInfo(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.GetUserInfoReq)
if !a.S(req) {
return
}
uid := a.UID
if req.UID > 0 {
uid = req.UID
}
pd := &common.PlayerData{UID: uid}
db.Mysql().Get(pd)
ret, err := call.GetUserXInfo(uid, "avatar", "nick", "mobile", "birth")
if err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
resp := values.UserInfoResp{
UID: uid,
Nick: ret.Nick,
Avatar: ret.Avatar,
VIPLevel: call.GetVIP(uid).Level,
Currencys: make(map[common.CurrencyType]int64),
Feedback: pd.FeedbackTime > 0,
NewPddShare: call.HasNewAcitivityPddShare(a.UID),
Birth: ret.Birth,
Phone: ret.Mobile,
CurrentVip: &values.OneUserInfoVip{},
NextVip: &values.OneUserInfoVip{},
}
resp.Activitys.RechargeBack = call.ShouldShowActivityFirstRechargeBack(uid)
resp.Activitys.DaySign = call.ShouldShowActivitySign(uid)
resp.Activitys.WeekCard = call.ShouldShowActivityWeekCard(uid)
resp.Activitys.LuckyShop = call.ShouldShowActivityLuckShop(uid)
vip := call.GetVipCon(a.UID)
nextVip := call.GetConfigVIPByLevel(vip.Level + 1)
resp.CurrentVip.Bonus = vip.Bonus
resp.CurrentVip.Cashback = vip.Cashback
resp.CurrentVip.WithdrawFee = vip.Fee
// resp.CurrentVip.Cashback = util.FormatFloat(float64(vip.Cashback)/10, 2) + "%"
// resp.CurrentVip.WithdrawFee = util.FormatFloat(float64(vip.Fee)/10, 2) + "%"
if nextVip != nil {
resp.NextVip.Bonus = nextVip.Bonus
resp.NextVip.Cashback = nextVip.Cashback
resp.NextVip.WithdrawFee = nextVip.Fee
// resp.NextVip.Cashback = util.FormatFloat(float64(nextVip.Cashback)/10, 2) + "%"
// resp.NextVip.WithdrawFee = util.FormatFloat(float64(nextVip.Fee)/10, 2) + "%"
} else {
resp.NextVip = resp.CurrentVip
}
if pd.LastAppSpinDraw == 0 {
resp.AppSpinCount++
}
// call.GetUserCurrency()
currency := &common.PlayerCurrency{UID: uid}
db.Mysql().Get(currency)
// currencyRe := &common.PlayerCurrency{UID: uid}
// db.Mysql().C().Table(common.PlayerRechargeTableName).Where("uid = ?", uid).Scan(currencyRe)
ref := reflect.ValueOf(currency).Elem()
// refRe := reflect.ValueOf(currencyRe).Elem()
for i := common.CurrencyTypeZero + 1; i < common.CurrencyAll; i++ {
if i == common.CurrencyUSDT {
continue
}
resp.Currencys[i] = ref.Field(int(i) + 1).Int()
}
// 一些参数只发给玩家自己
// if req.UID <= 0 {
re := &common.RechargeInfo{UID: uid}
db.Mysql().Get(re)
resp.Recharge = re.TotalRecharge
a.Code = values.CodeOK
// }
a.Data = resp
}
func EditUserInfo(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.EditUserInfoReq)
if !a.S(req) {
return
}
if req.Avatar == nil && req.Nick == nil {
a.Code = values.CodeParam
return
}
tx := db.Mysql().Begin()
uid := a.UID
defer func() {
a.MCommit(tx)
}()
update := map[string]interface{}{}
if req.Nick != nil {
if !call.IsUserNickValid(*req.Nick) {
a.Code = values.CodeNickInvalid
return
}
// pd := &common.PlayerData{UID: uid}
// db.Mysql().Get(pd)
// if pd.LastNickEdit > 0 {
// if time.Now().Unix()-pd.LastNickEdit < 24*60*60 {
// a.Code = values.CodeNickEditBusy
// return
// }
// if _, err := call.UpdateCurrencyAndNotify(&common.UpdateCurrencyNotify{
// UID: uid,
// Event: common.CurrencyEventChangeNick,
// Pairs: []*common.CurrencyPair{{Type: common.CurrencyTypeCash, Value: -200}},
// }, true, tx); err != nil {
// log.Error("err:%v", err)
// a.Code = values.CodeRetry
// return
// }
// }
// if err := tx.Model(pd).Where("uid = ? and last_nick_edit = ?", uid, pd.LastNickEdit).Updates(&common.PlayerData{LastNickEdit: time.Now().Unix()}).Error; err != nil {
// log.Error("err:%v", err)
// a.Code = values.CodeRetry
// return
// }
update["nick"] = *req.Nick
}
if req.Avatar != nil {
update["avatar"] = *req.Avatar
}
search := &common.PlayerDBInfo{Id: uid}
if err := tx.Model(search).Where(search).Updates(update).Error; err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
if err := db.Redis().UpdateUserFields(uid, update); err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
}
func Feedback(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.FeedbackReq)
if !a.S(req) {
return
}
if len(req.List) == 0 {
return
}
// questions := []int{}
// all := []values.OneFeedback{}
for _, v := range req.List {
for _, j := range v.Choose {
if j == 0 && v.Context == "" {
a.Code = values.CodeParam
a.Msg = "context should not be empty."
return
}
}
// if !util.SliceContain(questions, v.Index) {
// questions = append(questions, v.Index)
// all = append(all, v)
// }
}
pd := &common.PlayerData{UID: a.UID}
db.Mysql().Get(pd)
if pd.FeedbackTime > 0 {
a.Code = values.CodeRetry
return
}
now := time.Now().Unix()
rows, err := db.Mysql().UpdateResW(&common.PlayerData{}, map[string]interface{}{"feedback_time": now}, fmt.Sprintf("uid = %d and feedback_time = 0", a.UID))
if err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
if rows == 0 {
a.Code = values.CodeRetry
return
}
call.GetAcitivityPddData(a.UID)
db.Mysql().Update(&common.PddData{UID: a.UID}, map[string]interface{}{"spin": gorm.Expr("spin + 1")})
for _, v := range req.List {
for _, j := range v.Choose {
db.ES().InsertToESGO(common.ESIndexBackFeedback, &common.ESFeedback{
UID: a.UID,
QuestionIndex: v.Index,
Choose: j,
Context: v.Context,
Time: now,
})
}
}
}