Commit e4e37dfc authored by chenweijian's avatar chenweijian

Merge remote-tracking branch 'origin/master' into feature/trtc

parents a4c43c34 05a557cb
......@@ -2,7 +2,6 @@ package group_cron
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"github.com/robfig/cron"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m"
......@@ -30,9 +29,6 @@ func GroupPowerExpClear() {
})
// 每月20号发家族即将过期通知
spec = "0 0 0 20 * ?"
if !config.AppIsRelease() {
spec = "0 0 */1 * * ?"
}
_ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil()
_ = group_power_ev.PublishGroupPowerExpireNotice(model, &group_power_ev.GroupPowerExpireNoticeEvent{})
......
......@@ -80,6 +80,7 @@ func RoomLivingIn(model *domain.Model, groupUid string, userId uint64, externalI
}
go func(myContext *mycontext.MyContext, groupId string) {
model := domain.CreateModelContext(myContext) // 野协程给新的model.Db
roomOnlineUser, err := GetRoomOnlineUser(myContext, groupId)
if err != nil {
myContext.Log.Errorf("room RoomLivingIn roomOnlineUser err:%+v, groupUid:%v", err, groupId)
......
package mic_m
import (
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
......@@ -17,14 +18,15 @@ type UserOnMic struct {
LastCalTs int64
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
Tz timezone_e.Timezone
}
// 获取用户当日上麦
// 允许返回gorm.ErrRecordNotFound
func GetUserOnMic(model *domain.Model, userId mysql.ID) (*UserOnMic, error) {
func GetUserOnMic(model *domain.Model, userId mysql.ID, tz timezone_e.Timezone) (*UserOnMic, error) {
res := new(UserOnMic)
day := time.Now().Format("2006-01-02")
if err := model.DB().Where("date = ? AND user_id = ?", day, userId).First(res).Error; err != nil {
if err := model.DB().Where("date = ? AND user_id = ? AND tz = ?", day, userId, tz).First(res).Error; err != nil {
return nil, err
}
return res, nil
......@@ -34,13 +36,14 @@ func GetUserOnMic(model *domain.Model, userId mysql.ID) (*UserOnMic, error) {
// 事务操作
func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64) error {
return model.Transaction(func(model *domain.Model) error {
omMic, err := GetUserOnMic(model, userId)
for _, tz := range timezone_e.Timezones {
omMic, err := GetUserOnMic(model, userId, tz)
if err != nil && err != gorm.ErrRecordNotFound {
return err
}
curTs := joinMicTimestamp
nowTs := time.Now().Unix()
day0Ts := utils.GetZeroTime(time.Now()).Unix()
day0Ts := utils.GetZeroTime(time.Now().In(timezone_e.TimezoneLocMap[tz])).Unix()
if omMic != nil && joinMicTimestamp < omMic.LastCalTs { // 加入的时间比上次计算时间小
curTs = omMic.LastCalTs
}
......@@ -49,15 +52,16 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
curTs = day0Ts
}
score := nowTs - curTs
day := time.Now().Format("2006-01-02")
day := time.Now().In(timezone_e.TimezoneLocMap[tz]).Format("2006-01-02")
onMicNew := &UserOnMic{
Date: day,
UserId: userId,
Seconds: mysql.Num(score),
LastCalTs: nowTs,
Tz: tz,
}
if err := model.DB().Model(UserOnMic{}).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "date"}, {Name: "user_id"}},
Columns: []clause.Column{{Name: "date"}, {Name: "user_id"}, {Name: "tz"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"seconds": gorm.Expr("seconds + ?", onMicNew.Seconds),
"last_cal_ts": nowTs,
......@@ -66,16 +70,32 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
model.Log.Errorf("IncrUserOnMic fail:%v", err)
return err
}
}
return nil
})
}
// 批量获取用户上麦时长
// @return userId->seconds
func MGetUserOnMicSeconds(model *domain.Model, day string, userIds []uint64) (map[mysql.ID]mysql.Num, error) {
func MGetUserOnMicSeconds(model *domain.Model, day string, tz timezone_e.Timezone, userIds []uint64) (map[mysql.ID]mysql.Num, error) {
var rows []UserOnMic
res := make(map[mysql.ID]mysql.Num)
if err := model.DB().Model(UserOnMic{}).Where("`date`= ? AND tz = ? AND user_id in ?", day, tz, userIds).Find(&rows).Error; err != nil {
model.Log.Errorf("MGetUserOnMic fail:%v", err)
return res, err
}
for _, r := range rows {
res[r.UserId] = r.Seconds
}
return res, nil
}
// 批量获取用户上麦时长
// @return userId->seconds
func MGetUserOnMicSecondsRange(model *domain.Model, beginDate, endDate string, tz timezone_e.Timezone, userIds []uint64) (map[mysql.ID]mysql.Num, error) {
var rows []UserOnMic
res := make(map[mysql.ID]mysql.Num)
if err := model.DB().Model(UserOnMic{}).Where("`date`= ? AND user_id in ?", day, userIds).Find(&rows).Error; err != nil {
if err := model.DB().Model(UserOnMic{}).Where("`date` >= ? AND `date` <= ? AND tz = ? AND user_id in ?", beginDate, endDate, tz, userIds).Find(&rows).Error; err != nil {
model.Log.Errorf("MGetUserOnMic fail:%v", err)
return res, err
}
......
......@@ -8,6 +8,7 @@ import (
"hilo-group/domain/model/diamond_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
)
......@@ -24,6 +25,22 @@ func NewDiamondService(myContext *mycontext.MyContext) *DiamondService {
// 币商转账钻石-家族限制检查
func (this *DiamondService) CheckDealerTransferFamilyLimit(dealerId, userId uint64, lang string) error {
model := domain.CreateModelContext(this.svc.MyContext)
//获取国家信息
_, dealerArea, err := user_m.GetUserCountryArea(model, dealerId)
if err != nil {
model.Log.Errorf("CheckDealerTransferFamilyLimit 获取国家资源错误 dealerId:%d, err:%v", dealerId, err)
return err
}
_, area, err := user_m.GetUserCountryArea(model, userId)
if err != nil {
model.Log.Errorf("CheckDealerTransferFamilyLimit 获取国家资源错误 userId:%d, err:%v", userId, err)
return err
}
if dealerArea != area {
return bizerr.DealerCannotSaleToOtherArea
}
// 代理、用户是否加入了家族
dealerFamily, err := groupPower_m.GetGroupPowerUserOrNil(model, dealerId)
if err != nil {
......@@ -40,25 +57,25 @@ func (this *DiamondService) CheckDealerTransferFamilyLimit(dealerId, userId uint
return err
}
// 用户的家族是否有家族代理
var userHasFamilyAgent bool
if userFamily != nil {
userHasFamilyAgent, err = groupPower_m.IsGroupPowerHasFamilyAgent(model, userFamily.GroupPowerId)
if err != nil {
return err
}
}
//var userHasFamilyAgent bool
//if userFamily != nil {
// userHasFamilyAgent, err = groupPower_m.IsGroupPowerHasFamilyAgent(model, userFamily.GroupPowerId)
// if err != nil {
// return err
// }
//}
if dealerFamily != nil && dealerFamily.GroupPowerId > 0 { // 代理加入了家族
if isFamilyAgent && (userFamily == nil || userFamily.GroupPowerId != dealerFamily.GroupPowerId) { // 是家族代理:只能向本家族成员转移钻石,如果向非家族成员转移钻石,则提示“非家族成员”
return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_NOT_FAMILY_MEMBER, lang, bizerr.GroupPowerDealerNotMember))
}
if !isFamilyAgent && userHasFamilyAgent { // 不是家族代理:如果用户加入了家族,且家族中有家族代理,那么也不能,“此用户已有家族代理,不能出售钻石”
return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
}
//if !isFamilyAgent && userHasFamilyAgent { // 不是家族代理:如果用户加入了家族,且家族中有家族代理,那么也不能,“此用户已有家族代理,不能出售钻石”
// return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
//}
} else { // 代理没有加入家族的
// 普通代理:不能向已经加入家族的成员(并且家族有家族代理)转移钻石,如果转移则提示“此用户已有家族代理,不能出售钻石”
if userHasFamilyAgent {
return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
}
//if userHasFamilyAgent {
// return myerr.WrapErr(res_m.GetErrByLanguage(model.Db, common.MSG_ID_DEALER_CAN_NOT_SOLE, lang, bizerr.GroupPowerDealerCanNotSole))
//}
}
return nil
}
......@@ -94,6 +94,7 @@ var (
GroupPowerChangeNameplate = myerr.NewBusinessCode(15021, "Can only be modified at the silver level", myerr.BusinessData{}) // 修改铭牌不够等级
GroupPowerMemberMax = myerr.NewBusinessCode(15022, "The family size has reached the upper limit", myerr.BusinessData{}) // 家族人数达到上限
GroupPowerCannotJoin = myerr.NewBusinessCode(15023, "You cannot join", myerr.BusinessData{}) // 不能加入家族
DealerCannotSaleToOtherArea = myerr.NewBusinessCode(15024, "Fail", myerr.BusinessData{}) // 代理转账失败-不同地区
TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{})
......
......@@ -53,37 +53,38 @@ import (
// @Router /v1/groupPower/user [post]
func GroupPowerJoin(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
return myContext, bizerr.UpgradeRequired
// 旧版本(3.5.0以下),提示升级
//_, major, minor, _, err := GetAppVersion(c)
//_, major, minor, _, err := req.GetAppVersion(c)
//if err != nil {
// return myContext, err
//}
//if major <= 3 && minor < 5 {
// return myContext, bizerr.UpgradeRequired
//}
groupPowerId, err := strconv.ParseUint(c.PostForm("groupPowerId"), 10, 64)
if err != nil {
return myContext, err
}
//获取用户
userId, err := req.GetUserId(c)
if err != nil {
return myContext, err
}
// Aoxi要求不能让这些人加入家族
banUserMap := map[uint64]bool{251: true, 1384611: true, 4223511: true, 4338751: true, 4339471: true, 4339541: true,
4354581: true, 6541: true, 23971: true}
if _, ok := banUserMap[userId]; ok {
return myContext, bizerr.GroupPowerCannotJoin
}
if err := group_power_s.NewGroupPowerService(myContext).GroupPowerUserJoin(groupPowerId, userId); err != nil {
return myContext, err
}
resp.ResponseOk(c, nil)
return myContext, nil
//
//groupPowerId, err := strconv.ParseUint(c.PostForm("groupPowerId"), 10, 64)
//if err != nil {
// return myContext, err
//}
////获取用户
//userId, err := req.GetUserId(c)
//if err != nil {
// return myContext, err
//}
//
//// Aoxi要求不能让这些人加入家族
//banUserMap := map[uint64]bool{251: true, 1384611: true, 4223511: true, 4338751: true, 4339471: true, 4339541: true,
// 4354581: true, 6541: true, 23971: true}
//if _, ok := banUserMap[userId]; ok {
// return myContext, bizerr.GroupPowerCannotJoin
//}
//
//if err := group_power_s.NewGroupPowerService(myContext).GroupPowerUserJoin(groupPowerId, userId); err != nil {
// return myContext, err
//}
//resp.ResponseOk(c, nil)
//return myContext, nil
}
// @Tags 国家势力
......@@ -1024,7 +1025,7 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
} else {
for _, v := range mgrList {
// 发小助手通知用户
go msg.SendLittleAssistantMsg(model, v, msg_e.GroupPowerApplyJoinMsg, "", "", "", "", "")
msg.SendLittleAssistantMsg(model, v, msg_e.GroupPowerApplyJoinMsg, "", "", "", "", "")
}
}
......
package mic_r
import (
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
......@@ -12,12 +13,14 @@ import (
type MGetUserOnMicSecondsReq struct {
Day string `form:"day" binding:"required"`
Ids []mysql.ID `form:"ids" binding:"required"`
Tz timezone_e.Timezone `form:"tz"`
}
// @Tags 麦位-内部
// @Summary 批量获取用户天上麦时长
// @Param day query string true "天 格式2006-001-02"
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Param tz query string false "时区 0:北京时间(默认) 1:沙特时间"
// @Success 200 {object} map[uint64]uint32
// @Router /inner/mic/onMicSeconds [get]
func MGetUserOnMicSeconds(c *gin.Context) (*mycontext.MyContext, error) {
......@@ -27,7 +30,38 @@ func MGetUserOnMicSeconds(c *gin.Context) (*mycontext.MyContext, error) {
if err := c.ShouldBindQuery(&req); err != nil {
return myCtx, err
}
onMic, err := mic_m.MGetUserOnMicSeconds(model, req.Day, req.Ids)
onMic, err := mic_m.MGetUserOnMicSeconds(model, req.Day, req.Tz, req.Ids)
if err != nil {
return myCtx, err
}
response := onMic
resp.ResponseOk(c, response)
return myCtx, nil
}
type MGetUserOnMicSecondsRangeReq struct {
BeginDate string `form:"beginDate" binding:"required"`
EndDate string `form:"endDate" binding:"required"`
Ids []mysql.ID `form:"ids" binding:"required"`
Tz timezone_e.Timezone `form:"tz"`
}
// @Tags 麦位-内部
// @Summary 批量获取用户范围上麦时长
// @Param beginDate query string true "天 格式2006-001-02"
// @Param endDate query string true "天 格式2006-001-02"
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Param tz query string false "时区 0:北京时间(默认) 1:沙特时间"
// @Success 200 {object} map[uint64]uint32
// @Router /inner/mic/onMicSeconds/range [get]
func MGetUserOnMicSecondsRange(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
var model = domain.CreateModelContext(myCtx)
var req MGetUserOnMicSecondsRangeReq
if err := c.ShouldBindQuery(&req); err != nil {
return myCtx, err
}
onMic, err := mic_m.MGetUserOnMicSecondsRange(model, req.BeginDate, req.EndDate, req.Tz, req.Ids)
if err != nil {
return myCtx, err
}
......
......@@ -161,6 +161,7 @@ func InitRouter() *gin.Engine {
innerMic := inner.Group("/mic")
{
innerMic.GET("/onMicSeconds", wrapper(mic_r.MGetUserOnMicSeconds))
innerMic.GET("/onMicSeconds/range", wrapper(mic_r.MGetUserOnMicSecondsRange))
}
r.GET("/test", wrapper(group_power_r.Test))
return r
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment