FullMailHandler.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace addons\TinyShop\common\components\marketing;
  3. use Yii;
  4. use addons\TinyShop\common\enums\MarketingEnum;
  5. use addons\TinyShop\common\forms\PreviewForm;
  6. use addons\TinyShop\common\components\PreviewInterface;
  7. /**
  8. * 满额包邮
  9. *
  10. * Class FullMailHandler
  11. * @package addons\TinyShop\common\components
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class FullMailHandler extends PreviewInterface
  15. {
  16. /**
  17. * @param PreviewForm $form
  18. * @return PreviewForm
  19. */
  20. public function execute(PreviewForm $form): PreviewForm
  21. {
  22. // 满减送包邮成功触发
  23. if ($form->is_full_mail == true) {
  24. return $this->success($form);
  25. }
  26. $fullMail = Yii::$app->tinyShopService->marketingFullMail->postage($form->product_money, $form->address, $form->merchant_id);
  27. // 满包邮成功触发
  28. if ($fullMail) {
  29. $form->is_full_mail = true;
  30. // 触发营销
  31. $form->marketingDetails[] = [
  32. 'marketing_id' => $fullMail['id'],
  33. 'marketing_type' => MarketingEnum::FULL_MAIL,
  34. 'marketing_condition' => '满' . $fullMail['full_mail_money'] . '元包邮',
  35. 'free_shipping' => 1,
  36. 'discount_money' => $form->shipping_money,
  37. ];
  38. return $this->success($form);
  39. }
  40. return $form;
  41. }
  42. /**
  43. * 排斥营销
  44. *
  45. * @return array
  46. */
  47. public function rejectNames()
  48. {
  49. return [];
  50. }
  51. /**
  52. * 营销名称
  53. *
  54. * @return string
  55. */
  56. public static function getName(): string
  57. {
  58. return 'fullMail';
  59. }
  60. }
粤ICP备19079148号