104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 领取点赞奖励
|
|
|
|
func (this *apiComp) ZanreceiveCheck(session comm.IUserSession, req *pb.FriendZanreceiveReq) (errdata *pb.ErrorData) {
|
|
if len(req.FriendIds) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
this.module.Error("参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Zanreceive(session comm.IUserSession, req *pb.FriendZanreceiveReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.ZanreceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
var (
|
|
self *pb.DBFriend
|
|
err error
|
|
)
|
|
|
|
self = this.module.modelFriend.GetFriend(session.GetUserId())
|
|
if self == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSelfNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
var (
|
|
pointTotal int32 // 累计友情值
|
|
)
|
|
|
|
// 是否已领取点赞
|
|
for _, v := range req.FriendIds {
|
|
if _, ok := utils.Find(self.GetZandIds, v); ok {
|
|
self.GetZandIds = utils.Deletex(self.GetZandIds, v)
|
|
pointTotal += 1
|
|
}
|
|
}
|
|
|
|
// 修改获赞Id
|
|
if err = this.module.modelFriend.Change(self.Uid, map[string]interface{}{
|
|
"getZandIds": self.GetZandIds,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//设置自己的友情值
|
|
ue, err := this.module.ModuleUser.GetUserExpand(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 今日获赠的友情点是否达到上限
|
|
if ue.FriendPointID >= int32(this.module.globalConf.FriendMaxgetnum) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendPointLimit,
|
|
Title: pb.ErrorCode_FriendPointLimit.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"friendPoint": ue.FriendPoint + pointTotal,
|
|
"friendPointID": ue.FriendPointID + pointTotal,
|
|
}
|
|
if err := this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), FriendSubTypeZanreceive,
|
|
&pb.FriendZanreceiveResp{Flag: true})
|
|
|
|
return
|
|
}
|