981 lines
38 KiB
PHP
981 lines
38 KiB
PHP
<?php
|
||
namespace app\admin\controller\cms;
|
||
use addons\cms\library\FulltextSearch;
|
||
use app\admin\model\cms\Channel;
|
||
use app\admin\model\cms\ChannelAdmin;
|
||
use app\admin\model\cms\Modelx;
|
||
use app\common\controller\Backend;
|
||
use app\common\model\User;
|
||
use app\admin\model\ClubMatchApply;
|
||
use app\admin\model\Club;
|
||
use fast\Tree;
|
||
use think\Db;
|
||
use think\db\Query;
|
||
use think\Hook;
|
||
use think\Request;
|
||
|
||
/**
|
||
* 内容表
|
||
*
|
||
* @icon fa fa-file-text-o
|
||
*/
|
||
class Archives extends Backend
|
||
{
|
||
/**
|
||
* Archives模型对象
|
||
*/
|
||
protected $model = null;
|
||
protected $noNeedRight = ['get_fields_html', 'check_element_available', 'suggestion', 'copy', 'special', 'tags', 'move', 'flag'];
|
||
protected $channelIds = [];
|
||
protected $isSuperAdmin = false;
|
||
protected $searchFields = 'id,title';
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->model = new \app\admin\model\cms\Archives;
|
||
$this->MatchContestantModel = model('MatchContestant');
|
||
$this->UserModel = model('User');
|
||
$config = get_addon_config('cms');
|
||
if ($config['archivesdatalimit'] != 'all') {
|
||
$this->dataLimit = $config['archivesdatalimit'];
|
||
}
|
||
|
||
//复制/加入专题/修改标签均检测编辑权限
|
||
if (in_array($this->request->action(), ['copy', 'special', 'tags', 'move', 'flag']) && !$this->auth->check('cms/archives/edit')) {
|
||
Hook::listen('admin_nopermission', $this);
|
||
$this->error(__('You have no permission'), '');
|
||
}
|
||
|
||
//是否超级管理员
|
||
$this->isSuperAdmin = $this->auth->isSuperAdmin();
|
||
$channelList = [];
|
||
$disabledIds = [];
|
||
$all = collection(Channel::order("weigh desc,id desc")->select())->toArray();
|
||
|
||
//允许的栏目
|
||
$this->channelIds = $this->isSuperAdmin || !$config['channelallocate'] ? Channel::column('id') : ChannelAdmin::getAdminChanneIds();
|
||
$parentChannelIds = Channel::where('id', 'in', $this->channelIds)->column('parent_id');
|
||
$parentChannelIds = array_unique($parentChannelIds);
|
||
$parentChannelList = \think\Db::name('cms_channel')->where('id', 'in', $parentChannelIds)->where('parent_id', '<>', 0)->field('id,parent_id,name')->select();
|
||
$tree = Tree::instance()->init($all, 'parent_id');
|
||
foreach ($parentChannelList as $index => $channel) {
|
||
$parentChannelIds = array_merge($parentChannelIds, $tree->getParentsIds($channel['parent_id'], true));
|
||
}
|
||
$this->channelIds = array_merge($parentChannelIds, $this->channelIds);
|
||
foreach ($all as $k => $v) {
|
||
$state = ['opened' => true];
|
||
if ($v['type'] == 'link') {
|
||
$disabledIds[] = $v['id'];
|
||
}
|
||
if ($v['type'] == 'link') {
|
||
$state['checkbox_disabled'] = true;
|
||
}
|
||
if (!$this->isSuperAdmin) {
|
||
if (!in_array($v['id'], $parentChannelIds) && !in_array($v['id'], $this->channelIds)) {
|
||
unset($all[$k]);
|
||
continue;
|
||
}
|
||
}
|
||
$channelList[] = [
|
||
'id' => $v['id'],
|
||
'parent' => $v['parent_id'] ? $v['parent_id'] : '#',
|
||
'text' => __($v['name']),
|
||
'type' => $v['type'],
|
||
'state' => $state
|
||
];
|
||
}
|
||
$tree = Tree::instance()->init($all, 'parent_id');
|
||
$channelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", '', $disabledIds);
|
||
$secondChannelOptions = $tree->getTree(0, "<option model='@model_id' value=@id disabled>@spacer@name</option>", '', $disabledIds);
|
||
$this->view->assign('channelOptions', $channelOptions);
|
||
$this->view->assign('secondChannelOptions', $secondChannelOptions);
|
||
$this->assignconfig('channelList', $channelList);
|
||
$this->assignconfig('spiderRecord', intval($config['spiderrecord'] ?? 0));
|
||
|
||
$this->assignconfig("flagList", $this->model->getFlagList());
|
||
$this->view->assign("flagList", $this->model->getFlagList());
|
||
$this->view->assign("statusList", $this->model->getStatusList());
|
||
|
||
$this->assignconfig('cms', ['archiveseditmode' => $config['archiveseditmode']]);
|
||
}
|
||
|
||
/**
|
||
* 查看
|
||
*/
|
||
public function index()
|
||
{
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags']);
|
||
if ($this->request->isAjax()) {
|
||
$this->relationSearch = true;
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
if (!$this->auth->isSuperAdmin()) {
|
||
$this->model->where('channel_id', 'in', $this->channelIds);
|
||
}
|
||
$total = $this->model
|
||
->with('Channel')
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->count();
|
||
if (!$this->auth->isSuperAdmin()) {
|
||
$this->model->where('channel_id', 'in', $this->channelIds);
|
||
}
|
||
$list = $this->model
|
||
->with(['Channel'])
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->limit($offset, $limit)
|
||
->select();
|
||
|
||
addtion($list, [
|
||
[
|
||
'field' => 'channel_ids',
|
||
'display' => 'channel_ids',
|
||
'model' => Channel::class,
|
||
],
|
||
]);
|
||
\app\admin\model\cms\SpiderLog::render($list, 'archives');
|
||
$result = array("total" => $total, "rows" => $list);
|
||
|
||
return json($result);
|
||
}
|
||
|
||
$modelList = \app\admin\model\cms\Modelx::all();
|
||
$specialList = \app\admin\model\cms\Special::where('status', 'normal')->select();
|
||
$this->view->assign('modelList', $modelList);
|
||
$this->view->assign('specialList', $specialList);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 副表内容
|
||
*/
|
||
public function content($model_id = null)
|
||
{
|
||
$model = \app\admin\model\cms\Modelx::get($model_id);
|
||
if (!$model) {
|
||
$this->error('未找到对应模型');
|
||
}
|
||
$fieldsList = \app\admin\model\cms\Fields::where('source', 'model')->where('source_id', $model['id'])->where('type', '<>', 'text')->select();
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if ($this->request->isAjax()) {
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
$fields = [];
|
||
foreach ($fieldsList as $index => $item) {
|
||
$fields[] = "addon." . $item['name'];
|
||
}
|
||
$filter = $this->request->request('filter');
|
||
$op = $this->request->request('op');
|
||
if ($filter && $op) {
|
||
$filterArr = json_decode($filter, true);
|
||
$opArr = json_decode($op, true);
|
||
foreach ($filterArr as $index => $item) {
|
||
if (in_array("addon." . $index, $fields)) {
|
||
$filterArr["addon." . $index] = $item;
|
||
$opArr["addon." . $index] = $opArr[$index];
|
||
unset($filterArr[$index], $opArr[$index]);
|
||
}
|
||
}
|
||
$this->request->get(['filter' => json_encode($filterArr), 'op' => json_encode($opArr)]);
|
||
}
|
||
|
||
$this->searchFields = "archives.id,archives.title";
|
||
$this->relationSearch = true;
|
||
$table = $this->model->getTable();
|
||
list($where, $sort, $order, $offset, $limit, $page, $alias) = $this->buildparams();
|
||
$sort = 'archives.id';
|
||
$isSuperAdmin = $this->isSuperAdmin;
|
||
$channelIds = $this->channelIds;
|
||
$customWhere = function ($query) use ($isSuperAdmin, $channelIds, $model_id) {
|
||
if (!$isSuperAdmin) {
|
||
$query->where('archives.channel_id', 'in', $channelIds);
|
||
}
|
||
if ($model_id) {
|
||
$query->where('archives.model_id', $model_id);
|
||
if ($model_id == 2){
|
||
$res = $query->where('archives.channel_id', 36);
|
||
// var_dump($res);exit;
|
||
}
|
||
// if ($model_id == 6){
|
||
|
||
// $res = $query->where('archives.channel_id', 73);
|
||
// // var_dump($res);exit;
|
||
// }
|
||
}
|
||
};
|
||
|
||
|
||
|
||
$list = $this->model
|
||
->alias($alias)
|
||
->alias('archives')
|
||
->join('cms_channel channel', 'channel.id=archives.channel_id', 'LEFT')
|
||
->join($model['table'] . ' addon', 'addon.id=archives.id', 'LEFT')
|
||
->field('archives.*,channel.name as channel_name,addon.id as aid' . ($fields ? ',' . implode(',', $fields) : ''))
|
||
->where($customWhere)
|
||
->whereNull('deletetime')
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->paginate($limit);
|
||
// var_dump($list);exit;
|
||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
|
||
return json($result);
|
||
}
|
||
$fields = [];
|
||
foreach ($fieldsList as $index => $item) {
|
||
$fields[] = ['field' => $item['name'], 'title' => $item['title'], 'type' => $item['type'], 'content' => $item['content_list']];
|
||
}
|
||
|
||
$this->assignconfig('fields', $fields);
|
||
$this->view->assign('fieldsList', $fieldsList);
|
||
$this->view->assign('model', $model);
|
||
$this->assignconfig('model_id', $model_id);
|
||
$modelList = \app\admin\model\cms\Modelx::all();
|
||
$this->view->assign('modelList', $modelList);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 编辑
|
||
*
|
||
* @param mixed $ids
|
||
* @return string
|
||
*/
|
||
public function edit($ids = null)
|
||
{
|
||
$row = $this->model->get($ids);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
||
$this->error(__('You have no permission'));
|
||
}
|
||
}
|
||
if (!$this->isSuperAdmin && !in_array($row['channel_id'], $this->channelIds)) {
|
||
$this->error(__('You have no permission'));
|
||
}
|
||
if ($this->request->isPost()) {
|
||
return parent::edit($ids);
|
||
}
|
||
$channel = Channel::get($row['channel_id']);
|
||
if (!$channel) {
|
||
$this->error(__('No specified channel found'));
|
||
}
|
||
$model = \app\admin\model\cms\Modelx::get($channel['model_id']);
|
||
if (!$model) {
|
||
$this->error(__('No specified model found'));
|
||
}
|
||
$addon = db($model['table'])->where('id', $row['id'])->find();
|
||
if ($addon) {
|
||
$row->setData($addon);
|
||
}
|
||
|
||
$disabledIds = [];
|
||
$all = collection(Channel::order("weigh desc,id desc")->select())->toArray();
|
||
foreach ($all as $k => $v) {
|
||
if ($v['type'] == 'link' || $v['model_id'] != $channel['model_id']) {
|
||
$disabledIds[] = $v['id'];
|
||
}
|
||
}
|
||
$disabledIds = array_diff($disabledIds, [$row['channel_id']]);
|
||
$tree = Tree::instance()->init($all, 'parent_id');
|
||
$channelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", $row['channel_id'], $disabledIds);
|
||
$secondChannelOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>", explode(',', $row['channel_ids']), $disabledIds);
|
||
$this->view->assign('channelOptions', $channelOptions);
|
||
$this->view->assign('secondChannelOptions', $secondChannelOptions);
|
||
$this->view->assign("row", $row);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
* @param mixed $ids
|
||
*/
|
||
public function del($ids = "")
|
||
{
|
||
parent::del($ids);
|
||
}
|
||
|
||
/**
|
||
* 销毁
|
||
* @param string $ids
|
||
*/
|
||
public function destroy($ids = "")
|
||
{
|
||
\app\admin\model\cms\Archives::event('after_delete', function ($row) {
|
||
//删除副表
|
||
$channel = Channel::get($row->channel_id);
|
||
if ($channel) {
|
||
$model = Modelx::get($channel['model_id']);
|
||
if ($model) {
|
||
db($model['table'])->where("id", $row['id'])->delete();
|
||
}
|
||
}
|
||
});
|
||
parent::destroy($ids);
|
||
}
|
||
|
||
/**
|
||
* 还原
|
||
* @param mixed $ids
|
||
*/
|
||
public function restore($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
if ($ids) {
|
||
$this->model->where($pk, 'in', $ids);
|
||
}
|
||
$config = get_addon_config('cms');
|
||
$list = $this->model->onlyTrashed()->select();
|
||
if ($list) {
|
||
$ids = [];
|
||
$refreshIds = [];
|
||
foreach ($list as $index => $item) {
|
||
if ($item['status'] == 'normal') {
|
||
User::score($config['score']['postarchives'], $item['user_id'], '发布文章');
|
||
}
|
||
$ids[] = $item['id'];
|
||
$refreshIds = array_merge([$item['channel_id']], explode(',', $item['channel_ids']));
|
||
$refreshIds = array_filter(array_unique($refreshIds));
|
||
}
|
||
$this->model->where('id', 'in', $ids);
|
||
$this->model->restore('1=1');
|
||
Channel::refreshItems($refreshIds);
|
||
$this->success();
|
||
}
|
||
$this->error(__('No rows were updated'));
|
||
}
|
||
|
||
/**
|
||
* 移动
|
||
* @param string $ids
|
||
*/
|
||
public function move($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
if ($ids) {
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
$channel_id = $this->request->post('channel_id');
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$this->model->where($pk, 'in', $ids);
|
||
$channel = Channel::get($channel_id);
|
||
if ($channel && $channel['type'] === 'list') {
|
||
$channelNums = \app\admin\model\cms\Archives::
|
||
with('channel')
|
||
->where('archives.' . $pk, 'in', $ids)
|
||
->where('channel_id', '<>', $channel['id'])
|
||
->field('channel_id,COUNT(*) AS nums')
|
||
->group('channel_id')
|
||
->select();
|
||
$result = $this->model
|
||
->where('model_id', '=', $channel['model_id'])
|
||
->where('channel_id', '<>', $channel['id'])
|
||
->update(['channel_id' => $channel_id]);
|
||
if ($result) {
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('No rows were updated'));
|
||
}
|
||
} else {
|
||
$this->error(__('No rows were updated'));
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 复制选择行
|
||
* @param string $ids
|
||
*/
|
||
public function copy($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
if ($ids) {
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$archivesList = $this->model->where('id', 'in', $ids)->select();
|
||
foreach ($archivesList as $index => $item) {
|
||
try {
|
||
$model = Modelx::get($item['model_id']);
|
||
$addon = \think\Db::name($model['table'])->find($item['id']);
|
||
$data = $item->toArray();
|
||
$data = array_merge($data, $addon ?? []);
|
||
$data['title'] = $data['title'] . "_copy";
|
||
$data['status'] = 'hidden';
|
||
unset($data['id']);
|
||
\app\admin\model\cms\Archives::create($data, true);
|
||
} catch (\Exception $e) {
|
||
//
|
||
}
|
||
}
|
||
$this->success();
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 加入专题
|
||
* @param string $ids
|
||
*/
|
||
public function special($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
if ($ids) {
|
||
$special_id = $this->request->post('special_id');
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$special = \app\admin\model\cms\Special::get($special_id);
|
||
if ($special) {
|
||
$archivesList = $this->model->where($pk, 'in', $ids)->select();
|
||
foreach ($archivesList as $index => $item) {
|
||
$special_ids = explode(',', $item['special_ids']);
|
||
if (!in_array($special['id'], $special_ids)) {
|
||
$special_ids[] = $special['id'];
|
||
$item->save(['special_ids' => implode(',', array_unique(array_filter($special_ids)))]);
|
||
}
|
||
}
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('No rows were updated'));
|
||
}
|
||
}
|
||
$this->error(__('Please select at least one row'));
|
||
}
|
||
|
||
/**
|
||
* 加入标签
|
||
* @param string $ids
|
||
*/
|
||
public function tags($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
if ($ids) {
|
||
$tags = $this->request->post('tags');
|
||
$newTagsArr = array_filter(explode(',', $tags));
|
||
if ($newTagsArr) {
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$archivesList = $this->model->where($pk, 'in', $ids)->select();
|
||
foreach ($archivesList as $index => $item) {
|
||
$tagsArr = explode(',', $item['tags']);
|
||
$tagsArr = array_merge($tagsArr, $newTagsArr);
|
||
$item->save(['tags' => implode(',', array_unique(array_filter($tagsArr)))]);
|
||
}
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('标签数据不能为空'));
|
||
}
|
||
}
|
||
$this->error(__('Please select at least one row'));
|
||
}
|
||
|
||
/**
|
||
* 修改标志
|
||
* @param string $ids
|
||
*/
|
||
public function flag($ids = "")
|
||
{
|
||
if (!$this->request->isPost()) {
|
||
$this->error(__("Invalid parameters"));
|
||
}
|
||
if ($ids) {
|
||
$type = $this->request->post('type');
|
||
$flag = $this->request->post('flag');
|
||
$changeFlagArr = array_filter(explode(',', $flag));
|
||
if ($changeFlagArr) {
|
||
$pk = $this->model->getPk();
|
||
$adminIds = $this->getDataLimitAdminIds();
|
||
if (is_array($adminIds)) {
|
||
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
||
}
|
||
$archivesList = $this->model->where($pk, 'in', $ids)->select();
|
||
foreach ($archivesList as $index => $item) {
|
||
$flagArr = explode(',', $item['flag']);
|
||
if ($type == 'add') {
|
||
$flagArr = array_merge($flagArr, $changeFlagArr);
|
||
} else {
|
||
$flagArr = array_diff($flagArr, $changeFlagArr);
|
||
}
|
||
$item->save(['flag' => implode(',', array_unique(array_filter($flagArr)))]);
|
||
}
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('标志数据不能为空'));
|
||
}
|
||
}
|
||
$this->error(__('Please select at least one row'));
|
||
}
|
||
|
||
/**
|
||
* 获取栏目列表
|
||
* @internal
|
||
*/
|
||
public function get_fields_html()
|
||
{
|
||
$this->view->engine->layout(false);
|
||
$channel_id = $this->request->post('channel_id');
|
||
$archives_id = $this->request->post('archives_id');
|
||
$channel = Channel::get($channel_id, 'model');
|
||
if ($channel) {
|
||
$model_id = $channel['model_id'];
|
||
$values = [];
|
||
if ($archives_id) {
|
||
$values = db($channel['model']['table'])->where('id', $archives_id)->find();
|
||
|
||
//优先从栏目获取模型ID,再从文档获取
|
||
$archives = \app\admin\model\cms\Archives::get($archives_id);
|
||
$model_id = $archives ? $archives['model_id'] : $model_id;
|
||
}
|
||
|
||
$fields = \addons\cms\library\Service::getCustomFields('model', $model_id, $values);
|
||
|
||
$model = Modelx::get($model_id);
|
||
|
||
$setting = $model['setting'];
|
||
$publishfields = isset($setting['publishfields']) ? $setting['publishfields'] : [];
|
||
$titlelist = isset($setting['titlelist']) ? $setting['titlelist'] : [];
|
||
|
||
$this->view->assign('channel', $channel);
|
||
$this->view->assign('fields', $fields);
|
||
$this->view->assign('values', $values);
|
||
$this->success('', null, ['html' => $this->view->fetch('cms/common/fields'), 'publishfields' => $publishfields, 'titlelist' => $titlelist]);
|
||
} else {
|
||
$this->error(__('Please select channel'));
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
|
||
/**
|
||
* 检测元素是否可用
|
||
* @internal
|
||
*/
|
||
public function check_element_available()
|
||
{
|
||
$id = $this->request->request('id');
|
||
$name = $this->request->request('name');
|
||
$value = $this->request->request('value');
|
||
$name = substr($name, 4, -1);
|
||
if (!$name) {
|
||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||
}
|
||
if ($id) {
|
||
$this->model->where('id', '<>', $id);
|
||
}
|
||
$exist = $this->model->where($name, $value)->find();
|
||
if ($exist) {
|
||
$this->error(__('The data already exist'));
|
||
} else {
|
||
$this->success();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 搜索建议
|
||
* @internal
|
||
*/
|
||
public function suggestion()
|
||
{
|
||
$config = get_addon_config('cms');
|
||
$q = trim($this->request->request("q"));
|
||
$id = trim($this->request->request("id/d"));
|
||
$list = [];
|
||
if ($config['searchtype'] == 'xunsearch') {
|
||
$result = FulltextSearch::search($q, 1, 10);
|
||
} else {
|
||
$result = $this->model->where("title|keywords|description", "like", "%{$q}%")->where('id', '<>', $id)->limit(10)->order("id", "desc")->select();
|
||
foreach ($result as $index => $item) {
|
||
$item['image'] = $item['image'] ? $item['image'] : '/assets/addons/cms/img/noimage.png';
|
||
$list[] = ['id' => $item['id'], 'url' => $item['fullurl'], 'image' => cdnurl($item['image']), 'title' => $item['title'], 'create_date' => datetime($item['createtime']), 'status' => $item['status'], 'status_text' => $item['status_text'], 'deletetime' => $item['deletetime']];
|
||
}
|
||
}
|
||
return json($list);
|
||
}
|
||
|
||
/**
|
||
* Created by PhpStorm.
|
||
* Author:Soar
|
||
* Time:2023/7/12 11:54
|
||
* @return string
|
||
* @throws \think\Exception
|
||
* @DESC 赛事页面飞手列表
|
||
*/
|
||
public function league_allplayer()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
public function league_wholeplayer()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
public function leaguecontestant()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
public function contestant()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function club_match_list()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function uploadfile()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function test()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function course()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function visualization()
|
||
{
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function league(){
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function league_course(){
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function getleagueList()
|
||
{
|
||
$ClubMatchApply = new ClubMatchApply();
|
||
$club = new Club();
|
||
// $this->relationSearch = true;
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if ($this->request->isAjax()) {
|
||
// 拦截部分信息修改
|
||
if (!empty($this->request->get("op", '', 'trim'))) {
|
||
$op = json_decode($this->request->get("op", '', 'trim'), true);
|
||
$filter = json_decode($this->request->get("filter", '', 'trim'), true);
|
||
// var_dump($filter);exit;
|
||
if (!empty($filter['user.member_number'])) {
|
||
// 获取用户信息
|
||
$players = $this->UserModel->where('member_number', $filter['user.member_number'])->find();
|
||
// var_dump($players);exit;
|
||
if (!empty($players)) {
|
||
unset($op['user.member_number']);
|
||
unset($filter['user.member_number']);
|
||
$filter['players.member_id'] = $players->id;
|
||
$op['players.member_id'] = "LIKE";
|
||
$this->request->get(["op" => json_encode($op)])["op"] = json_encode($op);
|
||
$this->request->get(["filter" => json_encode($filter)]);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
// $res = $this->buildparams();
|
||
// var_dump($res);exit;
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
$matchId = trim($this->request->request("ids/d"));
|
||
|
||
// $list = $ClubMatchApply->where($where)
|
||
// ->where('match_id', 'eq', $matchId)
|
||
// ->order($sort, $order)
|
||
// ->paginate($limit);
|
||
// var_dump($order);exit;
|
||
$club_list = $this->MatchContestantModel
|
||
// ->with('clubs')
|
||
->alias('a')
|
||
// ->join('club club','a.club_id = club.id')
|
||
->where($where)
|
||
->where('match_id', 'eq', $matchId)
|
||
->order($sort, $order)
|
||
->group('a.club_id')
|
||
// ->fetchSql(true)
|
||
->paginate($limit);
|
||
// var_dump($club_list);exit;
|
||
// var_dump($list->toArray()['data']);exit;
|
||
// $lists = $list->toArray()['data'];
|
||
foreach ($club_list as &$val){
|
||
|
||
|
||
$val->club = $club->where('id',$val['club_id'])->find();
|
||
// if(!empty($res)) $res = $res->toArray();
|
||
// $val['clubs'] = $res;
|
||
}
|
||
// $a = $club_list->items();
|
||
// foreach ($a as &$val){
|
||
// $val = $val->toArray();
|
||
// }
|
||
// var_dump($a);exit;
|
||
$result = array("total" => $club_list->total(), "rows" => $club_list->items());
|
||
|
||
return json($result);
|
||
}
|
||
|
||
}
|
||
|
||
public function getmatch_wholeList()
|
||
{
|
||
$ClubMatchApply = new ClubMatchApply();
|
||
$club = new Club();
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if ($this->request->isAjax()) {
|
||
// 拦截部分信息修改
|
||
if (!empty($this->request->get("op", '', 'trim'))) {
|
||
$op = json_decode($this->request->get("op", '', 'trim'), true);
|
||
$filter = json_decode($this->request->get("filter", '', 'trim'), true);
|
||
// var_dump($filter);exit;
|
||
if (!empty($filter['user.member_number'])) {
|
||
// 获取用户信息
|
||
$players = $this->UserModel->where('member_number', $filter['user.member_number'])->find();
|
||
// var_dump($players);exit;
|
||
if (!empty($players)) {
|
||
unset($op['user.member_number']);
|
||
unset($filter['user.member_number']);
|
||
$filter['players.member_id'] = $players->id;
|
||
$op['players.member_id'] = "LIKE";
|
||
$this->request->get(["op" => json_encode($op)])["op"] = json_encode($op);
|
||
$this->request->get(["filter" => json_encode($filter)]);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
$ids = trim($this->request->request("ids/d"));
|
||
// var_dump($ids);exit;
|
||
$matchId = $this->MatchContestantModel
|
||
->field('match_id')->where('match_id', 'eq', $ids)->where('club_status',null)->find();
|
||
// var_dump($matchId);exit;
|
||
// $list = $ClubMatchApply->where($where)
|
||
// ->where('match_id', 'eq', $matchId)
|
||
// ->order($sort, $order)
|
||
// ->paginate($limit);
|
||
$list = $this->MatchContestantModel
|
||
->with('players')
|
||
->where($where)
|
||
->where('match_id', 'eq', $matchId['match_id'])
|
||
->where('club_status',null)
|
||
->order($sort, $order)
|
||
// ->distinct(true)
|
||
->paginate($limit);
|
||
// var_dump($list->toArray()['data']);exit;
|
||
// $lists = $list->toArray()['data'];
|
||
foreach ($list as &$val){
|
||
|
||
if(empty($val->players->member_id)){
|
||
|
||
continue;
|
||
}
|
||
if(strpos($val->players->player_pic, 'aliyuncs') === false){
|
||
// $val->players->player_pic = 'https://www.fpvone.cn'.$val->players->player_pic;
|
||
}
|
||
$val->user = $this->UserModel->find($val->players->member_id);
|
||
$val->club = $club->where('id',$val['club_id'])->find();
|
||
}
|
||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
// var_dump($result);exit;
|
||
return json($result);
|
||
}
|
||
|
||
}
|
||
|
||
public function getmatch_idsList()
|
||
{
|
||
$ClubMatchApply = new ClubMatchApply();
|
||
$club = new Club();
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if ($this->request->isAjax()) {
|
||
// 拦截部分信息修改
|
||
if (!empty($this->request->get("op", '', 'trim'))) {
|
||
$op = json_decode($this->request->get("op", '', 'trim'), true);
|
||
$filter = json_decode($this->request->get("filter", '', 'trim'), true);
|
||
// var_dump($filter);exit;
|
||
if (!empty($filter['user.member_number'])) {
|
||
// 获取用户信息
|
||
$players = $this->UserModel->where('member_number', $filter['user.member_number'])->find();
|
||
// var_dump($players);exit;
|
||
if (!empty($players)) {
|
||
unset($op['user.member_number']);
|
||
unset($filter['user.member_number']);
|
||
$filter['players.member_id'] = $players->id;
|
||
$op['players.member_id'] = "LIKE";
|
||
$this->request->get(["op" => json_encode($op)])["op"] = json_encode($op);
|
||
$this->request->get(["filter" => json_encode($filter)]);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
$ids = trim($this->request->request("ids/d"));
|
||
// var_dump($ids);exit;
|
||
$matchId = $this->MatchContestantModel
|
||
->field('match_id,club_id')->where('id', 'eq', $ids)->find();
|
||
// var_dump($matchId['club_id']);exit;
|
||
// $list = $ClubMatchApply->where($where)
|
||
// ->where('match_id', 'eq', $matchId)
|
||
// ->order($sort, $order)
|
||
// ->paginate($limit);
|
||
// var_dump($where);exit;
|
||
$list = $this->MatchContestantModel
|
||
->with('player')
|
||
->where($where)
|
||
->where('match_id', 'eq', $matchId['match_id'])
|
||
->where('club_id','eq',$matchId['club_id'])
|
||
->where('club_status',null)
|
||
->order($sort, $order)
|
||
// ->distinct(true)
|
||
->paginate($limit);
|
||
// var_dump($list->toArray()['data']);exit;
|
||
// $lists = $list->toArray()['data'];
|
||
foreach ($list as &$val){
|
||
|
||
if(empty($val->players->member_id)){
|
||
|
||
continue;
|
||
}
|
||
$val->user = $this->UserModel->find($val->players->member_id);
|
||
$val->club = $club->where('id',$val['club_id'])->find();
|
||
}
|
||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
// var_dump($result);exit;
|
||
return json($result);
|
||
}
|
||
|
||
}
|
||
|
||
public function getplayersList()
|
||
{
|
||
$ClubMatchApply = new ClubMatchApply();
|
||
$club = new Club();
|
||
//设置过滤方法
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if ($this->request->isAjax()) {
|
||
// 拦截部分信息修改
|
||
if (!empty($this->request->get("op", '', 'trim'))) {
|
||
$op = json_decode($this->request->get("op", '', 'trim'), true);
|
||
$filter = json_decode($this->request->get("filter", '', 'trim'), true);
|
||
// var_dump($filter);exit;
|
||
if (!empty($filter['user.member_number'])) {
|
||
// 获取用户信息
|
||
$players = $this->UserModel->where('member_number', $filter['user.member_number'])->find();
|
||
// var_dump($players);exit;
|
||
if (!empty($players)) {
|
||
unset($op['user.member_number']);
|
||
unset($filter['user.member_number']);
|
||
$filter['players.member_id'] = $players->id;
|
||
$op['players.member_id'] = "LIKE";
|
||
$this->request->get(["op" => json_encode($op)])["op"] = json_encode($op);
|
||
$this->request->get(["filter" => json_encode($filter)]);
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
// var_dump($where);exit;
|
||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||
$matchId = trim($this->request->request("ids/d"));
|
||
// var_dump($where);exit;
|
||
// $list = $ClubMatchApply->where($where)
|
||
// ->where('match_id', 'eq', $matchId)
|
||
// ->order($sort, $order)
|
||
// ->paginate($limit);
|
||
$list = $this->MatchContestantModel
|
||
->with('players')
|
||
->where($where)
|
||
->where('match_id', 'eq', $matchId)
|
||
->order($sort, $order)
|
||
// ->distinct(true)
|
||
->paginate($limit);
|
||
// var_dump($list->toArray()['data']);exit;
|
||
// $lists = $list->toArray()['data'];
|
||
foreach ($list as &$val){
|
||
|
||
if(empty($val->players->member_id)){
|
||
|
||
continue;
|
||
}
|
||
// var_dump($val['club_id']);exit;
|
||
// $club->where('id',$val->club_id);
|
||
$val->user = $this->UserModel->find($val->players->member_id);
|
||
|
||
$val->club = $club->where('id',$val['club_id'])->find();
|
||
// if(!empty($res)) $res = $res->toArray();
|
||
// $val['clubs'] = $res;
|
||
}
|
||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
// var_dump($result);exit;
|
||
return json($result);
|
||
}
|
||
|
||
}
|
||
|
||
}
|