// Package controllers /
package controllers

import (
	"boss/internal/config"
	"boss/internal/service"
	"boss/internal/utils"
	"encoding/base64"
	"strconv"
	"time"

	"github.com/beego/beego/v2/server/web"
)

type PageController struct {
	web.Controller
}

func (c *PageController) Index() {
	c.TplName = "index.html"
	testExtraLink, err := web.AppConfig.String("testExtraLink::host")
	if err != nil {
		testExtraLink = "http://127.0.0.1:12305"
	}
	roadList := service.QueryRoad()
	c.Data["roadList"] = roadList
	c.Data["title"] = web.AppConfig.DefaultString("baseSettings::subtitle", "聚合支付管理系统")
	c.Data["extraAddr"] = testExtraLink
}

func (c *PageController) LoginPage() {
	c.Data["title"] = web.AppConfig.DefaultString("baseSettings::title", "卡密核销结算平台")
	c.TplName = "login.html"
}

func (c *PageAuthController) AccountPage() {
	c.TplName = "account.html"
}

func (c *PageAuthController) AccountHistoryPage() {
	c.TplName = "account_history.html"
}

func (c *PageAuthController) BankCardPage() {
	c.TplName = "bank_card.html"
}

func (c *PageAuthController) CreateAgentPage() {
	c.TplName = "create_agent.html"
}

func (c *PageAuthController) EditRolePage() {
	c.TplName = "edit_role.html"
}

func (c *PageAuthController) FirstMenuPage() {
	c.TplName = "first_menu.html"
}

func (c *PageAuthController) MainPage() {
	c.TplName = "main.html"
}

func (c *PageAuthController) MenuPage() {
	c.TplName = "menu.html"
}

func (c *PageAuthController) MerchantPage() {
	c.TplName = "merchant.html"
}

func (c *PageAuthController) MerchantV2Page() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())

	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()

	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "merchant_v2.html"
}

func (c *PageAuthController) RechargeAppleAccountPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "apple-card/account.html"
}

func (c *PageAuthController) RechargeTMallGameAccountPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/account.html"
}

func (c *PageAuthController) RechargeTMallGameOrderPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/recharge-order.html"
}

func (c *PageAuthController) RechargeTMallGameSummaryPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/summary.html"
}

func (c *PageAuthController) OrderSummary() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "order_summary.html"
}

func (c *PageAuthController) UserManagement() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())
	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()
	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "user/management.html"
}

func (c *PageAuthController) RechargeAppleOrderPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())

	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()

	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "apple-card/recharge-order.html"
}

func (c *PageAuthController) StealOrderPage() {
	token := ""
	// 获取当前时间的时间戳
	currentTime := time.Now()
	targetMinute := (currentTime.Minute() / 10) * 10
	targetTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), currentTime.Hour(), targetMinute, 0, 0, currentTime.Location())

	now := strconv.Itoa(int(targetTime.Unix()))
	secretCfg := config.GetSecret()

	tokenB, err := utils.AesCBCEncrypt([]byte(now), []byte(secretCfg.Key), []byte(secretCfg.IV))
	if err == nil {
		//base64编码
		token = base64.URLEncoding.EncodeToString(tokenB)
	}
	c.Data["token"] = token
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "apple-card/steal-user-management.html"
}

func (c *PageAuthController) OperatorPage() {
	c.TplName = "operator.html"
}

func (c *PageAuthController) PowerPage() {
	c.TplName = "power.html"
}

func (c *PageAuthController) RoadPage() {
	c.TplName = "road.html"
}

func (c *PageAuthController) RoadPoolPage() {
	c.TplName = "road_pool.html"
}

func (c *PageAuthController) RoadProfitPage() {
	c.TplName = "road_profit.html"
}

func (c *PageAuthController) RolePage() {
	c.TplName = "role.html"
}

func (c *PageAuthController) SecondMenuPage() {
	c.TplName = "second_menu.html"
}

func (c *PageAuthController) OrderInfoPage() {
	//从查询参数中获取商户uid
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "order_info.html"
}

func (c *PageAuthController) OrderProfitPage() {
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "order_profit.html"
}

func (c *PageAuthController) MerchantPayforPage() {
	c.TplName = "merchant_payfor.html"
}

func (c *PageAuthController) SelfPayforPage() {
	c.TplName = "self_payfor.html"
}

func (c *PageAuthController) PayforRecordPage() {
	c.TplName = "payfor_record.html"
}

func (c *PageAuthController) ConfirmPage() {
	c.TplName = "confirm.html"
}

func (c *PageAuthController) SelfNotifyPage() {
	c.TplName = "self_notify.html"
}

func (c *PageAuthController) SelfPlusSubPage() {
	c.TplName = "self_plus_sub.html"
}

func (c *PageAuthController) AgentToMerchantPage() {
	c.TplName = "agent_to_merchant.html"
}

func (c *PageAuthController) PlatFormProfitPage() {
	c.TplName = "platform_profit.html"
}

func (c *PageAuthController) AgentProfitPage() {
	c.TplName = "agent_profit.html"
}
