| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace ghs\models\Admin;
- /**
- * 添加员工表单模型
- */
- class AddForm extends BaseForm
- {
- /**
- * @var string 用户名
- */
- public $username;
-
- /**
- * @var string 密码
- */
- public $password;
-
- /**
- * @var string 姓名
- */
- public $name;
-
- /**
- * @var string 手机号
- */
- public $mobile;
-
- /**
- * @var int 角色ID
- */
- public $roleId;
-
- /**
- * @var int 商家ID
- */
- public $sjId;
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['username', 'password', 'name', 'mobile', 'roleId'], 'required', 'message' => '{attribute}不能为空'],
- [['username', 'name'], 'string', 'max' => 50],
- [['password'], 'string', 'min' => 6, 'max' => 20],
- [['mobile'], 'match', 'pattern' => '/^1[3-9]\d{9}$/', 'message' => '手机号格式不正确'],
- [['roleId', 'sjId'], 'integer'],
- [['username'], 'validateUsername'],
- ];
- }
- /**
- * 验证用户名是否已存在
- *
- * @param string $attribute 属性名
- * @param array $params 参数
- */
- public function validateUsername($attribute, $params)
- {
- if (!$this->hasErrors()) {
- $exists = \bizGhs\admin\classes\AdminClass::getByCondition(['username' => $this->$attribute]);
- if ($exists) {
- $this->addError($attribute, '用户名已存在');
- }
- }
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'username' => '用户名',
- 'password' => '密码',
- 'name' => '姓名',
- 'mobile' => '手机号',
- 'roleId' => '角色',
- 'sjId' => '商家ID',
- ];
- }
- }
|