where(['qtime'=>$this->qtime, 'qdate'=>$this->qdate])->count(); if ($quque>=1){ $this->addError('qdate', 'คิวเต็มแล้ว'); } return parent::beforeSave($insert); // TODO: Change the autogenerated stub } public $verifyCode; /** * {@inheritdoc} */ public static function tableName() { return 'onlinequeue'; } public function behaviors() { return [ TimestampBehavior::class, ]; } /** * {@inheritdoc} */ public function rules() { return [ [['title', 'name', 'id_card', 'tel', 'process'], 'required'], [['address', 'description', 'proceed', 'remark'], 'string'], [['qtime', 'created_at', 'updated_at', 'status'], 'integer'], [['title', 'id_card'], 'string', 'max' => 45], [['id_card'], 'validateIdCard'], [['name', 'topic'], 'string', 'max' => 200], [['qdate'],'safe'], [['tel', 'email', 'process'], 'string', 'max' => 100], [['files'], 'string', 'max' => 500], ['verifyCode', 'captcha'], //[['qdate', 'qtime'], 'validateDateTime'] ]; } /*public function validateDateTime($attribute, $params, $validator) { $quque = self::find()->where(['qtime'=>$this->qtime, 'qdate'=>$this->qdate])->count(); if ($quque == 1){ $this->addError('qdate', 'คิวเต็มแล้ว'); $this->addError('qtime', 'คิวเต็มแล้ว'); } } */ /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'title' => 'คำนำหน้า', 'name' => 'ชื่อ นามสกุล', 'id_card' => 'หมายเลขบัตรประชาชน', 'address' => 'ที่อยู่', 'tel' => 'เบอร์โทรติดต่อ', 'email' => 'E-mail', 'qdate' => 'วันที่จะเข้ารับบริการ', 'qtime' => 'ช่วงเวลา ในการรับบริการ', 'topic' => 'มีความประสงค์รับบริการ', 'description' => 'รายละเอียด', 'process' => 'ข้าพเจ้าขอรับรองว่าข้อความข้างต้นเป็นความจริงทุกประการ', 'files' => 'แนบหลักฐานร้องเรียน', 'created_at' => 'เพิ่มเมื่อ', 'updated_at' => 'แก้ไขเมื่อ', 'status' => 'สถานะ', 'proceed' => 'การดำเนินการ', 'remark' => 'หมายเหตุ', ]; } public function validateIdCard() { $id = str_split(str_replace('-', '', $this->id_card)); $digi = 13; $sum = 0; foreach ($id as $key){ $digi > 1 ? $sum += intval($key) * $digi : null; $digi--; } $n13 = (11 - ($sum % 11)) % 10; if ($n13 != $id[12]) { $this->addError('id_card', 'หมายเลขบัตรประชาชนของท่านไม่ถูกต้อง'); } } }