91 lines
3.1 KiB
PHP
Executable File
91 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\mobile\controller;
|
|
|
|
use think\Loader;
|
|
use think\Cookie;
|
|
use think\Config;
|
|
use think\validate;
|
|
|
|
class Pinglun extends BaseController {
|
|
|
|
public function lists($type = '', $cid = 0) {
|
|
$arg_where = ['stat' => 0, 'display' => 1];
|
|
if ($type) {
|
|
$arg_where['typeid'] = $type;
|
|
}
|
|
if ($cid) {
|
|
$arg_where['content_id'] = $cid;
|
|
}
|
|
$arg_order = ['id' => 'desc'];
|
|
$arg_field = ['*'];
|
|
$dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
|
|
//header('content-type:text/html;charset=utf-8;');
|
|
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
|
|
$value['page'] = $dataObject->render();
|
|
$value['total'] = $dataObject->total();
|
|
if ($this->request->isAjax()) {
|
|
return $this->result($value, 'pinglun', true);
|
|
}
|
|
$value['cid'] = $cid;
|
|
$value['type'] = ucfirst($type);
|
|
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title');
|
|
$value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword');
|
|
$value['seo_description'] = config('article_seo_description')? : config('website_seo_description');
|
|
$this->assign($value);
|
|
return $this->fetch('pinglun');
|
|
}
|
|
|
|
public function add() {
|
|
$data = $this->request->post();
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
return $this->json(-3, '未知错误');
|
|
}
|
|
|
|
if (!$this->check_token($data['id'], $data['time'], $data['token'])) {
|
|
return $this->json(-101, 'token过期');
|
|
}
|
|
|
|
// $row = Loader::model('Pinglun')->getRow(['customer_id' => $data['id']], null, ['id' => 'desc']);
|
|
// if ($row && $row['id']) {
|
|
// $createtime = strtotime($row['createtime']);
|
|
// if (time() - $createtime < 60) {
|
|
// return $this->json(-2,'您已评论过了请不要重复评论');
|
|
// }
|
|
// }
|
|
|
|
// 验证....
|
|
$validate = Loader::validate('pinglun');
|
|
if (!$validate->scene('add')->check($data)) {
|
|
return $this->json(-1, $validate->getError());
|
|
}
|
|
|
|
$addtime = date('Y-m-d H:i:s');
|
|
$txarr = [1, 2, 3, 4, 5];
|
|
shuffle($txarr);
|
|
$set = [
|
|
'customer_id' => $data['id'],
|
|
'cname' => $data['firstname'],
|
|
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
|
|
'pid' => isset($data['pid']) ? $data['pid'] : 0,
|
|
'content_id' => isset($data['cid']) ? $data['cid'] : 0,
|
|
'content' => $data['content'],
|
|
'tx' => $txarr[0],
|
|
'stat' => 0,
|
|
'createtime' => $addtime,
|
|
'lasttime' => $addtime,
|
|
];
|
|
$model = Loader::model('Pinglun')->insert($set);
|
|
if ($model) {
|
|
isset($data['cid']) ? Loader::model('Article')->where(['id' => $data['cid']])->setInc('commentcount') : '';
|
|
return $this->json(1, '评论成功!');
|
|
} else {
|
|
return $this->json(-5, '操作失败');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|