IndexController.php
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// +----------------------------------------------------------------------
// | TcComment [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 Tangchao All rights reserved.
// +----------------------------------------------------------------------
// | Author: Tangchao <79300975@qq.com>
// +----------------------------------------------------------------------
namespace plugins\tc_comment\controller;
use cmf\controller\PluginBaseController;
use think\Db;
use app\user\model\UserModel;
class IndexController extends PluginBaseController
{
function index()
{
if ($this->request->isPost()) {
$data = $this->request->param();
$post = $data['post'];
if(empty($post['content'])) $this->error('评论不能为空!');
$user_id = cmf_get_current_user_id();
dump($user_id);
$User=new UserModel();
$user=$User->getUserInfo($user_id);
if(empty($user)) $this->error('未登录!');
$admin = Db::name("comment")->where('user_id', $user['id'])->field("create_time")->order(["create_time" => "DESC"])->find();
if(time()-$admin['create_time']<60) $this->error('1分钟内只能留言一次!');
dump($user);
exit();
$post ['user_id']=$user['id'];
$post ['full_name']= $user['user_nickname']?$user['user_nickname']:($user['user_login']?$user['user_login']:$user['mobile']);
if($post ['full_name'] == $user['mobile']) $post ['full_name']=substr_replace($post ['full_name'], '****', 3, 4);
$post ['email']=$user['user_email'];
$post ['create_time']=time();
$post ['url']=$_SERVER['HTTP_REFERER'];
$result = Db::name('comment')->insertGetId($post);
if ($result) {
Db::name('portal_post')->where('id', $post['object_id'])->setInc('comment_count');
addScore($user_id,20,'评论文章');
$this->success('留言成功! 获得20积分!', url('portal/Article/index', ['id' => $post['object_id']]));
}else{
$this->error('数据传入失败!');
}
}
}
}