95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
|
|
<?php
|
||
|
|
namespace app\common\controller;
|
||
|
|
|
||
|
|
use app\common\controller\BaseController;
|
||
|
|
use app\common\traits\crud\CrudControllerTrait;
|
||
|
|
use app\common\service\MessageUserStatusService;
|
||
|
|
use support\Request;
|
||
|
|
|
||
|
|
class MessageUserStatusController extends BaseController
|
||
|
|
{
|
||
|
|
use CrudControllerTrait;
|
||
|
|
|
||
|
|
protected $service;
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->service = new MessageUserStatusService();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 列表页数据格式化
|
||
|
|
*
|
||
|
|
* @param array $data
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
protected function indexFormat($data)
|
||
|
|
{
|
||
|
|
if (isset($data['read_at']) && $data['read_at'] !== null) {
|
||
|
|
$data['read_at'] = date('Y-m-d H:i:s', $data['read_at']);
|
||
|
|
} else {
|
||
|
|
$data['read_at'] = ' - ';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($data['message']))
|
||
|
|
$data['message']['created_at'] = date('Y-m-d H:i:s', $data['message']['created_at']);
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function showFormat($data)
|
||
|
|
{
|
||
|
|
if (isset($data['read_at']) && $data['read_at'] !== null) {
|
||
|
|
$data['read_at'] = date('Y-m-d H:i:s', $data['read_at']);
|
||
|
|
} else {
|
||
|
|
$data['read_at'] = ' - ';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($data['message']))
|
||
|
|
$data['message']['created_at'] = date('Y-m-d H:i:s', $data['message']['created_at']);
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function unReadFormat($data)
|
||
|
|
{
|
||
|
|
foreach ($data as &$item) {
|
||
|
|
if (isset($item['read_at']) && $item['read_at'] !== null) {
|
||
|
|
$item['read_at'] = date('Y-m-d H:i:s', $item['read_at']);
|
||
|
|
} else {
|
||
|
|
$item['read_at'] = ' - ';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($item['message'])) {
|
||
|
|
$item['message']['created_at'] = date('Y-m-d H:i:s', $item['message']['created_at']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function read(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'read');
|
||
|
|
$this->service->serviceRead($request, $data);
|
||
|
|
return $this->success([], '操作成功');
|
||
|
|
} catch (\Throwable $e) {
|
||
|
|
return $this->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function listUnRead(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$raw = $this->service->serviceListUnRead($request);
|
||
|
|
$data = $this->transformData($raw, method_exists($this, 'unReadFormat')
|
||
|
|
? [$this, 'unReadFormat']
|
||
|
|
: null);
|
||
|
|
$data = [
|
||
|
|
'list' => $data,
|
||
|
|
'counts' => count($data)
|
||
|
|
];
|
||
|
|
return $this->success($data);
|
||
|
|
} catch (\Throwable $e) {
|
||
|
|
return $this->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|