CancelReasonForm.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace ghs\models\delivery;
  3. use bizGhs\express\classes\GhsDeliveryOrderClass;
  4. use ghs\models\BaseForm;
  5. use Yii;
  6. /**
  7. * 获取订单取消原因表单模型
  8. * 用于 actionCancelReason 的参数验证
  9. */
  10. class CancelReasonForm extends BaseForm
  11. {
  12. public $ghsOrderId; // 批发订单ID
  13. public $platform; // 配送平台
  14. public function rules()
  15. {
  16. return [
  17. [['ghsOrderId', 'platform'], 'required'],
  18. ['ghsOrderId', 'integer'],
  19. ['ghsOrderId', 'validateGhsOrderId'],
  20. ['platform', 'string'],
  21. ['platform', 'in', 'range' => ['shansong', 'fengniao', 'huolala', 'dada']],
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'ghsOrderId' => '批发订单ID',
  28. 'platform' => '配送平台',
  29. ];
  30. }
  31. /**
  32. * 验证批发订单ID
  33. * @param $attribute
  34. */
  35. public function validateGhsOrderId($attribute)
  36. {
  37. if (!$this->hasErrors()) {
  38. $gdo = GhsDeliveryOrderClass::getByCondition(
  39. ['mainId' => Yii::$app->controller->mainId, 'ghsOrderId' => $this->ghsOrderId, 'orderStatus' => ['not in', [-1, -2]]],
  40. false
  41. );
  42. if (empty($gdo)) {
  43. $this->addError($attribute, '未找到对应的配送订单');
  44. }
  45. }
  46. }
  47. }