PickupDelivery.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace addons\TinyShop\common\components\delivery;
  3. use Yii;
  4. use yii\web\UnprocessableEntityHttpException;
  5. use addons\TinyShop\common\components\PreviewInterface;
  6. use addons\TinyShop\common\forms\PreviewForm;
  7. use common\enums\StatusEnum;
  8. /**
  9. * 门店自提
  10. *
  11. * Class PickupDelivery
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class PickupDelivery extends PreviewInterface
  15. {
  16. /**
  17. * @param PreviewForm $form
  18. * @return PreviewForm
  19. * @throws UnprocessableEntityHttpException
  20. */
  21. public function execute(PreviewForm $form): PreviewForm
  22. {
  23. if ($form->config['logistics_local_distribution'] != StatusEnum::ENABLED) {
  24. throw new UnprocessableEntityHttpException('未开启商品自提');
  25. }
  26. if (!$form->store_id) {
  27. throw new UnprocessableEntityHttpException('请选择自提地点');
  28. }
  29. if (!($form->store = Yii::$app->tinyStoreService->store->findById($form->store_id))) {
  30. throw new UnprocessableEntityHttpException('自提地点不存在');
  31. }
  32. if (empty($form->subscribe_shipping_start_time)) {
  33. throw new UnprocessableEntityHttpException('未选择自提时间');
  34. }
  35. // 计算运费
  36. $form->shipping_money = Yii::$app->tinyStoreService->config->getFreight($form->pay_money, $form->merchant_id);
  37. return $form;
  38. }
  39. /**
  40. * 排斥营销
  41. *
  42. * @return array
  43. */
  44. public function rejectNames()
  45. {
  46. return [];
  47. }
  48. /**
  49. * 营销名称
  50. *
  51. * @return string
  52. */
  53. public static function getName(): string
  54. {
  55. return 'pickup';
  56. }
  57. }
粤ICP备19079148号