LocalDelivery.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace addons\TinyShop\common\components\delivery;
  3. use Yii;
  4. use yii\web\UnprocessableEntityHttpException;
  5. use addons\TinyShop\common\forms\PreviewForm;
  6. use addons\TinyShop\common\components\PreviewInterface;
  7. /**
  8. * 同城配送(本地)
  9. *
  10. * Class LocalDelivery
  11. * @package addons\TinyShop\common\components\delivery
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class LocalDelivery 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 (empty($form->address)) {
  24. throw new UnprocessableEntityHttpException('收货地址不存在');
  25. }
  26. $cashAgainst = Yii::$app->tinyShopService->localArea->findOne($form->merchant_id);
  27. if ($form->address && $this->isNewRecord && $cashAgainst && !in_array($form->address->area_id, explode(',', $cashAgainst['area_ids']))) {
  28. throw new UnprocessableEntityHttpException('暂不支持该地区的配送');
  29. }
  30. if (empty($form->subscribe_shipping_start_time)) {
  31. throw new UnprocessableEntityHttpException('未选择配送时间');
  32. }
  33. // 配送费
  34. $form->shipping_money = Yii::$app->tinyShopService->localConfig->getShippingFeeByMerchantId($form->merchant_id, $form->product_money);
  35. return $form;
  36. }
  37. /**
  38. * 排斥营销
  39. *
  40. * @return array
  41. */
  42. public function rejectNames()
  43. {
  44. return [];
  45. }
  46. /**
  47. * 营销名称
  48. *
  49. * @return string
  50. */
  51. public static function getName(): string
  52. {
  53. return 'local';
  54. }
  55. }
粤ICP备19079148号