AddressForm.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace ghs\models\delivery;
  3. use bizGhs\order\classes\OrderClass;
  4. use ghs\models\BaseForm;
  5. use Yii;
  6. /**
  7. * 获取配送地址表单模型
  8. * 用于 actionAddress 的参数验证
  9. */
  10. class AddressForm extends BaseForm
  11. {
  12. public $orderId; // xhGhsOrder.id
  13. public function rules()
  14. {
  15. return [
  16. ['orderId', 'required'],
  17. ['orderId', 'integer'],
  18. ['orderId', 'validateOrderId'],
  19. ];
  20. }
  21. public function attributeLabels()
  22. {
  23. return [
  24. 'orderId' => '订单ID',
  25. ];
  26. }
  27. /**
  28. * 验证订单ID是否存在且属于当前商户
  29. * @param $attribute
  30. */
  31. public function validateOrderId($attribute)
  32. {
  33. if (!$this->hasErrors()) {
  34. $order = OrderClass::getById($this->orderId, false, 'id, mainId');
  35. if (empty($order)) {
  36. $this->addError($attribute, '订单不存在');
  37. return;
  38. }
  39. if ($order['mainId'] != Yii::$app->controller->mainId) {
  40. $this->addError($attribute, '订单不属于当前商户');
  41. }
  42. }
  43. }
  44. }