54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) CustomerCheck(session comm.IUserSession, req *pb.SmithyCustomerReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerReq) (code pb.ErrorCode, data proto.Message) {
|
|
customerCount := this.module.configure.GetGlobalConf().SmithyMaxNpc
|
|
if customerCount <= 0 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
cus, err := this.module.modelTrade.getDBCustomer(session.GetUserId())
|
|
if err != nil {
|
|
if err == mongo.ErrNoDocuments {
|
|
c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount) //3个顾客
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
cus = c
|
|
} else {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
|
|
if utils.IsFirstTody(cus.LastRefreshTime) {
|
|
this.module.modelTrade.DelByUId(session.GetUserId())
|
|
c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
cus = c
|
|
}
|
|
|
|
rsp := &pb.SmithyCustomerResp{
|
|
Customers: cus.Customers,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "customer", rsp)
|
|
return
|
|
}
|