Commit 9a7db41b authored by 聆听's avatar 聆听 Committed by Gitee
Browse files

!32 更新v3.2.9

Merge pull request !32 from 吴昊天/v3.2.9
parents d1d5405e 5ef2af8c
Showing with 2328 additions and 2371 deletions
+2328 -2371
version=CRMEB-DTKY v3.2.8
version=CRMEB-DTKY v3.2.9
version_code=134
\ No newline at end of file
版权所有 (c)2017-2027,西安众邦网络科技有限公司 保留所有权利。
感谢您选择CrmEb开源客户管理+电商系统(简称CRMEB),CRMEB是国内最稳定、最强大、最先进的互联网电商平台解决方案之一,CRMEB基于 PHP + MySQL 的技术,采用ThinkPHP5.0框架开发。
为了使你正确并合法的使用本软件,请你在使用前务必阅读清楚下面的协议条款:
本授权协议适用且仅适用于CRMEB任何版本,CRMEB官方对本授权协议的最终解释权和修改权。
一、协议许可的权利
1、您可以在完全遵守本最终用户授权协议的基础上,将本软件应用于非商业用途,而不必支付软件版权授权费用。
2、您可以在协议规定的约束和限制范围内修改 CRMEB 源代码或界面风格以适应您的网站要求。
3、您拥有使用本软件构建的网站全部内容所有权,并独立承担与这些内容的相关法律义务。
4、获得商业授权之后,您可以将本软件应用于商业用途,同时依据所购买的授权类型中确定的技术支持内容。商业授权用户享有反映和提出意见的权力,相关意见将被作为首要考虑,但没有一定被采纳的承诺或保证。
二、协议许可的权利和限制
1、未获商业授权之前,不得删除网站底部及相应的官方版权信息和链接。购买商业授权请联系西安众邦网络科技有限公司了解最新说明。CRMEB著作权已在中华人民共和国国家版权局注册(中国国家版权局著作权登记号 2018SR024463),著作权受到法律和国际公约保护。
2、未经官方许可,不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证。
3、不管你的网站是否整体使用 CRMEB ,还是部份栏目使用 CRMEB,在你使用了 CRMEB 的网站主页上必须加上 CRMEB 官方网址(www.crmeb.com)的链接。
4、未经官方许可,禁止在 CRMEB 的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。
5、如果您未能遵守本协议的条款,您的授权将被终止,所被许可的权利将被收回,并承担相应法律责任。
三、有限担保和免责声明
1、本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。
2、用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未购买产品技术服务之前,我们不承诺对免费用户提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的相关责任。
3、电子文本形式的授权协议如同双方书面签署的协议一样,具有完全的和等同的法律效力。您一旦开始确认本协议并安装 CRMEB,即被视为完全理解并接受本协议的各项条款,在享有上述条款授予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本授权协议并构成侵权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
协议发布时间: 2017年8月01日
版本最新更新: 2019年8月15日 By CRMEB
CRMEB官方网站:http://www.crmeb.com
CRMEB演示站:http://demo.crmeb.com
-----------------------------------------------------
运营团队: 众邦科技
电 话: 400-8888-794
邮 箱: admin@xazbkj.com
版权所有 (c)2017-2027,西安众邦网络科技有限公司 保留所有权利。
感谢您选择CrmEb开源客户管理+电商系统(简称CRMEB),CRMEB是国内最稳定、最强大、最先进的互联网电商平台解决方案之一,CRMEB基于 PHP + MySQL 的技术,采用ThinkPHP5.0框架开发。
为了使你正确并合法的使用本软件,请你在使用前务必阅读清楚下面的协议条款:
本授权协议适用且仅适用于CRMEB任何版本,CRMEB官方对本授权协议的最终解释权和修改权。
一、协议许可的权利
1、您可以在完全遵守本最终用户授权协议的基础上,将本软件应用于非商业用途,而不必支付软件版权授权费用。
2、您可以在协议规定的约束和限制范围内修改 CRMEB 源代码或界面风格以适应您的网站要求。
3、您拥有使用本软件构建的网站全部内容所有权,并独立承担与这些内容的相关法律义务。
4、获得商业授权之后,您可以将本软件应用于商业用途,同时依据所购买的授权类型中确定的技术支持内容。商业授权用户享有反映和提出意见的权力,相关意见将被作为首要考虑,但没有一定被采纳的承诺或保证。
二、协议许可的权利和限制
1、未获商业授权之前,不得删除网站底部及相应的官方版权信息和链接。购买商业授权请联系西安众邦网络科技有限公司了解最新说明。CRMEB著作权已在中华人民共和国国家版权局注册(中国国家版权局著作权登记号 2018SR024463),著作权受到法律和国际公约保护。
2、未经官方许可,不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证。
3、不管你的网站是否整体使用 CRMEB ,还是部份栏目使用 CRMEB,在你使用了 CRMEB 的网站主页上必须加上 CRMEB 官方网址(www.crmeb.com)的链接。
4、未经官方许可,禁止在 CRMEB 的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。
5、如果您未能遵守本协议的条款,您的授权将被终止,所被许可的权利将被收回,并承担相应法律责任。
三、有限担保和免责声明
1、本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。
2、用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未购买产品技术服务之前,我们不承诺对免费用户提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的相关责任。
3、电子文本形式的授权协议如同双方书面签署的协议一样,具有完全的和等同的法律效力。您一旦开始确认本协议并安装 CRMEB,即被视为完全理解并接受本协议的各项条款,在享有上述条款授予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本授权协议并构成侵权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
协议发布时间: 2017年8月01日
版本最新更新: 2019年8月15日 By CRMEB
CRMEB官方网站:http://www.crmeb.com
CRMEB演示站:http://demo.crmeb.com
-----------------------------------------------------
运营团队: 众邦科技
电 话: 400-8888-794
邮 箱: admin@xazbkj.com
网 址: http://www.xazbkj.com
\ No newline at end of file
CRMEB 3.0
===============
> 运行环境要求PHP7.1+。
## 主要特性
### 开源无加密
源码开源无加密,有详细的代码注释,有完整系统手册
### TP6框架
使用最新的 ThinkPHP 6.0框架开发
### 前端采用Vue CLI框架
前端使用Vue CLI框架nodejs打包,页面加载更流畅,用户体验更好
### 标准接口
标准接口、前后端分离,二次开发更方便
### 支持队列
降低流量高峰,解除耦合,高可用
### 长连接
减少CPU及内存使用及网络堵塞,减少请求响应时长
### 无缝事件机制
行为扩展更方便,方便二次开发
### 后台快速生成表单
后台应用form-builder 无需写页面快速增删改查
### 数据表格导出
PHPExcel数据导出,导出表格更加美观可视;
### 数据统计分析
后台使用ECharts图表统计,实现用户、产品、订单、资金等统计分析
### 强大的后台权限管理
后台多种角色、多重身份权限管理,权限可以控制到每一步操作
### 一件安装
自动检查系统环境一键安装
## 安装
## 一键安装
上传你的代码,站点入口目录设置/public
在浏览器中输入你的域名或IP(例如:www.yourdomain.com),
安装程序会自动执行安装。期间系统会提醒你输入数据库信息以完成安装,安装完成后建议删除install目录下index.php文件或将其改名。
后台访问地址:
1.域名/admin
2.域名/index.php/admin
3.域名/index.php?s=/admin
公众号和H5首页访问地址:
1.域名/
提示:正常访问是第一中模式,第一种访问不了请检测[URL重写](http://help.crmeb.net/895486)是否配置好
安装过程中请牢记您的账号密码!
## 重新安装
1. 清除数据库
2. 删除/public/install/install.lock 文件
## 手动安装
1.创建数据库,倒入数据库文件
数据库文件目录/public/install/crmeb.sql
2.修改数据库连接文件
配置文件路径/.env
~~~
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1 #数据库连接地址
DATABASE = test #数据库名称
USERNAME = username #数据库登录账号
PASSWORD = password #数据库登录密码
HOSTPORT = 3306 #数据库端口
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
~~~
3.修改目录权限(linux系统)777
/public
/runtime
4.后台登录:
http://域名/admin
默认账号:admin 密码:crmeb.com
## 定时任务
在自动收货,库存预警等功能使用到
```sh
php think timer [ status ] [ --d ]
```
参数
- status: 状态
- start: 启动
- stop: 关闭
- restart: 重启
- --d : 后台执行
## 长连接服务
在h5聊天,后台管理员消息通知等功能使用到
```sh
php think workerman [ status ] [ server ] [ --d ]
```
windows环境下需要分三步执行
```sh
# 内部通讯服务
php think workerman start channel
# h5端聊天服务
php think workerman start chat
# 后台管理员通知
php think workerman start admin
```
参数
- status: 状态
- start: 启动
- stop: 关闭
- restart: 重启
- server: 服务 (windows)
- channel: 内部通讯
- chat: h5
- admin: 后台
- --d : 后台执行
## 文档
[使用手册](https://help.crmeb.net)
[TP6开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
## 参与开发
请参阅 [CRMEB](https://github.com/crmeb/CRMEB)
## 版权信息
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2017-2019 by CRMEB (http://www.crmeb.com)
All rights reserved。
CRMEB® 商标和著作权所有者为西安众邦网络科技有限公司。
CRMEB 3.0
===============
> 运行环境要求PHP7.1+。
## 主要特性
### 开源无加密
源码开源无加密,有详细的代码注释,有完整系统手册
### TP6框架
使用最新的 ThinkPHP 6.0框架开发
### 前端采用Vue CLI框架
前端使用Vue CLI框架nodejs打包,页面加载更流畅,用户体验更好
### 标准接口
标准接口、前后端分离,二次开发更方便
### 支持队列
降低流量高峰,解除耦合,高可用
### 长连接
减少CPU及内存使用及网络堵塞,减少请求响应时长
### 无缝事件机制
行为扩展更方便,方便二次开发
### 后台快速生成表单
后台应用form-builder 无需写页面快速增删改查
### 数据表格导出
PHPExcel数据导出,导出表格更加美观可视;
### 数据统计分析
后台使用ECharts图表统计,实现用户、产品、订单、资金等统计分析
### 强大的后台权限管理
后台多种角色、多重身份权限管理,权限可以控制到每一步操作
### 一件安装
自动检查系统环境一键安装
## 安装
## 一键安装
上传你的代码,站点入口目录设置/public
在浏览器中输入你的域名或IP(例如:www.yourdomain.com),
安装程序会自动执行安装。期间系统会提醒你输入数据库信息以完成安装,安装完成后建议删除install目录下index.php文件或将其改名。
后台访问地址:
1.域名/admin
2.域名/index.php/admin
3.域名/index.php?s=/admin
公众号和H5首页访问地址:
1.域名/
提示:正常访问是第一中模式,第一种访问不了请检测[URL重写](http://help.crmeb.net/895486)是否配置好
安装过程中请牢记您的账号密码!
## 重新安装
1. 清除数据库
2. 删除/public/install/install.lock 文件
## 手动安装
1.创建数据库,倒入数据库文件
数据库文件目录/public/install/crmeb.sql
2.修改数据库连接文件
配置文件路径/.env
~~~
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1 #数据库连接地址
DATABASE = test #数据库名称
USERNAME = username #数据库登录账号
PASSWORD = password #数据库登录密码
HOSTPORT = 3306 #数据库端口
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
~~~
3.修改目录权限(linux系统)777
/public
/runtime
4.后台登录:
http://域名/admin
默认账号:admin 密码:crmeb.com
## 定时任务
在自动收货,库存预警等功能使用到
```sh
php think timer [ status ] [ --d ]
```
参数
- status: 状态
- start: 启动
- stop: 关闭
- restart: 重启
- --d : 后台执行
## 长连接服务
在h5聊天,后台管理员消息通知等功能使用到
```sh
php think workerman [ status ] [ server ] [ --d ]
```
windows环境下需要分三步执行
```sh
# 内部通讯服务
php think workerman start channel
# h5端聊天服务
php think workerman start chat
# 后台管理员通知
php think workerman start admin
```
参数
- status: 状态
- start: 启动
- stop: 关闭
- restart: 重启
- server: 服务 (windows)
- channel: 内部通讯
- chat: h5
- admin: 后台
- --d : 后台执行
## 文档
[使用手册](https://help.crmeb.net)
[TP6开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
## 参与开发
请参阅 [CRMEB](https://github.com/crmeb/CRMEB)
## 版权信息
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2017-2019 by CRMEB (http://www.crmeb.com)
All rights reserved。
CRMEB® 商标和著作权所有者为西安众邦网络科技有限公司。
<?php
namespace app;
use crmeb\services\SystemConfigService;
use crmeb\services\GroupDataService;
use crmeb\utils\Json;
use think\facade\Db;
use think\Service;
class AppService extends Service
{
public $bind = [
'json' => Json::class,
'sysConfig' => SystemConfigService::class,
'sysGroupData' => GroupDataService::class
];
public function boot()
{
}
}
<?php
namespace app;
use crmeb\services\SystemConfigService;
use crmeb\services\GroupDataService;
use crmeb\utils\Json;
use think\facade\Db;
use think\Service;
class AppService extends Service
{
public $bind = [
'json' => Json::class,
'sysConfig' => SystemConfigService::class,
'sysGroupData' => GroupDataService::class
];
public function boot()
{
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app;
use Spatie\Macroable\Macroable;
class Request extends \think\Request
{
use Macroable;
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace app;
use Spatie\Macroable\Macroable;
class Request extends \think\Request
{
use Macroable;
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
if (!function_exists('attr_format')) {
/**
* 格式化属性
* @param $arr
* @return array
*/
function attr_format($arr)
{
$data = [];
$res = [];
$count = count($arr);
if ($count > 1) {
for ($i = 0; $i < $count - 1; $i++) {
if ($i == 0) $data = $arr[$i]['detail'];
//替代变量1
$rep1 = [];
foreach ($data as $v) {
foreach ($arr[$i + 1]['detail'] as $g) {
//替代变量2
$rep2 = ($i != 0 ? '' : $arr[$i]['value'] . '_$_') . $v . '-$-' . $arr[$i + 1]['value'] . '_$_' . $g;
$tmp[] = $rep2;
if ($i == $count - 2) {
foreach (explode('-$-', $rep2) as $k => $h) {
//替代变量3
$rep3 = explode('_$_', $h);
//替代变量4
$rep4['detail'][$rep3[0]] = isset($rep3[1]) ? $rep3[1] : '';
}
if($count == count($rep4['detail']))
$res[] = $rep4;
}
}
}
$data = isset($tmp) ? $tmp : [];
}
} else {
$dataArr = [];
foreach ($arr as $k => $v) {
foreach ($v['detail'] as $kk => $vv) {
$dataArr[$kk] = $v['value'] . '_' . $vv;
$res[$kk]['detail'][$v['value']] = $vv;
}
}
$data[] = implode('-', $dataArr);
}
return [$data, $res];
}
}
if (!function_exists('get_month')) {
/**
* 格式化月份
* @param string $time
* @param int $ceil
* @return array
*/
function get_month($time = '', $ceil = 0)
{
if (empty($time)) {
$firstday = date("Y-m-01", time());
$lastday = date("Y-m-d", strtotime("$firstday +1 month -1 day"));
} else if ($time == 'n') {
if ($ceil != 0)
$season = ceil(date('n') / 3) - $ceil;
else
$season = ceil(date('n') / 3);
$firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
$lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
} else if ($time == 'y') {
$firstday = date('Y-01-01');
$lastday = date('Y-12-31');
} else if ($time == 'h') {
$firstday = date('Y-m-d', strtotime('this week +' . $ceil . ' day')) . ' 00:00:00';
$lastday = date('Y-m-d', strtotime('this week +' . ($ceil + 1) . ' day')) . ' 23:59:59';
}
return array($firstday, $lastday);
}
}
if (!function_exists('clearfile')) {
/**删除目录下所有文件
* @param $path 目录或者文件路径
* @param string $ext
* @return bool
*/
function clearfile($path, $ext = '*.log')
{
$files = (array)glob($path . DS . '*');
foreach ($files as $path) {
if (is_dir($path)) {
$matches = glob($path . '/' . $ext);
if (is_array($matches)) {
array_map('unlink', $matches);
}
rmdir($path);
} else {
unlink($path);
}
}
return true;
}
}
if (!function_exists('get_this_class_methods')) {
/**获取当前类方法
* @param $class
* @return array
*/
function get_this_class_methods($class, $unarray = [])
{
$arrayall = get_class_methods($class);
if ($parent_class = get_parent_class($class)) {
$arrayparent = get_class_methods($parent_class);
$arraynow = array_diff($arrayall, $arrayparent);//去除父级的
} else {
$arraynow = $arrayall;
}
return array_diff($arraynow, $unarray);//去除无用的
}
}
if (!function_exists('verify_domain')) {
/**
* 验证域名是否合法
* @param string $domain
* @return bool
*/
function verify_domain(string $domain): bool
{
$res = "/^(?=^.{3,255}$)(http(s)?:\/\/)(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$/";
if (preg_match($res, $domain))
return true;
else
return false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
if (!function_exists('attr_format')) {
/**
* 格式化属性
* @param $arr
* @return array
*/
function attr_format($arr)
{
$data = [];
$res = [];
$count = count($arr);
if ($count > 1) {
for ($i = 0; $i < $count - 1; $i++) {
if ($i == 0) $data = $arr[$i]['detail'];
//替代变量1
$rep1 = [];
foreach ($data as $v) {
foreach ($arr[$i + 1]['detail'] as $g) {
//替代变量2
$rep2 = ($i != 0 ? '' : $arr[$i]['value'] . '_$_') . $v . '-$-' . $arr[$i + 1]['value'] . '_$_' . $g;
$tmp[] = $rep2;
if ($i == $count - 2) {
foreach (explode('-$-', $rep2) as $k => $h) {
//替代变量3
$rep3 = explode('_$_', $h);
//替代变量4
$rep4['detail'][$rep3[0]] = isset($rep3[1]) ? $rep3[1] : '';
}
if($count == count($rep4['detail']))
$res[] = $rep4;
}
}
}
$data = isset($tmp) ? $tmp : [];
}
} else {
$dataArr = [];
foreach ($arr as $k => $v) {
foreach ($v['detail'] as $kk => $vv) {
$dataArr[$kk] = $v['value'] . '_' . $vv;
$res[$kk]['detail'][$v['value']] = $vv;
}
}
$data[] = implode('-', $dataArr);
}
return [$data, $res];
}
}
if (!function_exists('get_month')) {
/**
* 格式化月份
* @param string $time
* @param int $ceil
* @return array
*/
function get_month($time = '', $ceil = 0)
{
if (empty($time)) {
$firstday = date("Y-m-01", time());
$lastday = date("Y-m-d", strtotime("$firstday +1 month -1 day"));
} else if ($time == 'n') {
if ($ceil != 0)
$season = ceil(date('n') / 3) - $ceil;
else
$season = ceil(date('n') / 3);
$firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
$lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
} else if ($time == 'y') {
$firstday = date('Y-01-01');
$lastday = date('Y-12-31');
} else if ($time == 'h') {
$firstday = date('Y-m-d', strtotime('this week +' . $ceil . ' day')) . ' 00:00:00';
$lastday = date('Y-m-d', strtotime('this week +' . ($ceil + 1) . ' day')) . ' 23:59:59';
}
return array($firstday, $lastday);
}
}
if (!function_exists('clearfile')) {
/**删除目录下所有文件
* @param $path 目录或者文件路径
* @param string $ext
* @return bool
*/
function clearfile($path, $ext = '*.log')
{
$files = (array)glob($path . DS . '*');
foreach ($files as $path) {
if (is_dir($path)) {
$matches = glob($path . '/' . $ext);
if (is_array($matches)) {
array_map('unlink', $matches);
}
rmdir($path);
} else {
unlink($path);
}
}
return true;
}
}
if (!function_exists('get_this_class_methods')) {
/**获取当前类方法
* @param $class
* @return array
*/
function get_this_class_methods($class, $unarray = [])
{
$arrayall = get_class_methods($class);
if ($parent_class = get_parent_class($class)) {
$arrayparent = get_class_methods($parent_class);
$arraynow = array_diff($arrayall, $arrayparent);//去除父级的
} else {
$arraynow = $arrayall;
}
return array_diff($arraynow, $unarray);//去除无用的
}
}
if (!function_exists('verify_domain')) {
/**
* 验证域名是否合法
* @param string $domain
* @return bool
*/
function verify_domain(string $domain): bool
{
$res = "/^(?=^.{3,255}$)(http(s)?:\/\/)(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$/";
if (preg_match($res, $domain))
return true;
else
return false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => true,
// 路由是否完全匹配
'route_complete_match' => false,
// 是否自动转换URL中的控制器和操作名
'url_convert' => true,
];
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => true,
// 路由是否完全匹配
'route_complete_match' => false,
// 是否自动转换URL中的控制器和操作名
'url_convert' => true,
];
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板后缀
'view_suffix' => 'php',
// 视图输出字符串内容替换
'tpl_replace_string' => [
'{__PUBLIC_PATH}' => '/', //public 目录
'{__STATIC_PATH}' => '/static/', //全局静态目录
'{__PLUG_PATH}' => '/static/plug/', //全局静态插件
'{__ADMIN_PATH}' => '/system/', //后台目录
'{__FRAME_PATH}' => '/system/frame/', //后台框架
'{__MODULE_PATH}' => '/system/module/', //后台模块
]
];
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板后缀
'view_suffix' => 'php',
// 模板路径
'view_path' => app_path('view'),
// 视图输出字符串内容替换
'tpl_replace_string' => [
'{__PUBLIC_PATH}' => '/', //public 目录
'{__STATIC_PATH}' => '/static/', //全局静态目录
'{__PLUG_PATH}' => '/static/plug/', //全局静态插件
'{__ADMIN_PATH}' => '/system/', //后台目录
'{__FRAME_PATH}' => '/system/frame/', //后台框架
'{__MODULE_PATH}' => '/system/module/', //后台模块
]
];
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板后缀
'view_suffix' => 'php',
// 模板路径
'view_path' => app_path('view'),
// 视图输出字符串内容替换
'tpl_replace_string' => [
'{__PUBLIC_PATH}' => '/', //public 目录
'{__STATIC_PATH}' => '/static/', //全局静态目录
'{__PLUG_PATH}' => '/static/plug/', //全局静态插件
'{__ADMIN_PATH}' => '/system/', //后台目录
'{__FRAME_PATH}' => '/system/frame/', //后台框架
'{__MODULE_PATH}' => '/system/module/', //后台模块
]
];
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2018/01/10
*/
namespace app\admin\controller;
use think\exception\Handle;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 后台异常处理
*
* Class AdminException
* @package app\admin\controller
*/
class AdminException extends Handle
{
public function render($request, Throwable $e): Response
{
// 参数验证错误
if ($e instanceof ValidateException) {
return app('json')->make(422, $e->getError());
}
if ($e instanceof \Exception && request()->isAjax()) {
return app('json')->fail($e->getMessage(), ['code' => $e->getCode(), 'line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
}
return parent::render($request, $e);
}
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2018/01/10
*/
namespace app\admin\controller;
use think\exception\Handle;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 后台异常处理
*
* Class AdminException
* @package app\admin\controller
*/
class AdminException extends Handle
{
public function render($request, Throwable $e): Response
{
// 参数验证错误
if ($e instanceof ValidateException) {
return app('json')->make(422, $e->getError());
}
if ($e instanceof \Exception && request()->isAjax()) {
return app('json')->fail($e->getMessage(), ['code' => $e->getCode(), 'line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
}
return parent::render($request, $e);
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use app\admin\model\system\SystemAdmin;
use app\admin\model\system\SystemMenus;
use app\admin\model\system\SystemRole;
use think\facade\Route as Url;
/**
* 基类 所有控制器继承的类
* Class AuthController
* @package app\admin\controller
*/
class AuthController extends SystemBasic
{
/**
* 当前登陆管理员信息
* @var
*/
protected $adminInfo;
/**
* 当前登陆管理员ID
* @var
*/
protected $adminId;
/**
* 当前管理员权限
* @var array
*/
protected $auth = [];
protected $skipLogController = ['index', 'common'];
protected function initialize()
{
parent::initialize();
if (!SystemAdmin::hasActiveAdmin()) return $this->redirect(Url::buildUrl('login/index')->suffix(false)->build());
try {
$adminInfo = SystemAdmin::activeAdminInfoOrFail();
} catch (\Exception $e) {
return $this->failed(SystemAdmin::getErrorInfo($e->getMessage()), Url::buildUrl('login/index')->suffix(false)->build());
}
$this->adminInfo = $adminInfo;
$this->adminId = $adminInfo['id'];
$this->getActiveAdminInfo();
$this->auth = SystemAdmin::activeAdminAuthOrFail();
$this->adminInfo->level === 0 || $this->checkAuth();
$this->assign('_admin', $this->adminInfo);
$type = 'system';
event('AdminVisit', [$this->adminInfo, $type]);
}
protected function checkAuth($action = null, $controller = null, $module = null, array $route = [])
{
static $allAuth = null;
if ($allAuth === null) $allAuth = SystemRole::getAllAuth();
if ($module === null) $module = app('http')->getName();
if ($controller === null) $controller = $this->request->controller();
if ($action === null) $action = $this->request->action();
if (!count($route)) $route = $this->request->route();
if (in_array(strtolower($controller), $this->skipLogController, true)) return true;
$nowAuthName = SystemMenus::getAuthName($action, $controller, $module, $route);
$baseNowAuthName = SystemMenus::getAuthName($action, $controller, $module, []);
if ((in_array($nowAuthName, $allAuth) && !in_array($nowAuthName, $this->auth)) || (in_array($baseNowAuthName, $allAuth) && !in_array($baseNowAuthName, $this->auth)))
exit($this->failed('没有权限访问!'));
return true;
}
/**
* 获得当前用户最新信息
* @return SystemAdmin
*/
protected function getActiveAdminInfo()
{
$adminId = $this->adminId;
$adminInfo = SystemAdmin::getValidAdminInfoOrFail($adminId);
if (!$adminInfo) $this->failed(SystemAdmin::getErrorInfo('请登陆!'));
$this->adminInfo = $adminInfo;
SystemAdmin::setLoginInfo($adminInfo);
return $adminInfo;
}
<?php
namespace app\admin\controller;
use app\admin\model\system\SystemAdmin;
use app\admin\model\system\SystemMenus;
use app\admin\model\system\SystemRole;
use think\facade\Route as Url;
/**
* 基类 所有控制器继承的类
* Class AuthController
* @package app\admin\controller
*/
class AuthController extends SystemBasic
{
/**
* 当前登陆管理员信息
* @var
*/
protected $adminInfo;
/**
* 当前登陆管理员ID
* @var
*/
protected $adminId;
/**
* 当前管理员权限
* @var array
*/
protected $auth = [];
protected $skipLogController = ['index', 'common'];
protected function initialize()
{
parent::initialize();
if (!SystemAdmin::hasActiveAdmin()) return $this->redirect(Url::buildUrl('login/index')->suffix(false)->build());
try {
$adminInfo = SystemAdmin::activeAdminInfoOrFail();
} catch (\Exception $e) {
return $this->failed(SystemAdmin::getErrorInfo($e->getMessage()), Url::buildUrl('login/index')->suffix(false)->build());
}
$this->adminInfo = $adminInfo;
$this->adminId = $adminInfo['id'];
$this->getActiveAdminInfo();
$this->auth = SystemAdmin::activeAdminAuthOrFail();
$this->adminInfo->level === 0 || $this->checkAuth();
$this->assign('_admin', $this->adminInfo);
$type = 'system';
event('AdminVisit', [$this->adminInfo, $type]);
}
protected function checkAuth($action = null, $controller = null, $module = null, array $route = [])
{
static $allAuth = null;
if ($allAuth === null) $allAuth = SystemRole::getAllAuth();
if ($module === null) $module = app('http')->getName();
if ($controller === null) $controller = $this->request->controller();
if ($action === null) $action = $this->request->action();
if (!count($route)) $route = $this->request->route();
array_shift($route);
if (in_array(strtolower($controller), $this->skipLogController, true)) return true;
$nowAuthName = SystemMenus::getAuthName($action, $controller, $module, $route);
$baseNowAuthName = SystemMenus::getAuthName($action, $controller, $module, []);
//积分设置的父类 不是系统设置 但是 $baseNowAuthName 确实验证得 系统设置权限
if ((in_array($nowAuthName, $allAuth) && !in_array($nowAuthName, $this->auth)) || (in_array($baseNowAuthName, $allAuth) && ($nowAuthName != 'admin/setting.systemconfig/index/type/3/tab_id/11' && !in_array($baseNowAuthName, $this->auth))))
exit($this->failed('没有权限访问!'));
return true;
}
/**
* 获得当前用户最新信息
* @return SystemAdmin
*/
protected function getActiveAdminInfo()
{
$adminId = $this->adminId;
$adminInfo = SystemAdmin::getValidAdminInfoOrFail($adminId);
if (!$adminInfo) $this->failed(SystemAdmin::getErrorInfo('请登陆!'));
$this->adminInfo = $adminInfo;
SystemAdmin::setLoginInfo($adminInfo);
return $adminInfo;
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace app\admin\controller;
use app\admin\model\system\SystemAdmin;
use crmeb\services\UtilService;
use think\facade\Session;
use think\facade\Route as Url;
/**
* 登录验证控制器
* Class Login
* @package app\admin\controller
*/
class Login extends SystemBasic
{
public function index()
{
return $this->fetch();
}
/**
* 登录验证 + 验证码验证
*/
public function verify()
{
if (!request()->isPost()) return $this->failed('请登陆!');
list($account, $pwd, $verify) = UtilService::postMore([
'account', 'pwd', 'verify'
], null, true);
//检验验证码
if (!captcha_check($verify)) return $this->failed('验证码错误,请重新输入');
$error = Session::get('login_error') ?: ['num' => 0, 'time' => time()];
$error['num'] = 0;
if ($error['num'] >= 5 && $error['time'] > strtotime('- 5 minutes'))
return $this->failed('错误次数过多,请稍候再试!');
//检验帐号密码
$res = SystemAdmin::login($account, $pwd);
if ($res) {
Session::set('login_error', null);
Session::save();
return $this->successful(['url' => Url::buildUrl('Index/index')->build()]);
} else {
$error['num'] += 1;
$error['time'] = time();
Session::set('login_error', $error);
Session::save();
return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
}
}
public function captcha()
{
ob_clean();
return captcha();
}
/**
* 退出登陆
*/
public function logout()
{
SystemAdmin::clearLoginInfo();
$this->redirect(Url::buildUrl('index')->build());
}
<?php
namespace app\admin\controller;
use app\admin\model\system\SystemAdmin;
use crmeb\services\UtilService;
use think\facade\Session;
use think\facade\Route as Url;
/**
* 登录验证控制器
* Class Login
* @package app\admin\controller
*/
class Login extends SystemBasic
{
public function index()
{
return $this->fetch();
}
/**
* 登录验证 + 验证码验证
*/
public function verify()
{
if (!request()->isPost()) return $this->failed('请登陆!');
list($account, $pwd, $verify) = UtilService::postMore([
'account', 'pwd', 'verify'
], null, true);
//检验验证码
if (!captcha_check($verify)) return $this->failed('验证码错误,请重新输入');
$error = Session::get('login_error') ?: ['num' => 0, 'time' => time()];
$error['num'] = 0;
if ($error['num'] >= 5 && $error['time'] > strtotime('- 5 minutes'))
return $this->failed('错误次数过多,请稍候再试!');
//检验帐号密码
$res = SystemAdmin::login($account, $pwd);
if ($res) {
Session::set('login_error', null);
Session::save();
return $this->successful(['url' => Url::buildUrl('Index/index')->build()]);
} else {
$error['num'] += 1;
$error['time'] = time();
Session::set('login_error', $error);
Session::save();
return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
}
}
public function captcha()
{
ob_clean();
return captcha();
}
/**
* 退出登陆
*/
public function logout()
{
SystemAdmin::clearLoginInfo();
$this->redirect(Url::buildUrl('index')->build());
}
}
\ No newline at end of file
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2017/10/09
*/
namespace app\admin\controller;
use crmeb\services\JsonService;
use crmeb\basic\BaseController;
class SystemBasic extends BaseController
{
/**
* 操作失败提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $duration 持续时间
* @return mixed
*/
protected function failedNotice($msg = '操作失败', $backUrl = 0, $info = '', $duration = 3)
{
$type = 'error';
$this->assign(compact('msg', 'backUrl', 'info', 'duration', 'type'));
return $this->fetch('public/notice');
}
/**
* 失败提示一直持续
* @param $msg
* @param int $backUrl
* @param string $title
* @return mixed
*/
protected function failedNoticeLast($msg = '操作失败', $backUrl = 0, $info = '')
{
return $this->failedNotice($msg, $backUrl, $info, 0);
}
/**
* 操作成功提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $duration 持续时间
* @return mixed
*/
protected function successfulNotice($msg = '操作成功', $backUrl = 0, $info = '', $duration = 3)
{
$type = 'success';
$this->assign(compact('msg', 'backUrl', 'info', 'duration', 'type'));
return $this->fetch('public/notice');
}
/**
* 成功提示一直持续
* @param $msg
* @param int $backUrl
* @param string $title
* @return mixed
*/
protected function successfulNoticeLast($msg = '操作成功', $backUrl = 0, $info = '')
{
return $this->successfulNotice($msg, $backUrl, $info, 0);
}
/**
* 错误提醒页面
* @param string $msg
* @param int $url
*/
protected function failed($msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
{
if ($this->request->isAjax()) {
exit(JsonService::fail($msg, $url)->getContent());
} else {
$this->assign(compact('msg', 'url'));
exit($this->fetch('public/error'));
}
}
/**
* 成功提醒页面
* @param string $msg
* @param int $url
*/
protected function successful($msg, $url = 0)
{
if ($this->request->isAjax()) {
exit(JsonService::successful($msg, $url)->getContent());
} else {
$this->assign(compact('msg', 'url'));
exit($this->fetch('public/success'));
}
}
/**异常抛出
* @param $name
*/
protected function exception($msg = '无法打开页面')
{
$this->assign(compact('msg'));
exit($this->fetch('public/exception'));
}
/**找不到页面
* @param $name
*/
public function _empty($name)
{
exit($this->fetch('public/404'));
}
}
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2017/10/09
*/
namespace app\admin\controller;
use crmeb\services\JsonService;
use crmeb\basic\BaseController;
class SystemBasic extends BaseController
{
/**
* 操作失败提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $duration 持续时间
* @return mixed
*/
protected function failedNotice($msg = '操作失败', $backUrl = 0, $info = '', $duration = 3)
{
$type = 'error';
$this->assign(compact('msg', 'backUrl', 'info', 'duration', 'type'));
return $this->fetch('public/notice');
}
/**
* 失败提示一直持续
* @param $msg
* @param int $backUrl
* @param string $title
* @return mixed
*/
protected function failedNoticeLast($msg = '操作失败', $backUrl = 0, $info = '')
{
return $this->failedNotice($msg, $backUrl, $info, 0);
}
/**
* 操作成功提示框
* @param string $msg 提示信息
* @param string $backUrl 跳转地址
* @param string $title 标题
* @param int $duration 持续时间
* @return mixed
*/
protected function successfulNotice($msg = '操作成功', $backUrl = 0, $info = '', $duration = 3)
{
$type = 'success';
$this->assign(compact('msg', 'backUrl', 'info', 'duration', 'type'));
return $this->fetch('public/notice');
}
/**
* 成功提示一直持续
* @param $msg
* @param int $backUrl
* @param string $title
* @return mixed
*/
protected function successfulNoticeLast($msg = '操作成功', $backUrl = 0, $info = '')
{
return $this->successfulNotice($msg, $backUrl, $info, 0);
}
/**
* 错误提醒页面
* @param string $msg
* @param int $url
*/
protected function failed($msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
{
if ($this->request->isAjax()) {
exit(JsonService::fail($msg, $url)->getContent());
} else {
$this->assign(compact('msg', 'url'));
exit($this->fetch('public/error'));
}
}
/**
* 成功提醒页面
* @param string $msg
* @param int $url
*/
protected function successful($msg, $url = 0)
{
if ($this->request->isAjax()) {
exit(JsonService::successful($msg, $url)->getContent());
} else {
$this->assign(compact('msg', 'url'));
exit($this->fetch('public/success'));
}
}
/**异常抛出
* @param $name
*/
protected function exception($msg = '无法打开页面')
{
$this->assign(compact('msg'));
exit($this->fetch('public/exception'));
}
/**找不到页面
* @param $name
*/
public function _empty($name)
{
exit($this->fetch('public/404'));
}
}
<?php
namespace app\admin\controller;
use app\admin\model\system\SystemCity;
use crmeb\services\ExpressService;
use crmeb\services\HttpService;
use crmeb\services\JsonService;
use crmeb\utils\Queue;
use think\facade\Db;
use think\facade\Queue as QueueJob;
class Test
{
public function index($page = 1, $limit = 50, $level = 0)
{
// var_dump(is_file('uploads/981_1_user.jpg'));
// $appCode = '4a5b910fc344434cacb2edd36e0e56aa';
// $list = ExpressService::query('75341495702624');
// dump($list);
// $data = [];
// foreach ($list['data'] as $item) {
// $data[] = [
// 'level' => $item['level'],
// 'parent_id' => $item['parent_id'],
// 'area_code' => $item['area_code'],
// 'name' => $item['name'],
// 'merger_name' => $item['merger_name'],
// 'lng' => $item['lng'],
// 'lat' => $item['lat'],
// 'city_id' => $item['id'],
// ];
// }
// $res = SystemCity::insertAll($data);
// return JsonService::successful(['count' => $res]);
$sql = Db::name('system_menus')->whereIn('paid', function ($query) {
$query->name('system_menus')->where('menu_name', '评论管理')->find();
})->fetchSql(true)->delete();
var_dump($sql);
}
<?php
namespace app\admin\controller;
use crmeb\utils\Redis;
class Test
{
public function index()
{
$redis = Redis::instance();
var_dump($redis->get(['CRMEB','TESD']));
}
public function test()
{
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace app\admin\controller\article;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use crmeb\services\{
UtilService as Util, JsonService as Json
};
use app\admin\model\article\{
ArticleCategory as ArticleCategoryModel, Article as ArticleModel
};
/**
* 图文管理
* Class WechatNews
* @package app\admin\controller\wechat
*/
class Article extends AuthController
{
/**
* TODO 显示后台管理员添加的图文
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
$where = Util::getMore([
['title', ''],
['cid', $this->request->param('pid', '')],
], $this->request);
$this->assign('where', $where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList());
$this->assign(compact('tree'));
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* TODO 文件添加和修改
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function create()
{
$id = $this->request->param('id');
$cid = $this->request->param('cid');
$news = [];
$all = [];
$news['id'] = '';
$news['image_input'] = '';
$news['title'] = '';
$news['author'] = '';
$news['is_banner'] = '';
$news['is_hot'] = '';
$news['content'] = '';
$news['synopsis'] = '';
$news['url'] = '';
$news['cid'] = [];
$select = 0;
if ($id) {
$news = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
if (!$news) return $this->failed('数据不存在!');
$news['cid'] = explode(',', $news['cid']);
$news['content'] = htmlspecialchars_decode($news['content']);
}
if ($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0, 'id'))) {
$all = ArticleCategoryModel::getArticleCategoryInfo($cid);
$select = 1;
}
if (!$select) {
$list = ArticleCategoryModel::getTierList();
foreach ($list as $menu) {
$all[$menu['id']] = $menu['html'] . $menu['title'];
}
}
$this->assign('all', $all);
$this->assign('news', $news);
$this->assign('cid', $cid);
$this->assign('select', $select);
return $this->fetch();
}
/**
* 上传图文图片
* @return \think\response\Json
*/
public function upload_image()
{
$res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']);
if (!is_array($res)) return Json::fail($res);
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('上传成功!', ['url' => $res['dir']]);
}
/**
* 添加和修改图文
*/
public function add_new()
{
$data = Util::postMore([
['id', 0],
['cid', []],
'title',
'author',
'image_input',
'content',
'synopsis',
'share_title',
'share_synopsis',
['visit', 0],
['sort', 0],
'url',
['is_banner', 0],
['is_hot', 0],
['status', 1],]);
$data['cid'] = implode(',', $data['cid']);
$content = $data['content'];
unset($data['content']);
if ($data['id']) {
$id = $data['id'];
unset($data['id']);
$res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::edit($data, $id, 'id');
$res2 = ArticleModel::setContent($id, $content);
if ($res1 && $res2) {
$res = true;
}
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('修改图文成功!', $id);
else
return Json::fail('修改图文失败,您并没有修改什么!', $id);
} else {
$data['add_time'] = time();
$data['admin_id'] = $this->adminId;
$res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::create($data);
$res2 = false;
if ($res1)
$res2 = ArticleModel::setContent($res1->id, $content);
if ($res1 && $res2) {
$res = true;
}
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('添加图文成功!', $res1->id);
else
return Json::successful('添加图文失败!', $res1->id);
}
}
/**
* 删除图文
* @param $id
* @return \think\response\Json
*/
public function delete($id)
{
$res = ArticleModel::del($id);
if (!$res)
return Json::fail('删除失败,请稍候再试!');
else
return Json::successful('删除成功!');
}
public function merchantIndex()
{
$where = Util::getMore([
['title', '']
], $this->request);
$this->assign('where', $where);
$where['cid'] = input('cid');
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* 关联文章 id
* @param int $id
*/
public function relation($id = 0)
{
$this->assign('id', $id);
return $this->fetch();
}
/**
* 保存选择的产品
* @param int $id
*/
public function edit_article($id = 0)
{
if (!$id) return Json::fail('缺少参数');
list($product_id) = Util::postMore([
['product_id', 0]
], $this->request, true);
if (ArticleModel::edit(['product_id' => $product_id], ['id' => $id]))
return Json::successful('保存成功');
else
return Json::fail('保存失败');
}
/**
* 取消绑定的产品id
* @param int $id
*/
public function unrelation($id = 0)
{
if (!$id) return Json::fail('缺少参数');
if (ArticleModel::edit(['product_id' => 0], $id))
return Json::successful('取消关联成功!');
else
return Json::fail('取消失败');
}
<?php
namespace app\admin\controller\article;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use crmeb\services\{
UtilService as Util, JsonService as Json
};
use app\admin\model\article\{
ArticleCategory as ArticleCategoryModel, Article as ArticleModel
};
/**
* 图文管理
* Class WechatNews
* @package app\admin\controller\wechat
*/
class Article extends AuthController
{
/**
* TODO 显示后台管理员添加的图文
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
$where = Util::getMore([
['title', ''],
['cid', $this->request->param('pid', '')],
], $this->request);
$this->assign('where', $where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList());
$this->assign(compact('tree'));
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* TODO 文件添加和修改
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function create()
{
$id = $this->request->param('id');
$cid = $this->request->param('cid');
$news = [];
$all = [];
$news['id'] = '';
$news['image_input'] = '';
$news['title'] = '';
$news['author'] = '';
$news['is_banner'] = '';
$news['is_hot'] = '';
$news['content'] = '';
$news['synopsis'] = '';
$news['url'] = '';
$news['cid'] = [];
$select = 0;
if ($id) {
$news = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
if (!$news) return $this->failed('数据不存在!');
$news['cid'] = explode(',', $news['cid']);
$news['content'] = htmlspecialchars_decode($news['content']);
}
if ($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0, 'id'))) {
$all = ArticleCategoryModel::getArticleCategoryInfo($cid);
$select = 1;
}
if (!$select) {
$list = ArticleCategoryModel::getTierList();
foreach ($list as $menu) {
$all[$menu['id']] = $menu['html'] . $menu['title'];
}
}
$this->assign('all', $all);
$this->assign('news', $news);
$this->assign('cid', $cid);
$this->assign('select', $select);
return $this->fetch();
}
/**
* 上传图文图片
* @return \think\response\Json
*/
public function upload_image()
{
$res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']);
if (!is_array($res)) return Json::fail($res);
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('上传成功!', ['url' => $res['dir']]);
}
/**
* 添加和修改图文
*/
public function add_new()
{
$data = Util::postMore([
['id', 0],
['cid', []],
'title',
'author',
'image_input',
'content',
'synopsis',
'share_title',
'share_synopsis',
['visit', 0],
['sort', 0],
'url',
['is_banner', 0],
['is_hot', 0],
['status', 1],]);
$data['cid'] = implode(',', $data['cid']);
$content = $data['content'];
unset($data['content']);
if ($data['id']) {
$id = $data['id'];
unset($data['id']);
$res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::edit($data, $id, 'id');
$res2 = ArticleModel::setContent($id, $content);
if ($res1 && $res2) {
$res = true;
}
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('修改图文成功!', $id);
else
return Json::fail('修改图文失败,您并没有修改什么!', $id);
} else {
$data['add_time'] = time();
$data['admin_id'] = $this->adminId;
$res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::create($data);
$res2 = false;
if ($res1)
$res2 = ArticleModel::setContent($res1->id, $content);
if ($res1 && $res2) {
$res = true;
}
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('添加图文成功!', $res1->id);
else
return Json::successful('添加图文失败!', $res1->id);
}
}
/**
* 删除图文
* @param $id
* @return \think\response\Json
*/
public function delete($id)
{
$res = ArticleModel::del($id);
if (!$res)
return Json::fail('删除失败,请稍候再试!');
else
return Json::successful('删除成功!');
}
public function merchantIndex()
{
$where = Util::getMore([
['title', '']
], $this->request);
$this->assign('where', $where);
$where['cid'] = input('cid');
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* 关联文章 id
* @param int $id
*/
public function relation($id = 0)
{
$this->assign('id', $id);
return $this->fetch();
}
/**
* 保存选择的产品
* @param int $id
*/
public function edit_article($id = 0)
{
if (!$id) return Json::fail('缺少参数');
list($product_id) = Util::postMore([
['product_id', 0]
], $this->request, true);
if (ArticleModel::edit(['product_id' => $product_id], ['id' => $id]))
return Json::successful('保存成功');
else
return Json::fail('保存失败');
}
/**
* 取消绑定的产品id
* @param int $id
*/
public function unrelation($id = 0)
{
if (!$id) return Json::fail('缺少参数');
if (ArticleModel::edit(['product_id' => 0], $id))
return Json::successful('取消关联成功!');
else
return Json::fail('取消失败');
}
}
\ No newline at end of file
<?php
namespace app\admin\controller\article;
use think\facade\Route as Url;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use app\admin\model\article\{ArticleCategory as ArticleCategoryModel,Article as ArticleModel};
use crmeb\services\{FormBuilder as Form,UtilService as Util,JsonService as Json};
/**
* 文章分类管理 控制器
* */
class ArticleCategory extends AuthController
{
/**
* 分类管理
* */
public function index()
{
$where = Util::getMore([
['status', ''],
['title', ''],
], $this->request);
$this->assign('where', $where);
$this->assign(ArticleCategoryModel::systemPage($where));
return $this->fetch();
}
/**
* 添加分类管理
* */
public function create()
{
$f = array();
$f[] = Form::select('pid', '父级id')->setOptions(function () {
$list = ArticleCategoryModel::getTierList();
$menus[] = ['value' => 0, 'label' => '顶级分类'];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
}
return $menus;
})->filterable(1);
$f[] = Form::input('title', '分类名称');
$f[] = Form::input('intr', '分类简介')->type('textarea');
$f[] = Form::frameImageOne('image', '分类图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
$f[] = Form::number('sort', '排序', 0);
$f[] = Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
$form = Form::make_post_form('添加分类', $f, Url::buildUrl('save'));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* s上传图片
* */
public function upload()
{
$res = Upload::instance()->setUploadPath('article')->image('file');
if (!is_array($res)) return Json::fail($res);
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('图片上传成功!', ['name' => $res['name'], 'url' => path_to_url($res['thumb_path'])]);
}
/**
* 保存分类管理
* */
public function save()
{
$data = Util::postMore([
'title',
'pid',
'intr',
['new_id', []],
['image', []],
['sort', 0],
'status',]);
if (!$data['title']) return Json::fail('请输入分类名称');
if (count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
if ($data['sort'] < 0) return Json::fail('排序不能是负数');
$data['add_time'] = time();
$data['image'] = $data['image'][0];
$new_id = $data['new_id'];
unset($data['new_id']);
$res = ArticleCategoryModel::create($data);
if (!ArticleModel::saveBatchCid($res['id'], implode(',', $new_id))) return Json::fail('文章列表添加失败');
return Json::successful('添加分类成功!');
}
/**
* 修改分类
* */
public function edit($id)
{
if (!$id) return $this->failed('参数错误');
$article = ArticleCategoryModel::get($id)->getData();
if (!$article) return Json::fail('数据不存在!');
$f = array();
$f[] = Form::select('pid', '父级id', (string)$article['pid'])->setOptions(function () {
$list = ArticleCategoryModel::getTierList();
$menus[] = ['value' => 0, 'label' => '顶级分类'];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
}
return $menus;
})->filterable(1);
$f[] = Form::input('title', '分类名称', $article['title']);
$f[] = Form::input('intr', '分类简介', $article['intr'])->type('textarea');
$f[] = Form::frameImageOne('image', '分类图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $article['image'])->icon('image')->width('100%')->height('500px');
$f[] = Form::number('sort', '排序', $article['sort']);
$f[] = Form::radio('status', '状态', $article['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
$form = Form::make_post_form('编辑分类', $f, Url::buildUrl('update', array('id' => $id)));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
public function update($id)
{
$data = Util::postMore([
'pid',
'title',
'intr',
// ['new_id',[]],
['image', []],
['sort', 0],
'status',]);
if (!$data['title']) return Json::fail('请输入分类名称');
if (count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
if ($data['sort'] < 0) return Json::fail('排序不能是负数');
$data['image'] = $data['image'][0];
if (!ArticleCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
// if(!ArticleModel::saveBatchCid($id,implode(',',$data['new_id']))) return Json::fail('文章列表添加失败');
// unset($data['new_id']);
ArticleCategoryModel::edit($data, $id);
return Json::successful('修改成功!');
}
/**
* 删除分类
* */
public function delete($id)
{
$res = ArticleCategoryModel::delArticleCategory($id);
if (!$res)
return Json::fail(ArticleCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
else
return Json::successful('删除成功!');
}
}
<?php
namespace app\admin\controller\article;
use think\facade\Route as Url;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use app\admin\model\article\{ArticleCategory as ArticleCategoryModel,Article as ArticleModel};
use crmeb\services\{FormBuilder as Form,UtilService as Util,JsonService as Json};
/**
* 文章分类管理 控制器
* */
class ArticleCategory extends AuthController
{
/**
* 分类管理
* */
public function index()
{
$where = Util::getMore([
['status', ''],
['title', ''],
], $this->request);
$this->assign('where', $where);
$this->assign(ArticleCategoryModel::systemPage($where));
return $this->fetch();
}
/**
* 添加分类管理
* */
public function create()
{
$f = array();
$f[] = Form::select('pid', '父级id')->setOptions(function () {
$list = ArticleCategoryModel::getTierList();
$menus[] = ['value' => 0, 'label' => '顶级分类'];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
}
return $menus;
})->filterable(1);
$f[] = Form::input('title', '分类名称');
$f[] = Form::input('intr', '分类简介')->type('textarea');
$f[] = Form::frameImageOne('image', '分类图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
$f[] = Form::number('sort', '排序', 0);
$f[] = Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
$form = Form::make_post_form('添加分类', $f, Url::buildUrl('save'));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* s上传图片
* */
public function upload()
{
$res = Upload::instance()->setUploadPath('article')->image('file');
if (!is_array($res)) return Json::fail($res);
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('图片上传成功!', ['name' => $res['name'], 'url' => path_to_url($res['thumb_path'])]);
}
/**
* 保存分类管理
* */
public function save()
{
$data = Util::postMore([
'title',
'pid',
'intr',
['new_id', []],
['image', []],
['sort', 0],
'status',]);
if (!$data['title']) return Json::fail('请输入分类名称');
if (count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
if ($data['sort'] < 0) return Json::fail('排序不能是负数');
$data['add_time'] = time();
$data['image'] = $data['image'][0];
$new_id = $data['new_id'];
unset($data['new_id']);
$res = ArticleCategoryModel::create($data);
if (!ArticleModel::saveBatchCid($res['id'], implode(',', $new_id))) return Json::fail('文章列表添加失败');
return Json::successful('添加分类成功!');
}
/**
* 修改分类
* */
public function edit($id)
{
if (!$id) return $this->failed('参数错误');
$article = ArticleCategoryModel::get($id)->getData();
if (!$article) return Json::fail('数据不存在!');
$f = array();
$f[] = Form::select('pid', '父级id', (string)$article['pid'])->setOptions(function () {
$list = ArticleCategoryModel::getTierList();
$menus[] = ['value' => 0, 'label' => '顶级分类'];
foreach ($list as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
}
return $menus;
})->filterable(1);
$f[] = Form::input('title', '分类名称', $article['title']);
$f[] = Form::input('intr', '分类简介', $article['intr'])->type('textarea');
$f[] = Form::frameImageOne('image', '分类图片', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $article['image'])->icon('image')->width('100%')->height('500px');
$f[] = Form::number('sort', '排序', $article['sort']);
$f[] = Form::radio('status', '状态', $article['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
$form = Form::make_post_form('编辑分类', $f, Url::buildUrl('update', array('id' => $id)));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
public function update($id)
{
$data = Util::postMore([
'pid',
'title',
'intr',
// ['new_id',[]],
['image', []],
['sort', 0],
'status',]);
if (!$data['title']) return Json::fail('请输入分类名称');
if (count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
if ($data['sort'] < 0) return Json::fail('排序不能是负数');
$data['image'] = $data['image'][0];
if (!ArticleCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
// if(!ArticleModel::saveBatchCid($id,implode(',',$data['new_id']))) return Json::fail('文章列表添加失败');
// unset($data['new_id']);
ArticleCategoryModel::edit($data, $id);
return Json::successful('修改成功!');
}
/**
* 删除分类
* */
public function delete($id)
{
$res = ArticleCategoryModel::delArticleCategory($id);
if (!$res)
return Json::fail(ArticleCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
else
return Json::successful('删除成功!');
}
}
<?php
namespace app\admin\controller\article;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use app\admin\model\wechat\WechatNews as WechatNewsModel;
use crmeb\services\{
UtilService as Util, JsonService as Json
};
use app\admin\model\article\{
Article as ArticleModel, ArticleCategory as ArticleCategoryModel
};
use crmeb\services\upload\Upload;
/**
* 图文管理
* Class WechatNews
* @package app\admin\controller\wechat
*/
class WechatNews extends AuthController
{
/**
* 显示后台管理员添加的图文
* @return mixed
*/
public function index($cid = 0)
{
$where = Util::getMore([
['title', '']
], $this->request);
if ($cid)
$where['cid'] = $cid;
else
$where['cid'] = '';
$this->assign('where', $where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign('cid', $cid);
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* 展示页面 添加和删除
* @return mixed
*/
public function create()
{
$id = input('id');
$cid = input('cid');
$news = array();
$news['id'] = '';
$news['image_input'] = '';
$news['title'] = '';
$news['author'] = '';
$news['content'] = '';
$news['synopsis'] = '';
$news['url'] = '';
$news['cid'] = array();
if ($id) {
$news = WechatNewsModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('wechat_news_content c', 'c.nid=n.id')->find();
if (!$news) return $this->failedNotice('数据不存在!');
$news['cid'] = explode(',', $news['cid']);
}
$all = array();
$select = 0;
if (!$cid)
$cid = '';
else {
if ($id) {
$all = ArticleCategoryModel::where('id', $cid)->where('hidden', '<>', 0)->column('title', 'id');
$select = 1;
} else {
$all = ArticleCategoryModel::where('id', $cid)->column('title', 'id');
$select = 1;
}
}
if (empty($all)) {
$all = ArticleCategoryModel::getField();//新闻分类
$select = 0;
}
$this->assign('all', $all);
$this->assign('news', $news);
$this->assign('cid', $cid);
$this->assign('select', $select);
return $this->fetch();
}
/**
* 上传图文图片
* @return \think\response\Json
*/
public function upload_image()
{
$uploadType = (int)sys_config('upload_type', 1);
$upload = new Upload($uploadType, [
'accessKey' => sys_config('accessKey'),
'secretKey' => sys_config('secretKey'),
'uploadUrl' => sys_config('uploadUrl'),
'storageName' => sys_config('storage_name'),
'storageRegion' => sys_config('storage_region'),
]);
$resInfo = $upload->to('wechat/image/' . date('Ymd'))->validate()->move($this->request->post('file'));
if ($resInfo === false) {
return Json::fail($upload->getError());
}
$res = $upload->getUploadInfo();
$res['image_type'] = $uploadType;
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('上传成功!', ['url' => $res['thumb_path']]);
}
/**
* 添加和修改图文
*/
public function add_new()
{
$data = Util::postMore([
['id', 0],
['cid', []],
'title',
'author',
'image_input',
'content',
'synopsis',
'share_title',
'share_synopsis',
['visit', 0],
['sort', 0],
'url',
['status', 1],]);
$data['cid'] = implode(',', $data['cid']);
$content = $data['content'];
unset($data['content']);
if ($data['id']) {
$id = $data['id'];
unset($data['id']);
ArticleModel::beginTrans();
$res1 = ArticleModel::edit($data, $id, 'id');
$res2 = ArticleModel::setContent($id, $content);
if ($res1 && $res2)
$res = true;
else
$res = false;
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('修改图文成功!', $id);
else
return Json::fail('修改图文失败!', $id);
} else {
$data['add_time'] = time();
$data['admin_id'] = $this->adminId;
ArticleModel::beginTrans();
$res1 = ArticleModel::create($data);
$res2 = false;
if ($res1)
$res2 = ArticleModel::setContent($res1->id, $content);
if ($res1 && $res2)
$res = true;
else
$res = false;
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('添加图文成功!', $res1->id);
else
return Json::successful('添加图文失败!', $res1->id);
}
}
/**
* 删除图文
* @param $id
* @return \think\response\Json
*/
public function delete($id)
{
$res = ArticleModel::del($id);
if (!$res)
return Json::fail('删除失败,请稍候再试!');
else
return Json::successful('删除成功!');
}
public function merchantIndex()
{
$where = Util::getMore([
['title', '']
], $this->request);
$this->assign('where', $where);
$where['cid'] = input('cid');
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
<?php
namespace app\admin\controller\article;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use app\admin\model\wechat\WechatNews as WechatNewsModel;
use crmeb\services\{
UtilService as Util, JsonService as Json
};
use app\admin\model\article\{
Article as ArticleModel, ArticleCategory as ArticleCategoryModel
};
use crmeb\services\upload\Upload;
/**
* 图文管理
* Class WechatNews
* @package app\admin\controller\wechat
*/
class WechatNews extends AuthController
{
/**
* 显示后台管理员添加的图文
* @return mixed
*/
public function index($cid = 0)
{
$where = Util::getMore([
['title', '']
], $this->request);
if ($cid)
$where['cid'] = $cid;
else
$where['cid'] = '';
$this->assign('where', $where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign('cid', $cid);
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
* 展示页面 添加和删除
* @return mixed
*/
public function create()
{
$id = input('id');
$cid = input('cid');
$news = array();
$news['id'] = '';
$news['image_input'] = '';
$news['title'] = '';
$news['author'] = '';
$news['content'] = '';
$news['synopsis'] = '';
$news['url'] = '';
$news['cid'] = array();
if ($id) {
$news = WechatNewsModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('wechat_news_content c', 'c.nid=n.id')->find();
if (!$news) return $this->failedNotice('数据不存在!');
$news['cid'] = explode(',', $news['cid']);
}
$all = array();
$select = 0;
if (!$cid)
$cid = '';
else {
if ($id) {
$all = ArticleCategoryModel::where('id', $cid)->where('hidden', '<>', 0)->column('title', 'id');
$select = 1;
} else {
$all = ArticleCategoryModel::where('id', $cid)->column('title', 'id');
$select = 1;
}
}
if (empty($all)) {
$all = ArticleCategoryModel::getField();//新闻分类
$select = 0;
}
$this->assign('all', $all);
$this->assign('news', $news);
$this->assign('cid', $cid);
$this->assign('select', $select);
return $this->fetch();
}
/**
* 上传图文图片
* @return \think\response\Json
*/
public function upload_image()
{
$uploadType = (int)sys_config('upload_type', 1);
$upload = new Upload($uploadType, [
'accessKey' => sys_config('accessKey'),
'secretKey' => sys_config('secretKey'),
'uploadUrl' => sys_config('uploadUrl'),
'storageName' => sys_config('storage_name'),
'storageRegion' => sys_config('storage_region'),
]);
$resInfo = $upload->to('wechat/image/' . date('Ymd'))->validate()->move($this->request->post('file'));
if ($resInfo === false) {
return Json::fail($upload->getError());
}
$res = $upload->getUploadInfo();
$res['image_type'] = $uploadType;
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
return Json::successful('上传成功!', ['url' => $res['thumb_path']]);
}
/**
* 添加和修改图文
*/
public function add_new()
{
$data = Util::postMore([
['id', 0],
['cid', []],
'title',
'author',
'image_input',
'content',
'synopsis',
'share_title',
'share_synopsis',
['visit', 0],
['sort', 0],
'url',
['status', 1],]);
$data['cid'] = implode(',', $data['cid']);
$content = $data['content'];
unset($data['content']);
if ($data['id']) {
$id = $data['id'];
unset($data['id']);
ArticleModel::beginTrans();
$res1 = ArticleModel::edit($data, $id, 'id');
$res2 = ArticleModel::setContent($id, $content);
if ($res1 && $res2)
$res = true;
else
$res = false;
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('修改图文成功!', $id);
else
return Json::fail('修改图文失败!', $id);
} else {
$data['add_time'] = time();
$data['admin_id'] = $this->adminId;
ArticleModel::beginTrans();
$res1 = ArticleModel::create($data);
$res2 = false;
if ($res1)
$res2 = ArticleModel::setContent($res1->id, $content);
if ($res1 && $res2)
$res = true;
else
$res = false;
ArticleModel::checkTrans($res);
if ($res)
return Json::successful('添加图文成功!', $res1->id);
else
return Json::successful('添加图文失败!', $res1->id);
}
}
/**
* 删除图文
* @param $id
* @return \think\response\Json
*/
public function delete($id)
{
$res = ArticleModel::del($id);
if (!$res)
return Json::fail('删除失败,请稍候再试!');
else
return Json::successful('删除成功!');
}
public function merchantIndex()
{
$where = Util::getMore([
['title', '']
], $this->request);
$this->assign('where', $where);
$where['cid'] = input('cid');
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment