cxgj/models/Address.php
2023-11-27 09:45:13 +08:00

172 lines
5.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\models;
use Yii;
use app\models\Model;
/**
* This is the model class for table "{{%address}}".
*
* @property int $id ID
* @property int $cx_mch_id 平台商户ID
* @property int $user_id 用户ID
* @property string $name 姓名
* @property string $mobile 手机号
* @property int $province_id 省ID
* @property string|null $province 省
* @property int $city_id 市ID
* @property string|null $city 市
* @property int $district_id 区ID
* @property string|null $district 区
* @property int $town_id 镇id
* @property string|null $town 镇
* @property string|null $detail 详细地址
* @property string|null $formatted_addr 可读地址
* @property int $is_default 是否默认0=否1=是
* @property string $lat 纬度
* @property string $lng 经度
* @property int $created_at 添加时间
* @property int $updated_at 更新时间
* @property int $deleted_at 删除时间
* @property int $is_delete 是否删除0=否1=是
* @property int $gender 性别0=未知1=男2=女3=保密
* @property int $tag 标签0=未知1=家2=公司3=学校4=其他
*/
class Address extends \yii\db\ActiveRecord
{
const GENDER_UNKNOWN = 0;
const GENDER_MAN = 1;
const GENDER_WOMEN = 2;
const GENDER_SECRET = 3;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%address}}';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'detail', 'formatted_addr', 'mobile', 'province', 'city', 'district', 'town', 'lat', 'lng'], 'trim'],
[['cx_mch_id', 'user_id', 'province_id', 'city_id', 'district_id', 'town_id', 'is_default', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'gender', 'tag'], 'integer'],
[['user_id', 'name', 'mobile', 'lat', 'lng'], 'required'],
[['name', 'detail', 'formatted_addr'], 'string', 'max' => 256],
[['mobile'], 'string', 'max' => 16],
[['province', 'city', 'district', 'town'], 'string', 'max' => 50],
[['lat', 'lng'], 'string', 'max' => 32],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'cx_mch_id' => '平台商户ID',
'user_id' => '用户ID',
'name' => '姓名',
'mobile' => '手机号',
'province_id' => '省ID',
'province' => '省',
'city_id' => '市ID',
'city' => '市',
'district_id' => '区ID',
'district' => '区',
'town_id' => '镇id',
'town' => '镇',
'detail' => '详细地址',
'formatted_addr' => '可读地址',
'is_default' => '是否默认0=否1=是',
'lat' => '纬度',
'lng' => '经度',
'created_at' => '添加时间',
'updated_at' => '更新时间',
'deleted_at' => '删除时间',
'is_delete' => '是否删除0=否1=是',
'gender' => '性别0=未知1=男2=女3=保密',
'tag' => '标签0=未知1=家2=公司3=学校4=其他',
];
}
public function beforeSave($insert) {
if(parent::beforeSave($insert)){
if($this->isNewRecord){
$this->created_at = time();
}
$this->updated_at = time();
if($this->is_delete == 1)
$this->deleted_at = time();
$this->htmlTagFilter();
return true;
} else {
return false;
}
}
public function htmlTagFilter()
{
$this->name = Model::htmlTagFilter($this->name);
$this->mobile = Model::htmlTagFilter($this->mobile);
$this->province = Model::htmlTagFilter($this->province);
$this->city = Model::htmlTagFilter($this->city);
$this->district = Model::htmlTagFilter($this->district);
$this->town = Model::htmlTagFilter($this->town);
$this->detail = Model::htmlTagFilter($this->detail);
$this->formatted_addr = Model::htmlTagFilter($this->formatted_addr);
$this->lat = Model::htmlTagFilter($this->lat);
$this->lng = Model::htmlTagFilter($this->lng);
}
public static function getGender($gender)
{
$labels = self::genderLabels();
return isset($labels[$gender]) ? $labels[$gender] : "未知";
}
public static function genderLabels()
{
return [
'0' => '未知',
'1' => '男',
'2' => '女',
'3' => '保密'
];
}
public static function getTag($tag)
{
$labels = self::tagLabels();
return isset($labels[$tag]) ? $labels[$tag] : "未知";
}
public static function tagLabels()
{
return [
'0' => '未知',
'1' => '家',
'2' => '公司',
'3' => '学校',
'4' => '其他',
];
}
public function getLocation()
{
return $this->lat.','.$this->lng;
}
}