-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加账号管理接口
- Loading branch information
Showing
6 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: kekodmc | ||
* Date: 2020/12/11 | ||
* Time: 11:25 | ||
*/ | ||
|
||
namespace app\controller; | ||
|
||
|
||
use app\BaseController; | ||
use app\service\AccountService; | ||
|
||
class Account extends BaseController | ||
{ | ||
public function index(){ | ||
return invoke(AccountService::class)->index($this->params); | ||
} | ||
public function update(){ | ||
return invoke(AccountService::class)->update($this->params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: kekodmc | ||
* Date: 2020/12/11 | ||
* Time: 18:08 | ||
*/ | ||
|
||
namespace app\service; | ||
|
||
|
||
use app\model\AdminModel; | ||
use app\validate\AccountValidate; | ||
use think\exception\ValidateException; | ||
|
||
class AccountService extends BaseService | ||
{ | ||
public function index($params){ | ||
$data=AdminModel::find($params['uid']); | ||
return successResponse('查询成功',[ | ||
'username'=>$data->username, | ||
'avatar'=>$data->avatar, | ||
]); | ||
} | ||
public function update($params){ | ||
try { | ||
validate(AccountValidate::class)->scene('update')->check($params); | ||
} catch (ValidateException $e) { | ||
// 验证失败 输出错误信息 | ||
return errorResponse($e->getError()); | ||
} | ||
$password=$params['password']??''; | ||
$data=AdminModel::find($params['uid']); | ||
$data->avatar=$params['avatar']; | ||
if($password){ | ||
$data->password=password_hash($password,PASSWORD_BCRYPT,['code'=>9527]); | ||
} | ||
$data->save(); | ||
return successResponse('保存成功'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: kekodmc | ||
* Date: 2020/11/26 | ||
* Time: 10:41 | ||
*/ | ||
|
||
namespace app\validate; | ||
|
||
|
||
|
||
class AccountValidate extends BaseValidate | ||
{ | ||
/** | ||
* 定义验证规则 | ||
* 格式:'字段名' => ['规则1','规则2'...] | ||
* | ||
* @var array | ||
*/ | ||
protected $rule = [ | ||
'avatar'=>'require', | ||
'password'=>'require', | ||
]; | ||
|
||
/** | ||
* 定义错误信息 | ||
* 格式:'字段名.规则名' => '错误信息' | ||
* | ||
* @var array | ||
*/ | ||
protected $message = [ | ||
'avatar.require'=>'请上传头像', | ||
'password.require'=>'请输入密码', | ||
]; | ||
|
||
protected $scene = [ | ||
'update'=>['avatar'], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters