初始化提交

This commit is contained in:
shenquanyi
2024-05-28 11:01:13 +08:00
commit 5d96ff2eed
1393 changed files with 325846 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年11月29日
* 接口模块配置文件
*/
return array(
// 控制器返回数据输出方式
'return_data_type' => 'json'
);

View File

@@ -0,0 +1,55 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年11月11日
* 单页内容通过分类编码调用接口控制器
*/
namespace app\api\controller;
use core\basic\Controller;
use app\api\model\CmsModel;
use core\basic\Url;
use app\home\controller\ParserController;
class AboutController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new CmsModel();
}
public function index()
{
if (! ! $scode = request('scode', 'var')) {
// 区域获取
$acode = request('acode', 'var') ?: get_default_lg();
// 读取数据
if (! ! $data = $this->model->getAbout($acode, $scode)) {
if ($data->outlink) {
$data->apilink = $data->outlink;
} else {
$data->apilink = url('/api/content/index/id/' . $data->id, false);
}
$data->likeslink = url('/home/Do/likes/id/' . $data->id, false);
$data->opposelink = url('/home/Do/oppose/id/' . $data->id, false);
$Parser = new ParserController();
$data->contentlink = $Parser->parserLink(1, $data->urlname, 'about', $data->scode, $data->sortfilename);
$data->content = str_replace(STATIC_DIR . '/upload/', get_http_url() . STATIC_DIR . '/upload/', $data->content);
json(1, $data);
} else {
json(0, '分类编码为' . $scode . '的内容已经不存在了!');
}
} else {
json(1, '请求错误传递的内容scode有误');
}
}
}

View File

@@ -0,0 +1,523 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年4月20日
* CMS通用接口控制器
*/
namespace app\api\controller;
use core\basic\Controller;
use app\api\model\CmsModel;
use core\basic\Url;
use app\home\controller\ParserController;
class CmsController extends Controller
{
protected $model;
protected $lg;
public function __construct()
{
$this->model = new CmsModel();
$this->lg = get_default_lg();
}
// 站点基础信息
public function site()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
// 读取数据
if (! $name = request('name', 'var')) {
$data = $this->model->getSiteAll($acode);
} else {
$data = $this->model->getSite($acode, $name);
}
// 输出数据
json(1, $data);
}
// 公司信息
public function company()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
// 读取数据
if (! $name = request('name', 'var')) {
$data = $this->model->getCompanyAll($acode);
} else {
$data = $this->model->getCompany($acode, $name);
}
// 输出数据
json(1, $data);
}
// 自定义标签信息
public function label()
{
// 获取全部或指定自定义标签
if (! $name = request('name', 'var')) {
$data = $this->model->getLabelAll();
} else {
$data = $this->model->getLabel($name);
}
// 输出数据
json(1, $data);
}
// 获取菜单栏目树
public function nav()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
// 获取栏目树
if (! $scode = request('scode', 'var')) {
$data = $this->model->getSorts($acode);
} else { // 获取子类
$data = $this->model->getSortsSon($acode, $scode);
}
// 输出数据
json(1, $data);
}
// 当前栏目位置
public function position()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
if (! ! $scode = request('scode', 'var')) {
$data = $this->model->getPosition($acode, $scode);
json(1, $data);
} else {
json(0, '必须传递当前分类scode参数');
}
}
// 分类信息
public function sort()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
if (! ! $scode = request('scode', 'var')) {
$data = $this->model->getSort($acode, $scode);
json(1, $data);
} else {
json(0, '必须传递分类scode参数');
}
}
// 内容多图
public function pics()
{
if (! ! $id = request('id', 'int')) {
$acode = request('acode', 'var') ?: $this->lg;
if (! ! $pics = $this->model->getContentPics($acode, $id)) {
$pics = explode(',', $pics);
} else {
$pics = array();
}
json(1, $pics);
} else {
json(0, '必须传递内容id参数');
}
}
// 幻灯片
public function slide()
{
if (! ! $gid = request('gid', 'var')) {
$acode = request('acode', 'var') ?: $this->lg;
$num = request('num', 'int') ?: 10;
$data = $this->model->getSlides($acode, $gid, $num);
json(1, $data);
} else {
json(0, '必须传递幻灯片分组gid参数');
}
}
// 友情链接
public function link()
{
if (! ! $gid = request('gid', 'var')) {
$acode = request('acode', 'var') ?: $this->lg;
$num = request('num', 'int') ?: 20;
$data = $this->model->getLinks($acode, $gid, $num);
json(1, $data);
} else {
json(0, '必须传递友情链接分组gid参数');
}
}
// 搜索
public function search()
{
if (! $_POST) {
json(0, '请使用POST提交');
}
$acode = request('acode', 'var') ?: $this->lg;
// 获取主要参数
$field = request('field');
if (! preg_match('/^[\w\|]+$/', $field)) {
$field = '';
}
$keyword = request('keyword', 'vars');
$scode = request('scode'); // 支持多个分类逗号隔开
if (! preg_match('/^[\w,\s]+$/', $scode)) {
$scode = '';
}
if ($scode == '*') { // 星号意味任意栏目
$scode = '';
}
$num = request('num', 'int') ?: $this->config('pagesize');
$rorder = request('order');
$tags = request('tags', 'vars');
$fuzzy = request('fuzzy', 'int') ?: true;
if (! preg_match('/^[\w\-,\s]+$/', $rorder)) {
$order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
} else {
switch ($rorder) {
case 'id':
$order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
break;
case 'date':
$order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
break;
case 'sorting':
$order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
break;
case 'istop':
$order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'isrecommend':
$order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'isheadline':
$order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'visits':
case 'likes':
case 'oppose':
$order = $rorder . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'random': // 随机取数
$db_type = get_db_type();
if ($db_type == 'mysql') {
$order = "RAND()";
} elseif ($db_type == 'sqlite') {
$order = "RANDOM()";
}
break;
default:
if ($rorder) {
$orders = explode(',', $rorder);
foreach ($orders as $k => $v) {
if (strpos($v, 'ext_') === 0) {
$orders[$k] = 'e.' . $v;
} else {
$orders[$k] = 'a.' . $v;
}
}
$order = implode(',', $orders);
$order .= ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
}
}
}
$where1 = array();
// tags数据筛选
$where2 = array();
if ($tags) {
$tags_arr = explode(',', $tags);
foreach ($tags_arr as $value) {
if ($value) {
if ($fuzzy) {
$where2[] = "a.tags like '%" . escape_string($value) . "%'";
} else {
$where2[] = "a.tags='" . escape_string($value) . "'";
}
}
}
}
// 存储搜索条件,条件为“并列”关系,由于为模糊匹配,条件为空时意味着“任意”
$where3 = array();
// 采取keyword方式
if ($keyword) {
if (strpos($field, '|')) { // 匹配多字段的关键字搜索
$field = explode('|', $field);
foreach ($field as $value) {
if ($value == 'title') {
$value = 'a.title';
}
if ($fuzzy) {
$like = " like '%" . $keyword . "%'"; // 前面已经转义过
} else {
$like = " like '" . $keyword . "'"; // 前面已经转义过
}
if (isset($where3[0])) {
$where3[0] .= ' OR ' . $value . $like;
} else {
$where3[0] = $value . $like;
}
}
if (count($field) > 1) {
$where3[0] = '(' . $where3[0] . ')';
}
} else { // 匹配单一字段的关键字搜索
if ($field) {
if ($field == 'title') {
$field = 'a.title';
}
$where3[$field] = $keyword;
} else {
$where3['a.title'] = $keyword;
}
}
}
// 数据接收
if ($_POST) {
$receive = $_POST;
} else {
$receive = $_GET;
}
foreach ($receive as $key => $value) {
if (! ! $value = request($key, 'vars')) {
if ($key == 'title') {
$key = 'a.title';
}
if (preg_match('/^[\w\-\.]+$/', $key)) { // 带有违规字符时不带入查询
$where3[$key] = $value;
}
}
}
// 去除特殊键值
unset($where3['appid']);
unset($where3['timestamp']);
unset($where3['signature']);
unset($where3['keyword']);
unset($where3['field']);
unset($where3['scode']);
unset($where3['page']);
unset($where3['from']);
unset($where3['isappinstalled']);
unset($where3['tdsourcetag']);
unset($where3['x']);
unset($where3['y']);
unset($where3['searchtpl']);
unset($where3['p']);
unset($where3['s']);
// 读取数据
$data = $this->model->getLists($acode, $scode, $num, $order, $where1, $where2, $where3, $fuzzy);
$Parser = new ParserController();
foreach ($data as $key => $value) {
if ($value->outlink) {
$data[$key]->apilink = $value->outlink;
} else {
$data[$key]->apilink = url('/api/content/index/scode/' . $value->id, false);
}
$data[$key]->likeslink = url('/home/Do/likes/id/' . $value->id, false);
$data[$key]->opposelink = url('/home/Do/oppose/id/' . $value->id, false);
$data[$key]->content = str_replace(STATIC_DIR . '/upload/', get_http_url() . STATIC_DIR . '/upload/', $value->content);
// 返回网页链接地址便于AJAX调用内容
$data[$key]->contentlink = $Parser->parserLink(2, $value->urlname, 'content', $value->scode, $value->sortfilename, $value->id, $value->filename);
}
// 输出数据
if (request('page') <= PAGECOUNT) {
json(1, $data);
} else {
return json(0, '已经到底了!');
}
}
// 读取留言记录
public function msg()
{
// 获取参数
$acode = request('acode', 'var') ?: $this->lg;
$num = request('num', 'int') ?: $this->config('pagesize');
// 获取栏目数
$data = $this->model->getMessage($acode, $num);
if (request('page') <= PAGECOUNT) {
json(1, $data);
} else {
return json(0, '已经到底了!');
}
}
// 新增留言
public function addmsg()
{
if ($_POST) {
if ($this->config('message_status') === '0') {
json(0, '系统已经关闭留言功能,请到后台开启再试!');
}
// 读取字段
if (! $form = $this->model->getFormField(1)) {
json(0, '接收表单不存在任何字段,请核对后重试!');
}
// 接收数据
$mail_body = '';
foreach ($form as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = str_replace('pboot:if', '', $field_data);
if ($value->required && ! $field_data) {
json(0, $value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
$mail_body .= $value->description . '' . $field_data . '<br>';
}
}
$status = $this->config('message_verify') == '0' ? 1 : 0;
// 设置其他字段
if ($data) {
$data['acode'] = request('acode', 'var') ?: $this->lg;
$data['user_ip'] = ip2long(get_user_ip());
$data['user_os'] = get_user_os();
$data['user_bs'] = get_user_bs();
$data['recontent'] = '';
$data['status'] = $status;
$data['create_user'] = 'api';
$data['update_user'] = 'api';
}
// 写入数据
if ($this->model->addMessage($value->table_name, $data)) {
$this->log('API提交留言数据成功');
if ($this->config('message_send_mail') && $this->config('message_send_to')) {
$mail_subject = "" . CMSNAME . "】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站' . get_http_url() . '' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}
json(1, '留言提交成功!');
} else {
$this->log('API提交留言数据失败');
json(0, '留言提交失败!');
}
} else {
json(0, '留言提交失败请使用POST方式提交');
}
}
// 表单记录
public function form()
{
// 获取参数
$num = request('num', 'int') ?: $this->config('pagesize');
// 获取表单编码
if (! $fcode = request('fcode', 'var'))
json(0, '必须传递表单编码fcode');
// 获取表名称
if (! $table = $this->model->getFormTable($fcode)) {
json(0, '传递的fcode有误');
}
// 获取表数据
$data = $this->model->getForm($table, $num);
if (request('page') <= PAGECOUNT) {
json(1, $data);
} else {
return json(0, '已经到底了!');
}
}
// 表单提交
public function addform()
{
if ($_POST) {
if (! $fcode = request('fcode', 'var')) {
json(0, '传递的表单编码fcode有误');
}
if ($this->config('form_status') === '0') {
json(0, '系统已经关闭表单功能,请到后台开启再试!');
}
// 读取字段
if (! $form = $this->model->getFormField($fcode)) {
json(0, '接收表单不存在任何字段,请核对后重试!');
}
// 接收数据
$mail_body = '';
foreach ($form as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = str_replace('pboot:if', '', $field_data);
if ($value->required && ! $field_data) {
json(0, $value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
$mail_body .= $value->description . '' . $field_data . '<br>';
}
}
// 设置创建时间
if ($data) {
$data['create_time'] = get_datetime();
}
// 写入数据
if ($this->model->addForm($value->table_name, $data)) {
$this->log('API提交表单数据成功');
if ($this->config('form_send_mail') && $this->config('message_send_to')) {
$mail_subject = "" . CMSNAME . "】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站' . get_http_url() . '' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}
json(1, '表单提交成功!');
} else {
$this->log('API提交表单数据失败');
json(0, '表单提交失败!');
}
} else {
json(0, '表单提交失败请使用POST方式提交');
}
}
// 空拦截
public function _empty()
{
json(0, '您调用的接口不存在,请核对后重试!');
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年4月20日
* 内容接口控制器
*/
namespace app\api\controller;
use core\basic\Controller;
use app\api\model\CmsModel;
use core\basic\Url;
use app\home\controller\ParserController;
class ContentController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new CmsModel();
}
public function index()
{
if (! ! $id = request('id', 'int')) {
// 区域获取
$acode = request('acode', 'var') ?: get_default_lg();
// 读取数据
if (! ! $data = $this->model->getContent($acode, $id)) {
if ($data->outlink) {
$data->link = $data->outlink;
} else {
$data->apilink = url('/api/content/index/id/' . $data->id, false);
}
$data->likeslink = url('/home/Do/likes/id/' . $data->id, false);
$data->opposelink = url('/home/Do/oppose/id/' . $data->id, false);
// 返回网页链接地址
$Parser = new ParserController();
$data->contentlink = $Parser->parserLink(2, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename);
$data->content = str_replace(STATIC_DIR . '/upload/', get_http_url() . STATIC_DIR . '/upload/', $data->content);
json(1, $data);
} else {
json(0, 'id为' . $id . '的内容已经不存在了!');
}
} else {
json(1, '请求错误传递的内容id有误');
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年3月8日
*
*/
namespace app\api\controller;
use core\basic\Controller;
use app\api\model\DoModel;
class DoController extends Controller
{
private $model;
public function __construct()
{
$this->model = new DoModel();
}
// 点赞
public function likes()
{
if (! ! $id = request('id', 'int')) {
$this->model->addLikes($id);
json(1, '点赞成功');
} else {
json(0, '点赞失败');
}
}
// 反对
public function oppose()
{
if (! ! $id = request('id', 'int')) {
$this->model->addOppose($id);
json(1, '反对成功');
} else {
json(0, '反对失败');
}
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年4月20日
* 内容列表接口控制器
*/
namespace app\api\controller;
use core\basic\Controller;
use app\api\model\CmsModel;
use core\basic\Url;
use app\home\controller\ParserController;
class ListController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new CmsModel();
}
public function index()
{
// 获取参数
$acode = request('acode', 'var') ?: get_default_lg();
$scode = request('scode', 'var') ?: '';
$num = request('num', 'int') ?: $this->config('pagesize');
$rorder = request('order');
if (! preg_match('/^[\w\-,\s]+$/', $rorder)) {
$order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
} else {
switch ($rorder) {
case 'id':
$order = 'a.id DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC';
break;
case 'date':
$order = 'a.date DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.id DESC';
break;
case 'sorting':
$order = 'a.sorting ASC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.date DESC,a.id DESC';
break;
case 'istop':
$order = 'a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'isrecommend':
$order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'isheadline':
$order = 'a.isrecommend DESC,a.istop DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'visits':
case 'likes':
case 'oppose':
$order = $rorder . ' DESC,a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
break;
case 'random': // 随机取数
$db_type = get_db_type();
if ($db_type == 'mysql') {
$order = "RAND()";
} elseif ($db_type == 'sqlite') {
$order = "RANDOM()";
}
break;
default:
if ($rorder) {
$orders = explode(',', $rorder);
foreach ($orders as $k => $v) {
if (strpos($v, 'ext_') === 0) {
$orders[$k] = 'e.' . $v;
} else {
$orders[$k] = 'a.' . $v;
}
}
$order = implode(',', $orders);
$order .= ',a.istop DESC,a.isrecommend DESC,a.isheadline DESC,a.sorting ASC,a.date DESC,a.id DESC';
}
}
}
// 读取数据
$data = $this->model->getLists($acode, $scode, $num, $order);
$Parser = new ParserController();
foreach ($data as $key => $value) {
if ($value->outlink) {
$data[$key]->apilink = $value->outlink;
} else {
$data[$key]->apilink = url('/api/content/index/id/' . $value->id, false);
}
$data[$key]->likeslink = url('/home/Do/likes/id/' . $value->id, false);
$data[$key]->opposelink = url('/home/Do/oppose/id/' . $value->id, false);
$data[$key]->content = str_replace(STATIC_DIR . '/upload/', get_http_url() . STATIC_DIR . '/upload/', $value->content);
// 返回网页链接地址便于AJAX调用内容
$data[$key]->contentlink = $Parser->parserLink(2, $value->urlname, 'content', $value->scode, $value->sortfilename, $value->id, $value->filename);
}
// 输出数据
if (request('page') <= PAGECOUNT) {
json(1, $data);
} else {
return json(0, '已经到底了!');
}
}
}

546
apps/api/model/CmsModel.php Normal file
View File

@@ -0,0 +1,546 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年2月14日
* 标签解析引擎模型
*/
namespace app\api\model;
use core\basic\Model;
class CmsModel extends Model
{
// 存储分类及子编码
protected $scodes = array();
// 存储分类查询数据
protected $sorts;
// 存储栏目位置
protected $position = array();
// 单个站点配置信息
public function getSite($acode, $name)
{
return parent::table('ay_site')->where("acode='" . $acode . "'")->value($name);
}
// 站点配置信息
public function getSiteAll($acode)
{
return parent::table('ay_site')->where("acode='" . $acode . "'")->find();
}
// 单个公司信息
public function getCompany($acode, $name)
{
return parent::table('ay_company')->where("acode='" . $acode . "'")->value($name);
}
// 公司信息
public function getCompanyAll($acode)
{
return parent::table('ay_company')->where("acode='" . $acode . "'")->find();
}
// 自定义标签
public function getLabel($name)
{
return parent::table('ay_label')->where("name='$name'")
->decode()
->value('value');
}
// 所有自定义标签
public function getLabelAll()
{
return parent::table('ay_label')->decode()->column('value', 'name');
}
// 分类信息
public function getSort($acode, $scode)
{
$field = array(
'a.*',
'b.type'
);
$join = array(
'ay_model b',
'a.mcode=b.mcode',
'LEFT'
);
return parent::table('ay_content_sort a')->field($field)
->where("a.acode='" . $acode . "'")
->where("a.scode='$scode'")
->join($join)
->find();
}
// 分类栏目列表
public function getSorts($acode)
{
$fields = array(
'a.*',
'b.type'
);
$join = array(
'ay_model b',
'a.mcode=b.mcode',
'LEFT'
);
$result = parent::table('ay_content_sort a')->field($fields)
->where("a.acode='" . $acode . "'")
->where('a.status=1')
->join($join)
->order('a.pcode,a.sorting,a.id')
->select();
return get_tree($result, 0, 'scode', 'pcode');
}
// 获取分类的子类
public function getSortsSon($acode, $scode)
{
$fields = array(
'a.*',
'b.type'
);
$join = array(
'ay_model b',
'a.mcode=b.mcode',
'LEFT'
);
$result = parent::table('ay_content_sort a')->field($fields)
->where("a.pcode='" . $scode . "'")
->where("a.acode='" . $acode . "'")
->where('a.status=1')
->join($join)
->order('a.sorting,a.id')
->select();
return $result;
}
// 分类顶级编码
public function getSortTopScode($acode, $scode)
{
if (! isset($this->sorts)) {
$fields = array(
'a.id',
'a.pcode',
'a.scode',
'a.name',
'b.type'
);
$join = array(
'ay_model b',
'a.mcode=b.mcode',
'LEFT'
);
$this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . $acode . "'")
->join($join)
->column($fields, 'scode');
}
$result = $this->sorts;
return $this->getTopParent($scode, $result);
}
// 获取位置
public function getPosition($acode, $scode)
{
if (! isset($this->sorts)) {
$fields = array(
'a.id',
'a.pcode',
'a.scode',
'a.name',
'a.outlink',
'b.type'
);
$join = array(
'ay_model b',
'a.mcode=b.mcode',
'LEFT'
);
$this->sorts = parent::table('ay_content_sort a')->where("a.acode='" . $acode . "'")
->join($join)
->column($fields, 'scode');
}
$result = $this->sorts;
$this->position = array();
$this->getTopParent($scode, $result);
return array_reverse($this->position);
}
// 分类顶级编码及栏目树
private function getTopParent($scode, $sorts)
{
if (! $scode || ! $sorts) {
return;
}
$this->position[] = $sorts[$scode];
if ($sorts[$scode]['pcode']) {
return $this->getTopParent($sorts[$scode]['pcode'], $sorts);
} else {
return $sorts[$scode]['scode'];
}
}
// 分类子类集
private function getSubScodes($scode)
{
if (! $scode) {
return;
}
$this->scodes[] = $scode;
$subs = parent::table('ay_content_sort')->where("pcode='$scode'")->column('scode');
if ($subs) {
foreach ($subs as $value) {
$this->getSubScodes($value);
}
}
return $this->scodes;
}
// 列表内容,带分页
public function getLists($acode, $scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true)
{
$fields = array(
'a.*',
'b.name as sortname',
'b.filename as sortfilename',
'c.name as subsortname',
'd.type',
'd.name as modelname',
'd.urlname',
'e.*'
);
$join = array(
array(
'ay_content_sort b',
'a.scode=b.scode',
'LEFT'
),
array(
'ay_content_sort c',
'a.subscode=c.scode',
'LEFT'
),
array(
'ay_model d',
'b.mcode=d.mcode',
'LEFT'
),
array(
'ay_content_ext e',
'a.id=e.contentid',
'LEFT'
)
);
$scode_arr = array();
if ($scode) {
// 获取所有子类分类编码
$this->scodes = array(); // 先清空
$arr = explode(',', $scode); // 传递有多个分类时进行遍历
foreach ($arr as $value) {
$scodes = $this->getSubScodes(trim($value));
}
// 拼接条件
$scode_arr = array(
"a.scode in (" . implode_quot(',', $scodes) . ")",
"a.subscode='$scode'"
);
}
$where = array(
"a.acode='" . $acode . "'",
'a.status=1',
'd.type=2',
"a.date<'" . date('Y-m-d H:i:s') . "'"
);
// 筛选条件支持模糊匹配
return parent::table('ay_content a')->field($fields)
->where($scode_arr, 'OR')
->where($where)
->where($select, 'AND', 'AND', $fuzzy)
->where($filter, 'OR')
->where($tags, 'OR')
->join($join)
->order($order)
->page(1, $num)
->decode()
->select();
}
// 列表内容,不带分页
public function getList($acode, $scode, $num, $order, $filter = array(), $tags = array(), $select = array(), $fuzzy = true)
{
$fields = array(
'a.*',
'b.name as sortname',
'b.filename as sortfilename',
'c.name as subsortname',
'd.type',
'd.name as modelname',
'd.urlname',
'e.*'
);
$join = array(
array(
'ay_content_sort b',
'a.scode=b.scode',
'LEFT'
),
array(
'ay_content_sort c',
'a.subscode=c.scode',
'LEFT'
),
array(
'ay_model d',
'b.mcode=d.mcode',
'LEFT'
),
array(
'ay_content_ext e',
'a.id=e.contentid',
'LEFT'
)
);
$scode_arr = array();
if ($scode) {
// 获取所有子类分类编码
$this->scodes = array(); // 先清空
$arr = explode(',', $scode); // 传递有多个分类时进行遍历
foreach ($arr as $value) {
$scodes = $this->getSubScodes(trim($value));
}
// 拼接条件
$scode_arr = array(
"a.scode in (" . implode_quot(',', $scodes) . ")",
"a.subscode='$scode'"
);
}
$where = array(
"a.acode='" . $acode . "'",
'a.status=1',
'd.type=2',
"a.date<'" . date('Y-m-d H:i:s') . "'"
);
// 筛选条件支持模糊匹配
return parent::table('ay_content a')->field($fields)
->where($scode_arr, 'OR')
->where($where)
->where($select, 'AND', 'AND', $fuzzy)
->where($filter, 'OR')
->where($tags, 'OR')
->join($join)
->order($order)
->limit($num)
->decode()
->select();
}
// 内容详情
public function getContent($acode, $id)
{
$field = array(
'a.*',
'b.name as sortname',
'b.filename as sortfilename',
'c.name as subsortname',
'd.type',
'd.name as modelname',
'd.urlname',
'e.*'
);
$join = array(
array(
'ay_content_sort b',
'a.scode=b.scode',
'LEFT'
),
array(
'ay_content_sort c',
'a.subscode=c.scode',
'LEFT'
),
array(
'ay_model d',
'b.mcode=d.mcode',
'LEFT'
),
array(
'ay_content_ext e',
'a.id=e.contentid',
'LEFT'
)
);
$result = parent::table('ay_content a')->field($field)
->where("a.id='$id'")
->where("a.acode='" . $acode . "'")
->where('a.status=1')
->join($join)
->decode()
->find();
if ($result) {
$data2 = array(
'visits' => '+=1'
);
parent::table('ay_content')->where("id={$result->id}")->update($data2);
}
return $result;
}
// 单页详情
public function getAbout($acode, $scode)
{
$field = array(
'a.*',
'b.name as sortname',
'b.filename as sortfilename',
'c.name as subsortname',
'd.type',
'd.name as modelname',
'd.urlname',
'e.*'
);
$join = array(
array(
'ay_content_sort b',
'a.scode=b.scode',
'LEFT'
),
array(
'ay_content_sort c',
'a.subscode=c.scode',
'LEFT'
),
array(
'ay_model d',
'b.mcode=d.mcode',
'LEFT'
),
array(
'ay_content_ext e',
'a.id=e.contentid',
'LEFT'
)
);
$result = parent::table('ay_content a')->field($field)
->where("a.scode='$scode' OR b.filename='$scode'")
->where("a.acode='" . $acode . "'")
->where('a.status=1')
->join($join)
->order('id DESC')
->decode()
->find();
if ($result) {
$data2 = array(
'visits' => '+=1'
);
parent::table('ay_content')->where("id={$result->id}")->update($data2);
}
return $result;
}
// 指定内容多图
public function getContentPics($acode, $id)
{
$result = parent::table('ay_content')->where("id='$id'")
->where("acode='" . $acode . "'")
->where('status=1')
->value('pics');
return $result;
}
// 幻灯片
public function getSlides($acode, $gid, $num)
{
$result = parent::table('ay_slide')->where("gid='$gid'")
->where("acode='" . $acode . "'")
->order('sorting asc,id asc')
->limit($num)
->select();
return $result;
}
// 友情链接
public function getLinks($acode, $gid, $num)
{
$result = parent::table('ay_link')->where("gid='$gid'")
->where("acode='" . $acode . "'")
->order('sorting asc,id asc')
->limit($num)
->select();
return $result;
}
// 获取留言
public function getMessage($acode, $num)
{
return parent::table('ay_message')->where("status=1")
->where("acode='" . $acode . "'")
->order('id DESC')
->decode(false)
->page(1, $num)
->select();
}
// 新增留言
public function addMessage($table, $data)
{
return parent::table('ay_message')->autoTime()->insert($data);
}
// 获取表单字段
public function getFormField($fcode)
{
$field = array(
'a.table_name',
'a.form_name',
'b.name',
'b.required',
'b.description'
);
$join = array(
'ay_form_field b',
'a.fcode=b.fcode',
'LEFT'
);
return parent::table('ay_form a')->field($field)
->where("a.fcode='$fcode'")
->join($join)
->order('b.sorting ASC,b.id ASC')
->select();
}
// 获取表单表名称
public function getFormTable($fcode)
{
return parent::table('ay_form')->where("fcode='$fcode'")->value('table_name');
}
// 获取表单数据
public function getForm($table, $num)
{
return parent::table($table)->order('id DESC')
->decode(false)
->page(1, $num)
->select();
}
// 新增表单数据
public function addForm($table, $data)
{
return parent::table($table)->insert($data);
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年3月8日
*
*/
namespace app\api\model;
use core\basic\Model;
class DoModel extends Model
{
// 新增访问
public function addVisits($id)
{
$data = array(
'visits' => '+=1'
);
parent::table('ay_content')->where("id='$id'")->update($data);
}
// 新增喜欢
public function addLikes($id)
{
$data = array(
'likes' => '+=1'
);
parent::table('ay_content')->where("id='$id'")->update($data);
}
// 新增喜欢
public function addOppose($id)
{
$data = array(
'oppose' => '+=1'
);
parent::table('ay_content')->where("id='$id'")->update($data);
}
}

View File

@@ -0,0 +1 @@
<h2>(- -)欢迎您使用本系统,请开始您的开发旅程吧!</h2>