样机小程序
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\MessageNoticeService;
|
||||
use support\Request;
|
||||
|
||||
class MessageNoticeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new MessageNoticeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
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']);
|
||||
if (isset($data['post_id'])){
|
||||
$data['post'] = Post::where('id', $data['post_id'])->first();
|
||||
$data['post']['media'] = PostMedia::where('post_id', $data['post_id'])->get();
|
||||
}
|
||||
if (isset($data['sender_user_id'])){
|
||||
$ossservice = new OssService();
|
||||
$data['sender_user'] = User::where('id', $data['sender_user_id'])->select(['nickname', 'avatar', 'openid'])->first();
|
||||
|
||||
if(!str_contains($data['sender_user']['avatar'], 'http') && !empty($data['sender_user']['avatar'])){
|
||||
$data['sender_user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['sender_user']['avatar']);
|
||||
}
|
||||
}
|
||||
if (!empty($data['comment_id'])){
|
||||
$data['comment'] = PostComment::where('id', $data['comment_id'])->first();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user