132 lines
5.0 KiB
PHP
132 lines
5.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace common\models;
|
||
|
|
|
||
|
|
use Yii;
|
||
|
|
use yii\behaviors\TimestampBehavior;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This is the model class for table "onlinequeue".
|
||
|
|
*
|
||
|
|
* @property int $id
|
||
|
|
* @property string $title คำนำหน้า
|
||
|
|
* @property string $name ชื่อ นามสกุล
|
||
|
|
* @property string $id_card หมายเลขบัตรประชาชน
|
||
|
|
* @property string|null $address ที่อยู่
|
||
|
|
* @property string $tel เบอร์โทรติดต่อ
|
||
|
|
* @property string|null $email E-mail
|
||
|
|
* @property string|null $qdate วันที่จะเข้ารับบริการ
|
||
|
|
* @property string|null $qtime ช่วงเวลา ในการรับบริการ
|
||
|
|
* @property string|null $topic มีความประสงค์รับบริการ
|
||
|
|
* @property string|null $description รายละเอียด
|
||
|
|
* @property string $process ข้าพเจ้าขอรับรองว่าข้อความข้างต้นเป็นความจริงทุกประการ
|
||
|
|
* @property string|null $files แนบหลักฐานร้องเรียน
|
||
|
|
* @property int|null $created_at เพิ่มเมื่อ
|
||
|
|
* @property int|null $updated_at แก้ไขเมื่อ
|
||
|
|
* @property int|null $status สถานะ
|
||
|
|
* @property string|null $proceed การดำเนินการ
|
||
|
|
* @property string|null $remark หมายเหตุ
|
||
|
|
*/
|
||
|
|
class Onlinequeue extends \yii\db\ActiveRecord
|
||
|
|
{
|
||
|
|
|
||
|
|
public function beforeSave($insert)
|
||
|
|
{
|
||
|
|
$quque = Onlinequeue::find()->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', 'หมายเลขบัตรประชาชนของท่านไม่ถูกต้อง');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|