package controller

import (
	mhayaGin "github.com/mhaya/components/gin"
	mhayaTime "github.com/mhaya/extend/time"
	"github.com/mhaya/game/game_cluster/internal/code"
	"github.com/mhaya/game/game_cluster/internal/mdb/models"
	"github.com/mhaya/game/game_cluster/internal/param"
	mhayaLogger "github.com/mhaya/logger"
	"time"
)

func (p *Controller) test(c *mhayaGin.Context) {

	var pa param.ClaimReq
	if err := c.BindJSON(&pa); err != nil {
		mhayaLogger.Warnf("if share err {. params=%s", pa)
		code.RenderResult(c, code.Error)
		return
	}
	if pa.Tp == 0 {
		code.RenderResult(c, code.Error)
		return
	}

	if pa.Tp == 1 {
		models.TestPreserve(mhayaTime.Now().Add(-60*24*time.Hour).Add(time.Duration(pa.Id)*24*time.Hour).Unix(), 10000)
		code.RenderResult(c, code.OK)
	} else {
		rs := models.GetPlayerPreserve(int64(pa.Id), int64(pa.Id)+60*60*24*7)
		code.RenderResult(c, code.OK, rs)
	}
}
