|
@@ -31,7 +31,64 @@ class Coach extends Model
|
|
|
'jointime_text',
|
|
|
'status_text'
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
+ protected static function init()
|
|
|
+ {
|
|
|
+ self::beforeUpdate(function ($row) {
|
|
|
+ $changed = $row->getChangedData();
|
|
|
+ //如果有修改密码
|
|
|
+ if (isset($changed['password'])) {
|
|
|
+ if ($changed['password']) {
|
|
|
+ $salt = \fast\Random::alnum();
|
|
|
+ $row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt);
|
|
|
+ $row->salt = $salt;
|
|
|
+ } else {
|
|
|
+ unset($row->password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //email查重
|
|
|
+ if (isset($changed['email'])) {
|
|
|
+ if($changed['email']){
|
|
|
+ $exists = db('coach')->where('email', $changed['email'])->where('id', '<>', $row->id)->find();
|
|
|
+ if ($exists) {
|
|
|
+ abort(500,'email已经被使用');
|
|
|
+ }
|
|
|
+ $exists = db('user')->where('email', $changed['email'])->find();
|
|
|
+ if ($exists) {
|
|
|
+ abort(500,'email已经被用户使用');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ self::beforeInsert(function ($row) {
|
|
|
+ if (isset($row['password'])) {
|
|
|
+ if ($row['password']) {
|
|
|
+ $salt = \fast\Random::alnum();
|
|
|
+ $row->password = \app\common\library\Auth::instance()->getEncryptPassword($row['password'], $salt);
|
|
|
+ $row->salt = $salt;
|
|
|
+ } else {
|
|
|
+ unset($row->password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //email查重
|
|
|
+ if($row['email']){
|
|
|
+ $exists = db('coach')->where('email', $row['email'])->find();
|
|
|
+ if ($exists) {
|
|
|
+ abort(500,'email已经被使用');
|
|
|
+ }
|
|
|
+ $exists = db('user')->where('email', $row['email'])->find();
|
|
|
+ if ($exists) {
|
|
|
+ abort(500,'email已经被用户使用');
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ abort(500,'email不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public function getGenderList()
|