100 lines
2.2 KiB
Go
100 lines
2.2 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 公会创建
|
|
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.SociatyCreateReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.CreateCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
|
|
user, err := this.module.ModuleUser.GetRemoteUser(uid)
|
|
if err != nil {
|
|
this.module.Errorf("GetRmoteUser err:%v", err)
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
if user.Uid == "" {
|
|
this.module.Errorf("GetRmoteUser not found uid:%v", uid)
|
|
code = pb.ErrorCode_UserSessionNobeing
|
|
return
|
|
}
|
|
|
|
userExpand, err := this.module.ModuleUser.GetRemoteUserExpand(uid)
|
|
if err != nil {
|
|
this.module.Errorf("GetRemoteUserExpand err:%v", err)
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
|
|
//检查是否已加入公会
|
|
if userExpand.SociatyId != "" {
|
|
code = pb.ErrorCode_SociatyAdded
|
|
return
|
|
}
|
|
|
|
// CD校验
|
|
|
|
//检查钻石
|
|
if user.Diamond < 500 {
|
|
code = pb.ErrorCode_SociatyDiamondNoEnough
|
|
return
|
|
}
|
|
|
|
//创建公会
|
|
sociaty := &pb.DBSociaty{
|
|
Creater: user.Uid,
|
|
Name: req.Name,
|
|
Icon: req.Icon,
|
|
Notice: req.Notice,
|
|
IsApplyCheck: req.IsApplyCheck,
|
|
ApplyLv: req.ApplyLv,
|
|
}
|
|
|
|
//会长
|
|
sociaty.Members = append(sociaty.Members, &pb.SociatyMember{
|
|
Uid: user.Uid,
|
|
Job: pb.SociatyJob_PRESIDENT, //创建人是会长
|
|
Ctime: time.Now().Unix(),
|
|
})
|
|
if err := this.module.modelSociaty.create(sociaty); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Errorf("创建公会 err:%v", err)
|
|
return
|
|
}
|
|
|
|
// 更新玩家公会
|
|
update := map[string]interface{}{
|
|
"sociatyId": sociaty.Id,
|
|
}
|
|
|
|
if err = this.module.ModuleUser.ChangeRemoteUserExpand(user.Uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Errorf("更新玩家公会ID err:%v", err)
|
|
return
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeCreate, &pb.SociatyCreateResp{
|
|
Id: sociaty.Id,
|
|
Uid: uid,
|
|
}); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
return
|
|
}
|