'请选择客户'], ['product', 'required', 'message' => '请选择花材'], [['customId', 'expressId', 'book', 'sendType', 'transType', 'hasPay', 'callErrand', 'isCashier', 'getStaffId', 'shopAdminId', 'bookSn', 'needPrint'], 'integer'], [['modifyPrice', 'dealPrice', 'sendCost', 'packCost', 'deliveryPrice', 'deliveryDistance', 'weight'], 'number'], [['getStaffName', 'shopAdminName', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'historyDate', 'deliveryRemark'], 'string'], [['xj', 'product', 'payWay', 'deliveryAllParams'], 'safe'], ['modifyPrice', 'match', 'pattern' => '/^\d+(\.\d{1,2})?$/', 'message' => '金额不能超2位小数'], ['product', 'validateProduct'], ['historyDate', 'validateHistoryDate'], // 此规则依赖 Controller 上下文中的 shop->pfLevel 判断,可能不适合完全移入 Model,除非 Model 能获取 Shop 信息。 // 暂时不在 Model 中校验 sendCost 与 sendType 的复杂业务逻辑,因为涉及到 Shop 属性判断。 ]; } public function attributeLabels() { return [ 'customId' => '客户', 'modifyPrice' => '修改价格', 'product' => '花材', 'historyDate' => '订单日期', 'sendCost' => '运费', ]; } public function validateProduct($attribute, $params) { if (!$this->hasErrors()) { $productJson = $this->$attribute; if (empty($productJson)) { $this->addError($attribute, '请选择花材'); return; } $productList = json_decode($productJson, true); if (empty($productList)) { $this->addError($attribute, '请选择花材'); } } } public function validateHistoryDate($attribute, $params) { if (!$this->hasErrors() && !empty($this->historyDate)) { if ($this->book == 1) { $this->addError($attribute, '预订单不能选订单日期'); return; } // hasPay == 0 通常指 unPay / 扫码付?需确认 dict。 // 假设 Controller 逻辑: if ($hasPay == 0) fail('扫码付不能选订单日期'); // 这里 $hasPay 可能是 null,如果不传。 // Controller 逻辑: $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); // Model 中如果 load 进来,hasPay 会有值。 // 需要引入 dict 类。 // 注意:Controller 中 hasPay 的默认值处理逻辑是在 validation 之后(或者中间)。 // 我们可以尝试模拟这个默认值,或者只验证当 hasPay 明确为 0 时。 // Controller logic: // $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); // if ($hasPay == 0) ... $hasPayVal = $this->hasPay ?? dict::getDict('hasPay', 'unPay'); if ($hasPayVal == 0) { $this->addError($attribute, '扫码付不能选订单日期'); return; } } } }