114 lines
3.1 KiB
Go
114 lines
3.1 KiB
Go
// package 更新任务触发后的数据更新
|
|
package rtask
|
|
|
|
import (
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 覆盖更新
|
|
func (this *ModelRtaskRecord) overrideUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) {
|
|
var paramLen int
|
|
if paramLen, err = lenParam(cfg, vals...); err != nil {
|
|
return err
|
|
}
|
|
|
|
// record := &pb.DBRtaskRecord{Uid: uid}
|
|
// if err := this.Get(uid, record); err != nil {
|
|
// if err == mongo.ErrNoDocuments {
|
|
// record.Id = primitive.NewObjectID().Hex()
|
|
// record.Ctime = configure.Now().Unix()
|
|
// if err := this.Add(uid, record); err != nil {
|
|
// return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
|
|
// }
|
|
// } else {
|
|
// return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
|
|
// }
|
|
// }
|
|
|
|
if this.record.Vals == nil {
|
|
this.record.Vals = make(map[int32]*pb.RtaskData)
|
|
}
|
|
|
|
if v, ok := this.record.Vals[cfg.Id]; ok {
|
|
v.Data = hasUpdateData(paramLen, v, vals...)
|
|
// if len(v.Data) > 0 {
|
|
// update := map[string]interface{}{
|
|
// "vals": record.Vals,
|
|
// }
|
|
// if err = this.Change(uid, update); err != nil {
|
|
// this.moduleRtask.Error("更新失败",
|
|
// log.Field{Key: "uid", Value: uid},
|
|
// log.Field{Key: "update", Value: update})
|
|
// return
|
|
// }
|
|
// }
|
|
} else {
|
|
data := &pb.RtaskData{
|
|
Rtype: cfg.Type,
|
|
Data: toMap(vals...),
|
|
Timestamp: configure.Now().Unix(),
|
|
}
|
|
this.record.Vals[cfg.Id] = data
|
|
|
|
// update := map[string]interface{}{
|
|
// "vals": record.Vals,
|
|
// }
|
|
|
|
// if err = this.Change(uid, update); err != nil {
|
|
// this.moduleRtask.Error("更新失败",
|
|
// log.Field{Key: "uid", Value: uid},
|
|
// log.Field{Key: "update", Value: update})
|
|
// return
|
|
// }
|
|
}
|
|
return
|
|
}
|
|
|
|
// 累计更新 - 招募等
|
|
func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData, vals ...int32) (err error) {
|
|
// record := &pb.DBRtaskRecord{Uid: uid}
|
|
// err = this.Get(uid, record)
|
|
// if err != nil {
|
|
// if err == mongo.ErrNoDocuments {
|
|
// record.Id = primitive.NewObjectID().Hex()
|
|
// record.Ctime = configure.Now().Unix()
|
|
// if err := this.Add(uid, record); err != nil {
|
|
// return errors.Wrapf(err, "创建玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
|
|
// }
|
|
// } else {
|
|
// return errors.Wrapf(err, "获取玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
|
|
// }
|
|
// }
|
|
|
|
if this.record.Vals == nil {
|
|
this.record.Vals = make(map[int32]*pb.RtaskData)
|
|
}
|
|
//查找任务数据
|
|
if v, ok := this.record.Vals[cfg.Id]; ok {
|
|
newArr := make([]int32, len(vals))
|
|
copy(newArr, vals)
|
|
srcCount := v.Data[0]
|
|
newArr[0] = srcCount + vals[0]
|
|
v.Data = toMap(newArr...)
|
|
v.Timestamp = configure.Now().Unix()
|
|
|
|
// update := map[string]interface{}{
|
|
// "vals": record.Vals,
|
|
// }
|
|
// err = this.Change(uid, update)
|
|
} else {
|
|
this.record.Vals[cfg.Id] = &pb.RtaskData{
|
|
Data: toMap(vals...),
|
|
Rtype: cfg.Type,
|
|
Timestamp: configure.Now().Unix(),
|
|
}
|
|
// update := map[string]interface{}{
|
|
// "vals": record.Vals,
|
|
// }
|
|
// err = this.Change(uid, update)
|
|
}
|
|
return
|
|
}
|