|
|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
|
"go.mongodb.org/mongo-driver/bson" |
|
|
|
"go.mongodb.org/mongo-driver/bson" |
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive" |
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive" |
|
|
|
|
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
@ -17,6 +18,8 @@ import ( |
|
|
|
"tyj_admin/internal/consts" |
|
|
|
"tyj_admin/internal/consts" |
|
|
|
"tyj_admin/internal/dao" |
|
|
|
"tyj_admin/internal/dao" |
|
|
|
"tyj_admin/internal/model/entity" |
|
|
|
"tyj_admin/internal/model/entity" |
|
|
|
|
|
|
|
"tyj_admin/library/libUtils" |
|
|
|
|
|
|
|
"tyj_admin/utils" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func SearchGm(ctx context.Context, req *game.SearchGmReq) (gm int32, err error) { |
|
|
|
func SearchGm(ctx context.Context, req *game.SearchGmReq) (gm int32, err error) { |
|
|
|
@ -424,25 +427,177 @@ func ReviewState(ctx context.Context, req *game.ReviewStateReq) (res *game.Revie |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
res.SmallLayoutBlueprint = stores |
|
|
|
res.SmallLayoutBlueprint = stores |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error) { |
|
|
|
func SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error) { |
|
|
|
|
|
|
|
ip := libUtils.GetClientIp(ctx) |
|
|
|
|
|
|
|
data := []entity.GameRouter{} |
|
|
|
|
|
|
|
err = dao.GameRouter.Ctx(ctx).Where("router_ip=?", ip).Scan(&data) |
|
|
|
|
|
|
|
//log.Printf("data: %s", gjson.MustEncodeString(data))
|
|
|
|
|
|
|
|
if len(data) == 0 { |
|
|
|
|
|
|
|
whiteIps, _ := GetWhiteList(ctx) |
|
|
|
|
|
|
|
if !utils.ContainsWhiteList(whiteIps, ip) { |
|
|
|
|
|
|
|
return nil, gerror.New("ip白名单!") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
res = new(game.SetReviewStateRes) |
|
|
|
res = new(game.SetReviewStateRes) |
|
|
|
res.ServerId = req.ServerId |
|
|
|
res.ServerId = req.ServerId |
|
|
|
mongodb, ok := MongoDatabaseList[fmt.Sprint(req.ServerId)] |
|
|
|
mongodb, ok := MongoDatabaseList[fmt.Sprint(req.ServerId)] |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
g.Log().Info(ctx, "err== db is nil") |
|
|
|
g.Log().Info(ctx, "err== db is nil") |
|
|
|
|
|
|
|
err = errors.New("db is nil") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
filter := bson.M{"ArtID": req.ArtID} |
|
|
|
filter := bson.M{"ArtID": req.ArtID} |
|
|
|
update := bson.M{"State": req.State} |
|
|
|
update := bson.M{"State": req.State, "ArtID": req.ArtID} |
|
|
|
err = mongodb.Collection("SmallLayoutBlueprint").UpdateOne(ctx, filter, bson.M{"$set": update}) |
|
|
|
err = mongodb.Collection("SmallLayoutBlueprint").UpdateOne(ctx, filter, bson.M{"$set": update}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
g.Log().Info(ctx, "err== ", err) |
|
|
|
g.Log().Info(ctx, "err== ", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, _ = mongodb.Collection("SmallLayoutAuditState").UpsertId(ctx, req.ArtID, update) |
|
|
|
|
|
|
|
//g.Log().Info(ctx, "SmallLayoutAuditState == ", result)
|
|
|
|
|
|
|
|
//g.Log().Info(ctx, "err== ", err)
|
|
|
|
res.Result = 1 |
|
|
|
res.Result = 1 |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetOfficialView(ctx context.Context, req *game.GetOfficialViewReq) (res *game.GetOfficialViewRes, err error) { |
|
|
|
|
|
|
|
res = new(game.GetOfficialViewRes) |
|
|
|
|
|
|
|
mongodb, ok := MongoDatabaseList["0"] |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== db is nil") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stores := []map[string]interface{}{} |
|
|
|
|
|
|
|
err = mongodb.Collection("SmallLayoutBlueprint").Find(ctx, bson.M{}).All(&stores) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== ", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(stores) <= 0 { |
|
|
|
|
|
|
|
data := map[string]interface{}{"_id": 0, "data": ""} |
|
|
|
|
|
|
|
stores = append(stores, data) |
|
|
|
|
|
|
|
mongodb.Collection("SmallLayoutBlueprint").InsertOne(ctx, data) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.JsonData = fmt.Sprint(stores[0]["data"]) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func SetOfficialView(ctx context.Context, req *game.SetOfficialViewReq) (res *game.SetOfficialViewRes, err error) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = new(game.SetOfficialViewRes) |
|
|
|
|
|
|
|
//s := "{ \"_t\" : \"System.Collections.Generic.List`1[[PeachValley.OfficialSmallLayoutInfo, Model]]\", \"_v\" : [{ \"BaseInfo\" : { \"ArtID\" : 100013, \"OwnerId\" : 1000000867, \"CreateTime\" : 1760951195, \"LikeInfos\" : [1000000921, 1000000929], \"SubscribeInfos\" : [1000000929], \"ReportInfos\" : [{ \"UnitId\" : 1000000929, \"ReportReason\" : 1 }], \"Name\" : \"富饶之地\", \"State\" : 1, \"SmallLayoutInfos\" : [{ \"GameUnitType\" : 1, \"ConfigId\" : 2, \"Pos\" : { \"x\" : 15, \"y\" : 14 }, \"IsFlip\" : false, \"SkinId\" : 0 }, { \"GameUnitType\" : 1, \"ConfigId\" : 41, \"Pos\" : { \"x\" : 18, \"y\" : 0 }, \"IsFlip\" : false, \"SkinId\" : 0 }, { \"GameUnitType\" : 1, \"ConfigId\" : 21, \"Pos\" : { \"x\" : 0, \"y\" : 15 }, \"IsFlip\" : false, \"SkinId\" : 0 }, { \"GameUnitType\" : 1, \"ConfigId\" : 21, \"Pos\" : { \"x\" : 0, \"y\" : 0 }, \"IsFlip\" : false, \"SkinId\" : 0 }] }, \"Description\" : null }, { \"BaseInfo\" : { \"ArtID\" : 100014, \"OwnerId\" : 1000000867, \"CreateTime\" : 1760951195, \"LikeInfos\" : [1000000921, 1000000929], \"SubscribeInfos\" : [1000000929], \"ReportInfos\" : [{ \"UnitId\" : 1000000929, \"ReportReason\" : 1 }], \"Name\" : \"富饶之地\", \"State\" : 1, \"SmallLayoutInfos\" : [{ \"GameUnitType\" : 1, \"ConfigId\" : 41, \"Pos\" : { \"x\" : 6, \"y\" : 6 }, \"IsFlip\" : false, \"SkinId\" : 0 }] }, \"Description\" : null }, { \"BaseInfo\" : { \"ArtID\" : 100064, \"OwnerId\" : 1000000847, \"CreateTime\" : 1761213434, \"LikeInfos\" : [], \"SubscribeInfos\" : [1000000929], \"ReportInfos\" : [{ \"UnitId\" : 1000000929, \"ReportReason\" : 2 }], \"Name\" : \"圣诞节\", \"State\" : 1, \"SmallLayoutInfos\" : [{ \"GameUnitType\" : 1, \"ConfigId\" : 20, \"Pos\" : { \"x\" : 6, \"y\" : 6 }, \"IsFlip\" : false, \"SkinId\" : 0 }, { \"GameUnitType\" : 1, \"ConfigId\" : 21, \"Pos\" : { \"x\" : 0, \"y\" : 13 }, \"IsFlip\" : false, \"SkinId\" : 0 }, { \"GameUnitType\" : 1, \"ConfigId\" : 30, \"Pos\" : { \"x\" : 0, \"y\" : 0 }, \"IsFlip\" : false, \"SkinId\" : 0 }] }, \"Description\" : null }] }"
|
|
|
|
|
|
|
|
//req.JsonData = s
|
|
|
|
|
|
|
|
//data1 := map[string]interface{}{}
|
|
|
|
|
|
|
|
//_ = json.Unmarshal([]byte(s), &data1)
|
|
|
|
|
|
|
|
fmt.Println("SetOfficialView: ", req.JsonData) |
|
|
|
|
|
|
|
if len(req.JsonData) == 0 { |
|
|
|
|
|
|
|
return res, errors.New("空数据") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ip := libUtils.GetClientIp(ctx) |
|
|
|
|
|
|
|
data := []entity.GameRouter{} |
|
|
|
|
|
|
|
err = dao.GameRouter.Ctx(ctx).Where("router_ip=?", ip).Scan(&data) |
|
|
|
|
|
|
|
if len(data) == 0 { |
|
|
|
|
|
|
|
whiteIps, _ := GetWhiteList(ctx) |
|
|
|
|
|
|
|
if !utils.ContainsWhiteList(whiteIps, ip) { |
|
|
|
|
|
|
|
return nil, gerror.New("ip白名单!") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mongodb, ok := MongoDatabaseList["0"] |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== db is nil") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filter := bson.M{"_id": 0} |
|
|
|
|
|
|
|
update := bson.M{"data": req.JsonData} |
|
|
|
|
|
|
|
err = mongodb.Collection("SmallLayoutBlueprint").UpdateOne(ctx, filter, bson.M{"$set": update}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== ", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.IsSuccess = 1 |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func SendOfficialView(ctx context.Context, req *game.SendOfficialViewReq) (res *game.SendOfficialViewRes, err error) { |
|
|
|
|
|
|
|
//ip := libUtils.GetClientIp(ctx)
|
|
|
|
|
|
|
|
//data := []entity.GameRouter{}
|
|
|
|
|
|
|
|
//err = dao.GameRouter.Ctx(ctx).Where("router_ip=?", ip).Scan(&data)
|
|
|
|
|
|
|
|
//if len(data) == 0 {
|
|
|
|
|
|
|
|
// whiteIps, _ := GetWhiteList(ctx)
|
|
|
|
|
|
|
|
// if !utils.ContainsWhiteList(whiteIps, ip) {
|
|
|
|
|
|
|
|
// return nil, gerror.New("ip白名单!")
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
res = new(game.SendOfficialViewRes) |
|
|
|
|
|
|
|
mongodb, ok := MongoDatabaseList["0"] |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== db is nil") |
|
|
|
|
|
|
|
res.Message = "数据库错误!" |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stores := []map[string]interface{}{} |
|
|
|
|
|
|
|
err = mongodb.Collection("SmallLayoutBlueprint").Find(ctx, bson.M{}).All(&stores) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
g.Log().Info(ctx, "err== ", err) |
|
|
|
|
|
|
|
res.Message = "查询数据错误!" |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(stores) <= 0 { |
|
|
|
|
|
|
|
res.Message = "空数据!" |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.SeverId == 0 { |
|
|
|
|
|
|
|
sendMsgToAll(ctx, fmt.Sprint(stores[0]["data"])) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.Message = sendMsgToServer(ctx, fmt.Sprint(stores[0]["data"]), fmt.Sprint(req.SeverId), ServerConfig[fmt.Sprint(req.SeverId)]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func sendMsgToAll(ctx context.Context, jsonData string) { |
|
|
|
|
|
|
|
for k, v := range ServerConfig { |
|
|
|
|
|
|
|
sendMsgToServer(ctx, jsonData, k, v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func sendMsgToServer(ctx context.Context, jsonData, k, v string) string { |
|
|
|
|
|
|
|
url1 := "http://" + v + "/UpdateSmallLayout" |
|
|
|
|
|
|
|
g.Client().SetHeader("Content-Type", "application/json;charset=UTF-8") |
|
|
|
|
|
|
|
g.Log().Info(ctx, "sendMsgToServer - req: ", url1, jsonData) |
|
|
|
|
|
|
|
body := map[string]interface{}{"jsonData": jsonData} |
|
|
|
|
|
|
|
bytes := g.Client().PostBytes(ctx, url1, gjson.MustEncodeString(body)) |
|
|
|
|
|
|
|
src := string(bytes) |
|
|
|
|
|
|
|
if g.IsEmpty(src) { |
|
|
|
|
|
|
|
//err = v + "空回调,发送失败"
|
|
|
|
|
|
|
|
log.Printf("[%s]%s:空回调,发送失败", k, v) |
|
|
|
|
|
|
|
return fmt.Sprintf("[%s]%s:空回调,发送失败", k, v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Printf("[%s]%s 回调正常: %s", k, v, src) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srcCharset := "UTF-8" |
|
|
|
|
|
|
|
tmp, _ := gcharset.ToUTF8(srcCharset, src) |
|
|
|
|
|
|
|
json, err := gjson.DecodeToJson(tmp) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
g.Log().Info(ctx, " sendMsgToServer === DecodeToJson err ", v, err.Error()) |
|
|
|
|
|
|
|
return fmt.Sprintf("[%s]%s err.Error(): %s", k, v, err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
g.Log().Info(ctx, " sendMsgToServer === ", v, json) |
|
|
|
|
|
|
|
if json.Get("Error").Int() != 200 { |
|
|
|
|
|
|
|
return fmt.Sprintf("[%s]%s Error: %s", k, v, json.Get("Error")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "success" |
|
|
|
|
|
|
|
} |
|
|
|
|