|
@@ -3,7 +3,6 @@
|
|
|
namespace app\common\library;
|
|
|
|
|
|
use app\common\model\Coach;
|
|
|
-use app\common\model\UserRule;
|
|
|
use fast\Random;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
@@ -156,9 +155,9 @@ class Authcoach
|
|
|
* @param string $password 密码
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- public function login($account, $password, $openid)
|
|
|
+ public function login($account, $password)
|
|
|
{
|
|
|
- $field = 'mobile';
|
|
|
+ $field = 'email';
|
|
|
$user = Coach::get([$field => $account]);
|
|
|
if (!$user) {
|
|
|
$this->setError('Account is incorrect');
|
|
@@ -175,7 +174,7 @@ class Authcoach
|
|
|
}
|
|
|
|
|
|
//直接登录员工
|
|
|
- return $this->direct($user->id,$openid);
|
|
|
+ return $this->direct($user->id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -198,89 +197,45 @@ class Authcoach
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 修改密码
|
|
|
- * @param string $newpassword 新密码
|
|
|
- * @param string $oldpassword 旧密码
|
|
|
- * @param bool $ignoreoldpassword 忽略旧密码
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public function resetpwd($newpassword)
|
|
|
- {
|
|
|
- if (!$this->_logined) {
|
|
|
- $this->setError('You are not logged in');
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
-
|
|
|
- $salt = Random::alnum();
|
|
|
- $newpassword = $this->getEncryptPassword($newpassword, $salt);
|
|
|
- //unset($this->_user['company']);
|
|
|
- $this->_user->save(['password' => $newpassword, 'salt' => $salt]);
|
|
|
-
|
|
|
- Tokencoach::delete($this->_token);
|
|
|
-
|
|
|
- //同步到admin
|
|
|
- $admin = [
|
|
|
- 'password' => $newpassword,
|
|
|
- 'salt' => $salt,
|
|
|
- 'updatetime' => time(),
|
|
|
- ];
|
|
|
- $admin_rs = Db::name('admin')->where('staff_id',$this->_user->id)->update($admin);
|
|
|
- if($admin_rs === false){
|
|
|
- Db::rollback();
|
|
|
- $this->setError('重置失败');
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Db::commit();
|
|
|
-
|
|
|
- return true;
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 直接登录账号
|
|
|
* @param int $user_id
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- public function direct($staff_id,$openid = '')
|
|
|
+ public function direct($user_id)
|
|
|
{
|
|
|
- $user = CompanyStaff::get($staff_id);
|
|
|
+ $user = Coach::get($user_id);
|
|
|
if ($user) {
|
|
|
- if(!$user->company_id){
|
|
|
- return false;
|
|
|
- }
|
|
|
- $companyinfo = Company::get($user->company_id);
|
|
|
- if(!$companyinfo){
|
|
|
- return false;
|
|
|
- }
|
|
|
- if($companyinfo->status != 1){
|
|
|
- $this->setError('当前门店未通过审核');
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
+ $ip = request()->ip();
|
|
|
+ $time = time();
|
|
|
|
|
|
- if(!empty($openid)){
|
|
|
- $user->openid = $openid;
|
|
|
- $user->save();
|
|
|
+ //判断连续登录和最大连续登录
|
|
|
+ if ($user->logintime < \fast\Date::unixtime('day')) {
|
|
|
+ $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1;
|
|
|
+ $user->maxsuccessions = max($user->successions, $user->maxsuccessions);
|
|
|
}
|
|
|
- $user->openid = '';
|
|
|
|
|
|
- $user->company = $companyinfo;// 追加公司
|
|
|
+ $user->prevtime = $user->logintime;
|
|
|
+ //记录本次登录的IP和时间
|
|
|
+ $user->loginip = $ip;
|
|
|
+ $user->logintime = $time;
|
|
|
+ //重置登录失败次数
|
|
|
+ $user->loginfailure = 0;
|
|
|
+
|
|
|
+ $user->save();
|
|
|
|
|
|
$this->_user = $user;
|
|
|
|
|
|
$this->_token = Random::uuid();
|
|
|
- Tokencompany::set($this->_token, $user->id, $this->keeptime);
|
|
|
+ Tokencoach::set($this->_token, $user->id, $this->keeptime);
|
|
|
|
|
|
$this->_logined = true;
|
|
|
|
|
|
//登录成功的事件
|
|
|
- Hook::listen("company_login_successed", $this->_user);
|
|
|
+ Hook::listen("user_login_successed", $this->_user);
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
@@ -324,17 +279,10 @@ class Authcoach
|
|
|
$data = $this->_user->toArray();
|
|
|
$allowFields = $this->getAllowFields();
|
|
|
$userinfo = array_intersect_key($data, array_flip($allowFields));
|
|
|
- $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
|
|
|
+ $userinfo = array_merge($userinfo, Tokencoach::get($this->_token));
|
|
|
|
|
|
//追加
|
|
|
- $userinfo['company']['image'] = one_domain_image($userinfo['company']['image']);
|
|
|
-
|
|
|
- /////////////////////////////////////
|
|
|
- //个人信息
|
|
|
- $strattime = strtotime(date('Y-m-d'));
|
|
|
- $endtime = $strattime + 86399;
|
|
|
-
|
|
|
-
|
|
|
+ $userinfo['avatar'] = one_domain_image($userinfo['avatar']);
|
|
|
|
|
|
return $userinfo;
|
|
|
}
|