AllDeliveryQuotesForm.php 1.3 KB

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