Files
useds/app/common/controller/UserController.php
T

100 lines
2.9 KiB
PHP
Raw Normal View History

2026-01-05 14:33:21 +08:00
<?php
namespace app\common\controller;
2026-01-05 15:49:25 +08:00
use app\common\controller\BaseController;
2026-01-13 15:39:49 +08:00
use app\common\service\OssService;
2026-01-05 14:33:21 +08:00
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\UserService;
use support\Request;
2026-01-05 14:33:21 +08:00
class UserController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new UserService();
}
/**
2026-01-05 15:49:25 +08:00
* 列表页数据格式化
2026-01-05 14:33:21 +08:00
*
2026-01-05 15:49:25 +08:00
* @param array $data
* @return array
2026-01-05 14:33:21 +08:00
*/
2026-01-05 15:49:25 +08:00
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
/**
* 更新
*
* @param Request $request 请求对象
* @return mixed 返回更新成功的数据或信息
*/
public function edit(Request $request)
{
try {
$data = $request->post();
$request->setPost('id',$request->user['id']);
$res = $this->service->serviceUpdate($request, $data);
return $this->success([], '更新成功');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 获取详情
*
* @param Request $request 请求对象
* @param int|string $id 资源 ID
* @return mixed 返回资源详情数据
*/
public function show(Request $request)
{
try {
$request->setGet('id',$request->user['id']);
$raw = $this->service->serviceShow($request);
$data = $this->transformData($raw, method_exists($this, 'showFormat')
? [$this, 'showFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
unset($data['union_id']);
unset($data['app_id']);
2026-01-13 15:39:49 +08:00
$ossservice = new OssService();
2026-01-14 13:43:45 +08:00
$data['avatar_pull'] = $data['avatar'];
if(!str_contains($data['avatar'], 'http') && !str_contains($data['avatar'], 'www.') && !empty($data['user']['avatar'])){
$data['avatar_pull'] = $ossservice->generatePrivateUrl($data['avatar']);
2026-01-13 15:39:49 +08:00
}
2026-01-19 11:02:40 +08:00
if (isset($data['social_code']))
$data['social_code_pull'] = $ossservice->generatePrivateUrl($data['social_code']);
return $data;
}
2026-01-05 14:33:21 +08:00
}