GroupBuyActiveMarketing.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace addons\GroupBuy\common\logic\order\marketing;
  3. use addons\GroupBuy\common\models\GroupBuyActive;
  4. use common\enums\StatusEnum;
  5. use common\logic\order\marketing\BaseMarketing;
  6. /**
  7. * 检查活动免费开团
  8. */
  9. class GroupBuyActiveMarketing extends BaseMarketing
  10. {
  11. public function execute($form)
  12. {
  13. }
  14. /**
  15. * @param $item
  16. * @param $form
  17. * @param $extra
  18. *
  19. * @return mixed
  20. */
  21. public static function compute($item, &$form, &$extra = [])
  22. {
  23. // 不是团长
  24. if (empty($item['mch_order_info']['is_commander'])) {
  25. return $item;
  26. }
  27. // 开团是否免费
  28. if (
  29. !GroupBuyActive::find()
  30. ->where([
  31. 'id' => $form->data['active_id'],
  32. 'status' => StatusEnum::ENABLED,
  33. 'mall_id' => $form->mall_id,
  34. 'is_initiator_free' => StatusEnum::ENABLED
  35. ])
  36. ->exists()
  37. ) {
  38. return $item;
  39. }
  40. $item['mch_order_info']['pay_money'] = max(bcsub($item['mch_order_info']['pay_money'], $item['mch_order_info']['goods_price'], 2), 0);
  41. $item['mch_order_info']['group_buy_price'] = max(bcsub($item['mch_order_info']['group_buy_price'], $item['mch_order_info']['goods_price'], 2), 0);
  42. $item['mch_order_info']['is_free'] = 1; // 免费开团标识
  43. $form->marketing['deduct']['is_free_open_group'] = ['name' => '优惠金额', 'money' => $item['mch_order_info']['goods_price']];
  44. return $item;
  45. }
  46. }