package controllers

import (
	"eta/eta_mobile/models"
	"eta/eta_mobile/utils"
	"fmt"
)

// BusinessConfController 商家配置
type BusinessConfController struct {
	BaseAuthController
}

type BusinessConfOpenController struct {
	BaseCommonController
}

// Fetch
// @Title 获取配置
// @Description 获取配置
// @Success 200 Ret=200 获取成功
// @router /fetch [get]
func (this *BusinessConfController) Fetch() {
	br := new(models.BaseResponse).Init()
	defer func() {
		if br.ErrMsg == "" {
			br.IsSendEmail = false
		}
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}

	list, e := models.GetBusinessConf()
	if e != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取商家配置失败, Err: " + e.Error()
		return
	}

	br.Data = list
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
}

// CodeEncrypt
// @Title 商家编码加密
// @Description 商家编码加密
// @Success 200 Ret=200 获取成功
// @router /code_encrypt [get]
func (this *BusinessConfOpenController) CodeEncrypt() {
	br := new(models.BaseResponse).Init()
	defer func() {
		if br.ErrMsg == "" {
			br.IsSendEmail = false
		}
		this.Data["json"] = br
		this.ServeJSON()
	}()

	res := ""
	if utils.BusinessCode != "" {
		res = utils.MD5(fmt.Sprintf("%s%s", utils.BusinessCode, utils.BusinessCodeSalt))
	}

	br.Data = res
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
}
