<?php

namespace app\model;

use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

/**
 * 签到券主表
 * Class CouponMain
 * @package app\model
 */
class CouponMain extends Base
{
        const status_on     = 0;//进行中
        const status_off    = 1;//停止
        const on_shelf_on   = 0;//上架状态
        const on_shelf_off  = 1;//下架状态

        const on_screen_yes = 1;//展示到商圈大屏
        const on_screen_no  = 0;//不展示到商圈大屏

        const min_redpack_money  = 0.3;//

        const receive_status_over       = 2;//领取状态 已领完
        const receive_status_received   = 1;//领取状态 已领完
        const receive_status_default    = 0;//领取状态 可领取






    public function business()
    {
        return $this->hasOne(Business::class, 'code',"business_code");
    }
    public function couponType()
    {
        return $this->hasOne(CouponType::class, 'id',"type_id");
    }
    //public function usingRule()
    //{
    //    return $this->hasOne(UsingRule::class, 'coupon_id',"id");
    //}
    //创建完成之后
    public static function onAfterInsert( $obj)
    {
        $obj->sort                  = $obj->id;
        $obj->using_count           = $obj->count;
        $obj->received_count        = 0;
        $obj->verification_count    = 0;
        $obj->save();
    }
}