Merge branch 'bs_2.0.6.28' of http://git.legu.cc/liwei_3d/go_dreamfactory into bs_2.0.6.28
This commit is contained in:
commit
4a793aab9e
@ -9,14 +9,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 刷新
|
// 刷新
|
||||||
func (a *apiComp) RefreshCheck(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) RefreshCheck(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
func (this *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) {
|
||||||
|
var (
|
||||||
d := a.module.modelDispatch.getDBDispatch(session.GetUserId())
|
info *pb.DBDispatch
|
||||||
if d == nil {
|
need []*cfg.Gameatn
|
||||||
|
)
|
||||||
|
info = this.module.modelDispatch.getDBDispatch(session.GetUserId())
|
||||||
|
if info == nil {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_DataNotFound,
|
Code: pb.ErrorCode_DataNotFound,
|
||||||
Title: pb.ErrorCode_DataNotFound.ToString(),
|
Title: pb.ErrorCode_DataNotFound.ToString(),
|
||||||
@ -24,10 +27,10 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Nb != nil {
|
if info.Nb != nil {
|
||||||
if d.Nb.FreeCount > 0 {
|
if info.Nb.FreeCount > 0 {
|
||||||
//更新刷新次数
|
//更新刷新次数
|
||||||
if err := a.module.modelDispatch.updateFreeCount(session.GetUserId(), d.Nb); err != nil {
|
if err := this.module.modelDispatch.updateFreeCount(session.GetUserId(), info.Nb); err != nil {
|
||||||
var customer = new(comm.CustomError)
|
var customer = new(comm.CustomError)
|
||||||
var code pb.ErrorCode
|
var code pb.ErrorCode
|
||||||
if errors.As(err, &customer) {
|
if errors.As(err, &customer) {
|
||||||
@ -47,24 +50,28 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
refreshCount := a.module.ModuleTools.GetGlobalConf().DispatchRefreshtimes
|
refreshCount := this.module.ModuleTools.GetGlobalConf().DispatchRefreshtimes
|
||||||
if d.Nb.RefreshCount >= refreshCount {
|
if info.Nb.RefreshCount >= refreshCount {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_DispatchRefreshMax,
|
Code: pb.ErrorCode_DispatchRefreshMax,
|
||||||
Title: pb.ErrorCode_DispatchRefreshMax.ToString(),
|
Title: pb.ErrorCode_DispatchRefreshMax.ToString(),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//消耗金币
|
need = make([]*cfg.Gameatn, 0)
|
||||||
money := a.module.ModuleTools.GetGlobalConf().DispatchCheckmoney
|
money := this.module.ModuleTools.GetGlobalConf().DispatchCheckmoney
|
||||||
if errdata = a.module.CheckRes(session, []*cfg.Gameatn{money}); errdata != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if errdata = a.module.ConsumeRes(session, []*cfg.Gameatn{money}, true); errdata != nil {
|
need = append(need, &cfg.Gameatn{
|
||||||
|
A: money.A,
|
||||||
|
T: money.T,
|
||||||
|
N: money.N * (info.Nb.RefreshCount + 1),
|
||||||
|
})
|
||||||
|
//消耗金币
|
||||||
|
|
||||||
|
if errdata = this.module.ConsumeRes(session, need, true); errdata != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := a.module.modelDispatch.updateRefreshCount(session.GetUserId(), d.Nb); err != nil {
|
if err := this.module.modelDispatch.updateRefreshCount(session.GetUserId(), info.Nb); err != nil {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_DBError,
|
Code: pb.ErrorCode_DBError,
|
||||||
Title: pb.ErrorCode_DBError.ToString(),
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
@ -76,22 +83,22 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//刷新公告(随机新的任务 包括未领取和正在进行的任务)
|
//刷新公告(随机新的任务 包括未领取和正在进行的任务)
|
||||||
tasks, err := a.module.modelDispatch.taskRandom(session.GetUserId(), d)
|
tasks, err := this.module.modelDispatch.taskRandom(session.GetUserId(), info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//更新公告任务
|
//更新公告任务
|
||||||
if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, tasks); err != nil {
|
if err := this.module.modelDispatch.updateTasks(session.GetUserId(), info.Nb, tasks); err != nil {
|
||||||
a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()})
|
this.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp := &pb.DispatchRefreshResp{
|
rsp := &pb.DispatchRefreshResp{
|
||||||
FreeCount: d.Nb.FreeCount,
|
FreeCount: info.Nb.FreeCount,
|
||||||
RefreshCount: d.Nb.RefreshCount,
|
RefreshCount: info.Nb.RefreshCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
session.SendMsg(string(a.module.GetType()), "refresh", rsp)
|
session.SendMsg(string(this.module.GetType()), "refresh", rsp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,20 @@ func IsToday(d int64) bool {
|
|||||||
|
|
||||||
// 判断是否是出于同一周
|
// 判断是否是出于同一周
|
||||||
func IsSameWeek(d int64) bool {
|
func IsSameWeek(d int64) bool {
|
||||||
// 将时间戳转换成一个 time.Time 对象
|
// 将时间戳转换为 time.Time 类型
|
||||||
t1 := time.Unix(d, 0)
|
time1 := time.Unix(d, 0)
|
||||||
t2 := configure.Now()
|
time2 := configure.Now()
|
||||||
|
|
||||||
// 获取 t1 所在的周的第一天和 t2 所在的周的第一天
|
// 获取时间戳所属的年份和周数
|
||||||
t1FirstDay := t1.AddDate(0, 0, -int(t1.Weekday())+1)
|
year1, week1 := time1.ISOWeek()
|
||||||
t2FirstDay := t2.AddDate(0, 0, -int(t2.Weekday())+1)
|
year2, week2 := time2.ISOWeek()
|
||||||
// 判断两个时间所在的周的第一天是否相同
|
|
||||||
return t1FirstDay.Equal(t2FirstDay)
|
// 判断是否同一年同一周
|
||||||
|
if year1 == year2 && week1 == week2 {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否大于1周
|
// 判断是否大于1周
|
||||||
|
Loading…
Reference in New Issue
Block a user