EnoughReduce.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/5/23
  6. * Time: 上午11:17
  7. */
  8. namespace app\frontend\modules\dispatch\discount;
  9. use app\common\facades\Setting;
  10. /**
  11. * 全场运费满额减
  12. * Class EnoughReduce
  13. * @package app\frontend\modules\dispatch\discount
  14. */
  15. class EnoughReduce extends BaseFreightDiscount
  16. {
  17. protected $name = '全场运费满额减';
  18. protected $code = 'freightEnoughReduce';
  19. /**
  20. * @return int|number
  21. * @throws \app\common\exceptions\AppException
  22. */
  23. protected function _getAmount()
  24. {
  25. // 不参与包邮地区
  26. if (in_array($this->order->orderAddress->city_id, Setting::get('enoughReduce.freeFreight.city_ids'))) {
  27. trace_log()->freight('全场运费满额减',"{$this->order->orderAddress->city_id}地区不参加");
  28. return 0;
  29. }
  30. // 设置为0 全额包邮
  31. if (Setting::get('enoughReduce.freeFreight.enough') === 0 || Setting::get('enoughReduce.freeFreight.enough') === '0') {
  32. trace_log()->freight('全场运费满额减',"全额包邮");
  33. return $this->orderFreight->getPriceBefore($this->getCode());
  34. }
  35. // 订单金额满足满减金额(订单抵扣后价格)
  36. if (Setting::get('enoughReduce.freeFreight.amount_type') == 1) {
  37. trace_log()->freight('全场运费满额减','订单抵扣后价格计算');
  38. return 0;
  39. }
  40. // 订单金额满足满减金额(订单抵扣后价格)
  41. // if (Setting::get('enoughReduce.freeFreight.amount_type') == 1) {
  42. // if (($this->order->getPriceBefore('orderFee') - $this->order->getDispatchAmount()) >= Setting::get('enoughReduce.freeFreight.enough')) {
  43. // trace_log()->freight('全场运费满额减',"订单金额{$this->order->getPriceBefore('orderFee')}满足".Setting::get('enoughReduce.freeFreight.enough'));
  44. // return $this->orderFreight->getPriceBefore($this->getCode());
  45. // }
  46. // trace_log()->freight('全场运费满额减','订单抵扣后价格计算');
  47. // return 0;
  48. // }
  49. // 订单金额满足满减金额(商品现价)
  50. if ($this->order->getPriceBefore('orderDispatchPrice') >= Setting::get('enoughReduce.freeFreight.enough')) {
  51. trace_log()->freight('全场运费满额减',"订单金额{$this->order->getPriceBefore('orderDispatchPrice')}满足".Setting::get('enoughReduce.freeFreight.enough'));
  52. return $this->orderFreight->getPriceBefore($this->getCode());
  53. }
  54. trace_log()->freight('全场运费满额减',"订单金额{$this->order->getPriceBefore('orderDispatchPrice')}不满足".Setting::get('enoughReduce.freeFreight.enough'));
  55. return 0;
  56. }
  57. public function validate()
  58. {
  59. if (!Setting::get('enoughReduce.freeFreight.open')) {
  60. trace_log()->freight('全场运费满额减','设置未开启');
  61. return false;
  62. }
  63. //只有商城、应用市场、应用市场-子平台
  64. if(!in_array($this->order->plugin_id,[0,57,59])){
  65. trace_log()->freight('全场运费满额减','只有商城,应用市场,应用市场-子平台订单参加');
  66. return false;
  67. }
  68. return parent::validate();
  69. }
  70. }