mirror of https://gitee.com/karson/fastadmin.git
111 lines
3.5 KiB
PHP
111 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace addons\cms\controller\wxapp;
|
|
|
|
use addons\cms\model\Archives as ArchivesModel;
|
|
use addons\cms\model\Channel;
|
|
use addons\cms\model\Comment;
|
|
use addons\cms\model\Modelx;
|
|
|
|
/**
|
|
* 文档
|
|
*/
|
|
class Archives extends Base
|
|
{
|
|
|
|
protected $noNeedLogin = ['*'];
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
}
|
|
|
|
/**
|
|
* 读取文档列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$params = [];
|
|
$model = (int)$this->request->request('model');
|
|
$channel = (int)$this->request->request('channel');
|
|
$page = (int)$this->request->request('page');
|
|
|
|
if ($model) {
|
|
$params['model'] = $model;
|
|
}
|
|
if ($channel) {
|
|
$params['channel'] = $channel;
|
|
}
|
|
$page = max(1, $page);
|
|
$params['limit'] = ($page - 1) * 10 . ',10';
|
|
|
|
$list = ArchivesModel::getArchivesList($params);
|
|
$this->success('', ['archivesList' => $list]);
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
$action = $this->request->post("action");
|
|
if ($action && $this->request->isPost()) {
|
|
return $this->$action();
|
|
}
|
|
$diyname = $this->request->param('diyname');
|
|
if ($diyname && !is_numeric($diyname)) {
|
|
$archives = ArchivesModel::getByDiyname($diyname);
|
|
} else {
|
|
$id = $diyname ? $diyname : $this->request->request('id', '');
|
|
$archives = ArchivesModel::get($id);
|
|
}
|
|
if (!$archives || $archives['status'] == 'hidden' || $archives['deletetime']) {
|
|
$this->error(__('No specified article found'));
|
|
}
|
|
$channel = Channel::get($archives['channel_id']);
|
|
if (!$channel) {
|
|
$this->error(__('No specified channel found'));
|
|
}
|
|
$model = Modelx::get($channel['model_id']);
|
|
if (!$model) {
|
|
$this->error(__('No specified model found'));
|
|
}
|
|
$archives->setInc("views", 1);
|
|
$addon = db($model['table'])->where('id', $archives['id'])->find();
|
|
if ($addon) {
|
|
if ($model->fields) {
|
|
$fieldsContentList = $model->getFieldsContentList($model->id);
|
|
//附加列表字段
|
|
array_walk($fieldsContentList, function ($content, $field) use (&$addon) {
|
|
$addon[$field . '_text'] = isset($content[$addon[$field]]) ? $content[$addon[$field]] : $addon[$field];
|
|
});
|
|
}
|
|
$archives->setData($addon);
|
|
} else {
|
|
$this->error(__('No specified article addon found'));
|
|
}
|
|
$archives = array_merge($archives->toArray(), $addon);
|
|
|
|
$commentList = Comment::getCommentList(['aid' => $archives['id']]);
|
|
|
|
$this->success('', ['archivesInfo' => $archives, 'channelInfo' => $channel, 'commentList' => $commentList->getCollection()]);
|
|
}
|
|
|
|
/**
|
|
* 赞与踩
|
|
*/
|
|
public function vote()
|
|
{
|
|
$id = (int)$this->request->post("id");
|
|
$type = trim($this->request->post("type", ""));
|
|
if (!$id || !$type) {
|
|
$this->error(__('Operation failed'));
|
|
}
|
|
$archives = ArchivesModel::get($id);
|
|
if (!$archives || $archives['status'] == 'hidden') {
|
|
$this->error(__('No specified article found'));
|
|
}
|
|
$archives->where('id', $id)->setInc($type === 'like' ? 'likes' : 'dislikes', 1);
|
|
$archives = ArchivesModel::get($id);
|
|
$this->success(__('Operation completed'), ['likes' => $archives->likes, 'dislikes' => $archives->dislikes, 'likeratio' => $archives->likeratio]);
|
|
}
|
|
|
|
}
|