fullAmountFreeFreight.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/5/16
  8. * Time: 17:47
  9. */
  10. namespace app\frontend\modules\dispatch\models;
  11. use app\common\facades\Setting;
  12. use app\frontend\modules\order\discount\BaseDiscount;
  13. class fullAmountFreeFreight extends BaseDiscount
  14. {
  15. protected $name = '全场运费满额减';
  16. protected $code = 'freightEnoughReduce';
  17. public $amount;
  18. /**
  19. * 获取总金额
  20. * @return float
  21. */
  22. public function getAmount()
  23. {
  24. if (isset($this->amount)) {
  25. return $this->amount;
  26. }
  27. $this->amount = $this->_getAmount();
  28. return $this->amount;
  29. }
  30. /**
  31. * @return int|number
  32. * @throws \app\common\exceptions\AppException
  33. */
  34. protected function _getAmount()
  35. {
  36. if (!Setting::get('enoughReduce.freeFreight.open')) {
  37. trace_log()->freight('全场运费满额减','设置未开启');
  38. return 0;
  39. }
  40. //只有商城、应用市场、应用市场-子平台
  41. if(!in_array($this->order->plugin_id,[0,57,59])){
  42. trace_log()->freight('全场运费满额减','只有商城,应用市场,应用市场-子平台订单参加');
  43. return 0;
  44. }
  45. // 不参与包邮地区
  46. if (in_array($this->order->orderAddress->city_id, Setting::get('enoughReduce.freeFreight.city_ids'))) {
  47. trace_log()->freight('全场运费满额减',"{$this->order->orderAddress->city_id}地区不参加");
  48. return 0;
  49. }
  50. // 订单金额满足满减金额(订单抵扣后价格)
  51. if (Setting::get('enoughReduce.freeFreight.amount_type') == 1) {
  52. if (($this->order->getPriceBefore('orderFee') - $this->order->getDispatchAmount()) >= Setting::get('enoughReduce.freeFreight.enough')) {
  53. trace_log()->freight('全场运费满额减',"订单金额{$this->order->getPriceBefore('orderFee')}满足".Setting::get('enoughReduce.freeFreight.enough'));
  54. return $this->order->getDispatchAmount();
  55. }
  56. trace_log()->freight('全场运费满额减','订单抵扣后价格计算');
  57. return 0;
  58. }
  59. return 0;
  60. }
  61. }