GoodsInstall.php 949 B

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