AfterHandler.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace addons\TinyShop\common\components\marketing;
  3. use Yii;
  4. use yii\web\UnprocessableEntityHttpException;
  5. use common\helpers\ArrayHelper;
  6. use common\enums\StatusEnum;
  7. use common\helpers\BcHelper;
  8. use addons\TinyShop\common\models\order\OrderProduct;
  9. use addons\TinyShop\common\forms\PreviewForm;
  10. use addons\TinyShop\common\components\PreviewInterface;
  11. use addons\TinyShop\common\enums\MarketingEnum;
  12. /**
  13. * 统一处理数据
  14. *
  15. * Class AfterHandler
  16. * @package addons\TinyShop\common\components\marketing
  17. * @author jianyan74 <751393839@qq.com>
  18. */
  19. class AfterHandler extends PreviewInterface
  20. {
  21. /**
  22. * @param PreviewForm $form
  23. * @return PreviewForm|mixed
  24. */
  25. public function execute(PreviewForm $form): PreviewForm
  26. {
  27. foreach ($form->marketingDetails as &$detail) {
  28. empty($detail['marketing_name']) && $detail['marketing_name'] = MarketingEnum::getValue($detail['marketing_type']);
  29. }
  30. // 下单金额判断
  31. if (
  32. $this->isNewRecord == true &&
  33. $form->marketing_type != MarketingEnum::BARGAIN &&
  34. $form->product_money < $form->config['order_min_pay_money']
  35. ) {
  36. throw new UnprocessableEntityHttpException('最低下单金额为' . $form->order_buy_min_pay_money . '元');
  37. }
  38. return $form;
  39. }
  40. /**
  41. * 排斥营销
  42. *
  43. * @return array
  44. */
  45. public function rejectNames()
  46. {
  47. return [];
  48. }
  49. /**
  50. * 营销名称
  51. *
  52. * @return string
  53. */
  54. public static function getName(): string
  55. {
  56. return 'after';
  57. }
  58. }
粤ICP备19079148号