44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?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;//下架状态
|
|
|
|
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();
|
|
}
|
|
} |