diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php index fd4d0b43..45b9c7cf 100644 --- a/application/admin/controller/user/User.php +++ b/application/admin/controller/user/User.php @@ -61,6 +61,15 @@ class User extends Backend return $this->view->fetch(); } + /** + * 添加 + */ + public function add() + { + $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), 0, ['class' => 'form-control selectpicker'])); + return parent::add(); + } + /** * 编辑 */ diff --git a/application/admin/model/User.php b/application/admin/model/User.php index 691f3b12..a698f14d 100644 --- a/application/admin/model/User.php +++ b/application/admin/model/User.php @@ -29,6 +29,21 @@ class User extends Model protected static function init() { + self::beforeInsert(function ($row) { + $changed = $row->getChangedData(); + $salt = \fast\Random::alnum(); + $row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt); + $row->salt = $salt; + $row->nickname = $row->nickname ? $row->nickname : $row->username; + $row->joinip = $row->loginip = '127.0.0.1'; + $row->jointime = request()->time(); + //如果生日为空 + if (isset($row->birthday) && empty($row->birthday)) { + unset($row->birthday); + } + }); + + self::beforeUpdate(function ($row) { $changed = $row->getChangedData(); //如果有修改密码 @@ -41,6 +56,10 @@ class User extends Model unset($row->password); } } + //如果生日为空 + if (isset($row->birthday) && empty($row->birthday)) { + unset($row->birthday); + } }); diff --git a/application/admin/view/user/user/add.html b/application/admin/view/user/user/add.html new file mode 100644 index 00000000..1e9835c1 --- /dev/null +++ b/application/admin/view/user/user/add.html @@ -0,0 +1,102 @@ +
+ +
+ +
+ {$groupList} +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ +
+
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + {:build_radios('row[gender]', ['1'=>__('Male'), '0'=>__('Female')])} +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])} +
    +
    + +
    diff --git a/application/admin/view/user/user/index.html b/application/admin/view/user/user/index.html index 00308e8d..9ca85f50 100644 --- a/application/admin/view/user/user/index.html +++ b/application/admin/view/user/user/index.html @@ -6,7 +6,7 @@
    - {:build_toolbar('refresh,edit,del')} + {:build_toolbar('refresh,add,edit,del')}