LogisticsDelivery.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace addons\TinyShop\common\components\delivery;
  3. use Yii;
  4. use yii\web\UnprocessableEntityHttpException;
  5. use common\enums\StatusEnum;
  6. use addons\TinyShop\common\forms\PreviewForm;
  7. use addons\TinyShop\common\components\PreviewInterface;
  8. /**
  9. * 物流配送
  10. *
  11. * Class LogisticsDelivery
  12. * @package addons\TinyShop\common\components\delivery
  13. * @author jianyan74 <751393839@qq.com>
  14. */
  15. class LogisticsDelivery extends PreviewInterface
  16. {
  17. /**
  18. * @param PreviewForm $form
  19. * @return PreviewForm
  20. * @throws UnprocessableEntityHttpException
  21. */
  22. public function execute(PreviewForm $form): PreviewForm
  23. {
  24. if ($this->isNewRecord == false) {
  25. return $form;
  26. }
  27. // 物流配送
  28. if ($form->config['logistics'] == StatusEnum::DISABLED) {
  29. throw new UnprocessableEntityHttpException('物流配送已关闭');
  30. }
  31. if (empty($form->address)) {
  32. throw new UnprocessableEntityHttpException('找不到收货地址');
  33. }
  34. // 自选物流
  35. if ($form->config['logistics_select'] == StatusEnum::ENABLED && (!$form->company_id || !Yii::$app->tinyShopService->expressCompany->findById($form->company_id))) {
  36. throw new UnprocessableEntityHttpException('请选择物流公司');
  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 'logistics';
  57. }
  58. }
粤ICP备19079148号