Commit ea6fd439d25b37638795dbc3c9cad11d2c74a1e8
1 parent
34e6378e
[留言板]留言信息添加
Showing
3 changed files
with
87 additions
and
8 deletions
trunk/Message/Api/Controller/Message/MsgController.class.php
@@ -3,19 +3,60 @@ | @@ -3,19 +3,60 @@ | ||
3 | namespace Api\Controller\Message; | 3 | namespace Api\Controller\Message; |
4 | 4 | ||
5 | use Api\Controller\AbstractController; | 5 | use Api\Controller\AbstractController; |
6 | +use Common\Model\MessageModel; | ||
7 | +use Common\Model\AttachmentModel; | ||
6 | 8 | ||
7 | class MsgController extends AbstractController | 9 | class MsgController extends AbstractController |
8 | { | 10 | { |
9 | 11 | ||
10 | - public function Index_get() | 12 | + /** |
13 | + * 发布留言 | ||
14 | + * @author <362431947@qq.com> | ||
15 | + * @date 2018-10-09 | ||
16 | + */ | ||
17 | + public function Index_post() | ||
11 | { | 18 | { |
19 | + // echo md5('123'); | ||
20 | + // echo $msectime; 1539069172335 | ||
21 | + $input = I('post.'); | ||
12 | 22 | ||
13 | - $this->_result = array( | ||
14 | - 'total' => 0, | ||
15 | - 'list' => ['test' => 'Message/success'], | ||
16 | - 'title' => L('DEFAULT_TITLE') | ||
17 | - ); | 23 | + if(! $input){ |
24 | + E('_ERR_POST_EMPTY'); | ||
25 | + } | ||
18 | 26 | ||
19 | - return true; | 27 | + $title = $input['title']; |
28 | + if(! $title){ | ||
29 | + E('_ERROR_TITLE_EMPTY'); | ||
30 | + } | ||
31 | + | ||
32 | + if(get_str_len($title) > 80){ | ||
33 | + E('_ERROR_MESSAGE_TITLE_LENGTH'); | ||
34 | + } | ||
35 | + | ||
36 | + $message = $input['message']; | ||
37 | + if(! $message){ | ||
38 | + E('_ERROR_MESSAGE_EMPTY'); | ||
39 | + } | ||
40 | + | ||
41 | + if(get_str_len($message) > 500){ | ||
42 | + E('_ERROR_MESSAGE_LENGTH'); | ||
43 | + } | ||
44 | + | ||
45 | + $input['ip'] = $_SERVER['REMOTE_ADDR']; | ||
46 | + $input['uid'] = session['auth_login']['uid']; | ||
47 | + $input['attachment'] = ''; | ||
48 | + // 素材id,多个使用逗号分隔 | ||
49 | + // $input['receiver_uid'] = ''; // 不能是自己 | ||
50 | + $input['domain'] = md5($_SERVER['HTTP_HOST']); | ||
51 | + | ||
52 | + | ||
53 | + $m_message = new MessageModel(); | ||
54 | + | ||
55 | + $m_attachment = new AttachmentModel(); | ||
56 | + | ||
57 | + $result = $m_attachment->add(); | ||
58 | + | ||
59 | + $this->_result = boolval($result); | ||
20 | } | 60 | } |
21 | -} | ||
22 | \ No newline at end of file | 61 | \ No newline at end of file |
62 | + | ||
63 | +} |
trunk/Message/Common/Model/AbstractModel.class.php
@@ -17,4 +17,18 @@ abstract class AbstractModel extends \Com\Model | @@ -17,4 +17,18 @@ abstract class AbstractModel extends \Com\Model | ||
17 | parent::__construct(); | 17 | parent::__construct(); |
18 | 18 | ||
19 | } | 19 | } |
20 | + | ||
21 | + /** | ||
22 | + * 毫秒时间戳 | ||
23 | + * @author <362431947@qq.com> | ||
24 | + * @date 2018-10-09 | ||
25 | + * @return int | ||
26 | + */ | ||
27 | + public function microtime() | ||
28 | + { | ||
29 | + list($msec, $sec) = explode(' ', microtime()); | ||
30 | + $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); | ||
31 | + | ||
32 | + return $msectime; | ||
33 | + } | ||
20 | } | 34 | } |
trunk/Message/Common/Model/MessageModel.class.php
0 → 100644
1 | +<?php | ||
2 | +namespace Common\Model; | ||
3 | + | ||
4 | +class MessageModel extends AbstractModel | ||
5 | +{ | ||
6 | + /** | ||
7 | + * 添加留言内容 | ||
8 | + * @author <362431947@qq.com> | ||
9 | + * @date 2018-10-09 | ||
10 | + * @param array $data | ||
11 | + */ | ||
12 | + public function addOne(array $data) | ||
13 | + { | ||
14 | + if(! is_array($data)|| ! $data){ | ||
15 | + return false; | ||
16 | + } | ||
17 | + | ||
18 | + $data['created'] = $this->microtime(); | ||
19 | + | ||
20 | + $result = $this->_m->insert($data); | ||
21 | + | ||
22 | + return $result; | ||
23 | + } | ||
24 | +} |