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; } }