564 lines
19 KiB
PHP
Executable File
564 lines
19 KiB
PHP
Executable File
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ShopXO 国内领先企业级B2C免费开源电商系统
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Devil
|
|
// +----------------------------------------------------------------------
|
|
namespace app\service;
|
|
|
|
use think\Db;
|
|
use think\facade\Hook;
|
|
use app\service\ResourcesService;
|
|
|
|
/**
|
|
* 文章服务层
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
*/
|
|
class ArticleService
|
|
{
|
|
/**
|
|
* 获取文章列表
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-08-29
|
|
* @desc description
|
|
* @param [array] $params [输入参数]
|
|
*/
|
|
public static function ArticleList($params)
|
|
{
|
|
$where = empty($params['where']) ? [] : $params['where'];
|
|
$field = empty($params['field']) ? 'a.*' : $params['field'];
|
|
$m = isset($params['m']) ? intval($params['m']) : 0;
|
|
$n = isset($params['n']) ? intval($params['n']) : 10;
|
|
|
|
$data = Db::name('Article')->alias('a')->join(['__ARTICLE_CATEGORY__'=>'ac'], 'a.article_category_id=ac.id')->field($field)->where($where)->order('a.id desc')->limit($m, $n)->select();
|
|
if(!empty($data))
|
|
{
|
|
$common_is_enable_tips = lang('common_is_enable_tips');
|
|
foreach($data as &$v)
|
|
{
|
|
// url
|
|
$v['url'] = MyUrl('index/article/index', ['id'=>$v['id']]);
|
|
|
|
// 分类名称
|
|
if(isset($v['article_category_id']))
|
|
{
|
|
$v['article_category_name'] = Db::name('ArticleCategory')->where(['id'=>$v['article_category_id']])->value('name');
|
|
}
|
|
|
|
// 是否启用
|
|
if(isset($v['is_enable']))
|
|
{
|
|
$v['is_enable_text'] = $common_is_enable_tips[$v['is_enable']]['name'];
|
|
}
|
|
|
|
// 内容
|
|
if(isset($v['content']))
|
|
{
|
|
$v['content'] = ResourcesService::ContentStaticReplace($v['content'], 'get');
|
|
}
|
|
|
|
// 图片
|
|
if(isset($v['images']))
|
|
{
|
|
if(!empty($v['images']))
|
|
{
|
|
$images = json_decode($v['images'], true);
|
|
foreach($images as &$img)
|
|
{
|
|
$img = ResourcesService::AttachmentPathViewHandle($img);
|
|
}
|
|
$v['images'] = $images;
|
|
}
|
|
}
|
|
|
|
if(isset($v['add_time']))
|
|
{
|
|
$v['add_time_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
|
$v['add_time_date'] = date('Y-m-d', $v['add_time']);
|
|
}
|
|
if(isset($v['upd_time']))
|
|
{
|
|
$v['upd_time_time'] = date('Y-m-d H:i:s', $v['upd_time']);
|
|
$v['upd_time_date'] = date('Y-m-d', $v['upd_time']);
|
|
}
|
|
}
|
|
}
|
|
return DataReturn('处理成功', 0, $data);
|
|
}
|
|
|
|
/**
|
|
* 文章总数
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
* @param [array] $where [条件]
|
|
*/
|
|
public static function ArticleTotal($where)
|
|
{
|
|
return (int) Db::name('Article')->alias('a')->join(['__ARTICLE_CATEGORY__'=>'ac'], 'a.article_category_id=ac.id')->where($where)->count();
|
|
}
|
|
|
|
/**
|
|
* 列表条件
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-09-29
|
|
* @desc description
|
|
* @param [array] $params [输入参数]
|
|
*/
|
|
public static function ArticleListWhere($params = [])
|
|
{
|
|
$where = [];
|
|
|
|
if(!empty($params['keywords']))
|
|
{
|
|
$where[] = ['a.title', 'like', '%'.$params['keywords'].'%'];
|
|
}
|
|
|
|
// 是否更多条件
|
|
if(isset($params['is_more']) && $params['is_more'] == 1)
|
|
{
|
|
// 等值
|
|
if(isset($params['is_enable']) && $params['is_enable'] > -1)
|
|
{
|
|
$where[] = ['a.is_enable', '=', intval($params['is_enable'])];
|
|
}
|
|
if(isset($params['article_category_id']) && $params['article_category_id'] > -1)
|
|
{
|
|
$where[] = ['a.article_category_id', '=', intval($params['article_category_id'])];
|
|
}
|
|
if(isset($params['is_home_recommended']) && $params['is_home_recommended'] > -1)
|
|
{
|
|
$where[] = ['a.is_home_recommended', '=', intval($params['is_home_recommended'])];
|
|
}
|
|
if(isset($params['access_count']) && $params['access_count'] > -1)
|
|
{
|
|
$where[] = ['a.access_count', '>', intval($params['access_count'])];
|
|
}
|
|
|
|
if(!empty($params['time_start']))
|
|
{
|
|
$where[] = ['a.add_time', '>', strtotime($params['time_start'])];
|
|
}
|
|
if(!empty($params['time_end']))
|
|
{
|
|
$where[] = ['a.add_time', '<', strtotime($params['time_end'])];
|
|
}
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
/**
|
|
* 文章保存
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2018-12-18
|
|
* @desc description
|
|
* @param [array] $params [输入参数]
|
|
*/
|
|
public static function ArticleSave($params = [])
|
|
{
|
|
// 请求类型
|
|
$p = [
|
|
[
|
|
'checked_type' => 'length',
|
|
'key_name' => 'title',
|
|
'checked_data' => '2,60',
|
|
'error_msg' => '标题长度 2~60 个字符',
|
|
],
|
|
[
|
|
'checked_type' => 'empty',
|
|
'key_name' => 'article_category_id',
|
|
'error_msg' => '请选择文章分类',
|
|
],
|
|
[
|
|
'checked_type' => 'fun',
|
|
'key_name' => 'jump_url',
|
|
'checked_data' => 'CheckUrl',
|
|
'is_checked' => 1,
|
|
'error_msg' => '跳转url地址格式有误',
|
|
],
|
|
[
|
|
'checked_type' => 'length',
|
|