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(); } }