|
|
<?php
namespace antgoods\models\ars;
use Yii; use yii\behaviors\TimestampBehavior;
/** * This is the model class for table "antgoods_supplier". * * @property int $id * @property string $name 供应商名称 * @property string $full_name 供应商全称 * @property string $phone 手机号码 * @property string $address 地址 * @property int $is_delete 是否删除,1为已删除 * @property int $created_at 创建时间 * @property int $updated_at 更新时间 */ class Supplier extends \yii\db\ActiveRecord { //是否删除is_delete
const IS_DELETE_NO = 0;//未删除
const IS_DELETE_YES = 1;//已删除
/** * {@inheritdoc} */ public static function tableName() { return 'antgoods_supplier'; }
/** * {@inheritdoc} */ public function rules() { return [ [['name', 'full_name', 'phone', 'address'], 'required'], [['is_delete'], 'integer'], [['name', 'full_name', 'address'], 'string', 'max' => 50], [['phone'], 'string', 'max' => 20], ['phone', 'filter', 'filter' => 'trim'], ['phone','match','pattern'=>'/^[1][34578][0-9]{9}$/'], ['phone', 'unique', 'targetClass' => '\antgoods\models\ars\Supplier', 'message' => '手机号已被使用'], ]; }
/** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'id', 'name' => '供应商名称', 'full_name' => '供应商全称', 'phone' => '手机号码', 'address' => '地址', 'is_delete' => '是否删除,1为已删除', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; }
/** * @author linyao * @email 602604991@qq.com * @created Nov 8, 2019 * * 行为存储创建时间和更新时间 */ public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => function() { return time(); }, ], ]; }
/** * @return array * 数据键值对 */ public static function modelColumn() { return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); } }
|