// Package controllers /
package controllers

import (
	"boss/internal/config"
	"boss/internal/service"
	"fmt"

	"github.com/beego/beego/v2/core/config/env"

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

type PageController struct {
	web.Controller
}

func (c *PageController) Index() {
	ctx := c.Ctx.Request.Context()
	roadList := service.QueryRoad(ctx)
	c.Data["roadList"] = roadList
	c.Data["showStealConfig"] = web.AppConfig.DefaultBool("showStealConfig", true)
	serverName := env.Get("serverName", "")
	if serverName != "" {
		serverName = fmt.Sprintf("(%s)", serverName)
	}
	c.Data["title"] = serverName + "聚合支付管理系统"
	c.TplName = "index.html"
}

func (c *PageController) LoginPage() {
	serverName := env.Get("serverName", "")
	title := "卡密核销结算平台"
	if serverName != "" {
		title = fmt.Sprintf("(%s)%s", serverName, title)
	}
	c.Data["title"] = 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() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "merchant_v2.html"
}

func (c *PageAuthController) RechargeAppleAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "apple-card/account.html"
}

func (c *PageAuthController) RechargeTMallGameAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/account.html"
}

func (c *PageAuthController) RechargeTMallGameOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/recharge-order.html"
}

func (c *PageAuthController) JDOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "jd-card/order.html"
}

func (c *PageAuthController) JDAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "jd-card/account.html"
}

func (c *PageAuthController) WalmartOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "walmart-card/order.html"
}

func (c *PageAuthController) WalmartGroupPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "walmart-card/group.html"
}

func (c *PageAuthController) WalmartAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "walmart-card/account.html"
}

func (c *PageAuthController) CTripOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "c-trip-card/order.html"
}

func (c *PageAuthController) CTripAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "c-trip-card/account.html"
}

func (c *PageAuthController) RechargeTMallGameShopOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/recharge-shop-order.html"
}

func (c *PageAuthController) RechargeTMallGameSummaryPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "t-mall-game/summary.html"
}

func (c *PageAuthController) OrderSummary() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "order_summary.html"
}

func (c *PageAuthController) UserManagement() {
	userID, _ := c.GetSession("userID").(string)
	// 获取当前时间的时间戳
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "user/management.html"
}

func (c *PageAuthController) UserLoginLog() {
	userID, _ := c.GetSession("userID").(string)
	// 获取当前时间的时间戳
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.Data["roadUid"] = c.GetString("roadUid")
	c.TplName = "user/login-log.html"
}

func (c *PageAuthController) RechargeAppleOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "apple-card/recharge-order.html"
}

func (c *PageAuthController) StealOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	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"
}

func (c *PageAuthController) StealRule() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "merchant/steal-rule.html"
}

func (c *PageAuthController) JdCardCkAccount() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "jd-ck/account.html"
}

func (c *PageAuthController) JdCardCkOrder() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "jd-ck/order.html"
}

func (c *PageAuthController) JdCardCkJdOrder() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "jd-ck/jd-order.html"
}

func (c *PageAuthController) DashboardPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "dashboard/dashboard.html"
}

func (c *PageAuthController) AlipayTokenPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "camel-oil/token.html"
}

func (c *PageAuthController) AlipayAccountPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "camel-oil/account.html"
}

func (c *PageAuthController) AlipayOrderPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "camel-oil/order.html"
}

func (c *PageAuthController) AlipayPrefetchPage() {
	userID, _ := c.GetSession("userID").(string)
	ctx := c.Ctx.Request.Context()
	tokenService := service.NewTokenService()
	c.Data["token"] = tokenService.GetToken(ctx, userID)
	c.Data["portalHost"] = config.GetPortalHost()
	c.TplName = "camel-oil/camelOilPrefetch.html"
}
