Skip to content

Commit

Permalink
Fix coding standard [skip fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Feb 28, 2017
1 parent 5facff6 commit 7834b36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
31 changes: 16 additions & 15 deletions src/Controller/Admin/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function indexAction($req)
// 用户发送的消息
$user = wei()->arrayCache->get('user' . $message['userId'], function () use ($message) {
$user = wei()->user()->findOrInitById($message['userId']);

return $user->toArray(['id', 'nickName', 'headImg']);
});
} else {
Expand All @@ -95,12 +96,12 @@ public function indexAction($req)
if ($req['_format'] == 'csv') {
return $this->renderCsv($data);
} else {
return $this->json('读取列表成功', 1, array(
return $this->json('读取列表成功', 1, [
'data' => $data,
'page' => $req['page'],
'rows' => $req['rows'],
'records' => $messages->count(),
));
]);
}

default:
Expand All @@ -120,18 +121,18 @@ public function userAction($req)

protected function renderCsv($messages)
{
$data = array();
$data[0] = array('用户', '消息内容', '消息类型', '时间', '是否收藏');
$data = [];
$data[0] = ['用户', '消息内容', '消息类型', '时间', '是否收藏'];
$types = wei()->message->getOption('types');

foreach ($messages as $message) {
$data[] = array(
$data[] = [
$message['nickName'],
is_string($message['content']) ? $message['content'] : '(不支持显示)',
$types[$message['msgType']],
$message['createTime'],
$message['starred'] ? '是' : '否'
);
$message['starred'] ? '是' : '否',
];
}

return wei()->csvExporter->export('messages', $data);
Expand All @@ -144,21 +145,21 @@ public function sendAction($req, $res)
{
// 1. 校验提交的数据
$type = $req['type'] ?: 'text';
$validator = wei()->validate(array(
$validator = wei()->validate([
'data' => $req,
'rules' => [
'userId' => 'required',
'content' => 'required',
'appMsgId' => [
'required' => $type == 'news'
]
'required' => $type == 'news',
],
],
'names' => array(
'names' => [
'userId' => '用户',
'content' => '消息内容',
'appMsgId' => '图文消息编号'
)
));
'appMsgId' => '图文消息编号',
],
]);

if (!$validator->isValid()) {
return $this->err($validator->getFirstMessage());
Expand Down Expand Up @@ -190,7 +191,7 @@ public function sendAction($req, $res)
'msgType' => $type,
'platformId' => $account::PLATFORM_ID,
'content' => $req['content'],
'replyMessageId' => (int)$req['replyMessageId'],
'replyMessageId' => (int) $req['replyMessageId'],
'createTimestamp' => time(),
]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Service/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function afterFind()
break;

default:
$this['content'] = (array)json_decode($this['content'], true);
$this['content'] = (array) json_decode($this['content'], true);
}
}

Expand Down Expand Up @@ -55,6 +55,7 @@ public function setLastReadMessageTime()
{
$appId = wei()->app->getId();
$this->cache->set('lastReadMessageTime' . $appId, time());

return $this;
}

Expand All @@ -66,6 +67,7 @@ public function setLastReadMessageTime()
public function getLastReadMessageTime()
{
$appId = wei()->app->getId();
return (string)$this->cache->get('lastReadMessageTime' . $appId);

return (string) $this->cache->get('lastReadMessageTime' . $appId);
}
}

0 comments on commit 7834b36

Please sign in to comment.