GoodsInstallLink.php 857 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\common\model;
  3. use think\db\Query;
  4. use think\Model;
  5. /**
  6. * @property GoodsInstall install
  7. */
  8. class GoodsInstallLink extends Model
  9. {
  10. public function scopeSku(Query $query,$sku_id,$goods_id=null){
  11. $query->where('goods_sku_id',$sku_id);
  12. if($goods_id){
  13. $query->where('goods_id',$goods_id);
  14. }
  15. }
  16. public function install(){
  17. return $this->belongsTo(GoodsInstall::class);
  18. }
  19. public static function getFee($sku_id,$num,$single=false){
  20. if($sku_id instanceof GoodsSku){
  21. $sku_id=$sku_id['id'];
  22. }
  23. $installLink=self::where('goods_sku_id',$sku_id)->with(['install'])->find();
  24. $fee=0;
  25. if($installLink){
  26. $install=$installLink->install;
  27. $fee=$install->getFee($num,$single);
  28. }
  29. return $fee;
  30. }
  31. }