用户编辑,帖子创建优化
This commit is contained in:
@@ -127,6 +127,24 @@ class UserController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改名字与头像
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
* @throws \Random\RandomException
|
||||||
|
*/
|
||||||
|
public function save(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$uid = $request->user->uid;
|
||||||
|
$data = $request->all();
|
||||||
|
$result = (new UserService())->save($uid,$data);;
|
||||||
|
return $this->success($result, '编辑成功');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class PostService
|
|||||||
if (isset($p['category_id']) && $p['category_id']) {
|
if (isset($p['category_id']) && $p['category_id']) {
|
||||||
$config['where']['category_id'] = $p['category_id'];
|
$config['where']['category_id'] = $p['category_id'];
|
||||||
}
|
}
|
||||||
if (isset($p['self']) && $p['self']) {
|
if (isset($p['scene']) && $p['scene']=='self') {
|
||||||
$config['where']['user_id'] = $request->user->uid;
|
$config['where']['user_id'] = $request->user->uid;
|
||||||
}
|
}
|
||||||
$config['where']['status'] = 1;
|
$config['where']['status'] = 1;
|
||||||
@@ -95,11 +95,14 @@ class PostService
|
|||||||
{
|
{
|
||||||
$media = redis::get('PostMedia_'.$res['user_id']);
|
$media = redis::get('PostMedia_'.$res['user_id']);
|
||||||
$media = unserialize($media);
|
$media = unserialize($media);
|
||||||
|
if(!is_array($media)){
|
||||||
|
$media = explode(',',$media);
|
||||||
|
}
|
||||||
foreach ($media as $v) {
|
foreach ($media as $v) {
|
||||||
PostMedia::create([
|
PostMedia::create([
|
||||||
'post_id' => $res->id,
|
'post_id' => $res->id,
|
||||||
'media_type' => $this->getMediaTypeByUrl($v['url']),
|
'media_type' => $this->getMediaTypeByUrl($v),
|
||||||
'url' => $v['url'],
|
'url' => $v,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,8 +157,6 @@ class UserService
|
|||||||
return $this->logic->getList();
|
return $this->logic->getList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户密码
|
* 修改用户密码
|
||||||
*/
|
*/
|
||||||
@@ -175,7 +173,20 @@ class UserService
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户密码
|
||||||
|
*/
|
||||||
|
public function save(int $uid, array $data)
|
||||||
|
{
|
||||||
|
// 对密码进行哈希处理
|
||||||
|
$user = User::find($uid);
|
||||||
|
$keysToKeep = ['name', 'avatar'];
|
||||||
|
|
||||||
|
$data = array_intersect_key($data, array_flip($keysToKeep));
|
||||||
|
|
||||||
|
$user = $user::update($data);
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取微信小程序用户信息(登录及获取手机号)
|
* 获取微信小程序用户信息(登录及获取手机号)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ Route::group('/common', function () {
|
|||||||
Route::group('/user', function () {
|
Route::group('/user', function () {
|
||||||
Route::any('/info', [app\common\controller\UserController::class, 'info']);
|
Route::any('/info', [app\common\controller\UserController::class, 'info']);
|
||||||
Route::any('/update/password', [app\common\controller\UserController::class, 'savePassword']);
|
Route::any('/update/password', [app\common\controller\UserController::class, 'savePassword']);
|
||||||
|
Route::any('/update', [app\common\controller\UserController::class, 'save']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group('/preset', function () {
|
Route::group('/preset', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user