GoodsInstall.php 701 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class GoodsInstall extends Model
  5. {
  6. protected $type=[
  7. 'fee'=>'json',
  8. ];
  9. protected $autoWriteTimestamp=true;
  10. public function link(){
  11. return $this->hasMany(GoodsInstallLink::class);
  12. }
  13. public function getFee($num){
  14. foreach ($this['fee'] as $fee){
  15. if($num>=$fee['num_min'] && $num<$fee['num_max']){
  16. return bcmul($fee['amount'],$num);
  17. }
  18. }
  19. return 0;
  20. }
  21. public static function init()
  22. {
  23. self::afterDelete(function (self $goodsInstall){
  24. $goodsInstall->link()->delete();
  25. });
  26. }
  27. }