package services

import (
	"hongze/hongze_cygx/models"
	"hongze/hongze_cygx/utils"
)

// GetfreeButtonIsShow 用户免费分享按钮是否回显
func GetfreeButtonIsShow(user *models.WxUserItem) (isShow bool, err error) {
	detail, err := models.GetConfigByCode("free_trial_card")
	if err != nil {
		return
	}
	companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
	if err != nil && err.Error() != utils.ErrNoRow() {
		return
	}
	count, err := models.CountCygxUserFreeeButton(user.UserId)
	if err != nil && err.Error() != utils.ErrNoRow() {
		return
	}
	if companyDetail != nil && companyDetail.IsSuspend == 0 {
		if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
			isShow = true
		}
	}
	return
}
