85 lines
2.0 KiB
PHP
85 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Domains\Company\Http\Controllers;
|
|
|
|
use App\Core\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Domains\Virtual\Services\CompanyAccountService;
|
|
|
|
class AccountController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $companyAccountService;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, CompanyAccountService $companyAccountService)
|
|
{
|
|
$this->request = $request;
|
|
$this->companyAccountService = $companyAccountService;
|
|
$this->account = $request->user('company');
|
|
}
|
|
|
|
/**
|
|
* 修改密码.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function passwordByOld()
|
|
{
|
|
$oldPassword = $this->request->get('old_password');
|
|
$password = $this->request->get('password');
|
|
|
|
if ($this->account->password !== md5($oldPassword . $this->account->salt)) {
|
|
return err('原密码不正确');
|
|
}
|
|
|
|
if ($this->account->password === md5($password . $this->account->salt)) {
|
|
return err('密码未修改');
|
|
}
|
|
|
|
$attributes = [
|
|
'id' => $this->account->id,
|
|
'password' => $password,
|
|
];
|
|
|
|
$account = $this->companyAccountService->store($attributes);
|
|
|
|
return res($account, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 修改密码.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function password()
|
|
{
|
|
$attributes = [
|
|
'id' => $this->account->id,
|
|
'password' => $this->request->get('password'),
|
|
];
|
|
|
|
$account = $this->companyAccountService->store($attributes);
|
|
|
|
return res($account, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 绑定手机.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function mobile()
|
|
{
|
|
$attributes = [
|
|
'id' => $this->account->id,
|
|
'mobile' => $this->request->get('mobile'),
|
|
];
|
|
|
|
$account = $this->companyAccountService->store($attributes);
|
|
|
|
return res($account, '修改成功');
|
|
}
|
|
}
|