'json', ]; protected $autoWriteTimestamp=true; public function link(){ return $this->hasMany(GoodsInstallLink::class); } public function getFee($num,$single=false){ if($single){ return $this->fee_fix; } return bcmul($this->fee_fix,$num); foreach ($this['fee'] as $fee){ if($num>=$fee['num_min'] && $num<=$fee['num_max']){ if($single){ return $fee['amount']; } return bcmul($fee['amount'],$num); } } return 0; } public static function init() { self::afterDelete(function (self $goodsInstall){ $goodsInstall->link()->delete(); }); } }