66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/gin/engine"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type OpenTime struct {
|
|
Optime string `json:"optime"` //开服时间
|
|
Mytime string `json:"mytime"` //修改后的开服时间
|
|
}
|
|
|
|
//获取开服时间
|
|
func (this *Api_Comp) Getopentime(c *engine.Context) {
|
|
data := &OpenTime{
|
|
Optime: this.module.service.GetOpentime().Format("2006-01-02 15:04:05"),
|
|
Mytime: this.module.service.GetOpentime().Add(configure.GetOffsettime()).Format("2006-01-02 15:04:05"),
|
|
}
|
|
c.JSON(http.StatusOK, &Respond{
|
|
Code: 0,
|
|
Message: "成功",
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
//修改开服时间
|
|
func (this *Api_Comp) Modifyopentime(c *engine.Context) {
|
|
var (
|
|
code pb.ErrorCode
|
|
msg string
|
|
offest time.Duration
|
|
)
|
|
opentime := c.PostForm("opentime")
|
|
defer func() {
|
|
c.JSON(http.StatusOK, &Respond{
|
|
Code: code,
|
|
Message: msg,
|
|
Data: opentime,
|
|
})
|
|
}()
|
|
t, err := time.ParseInLocation("2006-01-02 15:04:05", opentime, time.Local)
|
|
if nil != err || t.IsZero() {
|
|
this.module.Errorln(err)
|
|
msg = fmt.Sprintf("opentime:%s 格式异常", opentime)
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
offest = t.Sub(this.module.service.GetOpentime())
|
|
configure.SetOffsettime(offest)
|
|
if err := this.module.service.RpcBroadcast(
|
|
context.Background(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ConfigureUpDate),
|
|
&pb.EmptyReq{},
|
|
&pb.EmptyResp{}); err != nil {
|
|
this.module.Errorln(err)
|
|
msg = err.Error()
|
|
code = pb.ErrorCode_RpcFuncExecutionError
|
|
}
|
|
}
|