| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace hd\models\delivery;
- use bizHd\order\classes\OrderClass;
- use hd\models\BaseForm;
- use Yii;
- /**
- * 创建配送订单表单模型
- * 用于 actionCreateOrder 的参数验证
- */
- class CreateOrderForm extends BaseForm
- {
- public $orderId; // xhGhsOrder.id
- public $remark; // 订单备注
- public $price; // 配送费(单位:分)
- public $pickupTime; // 取件时间
- public $allParams; // 配送平台所需的所有参数(透传平台参数)
- public function rules()
- {
- return [
- [['orderId', 'price'], 'required'],
- [['orderId', 'price'], 'integer'],
- //['orderId', 'validateOrderId'],
- ['pickupTime', 'safe'],
- ['allParams', 'safe'],
- ['remark', 'string', 'max' => 500],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'orderId' => '订单ID',
- 'remark' => '备注',
- 'price' => '配送费用',
- 'pickupTime' => '取件时间',
- 'allParams' => '配送参数',
- ];
- }
- /**
- * 验证订单ID是否存在且属于当前商户
- * @param $attribute
- */
- public function validateOrderId($attribute)
- {
- if (!$this->hasErrors()) {
- $order = OrderClass::getById($this->orderId, false, 'id, mainId, sendStatus');
- if (empty($order)) {
- $this->addError($attribute, '订单不存在');
- return;
- }
-
- if ($order['mainId'] != Yii::$app->controller->mainId) {
- $this->addError($attribute, '订单不属于当前商户');
- return;
- }
- // 检查订单是否已发过跑腿
- if (!in_array($order['sendStatus'], [-4, -2, -1])) {
- $this->addError($attribute, '订单已经发过跑腿');
- }
- }
- }
- }
|