Goods.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2019/1/2
  6. * Time: 18:31
  7. */
  8. namespace app\frontend\modules\goods\models;
  9. class Goods extends \app\common\models\Goods
  10. {
  11. public $appends = ['status_name','estimated_commission','vip_price'];
  12. public function getEstimatedCommissionAttribute()
  13. {
  14. $price = round($this->price * $this->getSalesCommission() / 100,2);
  15. return $price;
  16. }
  17. public function getSalesCommission()
  18. {
  19. if (app('plugins')->isEnabled('sales-commission')) {
  20. $set = \Setting::get('plugin.sales-commission');
  21. if ($set['switch']) {
  22. $salesCommissionGoods = \Yunshop\SalesCommission\models\GoodsSalesCommission::getGoodsByGoodsId($this->id)->first();
  23. if ($salesCommissionGoods) {
  24. if ($salesCommissionGoods->has_dividend == '1') {
  25. return $salesCommissionGoods->dividend_rate;
  26. } else {
  27. return $set['default_rate'];
  28. }
  29. }
  30. }
  31. }
  32. return 0;
  33. }
  34. }