package service

import (
	"XT_New/models"
	"errors"
	"time"
)

func GetOrgSubscibeState(subscibe *models.ServeSubscibe) (err error) {
	if subscibe == nil {
		err = errors.New("没有订阅信息")
		return
	}

	//免费试用版2，永久免费版9 不过期
	if subscibe.State == 9 || subscibe.State == 2 {
		return
	}

	timeNow := time.Now().Unix()
	if timeNow < subscibe.PeriodStart || timeNow > subscibe.PeriodEnd {
		subscibe.State = 3
	}
	if subscibe.State != 1 && subscibe.State != 8 {
		subscibe.State = 3
	}
	return

}

func GetOrgSubscibe(org_id int64) (subscibe models.ServeSubscibe, err error) {
	err = readUserDb.Model(&models.ServeSubscibe{}).Where("org_id = ? AND status = 1", org_id).First(&subscibe).Error
	return
}
