Files
shopxo/app/service/CustomViewService.php

257 lines
8.2 KiB
PHP
Raw Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
2021-07-18 23:42:10 +08:00
use think\facade\Db;
use app\service\ResourcesService;
2018-12-28 18:58:37 +08:00
/**
* 自定义页面服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class CustomViewService
{
/**
* 获取自定义列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function CustomViewList($params = [])
2018-12-28 18:58:37 +08:00
{
$where = empty($params['where']) ? [] : $params['where'];
2020-06-16 23:27:12 +08:00
$field = empty($params['field']) ? '*' : $params['field'];
$order_by = empty($params['order_by']) ? 'id desc' : trim($params['order_by']);
2018-12-28 18:58:37 +08:00
$m = isset($params['m']) ? intval($params['m']) : 0;
$n = isset($params['n']) ? intval($params['n']) : 10;
2021-07-18 23:42:10 +08:00
$data = Db::name('CustomView')->field($field)->where($where)->order($order_by)->limit($m, $n)->select()->toArray();
2018-12-28 18:58:37 +08:00
if(!empty($data))
{
2021-08-14 17:17:45 +08:00
$common_is_enable_list = MyConst('common_is_enable_list');
2018-12-28 18:58:37 +08:00
foreach($data as &$v)
{
// 是否启用
if(isset($v['is_enable']))
{
$v['is_enable_text'] = $common_is_enable_list[$v['is_enable']]['name'];
}
// 内容
if(isset($v['content']))
{
$v['content'] = ResourcesService::ContentStaticReplace($v['content'], 'get');
}
2019-10-10 19:13:50 +08:00
// 图片
2020-06-16 23:27:12 +08:00
if(!empty($v['images']))
2019-10-10 19:13:50 +08:00
{
2020-06-16 23:27:12 +08:00
$images = json_decode($v['images'], true);
foreach($images as &$img)
2019-10-10 19:13:50 +08:00
{
2020-06-16 23:27:12 +08:00
$img = ResourcesService::AttachmentPathViewHandle($img);
2019-10-10 19:13:50 +08:00
}
2020-06-16 23:27:12 +08:00
$v['images'] = $images;
2019-10-10 19:13:50 +08:00
}
2018-12-28 18:58:37 +08:00
// 时间
if(isset($v['add_time']))
{
2020-06-16 23:27:12 +08:00
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
2018-12-28 18:58:37 +08:00
}
if(isset($v['upd_time']))
{
2020-06-16 23:27:12 +08:00
$v['upd_time'] = empty($v['upd_time']) ? '' : date('Y-m-d H:i:s', $v['upd_time']);
2018-12-28 18:58:37 +08:00
}
}
}
return DataReturn('处理成功', 0, $data);
}
/**
* 总数
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-29
* @desc description
* @param [array] $where [条件]
*/
public static function CustomViewTotal($where = [])
2018-12-28 18:58:37 +08:00
{
return (int) Db::name('CustomView')->where($where)->count();
}
/**
* 自定义页面访问统计加1
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-10-15
* @desc description
* @param [array] $params [输入参数]
*/
public static function CustomViewAccessCountInc($params = [])
2018-12-28 18:58:37 +08:00
{
if(!empty($params['id']))
{
2021-07-21 16:35:38 +08:00
return Db::name('CustomView')->where(array('id'=>intval($params['id'])))->inc('access_count')->update();
2018-12-28 18:58:37 +08:00
}
return false;
}
/**
* 保存
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-18
* @desc description
* @param [array] $params [输入参数]
*/
public static function CustomViewSave($params = [])
2018-12-28 18:58:37 +08:00
{
// 请求类型
$p = [
[
'checked_type' => 'length',
'key_name' => 'title',
'checked_data' => '2,60',
'error_msg' => '标题长度 2~60 个字符',
],
[
'checked_type' => 'length',
'key_name' => 'content',
2020-06-16 23:27:12 +08:00
'checked_data' => '10,105000',
'error_msg' => '内容长度最少 10~105000 个字符',
2018-12-28 18:58:37 +08:00
],
];
$ret = ParamsChecked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
2019-02-20 16:18:21 +08:00
// 编辑器内容
2020-08-30 00:41:07 +08:00
$content = empty($params['content']) ? '' : ResourcesService::ContentStaticReplace(htmlspecialchars_decode($params['content']), 'add');
2019-02-20 16:18:21 +08:00
2018-12-28 18:58:37 +08:00
// 数据
2020-08-30 00:41:07 +08:00
$images = ResourcesService::RichTextMatchContentAttachment($content, 'customview');
2018-12-28 18:58:37 +08:00
$data = [
'title' => $params['title'],
2020-08-30 00:41:07 +08:00
'content' => $content,
2019-10-10 19:13:50 +08:00
'images' => empty($images) ? '' : json_encode($images),
'images_count' => count($images),
2018-12-28 18:58:37 +08:00
'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
'is_header' => isset($params['is_header']) ? intval($params['is_header']) : 0,
'is_footer' => isset($params['is_footer']) ? intval($params['is_footer']) : 0,
'is_full_screen'=> isset($params['is_full_screen']) ? intval($params['is_full_screen']) : 0,
];
if(empty($params['id']))
{
$data['add_time'] = time();
if(Db::name('CustomView')->insertGetId($data) > 0)
{
return DataReturn('添加成功', 0);
}
return DataReturn('添加失败', -100);
} else {
$data['upd_time'] = time();
if(Db::name('CustomView')->where(['id'=>intval($params['id'])])->update($data))
{
return DataReturn('编辑成功', 0);
}
return DataReturn('编辑失败', -100);
}
}
/**
* 删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-18
* @desc description
* @param [array] $params [输入参数]
*/
public static function CustomViewDelete($params = [])
2018-12-28 18:58:37 +08:00
{
2020-06-16 23:27:12 +08:00
// 参数是否有误
if(empty($params['ids']))
2018-12-28 18:58:37 +08:00
{
2020-06-16 23:27:12 +08:00
return DataReturn('操作id有误', -1);
}
// 是否数组
if(!is_array($params['ids']))
{
$params['ids'] = explode(',', $params['ids']);
2018-12-28 18:58:37 +08:00
}
// 删除操作
2020-06-16 23:27:12 +08:00
if(Db::name('CustomView')->where(['id'=>$params['ids']])->delete())
2018-12-28 18:58:37 +08:00
{
return DataReturn('删除成功');
}
2020-06-16 23:27:12 +08:00
return DataReturn('删除失败', -100);
2018-12-28 18:58:37 +08:00
}
/**
* 状态更新
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
* @param [array] $params [输入参数]
*/
public static function CustomViewStatusUpdate($params = [])
2018-12-28 18:58:37 +08:00
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'id',
'error_msg' => '操作id有误',
],
[
'checked_type' => 'empty',
'key_name' => 'field',
'error_msg' => '字段有误',
],
[
'checked_type' => 'in',
'key_name' => 'state',
'checked_data' => [0,1],
'error_msg' => '状态有误',
],
];
$ret = ParamsChecked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 数据更新
2020-06-16 23:27:12 +08:00
if(Db::name('CustomView')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()]))
2018-12-28 18:58:37 +08:00
{
return DataReturn('编辑成功');
}
2020-06-16 23:27:12 +08:00
return DataReturn('编辑失败', -100);
2018-12-28 18:58:37 +08:00
}
}
?>