<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\common\model\effective;


use app\common\model\BaseModel;
use app\common\model\goods_category\GoodsCategory;


/**
 * EffectiveRules模型
 * Class EffectiveRules
 * @package app\common\model\effective
 */
class EffectiveRules extends BaseModel
{
    
    protected $name = 'effective_rules';


    public function effectiveWithCategory()
    {
        return $this->belongsToMany(GoodsCategory::class,EffectiveCategory::class,'goods_category_id','effective_id');
    }

    public static function formatEndEffectiveTime( $time,$num,$unit)
    {
        if(is_numeric($time)){
            $time = date('Y-m-d H:i:s',$time);
        }
        $effectiveUnit = 'day';
        switch ($unit){
            case 1:
                $effectiveUnit = 'day';
                break;
            case 2:
                $effectiveUnit = 'hour';
                break;
        }
        return  strtotime("$time +". $num.$effectiveUnit);
    }
}