134 lines
4.9 KiB
PHP
134 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace common\models;
|
|
|
|
use Yii;
|
|
use yii\web\UploadedFile;
|
|
use yii\helpers\FileHelper;
|
|
use yii\behaviors\TimestampBehavior;
|
|
|
|
/**
|
|
* This is the model class for table "getbin".
|
|
*
|
|
* @property int $id
|
|
* @property string $title คำนำหน้า
|
|
* @property string $name ชื่อ นามสกุล
|
|
* @property string $id_card หมายเลขบัตรประชาชน
|
|
* @property string|null $address ที่อยู่
|
|
* @property string $tel เบอร์โทรติดต่อ
|
|
* @property string $map ภาพถ่ายสถานที่ ที่ต้องการรับบริการ
|
|
* @property string|null $email E-mail
|
|
* @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 Getbin extends \yii\db\ActiveRecord
|
|
{
|
|
|
|
public $verifyCode;
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function tableName()
|
|
{
|
|
return 'getbin';
|
|
}
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
TimestampBehavior::class,
|
|
];
|
|
}
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['title', 'name', 'id_card', 'tel', 'map', 'process'], 'required'],
|
|
[['address', 'description', 'proceed', 'remark'], 'string'],
|
|
[['created_at', 'updated_at', 'status'], 'integer'],
|
|
[['title', 'id_card'], 'string', 'max' => 45],
|
|
[['id_card'], 'validateIdCard'],
|
|
[['name', 'topic'], 'string', 'max' => 200],
|
|
[['tel', 'email', 'process'], 'string', 'max' => 100],
|
|
[['files'], 'string', 'max' => 500],
|
|
[['map'], 'file', 'extensions' => 'pdf,jpg,png'],
|
|
['verifyCode', 'captcha'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'ID',
|
|
'title' => 'คำนำหน้า',
|
|
'name' => 'ชื่อ นามสกุล',
|
|
'id_card' => 'หมายเลขบัตรประชาชน',
|
|
'address' => 'ที่อยู่',
|
|
'tel' => 'เบอร์โทรติดต่อ',
|
|
'map' => 'ภาพถ่ายสถานที่ ที่ต้องการรับบริการ',
|
|
'email' => 'E-mail',
|
|
'topic' => 'เรื่องร้องเรียน',
|
|
'description' => 'รายละเอียด',
|
|
'process' => 'ข้าพเจ้าขอรับรองว่าข้อความข้างต้นเป็นความจริงทุกประการ',
|
|
'files' => 'แนบหลักฐานร้องเรียน',
|
|
'created_at' => 'เพิ่มเมื่อ',
|
|
'updated_at' => 'แก้ไขเมื่อ',
|
|
'status' => 'สถานะ',
|
|
'proceed' => 'การดำเนินการ',
|
|
'remark' => 'หมายเหตุ',
|
|
];
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
|
|
public function uploadGetbin($model, $attribute)
|
|
{
|
|
$file = UploadedFile::getInstance($model, $attribute);
|
|
if($file) {
|
|
$file_name = time().'_'.$attribute.'.'.$file->extension;
|
|
|
|
$mimeType = FileHelper::getMimeType($file->tempName, null, false);
|
|
if (in_array($file->extension, ['pdf','jpg', 'jpeg', 'png'])&& in_array($mimeType,['application/pdf','image/jpeg','image/png']) ) {
|
|
if($file->saveAs(Yii::getAlias('@webroot').'/uploads/getbin/'.$file_name)){
|
|
return $file_name;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return $model->isNewRecord ? false : $this->getOldAttribute($attribute);
|
|
}
|
|
|
|
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', 'หมายเลขบัตรประชาชนของท่านไม่ถูกต้อง');
|
|
}
|
|
}
|
|
/**
|
|
*
|
|
*/
|
|
}
|