EnoughReduce.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/5/23
  6. * Time: 下午3:55
  7. */
  8. namespace app\frontend\modules\order\discount;
  9. use app\common\facades\Setting;
  10. class EnoughReduce extends BaseDiscount
  11. {
  12. protected $code = 'enoughReduce';
  13. protected $name = '全场满减优惠';
  14. /**
  15. * 获取总金额
  16. * @return int|mixed
  17. * @throws \app\common\exceptions\AppException
  18. */
  19. protected function _getAmount()
  20. {
  21. if(!Setting::get('enoughReduce.open')){
  22. return 0;
  23. }
  24. //只有商城、益生插件、应用市场、应用市场-子平台
  25. if(!in_array($this->order->plugin_id,[0,61,57,59])){
  26. return 0;
  27. }
  28. // 获取满减设置,按enough倒序
  29. $settings = collect(Setting::get('enoughReduce.enoughReduce'));
  30. if (empty($settings)) {
  31. return 0;
  32. }
  33. $settings = $settings->sortByDesc(function ($setting) {
  34. return $setting['enough'];
  35. });
  36. // 订单总价满足金额,则返回优惠金额
  37. foreach ($settings as $setting) {
  38. if ($this->order->getPriceBefore($this->getCode()) >= $setting['enough']) {
  39. return min($setting['reduce'],$this->order->getPriceBefore($this->getCode()));
  40. }
  41. }
  42. return 0;
  43. }
  44. }