Commit 4652874d7b93ce8bb042e9cebdc19e71a37ed801
1 parent
d089895c
[留言板]手机端留言添加
Showing
1 changed file
with
68 additions
and
0 deletions
trunk/Message/Api/Controller/Message/AddController.class.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Api\Controller\Message; | ||
4 | + | ||
5 | +use Api\Controller\AbstractController; | ||
6 | +use Common\Model\MessageModel; | ||
7 | +use Common\Model\AttachmentModel; | ||
8 | + | ||
9 | +class AddController extends AbstractController | ||
10 | +{ | ||
11 | + /** | ||
12 | + * 发布留言 | ||
13 | + * @author <362431947@qq.com> | ||
14 | + * @date 2018-10-09 | ||
15 | + */ | ||
16 | + public function Index_post() | ||
17 | + { | ||
18 | + // 对参数进行验证,包括验证是否为有效参数,多余参数应该剔除 | ||
19 | + $input = I('post.'); | ||
20 | + | ||
21 | + if (!$input) { | ||
22 | + E('_ERR_POST_EMPTY'); | ||
23 | + } | ||
24 | + | ||
25 | + $title = $input['title']; | ||
26 | + if (!$title) { | ||
27 | + E('_ERROR_TITLE_EMPTY'); | ||
28 | + } | ||
29 | + | ||
30 | + if (get_str_len($title) > 80) { | ||
31 | + E('_ERROR_MESSAGE_TITLE_LENGTH'); | ||
32 | + } | ||
33 | + | ||
34 | + $message = $input['message']; | ||
35 | + if (!$message) { | ||
36 | + E('_ERROR_MESSAGE_EMPTY'); | ||
37 | + } | ||
38 | + | ||
39 | + if (get_str_len($message) > 500) { | ||
40 | + E('_ERROR_MESSAGE_LENGTH'); | ||
41 | + } | ||
42 | + | ||
43 | + $input['ip'] = $_SERVER['REMOTE_ADDR']; | ||
44 | + | ||
45 | + | ||
46 | + $uid = $input['uid']; | ||
47 | + if (!$uid) { | ||
48 | + E('_ERROR_USER_ID_EMPTY'); | ||
49 | + } | ||
50 | + | ||
51 | + $m_attachment = new AttachmentModel(); | ||
52 | + $attach_id_str = $m_attachment->add(); | ||
53 | + | ||
54 | + if (false !== $attach_id_str) { | ||
55 | + $input['attachment'] = $attach_id_str; | ||
56 | + } | ||
57 | + | ||
58 | + // 素材id,多个使用逗号分隔 | ||
59 | + // $input['receiver_uid'] = ''; // 不能是自己 | ||
60 | + $input['domain'] = md5($_SERVER['HTTP_HOST']); | ||
61 | + | ||
62 | + | ||
63 | + $m_message = new MessageModel(); | ||
64 | + $result = $m_message->addOne($input); | ||
65 | + | ||
66 | + $this->_result = boolval($result); | ||
67 | + } | ||
68 | +} |