init
This commit is contained in:
1
src/application/.htaccess
Normal file
1
src/application/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
142
src/application/admin/behavior/ActionBeginBehavior.php
Normal file
142
src/application/admin/behavior/ActionBeginBehavior.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
/**
|
||||
* 系统行为扩展:新增/更新/删除之后的后置操作
|
||||
*/
|
||||
load_trait('controller/Jump');
|
||||
class ActionBeginBehavior {
|
||||
use \traits\controller\Jump;
|
||||
protected static $actionName;
|
||||
protected static $controllerName;
|
||||
protected static $moduleName;
|
||||
protected static $method;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
self::$actionName = request()->action();
|
||||
self::$controllerName = request()->controller();
|
||||
self::$moduleName = request()->module();
|
||||
self::$method = request()->method();
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
private function _initialize() {
|
||||
if ('POST' == self::$method) {
|
||||
$this->checkRepeatTitle();
|
||||
$this->clearWeapp();
|
||||
$this->instyes();
|
||||
} else {
|
||||
$this->verifyfile();
|
||||
}
|
||||
}
|
||||
|
||||
private function verifyfile()
|
||||
{
|
||||
$tmp1 = 'cGhwLnBocF9zZXJ2aW'.'NlaW5mbw==';
|
||||
$tmp1 = base64_decode($tmp1);
|
||||
$data = tpCache($tmp1);
|
||||
$data = mchStrCode($data, 'DECODE');
|
||||
$data = json_decode($data, true);
|
||||
if (empty($data['pid']) || 2 > $data['pid']) return true;
|
||||
$file = "./data/conf/{$data['code']}.txt";
|
||||
$tmp2 = 'cGhwX3NlcnZpY2VtZWFs';
|
||||
$tmp2 = base64_decode($tmp2);
|
||||
if (!file_exists($file)) {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('php', [$tmp2=>1], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('php', [$tmp2=>1]);
|
||||
}
|
||||
/*--end*/
|
||||
} else {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('php', [$tmp2=>$data['pid']], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('php', [$tmp2=>$data['pid']]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件每次post提交都清除插件相关缓存
|
||||
* @access private
|
||||
*/
|
||||
private function clearWeapp()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctlActArr = array(
|
||||
'Weapp@*',
|
||||
);
|
||||
$ctlActStr = self::$controllerName.'@*';
|
||||
if (in_array($ctlActStr, $ctlActArr)) {
|
||||
\think\Cache::clear('hooks');
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布或编辑时,检测文档标题的重复性
|
||||
* @access private
|
||||
*/
|
||||
private function checkRepeatTitle()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctlArr = \think\Db::name('channeltype')->field('id,ctl_name,is_repeat_title')
|
||||
->where('nid','NOT IN', ['guestbook','single'])
|
||||
->getAllWithIndex('ctl_name');
|
||||
$actArr = ['add','edit'];
|
||||
if (!empty($ctlArr[self::$controllerName]) && in_array(self::$actionName, $actArr)) {
|
||||
/*模型否开启文档重复标题的检测*/
|
||||
if (empty($ctlArr[self::$controllerName]['is_repeat_title'])) {
|
||||
$map = array(
|
||||
'title' => $_POST['title'],
|
||||
);
|
||||
if ('edit' == self::$actionName) {
|
||||
$map['aid'] = ['NEQ', $_POST['aid']];
|
||||
}
|
||||
$count = \think\Db::name('archives')->where($map)->count('aid');
|
||||
if(!empty($count)){
|
||||
$this->error('该标题已存在,请更改');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
private function instyes()
|
||||
{
|
||||
$ca = md5(self::$actionName.'@'.self::$controllerName);
|
||||
if ('0e3e00da04fcf78cd9fd7dc763d956fc' == $ca) {
|
||||
$s = '5a6J'.'6KOF'.'5oiQ5'.'Yqf';
|
||||
if (1605110400 < getTime()) {
|
||||
sleep(5);
|
||||
$this->success(base64_decode($s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
110
src/application/admin/behavior/AppEndBehavior.php
Normal file
110
src/application/admin/behavior/AppEndBehavior.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
/**
|
||||
* 系统行为扩展:
|
||||
*/
|
||||
class AppEndBehavior {
|
||||
protected static $actionName;
|
||||
protected static $controllerName;
|
||||
protected static $moduleName;
|
||||
protected static $method;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
self::$actionName = request()->action();
|
||||
self::$controllerName = request()->controller();
|
||||
self::$moduleName = request()->module();
|
||||
self::$method = request()->method();
|
||||
// file_put_contents ( DATA_PATH."log.txt", date ( "Y-m-d H:i:s" ) . " " . var_export('admin_CoreProgramBehavior',true) . "\r\n", FILE_APPEND );
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
private function _initialize() {
|
||||
$this->resetAuthor(); // 临时处理授权问题
|
||||
$this->clearHtmlCache(); // 变动数据之后,清除页面缓存和数据
|
||||
// $this->sitemap(); // 自动生成sitemap
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动生成sitemap
|
||||
* @access public
|
||||
*/
|
||||
// private function sitemap()
|
||||
// {
|
||||
// /*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
// if ('POST' == self::$method) {
|
||||
// $channeltype_row = \think\Cache::get("extra_global_channeltype");
|
||||
// if (empty($channeltype_row)) {
|
||||
// $ctlArr = \think\Db::name('channeltype')
|
||||
// ->where('id','NOTIN', [6,8])
|
||||
// ->column('ctl_name');
|
||||
// } else {
|
||||
// $ctlArr = array();
|
||||
// foreach($channeltype_row as $key => $val){
|
||||
// if (!in_array($val['id'], [6,8])) {
|
||||
// $ctlArr[] = $val['ctl_name'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// $systemCtl= ['Arctype'];
|
||||
// $ctlArr = array_merge($systemCtl, $ctlArr);
|
||||
// $actArr = ['add','edit'];
|
||||
// if (in_array(self::$controllerName, $ctlArr) && in_array(self::$actionName, $actArr)) {
|
||||
// sitemap_auto();
|
||||
// }
|
||||
// }
|
||||
// /*--end*/
|
||||
// }
|
||||
|
||||
/**
|
||||
* 临时处理授权问题
|
||||
*/
|
||||
private function resetAuthor()
|
||||
{
|
||||
/*在以下相应的控制器和操作名里执行,以便提高性能*/
|
||||
$ctlActArr = array(
|
||||
'Index@index',
|
||||
);
|
||||
$ctlActStr = self::$controllerName.'@'.self::$actionName;
|
||||
if (in_array($ctlActStr, $ctlActArr) && 'GET' == self::$method) {
|
||||
if(!empty($_SESSION['isset_resetAuthor']))
|
||||
return true;
|
||||
$_SESSION['isset_resetAuthor'] = 1;
|
||||
|
||||
session('isset_author', null);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据变动之后,清理页面和数据缓存
|
||||
*/
|
||||
private function clearHtmlCache()
|
||||
{
|
||||
/*在以下相应的控制器和操作名里执行,以便提高性能*/
|
||||
$actArr = ['add','edit','del','recovery','changeTableVal'];
|
||||
if ('POST' == self::$method) {
|
||||
foreach ($actArr as $key => $val) {
|
||||
if (preg_match('/^((.*)_)?('.$val.')$/i', self::$actionName)) {
|
||||
foreach ([HTML_ROOT,CACHE_PATH] as $k2 => $v2) {
|
||||
delFile($v2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
275
src/application/admin/behavior/AuthRoleBehavior.php
Normal file
275
src/application/admin/behavior/AuthRoleBehavior.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
/**
|
||||
* 管理员权限控制
|
||||
*/
|
||||
load_trait('controller/Jump');
|
||||
class AuthRoleBehavior
|
||||
{
|
||||
use \traits\controller\Jump;
|
||||
protected static $actionName;
|
||||
protected static $controllerName;
|
||||
protected static $moduleName;
|
||||
protected static $method;
|
||||
protected static $admin_info;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
!isset(self::$moduleName) && self::$moduleName = request()->module();
|
||||
!isset(self::$controllerName) && self::$controllerName = request()->controller();
|
||||
!isset(self::$actionName) && self::$actionName = request()->action();
|
||||
!isset(self::$method) && self::$method = request()->method();
|
||||
!isset(self::$admin_info) && self::$admin_info = session('admin_info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块初始化
|
||||
* @param array $params 传入参数
|
||||
* @access public
|
||||
*/
|
||||
public function moduleInit(&$params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作开始执行
|
||||
* @param array $params 传入参数
|
||||
* @access public
|
||||
*/
|
||||
public function actionBegin(&$params)
|
||||
{
|
||||
if (0 < intval(self::$admin_info['role_id'])) {
|
||||
// 检测全局的增、改、删的权限——优先级最高
|
||||
$this->cud_access();
|
||||
// 检测每个小插件的权限
|
||||
$this->weapp_access();
|
||||
// 检测栏目管理的每个栏目权限
|
||||
$this->arctype_access();
|
||||
// 检测内容管理每个栏目对应的内容里列表等权限
|
||||
$this->archives_access();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 视图内容过滤
|
||||
* @param array $params 传入参数
|
||||
* @access public
|
||||
*/
|
||||
public function viewFilter(&$params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用结束
|
||||
* @param array $params 传入参数
|
||||
* @access public
|
||||
*/
|
||||
public function appEnd(&$params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测全局的增、改、删的权限
|
||||
* @access private
|
||||
*/
|
||||
private function cud_access()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctl = strtolower(self::$controllerName);
|
||||
$act = strtolower(self::$actionName);
|
||||
$actArr = ['add','edit','del'];
|
||||
if ('weapp' == $ctl && 'execute' == $act) {
|
||||
$sa = input('param.sa/s');
|
||||
foreach ($actArr as $key => $cud) {
|
||||
$sa = preg_replace('/^(.*)_('.$cud.')$/i', '$2', $sa); // 同名add 或者以_add类似结尾都符合
|
||||
if ($sa == $cud) {
|
||||
$admin_info = self::$admin_info;
|
||||
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
|
||||
$cudArr = !empty($auth_role_info['cud']) ? $auth_role_info['cud'] : [];
|
||||
if (!in_array($sa, $cudArr)) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$post = input('post.');
|
||||
array_push($actArr, 'changetableval'); // 审核信息
|
||||
foreach ($actArr as $key => $cud) {
|
||||
$act = preg_replace('/^(.*)_('.$cud.')$/i', '$2', $act); // 同名add 或者以_add类似结尾都符合
|
||||
if ($act == $cud) {
|
||||
$admin_info = self::$admin_info;
|
||||
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
|
||||
$cudArr = !empty($auth_role_info['cud']) ? $auth_role_info['cud'] : [];
|
||||
if (!in_array($act, $cudArr)) {
|
||||
if ('changetableval' == $act) {
|
||||
// 审核信息
|
||||
if ('archives' == $post['table'] && 'arcrank' == $post['field']) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限', null, '', 2);
|
||||
}
|
||||
} else {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
} else {
|
||||
if (!in_array('changetableval', $cudArr)) {
|
||||
// 审核信息
|
||||
if (IS_POST && 'edit' == $act) {
|
||||
$archivesInfo = M('archives')->field('arcrank,admin_id')->find($post['aid']);
|
||||
if (-1 == $archivesInfo['arcrank'] && $archivesInfo['arcrank'] != $post['arcrank']) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限', url('Archives/edit', ['id'=>$post['aid']]), '', 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测每个小插件的权限
|
||||
* @access private
|
||||
*/
|
||||
private function weapp_access()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctl = strtolower(self::$controllerName);
|
||||
$act = strtolower(self::$actionName);
|
||||
if ('weapp' == $ctl && 'execute' == $act) {
|
||||
$sc = input('param.sc/s');
|
||||
$sm = input('param.sm/s');
|
||||
$sa = input('param.sa/s');
|
||||
$admin_info = self::$admin_info;
|
||||
$auth_role_info = !empty($admin_info['auth_role_info']) ? $admin_info['auth_role_info'] : [];
|
||||
$plugins = !empty($auth_role_info['permission']['plugins']) ? $auth_role_info['permission']['plugins'] : [];
|
||||
// 插件本身设置的权限列表
|
||||
$config = include WEAPP_PATH.$sc.DS.'config.php';
|
||||
$plugins_permission = !empty($config['permission']) ? array_keys($config['permission']) : [];
|
||||
// 管理员拥有的插件具体权限
|
||||
$admin_permission = !empty($plugins[$sc]['child']) ? $plugins[$sc]['child'] : [];
|
||||
// 没有赋给管理员的插件具体权限
|
||||
$diff_plugins_perm = array_diff($plugins_permission, $admin_permission);
|
||||
// 检测插件权限
|
||||
$bool = true;
|
||||
if (empty($plugins_permission) && !isset($plugins[$sc])) {
|
||||
$bool = false;
|
||||
} else if (!empty($plugins_permission)) {
|
||||
foreach ($diff_plugins_perm as $key => $val) {
|
||||
if (strtolower($sm.'@'.$sa) == strtolower($val)) {
|
||||
$bool = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$bool) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测栏目管理的每个栏目权限
|
||||
* @access private
|
||||
*/
|
||||
private function arctype_access()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctl_all = strtolower(self::$controllerName.'@*');
|
||||
$ctlArr = ['arctype@*'];
|
||||
if (in_array($ctl_all, $ctlArr)) {
|
||||
$typeids = [];
|
||||
if (in_array(strtolower(self::$actionName), ['edit','del'])) {
|
||||
$typeids[] = input('id/d', 0);
|
||||
} else if (in_array(strtolower(self::$actionName), ['add'])) {
|
||||
$typeids[] = input('parent_id/d', 0);
|
||||
}
|
||||
if (!$this->is_check_arctype($typeids)) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测内容管理每个栏目对应的内容里列表等权限
|
||||
* @access private
|
||||
*/
|
||||
private function archives_access()
|
||||
{
|
||||
/*只有相应的控制器和操作名才执行,以便提高性能*/
|
||||
$ctl = strtolower(self::$controllerName);
|
||||
$act = strtolower(self::$actionName);
|
||||
$ctl_act = $ctl.'@'.$act;
|
||||
$ctl_all = $ctl.'@*';
|
||||
|
||||
$ctlArr= ['arctype@single','archives@*'];
|
||||
$row = \think\Db::name('channeltype')
|
||||
->where('nid','NOTIN', ['single'])
|
||||
->column('ctl_name');
|
||||
foreach ($row as $key => $val) {
|
||||
array_push($ctlArr, strtolower($val).'@*');
|
||||
}
|
||||
if (in_array($ctl_act, $ctlArr) || in_array($ctl_all, $ctlArr)) {
|
||||
$typeids = [];
|
||||
if (in_array($act, ['add','edit','del'])) {
|
||||
$aids = [];
|
||||
switch ($act) {
|
||||
case 'edit':
|
||||
$aids = input('id/a', []);
|
||||
break;
|
||||
|
||||
case 'del':
|
||||
$aids = input('del_id/a', []);
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
if (!empty($aids)) {
|
||||
$typeids = M('archives')->where('aid','IN',$aids)->column('typeid');
|
||||
}
|
||||
} else {
|
||||
$typeids[] = input('typeid/d', 0);
|
||||
}
|
||||
if (!$this->is_check_arctype($typeids)) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测栏目是否有权限
|
||||
*/
|
||||
private function is_check_arctype($typeids = []) {
|
||||
$bool_flag = true;
|
||||
$admin_info = self::$admin_info;
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$permission = $auth_role_info['permission'];
|
||||
|
||||
foreach ($typeids as $key => $tid) {
|
||||
if (0 < intval($tid) && !in_array($tid, $permission['arctype'])) {
|
||||
$bool_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bool_flag;
|
||||
}
|
||||
}
|
||||
56
src/application/admin/behavior/ModuleInitBehavior.php
Normal file
56
src/application/admin/behavior/ModuleInitBehavior.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
/**
|
||||
* 系统行为扩展:
|
||||
*/
|
||||
class ModuleInitBehavior {
|
||||
protected static $actionName;
|
||||
protected static $controllerName;
|
||||
protected static $moduleName;
|
||||
protected static $method;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
self::$actionName = request()->action();
|
||||
self::$controllerName = request()->controller();
|
||||
self::$moduleName = request()->module();
|
||||
self::$method = request()->method();
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
private function _initialize() {
|
||||
// $this->setChanneltypeStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据前端模板自动开启系统模型
|
||||
*/
|
||||
// private function setChanneltypeStatus()
|
||||
// {
|
||||
// /*不在以下相应的控制器和操作名里不往下执行,以便提高性能*/
|
||||
// $ctlActArr = array(
|
||||
// 'Index@index',
|
||||
// 'System@clear_cache',
|
||||
// );
|
||||
// $ctlActStr = self::$controllerName.'@'.self::$actionName;
|
||||
// if (!in_array($ctlActStr, $ctlActArr) || 'GET' != self::$method) {
|
||||
// return true;
|
||||
// }
|
||||
// /*--end*/
|
||||
|
||||
// // 根据前端模板自动开启系统模型
|
||||
// model('Channeltype')->setChanneltypeStatus();
|
||||
// }
|
||||
}
|
||||
144
src/application/admin/behavior/ViewFilterBehavior.php
Normal file
144
src/application/admin/behavior/ViewFilterBehavior.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 系统行为扩展:
|
||||
*/
|
||||
class ViewFilterBehavior {
|
||||
protected static $actionName;
|
||||
protected static $controllerName;
|
||||
protected static $moduleName;
|
||||
protected static $method;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
self::$actionName = request()->action();
|
||||
self::$controllerName = request()->controller();
|
||||
self::$moduleName = request()->module();
|
||||
self::$method = request()->method();
|
||||
$this->_initialize($params);
|
||||
}
|
||||
|
||||
private function _initialize(&$params) {
|
||||
$this->weappUpgrade($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每个插件主入口index页面进行更新包检测
|
||||
*/
|
||||
private function weappUpgrade(&$params)
|
||||
{
|
||||
$ca = self::$controllerName.'&'.self::$actionName;
|
||||
if ('Weapp&execute' == $ca && 'GET' == self::$method) {
|
||||
$code = input('param.sm/s');
|
||||
if (!empty($code)) {
|
||||
$url1 = url('Weapp/ajax_check_upgrade');
|
||||
$url2 = url('Weapp/OneKeyUpgrade');
|
||||
$url3 = url('Weapp/ajax_cancel_upgrade');
|
||||
$replace = <<<EOF
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
|
||||
weapp_upgrade_1599613252();
|
||||
|
||||
// 检测升级
|
||||
function weapp_upgrade_1599613252()
|
||||
{
|
||||
var code = '{$code}';
|
||||
$.ajax({
|
||||
type : "GET",
|
||||
url : "{$url1}",
|
||||
data : {code:code , _ajax:1},
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.code == 1 && res.data.upgrade && res.data.upgrade.code == 2) {
|
||||
var upgrade_str = res.data.upgrade.msg.upgrade;
|
||||
var intro_str = res.data.upgrade.msg.intro;
|
||||
var notice_str = res.data.upgrade.msg.notice;
|
||||
intro_str += '<style type="text/css">.layui-layer-content{height:270px!important;text-align:left!important;}</style>';
|
||||
upgrade_str = notice_str + intro_str + '<br/>' + upgrade_str;
|
||||
//询问框
|
||||
layer.confirm(upgrade_str, {
|
||||
title: false,//'检测插件更新',
|
||||
area: ['580px','400px'],
|
||||
btn: ['立即升级','不再提醒'] //按钮
|
||||
|
||||
}, function(){
|
||||
layer.closeAll();
|
||||
setTimeout(function(){
|
||||
upgrade_1599613252(code); // 请求后台
|
||||
},200);
|
||||
|
||||
}, function(){
|
||||
setTimeout(function(){
|
||||
cancel_upgrade_1599613252(code);
|
||||
},200);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 执行升级
|
||||
function upgrade_1599613252(code){
|
||||
layer_loading('升级中');
|
||||
$.ajax({
|
||||
type : "GET",
|
||||
url : "{$url2}",
|
||||
timeout : 360000, //超时时间设置,单位毫秒 设置了 1小时
|
||||
data : {code:code, _ajax:1},
|
||||
error: function(request) {
|
||||
layer.closeAll();
|
||||
layer.alert("升级失败,请第一时间联系技术协助!", {icon: 2, closeBtn: false, title:false}, function(){
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
success: function(res) {
|
||||
layer.closeAll();
|
||||
if(1 == res.code){
|
||||
layer.alert('已升级最新版本!', {icon: 1, closeBtn: false, title:false}, function(){
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
else{
|
||||
layer.alert(res.msg, {icon: 2, closeBtn: false, title:false}, function(){
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 不再提醒
|
||||
function cancel_upgrade_1599613252(code){
|
||||
$.ajax({
|
||||
type : "GET",
|
||||
url : "{$url3}",
|
||||
data : {code:code, _ajax:1},
|
||||
success: function(res) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
EOF;
|
||||
$params = str_ireplace('</body>', $replace, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1406
src/application/admin/common.php
Normal file
1406
src/application/admin/common.php
Normal file
File diff suppressed because it is too large
Load Diff
287
src/application/admin/conf/auth_rule.php
Normal file
287
src/application/admin/conf/auth_rule.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
/**
|
||||
* 权限属性说明
|
||||
* array
|
||||
* id 主键ID
|
||||
* menu_id 一级模块ID
|
||||
* menu_id2 二级模块ID
|
||||
* name 权限名称
|
||||
* is_modules 是否显示在分组下
|
||||
* sort_order 排序号
|
||||
* auths 权限列表(格式:控制器@*,控制器@操作名 --多个权限以逗号隔开)
|
||||
*/
|
||||
return [
|
||||
[
|
||||
'id' => 1,
|
||||
'menu_id' => 1001,
|
||||
'menu_id2' => 0,
|
||||
'name' => '栏目管理',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Arctype@index,Arctype@add,Arctype@edit,Arctype@del,Arctype@pseudo_del',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'menu_id' => 1002,
|
||||
'menu_id2' => 0,
|
||||
'name' => '内容管理',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Archives@*,Arctype@single_edit',
|
||||
],
|
||||
[
|
||||
'id' => 3, // 广告管理
|
||||
'menu_id' => 1003,
|
||||
'menu_id2' => 0,
|
||||
'name' => '允许操作',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Other@*,AdPosition@*',
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'menu_id' => 2001,
|
||||
'menu_id2' => 2001001,
|
||||
'name' => '网站设置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 10,
|
||||
'auths' => 'System@web,System@customvar_index,System@customvar_save,System@customvar_del',
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'menu_id' => 2001,
|
||||
'menu_id2' => 2001002,
|
||||
'name' => '核心设置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 20,
|
||||
'auths' => 'System@web2',
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'menu_id' => 2001,
|
||||
'menu_id2' => 2001003,
|
||||
'name' => '附件设置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 30,
|
||||
'auths' => 'System@basic',
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004009,
|
||||
'name' => '水印配置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 20,
|
||||
'auths' => 'System@water',
|
||||
],
|
||||
[
|
||||
'id' => 8,
|
||||
'menu_id' => 2003,
|
||||
'menu_id2' => 2003001,
|
||||
'name' => 'URL配置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 10,
|
||||
'auths' => 'Seo@*',
|
||||
],
|
||||
[
|
||||
'id' => 9,
|
||||
'menu_id' => 2003,
|
||||
'menu_id2' => 2003003,
|
||||
'name' => '友情链接',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 30,
|
||||
'auths' => 'Links@*',
|
||||
],
|
||||
[
|
||||
'id' => 10,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004001,
|
||||
'name' => '管理员',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 50,
|
||||
'auths' => 'Admin@admin_pwd',
|
||||
],
|
||||
[
|
||||
'id' => 11,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004002,
|
||||
'name' => '备份还原',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 70,
|
||||
'auths' => 'Tools@*',
|
||||
],
|
||||
[
|
||||
'id' => 12,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004003,
|
||||
'name' => '模板管理',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Filemanager@*',
|
||||
],
|
||||
[
|
||||
'id' => 13,
|
||||
'menu_id' => 2001,
|
||||
'menu_id2' => 2001005,
|
||||
'name' => '接口配置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'System@api_conf,Member@wechat_set,Member@alipay_set,System@smtp,System@smtp_tpl,System@smtp_tpl_edit,System@sms,System@sms_tpl,System@microsite,PayApi@*',
|
||||
],
|
||||
// [
|
||||
// 'id' => 14,
|
||||
// 'menu_id' => 2004,
|
||||
// 'menu_id2' => 2004005,
|
||||
// 'name' => '清除缓存',
|
||||
// 'is_modules' => 1,
|
||||
// 'sort_order' => 100,
|
||||
// 'auths' => 'System@clear_cache',
|
||||
// ],
|
||||
[
|
||||
'id' => 15,
|
||||
'menu_id' => 2005,
|
||||
'menu_id2' => 0,
|
||||
'name' => '插件应用',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Weapp@index,Weapp@create,Weapp@pack,Weapp@upload,Weapp@disable,Weapp@install,Weapp@enable,Weapp@execute',
|
||||
],
|
||||
[
|
||||
'id' => 16,
|
||||
'menu_id' => 2002,
|
||||
'menu_id2' => 0,
|
||||
'name' => '允许操作',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Uiset@*',
|
||||
],
|
||||
[
|
||||
'id' => 17,
|
||||
'menu_id' => 2005,
|
||||
'menu_id2' => 0,
|
||||
'name' => '插件卸载',
|
||||
'is_modules' => 0,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Weapp@uninstall',
|
||||
],
|
||||
[
|
||||
'id' => 18,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004001,
|
||||
'name' => '权限组',
|
||||
'is_modules' => 0,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Admin@admin_add,Admin@admin_del,AuthRole@*',
|
||||
],
|
||||
[
|
||||
'id' => 19,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004006,
|
||||
'name' => '回收站',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 60,
|
||||
'auths' => 'RecycleBin@*',
|
||||
],
|
||||
[
|
||||
'id' => 20,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004007,
|
||||
'name' => '频道模型',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 80,
|
||||
'auths' => 'Channeltype@*,Field@*',
|
||||
],
|
||||
[
|
||||
'id' => 21,
|
||||
'menu_id' => 2006,
|
||||
'menu_id2' => 0,
|
||||
'name' => '允许操作',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Member@*',
|
||||
],
|
||||
[
|
||||
'id' => 22,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004004,
|
||||
'name' => '栏目字段',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 90,
|
||||
'auths' => 'Field@arctype_index,Field@arctype_add,Field@arctype_edit,Field@arctype_del',
|
||||
],
|
||||
[
|
||||
'id' => 23,
|
||||
'menu_id' => 2008,
|
||||
'menu_id2' => 0,
|
||||
'name' => '允许操作',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Statistics@*,Shop@*,ShopProduct@*,Member@*',
|
||||
],
|
||||
[
|
||||
'id' => 24,
|
||||
'menu_id' => 2009,
|
||||
'menu_id2' => 0,
|
||||
'name' => '允许操作',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 100,
|
||||
'auths' => 'Diyminipro@*',
|
||||
],
|
||||
[
|
||||
'id' => 25,
|
||||
'menu_id' => 2003,
|
||||
'menu_id2' => 2003002,
|
||||
'name' => 'Sitemap',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 20,
|
||||
'auths' => 'Sitemap@*',
|
||||
],
|
||||
[
|
||||
'id' => 26,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004008,
|
||||
'name' => '文档属性',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 10,
|
||||
'auths' => 'ArchivesFlag@*',
|
||||
],
|
||||
[
|
||||
'id' => 27,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004010,
|
||||
'name' => '缩略图配置',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 30,
|
||||
'auths' => 'System@thumb',
|
||||
],
|
||||
[
|
||||
'id' => 28,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004011,
|
||||
'name' => 'TAG管理',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 40,
|
||||
'auths' => 'Tags@*',
|
||||
],
|
||||
[
|
||||
'id' => 29,
|
||||
'menu_id' => 2004,
|
||||
'menu_id2' => 2004012,
|
||||
'name' => '模块开关',
|
||||
'is_modules' => 1,
|
||||
'sort_order' => 1,
|
||||
'auths' => 'Index@switch_map',
|
||||
],
|
||||
];
|
||||
3
src/application/admin/conf/constant.php
Normal file
3
src/application/admin/conf/constant.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
define('INSTALL_DATE',1684043912);
|
||||
define('SERIALNUMBER','20230514015832urBSc5');
|
||||
7
src/application/admin/conf/global.php
Normal file
7
src/application/admin/conf/global.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* 配置常量
|
||||
*/
|
||||
return array(
|
||||
|
||||
);
|
||||
0
src/application/admin/conf/md5list2.txt
Normal file
0
src/application/admin/conf/md5list2.txt
Normal file
785
src/application/admin/conf/menu.php
Normal file
785
src/application/admin/conf/menu.php
Normal file
@@ -0,0 +1,785 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
$main_lang= get_main_lang();
|
||||
$admin_lang = get_admin_lang();
|
||||
$domain = request()->domain();
|
||||
|
||||
/*PC端可视编辑URl*/
|
||||
$uiset_pc_arr = [];
|
||||
if (file_exists(ROOT_PATH.'template/'.TPL_THEME.'pc/uiset.txt')) {
|
||||
$uiset_pc_arr = array(
|
||||
'url' => url('Uiset/pc', array(), true, $domain),
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*手机端可视编辑URl*/
|
||||
$uiset_mobile_arr = [];
|
||||
if (file_exists(ROOT_PATH.'template/'.TPL_THEME.'mobile/uiset.txt')) {
|
||||
$uiset_mobile_arr = array(
|
||||
'url' => url('Uiset/mobile', array(), true, $domain),
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*清理数据URl*/
|
||||
$uiset_data_url = '';
|
||||
if (!empty($uiset_pc_arr) || !empty($uiset_mobile_arr)) {
|
||||
$uiset_data_url = url('Uiset/ui_index', array(), true, $domain);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*可视编辑URL*/
|
||||
$uiset_index_arr = array();
|
||||
if (!empty($uiset_pc_arr) || !empty($uiset_mobile_arr)) {
|
||||
$uiset_index_arr = array(
|
||||
'url' => url('Uiset/index', array(), true, $domain),
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*基本信息*/
|
||||
$ctlactArr = [
|
||||
'System@web',
|
||||
'System@web2',
|
||||
'System@basic',
|
||||
'System@water',
|
||||
'System@api_conf',
|
||||
'PayApi@pay_api_index',
|
||||
];
|
||||
$system_index_arr = array();
|
||||
foreach ($ctlactArr as $key => $val) {
|
||||
if (is_check_access($val)) {
|
||||
$arr = explode('@', $val);
|
||||
$system_index_arr = array(
|
||||
'controller' => !empty($arr[0]) ? $arr[0] : '',
|
||||
'action' => !empty($arr[1]) ? $arr[1] : '',
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*SEO优化URl*/
|
||||
$seo_index_arr = array();
|
||||
if ($main_lang != $admin_lang) {
|
||||
$seo_index_arr = array(
|
||||
'controller' => 'Links',
|
||||
'action' => 'index',
|
||||
);
|
||||
} else {
|
||||
$ctlactArr = [
|
||||
'Seo@seo',
|
||||
'Sitemap@index',
|
||||
'Links@index',
|
||||
];
|
||||
foreach ($ctlactArr as $key => $val) {
|
||||
if (is_check_access($val)) {
|
||||
$arr = explode('@', $val);
|
||||
$seo_index_arr = array(
|
||||
'controller' => !empty($arr[0]) ? $arr[0] : '',
|
||||
'action' => !empty($arr[1]) ? $arr[1] : '',
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*备份还原URl*/
|
||||
$tools_index_arr = array();
|
||||
if ($main_lang == $admin_lang) {
|
||||
$tools_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*频道模型URl*/
|
||||
$channeltype_index_arr = array();
|
||||
if ($main_lang == $admin_lang) {
|
||||
$channeltype_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*回收站URl*/
|
||||
$recyclebin_index_arr = array();
|
||||
if ($main_lang == $admin_lang) {
|
||||
$recyclebin_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*插件应用URl*/
|
||||
$weapp_index_arr = array();
|
||||
if (1 == tpCache('web.web_weapp_switch') && file_exists(ROOT_PATH.'weapp')) {
|
||||
//功能限制
|
||||
$auth_function = true;
|
||||
if (function_exists('checkAuthRule')) {
|
||||
$auth_function = checkAuthRule(2005);
|
||||
}
|
||||
//2005 菜单id
|
||||
if ($auth_function){
|
||||
$weapp_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
);
|
||||
}else{
|
||||
$weapp_index_arr = array(
|
||||
'is_menu' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*会员中心URl*/
|
||||
$users_index_arr = array();
|
||||
if (1 == tpCache('web.web_users_switch') && $main_lang == $admin_lang) {
|
||||
$users_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
'is_modules' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*商城中心URl*/
|
||||
$shop_index_arr = array();
|
||||
$shopServicemeal = array_join_string(array('cGhwLnBocF9zZXJ2aWNlbWVhbA=='));
|
||||
if (1 == tpCache('web.web_users_switch') && 1 == getUsersConfigData('shop.shop_open') && $main_lang == $admin_lang && 1.5 <= tpCache($shopServicemeal)) {
|
||||
$shop_index_arr = array(
|
||||
'is_menu' => 1,
|
||||
'is_modules' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*小程序*/
|
||||
$diyminipro_index_arr = array();
|
||||
if (is_dir('./weapp/Diyminipro/') && 1 == tpCache('web.web_diyminipro_switch') && $main_lang == $admin_lang) {
|
||||
$diyminipro_index_arr = array(
|
||||
'is_modules' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*更多功能*/
|
||||
$index_switch_map_arr = array();
|
||||
if ($main_lang == $admin_lang) {
|
||||
$index_switch_map_arr = array(
|
||||
'is_menu' => 1,
|
||||
'is_modules' => 1,
|
||||
);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/**
|
||||
* 权限模块属性说明
|
||||
* array
|
||||
* id 主键ID
|
||||
* parent_id 父ID
|
||||
* name 模块名称
|
||||
* controller 控制器
|
||||
* action 操作名
|
||||
* url 跳转链接(控制器与操作名为空时,才使用url)
|
||||
* target 打开窗口方式
|
||||
* icon 菜单图标
|
||||
* grade 层级
|
||||
* is_menu 是否显示菜单
|
||||
* is_modules 是否显示权限模块分组
|
||||
* is_subshowmenu 子模块是否有显示的模块
|
||||
* child 子模块
|
||||
*/
|
||||
return array(
|
||||
'1000'=>array(
|
||||
'id'=>1000,
|
||||
'parent_id'=>0,
|
||||
'name'=>'',
|
||||
'controller'=>'',
|
||||
'action'=>'',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'grade'=>0,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>1,
|
||||
'child'=>array(
|
||||
'1001' => array(
|
||||
'id'=>1001,
|
||||
'parent_id'=>1000,
|
||||
'name' => '栏目管理',
|
||||
'controller'=>'Arctype',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-bars',
|
||||
'grade'=>1,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'1002' => array(
|
||||
'id'=>1002,
|
||||
'parent_id'=>1000,
|
||||
'name' => '内容管理',
|
||||
'controller'=>'Archives',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-file-o',
|
||||
'grade'=>1,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'1003' => array(
|
||||
'id'=>1003,
|
||||
'parent_id'=>1000,
|
||||
'name' => '广告管理',
|
||||
'controller'=>'AdPosition',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-file-image-o',
|
||||
'grade'=>1,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'2000'=>array(
|
||||
'id'=>2000,
|
||||
'parent_id'=>0,
|
||||
'name'=>'设置',
|
||||
'controller'=>'',
|
||||
'action'=>'',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'grade'=>0,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>1,
|
||||
'child'=>array(
|
||||
'2001' => array(
|
||||
'id'=>2001,
|
||||
'parent_id'=>2000,
|
||||
'name' => '基本信息',
|
||||
'controller'=>isset($system_index_arr['controller']) ? $system_index_arr['controller'] : 'System',
|
||||
'action'=>isset($system_index_arr['action']) ? $system_index_arr['action'] : 'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-cog',
|
||||
'grade'=>1,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(
|
||||
'2001001' => array(
|
||||
'id'=>2001001,
|
||||
'parent_id'=>2001,
|
||||
'name' => '网站设置',
|
||||
'controller'=>'System',
|
||||
'action'=>'web',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2001002' => array(
|
||||
'id'=>2001002,
|
||||
'parent_id'=>2001,
|
||||
'name' => '核心设置',
|
||||
'controller'=>'System',
|
||||
'action'=>'web2',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2001003' => array(
|
||||
'id'=>2001003,
|
||||
'parent_id'=>2001,
|
||||
'name' => '附件设置',
|
||||
'controller'=>'System',
|
||||
'action'=>'basic',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2001005' => array(
|
||||
'id'=>2001005,
|
||||
'parent_id'=>2001,
|
||||
'name' => '接口配置',
|
||||
'controller'=>'System',
|
||||
'action'=>'api_conf',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'2002' => array(
|
||||
'id'=>2002,
|
||||
'parent_id'=>2000,
|
||||
'name' => '可视编辑',
|
||||
'controller'=>'Uiset',
|
||||
'action'=>'index',
|
||||
'url'=>isset($uiset_index_arr['url']) ? $uiset_index_arr['url'] : '',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-tachometer',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($uiset_index_arr['is_menu']) ? $uiset_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>1,
|
||||
'child'=>array(
|
||||
'2002001' => array(
|
||||
'id'=>2002001,
|
||||
'parent_id'=>2002,
|
||||
'name' => '电脑版',
|
||||
'controller'=>'Uiset',
|
||||
'action'=>'pc',
|
||||
'url'=>isset($uiset_pc_arr['url']) ? $uiset_pc_arr['url'] : '',
|
||||
'target'=>'_blank',
|
||||
'icon'=>'fa fa-desktop',
|
||||
'grade'=>2,
|
||||
'is_menu'=>isset($uiset_pc_arr['is_menu']) ? $uiset_pc_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2002002' => array(
|
||||
'id'=>2002002,
|
||||
'parent_id'=>2002,
|
||||
'name' => '手机版',
|
||||
'controller'=>'Uiset',
|
||||
'action'=>'mobile',
|
||||
'url'=>isset($uiset_mobile_arr['url']) ? $uiset_mobile_arr['url'] : '',
|
||||
'target'=>'_blank',
|
||||
'icon'=>'fa fa-mobile',
|
||||
'grade'=>2,
|
||||
'is_menu'=>isset($uiset_mobile_arr['is_menu']) ? $uiset_mobile_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2002003' => array(
|
||||
'id'=>2002003,
|
||||
'parent_id'=>2002,
|
||||
'name' => '数据清理',
|
||||
'controller'=>'Uiset',
|
||||
'action'=>'ui_index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'2003' => array(
|
||||
'id'=>2003,
|
||||
'parent_id'=>2000,
|
||||
'name' => 'SEO设置',
|
||||
'controller'=>isset($seo_index_arr['controller']) ? $seo_index_arr['controller'] : 'Seo',
|
||||
'action'=>isset($seo_index_arr['action']) ? $seo_index_arr['action'] : 'seo',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-paper-plane',
|
||||
'grade'=>1,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child'=>array(
|
||||
'2003001' => array(
|
||||
'id'=>2003001,
|
||||
'parent_id'=>2003,
|
||||
'name' => 'URL配置',
|
||||
'controller'=>'Seo',
|
||||
'action'=>'seo',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-newspaper-o',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2003002' => array(
|
||||
'id'=>2003002,
|
||||
'parent_id'=>2003,
|
||||
'name' => 'Sitemap',
|
||||
'controller'=>'Sitemap',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-newspaper-o',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2003003' => array(
|
||||
'id'=>2003003,
|
||||
'parent_id'=>2003,
|
||||
'name' => '友情链接',
|
||||
'controller'=>'Links',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-link',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'2004' => array(
|
||||
'id'=>2004,
|
||||
'parent_id'=>2000,
|
||||
'name' => '更多功能',
|
||||
'controller'=>'Index',
|
||||
'action'=>'switch_map',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-th-large',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($index_switch_map_arr['is_menu']) ? $index_switch_map_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($index_switch_map_arr['is_modules']) ? $index_switch_map_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(
|
||||
'2004001' => array(
|
||||
'id'=>2004001,
|
||||
'parent_id'=>2004,
|
||||
'name' => '管理员',
|
||||
'controller'=>'Admin',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-user',
|
||||
'grade'=>2,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004002' => array(
|
||||
'id'=>2004002,
|
||||
'parent_id'=>2004,
|
||||
'name' => '备份还原',
|
||||
'controller'=>'Tools',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-database',
|
||||
'grade'=>2,
|
||||
'is_menu'=>isset($tools_index_arr['is_menu']) ? $tools_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004003' => array(
|
||||
'id'=>2004003,
|
||||
'parent_id'=>2004,
|
||||
'name' => '模板管理',
|
||||
'controller'=>'Filemanager',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-folder-open',
|
||||
'grade'=>2,
|
||||
'is_menu'=>1,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004004' => array(
|
||||
'id'=>2004004,
|
||||
'parent_id'=>2004,
|
||||
'name' => '栏目字段',
|
||||
'controller'=>'Field',
|
||||
'action'=>'arctype_add',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-cogs',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
// '2004005' => array(
|
||||
// 'id'=>2004005,
|
||||
// 'parent_id'=>2004,
|
||||
// 'name' => '清除缓存',
|
||||
// 'controller'=>'System',
|
||||
// 'action'=>'clear_cache',
|
||||
// 'url'=>'',
|
||||
// 'target'=>'workspace',
|
||||
// 'icon'=>'fa fa-undo',
|
||||
// 'grade'=>2,
|
||||
// 'is_menu'=>1,
|
||||
// 'is_modules'=>0,
|
||||
// 'is_subshowmenu'=>0,
|
||||
// 'child' => array(),
|
||||
// ),
|
||||
'2004006' => array(
|
||||
'id'=>2004006,
|
||||
'parent_id'=>2004,
|
||||
'name' => '回收站',
|
||||
'controller'=>'RecycleBin',
|
||||
'action'=>'archives_index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-recycle',
|
||||
'grade'=>2,
|
||||
'is_menu'=>isset($recyclebin_index_arr['is_menu']) ? $recyclebin_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004007' => array(
|
||||
'id'=>2004007,
|
||||
'parent_id'=>2004,
|
||||
'name' => '频道模型',
|
||||
'controller'=>'Channeltype',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-cube',
|
||||
'grade'=>2,
|
||||
'is_menu'=>isset($channeltype_index_arr['is_menu']) ? $channeltype_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004008' => array(
|
||||
'id'=>2004008,
|
||||
'parent_id'=>2004,
|
||||
'name' => '文档属性',
|
||||
'controller'=>'ArchivesFlag',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004009' => array(
|
||||
'id'=>2004009,
|
||||
'parent_id'=>2004,
|
||||
'name' => '水印配置',
|
||||
'controller'=>'System',
|
||||
'action'=>'water',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004010' => array(
|
||||
'id'=>2004010,
|
||||
'parent_id'=>2004,
|
||||
'name' => '缩略图配置',
|
||||
'controller'=>'System',
|
||||
'action'=>'thumb',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004011' => array(
|
||||
'id'=>2004011,
|
||||
'parent_id'=>2004,
|
||||
'name' => 'TAG管理',
|
||||
'controller'=>'Tags',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2004012' => array(
|
||||
'id'=>2004012,
|
||||
'parent_id'=>2004,
|
||||
'name' => '模块开关',
|
||||
'controller'=>'Index',
|
||||
'action'=>'switch_map',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-undo',
|
||||
'grade'=>2,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>1,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'2005' => array(
|
||||
'id'=>2005,
|
||||
'parent_id'=>2000,
|
||||
'name' => '插件应用',
|
||||
'controller'=>'Weapp',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-futbol-o',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($weapp_index_arr['is_menu']) ? $weapp_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child'=>array(),
|
||||
),
|
||||
'2006' => array(
|
||||
'id'=>2006,
|
||||
'parent_id'=>2000,
|
||||
'name' => '会员中心',
|
||||
'controller'=>'Member',
|
||||
'action'=>'users_index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-user',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($users_index_arr['is_menu']) ? $users_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($users_index_arr['is_modules']) ? $users_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2010' => array(
|
||||
'id'=>2006,
|
||||
'parent_id'=>2000,
|
||||
'name' => '项目/服务商',
|
||||
'controller'=>'Project',
|
||||
'action'=>'users_index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-user',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($users_index_arr['is_menu']) ? $users_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($users_index_arr['is_modules']) ? $users_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2011' => array(
|
||||
'id'=>2006,
|
||||
'parent_id'=>2000,
|
||||
'name' => '案例列表',
|
||||
'controller'=>'Casevideo',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-user',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($users_index_arr['is_menu']) ? $users_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($users_index_arr['is_modules']) ? $users_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2012' => array(
|
||||
'id'=>2006,
|
||||
'parent_id'=>2000,
|
||||
'name' => '主流平台',
|
||||
'controller'=>'platform',
|
||||
'action'=>'index',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-user',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($users_index_arr['is_menu']) ? $users_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($users_index_arr['is_modules']) ? $users_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2008' => array(
|
||||
'id'=>2008,
|
||||
'parent_id'=>2000,
|
||||
'name' => '商城中心',
|
||||
'controller'=>'Shop',
|
||||
'action'=>'home',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-shopping-cart',
|
||||
'grade'=>1,
|
||||
'is_menu'=>isset($shop_index_arr['is_menu']) ? $shop_index_arr['is_menu'] : 0,
|
||||
'is_modules'=>isset($shop_index_arr['is_modules']) ? $shop_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
'2009' => array(
|
||||
'id'=>2009,
|
||||
'parent_id'=>2000,
|
||||
'name' => '可视化小程序',
|
||||
'controller'=>'Diyminipro',
|
||||
'action'=>'page_edit',
|
||||
'url'=>'',
|
||||
'target'=>'workspace',
|
||||
'icon'=>'fa fa-code',
|
||||
'grade'=>1,
|
||||
'is_menu'=>0,
|
||||
'is_modules'=>isset($diyminipro_index_arr['is_modules']) ? $diyminipro_index_arr['is_modules'] : 0,
|
||||
'is_subshowmenu'=>0,
|
||||
'child' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
5
src/application/admin/conf/session_conf.php
Normal file
5
src/application/admin/conf/session_conf.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$session_1600593464 = json_encode(array (
|
||||
'expire' => '3600',
|
||||
));
|
||||
define('EY_SESSION_CONF', $session_1600593464);
|
||||
92
src/application/admin/config.php
Normal file
92
src/application/admin/config.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
$admin_ey_config = [
|
||||
'seo_pseudo' => 1, // 默认纯动态URL模式,兼容不支持pathinfo环境
|
||||
'seo_dynamic_format' => 1, // 1=兼容模式的URL,2=伪动态
|
||||
'seo_rewrite_format' => config('ey_config.seo_rewrite_format'),
|
||||
'system_sql_mode' => config('ey_config.system_sql_mode'), // 数据库模式
|
||||
'seo_inlet' => config('ey_config.seo_inlet'), // 0=保留入口文件,1=隐藏入口文件
|
||||
];
|
||||
$ey_config = array_merge(config('ey_config'), $admin_ey_config);
|
||||
|
||||
// 分页数
|
||||
$system_paginate_pagesize = config('tpcache.system_paginate_pagesize');
|
||||
$system_paginate_pagesize = !empty($system_paginate_pagesize) ? intval($system_paginate_pagesize) : 20;
|
||||
|
||||
$admin_config = array(
|
||||
'ey_config' => $ey_config,
|
||||
//分页配置
|
||||
'paginate' => array(
|
||||
'list_rows' => $system_paginate_pagesize,
|
||||
),
|
||||
// 默认全局过滤方法 用逗号分隔多个
|
||||
'default_filter' => 'htmlspecialchars', // htmlspecialchars
|
||||
// 登录有效期
|
||||
'login_expire' => 3600,
|
||||
// 登录错误最大次数
|
||||
'login_errtotal' => 8,
|
||||
// 登录错误超过次数之后,锁定用户名有效时间 15 分钟
|
||||
'login_errexpire' => 900,
|
||||
// +----------------------------------------------------------------------
|
||||
// | 模板设置
|
||||
// +----------------------------------------------------------------------
|
||||
// 默认成功跳转对应的模板文件
|
||||
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
|
||||
// 默认错误跳转对应的模板文件
|
||||
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 异常及错误设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 异常页面的模板文件
|
||||
//'exception_tmpl' => ROOT_PATH.'public/static/errpage/404.html',
|
||||
// errorpage 错误页面
|
||||
//'error_tmpl' => ROOT_PATH.'public/static/errpage/404.html',
|
||||
|
||||
/**假设这个访问地址是 www.xxxxx.dev/home/goods/goodsInfo/id/1.html
|
||||
*就保存名字为 home_goods_goodsinfo_1.html
|
||||
*配置成这样, 指定 模块 控制器 方法名 参数名
|
||||
*/
|
||||
'HTML_CACHE_STATUS' => false,
|
||||
|
||||
// 控制器与操作名之间的连接符
|
||||
'POWER_OPERATOR' => '@',
|
||||
|
||||
// 数据管理
|
||||
'DATA_BACKUP_PATH' => '/data/sqldata', //数据库备份根路径
|
||||
'DATA_BACKUP_PART_SIZE' => 524288000, //数据库备份卷大小 50M
|
||||
'DATA_BACKUP_COMPRESS' => 0, //数据库备份文件是否启用压缩
|
||||
'DATA_BACKUP_COMPRESS_LEVEL' => 9, //数据库备份文件压缩级别
|
||||
|
||||
// 过滤不需要登录的操作
|
||||
'filter_login_action' => array(
|
||||
'Admin@login', // 登录
|
||||
'Admin@logout', // 退出
|
||||
'Admin@vertify', // 验证码
|
||||
),
|
||||
|
||||
// 无需验证权限的操作
|
||||
'uneed_check_action' => array(
|
||||
'Base@*', // 基类
|
||||
'Index@*', // 后台首页
|
||||
'Ajax@*', // 所有ajax操作
|
||||
'Ueditor@*', // 编辑器上传
|
||||
'Uploadify@*', // 图片上传
|
||||
),
|
||||
);
|
||||
|
||||
$html_config = include_once 'html.php';
|
||||
return array_merge($admin_config, $html_config);
|
||||
?>
|
||||
755
src/application/admin/controller/AdPosition.php
Normal file
755
src/application/admin/controller/AdPosition.php
Normal file
@@ -0,0 +1,755 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class AdPosition extends Base
|
||||
{
|
||||
private $ad_position_system_id = array(); // 系统默认位置ID,不可删除
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$get = input('get.');
|
||||
$keywords = input('keywords/s');
|
||||
$condition = [];
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'type'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else {
|
||||
$tmp_key = 'a.'.$key;
|
||||
$condition[$tmp_key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$adPositionM = M('ad_position');
|
||||
$count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $adPositionM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id');
|
||||
|
||||
// 每组获取三张图片
|
||||
$pids = get_arr_column($list, 'id');
|
||||
$ad = M('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select();
|
||||
foreach ($list as $k => $v) {
|
||||
if (1 == $v['type']) {
|
||||
// 图片封面图片
|
||||
$v['ad'] = [];
|
||||
foreach ($ad as $m => $n) {
|
||||
if ($v['id'] == $n['pid']) {
|
||||
$n['litpic'] = get_default_pic($n['litpic']); // 支持子目录
|
||||
$v['ad'][] = $n;
|
||||
unset($ad[$m]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 若没有内容则显示默认图片
|
||||
if (empty($v['ad'])) {
|
||||
$v['ad_count'] = 0;
|
||||
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/common/images/not_adv.jpg';
|
||||
} else {
|
||||
$v['ad_count'] = count($v['ad']);
|
||||
}
|
||||
// 广告类型
|
||||
$v['type_name'] = '图片';
|
||||
} else if (2 == $v['type']) {
|
||||
// 多媒体封面图片
|
||||
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png';
|
||||
// 广告类型
|
||||
$v['type_name'] = '多媒体';
|
||||
} else if (3 == $v['type']) {
|
||||
// HTML代码封面图片
|
||||
$v['ad'][]['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_html.png';
|
||||
// 广告类型
|
||||
$v['type_name'] = 'HTML代码';
|
||||
}
|
||||
$list[$k] = $v;
|
||||
}
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$map = array(
|
||||
'title' => trim($post['title']),
|
||||
'lang' => $this->admin_lang,
|
||||
);
|
||||
if(M('ad_position')->where($map)->count() > 0){
|
||||
$this->error('该广告名称已存在,请检查', url('AdPosition/index'));
|
||||
}
|
||||
|
||||
// 添加广告位置表信息
|
||||
$data = array(
|
||||
'title' => trim($post['title']),
|
||||
'type' => $post['type'],
|
||||
'intro' => $post['intro'],
|
||||
'admin_id' => session('admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$insertID = M('ad_position')->insertGetId($data);
|
||||
|
||||
if (!empty($insertID)) {
|
||||
// 同步广告位置ID到多语言的模板变量里,添加多语言广告位
|
||||
$this->syn_add_language_attribute($insertID);
|
||||
|
||||
// 读取组合广告位的图片及信息
|
||||
$AdData = [];
|
||||
if (1 == $post['type'] && !empty($post['img_litpic'])) { // 图片类型
|
||||
$i = 1;
|
||||
foreach ($post['img_litpic'] as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
// 去掉http:
|
||||
$value = str_replace("http:", "", $value);
|
||||
// 去掉https:
|
||||
$value = str_replace("https:", "", $value);
|
||||
// 主要参数
|
||||
$AdData['litpic'] = $value;
|
||||
$AdData['pid'] = $insertID;
|
||||
$AdData['title'] = trim($post['img_title'][$key]);
|
||||
$AdData['links'] = $post['img_links'][$key];
|
||||
$AdData['intro'] = $post['img_intro'][$key];
|
||||
$target = !empty($post['img_target'][$key]) ? 1 : 0;
|
||||
$AdData['target'] = $target;
|
||||
// 其他参数
|
||||
$AdData['media_type'] = 1;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = $i++;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
// 添加到广告图表
|
||||
$ad_id = Db::name('ad')->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (2 == $post['type'] && !empty($post['video_litpic'])) { // 媒体类型
|
||||
// 去掉http:
|
||||
$video_litpic = str_replace("http:", "", $post['video_litpic']);
|
||||
// 去掉https:
|
||||
$video_litpic = str_replace("https:", "", $post['video_litpic']);
|
||||
// 主要参数
|
||||
$AdData['litpic'] = $video_litpic;
|
||||
$AdData['pid'] = $insertID;
|
||||
$AdData['title'] = trim($post['title']);
|
||||
// 其他参数
|
||||
$AdData['intro'] = '';
|
||||
$AdData['links'] = '';
|
||||
$AdData['target'] = 0;
|
||||
$AdData['media_type'] = 2;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = 1;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
// 添加到广告图表
|
||||
$ad_id = Db::name('ad')->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
|
||||
} else if (3 == $post['type'] && !empty($post['html_intro'])) { // HTML代码
|
||||
// 主要参数
|
||||
$AdData['pid'] = $insertID;
|
||||
$AdData['title'] = trim($post['title']);
|
||||
$AdData['intro'] = $post['html_intro'];
|
||||
// 其他参数
|
||||
$AdData['litpic'] = '';
|
||||
$AdData['links'] = '';
|
||||
$AdData['target'] = 0;
|
||||
$AdData['media_type'] = 3;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = 1;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
// 添加到广告图表
|
||||
$ad_id = Db::name('ad')->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
|
||||
}
|
||||
adminLog('新增广告:'.$post['title']);
|
||||
$this->success("操作成功", url('AdPosition/index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('AdPosition/index'));
|
||||
}
|
||||
}
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$upload_max_filesize = upload_max_filesize();
|
||||
$this->assign('upload_max_filesize', $upload_max_filesize);
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$this->assign('media_type', $media_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if (!empty($post['id'])) {
|
||||
if (array_key_exists($post['id'], $this->ad_position_system_id)) {
|
||||
$this->error("不可更改系统预定义位置", url('AdPosition/edit',array('id'=>$post['id'])));
|
||||
}
|
||||
|
||||
/* 判断除自身外是否还有相同广告名称已存在 */
|
||||
$map = array(
|
||||
'id' => array('NEQ', $post['id']),
|
||||
'title' => trim($post['title']),
|
||||
'lang' => $this->admin_lang,
|
||||
);
|
||||
if (Db::name('ad_position')->where($map)->count() > 0) $this->error('该广告名称已存在,请检查');
|
||||
/* END */
|
||||
|
||||
/* 判断广告是否切换广告类型 */
|
||||
// $where = [
|
||||
// 'id' => $post['id'],
|
||||
// 'type' => $post['type'],
|
||||
// 'lang' => $this->admin_lang
|
||||
// ];
|
||||
// if (Db::name('ad_position')->where($where)->count() == 0) {
|
||||
// // 已切换广告类型,清除广告中的广告内容
|
||||
// $where = [
|
||||
// 'pid' => $post['id'],
|
||||
// 'lang' => $this->admin_lang
|
||||
// ];
|
||||
// Db::name('ad')->where($where)->delete();
|
||||
// }
|
||||
/* END */
|
||||
|
||||
/* 修改广告主体信息 */
|
||||
$data = array(
|
||||
'id' => $post['id'],
|
||||
'title' => trim($post['title']),
|
||||
'type' => $post['type'],
|
||||
'intro' => $post['intro'],
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$resultID = Db::name('ad_position')->update($data);
|
||||
/* END */
|
||||
}
|
||||
|
||||
if (!empty($resultID)) {
|
||||
$ad_db = Db::name('ad');
|
||||
if (1 == $post['type'] && !empty($post['img_litpic'])) { // 图片类型
|
||||
// 读取组合广告位的图片及信息
|
||||
$i = 1;
|
||||
foreach ($post['img_litpic'] as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
// 去掉http:
|
||||
$value = str_replace("http:", "", $value);
|
||||
// 去掉https:
|
||||
$value = str_replace("https:", "", $value);
|
||||
// 是否新窗口打开
|
||||
$target = !empty($post['img_target'][$key]) ? 1 : 0;
|
||||
// 广告位ID,为空则表示添加
|
||||
$ad_id = $post['img_id'][$key];
|
||||
if (!empty($ad_id)) {
|
||||
// 查询更新条件
|
||||
$where = [
|
||||
'id' => $ad_id,
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
if ($ad_db->where($where)->count() > 0) {
|
||||
// 主要参数
|
||||
$AdData['litpic'] = $value;
|
||||
$AdData['title'] = $post['img_title'][$key];
|
||||
$AdData['links'] = $post['img_links'][$key];
|
||||
$AdData['intro'] = $post['img_intro'][$key];
|
||||
$AdData['target'] = $target;
|
||||
// 其他参数
|
||||
$AdData['sort_order'] = $i++;
|
||||
$AdData['update_time'] = getTime();
|
||||
// 更新,不需要同步多语言
|
||||
$ad_db->where($where)->update($AdData);
|
||||
} else {
|
||||
// 主要参数
|
||||
$AdData['litpic'] = $value;
|
||||
$AdData['pid'] = $post['id'];
|
||||
$AdData['title'] = $post['img_title'][$key];
|
||||
$AdData['links'] = $post['img_links'][$key];
|
||||
$AdData['intro'] = $post['img_intro'][$key];
|
||||
$AdData['target'] = $target;
|
||||
// 其他参数
|
||||
$AdData['media_type'] = 1;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = $i++;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_id = $ad_db->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
}
|
||||
} else {
|
||||
// 主要参数
|
||||
$AdData['litpic'] = $value;
|
||||
$AdData['pid'] = $post['id'];
|
||||
$AdData['title'] = $post['img_title'][$key];
|
||||
$AdData['links'] = $post['img_links'][$key];
|
||||
$AdData['intro'] = $post['img_intro'][$key];
|
||||
$AdData['target'] = $target;
|
||||
// 其他参数
|
||||
$AdData['media_type'] = 1;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = $i++;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_id = $ad_db->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (2 == $post['type'] && !empty($post['video_litpic'])) { // 媒体类型
|
||||
// 去掉http:
|
||||
$video_litpic = str_replace("http:", "", $post['video_litpic']);
|
||||
// 去掉https:
|
||||
$video_litpic = str_replace("https:", "", $post['video_litpic']);
|
||||
if (!empty($post['video_id'])) {
|
||||
// 更新广告内容
|
||||
$AdData['litpic'] = $video_litpic;
|
||||
$AdData['title'] = trim($post['title']);
|
||||
$AdData['media_type'] = 2;
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_db->where('id', $post['video_id'])->update($AdData);
|
||||
} else {
|
||||
// 新增广告内容
|
||||
$AdData['litpic'] = $video_litpic;
|
||||
$AdData['pid'] = $post['id'];
|
||||
$AdData['title'] = trim($post['title']);
|
||||
$AdData['links'] = '';
|
||||
$AdData['intro'] = '';
|
||||
$AdData['target'] = 0;
|
||||
$AdData['media_type'] = 2;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = 1;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_id = $ad_db->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
}
|
||||
|
||||
} else if (3 == $post['type'] && !empty($post['html_intro'])) { // HTML代码
|
||||
if (!empty($post['html_id'])) {
|
||||
// 更新广告内容
|
||||
$AdData['title'] = trim($post['title']);
|
||||
$AdData['intro'] = $post['html_intro'];
|
||||
$AdData['media_type'] = 3;
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_db->where('id', $post['html_id'])->update($AdData);
|
||||
} else {
|
||||
// 新增广告内容
|
||||
$AdData['litpic'] = '';
|
||||
$AdData['pid'] = $post['id'];
|
||||
$AdData['title'] = trim($post['title']);
|
||||
$AdData['intro'] = $post['html_intro'];
|
||||
$AdData['links'] = '';
|
||||
$AdData['target'] = 0;
|
||||
$AdData['media_type'] = 3;
|
||||
$AdData['admin_id'] = session('admin_id');
|
||||
$AdData['lang'] = $this->admin_lang;
|
||||
$AdData['sort_order'] = 1;
|
||||
$AdData['add_time'] = getTime();
|
||||
$AdData['update_time'] = getTime();
|
||||
$ad_id = $ad_db->add($AdData);
|
||||
// 同步多语言
|
||||
$this->syn_add_ad_language_attribute($ad_id);
|
||||
}
|
||||
|
||||
}
|
||||
adminLog('编辑广告:'.$post['title']);
|
||||
$this->success("操作成功", url('AdPosition/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('ad_position')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
|
||||
if (empty($field)) $this->error('广告不存在,请联系管理员!');
|
||||
switch ($field['type']) {
|
||||
case '1':
|
||||
$field['type_name'] = '图片';
|
||||
break;
|
||||
case '2':
|
||||
$field['type_name'] = '多媒体';
|
||||
break;
|
||||
case '3':
|
||||
$field['type_name'] = 'HTML代码';
|
||||
break;
|
||||
}
|
||||
$assign_data['field'] = $field;
|
||||
|
||||
// 广告
|
||||
$ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
|
||||
foreach ($ad_data as $key => $val) {
|
||||
if (1 == $val['type']) {
|
||||
$ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
|
||||
}
|
||||
}
|
||||
$assign_data['ad_data'] = $ad_data;
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$upload_max_filesize = intval($min_size) * 1024 * 1024;
|
||||
$assign_data['upload_max_filesize'] = $upload_max_filesize;
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$assign_data['media_type'] = $media_type;
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告图片
|
||||
*/
|
||||
public function del_imgupload()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = Db::name('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
|
||||
Db::name('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
foreach ($id_arr as $key => $val) {
|
||||
if(array_key_exists($val, $this->ad_position_system_id)){
|
||||
$this->error('系统预定义,不能删除');
|
||||
}
|
||||
}
|
||||
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'adp'.$val;
|
||||
}
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad_position',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = M('ad_position')->where('id','IN',$id_arr)->delete();
|
||||
if ($r) {
|
||||
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
M('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad_position',
|
||||
])->delete();
|
||||
M('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad_position',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
M('ad')->where('pid','IN',$id_arr)->delete();
|
||||
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开预览视频
|
||||
*/
|
||||
public function open_preview_video()
|
||||
{
|
||||
$post = input('post.');
|
||||
$video_litpic = $post['video_litpic'];
|
||||
if (!is_http_url($video_litpic)) {
|
||||
$video_litpic = request()->domain() . handle_subdir_pic($video_litpic, 'media');
|
||||
}
|
||||
$this->success('执行成功', $video_litpic);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测广告名称是否存在重复
|
||||
*/
|
||||
public function detection_title_repeat()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('post.');
|
||||
$where = [
|
||||
'id' => ['NEQ', $post['id']],
|
||||
'title' => trim($post['title']),
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
$count = Db::name('ad_position')->where($where)->count();
|
||||
if (empty($count)) {
|
||||
$this->success('检测通过');
|
||||
} else {
|
||||
$this->error('该广告名称已存在,请检查');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步新增广告位置ID到多语言的模板变量里
|
||||
*/
|
||||
private function syn_add_language_attribute($adp_id)
|
||||
{
|
||||
/*单语言情况下不执行多语言代码*/
|
||||
if (!is_language()) {
|
||||
return true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$attr_group = 'ad_position';
|
||||
$admin_lang = $this->admin_lang;
|
||||
$main_lang = $this->main_lang;
|
||||
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
|
||||
$ad_position_db = Db::name('ad_position');
|
||||
$result = $ad_position_db->find($adp_id);
|
||||
$attr_name = 'adp'.$adp_id;
|
||||
$r = Db::name('language_attribute')->save([
|
||||
'attr_title' => $result['title'],
|
||||
'attr_name' => $attr_name,
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if (false !== $r) {
|
||||
$data = [];
|
||||
foreach ($languageRow as $key => $val) {
|
||||
/*同步新广告位置到其他语言广告位置列表*/
|
||||
if ($val['mark'] != $admin_lang) {
|
||||
$addsaveData = $result;
|
||||
$addsaveData['lang'] = $val['mark'];
|
||||
$addsaveData['title'] = $val['mark'].$addsaveData['title'];
|
||||
unset($addsaveData['id']);
|
||||
$adp_id = $ad_position_db->insertGetId($addsaveData);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*所有语言绑定在主语言的ID容器里*/
|
||||
$data[] = [
|
||||
'attr_name' => $attr_name,
|
||||
'attr_value' => $adp_id,
|
||||
'lang' => $val['mark'],
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
/*--end*/
|
||||
}
|
||||
if (!empty($data)) {
|
||||
model('LanguageAttr')->saveAll($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步新增广告ID到多语言的模板变量里
|
||||
*/
|
||||
private function syn_add_ad_language_attribute($ad_id)
|
||||
{
|
||||
/*单语言情况下不执行多语言代码*/
|
||||
if (!is_language()) {
|
||||
return true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$attr_group = 'ad';
|
||||
$admin_lang = $this->admin_lang;
|
||||
$main_lang = get_main_lang();
|
||||
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
|
||||
$ad_db = Db::name('ad');
|
||||
$result = $ad_db->find($ad_id);
|
||||
$attr_name = 'ad'.$ad_id;
|
||||
$r = Db::name('language_attribute')->save([
|
||||
'attr_title' => $result['title'],
|
||||
'attr_name' => $attr_name,
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if (false !== $r) {
|
||||
$data = [];
|
||||
foreach ($languageRow as $key => $val) {
|
||||
/*同步新广告到其他语言广告列表*/
|
||||
if ($val['mark'] != $admin_lang) {
|
||||
$addsaveData = $result;
|
||||
$addsaveData['lang'] = $val['mark'];
|
||||
$newPid = Db::name('language_attr')->where([
|
||||
'attr_name' => 'adp'.$result['pid'],
|
||||
'attr_group' => 'ad_position',
|
||||
'lang' => $val['mark'],
|
||||
])->getField('attr_value');
|
||||
$addsaveData['pid'] = $newPid;
|
||||
$addsaveData['title'] = $val['mark'].$addsaveData['title'];
|
||||
unset($addsaveData['id']);
|
||||
$ad_id = $ad_db->insertGetId($addsaveData);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*所有语言绑定在主语言的ID容器里*/
|
||||
$data[] = [
|
||||
'attr_name' => $attr_name,
|
||||
'attr_value' => $ad_id,
|
||||
'lang' => $val['mark'],
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
/*--end*/
|
||||
}
|
||||
if (!empty($data)) {
|
||||
model('LanguageAttr')->saveAll($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
827
src/application/admin/controller/Admin.php
Normal file
827
src/application/admin/controller/Admin.php
Normal file
@@ -0,0 +1,827 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Verify;
|
||||
use think\Db;
|
||||
use think\db\Query;
|
||||
use think\Session;
|
||||
use app\admin\model\AuthRole;
|
||||
use app\admin\logic\AjaxLogic;
|
||||
|
||||
class Admin extends Base {
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
$condition = array();
|
||||
if (!empty($keywords)) {
|
||||
$condition['a.user_name|a.true_name'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$condition['a.admin_id|a.parent_id'] = $admin_info['admin_id'];
|
||||
} else {
|
||||
if (!empty($admin_info['parent_id'])) {
|
||||
$condition['a.admin_id|a.parent_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/**
|
||||
* 数据查询
|
||||
*/
|
||||
$count = DB::name('admin')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('admin')->field('a.*, b.name AS role_name')
|
||||
->alias('a')
|
||||
->join('__AUTH_ROLE__ b', 'a.role_id = b.id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.admin_id asc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->select();
|
||||
|
||||
foreach ($list as $key => $val) {
|
||||
if (0 >= intval($val['role_id'])) {
|
||||
$val['role_name'] = !empty($val['parent_id']) ? '超级管理员' : '创始人';
|
||||
}
|
||||
$list[$key] = $val;
|
||||
}
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页集
|
||||
|
||||
/*第一次同步CMS用户的栏目ID到权限组里*/
|
||||
$this->syn_built_auth_role();
|
||||
/*--end*/
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 管理员登陆
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if (session('?admin_id') && session('admin_id') > 0) {
|
||||
$web_adminbasefile = tpCache('web.web_adminbasefile');
|
||||
$web_adminbasefile = !empty($web_adminbasefile) ? $web_adminbasefile : '/login.php';
|
||||
$this->success("您已登录", $web_adminbasefile);
|
||||
}
|
||||
|
||||
// $gb_funcs = get_extension_funcs('gd');
|
||||
$is_vertify = 1; // 默认开启验证码
|
||||
$admin_login_captcha = config('captcha.admin_login');
|
||||
if (!function_exists('imagettftext') || empty($admin_login_captcha['is_on'])) {
|
||||
$is_vertify = 0; // 函数不存在,不符合开启的条件
|
||||
}
|
||||
$this->assign('is_vertify', $is_vertify);
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$post = input('post.');
|
||||
|
||||
if (!function_exists('session_start')) {
|
||||
$this->error('请联系空间商,开启php的session扩展!');
|
||||
}
|
||||
if (!testWriteAble(ROOT_PATH.config('session.path').'/')) {
|
||||
$this->error('请仔细检查以下问题:<br/>1、磁盘空间大小是否100%;<br/>2、站点目录权限是否为755;<br/>3、站点所有目录的权限,禁止用root:root ;<br/>4、如还没解决,请点击:<a href="http://www.eyoucms.com/wenda/6958.html" target="_blank">查看教程</a>');
|
||||
}
|
||||
|
||||
if (1 == $is_vertify) {
|
||||
$verify = new Verify();
|
||||
if (!$verify->check(input('post.vertify'), "admin_login")) {
|
||||
$this->error('验证码错误');
|
||||
}
|
||||
}
|
||||
|
||||
$is_clicap = 0; // 默认关闭文字验证码
|
||||
if (is_dir('./weapp/Clicap/')) {
|
||||
$ClicapRow = model('Weapp')->getWeappList('Clicap');
|
||||
if (!empty($ClicapRow['status']) && 1 == $ClicapRow['status']) {
|
||||
if (!empty($ClicapRow['data']) && $ClicapRow['data']['captcha']['admin_login']['is_on'] == 1) {
|
||||
$clicaptcha_info = input('post.clicaptcha-submit-info');
|
||||
$clicaptcha = new \weapp\Clicap\vendor\Clicaptcha;
|
||||
if (empty($clicaptcha_info) || !$clicaptcha->check($clicaptcha_info, false)) {
|
||||
$this->error('文字点击验证错误!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user_name = input('post.user_name/s');
|
||||
$password = input('post.password/s');
|
||||
|
||||
/*登录错误次数的限制*/
|
||||
/* $ststem_login_errnum_key = 'system_'.md5('login_errnum_'.$user_name);
|
||||
$ststem_login_errtime_key = 'system_'.md5('login_errtime_'.$user_name);
|
||||
$loginErrtotal = config('login_errtotal'); // 限定最大的登录错误次数
|
||||
$loginErrexpire = config('login_errexpire'); // 限定登录错误锁定有效时间
|
||||
$loginErrnum = tpCache('system.'.$ststem_login_errnum_key); // 登录错误次数
|
||||
$loginErrtime = tpCache('system.'.$ststem_login_errtime_key); // 最后一次登录错误时间
|
||||
if (intval($loginErrnum) >= intval($loginErrtotal)) {
|
||||
if (getTime() < $loginErrtime + $loginErrexpire) {
|
||||
adminLog('登录失败(已被锁定)');
|
||||
$this->error("登录错误次数超限,用户名被锁定15分钟!");
|
||||
} else {
|
||||
// 重置登录错误次数
|
||||
$loginErrnum = 0;
|
||||
$loginErrtime = 0;
|
||||
tpCache('system', [$ststem_login_errnum_key => $loginErrnum]);
|
||||
tpCache('system', [$ststem_login_errtime_key => $loginErrtime]);
|
||||
}
|
||||
}*/
|
||||
/*end*/
|
||||
|
||||
$condition['user_name'] = $user_name;
|
||||
$condition['password'] = $password;
|
||||
if (!empty($condition['user_name']) && !empty($condition['password'])) {
|
||||
$condition['password'] = func_encrypt($condition['password']);
|
||||
$admin_info = M('admin')->where($condition)->find();
|
||||
if (empty($admin_info)) {
|
||||
adminLog('登录失败(用户名/密码错误)');
|
||||
/*记录登录错误次数*/
|
||||
/*$login_num = intval($loginErrtotal) - intval($loginErrnum);
|
||||
$ststem_login_errnum = $loginErrnum + 1;
|
||||
tpCache('system', [$ststem_login_errnum_key=>$ststem_login_errnum]);
|
||||
tpCache('system', [$ststem_login_errtime_key=>getTime()]);
|
||||
$this->error("用户名或密码错误,您还可以尝试[{$login_num}]次!");*/
|
||||
$this->error("用户名或密码错误!");
|
||||
/*end*/
|
||||
} else {
|
||||
if ($admin_info['status'] == 0) {
|
||||
adminLog('登录失败(用户名被禁用)');
|
||||
$this->error('用户名被禁用!');
|
||||
}
|
||||
|
||||
$role_id = !empty($admin_info['role_id']) ? $admin_info['role_id'] : -1;
|
||||
$auth_role_info = array();
|
||||
if (!empty($admin_info['parent_id'])) {
|
||||
$role_name = '超级管理员';
|
||||
$isFounder = 0;
|
||||
} else {
|
||||
$role_name = '创始人';
|
||||
$isFounder = 1;
|
||||
}
|
||||
if (0 < intval($role_id)) {
|
||||
$auth_role_info = M('auth_role')
|
||||
->field("a.*, a.name AS role_name")
|
||||
->alias('a')
|
||||
->where('a.id','eq', $role_id)
|
||||
->find();
|
||||
if (!empty($auth_role_info)) {
|
||||
$auth_role_info['language'] = unserialize($auth_role_info['language']);
|
||||
$auth_role_info['cud'] = unserialize($auth_role_info['cud']);
|
||||
$auth_role_info['permission'] = unserialize($auth_role_info['permission']);
|
||||
$role_name = $auth_role_info['name'];
|
||||
}
|
||||
}
|
||||
$admin_info['auth_role_info'] = $auth_role_info;
|
||||
$admin_info['role_name'] = $role_name;
|
||||
|
||||
$last_login_time = getTime();
|
||||
$last_login_ip = clientIP();
|
||||
$login_cnt = $admin_info['login_cnt'] + 1;
|
||||
M('admin')->where("admin_id = ".$admin_info['admin_id'])->save(array('last_login'=>$last_login_time, 'last_ip'=>$last_login_ip, 'login_cnt'=>$login_cnt, 'session_id'=>$this->session_id));
|
||||
$admin_info['last_login'] = $last_login_time;
|
||||
$admin_info['last_ip'] = $last_login_ip;
|
||||
|
||||
// 头像
|
||||
empty($admin_info['head_pic']) && $admin_info['head_pic'] = get_head_pic($admin_info['head_pic'], true);
|
||||
|
||||
$admin_info_new = $admin_info;
|
||||
/*过滤存储在session文件的敏感信息*/
|
||||
foreach (['user_name','true_name','password'] as $key => $val) {
|
||||
unset($admin_info_new[$val]);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
session('admin_id',$admin_info['admin_id']);
|
||||
session('admin_info', $admin_info_new);
|
||||
session('admin_login_expire', getTime()); // 登录有效期
|
||||
|
||||
/*检查密码复杂度*/
|
||||
$admin_login_pwdlevel = checkPasswordLevel($password);
|
||||
session('admin_login_pwdlevel', $admin_login_pwdlevel);
|
||||
/*end*/
|
||||
|
||||
// 重置登录错误次数
|
||||
/*tpCache('system', [$ststem_login_errnum_key=>0]);
|
||||
tpCache('system', [$ststem_login_errtime_key=>0]);*/
|
||||
|
||||
adminLog('后台登录');
|
||||
$url = session('from_url') ? session('from_url') : $this->request->baseFile();
|
||||
session('isset_author', null); // 内置勿动
|
||||
|
||||
/*同步追加一个后台管理员到会员用户表*/
|
||||
$this->syn_users_login($admin_info, $isFounder);
|
||||
/* END */
|
||||
|
||||
$this->success('登录成功', $url);
|
||||
}
|
||||
} else {
|
||||
$this->error('请填写用户名/密码');
|
||||
}
|
||||
}
|
||||
|
||||
$ajaxLogic = new AjaxLogic;
|
||||
$ajaxLogic->login_handle();
|
||||
|
||||
session('admin_info', null);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码获取
|
||||
*/
|
||||
public function vertify()
|
||||
{
|
||||
/*验证码插件开关*/
|
||||
$admin_login_captcha = config('captcha.admin_login');
|
||||
$config = (!empty($admin_login_captcha['is_on']) && !empty($admin_login_captcha['config'])) ? $admin_login_captcha['config'] : config('captcha.default');
|
||||
/*--end*/
|
||||
ob_clean(); // 清空缓存,才能显示验证码
|
||||
$Verify = new Verify($config);
|
||||
$Verify->entry('admin_login');
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改管理员密码
|
||||
* @return \think\mixed
|
||||
*/
|
||||
public function admin_pwd()
|
||||
{
|
||||
$admin_id = input('admin_id/d',0);
|
||||
$oldPwd = input('old_pw/s');
|
||||
$newPwd = input('new_pw/s');
|
||||
$new2Pwd = input('new_pw2/s');
|
||||
|
||||
if(!$admin_id){
|
||||
$admin_id = session('admin_id');
|
||||
}
|
||||
$info = M('admin')->where("admin_id", $admin_id)->find();
|
||||
$info['password'] = "";
|
||||
$this->assign('info',$info);
|
||||
|
||||
if(IS_POST){
|
||||
//修改密码
|
||||
$enOldPwd = func_encrypt($oldPwd);
|
||||
$enNewPwd = func_encrypt($newPwd);
|
||||
$admin = M('admin')->where('admin_id' , $admin_id)->find();
|
||||
if(!$admin || $admin['password'] != $enOldPwd){
|
||||
exit(json_encode(array('status'=>-1,'msg'=>'旧密码不正确')));
|
||||
}else if($newPwd != $new2Pwd){
|
||||
exit(json_encode(array('status'=>-1,'msg'=>'两次密码不一致')));
|
||||
}else{
|
||||
$data = array(
|
||||
'update_time' => getTime(),
|
||||
'password' => $enNewPwd,
|
||||
);
|
||||
$row = M('admin')->where('admin_id' , $admin_id)->save($data);
|
||||
if($row){
|
||||
/*检查密码复杂度*/
|
||||
$admin_login_pwdlevel = checkPasswordLevel($newPwd);
|
||||
session('admin_login_pwdlevel', $admin_login_pwdlevel);
|
||||
/*end*/
|
||||
adminLog('修改管理员密码');
|
||||
exit(json_encode(array('status'=>1,'msg'=>'操作成功')));
|
||||
}else{
|
||||
exit(json_encode(array('status'=>-1,'msg'=>'操作失败')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX) {
|
||||
return $this->fetch('admin/admin_pwd_ajax');
|
||||
} else {
|
||||
return $this->fetch('admin/admin_pwd');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登陆
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
adminLog('安全退出');
|
||||
session_unset();
|
||||
// session_destroy();
|
||||
session::clear();
|
||||
cookie('admin-treeClicked', null); // 清除并恢复栏目列表的展开方式
|
||||
$this->success("安全退出", request()->baseFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增管理员时,检测用户名是否与前台用户名相同
|
||||
*/
|
||||
public function ajax_add_user_name()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$user_name = input('post.user_name/s');
|
||||
if (M('admin')->where("user_name", $user_name)->count()) {
|
||||
$this->error("此用户名已被注册,请更换!");
|
||||
}
|
||||
$row = Db::name('users')->field('users_id')->where([
|
||||
'username' => $user_name,
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
if (!empty($row)) {
|
||||
$this->error('已有相同会员名,将其转为系统账号?');
|
||||
} else {
|
||||
$this->success('会员名不存在,无需提示!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增管理员
|
||||
*/
|
||||
public function admin_add()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$data = input('post.');
|
||||
|
||||
if (0 < intval(session('admin_info.role_id'))) {
|
||||
$this->error("超级管理员才能操作!");
|
||||
}
|
||||
|
||||
if (empty($data['password'])) {
|
||||
$this->error("密码不能为空!");
|
||||
}
|
||||
|
||||
$data['user_name'] = trim($data['user_name']);
|
||||
$data['password'] = func_encrypt($data['password']);
|
||||
$data['role_id'] = intval($data['role_id']);
|
||||
$data['parent_id'] = session('admin_info.admin_id');
|
||||
$data['add_time'] = getTime();
|
||||
if (empty($data['pen_name'])) {
|
||||
$data['pen_name'] = $data['user_name'];
|
||||
}
|
||||
if (M('admin')->where("user_name", $data['user_name'])->count()) {
|
||||
$this->error("此用户名已被注册,请更换",url('Admin/admin_add'));
|
||||
} else {
|
||||
$admin_id = M('admin')->insertGetId($data);
|
||||
if ($admin_id) {
|
||||
adminLog('新增管理员:'.$data['user_name']);
|
||||
|
||||
/*同步追加一个后台管理员到会员用户表*/
|
||||
try {
|
||||
$usersInfo = Db::name('users')->field('users_id')->where([
|
||||
'username' => $data['user_name'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
if (!empty($usersInfo)) {
|
||||
$r = Db::name('users')->where(['users_id'=>$usersInfo['users_id']])->update([
|
||||
'nickname' => $data['user_name'],
|
||||
'admin_id' => $admin_id,
|
||||
'is_activation' => 1,
|
||||
'is_lock' => 0,
|
||||
'is_del' => 0,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
!empty($r) && $users_id = $usersInfo['users_id'];
|
||||
} else {
|
||||
// 获取要添加的用户名
|
||||
$username = $this->GetUserName($data['user_name']);
|
||||
$AddData = [
|
||||
'username' => $username,
|
||||
'nickname' => $username,
|
||||
'password' => func_encrypt(getTime()),
|
||||
'level' => 1,
|
||||
'lang' => $this->admin_lang,
|
||||
'reg_time' => getTime(),
|
||||
'add_time' => getTime(),
|
||||
'head_pic' => ROOT_DIR . '/public/static/common/images/dfboy.png',
|
||||
'register_place' => 1,
|
||||
'admin_id' => $admin_id,
|
||||
];
|
||||
$users_id = Db::name('users')->insertGetId($AddData);
|
||||
}
|
||||
if (!empty($users_id)) {
|
||||
Db::name('admin')->where(['admin_id'=>$admin_id])->update([
|
||||
'syn_users_id' => $users_id,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
/* END */
|
||||
|
||||
$this->success("操作成功", url('Admin/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 权限组
|
||||
$admin_role_list = model('AuthRole')->getRoleAll();
|
||||
$this->assign('admin_role_list', $admin_role_list);
|
||||
|
||||
// 模块组
|
||||
$modules = getAllMenu();
|
||||
$this->assign('modules', $modules);
|
||||
|
||||
// 权限集
|
||||
$auth_rules = get_auth_rule(['is_modules'=>1]);
|
||||
$auth_rule_list = group_same_key($auth_rules, 'menu_id');
|
||||
foreach ($auth_rule_list as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$sort_order = [];
|
||||
foreach ($val as $_k => $_v) {
|
||||
$sort_order[$_k] = $_v['sort_order'];
|
||||
}
|
||||
array_multisort($sort_order, SORT_ASC, $val);
|
||||
$auth_rule_list[$key] = $val;
|
||||
}
|
||||
}
|
||||
$this->assign('auth_rule_list', $auth_rule_list);
|
||||
|
||||
// 栏目
|
||||
$arctype_data = $arctype_array = array();
|
||||
$arctype = M('arctype')->select();
|
||||
if(! empty($arctype)){
|
||||
foreach ($arctype as $item){
|
||||
if($item['parent_id'] <= 0){
|
||||
$arctype_data[] = $item;
|
||||
}
|
||||
$arctype_array[$item['parent_id']][] = $item;
|
||||
}
|
||||
}
|
||||
$this->assign('arctypes', $arctype_data);
|
||||
$this->assign('arctype_array', $arctype_array);
|
||||
|
||||
// 插件
|
||||
$plugins = model('Weapp')->getList(['status'=>1]);
|
||||
$this->assign('plugins', $plugins);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑管理员
|
||||
*/
|
||||
public function admin_edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$data = input('post.');
|
||||
$id = $data['admin_id'];
|
||||
|
||||
if ($id == session('admin_info.admin_id')) {
|
||||
unset($data['role_id']); // 不能修改自己的权限组
|
||||
} else if (0 < intval(session('admin_info.role_id')) && session('admin_info.admin_id') != $id) {
|
||||
$this->error('禁止更改别人的信息!');
|
||||
}
|
||||
|
||||
$password = $data['password'];
|
||||
$user_name = $data['user_name'];
|
||||
if(empty($password)){
|
||||
unset($data['password']);
|
||||
}else{
|
||||
$data['password'] = func_encrypt($password);
|
||||
}
|
||||
unset($data['user_name']);
|
||||
|
||||
if (empty($data['pen_name'])) {
|
||||
$data['pen_name'] = $user_name;
|
||||
}
|
||||
|
||||
/*不允许修改自己的权限组*/
|
||||
if (isset($data['role_id'])) {
|
||||
if (0 < intval(session('admin_info.role_id')) && intval($data['role_id']) != session('admin_info.role_id')) {
|
||||
$data['role_id'] = session('admin_info.role_id');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$data['update_time'] = getTime();
|
||||
$r = M('admin')->where('admin_id', $id)->save($data);
|
||||
if ($r) {
|
||||
/*检查密码复杂度*/
|
||||
if ($id == session('admin_info.admin_id')) {
|
||||
$admin_login_pwdlevel = checkPasswordLevel($password);
|
||||
session('admin_login_pwdlevel', $admin_login_pwdlevel);
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/*过滤存储在session文件的敏感信息*/
|
||||
if ($id == session('admin_info.admin_id')) {
|
||||
$admin_info = session('admin_info');
|
||||
$admin_info = array_merge($admin_info, $data);
|
||||
foreach (['user_name','true_name','password'] as $key => $val) {
|
||||
unset($admin_info[$val]);
|
||||
}
|
||||
session('admin_info', $admin_info);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*同步相同数据到会员表对应的会员*/
|
||||
$syn_users_id = Db::name('admin')->where(['admin_id'=>$data['admin_id']])->getField('syn_users_id');
|
||||
if (!empty($syn_users_id)) {
|
||||
$updateData = [
|
||||
'nickname' => $data['pen_name'],
|
||||
'head_pic' => $data['head_pic'],
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
Db::name('users')->where(['users_id'=>$syn_users_id])->update($updateData);
|
||||
}
|
||||
/*end*/
|
||||
|
||||
adminLog('编辑管理员:'.$user_name);
|
||||
$this->success("操作成功",url('Admin/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$id = input('get.id/d', 0);
|
||||
$info = M('admin')->field('a.*')
|
||||
->alias('a')
|
||||
->where("a.admin_id", $id)->find();
|
||||
$info['password'] = "";
|
||||
$this->assign('info',$info);
|
||||
|
||||
// 当前角色信息
|
||||
$admin_role_model = model('AuthRole');
|
||||
$role_info = $admin_role_model->getRole(array('id' => $info['role_id']));
|
||||
$this->assign('role_info', $role_info);
|
||||
|
||||
// 权限组
|
||||
$admin_role_list = $admin_role_model->getRoleAll();
|
||||
$this->assign('admin_role_list', $admin_role_list);
|
||||
|
||||
// 模块组
|
||||
$modules = getAllMenu();
|
||||
$this->assign('modules', $modules);
|
||||
|
||||
// 权限集
|
||||
$auth_rules = get_auth_rule(['is_modules'=>1]);
|
||||
$auth_rule_list = group_same_key($auth_rules, 'menu_id');
|
||||
foreach ($auth_rule_list as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$sort_order = [];
|
||||
foreach ($val as $_k => $_v) {
|
||||
$sort_order[$_k] = $_v['sort_order'];
|
||||
}
|
||||
array_multisort($sort_order, SORT_ASC, $val);
|
||||
$auth_rule_list[$key] = $val;
|
||||
}
|
||||
}
|
||||
$this->assign('auth_rule_list', $auth_rule_list);
|
||||
|
||||
// 栏目
|
||||
$arctype_data = $arctype_array = array();
|
||||
$arctype = M('arctype')->select();
|
||||
if(! empty($arctype)){
|
||||
foreach ($arctype as $item){
|
||||
if($item['parent_id'] <= 0){
|
||||
$arctype_data[] = $item;
|
||||
}
|
||||
$arctype_array[$item['parent_id']][] = $item;
|
||||
}
|
||||
}
|
||||
$this->assign('arctypes', $arctype_data);
|
||||
$this->assign('arctype_array', $arctype_array);
|
||||
|
||||
// 插件
|
||||
$plugins = model('Weapp')->getList(['status'=>1]);
|
||||
$this->assign('plugins', $plugins);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员
|
||||
*/
|
||||
public function admin_del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if (in_array(session('admin_id'), $id_arr)) {
|
||||
$this->error('禁止删除自己');
|
||||
}
|
||||
if (!empty($id_arr)) {
|
||||
if (0 < intval(session('admin_info.role_id')) || !empty($parent_id) ) {
|
||||
$count = M('admin')->where("admin_id in (".implode(',', $id_arr).") AND role_id = -1")
|
||||
->count();
|
||||
if (!empty($count)) {
|
||||
$this->error('禁止删除超级管理员');
|
||||
}
|
||||
}
|
||||
|
||||
$result = M('admin')->field('user_name')->where("admin_id",'IN',$id_arr)->select();
|
||||
$user_names = get_arr_column($result, 'user_name');
|
||||
|
||||
$r = M('admin')->where("admin_id",'IN',$id_arr)->delete();
|
||||
if($r){
|
||||
adminLog('删除管理员:'.implode(',', $user_names));
|
||||
|
||||
/*同步删除管理员关联的前台会员*/
|
||||
Db::name('users')->where(['admin_id'=>['IN', $id_arr],'lang'=>$this->admin_lang])->delete();
|
||||
/*end*/
|
||||
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
$this->error('非法操作');
|
||||
}
|
||||
|
||||
/*
|
||||
* 第一次同步CMS用户的栏目ID到权限组里
|
||||
* 默认赋予内置权限所有的内容栏目权限
|
||||
*/
|
||||
private function syn_built_auth_role()
|
||||
{
|
||||
$authRole = new AuthRole;
|
||||
$roleRow = $authRole->getRoleAll(['built_in'=>1,'update_time'=>['elt',0]]);
|
||||
if (!empty($roleRow)) {
|
||||
$saveData = [];
|
||||
foreach ($roleRow as $key => $val) {
|
||||
$permission = $val['permission'];
|
||||
$arctype = M('arctype')->where('status',1)->column('id');
|
||||
if (!empty($arctype)) {
|
||||
$permission['arctype'] = $arctype;
|
||||
} else {
|
||||
unset($permission['arctype']);
|
||||
}
|
||||
$saveData[] = array(
|
||||
'id' => $val['id'],
|
||||
'permission' => $permission,
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
}
|
||||
$authRole->saveAll($saveData);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 设置admin表数据
|
||||
*/
|
||||
public function ajax_setfield()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$admin_id = session('admin_id');
|
||||
$field = input('field'); // 修改哪个字段
|
||||
$value = input('value', '', null); // 修改字段值
|
||||
if (!empty($admin_id)) {
|
||||
$r = M('admin')->where('admin_id',intval($admin_id))->save([
|
||||
$field=>$value,
|
||||
'update_time'=>getTime(),
|
||||
]); // 根据条件保存修改的数据
|
||||
if ($r) {
|
||||
/*更新存储在session里的信息*/
|
||||
$admin_info = session('admin_info');
|
||||
$admin_info[$field] = $value;
|
||||
session('admin_info', $admin_info);
|
||||
/*--end*/
|
||||
$this->success('操作成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
/*
|
||||
* 检测密码的复杂程度
|
||||
*/
|
||||
public function ajax_checkPasswordLevel()
|
||||
{
|
||||
$password = input('post.password/s');
|
||||
if (IS_AJAX_POST && !empty($password)) {
|
||||
$pwdLevel = checkPasswordLevel($password);
|
||||
if (3 >= $pwdLevel) {
|
||||
$this->success("<font color='red'>当前密码复杂度为 {$pwdLevel} ,建议复杂度在 4~7 范围内,避免容易被暴力破解!</font>", null, ['pwdLevel'=>$pwdLevel]);
|
||||
} else {
|
||||
$this->success("<font color='green'>当前密码复杂度为 {$pwdLevel} ,在系统设定 4~7 安全范围内!</font>", null, ['pwdLevel'=>$pwdLevel]);
|
||||
}
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
// 确保用户名唯一
|
||||
private function GetUserName($username = null)
|
||||
{
|
||||
$count = Db::name('users')->where('username',$username)->count();
|
||||
if (!empty($count)) {
|
||||
$username_new = $username.rand(1000,9999);
|
||||
$username = $this->GetUserName($username_new);
|
||||
}
|
||||
|
||||
return $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步追加一个后台管理员到会员用户表,并同步前台登录
|
||||
*/
|
||||
private function syn_users_login($admin_info = [], $isFounder = 0)
|
||||
{
|
||||
$where_new = [
|
||||
'admin_id' => $admin_info['admin_id'],
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
$users_id = Db::name('users')->where($where_new)->getField('users_id');
|
||||
try {
|
||||
if (empty($users_id) && empty($admin_info['syn_users_id'])) {
|
||||
$usersInfo = [];
|
||||
if (1 == $isFounder) {
|
||||
// 如果是创始人,强制将与会员名相同的改为管理员前台用户名
|
||||
$usersInfo = Db::name('users')->field('users_id')->where([
|
||||
'username' => $admin_info['user_name'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
}
|
||||
if (!empty($usersInfo)) {
|
||||
$r = Db::name('users')->where(['users_id'=>$usersInfo['users_id']])->update([
|
||||
'nickname' => $admin_info['user_name'],
|
||||
'admin_id' => $admin_info['admin_id'],
|
||||
'is_activation' => 1,
|
||||
'is_lock' => 0,
|
||||
'is_del' => 0,
|
||||
'update_time' => getTime(),
|
||||
'last_login' => getTime(),
|
||||
]);
|
||||
!empty($r) && $users_id = $usersInfo['users_id'];
|
||||
} else {
|
||||
// 获取要添加的用户名
|
||||
$username = $this->GetUserName($admin_info['user_name']);
|
||||
$AddData = [
|
||||
'username' => $username,
|
||||
'nickname' => $username,
|
||||
'password' => func_encrypt(getTime()),
|
||||
'level' => 1,
|
||||
'lang' => $this->admin_lang,
|
||||
'reg_time' => getTime(),
|
||||
'head_pic' => ROOT_DIR . '/public/static/common/images/dfboy.png',
|
||||
'add_time' => getTime(),
|
||||
'last_login' => getTime(),
|
||||
'register_place' => 1,
|
||||
'admin_id' => $admin_info['admin_id'],
|
||||
];
|
||||
$users_id = Db::name('users')->insertGetId($AddData);
|
||||
}
|
||||
if (!empty($users_id)) {
|
||||
Db::name('admin')->where(['admin_id'=>$admin_info['admin_id']])->update([
|
||||
'syn_users_id' => $users_id,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
$admin_info['syn_users_id'] = $users_id;
|
||||
session('admin_info', $admin_info);
|
||||
}
|
||||
} else if (!empty($users_id) && empty($admin_info['syn_users_id'])) {
|
||||
Db::name('admin')->where(['admin_id'=>$admin_info['admin_id']])->update([
|
||||
'syn_users_id' => $users_id,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
$admin_info['syn_users_id'] = $users_id;
|
||||
session('admin_info', $admin_info);
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
// 加载前台session
|
||||
if (!empty($users_id)) {
|
||||
$users = M('users')->field('a.*,b.level_name,b.level_value,b.discount as level_discount')
|
||||
->alias('a')
|
||||
->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
|
||||
->where([
|
||||
'a.users_id' => $users_id,
|
||||
'a.lang' => $this->admin_lang,
|
||||
'a.is_activation' => 1,
|
||||
])->find();
|
||||
if (!empty($users)) {
|
||||
Db::name('users')->where(['users_id'=>$users_id])->update([
|
||||
'update_time' => getTime(),
|
||||
'last_login' => getTime(),
|
||||
]);
|
||||
GetUsersLatestData($users_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
124
src/application/admin/controller/Ajax.php
Normal file
124
src/application/admin/controller/Ajax.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
use think\Config;
|
||||
use app\admin\logic\AjaxLogic;
|
||||
|
||||
/**
|
||||
* 所有ajax请求或者不经过权限验证的方法全放在这里
|
||||
*/
|
||||
class Ajax extends Base {
|
||||
|
||||
private $ajaxLogic;
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->ajaxLogic = new AjaxLogic;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入欢迎页面需要异步处理的业务
|
||||
*/
|
||||
public function welcome_handle()
|
||||
{
|
||||
\think\Session::pause(); // 暂停session,防止session阻塞机制
|
||||
$this->ajaxLogic->welcome_handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏后台欢迎页的系统提示
|
||||
*/
|
||||
public function explanation_welcome()
|
||||
{
|
||||
\think\Session::pause(); // 暂停session,防止session阻塞机制
|
||||
$type = input('param.type/d', 0);
|
||||
$tpCacheKey = 'system_explanation_welcome';
|
||||
if (1 < $type) {
|
||||
$tpCacheKey .= '_'.$type;
|
||||
}
|
||||
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->field('mark')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('system', [$tpCacheKey=>1], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('system', [$tpCacheKey=>1]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本检测更新弹窗
|
||||
*/
|
||||
public function check_upgrade_version()
|
||||
{
|
||||
\think\Session::pause(); // 暂停session,防止session阻塞机制
|
||||
$upgradeLogic = new \app\admin\logic\UpgradeLogic;
|
||||
$security_patch = tpSetting('upgrade.upgrade_security_patch');
|
||||
if (!empty($security_patch) && 1 == $security_patch) {
|
||||
$upgradeMsg = $upgradeLogic->checkSecurityVersion(); // 安全补丁包消息
|
||||
} else {
|
||||
$upgradeMsg = $upgradeLogic->checkVersion(); // 升级包消息
|
||||
}
|
||||
$this->success('检测成功', null, $upgradeMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新stiemap.xml地图
|
||||
*/
|
||||
public function update_sitemap($controller, $action)
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
\think\Session::pause(); // 暂停session,防止session阻塞机制
|
||||
$channeltype_row = \think\Cache::get("extra_global_channeltype");
|
||||
if (empty($channeltype_row)) {
|
||||
$ctlArr = \think\Db::name('channeltype')
|
||||
->where('id','NOTIN', [6,8])
|
||||
->column('ctl_name');
|
||||
} else {
|
||||
$ctlArr = array();
|
||||
foreach($channeltype_row as $key => $val){
|
||||
if (!in_array($val['id'], [6,8])) {
|
||||
$ctlArr[] = $val['ctl_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$systemCtl= ['Arctype'];
|
||||
$ctlArr = array_merge($systemCtl, $ctlArr);
|
||||
$actArr = ['add','edit'];
|
||||
if (in_array($controller, $ctlArr) && in_array($action, $actArr)) {
|
||||
Session::pause(); // 暂停session,防止session阻塞机制
|
||||
sitemap_auto();
|
||||
$this->success('更新sitemap成功!');
|
||||
}
|
||||
}
|
||||
|
||||
$this->error('更新sitemap失败!');
|
||||
}
|
||||
|
||||
// 开启\关闭余额支付
|
||||
public function BalancePayOpen()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$open_value = input('post.open_value/d');
|
||||
getUsersConfigData('pay', ['pay_balance_open' => $open_value]);
|
||||
$this->success('操作成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
921
src/application/admin/controller/Archives.php
Normal file
921
src/application/admin/controller/Archives.php
Normal file
@@ -0,0 +1,921 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
use app\common\logic\ArctypeLogic;
|
||||
|
||||
class Archives extends Base
|
||||
{
|
||||
// 允许发布文档的模型ID
|
||||
public $allowReleaseChannel = array();
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->allowReleaseChannel = config('global.allow_release_channel');
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容管理
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$arctype_list = array();
|
||||
// 目录列表
|
||||
$arctypeLogic = new ArctypeLogic();
|
||||
$where['is_del'] = '0'; // 回收站功能
|
||||
$where['current_channel'] = ['neq',51]; // 问答模型
|
||||
$where['weapp_code'] = '';
|
||||
$arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, $where, false);
|
||||
$zNodes = "[";
|
||||
foreach ($arctype_list as $key => $val) {
|
||||
if ($val['current_channel'] == 5 && 1.5 > $this->php_servicemeal) {
|
||||
continue;
|
||||
}
|
||||
$current_channel = $val['current_channel'];
|
||||
if (!empty($val['weapp_code'])) {
|
||||
// 插件栏目
|
||||
$typeurl = weapp_url($val['weapp_code'].'/'.$val['weapp_code'].'/index');
|
||||
} else {
|
||||
if (6 == $current_channel) {
|
||||
$gourl = url('Arctype/single_edit', array('typeid'=>$val['id']));
|
||||
$typeurl = url("Arctype/single_edit", array('typeid'=>$val['id'],'gourl'=>$gourl));
|
||||
} else if (8 == $current_channel) {
|
||||
$typeurl = url("Guestbook/index", array('typeid'=>$val['id'], 'archives'=>1));
|
||||
} else {
|
||||
$typeurl = url('Archives/index_archives', array('typeid'=>$val['id']));
|
||||
}
|
||||
}
|
||||
$typename = $val['typename'];
|
||||
$zNodes .= "{"."id:{$val['id']}, pId:{$val['parent_id']}, name:\"{$typename}\", url:'{$typeurl}',target:'content_body'";
|
||||
/*默认展开一级栏目*/
|
||||
if (empty($val['parent_id'])) {
|
||||
$zNodes .= ",open:true";
|
||||
}
|
||||
/*--end*/
|
||||
/*栏目有下级栏目时,显示图标*/
|
||||
if (1 == $val['has_children']) {
|
||||
$zNodes .= ",isParent:true";
|
||||
} else {
|
||||
$zNodes .= ",isParent:false";
|
||||
}
|
||||
/*--end*/
|
||||
$zNodes .= "},";
|
||||
}
|
||||
$zNodes .= "]";
|
||||
$this->assign('zNodes', $zNodes);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容管理 - 所有文档列表风格(只针对ey_archives表,排除单页记录)
|
||||
*/
|
||||
public function index_archives()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有URL参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
|
||||
/*跳转到指定栏目的文档列表*/
|
||||
if (0 < intval($typeid)) {
|
||||
$row = Db::name('arctype')
|
||||
->alias('a')
|
||||
->field('b.ctl_name,b.id')
|
||||
->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
|
||||
->where('a.id', 'eq', $typeid)
|
||||
->find();
|
||||
$ctl_name = $row['ctl_name'];
|
||||
$current_channel = $row['id'];
|
||||
if (6 == $current_channel) {
|
||||
$gourl = url('Arctype/single_edit', array('typeid'=>$typeid));
|
||||
$gourl = url("Arctype/single_edit", array('typeid'=>$typeid,'gourl'=>$gourl));
|
||||
$this->redirect($gourl);
|
||||
} else if (8 == $current_channel) {
|
||||
$gourl = url("Guestbook/index", array('typeid'=>$typeid));
|
||||
$this->redirect($gourl);
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
if (empty($typeid)) {
|
||||
$typeids = [];
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
$typeids = $auth_role_info['permission']['arctype'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($typeids)) {
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if (empty($typeid)) {
|
||||
$id_tmp = [6,8];
|
||||
// 只显示允许发布文档的模型,且是开启状态
|
||||
$channelIds = Db::name('channeltype')->where('status',0)
|
||||
->whereOr('id','IN',$id_tmp)->column('id');
|
||||
$condition['a.channel'] = array('NOT IN', $channelIds);
|
||||
} else {
|
||||
// 只显示当前栏目对应模型下的文档
|
||||
$current_channel = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
|
||||
$condition['a.channel'] = array('eq', $current_channel);
|
||||
}
|
||||
|
||||
/*多语言*/
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
/*--end*/
|
||||
|
||||
/*回收站数据不显示*/
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
/*--end*/
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = Db::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = Db::name('archives')
|
||||
->field("a.aid,a.channel")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = Db::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/*获取当页文档的所有模型*/
|
||||
$channelIds = get_arr_column($list, 'channel');
|
||||
$channelRow = Db::name('channeltype')->field('id, ctl_name, ifsystem')
|
||||
->where('id','IN',$channelIds)
|
||||
->getAllWithIndex('id');
|
||||
$assign_data['channelRow'] = $channelRow;
|
||||
/*--end*/
|
||||
|
||||
$aids_channel2 = []; // 产品模型的文档ID
|
||||
foreach ($list as $key => $val) {
|
||||
if (2 == $val['channel']) {
|
||||
array_push($aids_channel2, $val['aid']);
|
||||
}
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
|
||||
// 产品参数
|
||||
$product_attr_row = [];
|
||||
if (!empty($aids_channel2)) {
|
||||
$product_attr_row = Db::name('product_attr')->field('count(product_attr_id) as num, aid')->where(['aid'=>['IN', $aids_channel2]])->group('aid')->getAllWithIndex('aid');
|
||||
}
|
||||
$assign_data['product_attr_row'] = $product_attr_row;
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename,current_channel')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$assign_data['arctype_html'] = allow_release_arctype($typeid, array());
|
||||
/*--end*/
|
||||
|
||||
/*前台URL模式*/
|
||||
$assign_data['seo_pseudo'] = tpCache('seo.seo_pseudo');
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
// 商城开关
|
||||
$assign_data['shop_open'] = getUsersConfigData('shop.shop_open');
|
||||
|
||||
/*是否存在栏目*/
|
||||
$assign_data['is_arctype'] = Db::name('arctype')->where([
|
||||
'is_del' => 0,
|
||||
'lang' => get_current_lang(),
|
||||
])->count();
|
||||
/*end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch('index_archives');
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容管理 - 栏目展开风格
|
||||
*/
|
||||
private function index_arctype() {
|
||||
$arctype_list = array();
|
||||
// 目录列表
|
||||
$arctypeLogic = new ArctypeLogic();
|
||||
$arctype_list = $arctypeLogic->arctype_list(0, 0, false, 0, array(), false);
|
||||
$this->assign('arctype_list', $arctype_list);
|
||||
|
||||
// 模型列表
|
||||
$channeltype_list = getChanneltypeList();
|
||||
$this->assign('channeltype_list', $channeltype_list);
|
||||
|
||||
// 栏目最多级别
|
||||
$arctype_max_level = intval(config('global.arctype_max_level'));
|
||||
$this->assign('arctype_max_level', $arctype_max_level);
|
||||
|
||||
// 允许发布文档的模型
|
||||
$this->assign('allow_release_channel', $this->allowReleaseChannel);
|
||||
|
||||
return $this->fetch('index_arctype');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布文档
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
if (!empty($typeid)) {
|
||||
$row = Db::name('arctype')
|
||||
->alias('a')
|
||||
->field('b.ctl_name,b.id,b.ifsystem')
|
||||
->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
|
||||
->where('a.id', 'eq', $typeid)
|
||||
->find();
|
||||
$data = [
|
||||
'typeid' => $typeid,
|
||||
];
|
||||
if (empty($row['ifsystem'])) {
|
||||
$ctl_name = 'Custom';
|
||||
$data['channel'] = $row['id'];
|
||||
} else {
|
||||
$ctl_name = $row['ctl_name'];
|
||||
}
|
||||
$gourl = url('Archives/index_archives', array('typeid'=>$typeid));
|
||||
$data['gourl'] = $gourl;
|
||||
$jumpUrl = url("{$ctl_name}/add", $data);
|
||||
} else {
|
||||
$jumpUrl = url("Archives/release");
|
||||
}
|
||||
$this->redirect($jumpUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文档
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$id = input('param.id/d', 0);
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$row = Db::name('archives')
|
||||
->alias('a')
|
||||
->field('a.channel,b.ctl_name,b.id,b.ifsystem')
|
||||
->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
|
||||
->where('a.aid', 'eq', $id)
|
||||
->find();
|
||||
if (empty($row['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel, ctl_name')
|
||||
->where('nid','article')
|
||||
->find();
|
||||
$row = array_merge($row, $channelRow);
|
||||
}
|
||||
$data = [
|
||||
'id' => $id,
|
||||
];
|
||||
if (empty($row['ifsystem'])) {
|
||||
$ctl_name = 'Custom';
|
||||
$data['channel'] = $row['id'];
|
||||
} else {
|
||||
$ctl_name = $row['ctl_name'];
|
||||
}
|
||||
$arcurl = input('param.arcurl/s');
|
||||
$data['arcurl'] = $arcurl;
|
||||
$jumpUrl = url("{$ctl_name}/edit", $data);
|
||||
$this->redirect($jumpUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文档
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$del_id = input('del_id/a');
|
||||
$thorough = input('thorough/d', 0);
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del($del_id, $thorough);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核文档
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$aids = input('ids/a');
|
||||
$aids = !empty($aids) ? eyIntval($aids) : '';
|
||||
if (!empty($aids)){
|
||||
$info = [
|
||||
'arcrank' => 0,
|
||||
'update_time'=>getTime(),
|
||||
];
|
||||
$r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
|
||||
if ($r !== false) {
|
||||
adminLog('审核文档-id:'.implode(',', $aids));
|
||||
$this->success('操作成功!');
|
||||
} else {
|
||||
$this->error('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消审核文档
|
||||
*/
|
||||
public function uncheck()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$aids = input('ids/a');
|
||||
$aids = !empty($aids) ? eyIntval($aids) : '';
|
||||
if (!empty($aids)){
|
||||
$info = [
|
||||
'arcrank' => -1,
|
||||
'update_time'=>getTime(),
|
||||
];
|
||||
$r = Db::name('archives')->where('aid','IN',$aids)->cache(true,null,'archives')->save($info);
|
||||
if ($r !== false) {
|
||||
adminLog('取消审核-id:'.implode(',', $aids));
|
||||
$this->success('操作成功!');
|
||||
} else {
|
||||
$this->error('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动
|
||||
*/
|
||||
public function move()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$typeid = !empty($post['typeid']) ? eyIntval($post['typeid']) : '';
|
||||
$aids = !empty($post['aids']) ? eyIntval($post['aids']) : '';
|
||||
|
||||
if (empty($typeid) || empty($aids)) {
|
||||
$this->error('参数有误,请联系技术支持');
|
||||
}
|
||||
|
||||
// 获取移动栏目的模型ID
|
||||
$current_channel = Db::name('arctype')->where([
|
||||
'id' => $typeid,
|
||||
'lang' => $this->admin_lang,
|
||||
])->getField('current_channel');
|
||||
// 抽取相符合模型ID的文档aid
|
||||
$aids = Db::name('archives')->where([
|
||||
'aid' => ['IN', $aids],
|
||||
'channel' => $current_channel,
|
||||
'lang' => $this->admin_lang,
|
||||
])->column('aid');
|
||||
// 移动文档处理
|
||||
$update_data = array(
|
||||
'typeid' => $typeid,
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$r = M('archives')->where([
|
||||
'aid' => ['IN', $aids],
|
||||
])->update($update_data);
|
||||
if($r){
|
||||
adminLog('移动文档-id:'.$aids);
|
||||
$this->success('操作成功');
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$allowReleaseChannel = [];
|
||||
if (!empty($typeid)) {
|
||||
$channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
|
||||
$allowReleaseChannel[] = $channelId;
|
||||
}
|
||||
$arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
|
||||
$this->assign('arctype_html', $arctype_html);
|
||||
/*--end*/
|
||||
|
||||
/*不允许发布文档的模型ID,用于JS判断*/
|
||||
// $js_allow_channel_arr = '[]';
|
||||
// if (!empty($allowReleaseChannel)) {
|
||||
// $js_allow_channel_arr = '[';
|
||||
// foreach ($allowReleaseChannel as $key => $val) {
|
||||
// if ($key > 0) {
|
||||
// $js_allow_channel_arr .= ',';
|
||||
// }
|
||||
// $js_allow_channel_arr .= $val;
|
||||
// }
|
||||
// $js_allow_channel_arr = $js_allow_channel_arr.']';
|
||||
// }
|
||||
// $this->assign('js_allow_channel_arr', $js_allow_channel_arr);
|
||||
/*--end*/
|
||||
|
||||
/*表单提交URL*/
|
||||
$form_action = url('Archives/move');
|
||||
$this->assign('form_action', $form_action);
|
||||
/*--end*/
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布内容
|
||||
*/
|
||||
public function release()
|
||||
{
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
if (0 < $typeid) {
|
||||
$param = input('param.');
|
||||
$row = Db::name('arctype')
|
||||
->field('b.ctl_name,b.id,b.ifsystem')
|
||||
->alias('a')
|
||||
->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
|
||||
->where('a.id', 'eq', $typeid)
|
||||
->find();
|
||||
/*针对不支持发布文档的模型*/
|
||||
if (!in_array($row['id'], $this->allowReleaseChannel)) {
|
||||
$this->error('该栏目不支持发布文档!', url('Archives/release'));
|
||||
exit;
|
||||
}
|
||||
/*-----end*/
|
||||
|
||||
$data = [
|
||||
'typeid' => $typeid,
|
||||
];
|
||||
if (empty($row['ifsystem'])) {
|
||||
$ctl_name = 'Custom';
|
||||
$data['channel'] = $row['id'];
|
||||
} else {
|
||||
$ctl_name = $row['ctl_name'];
|
||||
}
|
||||
$gourl = url('Archives/index_archives', array('typeid'=>$typeid), true, true);
|
||||
$data['gourl'] = $gourl;
|
||||
$jumpUrl = url("{$ctl_name}/add", $data, true, true);
|
||||
header('Location: '.$jumpUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
$iframe = input('param.iframe/d',0);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$select_html = allow_release_arctype();
|
||||
$this->assign('select_html',$select_html);
|
||||
/*--end*/
|
||||
|
||||
/*不允许发布文档的模型ID,用于JS判断*/
|
||||
$js_allow_channel_arr = '[';
|
||||
foreach ($this->allowReleaseChannel as $key => $val) {
|
||||
if ($key > 0) {
|
||||
$js_allow_channel_arr .= ',';
|
||||
}
|
||||
$js_allow_channel_arr .= $val;
|
||||
}
|
||||
$js_allow_channel_arr = $js_allow_channel_arr.']';
|
||||
$this->assign('js_allow_channel_arr', $js_allow_channel_arr);
|
||||
/*--end*/
|
||||
|
||||
if (!empty($iframe)) {
|
||||
$template = 'release_iframe';
|
||||
$attribute_row = Db::name('product_attribute')->field('typeid, count(attr_id) as num')
|
||||
->where([
|
||||
'is_del' => 0,
|
||||
'lang' => $this->admin_lang,
|
||||
])
|
||||
->group('typeid')
|
||||
->getAllWithIndex('typeid');
|
||||
$this->assign('attribute_row', $attribute_row);
|
||||
} else {
|
||||
$template = 'release';
|
||||
}
|
||||
$this->assign('iframe', $iframe);
|
||||
|
||||
return $this->fetch($template);
|
||||
}
|
||||
|
||||
public function ajax_get_arctype()
|
||||
{
|
||||
$pid = input('pid/d');
|
||||
$html = '';
|
||||
$status = 0;
|
||||
if (0 < $pid) {
|
||||
$map = array(
|
||||
'current_channel' => array('IN', $this->allowReleaseChannel),
|
||||
'parent_id' => $pid,
|
||||
);
|
||||
$row = model('Arctype')->getAll('id,typename', $map, 'id');
|
||||
if (!empty($row)) {
|
||||
$status = 1;
|
||||
$html = '<option value="0">请选择栏目…</option>';
|
||||
foreach ($row as $key => $val) {
|
||||
$html .= '<option value="'.$val['id'].'">'.$val['typename'].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respose(array(
|
||||
'status' => $status,
|
||||
'msg' => $html,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*/
|
||||
public function batch_copy()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$typeid = input('post.typeid/d');
|
||||
$aids = input('post.aids/s');
|
||||
$num = input('post.num/d');
|
||||
|
||||
if (empty($typeid) || empty($aids)) {
|
||||
$this->error('复制失败!');
|
||||
} else if (empty($num)) {
|
||||
$this->error('复制数量至少一篇!');
|
||||
}
|
||||
|
||||
// 获取复制栏目的模型ID
|
||||
$current_channel = Db::name('arctype')->where([
|
||||
'id' => $typeid,
|
||||
])->getField('current_channel');
|
||||
// 抽取相符合模型ID的文档aid
|
||||
$aids = Db::name('archives')->where([
|
||||
'aid' => ['IN', $aids],
|
||||
'channel' => $current_channel,
|
||||
])->column('aid');
|
||||
// 复制文档处理
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$r = $archivesLogic->batch_copy($aids, $typeid, $current_channel, $num);
|
||||
if($r){
|
||||
adminLog('复制文档-id:'.$aids);
|
||||
$this->success('操作成功');
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$allowReleaseChannel = [];
|
||||
if (!empty($typeid)) {
|
||||
$channelId = Db::name('arctype')->where('id',$typeid)->getField('current_channel');
|
||||
$allowReleaseChannel[] = $channelId;
|
||||
}
|
||||
$arctype_html = allow_release_arctype($typeid, $allowReleaseChannel);
|
||||
$this->assign('arctype_html', $arctype_html);
|
||||
/*--end*/
|
||||
|
||||
/*表单提交URL*/
|
||||
$form_action = url('Archives/batch_copy');
|
||||
$this->assign('form_action', $form_action);
|
||||
/*--end*/
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量属性操作
|
||||
*/
|
||||
public function batch_attr()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$opt = input('post.opt/s');
|
||||
$aids = input('post.aids/s');
|
||||
$attrType = input('post.attrType/s');
|
||||
|
||||
if (empty($opt)) {
|
||||
$this->error('操作失败!');
|
||||
} else if (empty($attrType)) {
|
||||
$this->error('请勾选属性!');
|
||||
} else if (empty($aids)) {
|
||||
$this->error('文档ID不能为空!');
|
||||
}
|
||||
|
||||
$value = ($opt == 'add') ? 1 : 0;
|
||||
$aids = str_replace(',', ',', $aids);
|
||||
$r = Db::name('archives')->where([
|
||||
'aid' => ['IN', explode(',', $aids)],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update([
|
||||
$attrType => $value,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if($r !== false){
|
||||
adminLog('批量处理属性-id:'.$aids);
|
||||
$this->success('操作成功');
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程图片本地化
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function ajax_remote_to_local()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$body = input('post.body/s', '', null);
|
||||
$body = remote_to_local($body);
|
||||
$this->success('本地化成功!', null, ['body'=>$body]);
|
||||
}
|
||||
$this->error('本地化失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除非站内链接
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function ajax_replace_links()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$body = input('post.body/s', '', null);
|
||||
$body = replace_links($body);
|
||||
$this->success('清除成功!', null, ['body'=>$body]);
|
||||
}
|
||||
$this->error('清除失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义字段
|
||||
*/
|
||||
public function ajax_get_addonextitem()
|
||||
{
|
||||
$aid = input('param.aid/d', 0);
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$channeltype = input('param.channeltype/d', 0);
|
||||
|
||||
if (!empty($typeid) && !empty($channeltype)) {
|
||||
// 存在aid则执行,查询文档数据
|
||||
$info = !empty($aid) ? model('Archives')->UnifiedGetInfo($aid, null, false) : [];
|
||||
// 查询对应的自定义字段
|
||||
$addonFieldExtList = model('Field')->getChannelFieldList($channeltype, 0, $aid, $info);
|
||||
$field_id_row = Db::name('channelfield_bind')->where([
|
||||
'field_id' => ['IN', get_arr_column($addonFieldExtList, 'id')],
|
||||
])->column('field_id');
|
||||
// 匹配显示的自定义字段
|
||||
$htmltextField = []; // 富文本的字段名
|
||||
if (!empty($field_id_row)) {
|
||||
// 查询绑定的自定义字段
|
||||
$channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
'typeid' => ['IN', [0, $typeid]],
|
||||
])->column('field_id');
|
||||
foreach ($addonFieldExtList as $key => $val) {
|
||||
if (in_array($val['id'], $field_id_row) && !in_array($val['id'], $channelfieldBindRow)) {
|
||||
unset($addonFieldExtList[$key]);
|
||||
continue;
|
||||
}
|
||||
if ($val['dtype'] == 'htmltext') {
|
||||
array_push($htmltextField, $val['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
|
||||
// 加载模板
|
||||
$assign_data['params'] = input('param.');
|
||||
$assign_data['field'] = $info;
|
||||
$this->assign($assign_data);
|
||||
// 渲染模板
|
||||
|
||||
$controller_name = input('param.controller_name/s');
|
||||
if (!empty($controller_name) && 'Custom' == $controller_name) {
|
||||
$html = $this->fetch('field/modelfield');
|
||||
} else {
|
||||
$html = $this->fetch('field/addonextitem');
|
||||
}
|
||||
$this->success('请求成功', null, ['html'=>$html, 'htmltextField'=>$htmltextField]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建模板文件
|
||||
*/
|
||||
public function ajax_newtpl()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.', '', null);
|
||||
$content = input('post.content', '', null);
|
||||
$view_suffix = config('template.view_suffix');
|
||||
if (!empty($post['filename'])) {
|
||||
if (!preg_match("/^[\w\-\_]{1,}$/u", $post['filename'])) {
|
||||
$this->error('文件名称只允许字母、数字、下划线、连接符的任意组合!');
|
||||
}
|
||||
$filename = "{$post['type']}_{$post['nid']}_{$post['filename']}.{$view_suffix}";
|
||||
} else {
|
||||
$filename = "{$post['type']}_{$post['nid']}.{$view_suffix}";
|
||||
}
|
||||
|
||||
$content = !empty($content) ? $content : '';
|
||||
$tpldirpath = !empty($post['tpldir']) ? '/template/'.TPL_THEME.trim($post['tpldir']) : '/template/'.TPL_THEME.'pc';
|
||||
if (file_exists(ROOT_PATH.ltrim($tpldirpath, '/').'/'.$filename)) {
|
||||
$this->error('文件名称已经存在,请重新命名!', null, ['focus'=>'filename']);
|
||||
}
|
||||
|
||||
$nosubmit = input('param.nosubmit/d');
|
||||
if (1 == $nosubmit) {
|
||||
$this->success('检测通过');
|
||||
}
|
||||
|
||||
$filemanagerLogic = new \app\admin\logic\FilemanagerLogic;
|
||||
$r = $filemanagerLogic->editFile($filename, $tpldirpath, $content);
|
||||
if ($r === true) {
|
||||
$this->success('操作成功', null, ['filename'=>$filename,'type'=>$post['type']]);
|
||||
} else {
|
||||
$this->error($r);
|
||||
}
|
||||
}
|
||||
$type = input('param.type/s');
|
||||
$nid = input('param.nid/s');
|
||||
$tpldirList = glob('template/'.TPL_THEME.'*');
|
||||
$tpl_theme = str_replace('/', '\\/', TPL_THEME);
|
||||
foreach ($tpldirList as $key => $val) {
|
||||
if (!preg_match('/template\/'.$tpl_theme.'(pc|mobile)$/i', $val)) {
|
||||
unset($tpldirList[$key]);
|
||||
} else {
|
||||
$tpldirList[$key] = preg_replace('/^(.*)template\/'.$tpl_theme.'(pc|mobile)$/i', '$2', $val);
|
||||
}
|
||||
}
|
||||
!empty($tpldirList) && arsort($tpldirList);
|
||||
$this->assign('tpldirList', $tpldirList);
|
||||
|
||||
$content = '';
|
||||
if ('special' == $nid) {
|
||||
$fileContent = @file_get_contents('./data/model/template/pc/view_custommodel.htm');
|
||||
if (!empty($fileContent)) {
|
||||
$content = $fileContent;
|
||||
$replace = <<<EOF
|
||||
<section class="article-list">
|
||||
{eyou:specnode code="default1" id="field"}
|
||||
<article>
|
||||
{eyou:notempty name="\$field.is_litpic"}
|
||||
<a href="{\$field.arcurl}" target="_blank" title="{\$field.title}" style="float: left; margin-right: 10px"> <img src="{\$field.litpic}" alt="{\$field.title}" height="100" /> </a>
|
||||
{/eyou:notempty}
|
||||
<h2><a href="{\$field.arcurl}" target="_blank">{\$field.title}</a><span>{\$field.click}°C</span></h2>
|
||||
<div class="excerpt">
|
||||
<p>{\$field.seo_description}</p>
|
||||
</div>
|
||||
<div class="meta">
|
||||
<span class="item"><time>{\$field.add_time|MyDate='Y-m-d',###}</time></span>
|
||||
<span class="item"><a href="{\$field.typeurl}" target="_blank">{\$field.typename}</a></span>
|
||||
</div>
|
||||
</article>
|
||||
{/eyou:specnode}
|
||||
</section>
|
||||
EOF;
|
||||
$content = str_replace("<!-- #special# -->", $replace, $content);
|
||||
}
|
||||
}
|
||||
$this->assign('content', $content);
|
||||
|
||||
$this->assign('type', $type);
|
||||
$this->assign('nid', $nid);
|
||||
$this->assign('tpl_theme', TPL_THEME);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测自定义文件名是否存在
|
||||
*/
|
||||
public function ajax_check_htmlfilename()
|
||||
{
|
||||
$htmlfilename = input('post.htmlfilename/s');
|
||||
$htmlfilename = trim($htmlfilename);
|
||||
if (!empty($htmlfilename)) {
|
||||
$aid = input('post.aid/d');
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
$map = array(
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
);
|
||||
if ($aid > 0) {
|
||||
$map['aid'] = array('neq', $aid);
|
||||
}
|
||||
$result = Db::name('archives')->where($map)->find();
|
||||
if (!empty($result)) {
|
||||
$this->error('自定义文件名已存在,请更改!');
|
||||
}
|
||||
}
|
||||
$this->success('自定义文件名可用!');
|
||||
}
|
||||
}
|
||||
43
src/application/admin/controller/ArchivesFlag.php
Normal file
43
src/application/admin/controller/ArchivesFlag.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
use think\Cache;
|
||||
|
||||
class ArchivesFlag extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
$condition = array();
|
||||
if (!empty($keywords)) {
|
||||
$condition['flag_name'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
$archivesflagM = M('archives_flag');
|
||||
$count = $archivesflagM->where($condition)->count('id');// 查询满足要求的总记录数
|
||||
$Page = $pager = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $archivesflagM->where($condition)->order('sort_order asc, id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$pager);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
1185
src/application/admin/controller/Arctype.php
Normal file
1185
src/application/admin/controller/Arctype.php
Normal file
File diff suppressed because it is too large
Load Diff
646
src/application/admin/controller/Article.php
Normal file
646
src/application/admin/controller/Article.php
Normal file
@@ -0,0 +1,646 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class Article extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'article';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
empty($this->channeltype) && $this->channeltype = 1;
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('archives')
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = DB::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
/*前台URL模式*/
|
||||
$assign_data['seo_pseudo'] = tpCache('seo.seo_pseudo');
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做自动通过审核判断
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$post['arcrank'] = -1;
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = Db::name('archives')->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model('Article')->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增文章:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0, $typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// 文档默认浏览量
|
||||
$other_config = tpCache('other');
|
||||
if (isset($other_config['other_arcclick']) && 0 <= $other_config['other_arcclick']) {
|
||||
$arcclick_arr = explode("|", $other_config['other_arcclick']);
|
||||
if (count($arcclick_arr) > 1) {
|
||||
$assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcclick_config['other_arcclick'] = '500|1000';
|
||||
tpCache('other', $arcclick_config);
|
||||
$assign_data['rand_arcclick'] = mt_rand(500, 1000);
|
||||
}
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'aid' => ['NEQ', $post['aid']],
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做未通过审核文档不允许修改文档状态操作
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
|
||||
if ($old_archives_arcrank < 0) {
|
||||
unset($post['arcrank']);
|
||||
}
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = Db::name('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Article')->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑文章:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model('Article')->getInfo($id, null, false);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
$assign_data['typeid'] = $typeid;
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/application/admin/controller/Ask.php
Normal file
10
src/application/admin/controller/Ask.php
Normal file
File diff suppressed because one or more lines are too long
271
src/application/admin/controller/AuthRole.php
Normal file
271
src/application/admin/controller/AuthRole.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
class AuthRole extends Base {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限组管理
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$map = array();
|
||||
$pid = input('pid/d');
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
if (!empty($keywords)) {
|
||||
$map['c.name'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
$AuthRole = M('auth_role');
|
||||
$count = $AuthRole->alias('c')->where($map)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, 10);// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$fields = "c.*,s.name AS pname";
|
||||
$list = DB::name('auth_role')
|
||||
->field($fields)
|
||||
->alias('c')
|
||||
->join('__AUTH_ROLE__ s','s.id = c.pid','LEFT')
|
||||
->where($map)
|
||||
->order('c.id asc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->select();
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页集
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增权限组
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$rule = array(
|
||||
'name' => 'require',
|
||||
);
|
||||
$msg = array(
|
||||
'name.require' => '权限组名称不能为空!',
|
||||
);
|
||||
$data = array(
|
||||
'name' => trim(input('name/s')),
|
||||
);
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if(!$result){
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
$model = model('AuthRole');
|
||||
$count = $model->where('name', $data['name'])->count();
|
||||
if(! empty($count)){
|
||||
$this->error('该权限组名称已存在,请检查');
|
||||
}
|
||||
$role_id = $model->saveAuthRole(input());
|
||||
if($role_id){
|
||||
adminLog('新增权限组:'.$data['name']);
|
||||
$admin_role_list = model('AuthRole')->getRoleAll();
|
||||
$this->success('操作成功', url('AuthRole/index'), ['role_id'=>$role_id,'role_name'=>$data['name'],'admin_role_list'=>json_encode($admin_role_list)]);
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 权限组
|
||||
$admin_role_list = model('AuthRole')->getRoleAll();
|
||||
$this->assign('admin_role_list', $admin_role_list);
|
||||
|
||||
// 模块组
|
||||
$modules = getAllMenu();
|
||||
$this->assign('modules', $modules);
|
||||
|
||||
// 权限集
|
||||
// $singleArr = array_multi2single($modules, 'child'); // 多维数组转为一维
|
||||
$auth_rules = get_auth_rule(['is_modules'=>1]);
|
||||
$auth_rule_list = group_same_key($auth_rules, 'menu_id');
|
||||
foreach ($auth_rule_list as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$sort_order = [];
|
||||
foreach ($val as $_k => $_v) {
|
||||
$sort_order[$_k] = $_v['sort_order'];
|
||||
}
|
||||
array_multisort($sort_order, SORT_ASC, $val);
|
||||
$auth_rule_list[$key] = $val;
|
||||
}
|
||||
}
|
||||
$this->assign('auth_rule_list', $auth_rule_list);
|
||||
|
||||
// 栏目
|
||||
$arctype_data = $arctype_array = array();
|
||||
$arctype = M('arctype')->select();
|
||||
if(! empty($arctype)){
|
||||
foreach ($arctype as $item){
|
||||
if($item['parent_id'] <= 0){
|
||||
$arctype_data[] = $item;
|
||||
}
|
||||
$arctype_array[$item['parent_id']][] = $item;
|
||||
}
|
||||
}
|
||||
$this->assign('arctypes', $arctype_data);
|
||||
$this->assign('arctype_array', $arctype_array);
|
||||
|
||||
// 插件
|
||||
$plugins = false;
|
||||
$web_weapp_switch = tpCache('web.web_weapp_switch');
|
||||
if (1 == $web_weapp_switch) {
|
||||
$plugins = model('Weapp')->getList(['status'=>1]);
|
||||
}
|
||||
$this->assign('plugins', $plugins);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$id = input('id/d', 0);
|
||||
if($id <= 0){
|
||||
$this->error('非法访问');
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
$rule = array(
|
||||
'name' => 'require',
|
||||
);
|
||||
$msg = array(
|
||||
'name.require' => '权限组名称不能为空!',
|
||||
);
|
||||
$data = array(
|
||||
'name' => trim(input('name/s')),
|
||||
);
|
||||
$validate = new Validate($rule, $msg);
|
||||
$result = $validate->check($data);
|
||||
if(!$result){
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
$model = model('AuthRole');
|
||||
$count = $model->where('name', $data['name'])
|
||||
->where('id', '<>', $id)
|
||||
->count();
|
||||
if(! empty($count)){
|
||||
$this->error('该权限组名称已存在,请检查');
|
||||
}
|
||||
$role_id = $model->saveAuthRole(input(), true);
|
||||
if($role_id){
|
||||
adminLog('编辑权限组:'.$data['name']);
|
||||
$this->success('操作成功', url('AuthRole/index'), ['role_id'=>$role_id,'role_name'=>$data['name']]);
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
$model = model('AuthRole');
|
||||
$info = $model->getRole(array('id' => $id));
|
||||
if(empty($info)){
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
}
|
||||
$this->assign('info', $info);
|
||||
|
||||
// 权限组
|
||||
$admin_role_list = model('AuthRole')->getRoleAll();
|
||||
$this->assign('admin_role_list', $admin_role_list);
|
||||
|
||||
// 模块组
|
||||
$modules = getAllMenu();
|
||||
$this->assign('modules', $modules);
|
||||
|
||||
// 权限集
|
||||
$auth_rules = get_auth_rule(['is_modules'=>1]);
|
||||
$auth_rule_list = group_same_key($auth_rules, 'menu_id');
|
||||
foreach ($auth_rule_list as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$sort_order = [];
|
||||
foreach ($val as $_k => $_v) {
|
||||
$sort_order[$_k] = $_v['sort_order'];
|
||||
}
|
||||
array_multisort($sort_order, SORT_ASC, $val);
|
||||
$auth_rule_list[$key] = $val;
|
||||
}
|
||||
}
|
||||
$this->assign('auth_rule_list', $auth_rule_list);
|
||||
|
||||
// 栏目
|
||||
$arctype_data = $arctype_array = array();
|
||||
$arctype = M('arctype')->select();
|
||||
if(! empty($arctype)){
|
||||
foreach ($arctype as $item){
|
||||
if($item['parent_id'] <= 0){
|
||||
$arctype_data[] = $item;
|
||||
}
|
||||
$arctype_array[$item['parent_id']][] = $item;
|
||||
}
|
||||
}
|
||||
$this->assign('arctypes', $arctype_data);
|
||||
$this->assign('arctype_array', $arctype_array);
|
||||
|
||||
// 插件
|
||||
$plugins = false;
|
||||
$web_weapp_switch = tpCache('web.web_weapp_switch');
|
||||
if (1 == $web_weapp_switch) {
|
||||
$plugins = model('Weapp')->getList(['status'=>1]);
|
||||
}
|
||||
$this->assign('plugins', $plugins);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function del()
|
||||
{
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if (!empty($id_arr)) {
|
||||
|
||||
$count = M('auth_role')->where(['built_in'=>1,'id'=>['IN',$id_arr]])->count();
|
||||
if (!empty($count)) {
|
||||
$this->error('系统内置不允许删除!');
|
||||
}
|
||||
|
||||
$role = M('auth_role')->where("pid",'IN',$id_arr)->select();
|
||||
if ($role) {
|
||||
$this->error('请先清空该权限组下的子权限组');
|
||||
}
|
||||
|
||||
$role_admin = M('admin')->where("role_id",'IN',$id_arr)->select();
|
||||
if ($role_admin) {
|
||||
$this->error('请先清空所属该权限组的管理员');
|
||||
} else {
|
||||
$r = M('auth_role')->where("id",'IN',$id_arr)->delete();
|
||||
if($r){
|
||||
adminLog('删除权限组');
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
}
|
||||
167
src/application/admin/controller/Base.php
Normal file
167
src/application/admin/controller/Base.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use app\admin\logic\UpgradeLogic;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\response\Json;
|
||||
use think\Session;
|
||||
class Base extends Controller {
|
||||
|
||||
public $session_id;
|
||||
public $php_servicemeal = 0;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
if (!session_id()) {
|
||||
Session::start();
|
||||
}
|
||||
header("Cache-control: private"); // history.back返回后输入框值丢失问题
|
||||
parent::__construct();
|
||||
|
||||
$this->global_assign();
|
||||
}
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
$this->session_id = session_id(); // 当前的 session_id
|
||||
!defined('SESSION_ID') && define('SESSION_ID', $this->session_id); //将当前的session_id保存为常量,供其它方法调用
|
||||
|
||||
parent::_initialize();
|
||||
|
||||
/*及时更新cookie中的admin_id,用于前台的可视化权限验证*/
|
||||
// $auth_role_info = model('AuthRole')->getRole(array('id' => session('admin_info.role_id')));
|
||||
// session('admin_info.auth_role_info', $auth_role_info);
|
||||
/*--end*/
|
||||
|
||||
//过滤不需要登陆的行为
|
||||
$ctl_act = CONTROLLER_NAME.'@'.ACTION_NAME;
|
||||
$ctl_all = CONTROLLER_NAME.'@*';
|
||||
$filter_login_action = config('filter_login_action');
|
||||
if (in_array($ctl_act, $filter_login_action) || in_array($ctl_all, $filter_login_action)) {
|
||||
//return;
|
||||
}else{
|
||||
$web_login_expiretime = tpCache('web.web_login_expiretime');
|
||||
empty($web_login_expiretime) && $web_login_expiretime = config('login_expire');
|
||||
$admin_login_expire = session('admin_login_expire'); // 登录有效期web_login_expiretime
|
||||
if (session('?admin_id') && getTime() - intval($admin_login_expire) < $web_login_expiretime) {
|
||||
session('admin_login_expire', getTime()); // 登录有效期
|
||||
$this->check_priv();//检查管理员菜单操作权限
|
||||
}else{
|
||||
/*自动退出*/
|
||||
adminLog('访问后台');
|
||||
session_unset();
|
||||
session::clear();
|
||||
cookie('admin-treeClicked', null); // 清除并恢复栏目列表的展开方式
|
||||
/*--end*/
|
||||
if (IS_AJAX) {
|
||||
$this->error('登录超时!');
|
||||
} else {
|
||||
$url = request()->baseFile().'?s=Admin/login';
|
||||
$this->redirect($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 增、改的跳转提示页,只限制于发布文档的模型和自定义模型 */
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$controller_name = $this->request->controller();
|
||||
$this->assign('controller_name', $controller_name);
|
||||
if (isset($channeltype_list[strtolower($controller_name)]) || 'Custom' == $controller_name) {
|
||||
if (in_array($this->request->action(), ['add','edit'])) {
|
||||
\think\Config::set('dispatch_success_tmpl', 'public/dispatch_jump');
|
||||
$id = input('param.id/d', input('param.aid/d'));
|
||||
('GET' == $this->request->method()) && cookie('ENV_IS_UPHTML', 0);
|
||||
} else if (in_array($this->request->action(), ['index'])) {
|
||||
cookie('ENV_GOBACK_URL', $this->request->url());
|
||||
cookie('ENV_LIST_URL', request()->baseFile()."?m=admin&c={$controller_name}&a=index&lang=".$this->admin_lang);
|
||||
}
|
||||
}
|
||||
if ('Archives' == $controller_name && in_array($this->request->action(), ['index_archives'])) {
|
||||
cookie('ENV_GOBACK_URL', $this->request->url());
|
||||
cookie('ENV_LIST_URL', request()->baseFile()."?m=admin&c=Archives&a=index_archives&lang=".$this->admin_lang);
|
||||
}
|
||||
/* end */
|
||||
}
|
||||
|
||||
public function check_priv()
|
||||
{
|
||||
$ctl = CONTROLLER_NAME;
|
||||
$act = ACTION_NAME;
|
||||
$ctl_act = $ctl.'@'.$act;
|
||||
$ctl_all = $ctl.'@*';
|
||||
//无需验证的操作
|
||||
$uneed_check_action = config('uneed_check_action');
|
||||
if (0 >= intval(session('admin_info.role_id'))) {
|
||||
//超级管理员无需验证
|
||||
return true;
|
||||
} else {
|
||||
$bool = false;
|
||||
|
||||
/*检测是否有该权限*/
|
||||
if (is_check_access($ctl_act)) {
|
||||
$bool = true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*在列表中的操作不需要验证权限*/
|
||||
if (IS_AJAX || strpos($act,'ajax') !== false || in_array($ctl_act, $uneed_check_action) || in_array($ctl_all, $uneed_check_action)) {
|
||||
$bool = true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
//检查是否拥有此操作权限
|
||||
if (!$bool) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存系统设置
|
||||
*/
|
||||
public function global_assign()
|
||||
{
|
||||
/*随时更新每页记录数*/
|
||||
$pagesize = input('get.pagesize/d');
|
||||
if (!empty($pagesize)) {
|
||||
$system_paginate_pagesize = config('tpcache.system_paginate_pagesize');
|
||||
if ($pagesize != intval($system_paginate_pagesize)) {
|
||||
tpCache('system', ['system_paginate_pagesize'=>$pagesize]);
|
||||
}
|
||||
}
|
||||
/*end*/
|
||||
|
||||
$globalConf = tpCache('global');
|
||||
$this->php_servicemeal = $globalConf['php_servicemeal'];
|
||||
$this->assign('global', $globalConf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多语言功能操作权限
|
||||
*/
|
||||
public function language_access()
|
||||
{
|
||||
if (is_language() && $this->main_lang != $this->admin_lang) {
|
||||
$lang_title = model('Language')->where('mark',$this->main_lang)->value('title');
|
||||
$this->error('当前语言没有此功能,请切换到【'.$lang_title.'】语言');
|
||||
}
|
||||
}
|
||||
}
|
||||
275
src/application/admin/controller/Case.php
Normal file
275
src/application/admin/controller/Case.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Case extends Base
|
||||
{
|
||||
private $ad_position_system_id = array(); // 系统默认位置ID,不可删除
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$get = input('get.');
|
||||
$keywords = input('keywords/s');
|
||||
$condition = [];
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'type'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else {
|
||||
$tmp_key = 'a.'.$key;
|
||||
$condition[$tmp_key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多语言
|
||||
// $condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$adPositionM = M('platform');
|
||||
$count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $adPositionM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id');
|
||||
|
||||
// 每组获取三张图片
|
||||
$pids = get_arr_column($list, 'id');
|
||||
$ad = M('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); // 支持子目录
|
||||
$list[$k] = $v;
|
||||
}
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
// 添加广告位置表信息
|
||||
$data = array(
|
||||
'title' => trim($post['title']),
|
||||
'desc' => $post['intro'],
|
||||
'logo'=>$post['img_litpic'][0],
|
||||
// 'intro' => $post['intro'],
|
||||
'admin_id' => session('admin_id'),
|
||||
// 'lang' => $this->admin_lang,
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$insertID = M('platform')->insertGetId($data);
|
||||
if (!empty($insertID)) {
|
||||
adminLog('新增平台:'.$post['title']);
|
||||
$this->success("操作成功", url('platform/index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('platform/index'));
|
||||
}
|
||||
}
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$upload_max_filesize = upload_max_filesize();
|
||||
$this->assign('upload_max_filesize', $upload_max_filesize);
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$this->assign('media_type', $media_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if (!empty($post['id'])) {
|
||||
// if (array_key_exists($post['id'], $this->ad_position_system_id)) {
|
||||
// $this->error("不可更改系统预定义位置", url('Platform/edit',array('id'=>$post['id'])));
|
||||
// }
|
||||
|
||||
$data = array(
|
||||
'id' => $post['id'],
|
||||
'desc' => $post['intro'],
|
||||
'logo'=>$post['img_litpic'][0],
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$resultID = Db::name('platform')->update($data);
|
||||
/* END */
|
||||
}
|
||||
|
||||
if (!empty($resultID)) {
|
||||
adminLog('编辑广告:'.$post['title']);
|
||||
$this->success("操作成功", url('Platform/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('platform')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
|
||||
if (empty($field)) $this->error('广告不存在,请联系管理员!');
|
||||
$assign_data['field'] = $field;
|
||||
/*
|
||||
// 广告
|
||||
$ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
|
||||
foreach ($ad_data as $key => $val) {
|
||||
if (1 == $val['type']) {
|
||||
$ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
|
||||
}
|
||||
}
|
||||
$assign_data['ad_data'] = $ad_data;
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$upload_max_filesize = intval($min_size) * 1024 * 1024;
|
||||
$assign_data['upload_max_filesize'] = $upload_max_filesize;
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$assign_data['media_type'] = $media_type;*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告图片
|
||||
*/
|
||||
public function del_imgupload()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = Db::name('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
|
||||
Db::name('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
$r = M('platform')->where('id','IN',$id_arr)->delete();
|
||||
if ($r) {
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
273
src/application/admin/controller/Casevideo.php
Normal file
273
src/application/admin/controller/Casevideo.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Casevideo extends Base
|
||||
{
|
||||
private $ad_position_system_id = array(); // 系统默认位置ID,不可删除
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$get = input('get.');
|
||||
$keywords = input('keywords/s');
|
||||
$condition = [];
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'type'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else {
|
||||
$tmp_key = 'a.'.$key;
|
||||
$condition[$tmp_key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多语言
|
||||
// $condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$adPositionM = M('casevideo');
|
||||
$count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $adPositionM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id');
|
||||
|
||||
// 每组获取三张图片
|
||||
$pids = get_arr_column($list, 'id');
|
||||
$ad = M('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); // 支持子目录
|
||||
$v['litpic'] = ROOT_DIR . '/public/static/admin/images/ad_type_media.png';
|
||||
$list[$k] = $v;
|
||||
}
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
// 添加广告位置表信息
|
||||
$data = array(
|
||||
'title' => trim($post['title']),
|
||||
'video'=>$post['video_litpic'],
|
||||
'admin_id' => session('admin_id'),
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$insertID = M('casevideo')->insertGetId($data);
|
||||
if (!empty($insertID)) {
|
||||
adminLog('新增平台:'.$post['title']);
|
||||
$this->success("操作成功", url('casevideo/index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('casevideo/index'));
|
||||
}
|
||||
}
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$upload_max_filesize = upload_max_filesize();
|
||||
$this->assign('upload_max_filesize', $upload_max_filesize);
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$this->assign('media_type', $media_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if (!empty($post['id'])) {
|
||||
// if (array_key_exists($post['id'], $this->ad_position_system_id)) {
|
||||
// $this->error("不可更改系统预定义位置", url('Platform/edit',array('id'=>$post['id'])));
|
||||
// }
|
||||
|
||||
$data = array(
|
||||
'id' => $post['id'],
|
||||
'title' => trim($post['title']),
|
||||
'video'=>$post['video_litpic'],
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$resultID = Db::name('casevideo')->update($data);
|
||||
/* END */
|
||||
}
|
||||
|
||||
if (!empty($resultID)) {
|
||||
adminLog('编辑广告:'.$post['title']);
|
||||
$this->success("操作成功", url('casevideo/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('casevideo')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
|
||||
if (empty($field)) $this->error('广告不存在,请联系管理员!');
|
||||
$assign_data['field'] = $field;
|
||||
/*
|
||||
// 广告
|
||||
$ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
|
||||
foreach ($ad_data as $key => $val) {
|
||||
if (1 == $val['type']) {
|
||||
$ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
|
||||
}
|
||||
}
|
||||
$assign_data['ad_data'] = $ad_data;*/
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$upload_max_filesize = intval($min_size) * 1024 * 1024;
|
||||
$assign_data['upload_max_filesize'] = $upload_max_filesize;
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$assign_data['media_type'] = $media_type;
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告图片
|
||||
*/
|
||||
public function del_imgupload()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = Db::name('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
|
||||
Db::name('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
$r = M('casevideo')->where('id','IN',$id_arr)->delete();
|
||||
if ($r) {
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除1失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1133
src/application/admin/controller/Channeltype.php
Normal file
1133
src/application/admin/controller/Channeltype.php
Normal file
File diff suppressed because it is too large
Load Diff
10
src/application/admin/controller/Coupon.php
Normal file
10
src/application/admin/controller/Coupon.php
Normal file
File diff suppressed because one or more lines are too long
678
src/application/admin/controller/Custom.php
Normal file
678
src/application/admin/controller/Custom.php
Normal file
@@ -0,0 +1,678 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-7
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Custom extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = '';
|
||||
// 模型ID
|
||||
public $channeltype = 0;
|
||||
// 模型附加表
|
||||
public $table = '';
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->archives_db = Db::name('archives');
|
||||
|
||||
$this->channeltype = input('param.channel/d', 0);
|
||||
$channeltypeRow = Db::name('channeltype')->field('nid,table')->where(['id'=>['eq',$this->channeltype]])->find();
|
||||
if (empty($this->channeltype) || empty($channeltypeRow)) {
|
||||
$this->error('自定义模型ID丢失,打开失败!');
|
||||
}
|
||||
|
||||
$this->nid = $channeltypeRow['nid'];
|
||||
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = $this->archives_db->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $this->archives_db
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = $this->archives_db
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
/*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
|
||||
$contentField = Db::name('channelfield')->where([
|
||||
'channel_id' => $this->channeltype,
|
||||
'dtype' => 'htmltext',
|
||||
])->getField('name');
|
||||
$content = input('post.addonFieldExt.'.$contentField, '', null);
|
||||
/*--end*/
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做自动通过审核判断
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$post['arcrank'] = -1;
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = $this->archives_db->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model('Custom')->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增数据:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*获取可显示的系统字段*/
|
||||
$condition['ifcontrol'] = 0;
|
||||
$condition['channel_id'] = $this->channeltype;
|
||||
$channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
|
||||
$assign_data['channelfield_row'] = $channelfield_row;
|
||||
/*--end*/
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// 文档默认浏览量
|
||||
$other_config = tpCache('other');
|
||||
if (isset($other_config['other_arcclick']) && 0 <= $other_config['other_arcclick']) {
|
||||
$arcclick_arr = explode("|", $other_config['other_arcclick']);
|
||||
if (count($arcclick_arr) > 1) {
|
||||
$assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcclick_config['other_arcclick'] = '500|1000';
|
||||
tpCache('other', $arcclick_config);
|
||||
$assign_data['rand_arcclick'] = mt_rand(500, 1000);
|
||||
}
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
/*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
|
||||
$contentField = Db::name('channelfield')->where([
|
||||
'channel_id' => $this->channeltype,
|
||||
'dtype' => 'htmltext',
|
||||
])->getField('name');
|
||||
$content = input('post.addonFieldExt.'.$contentField, '', null);
|
||||
/*--end*/
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
|
||||
//做未通过审核文档不允许修改文档状态操作
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
|
||||
if ($old_archives_arcrank < 0) {
|
||||
unset($post['arcrank']);
|
||||
}
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'aid' => ['NEQ', $post['aid']],
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = M('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Custom')->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑文章:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model('Custom')->getInfo($id, null, false);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
$assign_data['typeid'] = $typeid;
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
/*获取可显示的系统字段*/
|
||||
$condition['ifcontrol'] = 0;
|
||||
$condition['channel_id'] = $this->channeltype;
|
||||
$channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
|
||||
$assign_data['channelfield_row'] = $channelfield_row;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
26
src/application/admin/controller/DiyExtend.php
Normal file
26
src/application/admin/controller/DiyExtend.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
|
||||
/**
|
||||
* 用户自定义扩展php文件
|
||||
*/
|
||||
class DiyExtend extends Base {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
}
|
||||
930
src/application/admin/controller/Download.php
Normal file
930
src/application/admin/controller/Download.php
Normal file
@@ -0,0 +1,930 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Download extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'download';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
empty($this->channeltype) && $this->channeltype = 4;
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$list = DB::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$val['arcurl'] = get_arcurl($val);
|
||||
$val['litpic'] = handle_subdir_pic($val['litpic']); // 支持子目录
|
||||
$list[$key] = $val;
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
if (!empty($post['fileupload'])){
|
||||
foreach ($post['fileupload']['file_url'] as $k => $v){
|
||||
if (is_http_url($v)){
|
||||
$post['fileupload']['uhash'][$k] = md5($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做自动通过审核判断
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$post['arcrank'] = -1;
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = Db::name('archives')->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model('Download')->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增下载:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
//第三方存储空间 七牛云/oss开关信息
|
||||
$assign_data['qiniu_open'] = 0;
|
||||
$assign_data['oss_open'] = 0;
|
||||
$assign_data['cos_open'] = 0;
|
||||
$channelRow = Db::name('channeltype')->where('id', $this->channeltype)->find();
|
||||
if(!empty($channelRow)){
|
||||
$channelRow['data'] = json_decode($channelRow['data'], true);
|
||||
$assign_data['qiniu_open'] = !empty($channelRow['data']['qiniuyun_open']) ? $channelRow['data']['qiniuyun_open'] : 0;
|
||||
$assign_data['oss_open'] = !empty($channelRow['data']['oss_open']) ? $channelRow['data']['oss_open'] : 0;
|
||||
$assign_data['cos_open'] = !empty($channelRow['data']['cos_open']) ? $channelRow['data']['cos_open'] : 0;
|
||||
}
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
/*会员等级信息*/
|
||||
$assign_data['users_level'] = DB::name('users_level')->field('level_id,level_name')->where('lang',$this->admin_lang)->select();
|
||||
/*--end*/
|
||||
|
||||
/*下载模型自定义属性字段*/
|
||||
$attr_field = Db::name('download_attr_field')->select();
|
||||
$servername_use = 0;
|
||||
if ($attr_field) {
|
||||
$servername_info = [];
|
||||
for ($i = 0; $i < count($attr_field); $i++) {
|
||||
if ($attr_field[$i]['field_name'] == 'server_name') {
|
||||
if ($attr_field[$i]['field_use'] == 1) {
|
||||
$servername_use = 1;
|
||||
}
|
||||
$servername_info = $attr_field[$i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$assign_data['servername_info'] = $servername_info;
|
||||
}
|
||||
$assign_data['attr_field'] = $attr_field;
|
||||
$assign_data['servername_use'] = $servername_use;
|
||||
|
||||
$servername_arr = unserialize(tpCache('download.download_select_servername'));
|
||||
$assign_data['default_servername'] = $servername_arr?$servername_arr[0]:'立即下载';
|
||||
/*--end*/
|
||||
|
||||
// 文档默认浏览量 / 软件默认下载量
|
||||
$other_config = tpCache('other');
|
||||
if (isset($other_config['other_arcclick']) && 0 <= $other_config['other_arcclick']) {
|
||||
$arcclick_arr = explode("|", $other_config['other_arcclick']);
|
||||
if (count($arcclick_arr) > 1) {
|
||||
$assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcclick_config['other_arcclick'] = '500|1000';
|
||||
tpCache('other', $arcclick_config);
|
||||
$assign_data['rand_arcclick'] = mt_rand(500, 1000);
|
||||
}
|
||||
|
||||
if (isset($other_config['other_arcdownload']) && 0 <= $other_config['other_arcdownload']) {
|
||||
$arcdownload_arr = explode("|", $other_config['other_arcdownload']);
|
||||
if (count($arcdownload_arr) > 1) {
|
||||
$assign_data['rand_arcdownload'] = mt_rand($arcdownload_arr[0], $arcdownload_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcdownload'] = intval($arcdownload_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcdownload_config['other_arcdownload'] = '100|500';
|
||||
tpCache('other', $arcdownload_config);
|
||||
$assign_data['rand_arcdownload'] = mt_rand(100, 500);
|
||||
}
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
// 系统最大上传视频的大小 限制类型
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$basic['file_size'] = intval($min_size) * 1024 * 1024;
|
||||
$file_type = tpCache('basic.file_type');
|
||||
$basic['file_type'] = !empty($file_type) ? $file_type : "zip|gz|rar|iso|doc|xls|ppt|wps";
|
||||
$assign_data['basic'] = $basic;
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
if (!empty($post['fileupload'])){
|
||||
foreach ($post['fileupload']['file_url'] as $k => $v){
|
||||
if (is_http_url($v)){
|
||||
$post['fileupload']['uhash'][$k] = md5($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'aid' => ['NEQ', $post['aid']],
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
|
||||
//做未通过审核文档不允许修改文档状态操作
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
|
||||
if ($old_archives_arcrank < 0) {
|
||||
unset($post['arcrank']);
|
||||
}
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = Db::name('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Download')->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑下载:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model('Download')->getInfo($id);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
$assign_data['typeid'] = $typeid;
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
//第三方存储空间 七牛云/oss开关信息
|
||||
$assign_data['qiniu_open'] = 0;
|
||||
$assign_data['oss_open'] = 0;
|
||||
$assign_data['oss_open'] = 0;
|
||||
$channelRow = Db::name('channeltype')->where('id', $this->channeltype)->find();
|
||||
if(!empty($channelRow)){
|
||||
$channelRow['data'] = json_decode($channelRow['data'], true);
|
||||
$assign_data['qiniu_open'] = !empty($channelRow['data']['qiniuyun_open']) ? $channelRow['data']['qiniuyun_open'] : 0;
|
||||
$assign_data['oss_open'] = !empty($channelRow['data']['oss_open']) ? $channelRow['data']['oss_open'] : 0;
|
||||
$assign_data['cos_open'] = !empty($channelRow['data']['cos_open']) ? $channelRow['data']['cos_open'] : 0;
|
||||
}
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
// 下载文件
|
||||
$downfile_list = model('DownloadFile')->getDownFile($id);
|
||||
$assign_data['downfile_list'] = $downfile_list;
|
||||
|
||||
// 下载文件中是否存在远程链接
|
||||
$is_remote_file = 0;
|
||||
foreach ($downfile_list as $key => $value) {
|
||||
if (1 == $value['is_remote']) {
|
||||
$is_remote_file = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$assign_data['is_remote_file'] = $is_remote_file;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
/*会员等级信息*/
|
||||
$assign_data['users_level'] = DB::name('users_level')->field('level_id,level_name')->where('lang',$this->admin_lang)->select();
|
||||
/*--end*/
|
||||
|
||||
/*下载模型自定义属性字段*/
|
||||
$attr_field = Db::name('download_attr_field')->select();
|
||||
$servername_use = 0;
|
||||
if ($attr_field) {
|
||||
$servername_info = [];
|
||||
for ($i = 0; $i < count($attr_field); $i++) {
|
||||
if ($attr_field[$i]['field_name'] == 'server_name') {
|
||||
if ($attr_field[$i]['field_use'] == 1) {
|
||||
$servername_use = 1;
|
||||
}
|
||||
$servername_info = $attr_field[$i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$assign_data['servername_info'] = $servername_info;
|
||||
}
|
||||
$assign_data['attr_field'] = $attr_field;
|
||||
$assign_data['servername_use'] = $servername_use;
|
||||
|
||||
$servername_arr = unserialize(tpCache('download.download_select_servername'));
|
||||
$assign_data['default_servername'] = $servername_arr?$servername_arr[0]:'立即下载';
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
// 系统最大上传视频的大小 限制类型
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$basic['file_size'] = intval($min_size) * 1024 * 1024;
|
||||
$file_type = tpCache('basic.file_type');
|
||||
$basic['file_type'] = !empty($file_type) ? $file_type : "zip|gz|rar|iso|doc|xls|ppt|wps";
|
||||
$assign_data['basic'] = $basic;
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
|
||||
public function template_set()
|
||||
{
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
// 修改是否使用
|
||||
if (!empty($post) && isset($post['field_use'])) {
|
||||
$data['field_use'] = $post['field_use'];
|
||||
$data['update_time'] = getTime();
|
||||
Db::name('download_attr_field')->where('field_id',$post['field_id'])->update($data);
|
||||
$this->success("更新成功!");
|
||||
}
|
||||
// 修改标题
|
||||
if (!empty($post) && isset($post['field_title'])) {
|
||||
$data['field_title'] = $post['field_title'];
|
||||
$data['update_time'] = getTime();
|
||||
Db::name('download_attr_field')->where('field_id',$post['field_id'])->update($data);
|
||||
$this->success("更新成功!");
|
||||
}
|
||||
}
|
||||
|
||||
$list = Db::name('download_attr_field')->select();
|
||||
$assign_data['list'] = $list;
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function select_servername()
|
||||
{
|
||||
$servername_arr = unserialize(tpCache('download.download_select_servername'));
|
||||
$param = input('param.');
|
||||
$assign_data['select_servername'] = $servername_arr;
|
||||
$assign_data['file_key'] = $param['file_key'];
|
||||
$assign_data['sn_type'] = $param['sn_type'];
|
||||
$assign_data['sn_name_sub'] = $param['sn_name_sub'];
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function set_servername()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('param.');
|
||||
$servernames = htmlspecialchars($post['servername']);
|
||||
$servernames = str_replace("\r\n", "\n", trim($servernames));
|
||||
$servernames = explode("\n", $servernames);
|
||||
|
||||
$servernames_new = array_unique($servernames);
|
||||
$servernames_new = serialize($servernames_new);
|
||||
$param = ['download_select_servername'=>$servernames_new];
|
||||
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('download', $param, $val['mark']);
|
||||
}
|
||||
} else {
|
||||
tpCache('download', $param);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$this->success("更新成功!");
|
||||
}
|
||||
|
||||
$servername_arr = unserialize(tpCache('download.download_select_servername'));
|
||||
$servername_arr = implode("\n",$servername_arr);
|
||||
|
||||
$assign_data['servernames'] = $servername_arr;
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function search_servername()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('param.');
|
||||
$keyword = $post['keyword'];
|
||||
|
||||
$servernames = tpCache('download.download_select_servername');
|
||||
$servernames = unserialize($servernames);
|
||||
|
||||
$search_data = $servernames;
|
||||
if (!empty($keyword)) {
|
||||
$search_data = [];
|
||||
if ($servernames) {
|
||||
foreach ($servernames as $k => $v) {
|
||||
if (preg_match("/$keyword/s", $v)) $search_data[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->success("获取成功",null,$search_data);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_template()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
//$list = Db::name('download_attr_field')->where('field_use',1)->select();
|
||||
$list = Db::name('download_attr_field')->select();
|
||||
$this->success("查询成功!", null, $list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取七牛云token
|
||||
*/
|
||||
/* public function qiniu_upload()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$weappInfo = Db::name('weapp')->where('code','Qiniuyun')->field('id,status,data')->find();
|
||||
if (empty($weappInfo)) {
|
||||
$this->error('请先安装配置【七牛云图片加速】插件!', null, ['code'=>-1]);
|
||||
} else if (1 != $weappInfo['status']) {
|
||||
$this->error('请先启用【七牛云图片加速】插件!', null, ['code'=>-2,'id'=>$weappInfo['id']]);
|
||||
} else {
|
||||
$Qiniuyun = json_decode($weappInfo['data'], true);
|
||||
if (empty($Qiniuyun)) {
|
||||
$this->error('请先配置【七牛云图片加速】插件!', null, ['code'=>-3]);
|
||||
} else if (empty($Qiniuyun['domain'])) {
|
||||
$this->error('请先配置【七牛云图片加速】插件中的域名!', null, ['code'=>-3]);
|
||||
}
|
||||
}
|
||||
|
||||
//引入七牛云的相关文件
|
||||
weapp_vendor('Qiniu.src.Qiniu.Auth', 'Qiniuyun');
|
||||
weapp_vendor('Qiniu.src.Qiniu.Storage.UploadManager', 'Qiniuyun');
|
||||
require_once ROOT_PATH.'weapp/Qiniuyun/vendor/Qiniu/autoload.php';
|
||||
|
||||
// 配置信息
|
||||
$accessKey = $Qiniuyun['access_key'];
|
||||
$secretKey = $Qiniuyun['secret_key'];
|
||||
$bucket = $Qiniuyun['bucket'];
|
||||
$domain = '//'.$Qiniuyun['domain'];
|
||||
|
||||
// 区域对应的上传URl
|
||||
$config = new \Qiniu\Config(null);
|
||||
$uphost = $config->getUpHost($accessKey, $bucket);
|
||||
$uphost = str_replace('http://', '//', $uphost);
|
||||
|
||||
// 生成上传Token
|
||||
$auth = new \Qiniu\Auth($accessKey, $secretKey);
|
||||
$token = $auth->uploadToken($bucket);
|
||||
if ($token) {
|
||||
$filePath = UPLOAD_PATH.'soft/';
|
||||
// $filePath = UPLOAD_PATH.'soft/' . date('Ymd/') . session('admin_id') . '-' . dd2char(date("ymdHis") . mt_rand(100, 999));
|
||||
$data = [
|
||||
'token' => $token,
|
||||
'domain' => $domain,
|
||||
'uphost' => $uphost,
|
||||
'filePath' => $filePath,
|
||||
];
|
||||
$this->success('获取token成功!', null, $data);
|
||||
} else {
|
||||
$this->error('获取token失败!');
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
10
src/application/admin/controller/Encodes.php
Normal file
10
src/application/admin/controller/Encodes.php
Normal file
File diff suppressed because one or more lines are too long
1600
src/application/admin/controller/Field.php
Normal file
1600
src/application/admin/controller/Field.php
Normal file
File diff suppressed because it is too large
Load Diff
266
src/application/admin/controller/Filemanager.php
Normal file
266
src/application/admin/controller/Filemanager.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use app\admin\logic\FilemanagerLogic;
|
||||
|
||||
class Filemanager extends Base
|
||||
{
|
||||
public $filemanagerLogic;
|
||||
public $baseDir = '';
|
||||
public $maxDir = '';
|
||||
public $globalTpCache = array();
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->filemanagerLogic = new FilemanagerLogic();
|
||||
$this->globalTpCache = $this->filemanagerLogic->globalTpCache;
|
||||
$this->baseDir = $this->filemanagerLogic->baseDir; // 服务器站点根目录绝对路径
|
||||
$this->maxDir = $this->filemanagerLogic->maxDir; // 默认文件管理的最大级别目录
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.', '', null);
|
||||
$activepath = input('param.activepath', '', null);
|
||||
$activepath = $this->filemanagerLogic->replace_path($activepath, ':', true);
|
||||
|
||||
/*当前目录路径*/
|
||||
$activepath = !empty($activepath) ? $activepath : $this->maxDir;
|
||||
$tmp_max_dir = preg_replace("#\/#i", "\/", $this->maxDir);
|
||||
if (!preg_match("#^".$tmp_max_dir."#i", $activepath)) {
|
||||
$activepath = $this->maxDir;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$inpath = "";
|
||||
$activepath = str_replace("..", "", $activepath);
|
||||
$activepath = preg_replace("#^\/{1,}#", "/", $activepath); // 多个斜杆替换为单个斜杆
|
||||
if($activepath == "/") $activepath = "";
|
||||
|
||||
if(empty($activepath)) {
|
||||
$inpath = $this->baseDir.$this->maxDir;
|
||||
} else {
|
||||
$inpath = $this->baseDir.$activepath;
|
||||
}
|
||||
|
||||
$list = $this->filemanagerLogic->getDirFile($inpath, $activepath);
|
||||
$assign_data['list'] = $list;
|
||||
|
||||
/*文件操作*/
|
||||
$assign_data['replaceImgOpArr'] = $this->filemanagerLogic->replaceImgOpArr;
|
||||
$assign_data['editOpArr'] = $this->filemanagerLogic->editOpArr;
|
||||
$assign_data['renameOpArr'] = $this->filemanagerLogic->renameOpArr;
|
||||
$assign_data['delOpArr'] = $this->filemanagerLogic->delOpArr;
|
||||
$assign_data['moveOpArr'] = $this->filemanagerLogic->moveOpArr;
|
||||
/*--end*/
|
||||
|
||||
$assign_data['activepath'] = $activepath;
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 替换图片
|
||||
*/
|
||||
public function replace_img()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.', '', null);
|
||||
$activepath = !empty($post['activepath']) ? trim($post['activepath']) : '';
|
||||
if (empty($activepath)) {
|
||||
$this->error('参数有误');
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = request()->file('upfile');
|
||||
if (empty($file)) {
|
||||
$this->error('请选择上传图片!');
|
||||
exit;
|
||||
} else {
|
||||
$image_type = tpCache('basic.image_type');
|
||||
$fileExt = !empty($image_type) ? str_replace('|', ',', $image_type) : config('global.image_ext');
|
||||
$image_upload_limit_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file'=>'image|fileSize:'.$image_upload_limit_size.'|fileExt:'.$fileExt],
|
||||
['file.image' => '上传文件必须为图片','file.fileSize' => '上传文件过大','file.fileExt'=>'上传文件后缀名必须为'.$fileExt]
|
||||
);
|
||||
if (true !== $result || empty($file)) {
|
||||
$this->error($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$res = $this->filemanagerLogic->upload('upfile', $activepath, $post['filename'], 'image');
|
||||
if ($res['code'] == 1) {
|
||||
$this->success('操作成功!', url('Filemanager/index', array('activepath'=>$this->filemanagerLogic->replace_path($activepath, ':', false))));
|
||||
} else {
|
||||
$this->error($res['msg'], url('Filemanager/index', array('activepath'=>$this->filemanagerLogic->replace_path($activepath, ':', false))));
|
||||
}
|
||||
}
|
||||
|
||||
$filename = input('param.filename/s', '', null);
|
||||
|
||||
$activepath = input('param.activepath/s', '', null);
|
||||
$activepath = $this->filemanagerLogic->replace_path($activepath, ':', true);
|
||||
if ($activepath == "") $activepathname = "根目录";
|
||||
else $activepathname = $activepath;
|
||||
|
||||
$info = array(
|
||||
'activepath' => $activepath,
|
||||
'activepathname' => $activepathname,
|
||||
'filename' => $filename,
|
||||
);
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.', '', null);
|
||||
$content = input('post.content', '', null);
|
||||
$filename = !empty($post['filename']) ? trim($post['filename']) : '';
|
||||
$content = !empty($content) ? $content : '';
|
||||
$activepath = !empty($post['activepath']) ? trim($post['activepath']) : '';
|
||||
|
||||
if (empty($filename) || empty($activepath)) {
|
||||
$this->error('参数有误');
|
||||
exit;
|
||||
}
|
||||
|
||||
$r = $this->filemanagerLogic->editFile($filename, $activepath, $content);
|
||||
if ($r === true) {
|
||||
$this->success('操作成功!', url('Filemanager/index', array('activepath'=>$this->filemanagerLogic->replace_path($activepath, ':', false))));
|
||||
exit;
|
||||
} else {
|
||||
$this->error($r, null, [], 8);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$activepath = input('param.activepath/s', '', null);
|
||||
$activepath = $this->filemanagerLogic->replace_path($activepath, ':', true);
|
||||
|
||||
$filename = input('param.filename/s', '', null);
|
||||
|
||||
$activepath = str_replace("..", "", $activepath);
|
||||
$filename = str_replace("..", "", $filename);
|
||||
$path_parts = pathinfo($filename);
|
||||
$path_parts['extension'] = strtolower($path_parts['extension']);
|
||||
|
||||
/*不允许越过指定最大级目录的文件编辑*/
|
||||
$tmp_max_dir = preg_replace("#\/#i", "\/", $this->filemanagerLogic->maxDir);
|
||||
if (!preg_match("#^".$tmp_max_dir."#i", $activepath)) {
|
||||
$this->error('没有操作权限!');
|
||||
exit;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*允许编辑的文件类型*/
|
||||
if (!in_array($path_parts['extension'], $this->filemanagerLogic->editExt)) {
|
||||
$this->error('只允许操作文件类型如下:'.implode('|', $this->filemanagerLogic->editExt));
|
||||
exit;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*读取文件内容*/
|
||||
$file = $this->baseDir."$activepath/$filename";
|
||||
$content = "";
|
||||
if(is_file($file))
|
||||
{
|
||||
$filesize = filesize($file);
|
||||
if (0 < $filesize) {
|
||||
$fp = fopen($file, "r");
|
||||
$content = fread($fp, $filesize);
|
||||
fclose($fp);
|
||||
if ('htm' == $path_parts['extension']) {
|
||||
$content = htmlspecialchars($content, ENT_QUOTES);
|
||||
foreach ($this->filemanagerLogic->disableFuns as $key => $val) {
|
||||
$val_new = msubstr($val, 0, 1).'-'.msubstr($val, 1);
|
||||
$content = preg_replace("/(@)?".$val."(\s*)\(/i", "{$val_new}(", $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if($path_parts['extension'] == 'js'){
|
||||
$extension = 'text/javascript';
|
||||
} else if($path_parts['extension'] == 'css'){
|
||||
$extension = 'text/css';
|
||||
} else {
|
||||
$extension = 'text/html';
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'filename' => $filename,
|
||||
'activepath'=> $activepath,
|
||||
'extension' => $extension,
|
||||
'content' => $content,
|
||||
);
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件
|
||||
*/
|
||||
public function newfile()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.', '', null);
|
||||
$content = input('post.content', '', null);
|
||||
$filename = !empty($post['filename']) ? trim($post['filename']) : '';
|
||||
$content = !empty($content) ? $content : '';
|
||||
$activepath = !empty($post['activepath']) ? trim($post['activepath']) : '';
|
||||
|
||||
if (empty($filename) || empty($activepath)) {
|
||||
$this->error('参数有误');
|
||||
exit;
|
||||
}
|
||||
|
||||
$r = $this->filemanagerLogic->editFile($filename, $activepath, $content);
|
||||
if ($r === true) {
|
||||
$this->success('操作成功!', url('Filemanager/index', array('activepath'=>$this->filemanagerLogic->replace_path($activepath, ':', false))));
|
||||
exit;
|
||||
} else {
|
||||
$this->error($r, null, [], 8);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$activepath = input('param.activepath/s', '', null);
|
||||
$activepath = $this->filemanagerLogic->replace_path($activepath, ':', true);
|
||||
$filename = 'newfile.htm';
|
||||
$content = "";
|
||||
$info = array(
|
||||
'filename' => $filename,
|
||||
'activepath'=> $activepath,
|
||||
'content' => $content,
|
||||
'extension' => 'text/html',
|
||||
);
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
780
src/application/admin/controller/Guestbook.php
Normal file
780
src/application/admin/controller/Guestbook.php
Normal file
@@ -0,0 +1,780 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use app\common\logic\ArctypeLogic;
|
||||
|
||||
class Guestbook extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'guestbook';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
// 表单类型
|
||||
public $attrInputTypeArr = array();
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
$this->attrInputTypeArr = config('global.guestbook_attr_input_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* 留言列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$get = input('get.');
|
||||
$typeid = input('typeid/d');
|
||||
$begin = strtotime(input('param.add_time_begin/s'));
|
||||
$end = input('param.add_time_end/s');
|
||||
!empty($end) && $end .= ' 23:59:59';
|
||||
$end = strtotime($end);
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'typeid'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$attr_row = Db::name('guestbook_attr')->field('aid')->where(array('attr_value' => array('LIKE', "%{$get[$key]}%")))->group('aid')->getAllWithIndex('aid');
|
||||
$aids = array_keys($attr_row);
|
||||
$condition['a.aid'] = array('IN', $aids);
|
||||
} else if ($key == 'typeid') {
|
||||
$condition['a.typeid'] = array('eq', $get[$key]);
|
||||
} else {
|
||||
$condition['a.' . $key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
if (empty($typeid)) {
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
$is_notaccess = false;
|
||||
$permission_arctype = !empty($auth_role_info['permission']['arctype']) ? $auth_role_info['permission']['arctype'] : [];
|
||||
if(! empty($permission_arctype)){
|
||||
$typeids_tmp = Db::name('arctype')->where(['current_channel'=>8,'lang'=>$this->admin_lang])->cache(true, EYOUCMS_CACHE_TIME, 'arctype')->column('id');
|
||||
$typeids_tmp = !empty($typeids_tmp) ? $typeids_tmp : [];
|
||||
$typeids_tmp2 = array_intersect($typeids_tmp, $auth_role_info['permission']['arctype']);
|
||||
if (!empty($typeids_tmp2)) {
|
||||
$condition['a.typeid'] = ['IN', $typeids_tmp2];
|
||||
$is_notaccess = true;
|
||||
}
|
||||
}
|
||||
if (false === $is_notaccess) {
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('guestbook')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('guestbook')
|
||||
->field("b.*, a.*")
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.add_time desc')
|
||||
->limit($Page->firstRow . ',' . $Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$where = [
|
||||
'b.aid' => ['IN', array_keys($list)],
|
||||
'a.is_showlist' => 1,
|
||||
'a.lang' => $this->admin_lang,
|
||||
'a.is_del' => 0,
|
||||
];
|
||||
$row = DB::name('guestbook_attribute')
|
||||
->field('a.attr_name, b.attr_value, b.aid, b.attr_id,a.attr_input_type')
|
||||
->alias('a')
|
||||
->join('__GUESTBOOK_ATTR__ b', 'b.attr_id = a.attr_id', 'LEFT')
|
||||
->where($where)
|
||||
->order('b.aid desc, a.sort_order asc, a.attr_id asc')
|
||||
->getAllWithIndex();
|
||||
$attr_list = array();
|
||||
foreach ($row as $key => $val) {
|
||||
if (9 == $val['attr_input_type']){
|
||||
//如果是区域类型,转换名称
|
||||
$val['attr_value'] = Db::name('region')->where('id','in',$val['attr_value'])->column('name');
|
||||
$val['attr_value'] = implode('',$val['attr_value']);
|
||||
}
|
||||
if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
|
||||
if (!stristr($val['attr_value'], '|')) {
|
||||
$val['attr_value'] = handle_subdir_pic($val['attr_value']);
|
||||
$val['attr_value'] = "<img src='{$val['attr_value']}' width='60' height='60' style='float: unset;cursor: pointer;' onclick=\"Images('{$val['attr_value']}', 650, 350);\" />";
|
||||
}
|
||||
} else {
|
||||
$val['attr_value'] = str_replace(PHP_EOL, ' | ', $val['attr_value']);
|
||||
}
|
||||
$attr_list[$val['aid']][] = $val;
|
||||
}
|
||||
foreach ($list as $key => $val) {
|
||||
$list[$key]['attr_list'] = isset($attr_list[$val['aid']]) ? $attr_list[$val['aid']] : array();
|
||||
}
|
||||
}
|
||||
$assign_data['tab_list'] = Db::name('guestbook_attribute')->where([
|
||||
'typeid' => $typeid,
|
||||
'is_showlist' => 1,
|
||||
'lang' => $this->admin_lang,
|
||||
'is_del' => 0,
|
||||
])->order('sort_order asc, attr_id asc')->select();
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = Db::name('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if (!empty($id_arr)) {
|
||||
$r = Db::name('guestbook')->where([
|
||||
'aid' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])->delete();
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Guestbook')->afterDel($id_arr);
|
||||
// ---------end
|
||||
adminLog('删除留言-id:' . implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 留言表单表单列表
|
||||
*/
|
||||
public function attribute_index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$get = input('get.');
|
||||
$typeid = input('typeid/d');
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.attr_name'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeids = model('Arctype')->getHasChildren($get[$key]);
|
||||
$condition['a.typeid'] = array('IN', array_keys($typeids));
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$condition['b.id'] = ['gt', 0];
|
||||
$condition['a.is_del'] = 0;
|
||||
// 多语言
|
||||
$condition['a.lang'] = $this->admin_lang;
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('guestbook_attribute')->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where($condition)
|
||||
->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('guestbook_attribute')
|
||||
->field("a.attr_id")
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.typeid desc, a.sort_order asc, a.attr_id asc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('attr_id');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$attr_ida = array_keys($list);
|
||||
$fields = "b.*, a.*";
|
||||
$row = DB::name('guestbook_attribute')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.attr_id', 'in', $attr_ida)
|
||||
->getAllWithIndex('attr_id');
|
||||
|
||||
/*获取多语言关联绑定的值*/
|
||||
$row = model('LanguageAttr')->getBindValue($row, 'guestbook_attribute', $this->main_lang); // 多语言
|
||||
/*--end*/
|
||||
|
||||
foreach ($row as $key => $val) {
|
||||
$val['fieldname'] = 'attr_'.$val['attr_id'];
|
||||
$row[$key] = $val;
|
||||
}
|
||||
foreach ($list as $key => $val) {
|
||||
$list[$key] = $row[$val['attr_id']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
/*获取当前模型栏目*/
|
||||
$select_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$typeidNum = substr_count($select_html, '</option>');
|
||||
$this->assign('select_html',$select_html);
|
||||
$this->assign('typeidNum',$typeidNum);
|
||||
/*--end*/
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = Db::name('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
$assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增留言表单
|
||||
*/
|
||||
public function attribute_add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if(IS_AJAX && IS_POST)//ajax提交验证
|
||||
{
|
||||
$model = model('GuestbookAttribute');
|
||||
|
||||
$attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
|
||||
$attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
|
||||
$attr_values = trim($attr_values);
|
||||
|
||||
/*过滤重复值*/
|
||||
$attr_values_arr = explode(PHP_EOL, $attr_values);
|
||||
foreach ($attr_values_arr as $key => $val) {
|
||||
$tmp_val = trim($val);
|
||||
if (empty($tmp_val)) {
|
||||
unset($attr_values_arr[$key]);
|
||||
continue;
|
||||
}
|
||||
$attr_values_arr[$key] = $tmp_val;
|
||||
}
|
||||
$attr_values_arr = array_unique($attr_values_arr);
|
||||
$attr_values = implode(PHP_EOL, $attr_values_arr);
|
||||
/*end*/
|
||||
|
||||
$post_data = input('post.');
|
||||
$post_data['attr_values'] = $attr_values;
|
||||
$attr_input_type = isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : 0;
|
||||
|
||||
/*前台输入是否JS验证*/
|
||||
$validate_type = 0;
|
||||
$validate_type_list = config("global.validate_type_list"); // 前台输入验证类型
|
||||
if (!empty($validate_type_list[$attr_input_type])) {
|
||||
$validate_type = $attr_input_type;
|
||||
}
|
||||
/*end*/
|
||||
if (9 == $post_data['attr_input_type']) {
|
||||
if (!empty($post_data['region_data'])) {
|
||||
$post_data['attr_values'] = serialize($post_data['region_data']);
|
||||
} else {
|
||||
$this->error("请选择区域范围!");
|
||||
}
|
||||
}
|
||||
$savedata = array(
|
||||
'attr_name' => $post_data['attr_name'],
|
||||
'typeid' => $post_data['typeid'],
|
||||
'attr_input_type' => $attr_input_type,
|
||||
'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
|
||||
'is_showlist' => $post_data['is_showlist'],
|
||||
'required' => $post_data['required'],
|
||||
'validate_type' => $validate_type,
|
||||
'sort_order' => 100,
|
||||
'lang' => $this->admin_lang,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
|
||||
// 数据验证
|
||||
$validate = \think\Loader::validate('GuestbookAttribute');
|
||||
if(!$validate->batch()->check($savedata))
|
||||
{
|
||||
$error = $validate->getError();
|
||||
$error_msg = array_values($error);
|
||||
$return_arr = array(
|
||||
'status' => -1,
|
||||
'msg' => $error_msg[0],
|
||||
'data' => $error,
|
||||
);
|
||||
respose($return_arr);
|
||||
} else {
|
||||
$model->data($savedata,true); // 收集数据
|
||||
$model->save(); // 写入数据到数据库
|
||||
$insertId = $model->getLastInsID();
|
||||
|
||||
/*同步留言属性ID到多语言的模板变量里*/
|
||||
model('GuestbookAttribute')->syn_add_language_attribute($insertId);
|
||||
/*--end*/
|
||||
|
||||
$return_arr = array(
|
||||
'status' => 1,
|
||||
'msg' => '操作成功',
|
||||
'data' => array('url'=>url('Guestbook/attribute_index', array('typeid'=>$post_data['typeid']))),
|
||||
);
|
||||
adminLog('新增留言表单:'.$savedata['attr_name']);
|
||||
respose($return_arr);
|
||||
}
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
if ($typeid > 0) {
|
||||
$select_html = Db::name('arctype')->where('id', $typeid)->getField('typename');
|
||||
$select_html = !empty($select_html) ? $select_html : '该栏目不存在';
|
||||
} else {
|
||||
$arctypeLogic = new ArctypeLogic();
|
||||
$map = array(
|
||||
'channeltype' => $this->channeltype,
|
||||
);
|
||||
$arctype_max_level = intval(config('global.arctype_max_level'));
|
||||
$select_html = $arctypeLogic->arctype_list(0, $typeid, true, $arctype_max_level, $map);
|
||||
}
|
||||
$assign_data['select_html'] = $select_html; //
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
$assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
|
||||
//区域
|
||||
$China[] = [
|
||||
'id' => 0,
|
||||
'name' => '全国',
|
||||
];
|
||||
$Province = get_province_list();
|
||||
$assign_data['Province'] = array_merge($China, $Province);
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑留言表单
|
||||
*/
|
||||
public function attribute_edit()
|
||||
{
|
||||
if(IS_AJAX && IS_POST)//ajax提交验证
|
||||
{
|
||||
$model = model('GuestbookAttribute');
|
||||
|
||||
$attr_values = str_replace('_', '', input('attr_values')); // 替换特殊字符
|
||||
$attr_values = str_replace('@', '', $attr_values); // 替换特殊字符
|
||||
$attr_values = trim($attr_values);
|
||||
|
||||
/*过滤重复值*/
|
||||
$attr_values_arr = explode(PHP_EOL, $attr_values);
|
||||
foreach ($attr_values_arr as $key => $val) {
|
||||
$tmp_val = trim($val);
|
||||
if (empty($tmp_val)) {
|
||||
unset($attr_values_arr[$key]);
|
||||
continue;
|
||||
}
|
||||
$attr_values_arr[$key] = $tmp_val;
|
||||
}
|
||||
$attr_values_arr = array_unique($attr_values_arr);
|
||||
$attr_values = implode(PHP_EOL, $attr_values_arr);
|
||||
/*end*/
|
||||
|
||||
$post_data = input('post.');
|
||||
$post_data['attr_values'] = $attr_values;
|
||||
$attr_input_type = isset($post_data['attr_input_type']) ? $post_data['attr_input_type'] : 0;
|
||||
|
||||
/*前台输入是否JS验证*/
|
||||
$validate_type = 0;
|
||||
$validate_type_list = config("global.validate_type_list"); // 前台输入验证类型
|
||||
if (!empty($validate_type_list[$attr_input_type])) {
|
||||
$validate_type = $attr_input_type;
|
||||
}
|
||||
/*end*/
|
||||
if (9 == $post_data['attr_input_type']) {
|
||||
if (!empty($post_data['region_data'])) {
|
||||
$post_data['attr_values'] = serialize($post_data['region_data']);
|
||||
} else {
|
||||
$this->error("请选择区域范围!");
|
||||
}
|
||||
}
|
||||
$savedata = array(
|
||||
'attr_id' => $post_data['attr_id'],
|
||||
'attr_name' => $post_data['attr_name'],
|
||||
'typeid' => $post_data['typeid'],
|
||||
'attr_input_type' => $attr_input_type,
|
||||
'attr_values' => isset($post_data['attr_values']) ? $post_data['attr_values'] : '',
|
||||
'is_showlist' => $post_data['is_showlist'],
|
||||
'required' => $post_data['required'],
|
||||
'validate_type' => $validate_type,
|
||||
'sort_order' => 100,
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
// 数据验证
|
||||
$validate = \think\Loader::validate('GuestbookAttribute');
|
||||
if(!$validate->batch()->check($savedata))
|
||||
{
|
||||
$error = $validate->getError();
|
||||
$error_msg = array_values($error);
|
||||
$return_arr = array(
|
||||
'status' => -1,
|
||||
'msg' => $error_msg[0],
|
||||
'data' => $error,
|
||||
);
|
||||
respose($return_arr);
|
||||
} else {
|
||||
$model->data($savedata, true); // 收集数据
|
||||
$model->isUpdate(true, [
|
||||
'attr_id' => $post_data['attr_id'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->save(); // 写入数据到数据库
|
||||
$return_arr = array(
|
||||
'status' => 1,
|
||||
'msg' => '操作成功',
|
||||
'data' => array('url' => url('Guestbook/attribute_index', array('typeid' => $post_data['typeid']))),
|
||||
);
|
||||
adminLog('编辑留言表单:' . $savedata['attr_name']);
|
||||
respose($return_arr);
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
/*获取多语言关联绑定的值*/
|
||||
$new_id = model('LanguageAttr')->getBindValue($id, 'guestbook_attribute'); // 多语言
|
||||
!empty($new_id) && $id = $new_id;
|
||||
/*--end*/
|
||||
$info = Db::name('GuestbookAttribute')->where([
|
||||
'attr_id' => $id,
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
// 所在栏目
|
||||
$select_html = Db::name('arctype')->where('id', $info['typeid'])->getField('typename');
|
||||
$select_html = !empty($select_html) ? $select_html : '该栏目不存在';
|
||||
$assign_data['select_html'] = $select_html;
|
||||
|
||||
$assign_data['attrInputTypeArr'] = $this->attrInputTypeArr; // 表单类型
|
||||
/*区域字段处理*/
|
||||
// 初始化参数
|
||||
$assign_data['region'] = [
|
||||
'parent_id' => '-1',
|
||||
'region_id' => '-1',
|
||||
'region_names' => '',
|
||||
'region_ids' => '',
|
||||
];
|
||||
// 定义全国参数
|
||||
$China[] = [
|
||||
'id' => 0,
|
||||
'name' => '全国',
|
||||
];
|
||||
// 查询省份信息并且拼装上$China数组
|
||||
$Province = get_province_list();
|
||||
$assign_data['Province'] = array_merge($China, $Province);
|
||||
// 区域选择时,指定不出现下级地区列表
|
||||
$assign_data['parent_array'] = "[]";
|
||||
// 如果是区域类型则执行
|
||||
if (9 == $info['attr_input_type']) {
|
||||
// 反序列化默认值参数
|
||||
$dfvalue = unserialize($info['attr_values']);
|
||||
if (0 == $dfvalue['region_id']) {
|
||||
$parent_id = $dfvalue['region_id'];
|
||||
} else {
|
||||
// 查询当前选中的区域父级ID
|
||||
$parent_id = Db::name('region')->where("id", $dfvalue['region_id'])->getField('parent_id');
|
||||
if (0 == $parent_id) {
|
||||
$parent_id = $dfvalue['region_id'];
|
||||
}
|
||||
}
|
||||
|
||||
// 查询市\区\县信息
|
||||
$assign_data['City'] = Db::name('region')->where("parent_id", $parent_id)->select();
|
||||
// 加载数据到模板
|
||||
$assign_data['region'] = [
|
||||
'parent_id' => $parent_id,
|
||||
'region_id' => $dfvalue['region_id'],
|
||||
'region_names' => $dfvalue['region_names'],
|
||||
'region_ids' => $dfvalue['region_ids'],
|
||||
];
|
||||
|
||||
// 删除默认值,防止切换其他类型时使用到
|
||||
unset($info['attr_values']);
|
||||
|
||||
// 区域选择时,指定不出现下级地区列表
|
||||
$assign_data['parent_array'] = convert_js_array(config('global.field_region_all_type'));
|
||||
}
|
||||
/*区域字段处理结束*/
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除留言表单
|
||||
*/
|
||||
public function attribute_del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if (!empty($id_arr)) {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'attr_' . $val;
|
||||
}
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'guestbook_attribute',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
$r = Db::name('GuestbookAttribute')->where([
|
||||
'attr_id' => ['IN', $id_arr],
|
||||
])->update([
|
||||
'is_del' => 1,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if($r){
|
||||
adminLog('删除留言表单-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看详情
|
||||
*/
|
||||
public function details()
|
||||
{
|
||||
$aid = input('param.aid/d');
|
||||
|
||||
// 标记为已读和IP地区
|
||||
$row = Db::name('guestbook')->find($aid);
|
||||
$city = "";
|
||||
$city_arr = getCityLocation($row['ip']);
|
||||
if (!empty($city_arr)) {
|
||||
!empty($city_arr['location']) && $city .= $city_arr['location'];
|
||||
}
|
||||
$row['city'] = $city;
|
||||
$this->assign('row', $row);
|
||||
|
||||
// 留言属性
|
||||
$condition['a.aid'] = $aid;
|
||||
$condition['a.lang'] = $this->admin_lang;
|
||||
$attr_list = Db::name('guestbook_attr')
|
||||
->field("b.*, a.*")
|
||||
->alias('a')
|
||||
->join('__GUESTBOOK_ATTRIBUTE__ b', 'a.attr_id = b.attr_id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.attr_id asc')
|
||||
->select();
|
||||
foreach ($attr_list as $key => &$val) {
|
||||
if ($val['attr_input_type'] == 9) {
|
||||
$val['attr_value'] = Db::name('region')->where('id','in',$val['attr_value'])->column('name');
|
||||
$val['attr_value'] = implode('',$val['attr_value']);
|
||||
} else if ($val['attr_input_type'] == 4) {
|
||||
$val['attr_value'] = filter_line_return($val['attr_value'], '、');
|
||||
} else {
|
||||
if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
|
||||
if (!stristr($val['attr_value'], '|')) {
|
||||
$val['attr_value'] = handle_subdir_pic($val['attr_value']);
|
||||
$val['attr_value'] = "<a href='{$val['attr_value']}' target='_blank'><img src='{$val['attr_value']}' width='60' height='60' style='float: unset;cursor: pointer;' /></a>";
|
||||
}
|
||||
}elseif (preg_match('/(\.('.tpCache('basic.file_type').'))$/i', $val['attr_value'])){
|
||||
if (!stristr($val['attr_value'], '|')) {
|
||||
$val['attr_value'] = handle_subdir_pic($val['attr_value']);
|
||||
$val['attr_value'] = "<a href='{$val['attr_value']}' download='".time()."'><img src=\"".ROOT_DIR."/public/static/common/images/file.png\" alt=\"\" style=\"width: 16px;height: 16px;\">点击下载</a>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('attr_list', $attr_list);
|
||||
|
||||
// 标记为已读
|
||||
Db::name('guestbook')->where(['aid'=>$aid, 'lang'=>$this->admin_lang])->update([
|
||||
'is_read' => 1,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* excel导出
|
||||
*/
|
||||
public function excel_export()
|
||||
{
|
||||
$id_arr = input('aid/s');
|
||||
if (!empty($id_arr)) {
|
||||
$id_arr = explode(',', $id_arr);
|
||||
$id_arr = eyIntval($id_arr);
|
||||
}
|
||||
$typeid = input('typeid/d');
|
||||
$start_time = input('start_time/s');
|
||||
$end_time = input('end_time/s');
|
||||
|
||||
$strTable = '<table width="500" border="1">';
|
||||
$where = [];
|
||||
$where['typeid'] = $typeid;
|
||||
$where['lang'] = $this->admin_lang;
|
||||
$order = 'add_time asc';
|
||||
//没有指定ID就导出全部
|
||||
if (!empty($id_arr)) {
|
||||
$where['aid'] = ['IN', $id_arr];
|
||||
}
|
||||
//根据日期导出
|
||||
if (!empty($start_time) && !empty($end_time)) {
|
||||
$start_time = strtotime($start_time);
|
||||
$end_time = strtotime("+1 day", strtotime($end_time)) - 1;
|
||||
$where['add_time'] = ['between', [$start_time, $end_time]];
|
||||
} elseif (!empty($start_time) && empty($end_time)) {
|
||||
$start_time = strtotime($start_time);
|
||||
$where['add_time'] = ['>=', $start_time];
|
||||
} elseif (empty($start_time) && !empty($end_time)) {
|
||||
$end_time = strtotime("+1 day", strtotime($end_time)) - 1;
|
||||
$where['add_time'] = ['<=', $end_time];
|
||||
}
|
||||
$row = Db::name('guestbook')->where($where)->order($order)->select();
|
||||
|
||||
$title = Db::name('guestbook_attribute')->where([
|
||||
'typeid' => $typeid,
|
||||
'lang' => $this->admin_lang,
|
||||
'is_del' => 0,
|
||||
])->order('sort_order asc, attr_id asc')->select();
|
||||
|
||||
if ($row && $title) {
|
||||
$strTable .= '<tr>';
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;" width="*">ID</td>';
|
||||
foreach ($title as &$key) {
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;" width="*">' . $key['attr_name'] . '</td>';
|
||||
}
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;" width="*">新增时间</td>';
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;" width="*">更新时间</td>';
|
||||
$strTable .= '</tr>';
|
||||
|
||||
foreach ($row as &$val) {
|
||||
$attr_value = Db::name('guestbook_attr')
|
||||
->alias('a')
|
||||
->field('a.*,b.attr_input_type')
|
||||
->where(['a.aid' => $val['aid'], 'a.lang' => $this->admin_lang])
|
||||
->join('guestbook_attribute b','a.attr_id = b.attr_id')
|
||||
->getAllWithIndex('attr_id');
|
||||
foreach ($attr_value as $k => $v){
|
||||
if ($v['attr_input_type'] == 9){
|
||||
$v['attr_value'] = Db::name('region')->where('id','in',$v['attr_value'])->column('name');
|
||||
$attr_value[$k]['attr_value'] = implode('',$v['attr_value']);
|
||||
}
|
||||
}
|
||||
|
||||
$strTable .= '<tr>';
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;">' . $val['aid'] . '</td>';
|
||||
foreach ($title as &$key) {
|
||||
$strTable .= '<td style="text-align:center;font-size:12px;" style=\'vnd.ms-excel.numberformat:@\' width="*">' . $attr_value[$key['attr_id']]['attr_value'] . '</td>';
|
||||
}
|
||||
$strTable .= '<td style="text-align:left;font-size:12px;">' . date('Y-m-d H:i:s', $val['add_time']) . '</td>';
|
||||
$strTable .= '<td style="text-align:left;font-size:12px;">' . date('Y-m-d H:i:s', $val['update_time']) . '</td>';
|
||||
$strTable .= '</tr>';
|
||||
}
|
||||
}
|
||||
$strTable .= '</table>';
|
||||
downloadExcel($strTable, 'guestbook');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
673
src/application/admin/controller/Images.php
Normal file
673
src/application/admin/controller/Images.php
Normal file
@@ -0,0 +1,673 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Images extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'images';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
empty($this->channeltype) && $this->channeltype = 3;
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('archives')
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = DB::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做自动通过审核判断
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$post['arcrank'] = -1;
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = Db::name('archives')->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model('Images')->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增图集:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// 文档默认浏览量
|
||||
$other_config = tpCache('other');
|
||||
if (isset($other_config['other_arcclick']) && 0 <= $other_config['other_arcclick']) {
|
||||
$arcclick_arr = explode("|", $other_config['other_arcclick']);
|
||||
if (count($arcclick_arr) > 1) {
|
||||
$assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcclick_config['other_arcclick'] = '500|1000';
|
||||
tpCache('other', $arcclick_config);
|
||||
$assign_data['rand_arcclick'] = mt_rand(500, 1000);
|
||||
}
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'aid' => ['NEQ', $post['aid']],
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
|
||||
//做未通过审核文档不允许修改文档状态操作
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
|
||||
if ($old_archives_arcrank < 0) {
|
||||
unset($post['arcrank']);
|
||||
}
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = Db::name('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Images')->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑图集:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model('Images')->getInfo($id);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
$assign_data['typeid'] = $typeid;
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
// 图集相册
|
||||
$imgupload_list = model('ImagesUpload')->getImgUpload($id);
|
||||
foreach ($imgupload_list as $key => $val) {
|
||||
$imgupload_list[$key]['image_url'] = handle_subdir_pic($val['image_url']); // 支持子目录
|
||||
}
|
||||
$assign_data['imgupload_list'] = $imgupload_list;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图集相册图
|
||||
*/
|
||||
public function del_imgupload()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$filename= input('filename/s');
|
||||
$filename= str_replace('../','',$filename);
|
||||
$filename= trim($filename,'.');
|
||||
if(eyPreventShell($filename) && !empty($filename)){
|
||||
$filename_new = trim($filename,'/');
|
||||
$filetype = preg_replace('/^(.*)\.(\w+)$/i', '$2', $filename);
|
||||
$phpfile = strtolower(strstr($filename,'.php')); //排除PHP文件
|
||||
$size = getimagesize($filename_new);
|
||||
$fileInfo = explode('/',$size['mime']);
|
||||
if((file_exists($filename_new) && $fileInfo[0] != 'image') || $phpfile || !in_array($filetype, explode(',', config('global.image_ext')))){
|
||||
exit;
|
||||
}
|
||||
if (!empty($filename)) {
|
||||
M('images_upload')->where("image_url = '$filename'")->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1165
src/application/admin/controller/Index.php
Normal file
1165
src/application/admin/controller/Index.php
Normal file
File diff suppressed because it is too large
Load Diff
1333
src/application/admin/controller/Language.php
Normal file
1333
src/application/admin/controller/Language.php
Normal file
File diff suppressed because it is too large
Load Diff
242
src/application/admin/controller/Level.php
Normal file
242
src/application/admin/controller/Level.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-06-21
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class Level extends Base {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
/*会员中心数据表*/
|
||||
$this->users_db = Db::name('users'); // 会员信息表
|
||||
$this->users_level_db = Db::name('users_level'); // 会员等级表
|
||||
$this->users_money_db = Db::name('users_money'); // 会员充值表
|
||||
$this->users_type_manage_db = Db::name('users_type_manage'); // 会员等级表
|
||||
/*结束*/
|
||||
|
||||
// 是否开启支付功能设置
|
||||
$UsersConfigData = getUsersConfigData('all');
|
||||
$this->assign('userConfig',$UsersConfigData);
|
||||
|
||||
// 模型是否开启
|
||||
$channeltype_row = \think\Cache::get('extra_global_channeltype');
|
||||
$this->assign('channeltype_row',$channeltype_row);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// 会员级别
|
||||
$list = $this->users_level_db->where(['is_system'=>0])->order('level_value asc, level_id asc')->select();
|
||||
$this->assign('list',$list);
|
||||
|
||||
// 会员升级期限
|
||||
$member_limit_arr = Config::get('global.admin_member_limit_arr');
|
||||
$this->assign('member_limit_arr',$member_limit_arr);
|
||||
|
||||
// 会员升级产品分类
|
||||
$users_type = $this->users_type_manage_db->order('sort_order asc, type_id asc')->select();
|
||||
$this->assign('users_type',$users_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员升级业务列表
|
||||
*/
|
||||
public function upgrade_index()
|
||||
{
|
||||
// 查询条件
|
||||
$where = [
|
||||
// 升级消费
|
||||
'a.cause_type' => 0,
|
||||
// 已完成状态
|
||||
'a.status' => 2,
|
||||
// 语言标识
|
||||
'a.lang' => $this->admin_lang,
|
||||
];
|
||||
// 订单号查询
|
||||
$order_number = input('order_number/s');
|
||||
if (!empty($order_number)) {
|
||||
$where['order_number'] = array('LIKE', "%{$order_number}%");
|
||||
}
|
||||
|
||||
//时间检索条件
|
||||
$begin = strtotime(input('param.add_time_begin/s'));
|
||||
$end = input('param.add_time_end/s');
|
||||
!empty($end) && $end .= ' 23:59:59';
|
||||
$end = strtotime($end);
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$where['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$where['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$where['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 查询满足要求的总记录数
|
||||
$count = $this->users_money_db->alias('a')->where($where)->count('moneyid');
|
||||
$total_money = $this->users_money_db->alias('a')->where($where)->value("SUM(`money`) as `total_money`");
|
||||
$this->assign('total_money', $total_money);
|
||||
|
||||
// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$pageObj = new Page($count, config('paginate.list_rows'));
|
||||
// 订单表数据查询
|
||||
$list = $this->users_money_db->field('a.*,b.username')
|
||||
->alias('a')
|
||||
->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
|
||||
->where($where)
|
||||
->order('moneyid desc')
|
||||
->limit($pageObj->firstRow.','.$pageObj->listRows)
|
||||
->select();
|
||||
foreach ($list as $key => $value) {
|
||||
// 反序列化参数
|
||||
$list[$key]['cause'] = unserialize($value['cause']);
|
||||
}
|
||||
|
||||
// 分页显示
|
||||
$pageStr = $pageObj->show();
|
||||
$this->assign('page', $pageStr);
|
||||
$this->assign('pager', $pageObj);
|
||||
|
||||
// 订单数据
|
||||
$this->assign('list',$list);
|
||||
|
||||
// 支付方式
|
||||
$pay_method_arr = config('global.pay_method_arr');
|
||||
$this->assign('pay_method_arr',$pay_method_arr);
|
||||
|
||||
// 支付状态
|
||||
$pay_status_arr = config('global.pay_status_arr');
|
||||
$this->assign('pay_status_arr',$pay_status_arr);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员升级
|
||||
*/
|
||||
public function upgrade_del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
$result = Db::name('users_money')->field('order_number')
|
||||
->where([
|
||||
'moneyid' => ['IN', $id_arr],
|
||||
'cause_type' => 0,
|
||||
'lang' => $this->admin_lang,
|
||||
])->select();
|
||||
$order_number_list = get_arr_column($result, 'order_number');
|
||||
|
||||
$r = Db::name('users_money')->where([
|
||||
'moneyid' => ['IN', $id_arr],
|
||||
'cause_type' => 0,
|
||||
'lang' => $this->admin_lang,
|
||||
])
|
||||
->cache(true, null, "users_money")
|
||||
->delete();
|
||||
if($r !== false){
|
||||
adminLog('删除会员升级记录:'.implode(',', $order_number_list));
|
||||
$this->success('删除成功');
|
||||
}
|
||||
}
|
||||
$this->error('删除失败');
|
||||
}
|
||||
$this->error('非法访问');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function level_type_del()
|
||||
{
|
||||
$type_id = input('type_id/d');
|
||||
if (IS_AJAX_POST && !empty($type_id)) {
|
||||
$where = [
|
||||
'type_id' => $type_id,
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
$type_name_list = $this->users_type_manage_db->where($where)->getField('type_name');
|
||||
// 删除会员升级级别
|
||||
$return = $this->users_type_manage_db->where($where)->delete();
|
||||
if ($return) {
|
||||
adminLog('删除会员升级级别:'.$type_name_list);
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
$this->error('参数有误');
|
||||
}
|
||||
|
||||
// 新增/修改
|
||||
public function add_level_data()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
// 处理新增数据
|
||||
$AddLevelData = [];
|
||||
foreach ($post['type_name'] as $key => $value) {
|
||||
$type_id = $post['type_id'][$key];
|
||||
$type_name = trim($value);
|
||||
$level_id = $post['level_id'][$key];
|
||||
$price = $post['price'][$key];
|
||||
$limit_id = $post['limit_id'][$key];
|
||||
$sort_order = $post['sort_order'][$key];
|
||||
|
||||
if (empty($type_name)) $this->error('产品名称不可为空');
|
||||
if (empty($level_id)) $this->error('会员级别不可为空');
|
||||
if (empty($price)) $this->error('产品价格不可为空');
|
||||
if (empty($limit_id)) $this->error('会员期限不可为空');
|
||||
|
||||
$AddLevelData[] = [
|
||||
'type_id' => $type_id,
|
||||
'type_name' => $type_name,
|
||||
'level_id' => $level_id,
|
||||
'price' => $price,
|
||||
'limit_id' => $limit_id,
|
||||
'sort_order' => $sort_order,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
|
||||
if (empty($type_id)) {
|
||||
$AddLevelData[$key]['lang'] = $this->admin_lang;
|
||||
$AddLevelData[$key]['add_time'] = getTime();
|
||||
unset($AddLevelData[$key]['type_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($AddLevelData)) {
|
||||
$ReturnId = model('UsersTypeManage')->saveAll($AddLevelData);
|
||||
}
|
||||
|
||||
// 返回
|
||||
if (!empty($ReturnId)) {
|
||||
$this->success('保存成功');
|
||||
}else{
|
||||
$this->error('保存失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
193
src/application/admin/controller/Links.php
Normal file
193
src/application/admin/controller/Links.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
use think\Cache;
|
||||
|
||||
class Links extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
$condition = array();
|
||||
if (!empty($keywords)) {
|
||||
$condition['a.title'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
$fields = "a.*,b.group_name";
|
||||
|
||||
$linksM = M('links');
|
||||
$count = $linksM->alias("a")->where($condition)->count('a.id');// 查询满足要求的总记录数
|
||||
$Page = $pager = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $linksM->alias("a")->join('links_group b',"a.groupid=b.id",'LEFT')->field($fields)->where($condition)->order('a.sort_order asc, a.id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$pager);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加友情链接
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
// 处理LOGO
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$logo = '';
|
||||
if ($is_remote == 1) {
|
||||
$logo = $post['logo_remote'];
|
||||
} else {
|
||||
$logo = $post['logo_local'];
|
||||
}
|
||||
$post['logo'] = $logo;
|
||||
// --存储数据
|
||||
$nowData = array(
|
||||
'typeid' => empty($post['typeid']) ? 1 : $post['typeid'],
|
||||
'groupid' => empty($post['groupid']) ? 1 : $post['groupid'],
|
||||
'url' => trim($post['url']),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $nowData);
|
||||
$insertId = M('links')->insertGetId($data);
|
||||
if (false !== $insertId) {
|
||||
Cache::clear('links');
|
||||
adminLog('新增友情链接:'.$post['title']);
|
||||
$this->success("操作成功!", url('Links/index'));
|
||||
}else{
|
||||
$this->error("操作失败!", url('Links/index'));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$group_ids = M('links_group')->field('id,group_name,status')->order("sort_order asc, id asc")->select();
|
||||
$this->assign('group_ids',$group_ids);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑友情链接
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$r = false;
|
||||
if(!empty($post['id'])){
|
||||
// 处理LOGO
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$logo = '';
|
||||
if ($is_remote == 1) {
|
||||
$logo = $post['logo_remote'];
|
||||
} else {
|
||||
$logo = $post['logo_local'];
|
||||
}
|
||||
$post['logo'] = $logo;
|
||||
// --存储数据
|
||||
$nowData = array(
|
||||
'typeid' => empty($post['typeid']) ? 1 : $post['typeid'],
|
||||
'groupid' => empty($post['groupid']) ? 1 : $post['groupid'],
|
||||
'url' => trim($post['url']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $nowData);
|
||||
$r = M('links')->where([
|
||||
'id' => $post['id'],
|
||||
'lang' => $this->admin_lang,
|
||||
])
|
||||
->cache(true, null, "links")
|
||||
->update($data);
|
||||
}
|
||||
if (false !== $r) {
|
||||
adminLog('编辑友情链接:'.$post['title']);
|
||||
$this->success("操作成功!",url('Links/index'));
|
||||
}else{
|
||||
$this->error("操作失败!",url('Links/index'));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = input('id/d');
|
||||
$info = M('links')->where([
|
||||
'id' => $id,
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
if (is_http_url($info['logo'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['logo_remote'] = handle_subdir_pic($info['logo']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['logo_local'] = handle_subdir_pic($info['logo']);
|
||||
}
|
||||
|
||||
$group_ids = M('links_group')->field('id,group_name,status')->order("sort_order asc, id asc")->select();
|
||||
$this->assign('group_ids',$group_ids);
|
||||
$this->assign('info',$info);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除友情链接
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
$result = M('links')->field('title')
|
||||
->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])->select();
|
||||
$title_list = get_arr_column($result, 'title');
|
||||
|
||||
$r = M('links')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])
|
||||
->cache(true, null, "links")
|
||||
->delete();
|
||||
if($r){
|
||||
adminLog('删除友情链接:'.implode(',', $title_list));
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
$this->error('非法访问');
|
||||
}
|
||||
}
|
||||
142
src/application/admin/controller/LinksGroup.php
Normal file
142
src/application/admin/controller/LinksGroup.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
use think\Cache;
|
||||
|
||||
class LinksGroup extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
$condition = array();
|
||||
if (!empty($keywords)) {
|
||||
$condition['group_name'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
|
||||
$linksgroupsM = M('links_group');
|
||||
$count = $linksgroupsM->where($condition)->count('id');// 查询满足要求的总记录数
|
||||
$Page = $pager = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $linksgroupsM->where($condition)->order('sort_order asc, id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$pager);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存友情链接分组
|
||||
*/
|
||||
public function linksgroup_save()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
if (empty($post['group_name'])) {
|
||||
$this->error('至少新增一个链接分组!');
|
||||
} else {
|
||||
$is_empty = true;
|
||||
foreach ($post['group_name'] as $key => $val) {
|
||||
$val = trim($val);
|
||||
if (!empty($val)) {
|
||||
$is_empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (true === $is_empty) {
|
||||
$this->error('分组名称不能为空!');
|
||||
}
|
||||
}
|
||||
|
||||
// 数据处理
|
||||
$now_time = getTime();
|
||||
$admin_lang = $this->admin_lang;
|
||||
foreach ($post['group_name'] as $key => $val) {
|
||||
$group_name = trim($val);
|
||||
if (!empty($group_name)) {
|
||||
if (empty($post['id'][$key])) {
|
||||
$addData = [
|
||||
'group_name' => $group_name,
|
||||
'sort_order' => $post['sort_order'][$key] ? :100,
|
||||
'lang' => $admin_lang,
|
||||
'add_time' => $now_time,
|
||||
'update_time' => $now_time,
|
||||
];
|
||||
Db::name("links_group")->insert($addData);
|
||||
} else {
|
||||
$id = intval($post['id'][$key]);
|
||||
$editData = [
|
||||
'group_name' => $group_name,
|
||||
'sort_order' => $post['sort_order'][$key] ? :100,
|
||||
'lang' => $this->admin_lang,
|
||||
'update_time' => $now_time,
|
||||
];
|
||||
Db::name("links_group")->where(['id'=>$id])->update($editData);
|
||||
}
|
||||
}
|
||||
}
|
||||
adminLog('保存链接分组:'.implode(',', $post['group_name']));
|
||||
$this->success('保存成功');
|
||||
}
|
||||
$this->error('非法访问!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除友情链接分组
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
$result = M('links_group')->field('group_name')
|
||||
->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])->select();
|
||||
$group_name_list = get_arr_column($result, 'group_name');
|
||||
|
||||
$r = M('links_group')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
|
||||
])
|
||||
->cache(true, null, "links_group")
|
||||
->delete();
|
||||
M('links')->where([
|
||||
'groupid' => ['IN', $id_arr],
|
||||
|
||||
])
|
||||
->cache(true, null, "links_group")
|
||||
->delete();
|
||||
if($r){
|
||||
adminLog('删除友情链接分组:'.implode(',', $group_name_list));
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
$this->error('非法访问');
|
||||
}
|
||||
}
|
||||
55
src/application/admin/controller/Map.php
Normal file
55
src/application/admin/controller/Map.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
class Map extends Base
|
||||
{
|
||||
public function getLocationByAddress()
|
||||
{
|
||||
$address = input('param.address/s');
|
||||
$ak = base64_decode(config('global.baidu_map_ak'));
|
||||
$url = $this->request->scheme()."://api.map.baidu.com/geocoder/v2/?address={$address}&city=&output=json&ak={$ak}";
|
||||
$result = httpRequest($url);
|
||||
$result = json_decode($result, true);
|
||||
if (!empty($result) && $result['status'] == 0) {
|
||||
$data['lng'] = $result['result']['location']['lng']; // 经度
|
||||
$data['lat'] = $result['result']['location']['lat']; // 纬度
|
||||
$data['map'] = $data['lng'].','.$data['lat'];
|
||||
$this->success('请求成功', null, $data);
|
||||
}
|
||||
|
||||
$this->error('请求失败,无法继续~');
|
||||
}
|
||||
|
||||
public function get_coordinate()
|
||||
{
|
||||
$coordinate = input('param.coordinate/s');
|
||||
$keyword = input('param.keyword/s');
|
||||
$func = input('param.func/s', 'undefined');
|
||||
$lng = 0;
|
||||
$lat = 0;
|
||||
if($coordinate && strpos($coordinate,',') !== false)
|
||||
{
|
||||
$map = explode(',',$coordinate);
|
||||
$lng = $map[0];
|
||||
$lat = isset($map[1]) ? $map[1] : 0;
|
||||
}
|
||||
$this->assign('lng',$lng);
|
||||
$this->assign('lat',$lat);
|
||||
$this->assign('ak', base64_decode(config('global.baidu_map_ak')));
|
||||
$this->assign('keyword',$keyword);
|
||||
$this->assign('func',$func);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
10
src/application/admin/controller/Media.php
Normal file
10
src/application/admin/controller/Media.php
Normal file
File diff suppressed because one or more lines are too long
1902
src/application/admin/controller/Member.php
Normal file
1902
src/application/admin/controller/Member.php
Normal file
File diff suppressed because it is too large
Load Diff
392
src/application/admin/controller/Notify.php
Normal file
392
src/application/admin/controller/Notify.php
Normal file
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2021-02-22
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
|
||||
class Notify extends Base {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// 邮件通知配置
|
||||
$this->smtp_tpl_db = Db::name('smtp_tpl');
|
||||
// 短信通知配置
|
||||
$this->sms_template_db = Db::name('sms_template');
|
||||
// 站内信配置
|
||||
$this->users_notice_tpl_db = Db::name('users_notice_tpl');
|
||||
// 站内信通知记录表
|
||||
$this->users_notice_tpl_content_db = Db::name('users_notice_tpl_content');
|
||||
}
|
||||
|
||||
/**
|
||||
* 站内信模板列表
|
||||
*/
|
||||
public function notify_tpl()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
|
||||
$map = array();
|
||||
if (!empty($keywords)) {
|
||||
$map['tpl_name'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
|
||||
// 多语言
|
||||
$map['lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$count = $this->users_notice_tpl_db->where($map)->count('tpl_id');// 查询满足要求的总记录数
|
||||
$pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $this->users_notice_tpl_db->where($map)
|
||||
->order('tpl_id asc')
|
||||
->limit($pageObj->firstRow.','.$pageObj->listRows)
|
||||
->select();
|
||||
$pageStr = $pageObj->show(); // 分页显示输出
|
||||
$this->assign('list', $list); // 赋值数据集
|
||||
$this->assign('page', $pageStr); // 赋值分页输出
|
||||
$this->assign('pager', $pageObj); // 赋值分页对象
|
||||
|
||||
$shop_open = getUsersConfigData('shop.shop_open');
|
||||
$this->assign('shop_open', $shop_open);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 统计未读的站内信数量
|
||||
public function count_unread_notify()
|
||||
{
|
||||
$notice_where = [
|
||||
'is_read' => 0,
|
||||
'admin_id' => ['>', 0],
|
||||
];
|
||||
$notice_count = $this->users_notice_tpl_content_db->where($notice_where)->count('content_id');
|
||||
if (IS_AJAX_POST) {
|
||||
$this->success('查询成功', null, ['notice_count'=>$notice_count]);
|
||||
} else {
|
||||
$this->assign('notice_count', $notice_count);
|
||||
}
|
||||
}
|
||||
|
||||
// 通知首页
|
||||
/*public function index()
|
||||
{
|
||||
// 公共查询条件
|
||||
$where = [
|
||||
'lang' => $this->admin_lang
|
||||
];
|
||||
|
||||
// 查询邮件配置
|
||||
$Smtp = $this->smtp_tpl_db->field('tpl_id, is_open, tpl_name')->order('send_scene asc')->where($where)->select();
|
||||
|
||||
// 查询站内信配置
|
||||
$Notice = $this->users_notice_tpl_db->field('tpl_id, is_open, tpl_name')->order('send_scene asc')->where($where)->select();
|
||||
|
||||
// 查询短信配置
|
||||
$sms_type = tpCache('sms.sms_type') ? tpCache('sms.sms_type') : 1;
|
||||
$where['sms_type'] = $sms_type;
|
||||
$Sms = $this->sms_template_db->field('tpl_id, is_open, tpl_title')->order('send_scene asc')->where($where)->select();
|
||||
|
||||
// 拼装数据
|
||||
$NotifyList = [
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '留言表单',
|
||||
// title提示
|
||||
'title_msg' => '留言表单',
|
||||
// 短信开关
|
||||
'sms_open' => [],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[0],
|
||||
// 站内开关
|
||||
'notice_open' => $Notice[0]
|
||||
],
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '会员注册',
|
||||
// title提示
|
||||
'title_msg' => '会员注册',
|
||||
// 短信开关
|
||||
'sms_open' => $Sms[0],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[1],
|
||||
// 站内开关
|
||||
'notice_open' => []
|
||||
],
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '账户绑定',
|
||||
// title提示
|
||||
'title_msg' => '邮箱/手机绑定',
|
||||
// 短信开关
|
||||
'sms_open' => $Sms[1],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[2],
|
||||
// 站内开关
|
||||
'notice_open' => []
|
||||
],
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '找回密码',
|
||||
// title提示
|
||||
'title_msg' => '找回密码',
|
||||
// 短信开关
|
||||
'sms_open' => $Sms[2],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[3],
|
||||
// 站内开关
|
||||
'notice_open' => []
|
||||
],
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '订单付款',
|
||||
// title提示
|
||||
'title_msg' => '订单付款',
|
||||
// 短信开关
|
||||
'sms_open' => $Sms[3],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[4],
|
||||
// 站内开关
|
||||
'notice_open' => $Notice[1]
|
||||
],
|
||||
[
|
||||
// 功能名称
|
||||
'notify_title' => '订单发货',
|
||||
// title提示
|
||||
'title_msg' => '订单发货',
|
||||
// 短信开关
|
||||
'sms_open' => $Sms[4],
|
||||
// 邮件开关
|
||||
'smtp_open' => $Smtp[5],
|
||||
// 站内开关
|
||||
'notice_open' => $Notice[2]
|
||||
]
|
||||
];
|
||||
|
||||
$this->assign('NotifyList', $NotifyList);
|
||||
return $this->fetch();
|
||||
}*/
|
||||
|
||||
// 短信参数配置页面
|
||||
// public function SmsConfig()
|
||||
// {
|
||||
// if (IS_AJAX_POST) {
|
||||
// $inc_type = 'sms';
|
||||
// $param = input('post.');
|
||||
|
||||
// if (!isset($param['sms_type'])) $param['sms_type'] = 1;
|
||||
// if ($param['sms_type'] == 1) {
|
||||
// unset($param['sms_appkey_tx']);
|
||||
// unset($param['sms_appid_tx']);
|
||||
// } else {
|
||||
// unset($param['sms_appkey']);
|
||||
// unset($param['sms_secretkey']);
|
||||
// }
|
||||
|
||||
// /*多语言*/
|
||||
// if (is_language()) {
|
||||
// $langRow = \think\Db::name('language')->order('id asc')
|
||||
// ->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
// ->select();
|
||||
// foreach ($langRow as $key => $val) {
|
||||
// tpCache($inc_type, $param, $val['mark']);
|
||||
// }
|
||||
// } else {
|
||||
// tpCache($inc_type, $param);
|
||||
// }
|
||||
// /*--end*/
|
||||
|
||||
// $this->success('配置完成');
|
||||
// }
|
||||
|
||||
// // 手机短信配置
|
||||
// $sms = tpCache('sms');
|
||||
// if (!isset($sms['sms_type'])) {
|
||||
// $sms['sms_type'] = 1;
|
||||
// tpCache('sms', ['sms_type' => 1]);
|
||||
// }
|
||||
// $this->assign('sms', $sms);
|
||||
// return $this->fetch('sms_config');
|
||||
// }
|
||||
|
||||
// 邮件参数配置页面
|
||||
// public function SmtpConfig()
|
||||
// {
|
||||
// if (IS_AJAX_POST) {
|
||||
// $inc_type = 'smtp';
|
||||
// $param = input('post.');
|
||||
|
||||
// /*多语言*/
|
||||
// if (is_language()) {
|
||||
// $langRow = \think\Db::name('language')->order('id asc')
|
||||
// ->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
// ->select();
|
||||
// foreach ($langRow as $key => $val) {
|
||||
// tpCache($inc_type, $param, $val['mark']);
|
||||
// }
|
||||
// } else {
|
||||
// tpCache($inc_type, $param);
|
||||
// }
|
||||
// /*--end*/
|
||||
|
||||
// $this->success('配置完成');
|
||||
// }
|
||||
|
||||
// // 邮箱配置
|
||||
// $smtp = tpCache('smtp');
|
||||
// $this->assign('smtp', $smtp);
|
||||
// return $this->fetch('smtp_config');
|
||||
// }
|
||||
|
||||
// 配置页面
|
||||
// public function TemplateConfig()
|
||||
// {
|
||||
// if (IS_AJAX_POST) {
|
||||
// $post = input('post.');
|
||||
// if ('sms' == $post['config_type']) {
|
||||
// if (empty($post['sms_sign'])) $this->error('请填写签名名称');
|
||||
// if (empty($post['sms_tpl_code'])) $this->error(1 == $post['sms_type'] ? '请填写模板CODE' : '请填写模板ID');
|
||||
// if (empty($post['tpl_content'])) $this->error('请填写模板内容');
|
||||
// $UpData = [
|
||||
// 'tpl_id' => $post['tpl_id'],
|
||||
// 'sms_sign' => $post['sms_sign'],
|
||||
// 'sms_tpl_code' => $post['sms_tpl_code'],
|
||||
// 'tpl_content' => $post['tpl_content'],
|
||||
// 'is_open' => $post['is_open'],
|
||||
// 'update_time' => getTime()
|
||||
// ];
|
||||
// $UpdateID = $this->sms_template_db->update($UpData);
|
||||
|
||||
// } else if ('smtp' == $post['config_type']) {
|
||||
// if (empty($post['tpl_title'])) $this->error('请填写邮件标题');
|
||||
// $UpData = [
|
||||
// 'tpl_id' => $post['tpl_id'],
|
||||
// 'tpl_title' => $post['tpl_title'],
|
||||
// 'is_open' => $post['is_open'],
|
||||
// 'update_time' => getTime()
|
||||
// ];
|
||||
// $UpdateID = $this->smtp_tpl_db->update($UpData);
|
||||
|
||||
// } else if ('notice' == $post['config_type']) {
|
||||
// if (empty($post['tpl_title'])) $this->error('请填写站内信标题');
|
||||
// $UpData = [
|
||||
// 'tpl_id' => $post['tpl_id'],
|
||||
// 'tpl_title' => $post['tpl_title'],
|
||||
// 'is_open' => $post['is_open'],
|
||||
// 'update_time' => getTime()
|
||||
// ];
|
||||
// $UpdateID = $this->users_notice_tpl_db->update($UpData);
|
||||
// }
|
||||
|
||||
// if (!empty($UpdateID)) {
|
||||
// $this->success('保存成功');
|
||||
// } else {
|
||||
// $this->error('保存失败');
|
||||
// }
|
||||
// }
|
||||
|
||||
// $TemplateID = input('param.tpl_id/d');
|
||||
// $ConfigType = input('param.config_type/s');
|
||||
// if ('sms' == $ConfigType) {
|
||||
// // 短信处理逻辑
|
||||
// $this->FindSmsConfig($TemplateID, $ConfigType);
|
||||
// return $this->fetch('sms_tpl');
|
||||
|
||||
// } else if ('smtp' == $ConfigType) {
|
||||
// // 邮箱处理逻辑
|
||||
// $this->FindSmptConfig($TemplateID, $ConfigType);
|
||||
// return $this->fetch('smtp_tpl');
|
||||
|
||||
// } else if ('notice' == $ConfigType) {
|
||||
// // 站内信处理逻辑
|
||||
// $this->FindNoticeConfig($TemplateID, $ConfigType);
|
||||
// return $this->fetch('notice_tpl');
|
||||
// }
|
||||
// }
|
||||
|
||||
// 短信参数配置验证及加载页面
|
||||
// private function FindSmsConfig($TemplateID = null, $ConfigType = 'sms')
|
||||
// {
|
||||
// /*短信参数配置验证*/
|
||||
// $Sms = tpCache('sms');
|
||||
// $SmsConfigured = 404;
|
||||
// if (!empty($Sms)) {
|
||||
// if (1 == $Sms['sms_type'] && !empty($Sms['sms_appkey']) && !empty($Sms['sms_secretkey']) && !empty($Sms['sms_test_mobile'])) {
|
||||
// // 阿里云短信配置完成
|
||||
// $SmsConfigured = 200;
|
||||
// } else if (2 == $Sms['sms_type'] && !empty($Sms['sms_appkey_tx']) && !empty($Sms['sms_appid_tx']) && !empty($Sms['sms_test_mobile'])) {
|
||||
// // 腾讯云短信配置完成
|
||||
// $SmsConfigured = 200;
|
||||
// }
|
||||
// }
|
||||
// $this->assign('SmsConfigured', $SmsConfigured);
|
||||
// /* END */
|
||||
|
||||
// /*短信自定义模板配置*/
|
||||
// $where = [
|
||||
// 'tpl_id' => $TemplateID,
|
||||
// 'lang' => $this->admin_lang
|
||||
// ];
|
||||
// // 查询短信模板配置
|
||||
// $Find = $this->sms_template_db->where($where)->find();
|
||||
// $this->assign('Find', $Find);
|
||||
// /* END */
|
||||
|
||||
// // 配置类型
|
||||
// $this->assign('ConfigType', $ConfigType);
|
||||
// }
|
||||
|
||||
// 邮件参数配置验证及加载页面
|
||||
// private function FindSmptConfig($TemplateID = null, $ConfigType = 'smtp')
|
||||
// {
|
||||
// /*邮件参数配置验证*/
|
||||
// $Smtp = tpCache('smtp');
|
||||
// $SmtpConfigured = 404;
|
||||
// if (!empty($Smtp['smtp_server']) && !empty($Smtp['smtp_port']) && !empty($Smtp['smtp_user']) && !empty($Smtp['smtp_pwd']) && !empty($Smtp['smtp_from_eamil'])) {
|
||||
// $SmtpConfigured = 200;
|
||||
// }
|
||||
// $this->assign('SmtpConfigured', $SmtpConfigured);
|
||||
// /* END */
|
||||
|
||||
// /*邮箱自定义模板配置*/
|
||||
// $where = [
|
||||
// 'tpl_id' => $TemplateID,
|
||||
// 'lang' => $this->admin_lang
|
||||
// ];
|
||||
// // 查询邮箱模板配置
|
||||
// $Find = $this->smtp_tpl_db->where($where)->find();
|
||||
// $this->assign('Find', $Find);
|
||||
// /* END */
|
||||
|
||||
// // 配置类型
|
||||
// $this->assign('ConfigType', $ConfigType);
|
||||
// }
|
||||
|
||||
// 站内信参数配置验证及加载页面
|
||||
// private function FindNoticeConfig($TemplateID = null, $ConfigType = 'notice')
|
||||
// {
|
||||
// /*站内信自定义模板配置*/
|
||||
// $where = [
|
||||
// 'tpl_id' => $TemplateID,
|
||||
// 'lang' => $this->admin_lang
|
||||
// ];
|
||||
// // 查询站内信模板配置
|
||||
// $Find = $this->users_notice_tpl_db->where($where)->find();
|
||||
// $this->assign('find', $Find);
|
||||
// $this->assign('ConfigType', $ConfigType);
|
||||
// /* END */
|
||||
// }
|
||||
}
|
||||
482
src/application/admin/controller/Other.php
Normal file
482
src/application/admin/controller/Other.php
Normal file
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Other extends Base
|
||||
{
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
// 判断是否有广告位置
|
||||
if (strtolower(ACTION_NAME) != 'index') {
|
||||
$count = M('ad_position')->count('id');
|
||||
if (empty($count)) {
|
||||
$this->success('缺少广告位置,正在前往中……', url('AdPosition/add'), '', 3);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$get = input('get.');
|
||||
$pid = input('param.pid/d', 0);
|
||||
$keywords = input('keywords/s');
|
||||
$condition = array();
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'pid'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else {
|
||||
$tmp_key = 'a.'.$key;
|
||||
$condition[$tmp_key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$adM = M('ad');
|
||||
$count = $adM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $adM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
/*支持子目录*/
|
||||
foreach ($list as $key => $val) {
|
||||
$val['litpic'] = handle_subdir_pic($val['litpic']);
|
||||
$list[$key] = $val;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页对象
|
||||
|
||||
$ad_position = model('AdPosition')->getAll('*','id');
|
||||
$this->assign('ad_position',$ad_position);
|
||||
|
||||
$this->assign('pid',$pid);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
$newData = array(
|
||||
'litpic' => $litpic,
|
||||
'admin_id' => session('admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
$insertId = M('ad')->insertGetId($data);
|
||||
|
||||
if ($insertId) {
|
||||
|
||||
/*同步广告位置ID到多语言的模板变量里*/
|
||||
$this->syn_add_language_attribute($insertId);
|
||||
/*--end*/
|
||||
|
||||
\think\Cache::clear('ad');
|
||||
adminLog('新增广告:'.$post['title']);
|
||||
$this->success("操作成功", url('Other/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$pid = input('param.pid/d', 0);
|
||||
$this->assign('pid', $pid);
|
||||
|
||||
$ad_position = model('AdPosition')->getAll('*', 'id');
|
||||
$this->assign('ad_position', $ad_position);
|
||||
|
||||
$ad_media_type = config('global.ad_media_type');
|
||||
$this->assign('ad_media_type', $ad_media_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if(!empty($post['id'])){
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
$newData = array(
|
||||
'litpic' => $litpic,
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
$r = M('ad')->where([
|
||||
'id' => $post['id'],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->update($data);
|
||||
}
|
||||
if ($r) {
|
||||
adminLog('编辑广告');
|
||||
$this->success("操作成功", url('Other/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('ad')->where([
|
||||
'id' => $id,
|
||||
])->find();
|
||||
if (empty($field)) {
|
||||
$this->error('广告不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
if (is_http_url($field['litpic'])) {
|
||||
$field['is_remote'] = 1;
|
||||
$field['litpic_remote'] = handle_subdir_pic($field['litpic']);
|
||||
} else {
|
||||
$field['is_remote'] = 0;
|
||||
$field['litpic_local'] = handle_subdir_pic($field['litpic']);
|
||||
}
|
||||
|
||||
/*支持子目录*/
|
||||
$field['intro'] = handle_subdir_pic($field['intro'], 'html');
|
||||
/*--end*/
|
||||
|
||||
$assign_data['field'] = $field;
|
||||
$assign_data['ad_position'] = model('AdPosition')->getAll('*', 'id');
|
||||
|
||||
$assign_data['ad_media_type'] = config('global.ad_media_type');
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
$r = M('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
M('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
M('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ui美化新增
|
||||
*/
|
||||
public function ui_add()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
$newData = array(
|
||||
'media_type' => 1,
|
||||
'litpic' => $litpic,
|
||||
'lang' => get_current_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
$insertId = M('ad')->insertGetId($data);
|
||||
if ($insertId) {
|
||||
|
||||
/*同步广告位置ID到多语言的模板变量里*/
|
||||
$this->syn_add_language_attribute($insertId);
|
||||
/*--end*/
|
||||
|
||||
\think\Cache::clear('ad');
|
||||
adminLog('新增广告:'.$post['title']);
|
||||
$this->success('操作成功');
|
||||
} else {
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
$edit_id = input('param.edit_id/d', 0);
|
||||
$pid = input('param.pid/d', 0);
|
||||
/*多语言*/
|
||||
$new_pid = model('LanguageAttr')->getBindValue($pid, 'ad_position');
|
||||
!empty($new_pid) && $pid = $new_pid;
|
||||
/*--end*/
|
||||
$assign_data = array();
|
||||
$assign_data['ad_position'] = model('AdPosition')->getInfo($pid);
|
||||
$assign_data['edit_id'] = $edit_id;
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* ui美化编辑
|
||||
*/
|
||||
public function ui_edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if(!empty($post['id'])){
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
$newData = array(
|
||||
'litpic' => $litpic,
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
$r = M('ad')->where([
|
||||
'id' => $post['id'],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->update($data);
|
||||
if ($r) {
|
||||
adminLog('编辑广告:'.$post['title']);
|
||||
$this->success('操作成功');
|
||||
}
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('ad')->where([
|
||||
'id' => $id,
|
||||
])->find();
|
||||
if (empty($field)) {
|
||||
$this->error('广告不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
if (is_http_url($field['litpic'])) {
|
||||
$field['is_remote'] = 1;
|
||||
$field['litpic_remote'] = $field['litpic'];
|
||||
} else {
|
||||
$field['is_remote'] = 0;
|
||||
$field['litpic_local'] = $field['litpic'];
|
||||
}
|
||||
$assign_data['field'] = $field;
|
||||
$assign_data['ad_position'] = model('AdPosition')->getInfo($field['pid']);
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function ui_del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = M('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
M('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
M('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步新增广告ID到多语言的模板变量里
|
||||
*/
|
||||
private function syn_add_language_attribute($ad_id)
|
||||
{
|
||||
/*单语言情况下不执行多语言代码*/
|
||||
if (!is_language()) {
|
||||
return true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$attr_group = 'ad';
|
||||
$admin_lang = $this->admin_lang;
|
||||
$main_lang = get_main_lang();
|
||||
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
|
||||
$ad_db = Db::name('ad');
|
||||
$result = $ad_db->find($ad_id);
|
||||
$attr_name = 'ad'.$ad_id;
|
||||
$r = Db::name('language_attribute')->save([
|
||||
'attr_title' => $result['title'],
|
||||
'attr_name' => $attr_name,
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if (false !== $r) {
|
||||
$data = [];
|
||||
foreach ($languageRow as $key => $val) {
|
||||
/*同步新广告到其他语言广告列表*/
|
||||
if ($val['mark'] != $admin_lang) {
|
||||
$addsaveData = $result;
|
||||
$addsaveData['lang'] = $val['mark'];
|
||||
$newPid = Db::name('language_attr')->where([
|
||||
'attr_name' => 'adp'.$result['pid'],
|
||||
'attr_group' => 'ad_position',
|
||||
'lang' => $val['mark'],
|
||||
])->getField('attr_value');
|
||||
$addsaveData['pid'] = $newPid;
|
||||
unset($addsaveData['id']);
|
||||
$ad_id = $ad_db->insertGetId($addsaveData);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*所有语言绑定在主语言的ID容器里*/
|
||||
$data[] = [
|
||||
'attr_name' => $attr_name,
|
||||
'attr_value' => $ad_id,
|
||||
'lang' => $val['mark'],
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
/*--end*/
|
||||
}
|
||||
if (!empty($data)) {
|
||||
model('LanguageAttr')->saveAll($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
218
src/application/admin/controller/PayApi.php
Normal file
218
src/application/admin/controller/PayApi.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2020-05-22
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class PayApi extends Base {
|
||||
|
||||
private $UsersConfigData = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
$this->pay_api_config_db = Db::name('pay_api_config');
|
||||
|
||||
// 会员中心配置信息
|
||||
$this->UsersConfigData = getUsersConfigData('all');
|
||||
$this->assign('userConfig', $this->UsersConfigData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付接口首页
|
||||
*/
|
||||
public function pay_api_index()
|
||||
{
|
||||
$list = $this->pay_api_config_db->where('status', 1)->order('pay_id asc')->select();
|
||||
foreach ($list as $key => $val) {
|
||||
if (1 == $val['system_built']) {
|
||||
$val['litpic'] = $this->root_dir . "/public/static/admin/images/{$val['pay_mark']}.png";
|
||||
} else {
|
||||
$val['litpic'] = $this->root_dir . "/weapp/{$val['pay_mark']}/logo.png";
|
||||
}
|
||||
$list[$key] = $val;
|
||||
}
|
||||
$this->assign('list', $list);
|
||||
return $this->fetch('pay_api_index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开支付接口配置
|
||||
*/
|
||||
public function open_pay_api_config()
|
||||
{
|
||||
$pay_id = input('get.pay_id') ? input('get.pay_id') : 0;
|
||||
$Config = $this->pay_api_config_db->where('pay_id', $pay_id)->find();
|
||||
|
||||
if (!empty($Config) && 1 == $Config['pay_id'] && 'wechat' == $Config['pay_mark']) {
|
||||
// 系统内置的微信支付
|
||||
$TemplateHtml = $this->WeChatPayTemplate($Config);
|
||||
} else if (!empty($Config) && 2 == $Config['pay_id'] && 'alipay' == $Config['pay_mark']) {
|
||||
// 系统内置的支付宝支付
|
||||
$TemplateHtml = $this->AliPayPayTemplate($Config);
|
||||
} else if (!empty($Config) && !empty($Config['pay_mark']) && 0 == $Config['system_built']) {
|
||||
// 第三方插件
|
||||
$ControllerName = "\weapp\\" . $Config['pay_mark']."\controller\\" . $Config['pay_mark'];
|
||||
$UnifyController = new $ControllerName;
|
||||
$TemplateHtml = $UnifyController->UnifyAction($Config);
|
||||
}
|
||||
|
||||
return $this->display($TemplateHtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存支付接口配置
|
||||
*/
|
||||
public function save_pay_api_config()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
$pay_id = !empty($post['pay_id']) ? $post['pay_id'] : 0;
|
||||
$Config = $this->pay_api_config_db->where('pay_id', $pay_id)->find();
|
||||
if (empty($Config)) $this->error('数据有误,请刷新重试');
|
||||
|
||||
if (1 == $Config['pay_id'] && 'wechat' == $Config['pay_mark']) {
|
||||
// 系统内置的微信支付
|
||||
$this->WeChatPayConfig($post);
|
||||
} else if (2 == $Config['pay_id'] && 'alipay' == $Config['pay_mark']) {
|
||||
// 系统内置的支付宝支付
|
||||
$this->AliPayPayConfig($post);
|
||||
} else if (!empty($Config) && !empty($Config['pay_mark']) && 0 == $Config['system_built']) {
|
||||
// 第三方插件
|
||||
$ControllerName = "\weapp\\" . $Config['pay_mark']."\controller\\" . $Config['pay_mark'];
|
||||
$UnifyController = new $ControllerName;
|
||||
$TemplateHtml = $UnifyController->UnifySaveConfigAction($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 微信逻辑 */
|
||||
public function WeChatPayTemplate($Config = [])
|
||||
{
|
||||
$pay_info = !empty($Config['pay_info']) ? unserialize($Config['pay_info']) : [];
|
||||
$Config['pay_terminal'] = !empty($Config['pay_terminal']) ? unserialize($Config['pay_terminal']) : [];
|
||||
$this->assign('Config', $Config);
|
||||
$this->assign('pay_info', $pay_info);
|
||||
return $this->fetch('wechat_template');
|
||||
}
|
||||
|
||||
// 保存微信配置
|
||||
public function WeChatPayConfig($post = [])
|
||||
{
|
||||
if (empty($post['pay_info']['is_open_wechat'])) {
|
||||
// 配置信息不允许为空
|
||||
if (empty($post['pay_info']['appid'])) $this->error('请填写微信AppId');
|
||||
if (empty($post['pay_info']['mchid'])) $this->error('请填写微信商户号');
|
||||
if (empty($post['pay_info']['key'])) $this->error('请填写微信KEY值');
|
||||
|
||||
// 验证微信配置是否正确,不正确则返回提示
|
||||
$Result = model('PayApi')->VerifyWeChatConfig($post['pay_info']);
|
||||
if ($Result['return_code'] == 'FAIL') $this->error($Result['return_msg']);
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
$SynData['pay_info'] = serialize($post['pay_info']);
|
||||
// $SynData['pay_terminal'] = serialize($post['pay_terminal']);
|
||||
$SynData['update_time'] = getTime();
|
||||
|
||||
// 保存条件
|
||||
$where = [
|
||||
'pay_id' => $post['pay_id'],
|
||||
'pay_mark' => 'wechat',
|
||||
'system_built' => 1
|
||||
];
|
||||
$ResultID = $this->pay_api_config_db->where($where)->update($SynData);
|
||||
|
||||
// 返回结果
|
||||
if (!empty($ResultID)) {
|
||||
$this->success('保存成功');
|
||||
} else {
|
||||
$this->error('数据错误');
|
||||
}
|
||||
}
|
||||
/* END */
|
||||
|
||||
/* 支付宝逻辑 */
|
||||
public function AliPayPayTemplate($Config = [])
|
||||
{
|
||||
$pay_info = !empty($Config['pay_info']) ? unserialize($Config['pay_info']) : [];
|
||||
$Config['pay_terminal'] = !empty($Config['pay_terminal']) ? unserialize($Config['pay_terminal']) : [];
|
||||
$this->assign('Config', $Config);
|
||||
$this->assign('pay_info', $pay_info);
|
||||
// PHP5.5.0或更高版本,可使用新版支付方式,兼容旧版支付方式
|
||||
$php_version = 0;
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||
// PHP5.4.0或更低版本,可使用旧版支付方式
|
||||
$php_version = 1;
|
||||
}
|
||||
$this->assign('php_version', $php_version);
|
||||
return $this->fetch('alipay_template');
|
||||
}
|
||||
|
||||
// 保存支付宝支付配置
|
||||
public function AliPayPayConfig($post = [])
|
||||
{
|
||||
$php_version = $post['pay_info']['version'];
|
||||
if (0 == $php_version) {
|
||||
if (empty($post['pay_info']['is_open_alipay'])) {
|
||||
// 配置信息不允许为空
|
||||
if (empty($post['pay_info']['app_id'])) $this->error('请填写支付宝APPID');
|
||||
if (empty($post['pay_info']['alipay_public_key'])) $this->error('请填写支付宝公钥');
|
||||
if (empty($post['pay_info']['merchant_private_key'])) $this->error('请填写商户私钥');
|
||||
|
||||
// 验证支付宝配置是否正确,不正确则返回提示
|
||||
$Result = model('PayApi')->VerifyAliPayConfig($post['pay_info']);
|
||||
if ('ok' != $Result) $this->error($Result);
|
||||
}
|
||||
|
||||
// 处理数据中的空格和换行
|
||||
$post['pay_info']['app_id'] = preg_replace('/\r|\n/', '', $post['pay_info']['app_id']);
|
||||
$post['pay_info']['alipay_public_key'] = preg_replace('/\r|\n/', '', $post['pay_info']['alipay_public_key']);
|
||||
$post['pay_info']['merchant_private_key'] = preg_replace('/\r|\n/', '', $post['pay_info']['merchant_private_key']);
|
||||
|
||||
} else if (1 == $php_version) {
|
||||
if (empty($post['pay_info']['is_open_alipay'])) {
|
||||
// 配置信息不允许为空
|
||||
if (empty($post['pay_info']['id'])) $this->error('请填写合作者身份ID');
|
||||
if (empty($post['pay_info']['code'])) $this->error('请填写安全校验码');
|
||||
if (empty($post['pay_info']['account'])) $this->error('请填写支付宝账号');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
$SynData['pay_info'] = serialize($post['pay_info']);
|
||||
// $SynData['pay_terminal'] = serialize($post['pay_terminal']);
|
||||
$SynData['update_time'] = getTime();
|
||||
$where = [
|
||||
'pay_id' => $post['pay_id'],
|
||||
'pay_mark' => 'alipay',
|
||||
'system_built' => 1
|
||||
];
|
||||
$ResultID = $this->pay_api_config_db->where($where)->update($SynData);
|
||||
|
||||
// 返回结果
|
||||
if (!empty($ResultID)) {
|
||||
$this->success('保存成功');
|
||||
} else {
|
||||
$this->error('数据错误');
|
||||
}
|
||||
}
|
||||
/* END */
|
||||
}
|
||||
279
src/application/admin/controller/Platform.php
Normal file
279
src/application/admin/controller/Platform.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Platform extends Base
|
||||
{
|
||||
private $ad_position_system_id = array(); // 系统默认位置ID,不可删除
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$get = input('get.');
|
||||
$keywords = input('keywords/s');
|
||||
$condition = [];
|
||||
// 应用搜索条件
|
||||
foreach (['keywords', 'type'] as $key) {
|
||||
if (isset($get[$key]) && $get[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$get[$key]}%");
|
||||
} else {
|
||||
$tmp_key = 'a.'.$key;
|
||||
$condition[$tmp_key] = array('eq', $get[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多语言
|
||||
// $condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$adPositionM = M('platform');
|
||||
$count = $adPositionM->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $adPositionM->alias('a')->where($condition)->order('sort desc')->limit($Page->firstRow.','.$Page->listRows)->getAllWithIndex('id');
|
||||
|
||||
// 每组获取三张图片
|
||||
$pids = get_arr_column($list, 'id');
|
||||
$ad = M('ad')->where(['pid' => ['IN', $pids], 'lang' => $this->admin_lang])->order('pid asc, id asc')->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); // 支持子目录
|
||||
$list[$k] = $v;
|
||||
}
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页对象
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
// 添加广告位置表信息
|
||||
$data = array(
|
||||
'title' => trim($post['title']),
|
||||
'desc' => $post['intro'],
|
||||
'link' => $post['link'],
|
||||
'sort' => $post['sort'],
|
||||
'logo'=>$post['img_litpic'][0],
|
||||
// 'intro' => $post['intro'],
|
||||
'admin_id' => session('admin_id'),
|
||||
// 'lang' => $this->admin_lang,
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$insertID = M('platform')->insertGetId($data);
|
||||
if (!empty($insertID)) {
|
||||
adminLog('新增平台:'.$post['title']);
|
||||
$this->success("操作成功", url('platform/index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('platform/index'));
|
||||
}
|
||||
}
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$upload_max_filesize = upload_max_filesize();
|
||||
$this->assign('upload_max_filesize', $upload_max_filesize);
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$this->assign('media_type', $media_type);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if (!empty($post['id'])) {
|
||||
// if (array_key_exists($post['id'], $this->ad_position_system_id)) {
|
||||
// $this->error("不可更改系统预定义位置", url('Platform/edit',array('id'=>$post['id'])));
|
||||
// }
|
||||
|
||||
$data = array(
|
||||
'id' => $post['id'],
|
||||
'desc' => $post['intro'],
|
||||
'link' => $post['link'],
|
||||
'logo'=>$post['img_litpic'][0],
|
||||
'sort' => $post['sort'],
|
||||
'createtime' => getTime(),
|
||||
);
|
||||
$resultID = Db::name('platform')->update($data);
|
||||
/* END */
|
||||
}
|
||||
|
||||
if (!empty($resultID)) {
|
||||
adminLog('编辑广告:'.$post['title']);
|
||||
$this->success("操作成功", url('Platform/index'));
|
||||
} else {
|
||||
$this->error("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$field = M('platform')->field('a.*')->alias('a')->where(array('a.id'=>$id))->find();
|
||||
if (empty($field)) $this->error('广告不存在,请联系管理员!');
|
||||
$assign_data['field'] = $field;
|
||||
/*
|
||||
// 广告
|
||||
$ad_data = Db::name('ad')->where(array('pid'=>$field['id']))->order('sort_order asc')->select();
|
||||
foreach ($ad_data as $key => $val) {
|
||||
if (1 == $val['type']) {
|
||||
$ad_data[$key]['litpic'] = get_default_pic($val['litpic']); // 支持子目录
|
||||
}
|
||||
}
|
||||
$assign_data['ad_data'] = $ad_data;
|
||||
|
||||
// 上传通道
|
||||
$WeappConfig = Db::name('weapp')->field('code, status')->where('code', 'IN', ['Qiniuyun', 'AliyunOss', 'Cos'])->select();
|
||||
$WeappOpen = [];
|
||||
foreach ($WeappConfig as $value) {
|
||||
if ('Qiniuyun' == $value['code']) {
|
||||
$WeappOpen['qny_open'] = $value['status'];
|
||||
} else if ('AliyunOss' == $value['code']) {
|
||||
$WeappOpen['oss_open'] = $value['status'];
|
||||
} else if ('Cos' == $value['code']) {
|
||||
$WeappOpen['cos_open'] = $value['status'];
|
||||
}
|
||||
}
|
||||
$this->assign('WeappOpen', $WeappOpen);
|
||||
|
||||
// 系统最大上传视频的大小
|
||||
$file_size = tpCache('basic.file_size');
|
||||
$postsize = @ini_get('file_uploads') ? ini_get('post_max_size') : -1;
|
||||
$fileupload = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : -1;
|
||||
$min_size = strval($file_size) < strval($postsize) ? $file_size : $postsize;
|
||||
$min_size = strval($min_size) < strval($fileupload) ? $min_size : $fileupload;
|
||||
$upload_max_filesize = intval($min_size) * 1024 * 1024;
|
||||
$assign_data['upload_max_filesize'] = $upload_max_filesize;
|
||||
|
||||
// 视频类型
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? $media_type : config('global.media_ext');
|
||||
$media_type = str_replace(",", "|", $media_type);
|
||||
$assign_data['media_type'] = $media_type;*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告图片
|
||||
*/
|
||||
public function del_imgupload()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
/*多语言*/
|
||||
$attr_name_arr = [];
|
||||
foreach ($id_arr as $key => $val) {
|
||||
$attr_name_arr[] = 'ad'.$val;
|
||||
}
|
||||
|
||||
if (is_language()) {
|
||||
$new_id_arr = Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->column('attr_value');
|
||||
!empty($new_id_arr) && $id_arr = $new_id_arr;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$r = Db::name('ad')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
])
|
||||
->cache(true,null,'ad')
|
||||
->delete();
|
||||
if ($r) {
|
||||
/*多语言*/
|
||||
if (!empty($attr_name_arr)) {
|
||||
Db::name('language_attr')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
|
||||
Db::name('language_attribute')->where([
|
||||
'attr_name' => ['IN', $attr_name_arr],
|
||||
'attr_group' => 'ad',
|
||||
])->delete();
|
||||
}
|
||||
/*--end*/
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
$r = M('platform')->where('id','IN',$id_arr)->delete();
|
||||
if ($r) {
|
||||
adminLog('删除广告-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1259
src/application/admin/controller/Product.php
Normal file
1259
src/application/admin/controller/Product.php
Normal file
File diff suppressed because it is too large
Load Diff
396
src/application/admin/controller/Project.php
Normal file
396
src/application/admin/controller/Project.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-2-12
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
use app\admin\logic\MemberLogic;
|
||||
|
||||
class Project extends Base {
|
||||
|
||||
public $userConfig = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
/*会员中心数据表*/
|
||||
$this->project_db = Db::name('project'); //
|
||||
$this->service_db = Db::name('service'); //
|
||||
|
||||
// 是否开启支付功能设置
|
||||
$this->userConfig = getUsersConfigData('all');
|
||||
$this->assign('userConfig',$this->userConfig);
|
||||
|
||||
// 模型是否开启
|
||||
$channeltype_row = \think\Cache::get('extra_global_channeltype');
|
||||
$this->assign('channeltype_row',$channeltype_row);
|
||||
}
|
||||
|
||||
|
||||
// 会员列表
|
||||
public function users_index()
|
||||
{
|
||||
$list = array();
|
||||
|
||||
$param = input('param.');
|
||||
$condition = array();
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','origin_type'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.enterprise|a.name'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $condition['a.is_del'] = 0;
|
||||
// 多语言
|
||||
//$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
/**
|
||||
* 数据查询
|
||||
*/
|
||||
$count = $this->project_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $this->project_db->field('a.*')
|
||||
->alias('a')
|
||||
// ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.id desc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页集
|
||||
|
||||
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
//新增项目
|
||||
public function add()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
$id = input('id',0);
|
||||
if($id){
|
||||
$item = $this->project_db->where([
|
||||
'id' => $id
|
||||
])->find();
|
||||
$this->assign('item',$item);
|
||||
}
|
||||
$this->assign('id',$id);
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
// 添加表信息
|
||||
$data = array(
|
||||
'name' => $post['name'],
|
||||
'pwd' => $post['pwd'],
|
||||
'enterprise' => $post['enterprise'],
|
||||
'filing' => $post['filing'],
|
||||
'sid' =>$post['sid'],
|
||||
'limitationdate' => $post['limitationdate'],
|
||||
);
|
||||
if($id >0){
|
||||
$this->project_db->where(array('id'=>$id))->update($data);
|
||||
$insertID = $id;
|
||||
}else{
|
||||
$data['createtime'] = getTime();
|
||||
$insertID = M('project')->insertGetId($data);
|
||||
}
|
||||
$data['id'] = $insertID;
|
||||
$datas['qrcode'] = $this->book($data);
|
||||
$this->project_db->where(array('id'=>$insertID))->update($datas);
|
||||
|
||||
if (!empty($insertID)) {
|
||||
// adminLog('新增项目:'.$post['name']);
|
||||
$this->success("操作成功", url('Project/users_index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('Project/users_index'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
//新增服务商
|
||||
public function edit()
|
||||
{
|
||||
//防止php超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
$id = input('id',0);
|
||||
if($id){
|
||||
$item = $this->service_db->where([
|
||||
'id' => $id
|
||||
])->find();
|
||||
$this->assign('item',$item);
|
||||
}
|
||||
$this->assign('id',$id);
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
// 添加表信息
|
||||
$data = array(
|
||||
'name' => $post['name'],
|
||||
'centre' => $post['centre']
|
||||
);
|
||||
|
||||
if($id >0){
|
||||
$this->service_db->where(array('id'=>$id))->update($data);
|
||||
$insertID = $id;
|
||||
}else{
|
||||
$data['createtime'] = getTime();
|
||||
$insertID = M('service')->insertGetId($data);
|
||||
}
|
||||
$data['id'] = $insertID;
|
||||
$datas['qrcode'] = $this->service($data);
|
||||
$this->service_db->where(array('id'=>$insertID))->update($datas);
|
||||
if (!empty($insertID)) {
|
||||
// adminLog('新增项目:'.$post['name']);
|
||||
$this->success("操作成功", url('Project/users_index'));
|
||||
} else {
|
||||
$this->error("操作失败", url('Project/users_index'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
// 项目删除
|
||||
public function users_del()
|
||||
{
|
||||
$users_id = input('del_id/a');
|
||||
$users_id = eyIntval($users_id);
|
||||
if (IS_AJAX_POST && !empty($users_id)) {
|
||||
// 删除统一条件
|
||||
$Where = [
|
||||
'id' => ['IN', $users_id],
|
||||
];
|
||||
|
||||
$result = $this->project_db->field('name')->where($Where)->select();
|
||||
$username_list = get_arr_column($result, 'name');
|
||||
|
||||
$return = $this->project_db->where($Where)->delete();
|
||||
if (false !== $return) {
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
$this->error('参数有误');
|
||||
}
|
||||
|
||||
// 级别列表
|
||||
public function level_index()
|
||||
{
|
||||
|
||||
$list = array();
|
||||
|
||||
$param = input('param.');
|
||||
$condition = array();
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','origin_type'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.name|a.centre'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// $condition['a.is_del'] = 0;
|
||||
// 多语言
|
||||
//$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
/**
|
||||
* 数据查询
|
||||
*/
|
||||
$count = $this->service_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $this->service_db->field('a.*')
|
||||
->alias('a')
|
||||
// ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
|
||||
->where($condition)
|
||||
->order('a.id desc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$Page);// 赋值分页集
|
||||
|
||||
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 服务商删除
|
||||
public function del()
|
||||
{
|
||||
$users_id = input('del_id/a');
|
||||
$users_id = eyIntval($users_id);
|
||||
if (IS_AJAX_POST && !empty($users_id)) {
|
||||
// 删除统一条件
|
||||
$Where = [
|
||||
'id' => ['IN', $users_id],
|
||||
];
|
||||
|
||||
$result = $this->service_db->field('name')->where($Where)->select();
|
||||
$username_list = get_arr_column($result, 'name');
|
||||
|
||||
$return = $this->service_db->where($Where)->delete();
|
||||
if (false !== $return) {
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
$this->error('参数有误');
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目
|
||||
* @return string
|
||||
*/
|
||||
public function book($data)
|
||||
{
|
||||
// $data = array(
|
||||
// 'title'=>'防爆电器',
|
||||
// 'enterprise'=>'新黎明科技股份有限公司',
|
||||
// 'filing'=>'G-20230525',
|
||||
// 'sid'=>'91320500582331116Y',
|
||||
// 'limitationdate'=>'2023-05-25',
|
||||
// );
|
||||
$path = "uploads/imgs/";
|
||||
// file_put_contents(__DIR__ . '/debug.txt', var_export($data,true));
|
||||
$file = $data['id'].'.jpg';
|
||||
$font = "uploads/msyh.ttf";
|
||||
$target = imagecreatetruecolor(1657, 1105);
|
||||
$bc = imagecolorallocate($target, 0, 0, 0);
|
||||
$cc = imagecolorallocate($target, 255, 51, 0);
|
||||
$wc = imagecolorallocate($target, 255, 255, 255);
|
||||
$yc = imagecolorallocate($target, 255, 255, 0);
|
||||
//背景
|
||||
$bg = imagecreatefromjpeg("uploads/imgs/b.jpg");
|
||||
imagecopy($target, $bg, 0, 0, 0, 0, 1657, 1105);
|
||||
imagedestroy($bg);
|
||||
|
||||
//名称
|
||||
imagettftext($target, 23, 0, 600, 589, $bc, $font, $data['name']);
|
||||
//个人/企业
|
||||
imagettftext($target, 23, 0, 600, 652, $bc, $font, $data['enterprise']);
|
||||
//备案号
|
||||
imagettftext($target, 23, 0, 600, 718, $bc, $font, $data['filing']);
|
||||
//证件号码
|
||||
imagettftext($target, 23, 0, 600, 786, $bc, $font, $data['sid']);
|
||||
//有效期
|
||||
imagettftext($target, 23, 0, 600, 850, $bc, $font, $data['limitationdate']);
|
||||
imagejpeg($target, $path . $file);
|
||||
imagedestroy($target);
|
||||
// echo '<img src="../../uploads/imgs/'.$data['id'].'.jpg">';
|
||||
return '/uploads/imgs/'.$data['id'].'.jpg';
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务商
|
||||
* @return string
|
||||
*/
|
||||
public function service($data)
|
||||
{
|
||||
|
||||
// $id = 1;
|
||||
/* $data = array(
|
||||
'name'=>'上 海 聚 上 网 络 科 技 有 限 公 司',
|
||||
'centre'=>'华 东 服 务 中 心',
|
||||
);*/
|
||||
$path = "uploads/imgs/";
|
||||
$me =array();
|
||||
$file = $data['id'].'.jpg';
|
||||
$font = "uploads/msyh.ttf";
|
||||
$target = imagecreatetruecolor(800, 1111);
|
||||
$bc = imagecolorallocate($target, 0, 0, 0);
|
||||
$cc = imagecolorallocate($target, 255, 51, 0);
|
||||
// $wc = imagecolorallocate($target, 255, 255, 255);
|
||||
// $yc = imagecolorallocate($target, 255, 255, 0);
|
||||
//背景
|
||||
$bg = imagecreatefromjpeg("uploads/imgs/a.jpg");
|
||||
|
||||
imagecopy($target, $bg, 0, 0, 0, 0, 800, 1111);
|
||||
imagedestroy($bg);
|
||||
|
||||
imagettftext($target, 23, 0, 160, 625, $bc, $font, $data['name']);
|
||||
imagettftext($target, 21, 0, 300, 690, $cc, $font, $data['centre']);
|
||||
imagejpeg($target, $path . $file);
|
||||
imagedestroy($target);
|
||||
// echo '<img src="../../uploads/imgs/'.$id.'.jpg">';
|
||||
return '/uploads/imgs/'.$data['id'].'.jpg';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试
|
||||
* @return string
|
||||
*/
|
||||
public function createShopImage()
|
||||
{
|
||||
$data = array(
|
||||
'title'=>'防爆电器',
|
||||
'enterprise'=>'新黎明科技股份有限公司',
|
||||
'filing'=>'G-20230525',
|
||||
'sid'=>'91320500582331116Y',
|
||||
'limitationdate'=>'2023-05-25',
|
||||
);
|
||||
$id = 1;
|
||||
$path = "uploads/imgs/";
|
||||
$mid = 1;
|
||||
$me =array();
|
||||
$file = $id.'.jpg';
|
||||
$font = "uploads/msyh.ttf";
|
||||
$target = imagecreatetruecolor(1657, 1105);
|
||||
$bc = imagecolorallocate($target, 0, 0, 0);
|
||||
$cc = imagecolorallocate($target, 255, 51, 0);
|
||||
$wc = imagecolorallocate($target, 255, 255, 255);
|
||||
$yc = imagecolorallocate($target, 255, 255, 0);
|
||||
//背景
|
||||
$bg = imagecreatefromjpeg("uploads/imgs/b.jpg");
|
||||
imagecopy($target, $bg, 0, 0, 0, 0, 1657, 1105);
|
||||
imagedestroy($bg);
|
||||
|
||||
//名称
|
||||
imagettftext($target, 23, 0, 600, 589, $bc, $font, $data['title']);
|
||||
//个人/企业
|
||||
imagettftext($target, 23, 0, 600, 652, $bc, $font, $data['enterprise']);
|
||||
//备案号
|
||||
imagettftext($target, 23, 0, 600, 718, $bc, $font, $data['filing']);
|
||||
//证件号码
|
||||
imagettftext($target, 23, 0, 600, 786, $bc, $font, $data['sid']);
|
||||
//有效期
|
||||
imagettftext($target, 23, 0, 600, 850, $bc, $font, $data['limitationdate']);
|
||||
imagejpeg($target, $path . $file);
|
||||
imagedestroy($target);
|
||||
echo '<img src="../../uploads/imgs/'.$id.'.jpg">';
|
||||
}
|
||||
}
|
||||
535
src/application/admin/controller/Recruit.php
Normal file
535
src/application/admin/controller/Recruit.php
Normal file
@@ -0,0 +1,535 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-7
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
|
||||
class Recruit extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'recruit';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
// 模型附加表
|
||||
public $table = 'Recruit';
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->archives_db = Db::name('archives');
|
||||
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = $this->archives_db->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $this->archives_db
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order('a.aid desc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = $this->archives_db
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
/* 生成静态页面代码 */
|
||||
$aid = input('param.aid/d',0);
|
||||
$this->assign('aid',$aid);
|
||||
$tid = input('param.tid/d',0);
|
||||
$this->assign('typeid',$tid);
|
||||
/* end */
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
|
||||
$contentField = Db::name('channelfield')->where([
|
||||
'channel_id' => $this->channeltype,
|
||||
'dtype' => 'htmltext',
|
||||
])->getField('name');
|
||||
$content = input('post.addonFieldExt.'.$contentField, '', null);
|
||||
/*--end*/
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = $this->archives_db->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model($this->table)->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增数据:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
$addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
$channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
'typeid' => ['IN', [0,$typeid]],
|
||||
])->column('field_id');
|
||||
if (!empty($channelfieldBindRow)) {
|
||||
foreach ($addonFieldExtList as $key => $val) {
|
||||
if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
unset($addonFieldExtList[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
$assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*获取可显示的系统字段*/
|
||||
$condition['ifcontrol'] = 0;
|
||||
$condition['channel_id'] = $this->channeltype;
|
||||
$channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
|
||||
$assign_data['channelfield_row'] = $channelfield_row;
|
||||
/*--end*/
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
|
||||
/*获取第一个html类型的内容,作为文档的内容来截取SEO描述*/
|
||||
$contentField = Db::name('channelfield')->where([
|
||||
'channel_id' => $this->channeltype,
|
||||
'dtype' => 'htmltext',
|
||||
])->getField('name');
|
||||
$content = input('post.addonFieldExt.'.$contentField, '', null);
|
||||
/*--end*/
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = M('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model($this->table)->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑文章:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model($this->table)->getInfo($id, null, false);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
$addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
$channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
'typeid' => ['IN', [0,$typeid]],
|
||||
])->column('field_id');
|
||||
if (!empty($channelfieldBindRow)) {
|
||||
foreach ($addonFieldExtList as $key => $val) {
|
||||
if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
unset($addonFieldExtList[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
$assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
/*获取可显示的系统字段*/
|
||||
$condition['ifcontrol'] = 0;
|
||||
$condition['channel_id'] = $this->channeltype;
|
||||
$channelfield_row = Db::name('channelfield')->where($condition)->field('name,ifeditable')->getAllWithIndex('name');
|
||||
$assign_data['channelfield_row'] = $channelfield_row;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
1184
src/application/admin/controller/RecycleBin.php
Normal file
1184
src/application/admin/controller/RecycleBin.php
Normal file
File diff suppressed because it is too large
Load Diff
33
src/application/admin/controller/Region.php
Normal file
33
src/application/admin/controller/Region.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
|
||||
class Region extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取子类列表
|
||||
*/
|
||||
/*public function ajax_get_region($pid = 0, $text = ''){
|
||||
$data = model('Region')->getList($pid);
|
||||
$html = "<option value=''>--".urldecode($text)."--</option>";
|
||||
foreach($data as $key=>$val){
|
||||
$html.="<option value='".$val['id']."'>".$val['name']."</option>";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}*/
|
||||
}
|
||||
2051
src/application/admin/controller/Rlatform.php
Normal file
2051
src/application/admin/controller/Rlatform.php
Normal file
File diff suppressed because it is too large
Load Diff
470
src/application/admin/controller/Seo.php
Normal file
470
src/application/admin/controller/Seo.php
Normal file
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use app\common\logic\ArctypeLogic;
|
||||
use think\paginator\driver; // 生成静态页面代码
|
||||
class Seo extends Base
|
||||
{
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成总站
|
||||
*/
|
||||
public function site(){
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成栏目页
|
||||
*/
|
||||
public function channel(){
|
||||
$typeid = input('param.typeid/d','0'); // 栏目ID
|
||||
$this->assign("typeid",$typeid);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成文档页
|
||||
*/
|
||||
public function article()
|
||||
{
|
||||
$typeid = input('param.typeid/d','0'); // 栏目ID
|
||||
$this->assign("typeid",$typeid);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* URL配置
|
||||
*/
|
||||
public function seo()
|
||||
{
|
||||
/* 纠正栏目的HTML目录路径字段值 */
|
||||
$this->correctArctypeDirpath();
|
||||
/* end */
|
||||
|
||||
$inc_type = 'seo';
|
||||
$config = tpCache($inc_type);
|
||||
$config['seo_pseudo'] = tpCache('seo.seo_pseudo');
|
||||
$seo_pseudo_list = get_seo_pseudo_list();
|
||||
$this->assign('seo_pseudo_list', $seo_pseudo_list);
|
||||
|
||||
/* 生成静态页面代码 - 多语言统一设置URL模式 */
|
||||
$seo_pseudo_lang = '';
|
||||
$web_language_switch = tpCache('web.web_language_switch');
|
||||
if (is_language() && !empty($web_language_switch)) {
|
||||
$markArr = Db::name('language')->field('mark')->order('id asc')->limit('1,1')->select();
|
||||
if (!empty($markArr[0]['mark'])) {
|
||||
$seo_pseudo_lang = tpCache('seo.seo_pseudo', [], $markArr[0]['mark']);
|
||||
}
|
||||
$seo_pseudo_lang = !empty($seo_pseudo_lang) ? $seo_pseudo_lang : 1;
|
||||
}
|
||||
$this->assign('seo_pseudo_lang', $seo_pseudo_lang);
|
||||
/* end */
|
||||
|
||||
/* 限制文档HTML保存路径的名称 */
|
||||
$wwwroot_dir = config('global.wwwroot_dir'); // 网站根目录的目录列表
|
||||
$disable_dirname = config('global.disable_dirname'); // 栏目伪静态时的路由路径
|
||||
$wwwroot_dir = array_merge($wwwroot_dir, $disable_dirname);
|
||||
// 不能与栏目的一级目录名称重复
|
||||
$arctypeDirnames = Db::name('arctype')->where(['parent_id'=>0])->column('dirname');
|
||||
is_array($arctypeDirnames) && $wwwroot_dir = array_merge($wwwroot_dir, $arctypeDirnames);
|
||||
// 不能与多语言的标识重复
|
||||
$markArr = Db::name('language_mark')->column('mark');
|
||||
is_array($markArr) && $wwwroot_dir = array_merge($wwwroot_dir, $markArr);
|
||||
$wwwroot_dir = array_unique($wwwroot_dir);
|
||||
$this->assign('seo_html_arcdir_limit', implode(',', $wwwroot_dir));
|
||||
/* end */
|
||||
|
||||
$seo_html_arcdir_1 = '';
|
||||
if (!empty($config['seo_html_arcdir'])) {
|
||||
$config['seo_html_arcdir'] = trim($config['seo_html_arcdir'], '/');
|
||||
$seo_html_arcdir_1 = '/'.$config['seo_html_arcdir'];
|
||||
}
|
||||
$this->assign('seo_html_arcdir_1', $seo_html_arcdir_1);
|
||||
|
||||
// 栏目列表
|
||||
$map = array(
|
||||
'status' => 1,
|
||||
'is_del' => 0, // 回收站功能
|
||||
'current_channel' => ['neq', 51], // 问答模型
|
||||
'weapp_code' => '',
|
||||
);
|
||||
$arctypeLogic = new ArctypeLogic();
|
||||
$select_html = $arctypeLogic->arctype_list(0, 0, true, config('global.arctype_max_level'), $map);
|
||||
$this->assign('select_html',$select_html);
|
||||
// 允许发布文档列表的栏目
|
||||
$arc_select_html = allow_release_arctype();
|
||||
$this->assign('arc_select_html', $arc_select_html);
|
||||
// 生成完页面之后,清除缓存
|
||||
$this->buildhtml_clear_cache();
|
||||
|
||||
/*标记是否第一次切换静态页面模式*/
|
||||
if (!isset($config['seo_html_arcdir'])) {
|
||||
$init_html = 1; // 第一次切换
|
||||
} else {
|
||||
$init_html = 2; // 多次切换
|
||||
}
|
||||
$this->assign('init_html', $init_html);
|
||||
/*--end*/
|
||||
|
||||
$this->assign('config',$config);//当前配置项
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存URL配置
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$inc_type = 'seo';
|
||||
$param = input('post.');
|
||||
$globalConfig = tpCache('global');
|
||||
$seo_pseudo_new = $param['seo_pseudo'];
|
||||
|
||||
/*伪静态格式*/
|
||||
if (3 == $seo_pseudo_new && in_array($param['seo_rewrite_format'], [1,3])) {
|
||||
$param['seo_rewrite_format'] = $param['seo_rewrite_view_format'];
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/* 生成静态页面代码 */
|
||||
unset($param['seo_html_arcdir_limit']);
|
||||
if (!empty($param['seo_html_arcdir']) && !preg_match('/^([0-9a-zA-Z\_\-\/]+)$/i', $param['seo_html_arcdir'])) {
|
||||
$this->error('页面保存路径的格式错误!');
|
||||
}
|
||||
if (!empty($param['seo_html_arcdir'])) {
|
||||
if (preg_match('/^([0-9a-zA-Z\_\-\/]+)$/i', $param['seo_html_arcdir'])) {
|
||||
// $param['seo_html_arcdir'] = ROOT_DIR.'/'.trim($param['seo_html_arcdir'], '/');
|
||||
$param['seo_html_arcdir'] = '/'.trim($param['seo_html_arcdir'], '/');
|
||||
} else {
|
||||
$this->error('页面保存路径的格式错误!');
|
||||
}
|
||||
}
|
||||
$seo_html_arcdir_old = !empty($globalConfig['seo_html_arcdir']) ? $globalConfig['seo_html_arcdir'] : '';
|
||||
/* end */
|
||||
|
||||
/*检测是否开启pathinfo模式*/
|
||||
try {
|
||||
if (3 == $seo_pseudo_new || (1 == $seo_pseudo_new && 2 == $param['seo_dynamic_format'])) {
|
||||
$fix_pathinfo = ini_get('cgi.fix_pathinfo');
|
||||
if (stristr($_SERVER['HTTP_HOST'], '.mylightsite.com')) {
|
||||
$this->error('腾讯云空间不支持伪静态!');
|
||||
} else if ('' != $fix_pathinfo && 0 === $fix_pathinfo) {
|
||||
$this->error('空间不支持伪静态,请开启pathinfo,或者在php.ini里修改cgi.fix_pathinfo=1');
|
||||
}
|
||||
}
|
||||
/* 生成静态页面代码 - URL模式切换时删掉根目录下的index.html静态文件 */
|
||||
if(1 == $seo_pseudo_new || 3 == $seo_pseudo_new){
|
||||
if(file_exists('./index.html')){
|
||||
@unlink('./index.html');
|
||||
}
|
||||
}
|
||||
/* end */
|
||||
} catch (\Exception $e) {}
|
||||
/*--end*/
|
||||
|
||||
/*强制去除index.php*/
|
||||
if (isset($param['seo_force_inlet'])) {
|
||||
$seo_force_inlet = $param['seo_force_inlet'];
|
||||
$seo_force_inlet_old = !empty($globalConfig['seo_force_inlet']) ? $globalConfig['seo_force_inlet'] : '';
|
||||
if ($seo_force_inlet_old != $seo_force_inlet) {
|
||||
$param['seo_inlet'] = $seo_force_inlet;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$seo_pseudo_lang = !empty($param['seo_pseudo_lang']) ? $param['seo_pseudo_lang'] : 1;
|
||||
unset($param['seo_pseudo_lang']);
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
if (2 != $seo_pseudo_new) { // 非生成静态模式下,所有语言的URL模式一致
|
||||
tpCache($inc_type,$param,$val['mark']);
|
||||
} else {
|
||||
if($key == 0){ // 主体语言(第一个语言)是生成静态模式
|
||||
tpCache($inc_type,$param,$val['mark']);
|
||||
}else{//其他语言统一设置URL模式非静态模式
|
||||
$param['seo_pseudo'] = $seo_pseudo_lang;
|
||||
tpCache($inc_type,$param,$val['mark']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tpCache($inc_type,$param);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/* 生成静态页面代码 - 更新分页php文件支持生成静态功能*/
|
||||
$this->update_paginatorfile();
|
||||
/* end */
|
||||
|
||||
// 清空缓存
|
||||
delFile(rtrim(HTML_ROOT, '/'));
|
||||
\think\Cache::clear();
|
||||
$this->success('操作成功', url('Seo/seo'));
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成静态页面代码 - 更新分页php文件支持生成静态功能
|
||||
*/
|
||||
private function update_paginatorfile()
|
||||
{
|
||||
$dirpath = CORE_PATH . 'paginator/driver/*.php';
|
||||
$files = glob($dirpath);
|
||||
foreach ($files as $key => $file) {
|
||||
if (is_writable($file)) {
|
||||
$strContent = @file_get_contents($file);
|
||||
if (false != $strContent && !stristr($strContent, 'data-ey_fc35fdc="html"')) {
|
||||
$replace = 'htmlentities($url) . \'" data-ey_fc35fdc="html" data-tmp="1\'';
|
||||
$strContent = str_replace('htmlentities($url)', $replace, $strContent);
|
||||
@chmod($file,0777);
|
||||
@file_put_contents($file, $strContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成整站静态文件
|
||||
*/
|
||||
public function buildSite(){
|
||||
$type = input("param.type/s");
|
||||
if($type != 'site'){
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取生成栏目或文章的栏目id
|
||||
*/
|
||||
public function getAllType(){
|
||||
$id = input("param.id/d");//栏目id
|
||||
$type = input("param.type/d");//1栏目2文章
|
||||
if(empty($id)) {
|
||||
if($id == 0){
|
||||
$mark = Db::name('language')->order('id asc')->value('mark');
|
||||
if($type == 1){
|
||||
$arctype = Db::name('arctype')->where(['is_del'=>0,'status'=>1,'lang'=>$mark])->getfield('id',true);
|
||||
}else{
|
||||
$where['is_del'] = 0;
|
||||
$where['status'] = 1;
|
||||
$where['lang'] = $mark;
|
||||
$where['current_channel'] = array(array('neq',6),array('neq',8));
|
||||
$arctype = Db::name('arctype')->where($where)->getfield('id',true);
|
||||
}
|
||||
if(empty($arctype)){
|
||||
$this->error('没有要更新的栏目!');
|
||||
}else{
|
||||
$arctype = implode(',',$arctype);
|
||||
$this->success($arctype);
|
||||
}
|
||||
}else{
|
||||
$this->error('栏目ID不能为空!');
|
||||
}
|
||||
}else{
|
||||
//递归查询所有的子类
|
||||
$arctype_child_all = array($id);
|
||||
getAllChild($arctype_child_all,$id,$type);
|
||||
|
||||
$arctype_child_all = implode(',',$arctype_child_all);
|
||||
if(empty($arctype_child_all)) {
|
||||
$this->error('没有要更新的栏目!');
|
||||
}else{
|
||||
$this->success($arctype_child_all);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 纠正栏目的HTML目录路径字段值
|
||||
*/
|
||||
private function correctArctypeDirpath()
|
||||
{
|
||||
$system_correctArctypeDirpath = tpCache('system.system_correctArctypeDirpath');
|
||||
if (!empty($system_correctArctypeDirpath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$saveData = [];
|
||||
$arctypeList = Db::name('arctype')->field('id,parent_id,dirname,dirpath,grade')
|
||||
->order('grade asc')
|
||||
->getAllWithIndex('id');
|
||||
foreach ($arctypeList as $key => $val) {
|
||||
if (empty($val['parent_id'])) { // 一级栏目
|
||||
$saveData[] = [
|
||||
'id' => $val['id'],
|
||||
'dirpath' => '/'.$val['dirname'],
|
||||
'grade' => 0,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
} else {
|
||||
$parentRow = $arctypeList[$val['parent_id']];
|
||||
if (empty($parentRow['parent_id'])) { // 二级栏目
|
||||
$saveData[] = [
|
||||
'id' => $val['id'],
|
||||
'dirpath' => '/'.$parentRow['dirname'].'/'.$val['dirname'],
|
||||
'grade' => 1,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
} else { // 三级栏目
|
||||
$topRow = $arctypeList[$parentRow['parent_id']];
|
||||
$saveData[] = [
|
||||
'id' => $val['id'],
|
||||
'dirpath' => '/'.$topRow['dirname'].'/'.$parentRow['dirname'].'/'.$val['dirname'],
|
||||
'grade' => 2,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$r = model('Arctype')->saveAll($saveData);
|
||||
if (false !== $r) {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('system', ['system_correctArctypeDirpath'=>1],$val['mark']);
|
||||
}
|
||||
} else {
|
||||
tpCache('system',['system_correctArctypeDirpath'=>1]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态页面模式切换为其他模式时,检测之前生成的静态目录是否存在,并提示手工删除还是自动删除
|
||||
*/
|
||||
public function ajax_checkHtmlDirpath()
|
||||
{
|
||||
$seo_pseudo_new = input('param.seo_pseudo_new/d');
|
||||
if (3 == $seo_pseudo_new) {
|
||||
$dirArr = [];
|
||||
$seo_html_listname = tpCache('seo.seo_html_listname');
|
||||
$row = Db::name('arctype')->field('dirpath')->select();
|
||||
foreach ($row as $key => $val) {
|
||||
$dirpathArr = explode('/', $val['dirpath']);
|
||||
if (3 == $seo_html_listname) {
|
||||
$dir = end($dirpathArr);
|
||||
} else {
|
||||
$dir = !empty($dirpathArr[1]) ? $dirpathArr[1] : '';
|
||||
}
|
||||
if (!empty($dir) && !in_array($dir, $dirArr)) {
|
||||
array_push($dirArr, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['msg'] = '';
|
||||
$num = 0;
|
||||
$wwwroot = glob('*', GLOB_ONLYDIR);
|
||||
foreach ($wwwroot as $key => $val) {
|
||||
if (in_array($val, $dirArr)) {
|
||||
if (0 == $num) {
|
||||
$data['msg'] .= "<font color='red'>根目录下有HTML静态目录,请先删除:</font><br/>";
|
||||
}
|
||||
$data['msg'] .= ($num+1)."、{$val}<br/>";
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
$data['height'] = $num * 24;
|
||||
|
||||
$this->success('检测成功!', null, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动删除静态HTML存放目录
|
||||
*/
|
||||
public function ajax_delHtmlDirpath()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
$error = false;
|
||||
$dirArr = [];
|
||||
$seo_html_listname = tpCache('seo.seo_html_listname');
|
||||
$row = Db::name('arctype')->field('dirpath')->select();
|
||||
foreach ($row as $key => $val) {
|
||||
$dirpathArr = explode('/', $val['dirpath']);
|
||||
if (3 == $seo_html_listname) {
|
||||
$dir = end($dirpathArr);
|
||||
} else {
|
||||
$dir = !empty($dirpathArr[1]) ? $dirpathArr[1] : '';
|
||||
}
|
||||
$filepath = "./{$dir}";
|
||||
if (!empty($dir) && !in_array($dir, $dirArr) && file_exists($filepath)) {
|
||||
@unlink($filepath."/index.html");
|
||||
$bool = delFile($filepath, true);
|
||||
if (false !== $bool) {
|
||||
array_push($dirArr, $dir);
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['msg'] = '';
|
||||
if ($error) {
|
||||
$num = 0;
|
||||
$wwwroot = glob('*', GLOB_ONLYDIR);
|
||||
foreach ($wwwroot as $key => $val) {
|
||||
if (in_array($val, $dirArr)) {
|
||||
if (0 == $num) {
|
||||
$data['msg'] .= "<font color='red'>部分目录删除失败,请手工删除:</font><br/>";
|
||||
}
|
||||
$data['msg'] .= ($num+1)."、{$val}<br/>";
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
$data['height'] = $num * 24;
|
||||
$this->error('删除失败!', null, $data);
|
||||
}
|
||||
|
||||
$this->success('删除成功!', null, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成完页面之后,清除缓存
|
||||
*/
|
||||
private function buildhtml_clear_cache()
|
||||
{
|
||||
// 文档参数缓存
|
||||
cache("article_info_serialize",null);
|
||||
cache("article_page_total_serialize",null);
|
||||
cache("article_content_serialize",null);
|
||||
cache("article_tags_serialize",null);
|
||||
cache("article_attr_info_serialize",null);
|
||||
cache("article_children_row_serialize",null);
|
||||
// 栏目参数缓存
|
||||
cache("channel_page_total_serialize",null);
|
||||
cache("channel_info_serialize",null);
|
||||
cache("has_children_Row_serialize",null);
|
||||
}
|
||||
}
|
||||
10
src/application/admin/controller/Sharp.php
Normal file
10
src/application/admin/controller/Sharp.php
Normal file
File diff suppressed because one or more lines are too long
1432
src/application/admin/controller/Shop.php
Normal file
1432
src/application/admin/controller/Shop.php
Normal file
File diff suppressed because it is too large
Load Diff
111
src/application/admin/controller/ShopComment.php
Normal file
111
src/application/admin/controller/ShopComment.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2021-01-26
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class ShopComment extends Base
|
||||
{
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
$functionLogic = new \app\common\logic\FunctionLogic;
|
||||
$functionLogic->check_authorfile(2);
|
||||
|
||||
// 产品属性表
|
||||
$this->shop_order_comment_db = Db::name('shop_order_comment');
|
||||
}
|
||||
|
||||
// 评价列表
|
||||
public function comment_index()
|
||||
{
|
||||
$functionLogic = new \app\common\logic\FunctionLogic;
|
||||
$assign_data = $functionLogic->comment_index();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 评价详情
|
||||
public function comment_details()
|
||||
{
|
||||
$comment_id = input('param.comment_id');
|
||||
if (!empty($comment_id)) {
|
||||
// 退换货信息
|
||||
$field = 'a.comment_id, a.order_id, a.users_id, a.order_code, a.product_id, a.upload_img, a.content, a.total_score, a.is_show, a.add_time, b.product_name, b.product_price, b.litpic as product_img, b.num as product_num, b.data, c.username, c.nickname';
|
||||
$Comment[0] = $this->shop_order_comment_db->alias('a')->where('comment_id', $comment_id)
|
||||
->field($field)
|
||||
->join('__SHOP_ORDER_DETAILS__ b', 'a.details_id = b.details_id', 'LEFT')
|
||||
->join('__USERS__ c', 'a.users_id = c.users_id')
|
||||
->find();
|
||||
$array_new = get_archives_data($Comment, 'product_id');
|
||||
$Comment = $Comment[0];
|
||||
|
||||
// 评价上传的图片
|
||||
$Comment['upload_img'] = !empty($Comment['upload_img']) ? explode(',', unserialize($Comment['upload_img'])) : '';
|
||||
|
||||
// 商品规格
|
||||
$Comment['product_spec'] = str_replace("<br/>", " || ", unserialize($Comment['data'])['spec_value']);
|
||||
|
||||
// 商品图片
|
||||
$Comment['product_img'] = handle_subdir_pic(get_default_pic($Comment['product_img']));
|
||||
|
||||
// 商品链接
|
||||
$Comment['arcurl'] = get_arcurl($array_new[$Comment['product_id']]);
|
||||
|
||||
// 商品评价评分
|
||||
$Comment['order_total_score'] = Config::get('global.order_total_score')[$Comment['total_score']];
|
||||
|
||||
// 评价转换星级评分
|
||||
$Comment['total_score'] = GetScoreArray($Comment['total_score']);
|
||||
|
||||
// 评价的内容
|
||||
$Comment['content'] = !empty($Comment['content']) ? htmlspecialchars_decode(unserialize($Comment['content'])) : '';
|
||||
|
||||
// 会员信息
|
||||
$Users = Db::name('users')->field('users_id, username, nickname, mobile')->find($Service['users_id']);
|
||||
$Users['nickname'] = empty($Users['nickname']) ? $Users['username'] : $Users['nickname'];
|
||||
|
||||
// 加载数据
|
||||
$this->assign('Users', $Users);
|
||||
$this->assign('Comment', $Comment);
|
||||
return $this->fetch('comment_details');
|
||||
} else {
|
||||
$this->error('非法访问!');
|
||||
}
|
||||
}
|
||||
|
||||
// 评价删除
|
||||
public function comment_del()
|
||||
{
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(IS_POST && !empty($id_arr)){
|
||||
$ResultID = $this->shop_order_comment_db->where(['comment_id' => ['IN', $id_arr]])->delete();
|
||||
if (!empty($ResultID)) {
|
||||
foreach ($id_arr as $key => $val) {
|
||||
cache('EyouHomeAjaxComment_' . $val, null, null, 'shop_order_comment');
|
||||
}
|
||||
adminLog('删除评价-id:'.implode(',', $id_arr));
|
||||
$this->success('删除成功');
|
||||
} else {
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1540
src/application/admin/controller/ShopProduct.php
Normal file
1540
src/application/admin/controller/ShopProduct.php
Normal file
File diff suppressed because it is too large
Load Diff
10
src/application/admin/controller/ShopService.php
Normal file
10
src/application/admin/controller/ShopService.php
Normal file
File diff suppressed because one or more lines are too long
81
src/application/admin/controller/Sitemap.php
Normal file
81
src/application/admin/controller/Sitemap.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
class Sitemap extends Base
|
||||
{
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sitemap
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$inc_type = 'sitemap';
|
||||
if (IS_POST) {
|
||||
$param = input('post.');
|
||||
$param['sitemap_not1'] = isset($param['sitemap_not1']) ? $param['sitemap_not1'] : 0;
|
||||
$param['sitemap_not2'] = isset($param['sitemap_not2']) ? $param['sitemap_not2'] : 0;
|
||||
$param['sitemap_xml'] = isset($param['sitemap_xml']) ? $param['sitemap_xml'] : 0;
|
||||
$param['sitemap_txt'] = isset($param['sitemap_txt']) ? $param['sitemap_txt'] : 0;
|
||||
$param['sitemap_archives_num'] = isset($param['sitemap_archives_num']) ? intval($param['sitemap_archives_num']) : 100;
|
||||
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache($inc_type,$param,$val['mark']);
|
||||
}
|
||||
} else {
|
||||
tpCache($inc_type,$param);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/* 生成sitemap */
|
||||
sitemap_all();
|
||||
$this->success('操作成功', url('Sitemap/index'));
|
||||
}
|
||||
|
||||
$config = tpCache($inc_type);
|
||||
$this->assign('config',$config);//当前配置项
|
||||
return $this->fetch('seo/sitemap');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成相应的搜索引擎sitemap
|
||||
*/
|
||||
public function create($ver = 'xml')
|
||||
{
|
||||
if (empty($ver)) {
|
||||
sitemap_all();
|
||||
} else {
|
||||
$fun_name = 'sitemap_'.$ver;
|
||||
$fun_name();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajax_update_sitemap()
|
||||
{
|
||||
if (IS_POST) {
|
||||
/* 生成sitemap */
|
||||
sitemap_all();
|
||||
$this->success('更新成功');
|
||||
}
|
||||
$this->error('更新失败!');
|
||||
}
|
||||
}
|
||||
813
src/application/admin/controller/Special.php
Normal file
813
src/application/admin/controller/Special.php
Normal file
@@ -0,0 +1,813 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class Special extends Base
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'special';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
empty($this->channeltype) && $this->channeltype = 7;
|
||||
$this->assign('nid', $this->nid);
|
||||
$this->assign('channeltype', $this->channeltype);
|
||||
}
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
$flag = input('flag/s');
|
||||
$typeid = input('typeid/d', 0);
|
||||
$begin = strtotime(input('add_time_begin'));
|
||||
$end = strtotime(input('add_time_end'));
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','flag','is_release'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid') {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'flag') {
|
||||
if ('is_release' == $param[$key]) {
|
||||
$condition['a.users_id'] = array('gt', 0);
|
||||
} else {
|
||||
$condition['a.'.$param[$key]] = array('eq', 1);
|
||||
}
|
||||
// } else if ($key == 'is_release') {
|
||||
// if (0 < intval($param[$key])) {
|
||||
// $condition['a.users_id'] = array('gt', intval($param[$key]));
|
||||
// }
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 时间检索
|
||||
if ($begin > 0 && $end > 0) {
|
||||
$condition['a.add_time'] = array('between',"$begin,$end");
|
||||
} else if ($begin > 0) {
|
||||
$condition['a.add_time'] = array('egt', $begin);
|
||||
} else if ($end > 0) {
|
||||
$condition['a.add_time'] = array('elt', $end);
|
||||
}
|
||||
|
||||
// 模型ID
|
||||
$condition['a.channel'] = array('eq', $this->channeltype);
|
||||
// 多语言
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
// 回收站
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/*自定义排序*/
|
||||
$orderby = input('param.orderby/s');
|
||||
$orderway = input('param.orderway/s');
|
||||
if (!empty($orderby)) {
|
||||
$orderby = "a.{$orderby} {$orderway}";
|
||||
$orderby .= ", a.aid desc";
|
||||
} else {
|
||||
$orderby = "a.aid desc";
|
||||
}
|
||||
/*end*/
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = DB::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = DB::name('archives')
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order($orderby)
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = DB::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
|
||||
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
// 栏目ID
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
/*当前栏目信息*/
|
||||
$arctype_info = array();
|
||||
if ($typeid > 0) {
|
||||
$arctype_info = M('arctype')->field('typename')->find($typeid);
|
||||
}
|
||||
$assign_data['arctype_info'] = $arctype_info;
|
||||
/*--end*/
|
||||
|
||||
/*选项卡*/
|
||||
$tab = input('param.tab/d', 3);
|
||||
$assign_data['tab'] = $tab;
|
||||
/*--end*/
|
||||
|
||||
/*前台URL模式*/
|
||||
$assign_data['seo_pseudo'] = tpCache('seo.seo_pseudo');
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = 1; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// 外部链接跳转
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做自动通过审核判断
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$post['arcrank'] = -1;
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> empty($post['typeid']) ? 0 : $post['typeid'],
|
||||
'channel' => $this->channeltype,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'admin_id' => session('admin_info.admin_id'),
|
||||
'lang' => $this->admin_lang,
|
||||
'sort_order' => 100,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => strtotime($post['add_time']),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$aid = Db::name('archives')->insertGetId($data);
|
||||
$_POST['aid'] = $aid;
|
||||
if ($aid) {
|
||||
// ---------后置操作
|
||||
model('Special')->afterSave($aid, $data, 'add');
|
||||
// ---------end
|
||||
adminLog('新增专题:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $aid,
|
||||
'tid' => $post['typeid'],
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$typeid = input('param.typeid/d', 0);
|
||||
$assign_data['typeid'] = $typeid; // 栏目ID
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($this->channeltype));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($this->channeltype);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0, $typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = 0;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = 'view_'.$this->nid.'.'.config('template.view_suffix');
|
||||
!empty($arctypeInfo['tempview']) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
/*--end*/
|
||||
|
||||
/*节点允许发布文档列表的栏目*/
|
||||
$allow_release_channel = config('global.allow_release_channel');
|
||||
$key_tmp = array_search('7', $allow_release_channel);
|
||||
if (is_numeric($key_tmp) && 0 <= $key_tmp) {
|
||||
unset($allow_release_channel[$key_tmp]);
|
||||
}
|
||||
$node_select_html = allow_release_arctype(0, $allow_release_channel);
|
||||
$assign_data['node_select_html'] = $node_select_html;
|
||||
/*--end*/
|
||||
|
||||
/* 节点模型列表 */
|
||||
$allow_release_channel = config('global.allow_release_channel');
|
||||
$node_channeltype_list = \think\Cache::get('extra_global_channeltype');
|
||||
foreach ($node_channeltype_list as $key => $val) {
|
||||
if (!in_array($val['id'], $allow_release_channel)) {
|
||||
unset($node_channeltype_list[$val['id']]);
|
||||
}
|
||||
}
|
||||
unset($node_channeltype_list[7]);
|
||||
$assign_data['node_channeltype_list'] = $node_channeltype_list;
|
||||
/*--end*/
|
||||
|
||||
// 文档默认浏览量
|
||||
$other_config = tpCache('other');
|
||||
if (isset($other_config['other_arcclick']) && 0 <= $other_config['other_arcclick']) {
|
||||
$arcclick_arr = explode("|", $other_config['other_arcclick']);
|
||||
if (count($arcclick_arr) > 1) {
|
||||
$assign_data['rand_arcclick'] = mt_rand($arcclick_arr[0], $arcclick_arr[1]);
|
||||
} else {
|
||||
$assign_data['rand_arcclick'] = intval($arcclick_arr[0]);
|
||||
}
|
||||
}else{
|
||||
$arcclick_config['other_arcclick'] = '500|1000';
|
||||
tpCache('other', $arcclick_config);
|
||||
$assign_data['rand_arcclick'] = mt_rand(500, 1000);
|
||||
}
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$admin_info = session('admin_info');
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$this->assign('auth_role_info', $auth_role_info);
|
||||
$this->assign('admin_info', $admin_info);
|
||||
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
|
||||
/* 处理TAG标签 */
|
||||
if (!empty($post['tags_new'])) {
|
||||
$post['tags'] = !empty($post['tags']) ? $post['tags'] . ',' . $post['tags_new'] : $post['tags_new'];
|
||||
unset($post['tags_new']);
|
||||
}
|
||||
$post['tags'] = explode(',', $post['tags']);
|
||||
$post['tags'] = array_unique($post['tags']);
|
||||
$post['tags'] = implode(',', $post['tags']);
|
||||
/* END */
|
||||
|
||||
$typeid = input('post.typeid/d', 0);
|
||||
$content = input('post.addonFieldExt.content', '', null);
|
||||
|
||||
// 根据标题自动提取相关的关键字
|
||||
$seo_keywords = $post['seo_keywords'];
|
||||
if (!empty($seo_keywords)) {
|
||||
$seo_keywords = str_replace(',', ',', $seo_keywords);
|
||||
} else {
|
||||
// $seo_keywords = get_split_word($post['title'], $content);
|
||||
}
|
||||
|
||||
// 自动获取内容第一张图片作为封面图
|
||||
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
|
||||
$litpic = '';
|
||||
if ($is_remote == 1) {
|
||||
$litpic = $post['litpic_remote'];
|
||||
} else {
|
||||
$litpic = $post['litpic_local'];
|
||||
}
|
||||
if (empty($litpic)) {
|
||||
$litpic = get_html_first_imgurl($content);
|
||||
}
|
||||
$post['litpic'] = $litpic;
|
||||
|
||||
/*是否有封面图*/
|
||||
if (empty($post['litpic'])) {
|
||||
$is_litpic = 0; // 无封面图
|
||||
} else {
|
||||
$is_litpic = !empty($post['is_litpic']) ? $post['is_litpic'] : 0; // 有封面图
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
$seo_description = '';
|
||||
if (empty($post['seo_description']) && !empty($content)) {
|
||||
$seo_description = @msubstr(checkStrHtml($content), 0, config('global.arc_seo_description_length'), false);
|
||||
} else {
|
||||
$seo_description = $post['seo_description'];
|
||||
}
|
||||
|
||||
// --外部链接
|
||||
$jumplinks = '';
|
||||
$is_jump = isset($post['is_jump']) ? $post['is_jump'] : 0;
|
||||
if (intval($is_jump) > 0) {
|
||||
$jumplinks = $post['jumplinks'];
|
||||
}
|
||||
|
||||
// 模板文件,如果文档模板名与栏目指定的一致,默认就为空。让它跟随栏目的指定而变
|
||||
if ($post['type_tempview'] == $post['tempview']) {
|
||||
unset($post['type_tempview']);
|
||||
unset($post['tempview']);
|
||||
}
|
||||
|
||||
// 同步栏目切换模型之后的文档模型
|
||||
$channel = Db::name('arctype')->where(['id'=>$typeid])->getField('current_channel');
|
||||
|
||||
//处理自定义文件名,仅由字母数字下划线和短横杆组成,大写强制转换为小写
|
||||
$htmlfilename = trim($post['htmlfilename']);
|
||||
if (!empty($htmlfilename)) {
|
||||
$htmlfilename = preg_replace("/[^a-zA-Z0-9_-]+/", "-", $htmlfilename);
|
||||
$htmlfilename = strtolower($htmlfilename);
|
||||
//判断是否存在相同的自定义文件名
|
||||
$filenameCount = Db::name('archives')->where([
|
||||
'aid' => ['NEQ', $post['aid']],
|
||||
'htmlfilename' => $htmlfilename,
|
||||
'lang' => $this->admin_lang,
|
||||
])->count();
|
||||
if (!empty($filenameCount)) {
|
||||
$this->error("自定义文件名已存在,请重新设置!");
|
||||
}
|
||||
}
|
||||
$post['htmlfilename'] = $htmlfilename;
|
||||
|
||||
//做未通过审核文档不允许修改文档状态操作
|
||||
if ($admin_info['role_id'] > 0 && $auth_role_info['check_oneself'] < 1) {
|
||||
$old_archives_arcrank = Db::name('archives')->where(['aid' => $post['aid']])->getField("arcrank");
|
||||
if ($old_archives_arcrank < 0) {
|
||||
unset($post['arcrank']);
|
||||
}
|
||||
}
|
||||
|
||||
// --存储数据
|
||||
$newData = array(
|
||||
'typeid'=> $typeid,
|
||||
'channel' => $channel,
|
||||
'is_b' => empty($post['is_b']) ? 0 : $post['is_b'],
|
||||
'is_head' => empty($post['is_head']) ? 0 : $post['is_head'],
|
||||
'is_special' => empty($post['is_special']) ? 0 : $post['is_special'],
|
||||
'is_recom' => empty($post['is_recom']) ? 0 : $post['is_recom'],
|
||||
'is_roll' => empty($post['is_roll']) ? 0 : $post['is_roll'],
|
||||
'is_slide' => empty($post['is_slide']) ? 0 : $post['is_slide'],
|
||||
'is_diyattr' => empty($post['is_diyattr']) ? 0 : $post['is_diyattr'],
|
||||
'is_jump' => $is_jump,
|
||||
'is_litpic' => $is_litpic,
|
||||
'jumplinks' => $jumplinks,
|
||||
'seo_keywords' => $seo_keywords,
|
||||
'seo_description' => $seo_description,
|
||||
'add_time' => strtotime($post['add_time']),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$data = array_merge($post, $newData);
|
||||
|
||||
$r = Db::name('archives')->where([
|
||||
'aid' => $data['aid'],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update($data);
|
||||
|
||||
if ($r) {
|
||||
// ---------后置操作
|
||||
model('Special')->afterSave($data['aid'], $data, 'edit');
|
||||
// ---------end
|
||||
adminLog('编辑专题:'.$data['title']);
|
||||
|
||||
// 生成静态页面代码
|
||||
$successData = [
|
||||
'aid' => $data['aid'],
|
||||
'tid' => $typeid,
|
||||
];
|
||||
$this->success("操作成功!", null, $successData);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->error("操作失败!");
|
||||
exit;
|
||||
}
|
||||
|
||||
$assign_data = array();
|
||||
|
||||
$id = input('id/d');
|
||||
$info = model('Special')->getInfo($id, null, false);
|
||||
if (empty($info)) {
|
||||
$this->error('数据不存在,请联系管理员!');
|
||||
exit;
|
||||
}
|
||||
/*兼容采集没有归属栏目的文档*/
|
||||
if (empty($info['channel'])) {
|
||||
$channelRow = Db::name('channeltype')->field('id as channel')
|
||||
->where('id',$this->channeltype)
|
||||
->find();
|
||||
$info = array_merge($info, $channelRow);
|
||||
}
|
||||
/*--end*/
|
||||
$typeid = $info['typeid'];
|
||||
$assign_data['typeid'] = $typeid;
|
||||
|
||||
// 栏目信息
|
||||
$arctypeInfo = Db::name('arctype')->find($typeid);
|
||||
|
||||
$info['channel'] = $arctypeInfo['current_channel'];
|
||||
if (is_http_url($info['litpic'])) {
|
||||
$info['is_remote'] = 1;
|
||||
$info['litpic_remote'] = handle_subdir_pic($info['litpic']);
|
||||
} else {
|
||||
$info['is_remote'] = 0;
|
||||
$info['litpic_local'] = handle_subdir_pic($info['litpic']);
|
||||
}
|
||||
|
||||
// SEO描述
|
||||
if (!empty($info['seo_description'])) {
|
||||
$info['seo_description'] = @msubstr(checkStrHtml($info['seo_description']), 0, config('global.arc_seo_description_length'), false);
|
||||
}
|
||||
|
||||
$assign_data['field'] = $info;
|
||||
|
||||
/*允许发布文档列表的栏目,文档所在模型以栏目所在模型为主,兼容切换模型之后的数据编辑*/
|
||||
$arctype_html = allow_release_arctype($typeid, array($info['channel']));
|
||||
$assign_data['arctype_html'] = $arctype_html;
|
||||
/*--end*/
|
||||
|
||||
/*自定义字段*/
|
||||
// $addonFieldExtList = model('Field')->getChannelFieldList($info['channel'], 0, $id, $info);
|
||||
// $channelfieldBindRow = Db::name('channelfield_bind')->where([
|
||||
// 'typeid' => ['IN', [0,$typeid]],
|
||||
// ])->column('field_id');
|
||||
// if (!empty($channelfieldBindRow)) {
|
||||
// foreach ($addonFieldExtList as $key => $val) {
|
||||
// if (!in_array($val['id'], $channelfieldBindRow)) {
|
||||
// unset($addonFieldExtList[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $assign_data['addonFieldExtList'] = $addonFieldExtList;
|
||||
// $assign_data['aid'] = $id;
|
||||
/*--end*/
|
||||
|
||||
// 阅读权限
|
||||
$arcrank_list = get_arcrank_list();
|
||||
$assign_data['arcrank_list'] = $arcrank_list;
|
||||
|
||||
/*模板列表*/
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$templateList = $archivesLogic->getTemplateList($this->nid);
|
||||
$this->assign('templateList', $templateList);
|
||||
/*--end*/
|
||||
|
||||
/*默认模板文件*/
|
||||
$tempview = $info['tempview'];
|
||||
empty($tempview) && $tempview = $arctypeInfo['tempview'];
|
||||
$this->assign('tempview', $tempview);
|
||||
/*--end*/
|
||||
|
||||
// URL模式
|
||||
$tpcache = config('tpcache');
|
||||
$assign_data['seo_pseudo'] = !empty($tpcache['seo_pseudo']) ? $tpcache['seo_pseudo'] : 1;
|
||||
/*--end*/
|
||||
|
||||
/*节点允许发布文档列表的栏目*/
|
||||
$allow_release_channel = config('global.allow_release_channel');
|
||||
$key_tmp = array_search('7', $allow_release_channel);
|
||||
if (is_numeric($key_tmp) && 0 <= $key_tmp) {
|
||||
unset($allow_release_channel[$key_tmp]);
|
||||
}
|
||||
$node_select_html = allow_release_arctype(0, $allow_release_channel);
|
||||
$assign_data['node_select_html'] = $node_select_html;
|
||||
/*--end*/
|
||||
|
||||
/* 节点模型列表 */
|
||||
$allow_release_channel = config('global.allow_release_channel');
|
||||
$node_channeltype_list = \think\Cache::get('extra_global_channeltype');
|
||||
foreach ($node_channeltype_list as $key => $val) {
|
||||
if (!in_array($val['id'], $allow_release_channel)) {
|
||||
unset($node_channeltype_list[$val['id']]);
|
||||
}
|
||||
}
|
||||
unset($node_channeltype_list[7]);
|
||||
$assign_data['node_channeltype_list'] = $node_channeltype_list;
|
||||
/*--end*/
|
||||
|
||||
/*节点数据*/
|
||||
$specialNodeList = model('SpecialNode')->getList($id);
|
||||
$assign_data['specialNodeList'] = $specialNodeList;
|
||||
/*--end*/
|
||||
|
||||
/*文档属性*/
|
||||
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();
|
||||
|
||||
$this->assign($assign_data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$archivesLogic = new \app\admin\logic\ArchivesLogic;
|
||||
$archivesLogic->del();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择节点文档
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function ajax_node_archives_list()
|
||||
{
|
||||
$assign_data = array();
|
||||
$condition = array();
|
||||
// 获取到所有URL参数
|
||||
$param = input('param.');
|
||||
$typeid = input('param.typeid/d');
|
||||
$channels = input('param.channel/s');
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','typeid','channel'] as $key) {
|
||||
if ($key == 'keywords' && !empty($param[$key])) {
|
||||
$param[$key] = trim($param[$key]);
|
||||
$condition['a.title'] = array('LIKE', "%{$param[$key]}%");
|
||||
} else if ($key == 'typeid' && !empty($param[$key])) {
|
||||
$typeid = $param[$key];
|
||||
$hasRow = model('Arctype')->getHasChildren($typeid);
|
||||
$typeids = get_arr_column($hasRow, 'id');
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
|
||||
$condition['a.admin_id'] = $admin_info['admin_id'];
|
||||
}
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
if (!empty($typeid)) {
|
||||
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
$condition['a.typeid'] = array('IN', $typeids);
|
||||
} else if ($key == 'channel') {
|
||||
if (empty($param[$key])) {
|
||||
$allow_release_channel = config('global.allow_release_channel');
|
||||
$key_tmp = array_search('7', $allow_release_channel);
|
||||
if (is_numeric($key_tmp) && 0 <= $key_tmp) {
|
||||
unset($allow_release_channel[$key_tmp]);
|
||||
}
|
||||
$param[$key] = implode(',', $allow_release_channel);
|
||||
}
|
||||
$condition['a.'.$key] = array('in', explode(',', $param[$key]));
|
||||
} else if (!empty($param[$key])) {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// 排除已选中的文档
|
||||
$aids = input('param.aids/s');
|
||||
$aidArr = explode(',', trim($aids, ','));
|
||||
if (!empty($aidArr)) {
|
||||
$condition['a.aid'] = ['NOT IN', $aids];
|
||||
}
|
||||
|
||||
// 审核通过
|
||||
$condition['a.arcrank'] = array('gt', -1);
|
||||
/*多语言*/
|
||||
$condition['a.lang'] = array('eq', $this->admin_lang);
|
||||
/*回收站数据不显示*/
|
||||
$condition['a.is_del'] = array('eq', 0);
|
||||
|
||||
/**
|
||||
* 数据查询,搜索出主键ID的值
|
||||
*/
|
||||
$count = Db::name('archives')->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
|
||||
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = Db::name('archives')
|
||||
->field("a.aid")
|
||||
->alias('a')
|
||||
->where($condition)
|
||||
->order('a.sort_order asc, a.aid desc')
|
||||
->limit($Page->firstRow.','.$Page->listRows)
|
||||
->getAllWithIndex('aid');
|
||||
|
||||
/**
|
||||
* 完善数据集信息
|
||||
* 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
|
||||
*/
|
||||
if ($list) {
|
||||
$aids = array_keys($list);
|
||||
$fields = "b.*, a.*, a.aid as aid";
|
||||
$row = Db::name('archives')
|
||||
->field($fields)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
|
||||
->where('a.aid', 'in', $aids)
|
||||
->getAllWithIndex('aid');
|
||||
foreach ($list as $key => $val) {
|
||||
$list[$key] = $row[$val['aid']];
|
||||
}
|
||||
}
|
||||
$show = $Page->show(); // 分页显示输出
|
||||
$assign_data['page'] = $show; // 赋值分页输出
|
||||
$assign_data['list'] = $list; // 赋值数据集
|
||||
$assign_data['pager'] = $Page; // 赋值分页对象
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$allow_release_channel = !empty($channels) ? explode(',', $channels) : config('global.allow_release_channel');
|
||||
$key_tmp = array_search('7', $allow_release_channel);
|
||||
if (is_numeric($key_tmp) && 0 <= $key_tmp) {
|
||||
unset($allow_release_channel[$key_tmp]);
|
||||
}
|
||||
$assign_data['arctype_html'] = allow_release_arctype($typeid, $allow_release_channel);
|
||||
/*--end*/
|
||||
|
||||
$this->assign($assign_data);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
276
src/application/admin/controller/Statistics.php
Normal file
276
src/application/admin/controller/Statistics.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 易而优团队 by 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-11-21
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
// 数据统计
|
||||
class Statistics extends Base {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据表列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// 近七日成交量成交额折线图数据
|
||||
$LineChartData = $this->GetLineChartData();
|
||||
$this->assign('DealNum', $LineChartData['DealNum']);
|
||||
$this->assign('DealAmount', $LineChartData['DealAmount']);
|
||||
|
||||
// 起始时间
|
||||
$StartTime = $this->GetTime(6);
|
||||
$EndTime = getTime();
|
||||
$this->assign('StartTime', $StartTime);
|
||||
$this->assign('EndTime', $EndTime);
|
||||
// 数据统计
|
||||
$CycletData = $this->GetTimeCycletData($StartTime, $EndTime);
|
||||
$this->assign('CycletData', $CycletData);
|
||||
|
||||
// 商品销售榜
|
||||
$OrderSalesList = $this->GetOrderSalesList();
|
||||
$this->assign('OrderSalesList', $OrderSalesList);
|
||||
|
||||
// 用户消费榜
|
||||
$UserConsumption = $this->GetUserConsumption();
|
||||
$this->assign('UserConsumption', $UserConsumption);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 用户消费榜
|
||||
private function GetUserConsumption()
|
||||
{
|
||||
$where = [
|
||||
'order_status' => ['IN', [1, 2, 3]]
|
||||
];
|
||||
$Return = Db::name('shop_order')->field('users_id, sum(order_total_amount+shipping_fee) as amount')->where($where)->group('users_id')->select();
|
||||
$users_id = get_arr_column($Return, 'users_id');
|
||||
$Return = convert_arr_key($Return, 'users_id');
|
||||
|
||||
$UsersData = Db::name('users')->field('users_id, username, nickname')->select();
|
||||
foreach ($UsersData as $key => $value) {
|
||||
$UsersData[$key]['amount'] = !empty($Return[$value['users_id']]['amount']) ? $Return[$value['users_id']]['amount'] : 0;
|
||||
$UsersData[$key]['nickname'] = !empty($UsersData[$key]['nickname']) ? $UsersData[$key]['nickname'] : $UsersData[$key]['username'];
|
||||
}
|
||||
|
||||
// 以消费金额排序
|
||||
array_multisort(get_arr_column($UsersData, 'amount'), SORT_DESC, $UsersData);
|
||||
// 读取前十数据
|
||||
$UsersData = array_slice($UsersData, 0, 10);
|
||||
|
||||
return $UsersData;
|
||||
}
|
||||
|
||||
// 商品销售榜
|
||||
private function GetOrderSalesList()
|
||||
{
|
||||
$Return = Db::name('archives')
|
||||
->field('aid, title, sales_num')
|
||||
->order('sales_num desc')
|
||||
->limit('0, 10')
|
||||
->where('channel', 2)
|
||||
->select();
|
||||
$aid = get_arr_column($Return, 'aid');
|
||||
|
||||
$where = [
|
||||
'a.product_id' => ['IN', $aid],
|
||||
'b.order_status' => ['IN', [1, 2, 3]],
|
||||
];
|
||||
$Price = Db::name('shop_order_details')->alias('a')
|
||||
->field('a.product_id, sum(a.product_price*a.num) as price, count(a.details_id) as sales_num')
|
||||
->join('__SHOP_ORDER__ b', 'a.order_id = b.order_id', 'LEFT')
|
||||
->where($where)
|
||||
->group('product_id')
|
||||
->select();
|
||||
$Price = convert_arr_key($Price, 'product_id');
|
||||
$array_new = get_archives_data($Return, 'aid');
|
||||
$Return = convert_arr_key($Return, 'aid');
|
||||
|
||||
foreach ($Return as $key => $value) {
|
||||
$Return[$key]['sales_amount'] = !empty($Price[$value['aid']]['price']) ? $Price[$value['aid']]['price'] : 0;
|
||||
$Return[$key]['title'] = @msubstr($value['title'], 0, 25, '...');
|
||||
$Return[$key]['arcurl'] = get_arcurl($array_new[$value['aid']]);
|
||||
$Return[$key]['sales_num'] = !empty($Price[$value['aid']]['sales_num']) ? $Price[$value['aid']]['sales_num'] : 0;
|
||||
}
|
||||
return $Return;
|
||||
}
|
||||
|
||||
// 获取时间周期内的指定数据
|
||||
public function GetTimeCycletData($Start = null, $End = null)
|
||||
{
|
||||
$param = input('param.');
|
||||
if (0 != $param['Year']) {
|
||||
$param['Start'] = strtotime("-0 year -{$param['Year']} month -0 day");
|
||||
$param['End'] = getTime();
|
||||
} else {
|
||||
if (empty($Start) || empty($End)) {
|
||||
$param['Start'] = strtotime($param['StartNew']);
|
||||
$param['End'] = strtotime($param['EndNew']);
|
||||
} else {
|
||||
$param = [
|
||||
'Start' => $Start,
|
||||
'End' => $End,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 会员查询条件
|
||||
$Uwhere = [
|
||||
'reg_time' => ['between', [$param['Start'], $param['End']]]
|
||||
];
|
||||
|
||||
// 商品查询条件
|
||||
$Awhere = [
|
||||
'channel' => 2,
|
||||
'add_time' => ['between', [$param['Start'], $param['End']]]
|
||||
];
|
||||
|
||||
// 商品查询条件
|
||||
$Swhere = [
|
||||
'add_time' => ['between', [$param['Start'], $param['End']]]
|
||||
];
|
||||
|
||||
// 订单查询条件
|
||||
$Owhere = [
|
||||
'order_status' => ['IN', [1, 2, 3]],
|
||||
'add_time' => ['between', [$param['Start'], $param['End']]]
|
||||
];
|
||||
// 查询订单数据
|
||||
$Result = $this->GetTimeWhereData($Owhere);
|
||||
|
||||
// 充值查询条件
|
||||
$Mwhere = [
|
||||
'cause' => Config::get('global.pay_cause_type_arr')[1],
|
||||
'cause_type' => 1,
|
||||
'status' => 3,
|
||||
'add_time' => ['between', [$param['Start'], $param['End']]]
|
||||
];
|
||||
|
||||
$Return = [
|
||||
// 会员人数
|
||||
'UsersNum' => Db::name('users')->where($Uwhere)->count(),
|
||||
// 付款订单数
|
||||
'PayOrderNum' => $Result['deal_num'],
|
||||
// 订单销售额
|
||||
'OrderSales' => $Result['deal_amount'],
|
||||
// 商品数
|
||||
'ProductNum' => Db::name('archives')->where($Awhere)->count(),
|
||||
// 消费人数
|
||||
'OrderUsersNum' => Db::name('shop_order')->where($Swhere)->group('users_id')->count(),
|
||||
// 充值金额
|
||||
'UsersRecharge' => Db::name('users_money')->where($Mwhere)->sum('money'),
|
||||
// 返回查询时间
|
||||
'Start' => date("Y-m-d H:i:s", $param['Start']),
|
||||
'End' => date("Y-m-d H:i:s", $param['End'])
|
||||
];
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$this->success('查询成功!', null, $Return);
|
||||
} else {
|
||||
return $Return;
|
||||
}
|
||||
}
|
||||
|
||||
// 近七日成交量成交额折线图数据
|
||||
private function GetLineChartData()
|
||||
{
|
||||
/*七日内每日起始结束时间戳*/
|
||||
$Time = [
|
||||
// 当天
|
||||
'ToDaysStart' => strtotime(date("Y-m-d"),time()),
|
||||
'ToDaysEnd' => getTime(),
|
||||
// 昨天
|
||||
'YesterDaysStart' => $this->GetTime(1),
|
||||
'YesterDaysEnd' => $this->GetTime(1) + 86399,
|
||||
// 前天
|
||||
'AgoDaysStart' => $this->GetTime(2),
|
||||
'AgoDaysEnd' => $this->GetTime(2) + 86399,
|
||||
// 三天前
|
||||
'ThreeDaysAgoStart' => $this->GetTime(3),
|
||||
'ThreeDaysAgoEnd' => $this->GetTime(3) + 86399,
|
||||
// 四天前
|
||||
'FourDaysAgoStart' => $this->GetTime(4),
|
||||
'FourDaysAgoEnd' => $this->GetTime(4) + 86399,
|
||||
// 五天前
|
||||
'FiveDaysAgoStart' => $this->GetTime(5),
|
||||
'FiveDaysAgoEnd' => $this->GetTime(5) + 86399,
|
||||
// 六天前
|
||||
'SixDaysAgoStart' => $this->GetTime(6),
|
||||
'SixDaysAgoEnd' => $this->GetTime(6) + 86399,
|
||||
];
|
||||
/* END */
|
||||
|
||||
$where['order_status'] = ['IN', [1, 2, 3]];
|
||||
// 六天前
|
||||
$where['add_time'] = ['between', [$Time['SixDaysAgoStart'], $Time['SixDaysAgoEnd']]];
|
||||
$Six = $this->GetTimeWhereData($where);
|
||||
$Six['deal_amount'] = !empty($Six['deal_amount']) ? $Six['deal_amount'] : 0;
|
||||
// 五天前
|
||||
$where['add_time'] = ['between', [$Time['FiveDaysAgoStart'], $Time['FiveDaysAgoEnd']]];
|
||||
$Five = $this->GetTimeWhereData($where);
|
||||
$Five['deal_amount'] = !empty($Five['deal_amount']) ? $Five['deal_amount'] : 0;
|
||||
// 四天前
|
||||
$where['add_time'] = ['between', [$Time['FourDaysAgoStart'], $Time['FourDaysAgoEnd']]];
|
||||
$Four = $this->GetTimeWhereData($where);
|
||||
$Four['deal_amount'] = !empty($Four['deal_amount']) ? $Four['deal_amount'] : 0;
|
||||
// 三天前
|
||||
$where['add_time'] = ['between', [$Time['ThreeDaysAgoStart'], $Time['ThreeDaysAgoEnd']]];
|
||||
$Three = $this->GetTimeWhereData($where);
|
||||
$Three['deal_amount'] = !empty($Three['deal_amount']) ? $Three['deal_amount'] : 0;
|
||||
// 前天
|
||||
$where['add_time'] = ['between', [$Time['AgoDaysStart'], $Time['AgoDaysEnd']]];
|
||||
$Ago = $this->GetTimeWhereData($where);
|
||||
$Ago['deal_amount'] = !empty($Ago['deal_amount']) ? $Ago['deal_amount'] : 0;
|
||||
// 昨天
|
||||
$where['add_time'] = ['between', [$Time['YesterDaysStart'], $Time['YesterDaysEnd']]];
|
||||
$Yester = $this->GetTimeWhereData($where);
|
||||
$Yester['deal_amount'] = !empty($Yester['deal_amount']) ? $Yester['deal_amount'] : 0;
|
||||
// 当天
|
||||
$where['add_time'] = ['between', [$Time['ToDaysStart'], $Time['ToDaysEnd']]];
|
||||
$ToDays = $this->GetTimeWhereData($where);
|
||||
$ToDays['deal_amount'] = !empty($ToDays['deal_amount']) ? $ToDays['deal_amount'] : 0;
|
||||
|
||||
$Return = [
|
||||
'DealAmount' => [$Six['deal_amount'], $Five['deal_amount'], $Four['deal_amount'], $Three['deal_amount'], $Ago['deal_amount'], $Yester['deal_amount'], $ToDays['deal_amount']],
|
||||
|
||||
'DealNum' => [$Six['deal_num'], $Five['deal_num'], $Four['deal_num'], $Three['deal_num'], $Ago['deal_num'], $Yester['deal_num'], $ToDays['deal_num']]
|
||||
];
|
||||
|
||||
return $Return;
|
||||
}
|
||||
|
||||
// 获取指定日期下的数据
|
||||
private function GetTimeWhereData($where = [])
|
||||
{
|
||||
$field = 'sum(order_total_amount+shipping_fee) as deal_amount, count(users_id) as deal_num';
|
||||
$Return = Db::name('shop_order')->field($field)->where($where)->select();
|
||||
|
||||
$Return[0]['deal_amount'] = $Return[0]['deal_amount'] ? $Return[0]['deal_amount'] : 0;
|
||||
$Return[0]['deal_num'] = $Return[0]['deal_num'] ? $Return[0]['deal_num'] : 0;
|
||||
return $Return[0];
|
||||
}
|
||||
|
||||
// 获取指定日期时间戳
|
||||
private function GetTime($num = null)
|
||||
{
|
||||
$time = strtotime(date("Y-m-d", strtotime("-{$num} day")));
|
||||
return $time;
|
||||
}
|
||||
|
||||
}
|
||||
1557
src/application/admin/controller/System.php
Normal file
1557
src/application/admin/controller/System.php
Normal file
File diff suppressed because it is too large
Load Diff
346
src/application/admin/controller/Tags.php
Normal file
346
src/application/admin/controller/Tags.php
Normal file
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Page;
|
||||
|
||||
class Tags extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$list = array();
|
||||
$keywords = input('keywords/s');
|
||||
$condition = array();
|
||||
if (!empty($keywords)) {
|
||||
$condition['tag'] = array('LIKE', "%{$keywords}%");
|
||||
}
|
||||
// 多语言
|
||||
$condition['lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$tagsM = M('tagindex');
|
||||
|
||||
// 查询分页
|
||||
$count = $tagsM->where($condition)->count('id');
|
||||
$Page = $pager = new Page($count, config('paginate.list_rows'));
|
||||
$show = $Page->show();
|
||||
$this->assign('page', $show);
|
||||
$this->assign('pager', $pager);
|
||||
|
||||
// 查询ID数组,用于纠正本页TAG文档书
|
||||
$IndexID = $tagsM->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->column('id');
|
||||
|
||||
// 纠正tags标签的文档数
|
||||
$this->correct($IndexID);
|
||||
|
||||
// 查询TAG数据
|
||||
$list = $tagsM->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
$this->assign('list', $list);
|
||||
|
||||
$source = input('param.source/s');
|
||||
$this->assign('source', $source);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function tag_list()
|
||||
{
|
||||
// 多语言
|
||||
$condition['lang'] = array('eq', $this->admin_lang);
|
||||
|
||||
$tagsM = M('tagindex');
|
||||
|
||||
// 查询分页
|
||||
$count = $tagsM->where($condition)->count('id');
|
||||
$Page = $pager = new Page($count, 100);
|
||||
$show = $Page->show();
|
||||
$this->assign('page', $show);
|
||||
$this->assign('pager', $pager);
|
||||
|
||||
// 查询ID数组,用于纠正本页TAG文档书
|
||||
$IndexID = $tagsM->where($condition)->order($order)->limit($Page->firstRow.','.$Page->listRows)->column('id');
|
||||
|
||||
// 纠正tags标签的文档数
|
||||
$this->correct($IndexID);
|
||||
|
||||
// 查询TAG数据
|
||||
$order = 'total desc, id desc, monthcc desc, weekcc desc';
|
||||
$list = $tagsM->where($condition)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
|
||||
|
||||
$this->assign('list', $list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
if (!empty($post['id'])) {
|
||||
$tag = !empty($post['tag_tag']) ? trim($post['tag_tag']) : '';
|
||||
if (empty($tag)) {
|
||||
$this->error('标签名称不能为空!');
|
||||
} else {
|
||||
$row = Db::name('tagindex')->where([
|
||||
'tag' => $tag,
|
||||
'id' => ['NEQ', $post['id']],
|
||||
'lang' => $this->admin_lang,
|
||||
])->find();
|
||||
if (!empty($row)) {
|
||||
$this->error('标签名称已存在,请更改!');
|
||||
}
|
||||
}
|
||||
$updata = [
|
||||
'tag' => $tag,
|
||||
'seo_title' => !empty($post['tag_seo_title']) ? trim($post['tag_seo_title']) : '',
|
||||
'seo_keywords' => !empty($post['tag_seo_keywords']) ? trim($post['tag_seo_keywords']) : '',
|
||||
'seo_description' => !empty($post['tag_seo_description']) ? trim($post['tag_seo_description']) : '',
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
$ResultID = Db::name('tagindex')->where('id', $post['id'])->update($updata);
|
||||
if (false !== $ResultID) {
|
||||
if (trim($post['tag_tag']) != trim($post['tag_tagold'])) {
|
||||
Db::name('taglist')->where([
|
||||
'tid' => $post['id'],
|
||||
])->update([
|
||||
'tag' => trim($post['tag_tag']),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
$id = input('id/d');
|
||||
if (empty($id)) $this->error('操作异常');
|
||||
|
||||
$Result = Db::name('tagindex')->where('id', $id)->find();
|
||||
if (empty($Result)) $this->error('操作异常');
|
||||
$this->assign('tag', $Result);
|
||||
|
||||
$this->assign('backurl', url('Tags/index'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
$result = M('tagindex')->field('tag')
|
||||
->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])->select();
|
||||
$title_list = get_arr_column($result, 'tag');
|
||||
|
||||
$r = M('tagindex')->where([
|
||||
'id' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])->delete();
|
||||
if($r){
|
||||
M('taglist')->where([
|
||||
'tid' => ['IN', $id_arr],
|
||||
'lang' => $this->admin_lang,
|
||||
])->delete();
|
||||
adminLog('删除Tags标签:'.implode(',', $title_list));
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
$this->error('非法访问');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空
|
||||
*/
|
||||
public function clearall()
|
||||
{
|
||||
$r = M('tagindex')->where([
|
||||
'lang' => $this->admin_lang,
|
||||
])->delete();
|
||||
if(false !== $r){
|
||||
M('taglist')->where([
|
||||
'lang' => $this->admin_lang,
|
||||
])->delete();
|
||||
adminLog('清空Tags标签');
|
||||
$this->success('操作成功');
|
||||
}else{
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 纠正tags文档数
|
||||
*/
|
||||
private function correct($IndexID = [])
|
||||
{
|
||||
$where = [
|
||||
'tid' => ['IN', $IndexID],
|
||||
'lang' => $this->admin_lang
|
||||
];
|
||||
$taglistRow = Db::name('taglist')->field('count(tid) as total, tid, add_time')
|
||||
->where($where)
|
||||
->group('tid')
|
||||
->getAllWithIndex('tid');
|
||||
$updateData = [];
|
||||
$weekup = getTime();
|
||||
foreach ($taglistRow as $key => $val) {
|
||||
$updateData[] = [
|
||||
'id' => $val['tid'],
|
||||
'total' => $val['total'],
|
||||
'weekup' => $weekup,
|
||||
'add_time' => $val['add_time'] + 1,
|
||||
];
|
||||
}
|
||||
if (!empty($updateData)) {
|
||||
$r = model('Tagindex')->saveAll($updateData);
|
||||
if (false !== $r) {
|
||||
// Db::name('tagindex')->where(['weekup'=>['lt', $weekup],'lang'=>$this->admin_lang])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取常用标签列表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function get_common_list()
|
||||
{
|
||||
if (IS_AJAX) {
|
||||
$tags = input('tags/s');
|
||||
$type = input('type/d');
|
||||
if (!empty($tags)){
|
||||
$tagsArr = explode(',',$tags);
|
||||
$tags = trim(end($tagsArr));
|
||||
}
|
||||
|
||||
/*发布最新文档的tag里前3个*/
|
||||
$newTagList = [];
|
||||
$newtids = [];
|
||||
if (empty($tags)){
|
||||
$taglistRow = Db::name('taglist')->field('tid,tag')->order('aid desc')->limit(20)->select();
|
||||
foreach ($taglistRow as $key => $val) {
|
||||
if (3 <= count($newTagList)) {
|
||||
break;
|
||||
}
|
||||
if (in_array($val['tid'], $newtids)) {
|
||||
continue;
|
||||
}
|
||||
array_push($newTagList, $val);
|
||||
array_push($newtids, $val['tid']);
|
||||
}
|
||||
}
|
||||
$list = $newTagList;
|
||||
/*end*/
|
||||
|
||||
/*常用标签*/
|
||||
$where = [];
|
||||
$where['is_common'] = 1;
|
||||
!empty($newtids) && $where['id'] = ['NOTIN', $newtids];
|
||||
$where['lang'] = $this->admin_lang;
|
||||
if (!empty($tags)){
|
||||
$where['tag'] = ['like','%'.$tags."%"];
|
||||
}
|
||||
$num = 20 - count($list);
|
||||
$row = Db::name('tagindex')->field('id as tid,tag')->where($where)
|
||||
->order('total desc, id desc')
|
||||
->limit($num)
|
||||
->select();
|
||||
if (is_array($list) && is_array($row)) {
|
||||
$list = array_merge($list, $row);
|
||||
}
|
||||
/*end*/
|
||||
|
||||
// 不够数量进行补充
|
||||
$surplusNum = $num - count($list);
|
||||
if (0 < $surplusNum) {
|
||||
$ids = get_arr_column($list, 'tid');
|
||||
$condition['lang'] = $this->admin_lang;
|
||||
$condition['id'] = ['NOT IN', $ids];
|
||||
if (!empty($tags)){
|
||||
$condition['tag'] = ['like','%'.$tags."%"];
|
||||
}
|
||||
$row2 = Db::name('tagindex')->field('id as tid,tag')->where($condition)
|
||||
->order('total desc, id desc')
|
||||
->limit($surplusNum)
|
||||
->select();
|
||||
if (is_array($list) && is_array($row2)) {
|
||||
$list = array_merge($list, $row2);
|
||||
}
|
||||
}
|
||||
/*end*/
|
||||
|
||||
$html = "";
|
||||
$data = [];
|
||||
if (!empty($list)) {
|
||||
$tags = input('param.tags/s');
|
||||
$tags = str_replace(',', ',', $tags);
|
||||
$tagArr = explode(',', $tags);
|
||||
foreach ($tagArr as $key => $val) {
|
||||
$tagArr[$key] = trim($val);
|
||||
}
|
||||
|
||||
foreach ($list as $_k1 => $_v1) {
|
||||
if (!empty($type)){
|
||||
if (in_array($_v1['tag'], $tagArr)) {
|
||||
$html .= "<a class='cur' href='javascript:void(0);' onclick='selectArchivesTagInput(this);'>{$_v1['tag']}</a>";
|
||||
} else {
|
||||
$html .= "<a href='javascript:void(0);' onclick='selectArchivesTagInput(this);'>{$_v1['tag']}</a>";
|
||||
}
|
||||
}else{
|
||||
if (in_array($_v1['tag'], $tagArr)) {
|
||||
$html .= "<a class='cur' href='javascript:void(0);' onclick='selectArchivesTag(this);'>{$_v1['tag']}</a>";
|
||||
} else {
|
||||
$html .= "<a href='javascript:void(0);' onclick='selectArchivesTag(this);'>{$_v1['tag']}</a>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$is_click = input('param.is_click/d');
|
||||
if (!empty($is_click)) {
|
||||
if (empty($html)) {
|
||||
$html .= "没有找到记录";
|
||||
}
|
||||
$html .= "<a href='javascript:void(0);' onclick='tags_list_1610411887(this);' style='float: right;'>[设置]</a>";
|
||||
}
|
||||
$data['html'] = $html;
|
||||
|
||||
if (!empty($type) && empty($tags)){
|
||||
$data = [];
|
||||
}
|
||||
|
||||
$this->success('请求成功', null, $data);
|
||||
}
|
||||
$this->error('请求失败');
|
||||
}
|
||||
|
||||
// 批量新增
|
||||
public function batch_add()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
522
src/application/admin/controller/Tools.php
Normal file
522
src/application/admin/controller/Tools.php
Normal file
@@ -0,0 +1,522 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Db;
|
||||
use think\Backup;
|
||||
|
||||
class Tools extends Base {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->language_access(); // 多语言功能操作权限
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据表列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$dbtables = Db::query('SHOW TABLE STATUS');
|
||||
$total = 0;
|
||||
$list = array();
|
||||
foreach ($dbtables as $k => $v) {
|
||||
if (preg_match('/^'.PREFIX.'/i', $v['Name'])) {
|
||||
$v['size'] = format_bytes($v['Data_length'] + $v['Index_length']);
|
||||
$list[$k] = $v;
|
||||
$total += $v['Data_length'] + $v['Index_length'];
|
||||
}
|
||||
}
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
if (file_exists(realpath(trim($path, '/')) . DS . 'backup.lock')) {
|
||||
@unlink(realpath(trim($path, '/')) . DS . 'backup.lock');
|
||||
}
|
||||
// if (session('?backup_config.path')) {
|
||||
//备份完成,清空缓存
|
||||
session('backup_tables', null);
|
||||
session('backup_file', null);
|
||||
session('backup_config', null);
|
||||
// }
|
||||
$this->assign('list', $list);
|
||||
$this->assign('total', format_bytes($total));
|
||||
$this->assign('tableNum', count($list));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据备份
|
||||
*/
|
||||
public function export($tables = null, $id = null, $start = null,$optstep = 0)
|
||||
{
|
||||
//防止备份数据过程超时
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
@ini_set('memory_limit','-1');
|
||||
|
||||
/*升级完自动备份所有数据表*/
|
||||
if ('all' == $tables) {
|
||||
$dbtables = Db::query('SHOW TABLE STATUS');
|
||||
$list = array();
|
||||
foreach ($dbtables as $k => $v) {
|
||||
if (preg_match('/^'.PREFIX.'/i', $v['Name'])) {
|
||||
$list[] = $v['Name'];
|
||||
}
|
||||
}
|
||||
$tables = $list;
|
||||
unlink(session('backup_config.path') . 'backup.lock');
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if(IS_POST && !empty($tables) && is_array($tables) && empty($optstep)){ //初始化
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
if(!empty($path) && !is_dir($path)){
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
|
||||
//读取备份配置
|
||||
$config = array(
|
||||
'path' => realpath($path) . DS,
|
||||
'part' => config('DATA_BACKUP_PART_SIZE'),
|
||||
'compress' => config('DATA_BACKUP_COMPRESS'),
|
||||
'level' => config('DATA_BACKUP_COMPRESS_LEVEL'),
|
||||
);
|
||||
//检查是否有正在执行的任务
|
||||
$lock = "{$config['path']}backup.lock";
|
||||
if(is_file($lock)){
|
||||
return json(array('msg'=>'检测到有一个备份任务正在执行,请稍后再试!', 'code'=>0, 'url'=>''));
|
||||
} else {
|
||||
//创建锁文件
|
||||
file_put_contents($lock, $_SERVER['REQUEST_TIME']);
|
||||
}
|
||||
|
||||
//检查备份目录是否可写
|
||||
if(!is_writeable($config['path'])){
|
||||
return json(array('msg'=>'备份目录不存在或不可写,请检查后重试!', 'code'=>0, 'url'=>''));
|
||||
}
|
||||
session('backup_config', $config);
|
||||
|
||||
//生成备份文件信息
|
||||
$file = array(
|
||||
'name' => date('Ymd-His', $_SERVER['REQUEST_TIME']),
|
||||
'part' => 1,
|
||||
'version' => getCmsVersion(),
|
||||
);
|
||||
session('backup_file', $file);
|
||||
//缓存要备份的表
|
||||
session('backup_tables', $tables);
|
||||
//创建备份文件
|
||||
$Database = new Backup($file, $config);
|
||||
if(false !== $Database->create()){
|
||||
$speed = (floor((1/count($tables))*10000)/10000*100);
|
||||
$speed = sprintf("%.2f", $speed);
|
||||
$tab = array('id' => 0, 'start' => 0, 'speed'=>$speed, 'table'=>$tables[0], 'optstep'=>1);
|
||||
return json(array('tables' => $tables, 'tab' => $tab, 'msg'=>'初始化成功!', 'code'=>1, 'url'=>''));
|
||||
} else {
|
||||
return json(array('msg'=>'初始化失败,备份文件创建失败!', 'code'=>0, 'url'=>''));
|
||||
}
|
||||
} elseif (IS_POST && is_numeric($id) && is_numeric($start) && 1 == intval($optstep)) { //备份数据
|
||||
$tables = session('backup_tables');
|
||||
//备份指定表
|
||||
$Database = new Backup(session('backup_file'), session('backup_config'));
|
||||
$start = $Database->backup($tables[$id], $start);
|
||||
if(false === $start){ //出错
|
||||
return json(array('msg'=>'备份出错!', 'code'=>0, 'url'=>''));
|
||||
} elseif (0 === $start) { //下一表
|
||||
if(isset($tables[++$id])){
|
||||
$speed = (floor((($id+1)/count($tables))*10000)/10000*100);
|
||||
$speed = sprintf("%.2f", $speed);
|
||||
$tab = array('id' => $id, 'start' => 0, 'speed' => $speed, 'table'=>$tables[$id], 'optstep'=>1);
|
||||
return json(array('tab' => $tab, 'msg'=>'备份完成!', 'code'=>1, 'url'=>''));
|
||||
} else { //备份完成,清空缓存
|
||||
/*自动覆盖安装目录下的eyoucms.sql*/
|
||||
$install_time = DEFAULT_INSTALL_DATE;
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('INSTALL_DATE') && $install_time = INSTALL_DATE;
|
||||
}
|
||||
$install_path = ROOT_PATH.'install';
|
||||
if (!is_dir($install_path) || !file_exists($install_path)) {
|
||||
$install_path = ROOT_PATH.'install_'.$install_time;
|
||||
}
|
||||
if (is_dir($install_path) && file_exists($install_path)) {
|
||||
$srcfile = session('backup_config.path').session('backup_file.name').'-'.session('backup_file.part').'-'.session('backup_file.version').'.sql';
|
||||
$dstfile = $install_path.'/eyoucms.sql';
|
||||
if(@copy($srcfile, $dstfile)){
|
||||
/*替换所有表的前缀为官方默认ey_,并重写安装数据包里*/
|
||||
$eyouDbStr = file_get_contents($dstfile);
|
||||
$dbtables = Db::query('SHOW TABLE STATUS');
|
||||
$tableName = $eyTableName = [];
|
||||
foreach ($dbtables as $k => $v) {
|
||||
if (preg_match('/^'.PREFIX.'/i', $v['Name'])) {
|
||||
$tableName[] = "`{$v['Name']}`";
|
||||
$eyTableName[] = preg_replace('/^`'.PREFIX.'/i', '`ey_', "`{$v['Name']}`");
|
||||
}
|
||||
}
|
||||
$eyouDbStr = str_replace($tableName, $eyTableName, $eyouDbStr);
|
||||
@file_put_contents($dstfile, $eyouDbStr);
|
||||
unset($eyouDbStr);
|
||||
/*--end*/
|
||||
} else {
|
||||
@unlink($dstfile); // 复制失败就删掉,避免安装错误的数据包
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
unlink(session('backup_config.path') . 'backup.lock');
|
||||
session('backup_tables', null);
|
||||
session('backup_file', null);
|
||||
session('backup_config', null);
|
||||
return json(array('msg'=>'备份完成!', 'code'=>1, 'url'=>''));
|
||||
}
|
||||
} else {
|
||||
$rate = floor(100 * ($start[0] / $start[1]));
|
||||
$speed = floor((($id+1)/count($tables))*10000)/10000*100 + ($rate/100);
|
||||
$speed = sprintf("%.2f", $speed);
|
||||
$tab = array('id' => $id, 'start' => $start[0], 'speed' => $speed, 'table'=>$tables[$id], 'optstep'=>1);
|
||||
return json(array('tab' => $tab, 'msg'=>"正在备份...({$rate}%)", 'code'=>1, 'url'=>''));
|
||||
}
|
||||
|
||||
} else {//出错
|
||||
return json(array('msg'=>'参数有误', 'tab'=>['speed'=>-1], 'code'=>0, 'url'=>''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化
|
||||
*/
|
||||
public function optimize()
|
||||
{
|
||||
$batchFlag = input('get.batchFlag', 0, 'intval');
|
||||
//批量删除
|
||||
if ($batchFlag) {
|
||||
$table = input('key', array());
|
||||
}else {
|
||||
$table[] = input('tablename' , '');
|
||||
}
|
||||
|
||||
if (empty($table)) {
|
||||
$this->error('请选择数据表');
|
||||
}
|
||||
|
||||
$strTable = implode(',', $table);
|
||||
if (!DB::query("OPTIMIZE TABLE {$strTable} ")) {
|
||||
$strTable = '';
|
||||
}
|
||||
$this->success("操作成功" . $strTable, url('Tools/index'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复
|
||||
*/
|
||||
public function repair()
|
||||
{
|
||||
$batchFlag = input('get.batchFlag', 0, 'intval');
|
||||
//批量删除
|
||||
if ($batchFlag) {
|
||||
$table = input('key', array());
|
||||
}else {
|
||||
$table[] = input('tablename' , '');
|
||||
}
|
||||
|
||||
if (empty($table)) {
|
||||
$this->error('请选择数据表');
|
||||
}
|
||||
|
||||
$strTable = implode(',', $table);
|
||||
if (!DB::query("REPAIR TABLE {$strTable} ")) {
|
||||
$strTable = '';
|
||||
}
|
||||
|
||||
$this->success("操作成功" . $strTable, url('Tools/index'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据还原
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
if(!empty($path) && !is_dir($path)){
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
$path = realpath($path);
|
||||
$flag = \FilesystemIterator::KEY_AS_FILENAME;
|
||||
$glob = new \FilesystemIterator($path, $flag);
|
||||
$list = array();
|
||||
$filenum = $total = 0;
|
||||
foreach ($glob as $name => $file) {
|
||||
if(preg_match('/^\d{8,8}-\d{6,6}-\d+-v\d+\.\d+\.\d+(.*)\.sql(?:\.gz)?$/', $name)){
|
||||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d-%s');
|
||||
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
|
||||
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
|
||||
$part = $name[6];
|
||||
$version = preg_replace('#\.sql(.*)#i', '', $name[7]);
|
||||
$info = pathinfo($file);
|
||||
if(isset($list["{$date} {$time}"])){
|
||||
$info = $list["{$date} {$time}"];
|
||||
$info['part'] = max($info['part'], $part);
|
||||
$info['size'] = $info['size'] + $file->getSize();
|
||||
} else {
|
||||
$info['part'] = $part;
|
||||
$info['size'] = $file->getSize();
|
||||
}
|
||||
$info['compress'] = ($info['extension'] === 'sql') ? '-' : $info['extension'];
|
||||
$info['time'] = strtotime("{$date} {$time}");
|
||||
$info['version'] = $version;
|
||||
$filenum++;
|
||||
$total += $info['size'];
|
||||
$list["{$date} {$time}"] = $info;
|
||||
}
|
||||
}
|
||||
array_multisort($list, SORT_DESC);
|
||||
$this->assign('list', $list);
|
||||
$this->assign('filenum',$filenum);
|
||||
$this->assign('total',$total);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传sql文件
|
||||
*/
|
||||
public function restoreUpload()
|
||||
{
|
||||
$this->error('该功能仅限技术人员使用!');
|
||||
|
||||
$file = request()->file('sqlfile');
|
||||
if(empty($file)){
|
||||
$this->error('请上传sql文件');
|
||||
}
|
||||
// 移动到框架应用根目录/data/sqldata/ 目录下
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$image_upload_limit_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
$info = $file->validate(['size'=>$image_upload_limit_size,'ext'=>'sql,gz'])->move($path, $_FILES['sqlfile']['name']);
|
||||
if ($info) {
|
||||
//上传成功 获取上传文件信息
|
||||
$file_path_full = $info->getPathName();
|
||||
if (file_exists($file_path_full)) {
|
||||
$sqls = Backup::parseSql($file_path_full);
|
||||
if(Backup::install($sqls)){
|
||||
/*清除缓存*/
|
||||
delFile(RUNTIME_PATH);
|
||||
/*--end*/
|
||||
$this->success("执行sql成功", url('Tools/restore'));
|
||||
}else{
|
||||
$this->error('执行sql失败');
|
||||
}
|
||||
} else {
|
||||
$this->error('sql文件上传失败');
|
||||
}
|
||||
} else {
|
||||
//上传错误提示错误信息
|
||||
$this->error($file->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行还原数据库操作
|
||||
* @param int $time
|
||||
* @param null $part
|
||||
* @param null $start
|
||||
*/
|
||||
public function import($time = 0, $part = null, $start = null)
|
||||
{
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
if(is_numeric($time) && is_null($part) && is_null($start)){ //初始化
|
||||
//获取备份文件信息
|
||||
$name = date('Ymd-His', $time) . '-*.sql*';
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$path = realpath($path) . DS . $name;
|
||||
$files = glob($path);
|
||||
$list = array();
|
||||
foreach($files as $name){
|
||||
$basename = basename($name);
|
||||
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d');
|
||||
$gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename);
|
||||
$list[$match[6]] = array($match[6], $name, $gz);
|
||||
}
|
||||
ksort($list);
|
||||
|
||||
//检测文件正确性
|
||||
$last = end($list);
|
||||
if(count($list) === $last[0]){
|
||||
session('backup_list', $list); //缓存备份列表
|
||||
$part = 1;
|
||||
$start = 0;
|
||||
$data = array('part' => $part, 'start' => $start);
|
||||
// $this->success('初始化完成!', null, array('part' => $part, 'start' => $start));
|
||||
respose(array('code'=>1, 'msg'=>"初始化完成!准备还原#{$part}...", 'rate'=>'', 'data'=>$data));
|
||||
} else {
|
||||
// $this->error('备份文件可能已经损坏,请检查!');
|
||||
respose(array('code'=>0, 'msg'=>"备份文件可能已经损坏,请检查!"));
|
||||
}
|
||||
} elseif(is_numeric($part) && is_numeric($start)) {
|
||||
$list = session('backup_list');
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$db = new Backup($list[$part], array(
|
||||
'path' => realpath($path) . DS,
|
||||
'compress' => $list[$part][2]));
|
||||
$start = $db->import($start);
|
||||
if(false === $start){
|
||||
// $this->error('还原数据出错!');
|
||||
respose(array('code'=>0, 'msg'=>"还原数据出错!", 'rate'=>'0%'));
|
||||
} elseif(0 === $start) { //下一卷
|
||||
if(isset($list[++$part])){
|
||||
$data = array('part' => $part, 'start' => 0);
|
||||
// $this->success("正在还g原...#{$part}", null, $data);
|
||||
$rate = (floor((($start+1)/count($list))*10000)/10000*100).'%';
|
||||
respose(array('code'=>1, 'msg'=>"正在还原#{$part}...", 'rate'=>$rate, 'data'=>$data));
|
||||
} else {
|
||||
session('backup_list', null);
|
||||
delFile(RUNTIME_PATH);
|
||||
respose(array('code'=>1, 'msg'=>"还原完成...", 'rate'=>'100%'));
|
||||
// $this->success('还原完成!');
|
||||
}
|
||||
} else {
|
||||
$data = array('part' => $part, 'start' => $start[0]);
|
||||
if($start[1]){
|
||||
$rate = floor(100 * ($start[0] / $start[1])).'%';
|
||||
respose(array('code'=>1, 'msg'=>"正在还原#{$part}...", 'rate'=>$rate, 'data'=>$data));
|
||||
// $this->success("正在还d原...#{$part} ({$rate}%)", null, $data);
|
||||
} else {
|
||||
$data['gz'] = 1;
|
||||
respose(array('code'=>1, 'msg'=>"正在还原#{$part}...", 'data'=>$data, 'start'=>$start));
|
||||
// $this->success("正在还s原...#{$part}", null, $data);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $this->error('参数错误!');
|
||||
respose(array('code'=>0, 'msg'=>"参数有误", 'rate'=>'0%'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (新)执行还原数据库操作
|
||||
* @param int $time
|
||||
*/
|
||||
public function new_import($time = 0)
|
||||
{
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
@ini_set('memory_limit','-1');
|
||||
|
||||
if(is_numeric($time) && intval($time) > 0){
|
||||
//获取备份文件信息
|
||||
$name = date('Ymd-His', $time) . '-*.sql*';
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$path = realpath($path) . DS . $name;
|
||||
$files = glob($path);
|
||||
$list = array();
|
||||
foreach($files as $name){
|
||||
$basename = basename($name);
|
||||
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d-%s');
|
||||
$gz = preg_match('/^\d{8,8}-\d{6,6}-\d+-v\d+\.\d+\.\d+(.*)\.sql.gz$/', $basename);
|
||||
$list[$match[6]] = array($match[6], $name, $gz);
|
||||
}
|
||||
ksort($list);
|
||||
|
||||
//检测文件正确性
|
||||
$last = end($list);
|
||||
$file_path_full = !empty($last[1]) ? $last[1] : '';
|
||||
if (file_exists($file_path_full)) {
|
||||
/*校验sql文件是否属于当前CMS版本*/
|
||||
preg_match('/(\d{8,8})-(\d{6,6})-(\d+)-(v\d+\.\d+\.\d+(.*))\.sql/i', $file_path_full, $matches);
|
||||
$version = getCmsVersion();
|
||||
if ($matches[4] != $version) {
|
||||
$this->error('sql不兼容当前版本:'.$version, url('Tools/restore'));
|
||||
}
|
||||
/*--end*/
|
||||
$sqls = Backup::parseSql($file_path_full);
|
||||
if(Backup::install($sqls)){
|
||||
/*清除缓存*/
|
||||
delFile(RUNTIME_PATH);
|
||||
/*--end*/
|
||||
$this->success('操作成功', request()->baseFile(), '', 1, [], '_parent');
|
||||
}else{
|
||||
$this->error('操作失败!', url('Tools/restore'));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error("参数有误", url('Tools/restore'));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
* @param int $time
|
||||
*/
|
||||
public function downFile($time = 0)
|
||||
{
|
||||
$name = date('Ymd-His', $time) . '-*.sql*';
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$path = realpath($path) . DS . $name;
|
||||
$files = glob($path);
|
||||
if(is_array($files)){
|
||||
foreach ($files as $filePath){
|
||||
if (!file_exists($filePath)) {
|
||||
$this->error("该文件不存在,可能是被删除");
|
||||
}else{
|
||||
$filename = basename($filePath);
|
||||
header("Content-type: application/octet-stream");
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header("Content-Length: " . filesize($filePath));
|
||||
readfile($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除备份文件
|
||||
* @param Integer $time 备份时间
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$time_arr = input('del_id/a');
|
||||
$time_arr = eyIntval($time_arr);
|
||||
if(is_array($time_arr) && !empty($time_arr)){
|
||||
foreach ($time_arr as $key => $val) {
|
||||
$name = date('Ymd-His', $val) . '-*.sql*';
|
||||
$path = tpCache('global.web_sqldatapath');
|
||||
$path = !empty($path) ? $path : config('DATA_BACKUP_PATH');
|
||||
$path = trim($path, '/');
|
||||
$path = realpath($path) . DS . $name;
|
||||
array_map("unlink", glob($path));
|
||||
if(count(glob($path))){
|
||||
$this->error('备份文件删除失败,请检查目录权限!');
|
||||
}
|
||||
}
|
||||
$this->success('删除成功!');
|
||||
} else {
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
}
|
||||
841
src/application/admin/controller/Ueditor.php
Normal file
841
src/application/admin/controller/Ueditor.php
Normal file
@@ -0,0 +1,841 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use common\util\File;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* Class UeditorController
|
||||
* @package admin\Controller
|
||||
*/
|
||||
class Ueditor extends Base
|
||||
{
|
||||
private $image_type = '';
|
||||
private $sub_name = array('date', 'Ymd');
|
||||
private $imageExt = '';
|
||||
private $savePath = 'allimg/';
|
||||
private $nowFileName = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
//header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问
|
||||
//header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header
|
||||
|
||||
date_default_timezone_set("Asia/Shanghai");
|
||||
|
||||
$this->savePath = input('savepath','allimg').'/';
|
||||
|
||||
$this->nowFileName = input('nowfilename', '');
|
||||
if (empty($this->nowFileName)) {
|
||||
$this->nowFileName = md5(time().uniqid(mt_rand(), TRUE));
|
||||
}
|
||||
|
||||
error_reporting(E_ERROR | E_WARNING);
|
||||
|
||||
header("Content-Type: text/html; charset=utf-8");
|
||||
|
||||
$this->imageExt = config('global.image_ext');
|
||||
$this->image_type = tpCache('basic.image_type');
|
||||
$this->image_type = !empty($this->image_type) ? str_replace('|', ',', $this->image_type) : $this->imageExt;
|
||||
}
|
||||
|
||||
public function index(){
|
||||
|
||||
$CONFIG2 = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("./public/plugins/Ueditor/php/config.json")), true);
|
||||
$action = $_GET['action'];
|
||||
|
||||
switch ($action) {
|
||||
case 'config':
|
||||
$result = json_encode($CONFIG2);
|
||||
break;
|
||||
/* 上传图片 */
|
||||
case 'uploadimage':
|
||||
$fieldName = $CONFIG2['imageFieldName'];
|
||||
$result = $this->upFile($fieldName);
|
||||
|
||||
/*同步到第三方对象存储空间*/
|
||||
$result = json_decode($result, true);
|
||||
$bucket_data = SynImageObjectBucket($result['url']);
|
||||
$result = array_merge($result, $bucket_data);
|
||||
$result = json_encode($result);
|
||||
/*end*/
|
||||
|
||||
break;
|
||||
/* 上传涂鸦 */
|
||||
case 'uploadscrawl':
|
||||
$config = array(
|
||||
"pathFormat" => $CONFIG2['scrawlPathFormat'],
|
||||
"maxSize" => $CONFIG2['scrawlMaxSize'],
|
||||
"allowFiles" => $CONFIG2['scrawlAllowFiles'],
|
||||
"oriName" => "scrawl.png"
|
||||
);
|
||||
$fieldName = $CONFIG2['scrawlFieldName'];
|
||||
$base64 = "base64";
|
||||
$result = $this->upBase64($config,$fieldName);
|
||||
break;
|
||||
/* 上传视频 */
|
||||
case 'uploadvideo':
|
||||
$fieldName = $CONFIG2['videoFieldName'];
|
||||
$result = $this->upFile($fieldName);
|
||||
break;
|
||||
/* 上传文件 */
|
||||
case 'uploadfile':
|
||||
$fieldName = $CONFIG2['fileFieldName'];
|
||||
$result = $this->upFile($fieldName);
|
||||
break;
|
||||
/* 列出图片 */
|
||||
case 'listimage':
|
||||
$allowFiles = $CONFIG2['imageManagerAllowFiles'];
|
||||
$listSize = $CONFIG2['imageManagerListSize'];
|
||||
$path = $CONFIG2['imageManagerListPath'];
|
||||
$get =$_GET;
|
||||
$result =$this->fileList($allowFiles,$listSize,$get);
|
||||
break;
|
||||
/* 列出文件 */
|
||||
case 'listfile':
|
||||
$allowFiles = $CONFIG2['fileManagerAllowFiles'];
|
||||
$listSize = $CONFIG2['fileManagerListSize'];
|
||||
$path = $CONFIG2['fileManagerListPath'];
|
||||
$get = $_GET;
|
||||
$result = $this->fileList($allowFiles,$listSize,$get);
|
||||
break;
|
||||
/* 抓取远程文件 */
|
||||
case 'catchimage':
|
||||
$config = array(
|
||||
"pathFormat" => $CONFIG2['catcherPathFormat'],
|
||||
"maxSize" => $CONFIG2['catcherMaxSize'],
|
||||
"allowFiles" => $CONFIG2['catcherAllowFiles'],
|
||||
"oriName" => "remote.png"
|
||||
);
|
||||
$fieldName = $CONFIG2['catcherFieldName'];
|
||||
/* 抓取远程图片 */
|
||||
$list = array();
|
||||
isset($_POST[$fieldName]) ? $source = $_POST[$fieldName] : $source = $_GET[$fieldName];
|
||||
|
||||
/*编辑器七牛云/OSS等同步*/
|
||||
$weappList = Db::name('weapp')->where([
|
||||
'status' => 1,
|
||||
])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
|
||||
->getAllWithIndex('code');
|
||||
/* END */
|
||||
|
||||
foreach($source as $imgUrl){
|
||||
$info = json_decode($this->saveRemote($config,$imgUrl),true);
|
||||
|
||||
/*同步到第三方对象存储空间*/
|
||||
$bucket_data = SynImageObjectBucket($info['url'], $weappList);
|
||||
$info = array_merge($info, $bucket_data);
|
||||
/*end*/
|
||||
|
||||
array_push($list, array(
|
||||
"state" => $info["state"],
|
||||
"url" => $info["url"],
|
||||
"size" => $info["size"],
|
||||
"title" => htmlspecialchars($info["title"]),
|
||||
"original" => str_replace("&", "&", htmlspecialchars($info["original"])),
|
||||
// "source" => htmlspecialchars($imgUrl)
|
||||
"source" => str_replace("&", "&", htmlspecialchars($imgUrl))
|
||||
));
|
||||
}
|
||||
|
||||
$result = json_encode(array(
|
||||
'state' => !empty($list) ? 'SUCCESS':'ERROR',
|
||||
'list' => $list
|
||||
));
|
||||
break;
|
||||
default:
|
||||
$result = json_encode(array(
|
||||
'state' => '请求地址出错'
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
/* 输出结果 */
|
||||
if(isset($_GET["callback"])){
|
||||
if(preg_match("/^[\w_]+$/", $_GET["callback"])){
|
||||
echo htmlspecialchars($_GET["callback"]).'('.$result.')';
|
||||
}else{
|
||||
echo json_encode(array(
|
||||
'state' => 'callback参数不合法'
|
||||
));
|
||||
}
|
||||
}else{
|
||||
echo $result;
|
||||
}
|
||||
}
|
||||
|
||||
//上传文件
|
||||
private function upFile($fieldName){
|
||||
$file = request()->file($fieldName);
|
||||
if(empty($file)){
|
||||
if (!@ini_get('file_uploads')) {
|
||||
return json_encode(['state' =>'请检查空间是否开启文件上传功能!']);
|
||||
} else {
|
||||
return json_encode(['state' =>'ERROR,请上传文件']);
|
||||
}
|
||||
}
|
||||
$error = $file->getError();
|
||||
if(!empty($error)){
|
||||
return json_encode(['state' =>$error]);
|
||||
}
|
||||
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
$fileExt = '';
|
||||
$image_type = tpCache('basic.image_type');
|
||||
!empty($image_type) && $fileExt .= '|'.$image_type;
|
||||
$file_type = tpCache('basic.file_type');
|
||||
!empty($file_type) && $fileExt .= '|'.$file_type;
|
||||
$media_type = tpCache('basic.media_type');
|
||||
!empty($media_type) && $fileExt .= '|'.$media_type;
|
||||
$fileExt = !empty($fileExt) ? str_replace('||', '|', $fileExt) : config('global.image_ext');
|
||||
$fileExt = str_replace('|', ',', trim($fileExt, '|'));
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file'=>'fileSize:'.$max_file_size.'|fileExt:'.$fileExt],
|
||||
['file.fileSize' => '上传文件过大','file.fileExt'=>'上传文件后缀名必须为'.$fileExt]
|
||||
);
|
||||
if (true !== $result || empty($file)) {
|
||||
$state = "ERROR" . $result;
|
||||
return json_encode(['state' =>$state]);
|
||||
}
|
||||
|
||||
// 移动到框架应用根目录/public/uploads/ 目录下
|
||||
$this->savePath = $this->savePath.date('Ymd/');
|
||||
// 使用自定义的文件保存规则
|
||||
$info = $file->rule(function ($file) {
|
||||
return session('admin_id').'-'.dd2char(date("ymdHis").mt_rand(100,999));
|
||||
})->move(UPLOAD_PATH.$this->savePath);
|
||||
|
||||
if (!empty($info)) {
|
||||
$data = array(
|
||||
'state' => 'SUCCESS',
|
||||
'url' => '/'.UPLOAD_PATH.$this->savePath.$info->getSaveName(),
|
||||
'title' => '',//$info->getSaveName(),
|
||||
'original' => $info->getSaveName(),
|
||||
'type' => '.' . $info->getExtension(),
|
||||
'size' => $info->getSize(),
|
||||
);
|
||||
|
||||
//图片加水印
|
||||
if ($data['state'] == 'SUCCESS') {
|
||||
$file_type = $file->getInfo('type');
|
||||
$file_ext = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION);
|
||||
$fileextArr = explode(',', $this->image_type);
|
||||
if (stristr($file_type, 'image') && 'ico' != $file_ext) {
|
||||
print_water($data['url']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['url'] = ROOT_DIR.$data['url']; // 支持子目录
|
||||
} else {
|
||||
$data = array('state' => 'ERROR'.$info->getError());
|
||||
}
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//列出图片
|
||||
private function fileList($allowFiles,$listSize,$get){
|
||||
$dirname = './'.UPLOAD_PATH;
|
||||
$allowFiles = substr(str_replace(".","|",join("",$allowFiles)),1);
|
||||
/* 获取参数 */
|
||||
$size = isset($get['size']) ? htmlspecialchars($get['size']) : $listSize;
|
||||
$start = isset($get['start']) ? htmlspecialchars($get['start']) : 0;
|
||||
$end = $start + $size;
|
||||
/* 获取文件列表 */
|
||||
$path = $dirname;
|
||||
$files = $this->getFiles($path,$allowFiles);
|
||||
if(empty($files)){
|
||||
return json_encode(array(
|
||||
"state" => "no match file",
|
||||
"list" => array(),
|
||||
"start" => $start,
|
||||
"total" => count($files)
|
||||
));
|
||||
}
|
||||
/* 获取指定范围的列表 */
|
||||
$len = count($files);
|
||||
for($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){
|
||||
$list[] = $files[$i];
|
||||
}
|
||||
|
||||
/* 返回数据 */
|
||||
$result = json_encode(array(
|
||||
"state" => "SUCCESS",
|
||||
"list" => $list,
|
||||
"start" => $start,
|
||||
"total" => count($files)
|
||||
));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* 遍历获取目录下的指定类型的文件
|
||||
* @param $path
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
private function getFiles($path,$allowFiles,&$files = array()){
|
||||
if(!is_dir($path)) return null;
|
||||
if(substr($path,strlen($path)-1) != '/') $path .= '/';
|
||||
$handle = opendir($path);
|
||||
|
||||
while(false !== ($file = readdir($handle))){
|
||||
if($file != '.' && $file != '..'){
|
||||
$path2 = $path.$file;
|
||||
if(is_dir($path2)){
|
||||
$this->getFiles($path2,$allowFiles,$files);
|
||||
}else{
|
||||
if(preg_match("/\.(".$allowFiles.")$/i",$file)){
|
||||
$files[] = array(
|
||||
'url' => substr($path2,1),
|
||||
'mtime' => filemtime($path2)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
//抓取远程图片
|
||||
private function saveRemote($config,$fieldName){
|
||||
$imgUrl = htmlspecialchars($fieldName);
|
||||
$imgUrl = str_replace("&","&",$imgUrl);
|
||||
|
||||
//http开头验证
|
||||
if(strpos($imgUrl,"http") !== 0){
|
||||
$data=array(
|
||||
'state' => '链接不是http链接',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
//获取请求头并检测死链
|
||||
$heads = @get_headers($imgUrl, 1);
|
||||
if (empty($heads)) {
|
||||
$data=array(
|
||||
'state' => '链接不可用',
|
||||
);
|
||||
return json_encode($data);
|
||||
} else if(!(stristr($heads[0],"200") && !stristr($heads[0],"304"))){
|
||||
$data=array(
|
||||
'state' => '链接不可用',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
//格式验证(扩展名验证和Content-Type验证)
|
||||
if(preg_match("/^http(s?):\/\/mmbiz.qpic.cn\/(.*)/", $imgUrl) != 1){
|
||||
$fileType = strtolower(strrchr($imgUrl,'.'));
|
||||
if(!in_array($fileType,$config['allowFiles']) || (isset($heads['Content-Type']) && !stristr($heads['Content-Type'],"image"))){
|
||||
$data=array(
|
||||
'state' => '链接contentType不正确',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
} else {
|
||||
$data=array(
|
||||
'state' => '微信公众号图片请点击远程本地化处理!',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//打开输出缓冲区并获取远程图片
|
||||
ob_start();
|
||||
$context = stream_context_create(
|
||||
array('http' => array(
|
||||
'follow_location' => false // don't follow redirects
|
||||
))
|
||||
);
|
||||
readfile($imgUrl,false,$context);
|
||||
$img = ob_get_contents();
|
||||
ob_end_clean();
|
||||
preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/",$imgUrl,$m);
|
||||
|
||||
$dirname = './'.UPLOAD_PATH.'ueditor/'.date('Ymd/');
|
||||
$file['oriName'] = $m ? $m[1] : "";
|
||||
$file['filesize'] = strlen($img);
|
||||
$file['ext'] = strtolower(strrchr($config['oriName'],'.'));
|
||||
$file['name'] = session('admin_id').'-'.dd2char(date("ymdHis").mt_rand(100,999)).$file['ext'];
|
||||
$file['fullName'] = $dirname.$file['name'];
|
||||
$fullName = $file['fullName'];
|
||||
|
||||
//检查文件大小是否超出限制
|
||||
if($file['filesize'] >= ($config["maxSize"])){
|
||||
$data=array(
|
||||
'state' => '文件大小超出网站限制',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//创建目录失败
|
||||
if(!file_exists($dirname) && !mkdir($dirname,0777,true)){
|
||||
$data=array(
|
||||
'state' => '目录创建失败',
|
||||
);
|
||||
return json_encode($data);
|
||||
}else if(!is_writeable($dirname)){
|
||||
$data=array(
|
||||
'state' => '目录没有写权限',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//移动文件
|
||||
if(!(file_put_contents($fullName, $img) && file_exists($fullName))){ //移动失败
|
||||
$data=array(
|
||||
'state' => '写入文件内容错误',
|
||||
);
|
||||
return json_encode($data);
|
||||
}else{ //移动成功
|
||||
$data = array(
|
||||
'state' => 'SUCCESS',
|
||||
'url' => ROOT_DIR.substr($file['fullName'],1), // 支持子目录
|
||||
'title' => $file['name'],
|
||||
'original' => $file['oriName'],
|
||||
'type' => $file['ext'],
|
||||
'size' => $file['filesize'],
|
||||
);
|
||||
|
||||
print_water($data['url']); // 添加水印
|
||||
}
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* 处理base64编码的图片上传
|
||||
* 例如:涂鸦图片上传
|
||||
*/
|
||||
private function upBase64($config,$fieldName){
|
||||
$base64Data = $_POST[$fieldName];
|
||||
$img = base64_decode($base64Data);
|
||||
|
||||
$dirname = './'.UPLOAD_PATH.'ueditor/'.date('Ymd/');
|
||||
$file['filesize'] = strlen($img);
|
||||
$file['oriName'] = $config['oriName'];
|
||||
$file['ext'] = strtolower(strrchr($config['oriName'],'.'));
|
||||
$file['name'] = uniqid().$file['ext'];
|
||||
$file['fullName'] = $dirname.$file['name'];
|
||||
$fullName = $file['fullName'];
|
||||
|
||||
//检查文件大小是否超出限制
|
||||
if($file['filesize'] >= ($config["maxSize"])){
|
||||
$data=array(
|
||||
'state' => '文件大小超出网站限制',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//创建目录失败
|
||||
if(!file_exists($dirname) && !mkdir($dirname,0777,true)){
|
||||
$data=array(
|
||||
'state' => '目录创建失败',
|
||||
);
|
||||
return json_encode($data);
|
||||
}else if(!is_writeable($dirname)){
|
||||
$data=array(
|
||||
'state' => '目录没有写权限',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
//移动文件
|
||||
if(!(file_put_contents($fullName, $img) && file_exists($fullName))){ //移动失败
|
||||
$data=array(
|
||||
'state' => '写入文件内容错误',
|
||||
);
|
||||
}else{ //移动成功
|
||||
$data=array(
|
||||
'state' => 'SUCCESS',
|
||||
'url' => substr($file['fullName'],1),
|
||||
'title' => $file['name'],
|
||||
'original' => $file['oriName'],
|
||||
'type' => $file['ext'],
|
||||
'size' => $file['filesize'],
|
||||
);
|
||||
}
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function imageUp
|
||||
*/
|
||||
public function imageUp()
|
||||
{
|
||||
if (!IS_POST) {
|
||||
$return_data['state'] = '非法上传';
|
||||
respose($return_data,'json');
|
||||
}
|
||||
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
// 上传图片框中的描述表单名称,
|
||||
$pictitle = input('pictitle');
|
||||
$dir = input('dir');
|
||||
$title = htmlspecialchars($pictitle , ENT_QUOTES);
|
||||
$path = htmlspecialchars($dir, ENT_QUOTES);
|
||||
//$input_file ['upfile'] = $info['Filedata']; 一个是上传插件里面来的, 另外一个是 文章编辑器里面来的
|
||||
// 获取表单上传文件
|
||||
$file = request()->file('file');
|
||||
empty($file) && $file = request()->file('upfile');
|
||||
if (empty($file) || !@ini_get('file_uploads')) {
|
||||
$return_data['state'] = '请检查空间是否开启文件上传功能!';
|
||||
respose($return_data,'json');
|
||||
}
|
||||
// ico图片文件不进行验证
|
||||
if (pathinfo($file->getInfo('name'), PATHINFO_EXTENSION) != 'ico') {
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file' => 'image|fileSize:' . $max_file_size . '|fileExt:' . $this->image_type],
|
||||
[
|
||||
'file.image' => '上传文件必须为图片',
|
||||
'file.fileSize' => '上传图片过大',
|
||||
'file.fileExt' => '上传图片后缀名必须为' . $this->image_type
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
/*验证图片一句话木马*/
|
||||
if (false === check_illegal($file->getInfo('tmp_name'))) {
|
||||
$result = '疑似木马图片!';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if (true !== $result || empty($file)) {
|
||||
$state = "ERROR:" . $result;
|
||||
} else {
|
||||
if ('adminlogo/' == $this->savePath) {
|
||||
$savePath = 'public/static/admin/logo/';
|
||||
} else if ('loginlogo/' == $this->savePath) {
|
||||
$savePath = 'public/static/admin/login/';
|
||||
} else if ('loginbgimg/' == $this->savePath) {
|
||||
$savePath = 'public/static/admin/loginbg/';
|
||||
} else {
|
||||
$savePath = UPLOAD_PATH . $this->savePath . date('Ymd/');
|
||||
}
|
||||
// 移动到框架应用根目录/public/uploads/ 目录下
|
||||
$info = $file->rule(function ($file) {
|
||||
// return md5(mt_rand()); // 使用自定义的文件保存规则
|
||||
return session('admin_id').'-'.dd2char(date("ymdHis").mt_rand(100,999)); // 使用自定义的文件保存规则
|
||||
})->move($savePath);
|
||||
if ($info) {
|
||||
$state = "SUCCESS";
|
||||
} else {
|
||||
$state = "ERROR" . $file->getError();
|
||||
}
|
||||
$return_url = '/' . $savePath . $info->getSaveName();
|
||||
$return_data['url'] = ROOT_DIR . $return_url; // 支持子目录
|
||||
|
||||
// 重新制作一张图片,抹去任何可能有危害的数据
|
||||
// $image = \think\Image::open('.'.$return_url);
|
||||
// $image->save('.'.$return_url, null, 100);
|
||||
}
|
||||
|
||||
// 添加水印
|
||||
if($state == 'SUCCESS' && pathinfo($file->getInfo('name'), PATHINFO_EXTENSION) != 'ico'){
|
||||
$is_water = input('param.is_water/d');
|
||||
if(!in_array($this->savePath, ['adminlogo/','loginlogo/','loginbgimg/']) && $is_water == 1) print_water($return_url);
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
$return_data['title'] = $title;
|
||||
$return_data['original'] = $title;
|
||||
$return_data['state'] = $state;
|
||||
$return_data['path'] = $path;
|
||||
|
||||
/*同步到第三方对象存储空间*/
|
||||
$bucket_data = SynImageObjectBucket($return_url);
|
||||
$return_data = array_merge($return_data, $bucket_data);
|
||||
/*end*/
|
||||
|
||||
respose($return_data,'json');
|
||||
}
|
||||
|
||||
/**
|
||||
* app文件上传
|
||||
*/
|
||||
public function appFileUp()
|
||||
{
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
$path = UPLOAD_PATH.'soft/'.date('Ymd/');
|
||||
if (!file_exists($path)) {
|
||||
mkdir($path);
|
||||
}
|
||||
|
||||
//$input_file ['upfile'] = $info['Filedata']; 一个是上传插件里面来的, 另外一个是 文章编辑器里面来的
|
||||
// 获取表单上传文件
|
||||
$file = request()->file('Filedata');
|
||||
if (empty($file)) {
|
||||
$file = request()->file('upfile');
|
||||
}
|
||||
|
||||
$result = $this->validate(
|
||||
['file2' => $file],
|
||||
['file2'=>'fileSize:'.$max_file_size.'|fileExt:apk,ipa,pxl,deb'],
|
||||
['file2.fileSize' => '上传文件过大', 'file2.fileExt' => '上传文件后缀名必须为:apk,ipa,pxl,deb']
|
||||
);
|
||||
if (true !== $result || empty($file)) {
|
||||
$state = "ERROR" . $result;
|
||||
} else {
|
||||
$info = $file->rule(function ($file) {
|
||||
return date('YmdHis_').input('Filename'); // 使用自定义的文件保存规则
|
||||
})->move($path);
|
||||
if ($info) {
|
||||
$state = "SUCCESS";
|
||||
} else {
|
||||
$state = "ERROR" . $file->getError();
|
||||
}
|
||||
$return_data['url'] = $path.$info->getSaveName();
|
||||
}
|
||||
|
||||
$return_data['title'] = 'app文件';
|
||||
$return_data['original'] = ''; // 这里好像没啥用 暂时注释起来
|
||||
$return_data['state'] = $state;
|
||||
$return_data['path'] = $path;
|
||||
|
||||
respose($return_data);
|
||||
}
|
||||
|
||||
public function uhash( $file ) {
|
||||
$fragment = 65536;
|
||||
|
||||
$rh = fopen($file, 'rb');
|
||||
$size = filesize($file);
|
||||
|
||||
$part1 = fread( $rh, $fragment );
|
||||
fseek($rh, $size-$fragment);
|
||||
$part2 = fread( $rh, $fragment);
|
||||
fclose($rh);
|
||||
|
||||
return md5( $part1.$part2 );
|
||||
}
|
||||
|
||||
//上传文件
|
||||
public function DownloadUploadFile(){
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
// 获取定义的上传最大参数
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
// 获取上传的文件信息
|
||||
$files = request()->file();
|
||||
// 若获取不到则定义为空
|
||||
$file = !empty($files['file']) ? $files['file'] : '';
|
||||
|
||||
/*判断上传文件是否存在错误*/
|
||||
if(empty($file)){
|
||||
echo json_encode(['msg' => '文件过大或文件已损坏!']);exit;
|
||||
}
|
||||
$error = $file->getError();
|
||||
if(!empty($error)){
|
||||
echo json_encode(['msg' => $error]);exit;
|
||||
}
|
||||
|
||||
$file_type = tpCache('basic.file_type');
|
||||
$file_type = !empty($file_type) ? str_replace('|', ',', $file_type) : 'zip,gz,rar,iso,doc,xls,ppt,wps,txt,docx';
|
||||
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file'=>'fileSize:'.$max_file_size.'|fileExt:'.$file_type],
|
||||
['file.fileSize' => '上传文件过大','file.fileExt'=>'上传文件后缀名必须为'.$file_type]
|
||||
);
|
||||
if (true !== $result || empty($file)) {
|
||||
echo json_encode(['msg' => $result]);exit;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 移动到框架应用根目录/public/uploads/ 目录下
|
||||
$this->savePath = $this->savePath.date('Ymd/');
|
||||
// 定义文件名
|
||||
$fileName = $file->getInfo('name');
|
||||
// 提取文件名后缀
|
||||
$file_ext = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
// 提取出文件名,不包括扩展名
|
||||
$newfileName = preg_replace('/\.([^\.]+)$/', '', $fileName);
|
||||
// 过滤文件名.\/的特殊字符,防止利用上传漏洞
|
||||
$newfileName = preg_replace('#(\\\|\/|\.)#i', '', $newfileName);
|
||||
// 过滤后的新文件名
|
||||
$fileName = $newfileName.'.'.$file_ext;
|
||||
// 中文转码
|
||||
$this->fileName = iconv("utf-8","gb2312//IGNORE",$fileName);
|
||||
|
||||
// 使用自定义的文件保存规则
|
||||
$info = $file->rule(function ($file) {
|
||||
return $this->fileName;
|
||||
})->move(UPLOAD_PATH.$this->savePath);
|
||||
if($info){
|
||||
// 拼装数据存入session
|
||||
$file_path = UPLOAD_PATH.$this->savePath.$info->getSaveName();
|
||||
$return = array(
|
||||
'code' => 1,
|
||||
'msg' => '上传成功',
|
||||
'file_url' => '/' . UPLOAD_PATH.$this->savePath.$fileName,
|
||||
'file_mime' => $file->getInfo('type'),
|
||||
'file_name' => $fileName,
|
||||
'file_ext' => '.' . $file_ext,
|
||||
'file_size' => $info->getSize(),
|
||||
'uhash' => $this->uhash($file_path),
|
||||
'md5file' => md5_file($file_path),
|
||||
);
|
||||
}else{
|
||||
$return = array('msg' => $info->getError());
|
||||
}
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
//上传文件
|
||||
public function DownloadUploadFileAjax()
|
||||
{
|
||||
// 获取上传的文件信息
|
||||
$file = request()->file('file');
|
||||
/*判断上传文件是否存在错误*/
|
||||
if (empty($file)) {
|
||||
$res = ['code' => 0, 'msg' => '文件过大或文件已损坏!'];
|
||||
respose($res);
|
||||
}
|
||||
$error = $file->getError();
|
||||
if (!empty($error)) {
|
||||
$res = ['code' => 0, 'msg' => $error];
|
||||
respose($res);
|
||||
}
|
||||
|
||||
$file_type = tpCache('basic.file_type');
|
||||
$file_type = !empty($file_type) ? str_replace('|', ',', $file_type) : 'zip,gz,rar,iso,doc,xls,ppt,wps,txt,docx';
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file'=>'fileSize:'.$max_file_size.'|fileExt:'.$file_type],
|
||||
['file.fileSize' => '上传文件过大','file.fileExt'=>'上传文件后缀名必须为'.$file_type]
|
||||
);
|
||||
|
||||
if (true !== $result || empty($file)) {
|
||||
$res = ['code' => 0, 'msg' => $result];
|
||||
respose($res);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 移动到框架应用根目录/public/uploads/ 目录下
|
||||
$this->savePath = "soft/" . date('Ymd/');
|
||||
// 定义文件名
|
||||
$fileName = $file->getInfo('name');
|
||||
// 提取文件名后缀
|
||||
$file_ext = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
|
||||
// 使用自定义的文件保存规则
|
||||
$info = $file->rule(function ($file) {
|
||||
return session('admin_id') . '-' . dd2char(date("ymdHis") . mt_rand(100, 999));
|
||||
})->move(UPLOAD_PATH . $this->savePath);
|
||||
if ($info) {
|
||||
// 拼装数据存入session
|
||||
$file_path = UPLOAD_PATH . $this->savePath . $info->getSaveName();
|
||||
$return = array(
|
||||
'code' => 1,
|
||||
'msg' => '上传成功',
|
||||
'file_url' => ROOT_DIR.'/' . UPLOAD_PATH . $this->savePath . $info->getSaveName(),
|
||||
'file_mime' => $file->getInfo('type'),
|
||||
'file_name' => $fileName,
|
||||
'file_ext' => '.' . $file_ext,
|
||||
'file_size' => $info->getSize(),
|
||||
'uhash' => $this->uhash($file_path),
|
||||
'md5file' => md5_file($file_path),
|
||||
);
|
||||
} else {
|
||||
$res = ['code' => 0, 'msg' => $info->getError()];
|
||||
}
|
||||
respose($return);
|
||||
}
|
||||
|
||||
// 上传视频
|
||||
public function upVideo()
|
||||
{
|
||||
$file = request()->file('file');
|
||||
if (empty($file)) {
|
||||
if (!@ini_get('file_uploads')) {
|
||||
return json_encode(['state' => '请检查空间是否开启文件上传功能!']);
|
||||
} else {
|
||||
return json_encode(['state' => 'ERROR,空间限制上传大小!']);
|
||||
}
|
||||
}
|
||||
$error = $file->getError();
|
||||
if (!empty($error)) {
|
||||
return json_encode(['state' => $error]);
|
||||
}
|
||||
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$media_type = !empty($media_type) ? str_replace('|', ',', $media_type) : config('global.media_ext');
|
||||
if (empty($media_type)) {
|
||||
return json_encode(['state' => 'ERROR,请设置上传多媒体文件类型!']);
|
||||
} else {
|
||||
$media_type = str_replace('|', ',', $media_type);
|
||||
}
|
||||
$max_file_size = intval(tpCache('basic.file_size') * 1024 * 1024);
|
||||
$result = $this->validate(
|
||||
['file' => $file],
|
||||
['file' => 'fileSize:' . $max_file_size . '|fileExt:' . $media_type],
|
||||
['file.fileSize' => '上传视频过大', 'file.fileExt' => '上传视频后缀名必须为' . $media_type]
|
||||
);
|
||||
if (true !== $result || empty($file)) {
|
||||
$state = "ERROR" . $result;
|
||||
return json_encode(['state' => $state]);
|
||||
}
|
||||
|
||||
//获取视频时长start
|
||||
vendor('getid3.getid3');
|
||||
// 实例化
|
||||
$getID3 = new \getID3(); //实例化类
|
||||
$tmp_name = $file->getInfo('tmp_name');
|
||||
$ThisFileInfo = $getID3->analyze($tmp_name); //分析文件,$path为音频文件的地址
|
||||
$fileduration = intval($ThisFileInfo['playtime_seconds']); //这个获得的便是音频文件的时长
|
||||
//获取视频时长end
|
||||
|
||||
// 移动到框架应用根目录/public/uploads/ 目录下
|
||||
$this->savePath = $this->savePath.date('Ymd/');
|
||||
// 使用自定义的文件保存规则
|
||||
$info = $file->rule(function ($file) {
|
||||
return session('admin_id') . '-' . dd2char(date("ymdHis") . mt_rand(100, 999));
|
||||
})->move(UPLOAD_PATH . $this->savePath);
|
||||
|
||||
if ($info) {
|
||||
// 定义文件名
|
||||
$fileName = $file->getInfo('name');
|
||||
// 提取出文件名,不包括扩展名
|
||||
$newfileName = preg_replace('/\.([^\.]+)$/', '', $fileName);
|
||||
// 过滤文件名.\/的特殊字符,防止利用上传漏洞
|
||||
$newfileName = preg_replace('#(\\\|\/|\.)#i', '', $newfileName);
|
||||
|
||||
$file_path = UPLOAD_PATH.$this->savePath.$info->getSaveName();
|
||||
|
||||
$file_size = $info->getSize();
|
||||
|
||||
$data = array(
|
||||
'state' => 'SUCCESS',
|
||||
'url' => '/' . $file_path,
|
||||
'time' => $fileduration,
|
||||
'title' => $newfileName,
|
||||
'original' => $info->getSaveName(),
|
||||
'type' => '.' . $info->getExtension(),
|
||||
'size' => $file_size,
|
||||
'mime' => $file->getInfo('type'),
|
||||
);
|
||||
|
||||
$data['url'] = ROOT_DIR . $data['url']; // 支持子目录
|
||||
} else {
|
||||
$data = array('state' => 'ERROR' . $info->getError());
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
161
src/application/admin/controller/Uiset.php
Normal file
161
src/application/admin/controller/Uiset.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Page;
|
||||
|
||||
class Uiset extends Base
|
||||
{
|
||||
public $theme_style;
|
||||
public $templateArr = array();
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->theme_style = 'pc';
|
||||
|
||||
/*模板列表*/
|
||||
if (file_exists(ROOT_PATH.'template/'.TPL_THEME.'pc/uiset.txt')) {
|
||||
array_push($this->templateArr, 'pc');
|
||||
}
|
||||
if (file_exists(ROOT_PATH.'template/'.TPL_THEME.'mobile/uiset.txt')) {
|
||||
array_push($this->templateArr, 'mobile');
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
$permission = $auth_role_info['permission'];
|
||||
$auth_rule = get_auth_rule();
|
||||
$all_auths = []; // 系统全部权限对应的菜单ID
|
||||
$admin_auths = []; // 用户当前拥有权限对应的菜单ID
|
||||
$diff_auths = []; // 用户没有被授权的权限对应的菜单ID
|
||||
foreach($auth_rule as $key => $val){
|
||||
$all_auths = array_merge($all_auths, explode(',', $val['menu_id']), explode(',', $val['menu_id2']));
|
||||
if (in_array($val['id'], $permission['rules'])) {
|
||||
$admin_auths = array_merge($admin_auths, explode(',', $val['menu_id']), explode(',', $val['menu_id2']));
|
||||
}
|
||||
}
|
||||
$all_auths = array_unique($all_auths);
|
||||
$admin_auths = array_unique($admin_auths);
|
||||
$diff_auths = array_diff($all_auths, $admin_auths);
|
||||
|
||||
if(in_array(2002, $diff_auths)){
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* PC调试外观
|
||||
*/
|
||||
public function pc()
|
||||
{
|
||||
// 支持子目录
|
||||
$index_url = ROOT_DIR.'/index.php?m=home&c=Index&a=index&uiset=on&v=pc&lang='.$this->admin_lang;
|
||||
$this->redirect($index_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机调试外观
|
||||
*/
|
||||
public function mobile()
|
||||
{
|
||||
// 支持子目录
|
||||
$index_url = ROOT_DIR.'/index.php?m=home&c=Index&a=index&uiset=on&v=mobile&lang='.$this->admin_lang;
|
||||
$this->redirect($index_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调试外观
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function ui_index()
|
||||
{
|
||||
$condition = array();
|
||||
// 获取到所有GET参数
|
||||
$param = input('param.');
|
||||
/*模板主题*/
|
||||
$param['theme_style'] = $this->theme_style = input('param.theme_style/s', 'pc');
|
||||
/*--end*/
|
||||
|
||||
// 应用搜索条件
|
||||
foreach (['keywords','theme_style'] as $key) {
|
||||
if (isset($param[$key]) && $param[$key] !== '') {
|
||||
if ($key == 'keywords') {
|
||||
$condition['a.page|a.type|a.name'] = array('eq', "%{$param[$key]}%");
|
||||
} else if ($key == 'theme_style') {
|
||||
$condition['a.'.$key] = array('eq', TPL_THEME.$param[$key]);
|
||||
} else {
|
||||
$condition['a.'.$key] = array('eq', $param[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*多语言*/
|
||||
$condition['a.lang'] = $this->admin_lang;
|
||||
/*--end*/
|
||||
|
||||
$list = array();
|
||||
|
||||
$uiconfigM = M('ui_config');
|
||||
$count = $uiconfigM->alias('a')->where($condition)->count('id');// 查询满足要求的总记录数
|
||||
$Page = $pager = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
||||
$list = $uiconfigM->alias('a')->where($condition)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
|
||||
|
||||
$show = $Page->show();// 分页显示输出
|
||||
$this->assign('page',$show);// 赋值分页输出
|
||||
$this->assign('list',$list);// 赋值数据集
|
||||
$this->assign('pager',$pager);// 赋值分页对象
|
||||
$this->assign('theme_style',$this->theme_style);// 模板主题
|
||||
$this->assign('templateArr',$this->templateArr);// 模板列表
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$id_arr = input('del_id/a');
|
||||
$id_arr = eyIntval($id_arr);
|
||||
if(!empty($id_arr)){
|
||||
$result = M('ui_config')->where("id",'IN',$id_arr)->getAllWithIndex('name');
|
||||
$r = M('ui_config')->where("id",'IN',$id_arr)->delete();
|
||||
if($r){
|
||||
\think\Cache::clear('ui_config');
|
||||
delFile(RUNTIME_PATH.'ui/'.$result['theme_style']);
|
||||
adminLog('删除可视化数据 e-id:'.implode(array_keys($result)));
|
||||
$this->success('删除成功');
|
||||
}else{
|
||||
$this->error('删除失败');
|
||||
}
|
||||
}else{
|
||||
$this->error('参数有误');
|
||||
}
|
||||
}
|
||||
}
|
||||
316
src/application/admin/controller/Upgrade.php
Normal file
316
src/application/admin/controller/Upgrade.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/**
|
||||
* eyoucms
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\response\Json;
|
||||
use app\admin\model;
|
||||
class Upgrade extends Controller {
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
@ini_set('memory_limit', '1024M'); // 设置内存大小
|
||||
@ini_set("max_execution_time", "0"); // 请求超时时间 0 为不限时
|
||||
@ini_set('default_socket_timeout', 3600); // 设置 file_get_contents 请求超时时间 官方的说明,似乎没有不限时间的选项,也就是不能填0,你如果填0,那么socket就会立即返回失败,
|
||||
$this->assign('version', getCmsVersion());
|
||||
}
|
||||
|
||||
public function welcome()
|
||||
{
|
||||
$sys_info['os'] = PHP_OS;
|
||||
$sys_info['zlib'] = function_exists('gzclose') ? 'YES' : 'NO';//zlib
|
||||
$sys_info['safe_mode'] = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
|
||||
$sys_info['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
|
||||
$sys_info['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
|
||||
$sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE'];
|
||||
$sys_info['phpv'] = phpversion();
|
||||
$sys_info['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
|
||||
$sys_info['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
|
||||
$sys_info['max_ex_time'] = @ini_get("max_execution_time").'s'; //脚本最大执行时间
|
||||
$sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
|
||||
$sys_info['domain'] = $_SERVER['HTTP_HOST'];
|
||||
$sys_info['memory_limit'] = ini_get('memory_limit');
|
||||
$sys_info['version'] = file_get_contents(DATA_PATH.'conf/version.txt');
|
||||
$mysqlinfo = Db::query("SELECT VERSION() as version");
|
||||
$sys_info['mysql_version'] = $mysqlinfo[0]['version'];
|
||||
if(function_exists("gd_info")){
|
||||
$gd = gd_info();
|
||||
$sys_info['gdinfo'] = $gd['GD Version'];
|
||||
}else {
|
||||
$sys_info['gdinfo'] = "未知";
|
||||
}
|
||||
|
||||
$globalTpCache = tpCache('global');
|
||||
|
||||
$upgradeLogic = new \app\admin\logic\UpgradeLogic();
|
||||
$sys_info['curent_version'] = $upgradeLogic->curent_version; //当前程序版本
|
||||
$sys_info['web_name'] = !empty($globalTpCache['web_name']) ? $globalTpCache['web_name'] : '';
|
||||
$this->assign('sys_info', $sys_info);
|
||||
|
||||
$upgradeMsg = $upgradeLogic->checkVersion(); //升级包消息
|
||||
$this->assign('upgradeMsg',$upgradeMsg);
|
||||
|
||||
$this->assign('web_show_popup_upgrade', $globalTpCache['web.web_show_popup_upgrade']);
|
||||
|
||||
$this->assign('global', $globalTpCache);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键升级
|
||||
*/
|
||||
public function OneKeyUpgrade(){
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
function_exists('set_time_limit') && set_time_limit(0);
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$auth_role_info = session('admin_info.auth_role_info');
|
||||
if(0 < intval(session('admin_info.role_id')) && ! empty($auth_role_info) && intval($auth_role_info['online_update']) <= 0){
|
||||
$this->error('您没有操作权限,请联系超级管理员分配权限');
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$upgradeLogic = new \app\admin\logic\UpgradeLogic();
|
||||
$data = $upgradeLogic->OneKeyUpgrade(); //升级包消息
|
||||
if (1 <= intval($data['code'])) {
|
||||
$this->success($data['msg'], null, ['code'=>$data['code']]);
|
||||
} else {
|
||||
$code = 0;
|
||||
$msg = '升级异常,请第一时间联系技术支持,排查问题!';
|
||||
if (is_array($data)) {
|
||||
isset($data['code']) && $code = $data['code'];
|
||||
isset($data['msg']) && $msg = $data['msg'];
|
||||
}
|
||||
$this->error($msg, null, ['code'=>$code]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置弹窗更新-不再提醒
|
||||
*/
|
||||
public function setPopupUpgrade()
|
||||
{
|
||||
$show_popup_upgrade = input('param.show_popup_upgrade/s', '1');
|
||||
$inc_type = 'web';
|
||||
tpCache($inc_type, array($inc_type.'_show_popup_upgrade'=>$show_popup_upgrade));
|
||||
respose(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测目录权限、当前版本的数据库是否与官方一致
|
||||
*/
|
||||
public function check_authority()
|
||||
{
|
||||
/*------------------检测目录读写权限----------------------*/
|
||||
$filelist = tpCache('system.system_upgrade_filelist');
|
||||
$filelist = base64_decode($filelist);
|
||||
$filelist = htmlspecialchars_decode($filelist);
|
||||
$filelist = explode('<br>', $filelist);
|
||||
$dirs = array();
|
||||
$i = -1;
|
||||
foreach($filelist as $filename)
|
||||
{
|
||||
$tfilename = $filename;
|
||||
$curdir = $this->GetDirName($tfilename);
|
||||
if (empty($curdir) || !file_exists($curdir)) {
|
||||
continue;
|
||||
}
|
||||
if( !isset($dirs[$curdir]) )
|
||||
{
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
if($dirs[$curdir]['isdir'] == FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
@tp_mkdir($curdir, 0777);
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$is_pass = true;
|
||||
$msg = '检测通过';
|
||||
if($i > -1)
|
||||
{
|
||||
$n = 0;
|
||||
$dirinfos = '';
|
||||
foreach($dirs as $curdir)
|
||||
{
|
||||
$dirinfos .= $curdir['name']." 状态:";
|
||||
if ($curdir['writeable']) {
|
||||
$dirinfos .= "[√正常]";
|
||||
} else {
|
||||
$is_pass = false;
|
||||
$n++;
|
||||
$dirinfos .= "<font color='red'>[×不可写]</font>";
|
||||
}
|
||||
$dirinfos .= "<br />";
|
||||
}
|
||||
$title = "本次升级需要在下面文件夹写入更新文件,已检测站点有 <font color='red'>{$n}</font> 处没有写入权限:<br />";
|
||||
$title .= "<font color='red'>问题分析(如有问题,请咨询技术支持):<br />";
|
||||
$title .= "1、检查站点目录的用户组与所有者,禁止是 root ;<br />";
|
||||
$title .= "2、检查站点目录的读写权限,一般权限值是 0755 ;<br />";
|
||||
$title .= "</font>涉及更新目录列表如下:<br />";
|
||||
$msg = $title . $dirinfos;
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
if (true == $is_pass) {
|
||||
/*------------------检测目录读写权限----------------------*/
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVNlcnZpY2UmYT1nZXRfZGF0YWJhc2VfdHh0';
|
||||
$service_url = base64_decode(config('service_ey')).base64_decode($tmp_str);
|
||||
$url = $service_url . '&version=' . getCmsVersion();
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
|
||||
$response = @file_get_contents($url,false,$context);
|
||||
if (false === $response) {
|
||||
$url = str_replace('http://service', 'https://service', $url);
|
||||
$response = @httpRequest($url);
|
||||
}
|
||||
$params = json_decode($response,true);
|
||||
if (false == $params) {
|
||||
$this->error('连接升级服务器超时,请刷新重试,或者联系技术支持!', null, ['code'=>2]);
|
||||
}
|
||||
|
||||
if (is_array($params)) {
|
||||
if (1 == intval($params['code'])) {
|
||||
/*------------------组合本地数据库信息----------------------*/
|
||||
$dbtables = Db::query('SHOW TABLE STATUS');
|
||||
$local_database = array();
|
||||
foreach ($dbtables as $k => $v) {
|
||||
$table = $v['Name'];
|
||||
if (preg_match('/^'.PREFIX.'/i', $table)) {
|
||||
$local_database[$table] = [
|
||||
'name' => $table,
|
||||
'field' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
/*------------------组合官方远程数据库信息----------------------*/
|
||||
$info = $params['info'];
|
||||
$info = preg_replace("#[\r\n]{1,}#", "\n", $info);
|
||||
$infos = explode("\n", $info);
|
||||
$infolists = [];
|
||||
foreach ($infos as $key => $val) {
|
||||
if (!empty($val)) {
|
||||
$arr = explode('|', $val);
|
||||
$infolists[$arr[0]] = $val;
|
||||
}
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
/*------------------校验数据库是否合格----------------------*/
|
||||
foreach ([1] as $testk => $testv) {
|
||||
// 对比数据表数量
|
||||
if (count($local_database) < count($infolists)) {
|
||||
$is_pass = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// 对比数据表字段数量
|
||||
foreach ($infolists as $k1 => $v1) {
|
||||
$arr1 = explode('|', $v1);
|
||||
|
||||
if (1 >= count($arr1)) {
|
||||
continue; // 忽略不对比的数据表
|
||||
}
|
||||
|
||||
$fieldArr = explode(',', $arr1[1]);
|
||||
$table = preg_replace('/^ey_/i', PREFIX, $arr1[0]);
|
||||
$local_fields = Db::getFields($table); // 本地数据表字段列表
|
||||
$local_database[$table]['field'] = $local_fields;
|
||||
if (count($local_fields) < count($fieldArr)) {
|
||||
$is_pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (false == $is_pass) break;
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
} else if (2 == intval($params['code'])) {
|
||||
$this->error('官方缺少版本号'.getCmsVersion().'的数据库比较文件,请第一时间联系技术支持!', null, ['code'=>2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (true == $is_pass) {
|
||||
$this->success($msg);
|
||||
} else {
|
||||
$this->error('当前数据库结构与官方不一致,请查看官方解决教程!', null, ['code'=>2]);
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
} else {
|
||||
$this->error($msg, null, ['code'=>1]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的目录路径
|
||||
* @param string $filename 文件路径+文件名
|
||||
* @return string
|
||||
*/
|
||||
private function GetDirName($filename)
|
||||
{
|
||||
$dirname = preg_replace("#[\\\\\/]{1,}#", '/', $filename);
|
||||
$dirname = preg_replace("#([^\/]*)$#", '', $dirname);
|
||||
$dirname = preg_replace('/^data\/backup\/tpl\//i', '', $dirname);
|
||||
return $dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有读写权限
|
||||
* @param string $dirname 文件目录路径
|
||||
* @return array
|
||||
*/
|
||||
private function TestIsFileDir($dirname)
|
||||
{
|
||||
$dirs = array('name'=>'', 'isdir'=>FALSE, 'writeable'=>FALSE);
|
||||
$dirs['name'] = $dirname;
|
||||
tp_mkdir($dirname);
|
||||
if(is_dir($dirname))
|
||||
{
|
||||
$dirs['isdir'] = TRUE;
|
||||
$dirs['writeable'] = $this->TestWriteAble($dirname);
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有写入权限
|
||||
* @param string $d 目录路劲
|
||||
* @return boolean
|
||||
*/
|
||||
private function TestWriteAble($d)
|
||||
{
|
||||
$tfile = '_eyout.txt';
|
||||
$fp = @fopen($d.$tfile,'w');
|
||||
if(!$fp) {
|
||||
if (@is_writable($d)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
fclose($fp);
|
||||
$rs = @unlink($d.$tfile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
623
src/application/admin/controller/Uploadify.php
Normal file
623
src/application/admin/controller/Uploadify.php
Normal file
@@ -0,0 +1,623 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\common\logic\ArctypeLogic;
|
||||
|
||||
class Uploadify extends Base
|
||||
{
|
||||
public $image_type = '';
|
||||
private $imageExt = '';
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->imageExt = config('global.image_ext');
|
||||
$this->image_type = tpCache('basic.image_type');
|
||||
$this->image_type = !empty($this->image_type) ? str_replace('|', ',', $this->image_type) : $this->imageExt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的上传图片
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$func = input('func');
|
||||
$path = input('path','allimg');
|
||||
$num = input('num/d', '1');
|
||||
$is_water = input('is_water/d', 1);
|
||||
$default_size = intval(tpCache('basic.file_size') * 1024 * 1024); // 单位为b
|
||||
$size = input('size/d'); // 单位为kb
|
||||
$size = empty($size) ? $default_size : $size*1024;
|
||||
$info = array(
|
||||
'num' => $num,
|
||||
'title' => '',
|
||||
'upload' => url('Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images','is_water'=>$is_water)),
|
||||
'fileList' => url('Uploadify/fileList',array('path'=>$path)),
|
||||
'size' => $size,
|
||||
'type' => $this->image_type,
|
||||
'input' => input('input'),
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
'path' => $path,
|
||||
);
|
||||
$this->assign('info',$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图库在线管理 - 左侧树形目录结构
|
||||
*/
|
||||
public function picture_folder()
|
||||
{
|
||||
$func = input('func');
|
||||
$path = input('path','allimg');
|
||||
$num = input('num/d', '1');
|
||||
$default_size = intval(tpCache('basic.file_size') * 1024 * 1024); // 单位为b
|
||||
$size = input('size/d'); // 单位为kb
|
||||
$size = empty($size) ? $default_size : $size*1024;
|
||||
$info = array(
|
||||
'num' => $num,
|
||||
'title' => '',
|
||||
'upload' => url('Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
|
||||
'fileList' => url('Uploadify/fileList',array('path'=>$path)),
|
||||
'size' => $size,
|
||||
'type' => $this->image_type,
|
||||
'input' => input('input'),
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
'path' => $path,
|
||||
);
|
||||
$this->assign('info',$info);
|
||||
|
||||
// 侧边栏目录栏目
|
||||
$dirArr = $this->getDir('uploads');
|
||||
$dirArr2 = [];
|
||||
foreach ($dirArr as $key => $val) {
|
||||
$dirArr2[$val['id']] = $val['dirpath'];
|
||||
}
|
||||
foreach ($dirArr as $key => $val) {
|
||||
$dirfileArr = glob("{$val['dirpath']}/*");
|
||||
if (empty($dirfileArr)) {
|
||||
empty($dirfileArr) && @rmdir($val['dirpath']);
|
||||
$dirArr[$key] = [];
|
||||
continue;
|
||||
}
|
||||
/*图库显示数量*/
|
||||
$countFile = 0;
|
||||
$dirfileArr2 = glob("{$val['dirpath']}/*.*"); // 文件数量
|
||||
$countFile = count($dirfileArr2);
|
||||
/*end*/
|
||||
$dirname = preg_replace('/([^\/]+)$/i', '', $val['dirpath']);
|
||||
$arr_key = array_search(trim($dirname, '/'), $dirArr2);
|
||||
if (!empty($arr_key)) {
|
||||
$dirArr[$key]['pId'] = $arr_key;
|
||||
} else {
|
||||
$dirArr[$key]['pId'] = 0;
|
||||
}
|
||||
$dirArr[$key]['name'] = preg_replace('/^(.*)\/([^\/]+)$/i', '${2}', $val['dirpath']);
|
||||
!empty($countFile) && $dirArr[$key]['name'] .= "({$countFile})"; // 图库显示数量
|
||||
}
|
||||
|
||||
$zNodes = json_encode($dirArr,true);
|
||||
$this->assign('zNodes', $zNodes);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图库在线管理 - 图片列表显示
|
||||
*/
|
||||
public function get_images_path($images_path = 'uploads')
|
||||
{
|
||||
if ('uploads' != $images_path && !preg_match('#^(uploads)/(.*)$#i', $images_path)) {
|
||||
$this->error('非法访问!');
|
||||
}
|
||||
|
||||
$func = input('func/s');
|
||||
$num = input('num/d', '1');
|
||||
$info = array(
|
||||
'num' => $num,
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
);
|
||||
$this->assign('info',$info);
|
||||
|
||||
// 常用图片
|
||||
$common_pic = [];
|
||||
$arr1 = explode('/', $images_path);
|
||||
if (1 >= count($arr1)) { // 只有一级目录才显示常用图片
|
||||
$where = [
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
$common_pic = M('common_pic')->where($where)->order('id desc')->limit(6)->field('pic_path')->select();
|
||||
}
|
||||
$this->assign('common_pic', $common_pic);
|
||||
|
||||
// 图片列表
|
||||
$images_data = glob($images_path.'/*');
|
||||
$list = [];
|
||||
if (!empty($images_data)) {
|
||||
// 图片类型数组
|
||||
$image_ext = explode(',', $this->imageExt);
|
||||
// 处理图片
|
||||
foreach ($images_data as $key => $file) {
|
||||
$fileArr = explode('.', $file);
|
||||
$ext = end($fileArr);
|
||||
$ext = strtolower($ext);
|
||||
if (in_array($ext, $image_ext)) {
|
||||
$list[$key]['path'] = ROOT_DIR.'/'.$file;
|
||||
$list[$key]['time'] = @filemtime($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 图片选择的时间从大到小排序
|
||||
$list_time = get_arr_column($list,'time');
|
||||
array_multisort($list_time,SORT_DESC,$list);
|
||||
// 返回数据
|
||||
$this->assign('list', $list);
|
||||
|
||||
$this->assign('path_directory', $images_path);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录常用图片
|
||||
*/
|
||||
public function update_pic()
|
||||
{
|
||||
if(IS_AJAX_POST){
|
||||
$param = input('param.');
|
||||
if (!empty($param['images_array'])) {
|
||||
$commonPic_db = Db::name('common_pic');
|
||||
|
||||
$where = '';
|
||||
$data = [];
|
||||
foreach ($param['images_array'] as $key => $value) {
|
||||
// 删除条件
|
||||
if ($key > '0') { $where .= ','; }
|
||||
$where .= $value;
|
||||
|
||||
// 添加数组
|
||||
$data[$key] = [
|
||||
'pic_path' => $value,
|
||||
'lang' => $this->admin_lang,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
|
||||
// 批量删除选中的图片
|
||||
$commonPic_db->where('pic_path','IN',$where)->delete();
|
||||
|
||||
// 批量添加图片
|
||||
!empty($data) && $commonPic_db->insertAll($data);
|
||||
|
||||
// 查询最后一条数据
|
||||
$row = $commonPic_db->order('id desc')->limit('20,1')->field('id')->select();
|
||||
if (!empty($row)) {
|
||||
$id = $row[0]['id'];
|
||||
// 删除ID往后的数据
|
||||
$where_ = array(
|
||||
'id' => array('<',$id),
|
||||
'lang' => $this->admin_lang,
|
||||
);
|
||||
$commonPic_db->where($where_)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在弹出窗里的上传图片
|
||||
*/
|
||||
public function upload_frame()
|
||||
{
|
||||
$func = input('func');
|
||||
$path = input('path','allimg');
|
||||
$num = input('num/d', '1');
|
||||
$default_size = intval(tpCache('basic.file_size') * 1024 * 1024); // 单位为b
|
||||
$size = input('size/d'); // 单位为kb
|
||||
$size = empty($size) ? $default_size : $size*1024;
|
||||
$info = array(
|
||||
'num'=> $num,
|
||||
'title' => '',
|
||||
'upload' =>url('Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
|
||||
'fileList'=>url('Uploadify/fileList',array('path'=>$path)),
|
||||
'size' => $size,
|
||||
'type' => $this->image_type,
|
||||
'input' => input('input'),
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
'path' => $path,
|
||||
);
|
||||
$this->assign('info',$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台(产品)专用
|
||||
*/
|
||||
public function upload_product()
|
||||
{
|
||||
$aid = input('aid/d');
|
||||
$func = input('func');
|
||||
$path = input('path','allimg');
|
||||
$num = input('num/d', '1');
|
||||
$default_size = intval(tpCache('basic.file_size') * 1024 * 1024); // 单位为b
|
||||
$size = input('size/d'); // 单位为kb
|
||||
$size = empty($size) ? $default_size : $size*1024;
|
||||
$field = array(
|
||||
'aid' => $aid,
|
||||
'num' => $num,
|
||||
'title' => '',
|
||||
'upload' => url('Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
|
||||
'fileList'=> url('Uploadify/fileList',array('path'=>$path)),
|
||||
'size' => $size,
|
||||
'type' => $this->image_type,
|
||||
'input' => input('input'),
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
'path' => $path,
|
||||
);
|
||||
$this->assign('field',$field);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整的上传模板展示
|
||||
*/
|
||||
public function upload_full()
|
||||
{
|
||||
$func = input('func');
|
||||
$path = input('path','allimg');
|
||||
$num = input('num/d', '1');
|
||||
$default_size = intval(tpCache('basic.file_size') * 1024 * 1024); // 单位为b
|
||||
$size = input('size/d'); // 单位为kb
|
||||
$size = empty($size) ? $default_size : $size*1024;
|
||||
$info = array(
|
||||
'num'=> $num,
|
||||
'title' => '',
|
||||
'upload' =>url('Ueditor/imageUp',array('savepath'=>$path,'pictitle'=>'banner','dir'=>'images')),
|
||||
'fileList'=>url('Uploadify/fileList',array('path'=>$path)),
|
||||
'size' => $size,
|
||||
'type' => $this->image_type,
|
||||
'input' => input('input'),
|
||||
'func' => empty($func) ? 'undefined' : $func,
|
||||
'path' => $path,
|
||||
);
|
||||
$this->assign('info',$info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除上传的图片
|
||||
*/
|
||||
public function delupload()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$action = input('action','del');
|
||||
$filename= input('filename/s');
|
||||
$filename= empty($filename) ? input('url') : $filename;
|
||||
$filename= str_replace('../','',$filename);
|
||||
$filename= trim($filename,'.');
|
||||
$filename = preg_replace('#^(/[/\w]+)?(/public/upload/|/uploads/|/public/static/admin/logo/)#i', '$2', $filename);
|
||||
if(eyPreventShell($filename) && $action=='del' && !empty($filename) && file_exists('.'.$filename)){
|
||||
if (stristr($filename, '/admin/logo/')) {
|
||||
$filetype = preg_replace('/^(.*)\.(\w+)$/i', '$2', $filename);
|
||||
$phpfile = strtolower(strstr($filename,'.php')); //排除PHP文件
|
||||
$size = getimagesize('.'.$filename);
|
||||
$fileInfo = explode('/',$size['mime']);
|
||||
if($fileInfo[0] != 'image' || $phpfile || !in_array($filetype, explode(',', $this->imageExt))){
|
||||
exit;
|
||||
}
|
||||
if(@unlink('.'.$filename)){
|
||||
echo 1;
|
||||
}else{
|
||||
echo 0;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo 1;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function fileList(){
|
||||
/* 判断类型 */
|
||||
$type = input('type','Images');
|
||||
switch ($type){
|
||||
/* 列出图片 */
|
||||
case 'Images' : $allowFiles = str_replace(',', '|', $this->image_type);break;
|
||||
|
||||
case 'Flash' : $allowFiles = 'flash|swf';break;
|
||||
|
||||
/* 列出文件 */
|
||||
default :
|
||||
{
|
||||
$file_type = tpCache('basic.file_type');
|
||||
$media_type = tpCache('basic.media_type');
|
||||
$allowFiles = $file_type.'|'.$media_type;
|
||||
}
|
||||
}
|
||||
|
||||
$listSize = 102400000;
|
||||
|
||||
$key = empty($_GET['key']) ? '' : $_GET['key'];
|
||||
|
||||
/* 获取参数 */
|
||||
$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize;
|
||||
$start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
|
||||
$end = $start + $size;
|
||||
|
||||
$path = input('path','allimg');
|
||||
if (1 == preg_match('#\.#', $path)) {
|
||||
echo json_encode(array(
|
||||
"state" => "路径不符合规范",
|
||||
"list" => array(),
|
||||
"start" => $start,
|
||||
"total" => 0
|
||||
));
|
||||
exit;
|
||||
}
|
||||
if ('adminlogo' == $path) {
|
||||
$path = 'public/static/admin/logo';
|
||||
} else if ('loginlogo' == $path) {
|
||||
$path = 'public/static/admin/login';
|
||||
} else if ('loginbgimg' == $path) {
|
||||
$path = 'public/static/admin/loginbg';
|
||||
} else {
|
||||
$path = UPLOAD_PATH.$path;
|
||||
}
|
||||
|
||||
/* 获取文件列表 */
|
||||
$files = $this->getfiles($path, $allowFiles, $key);
|
||||
if (empty($files)) {
|
||||
echo json_encode(array(
|
||||
"state" => "没有相关文件",
|
||||
"list" => array(),
|
||||
"start" => $start,
|
||||
"total" => count($files)
|
||||
));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* 获取指定范围的列表 */
|
||||
$len = count($files);
|
||||
for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){
|
||||
$list[] = $files[$i];
|
||||
}
|
||||
|
||||
/* 返回数据 */
|
||||
$result = json_encode(array(
|
||||
"state" => "SUCCESS",
|
||||
"list" => $list,
|
||||
"start" => $start,
|
||||
"total" => count($files)
|
||||
));
|
||||
|
||||
echo $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历获取目录下的指定类型的文件
|
||||
* @param $path
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
private function getfiles($path, $allowFiles, $key, &$files = array()){
|
||||
if (!is_dir($path)) return null;
|
||||
if(substr($path, strlen($path) - 1) != '/') $path .= '/';
|
||||
$handle = opendir($path);
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
$path2 = $path . $file;
|
||||
if (is_dir($path2)) {
|
||||
$this->getfiles($path2, $allowFiles, $key, $files);
|
||||
} else {
|
||||
if (preg_match("/\.(".$allowFiles.")$/i", $file) && preg_match("/.*". $key .".*/i", $file)) {
|
||||
$files[] = array(
|
||||
'url'=> ROOT_DIR.'/'.$path2, // 支持子目录
|
||||
'name'=> $file,
|
||||
'mtime'=> filemtime($path2)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取上传图片目录下的所有图片
|
||||
*
|
||||
* @param string $directory 目录路径
|
||||
* @param string $dir_name 显示的目录前缀路径
|
||||
* @param array $arr_file 是否删除空目录
|
||||
* @param num $num 数量
|
||||
*/
|
||||
private function getDir($directory, &$arr_file = array(), &$num = 0) {
|
||||
$mydir = glob($directory.'/*', GLOB_ONLYDIR);
|
||||
$param = input('param.');
|
||||
if (0 <= $num) {
|
||||
$dirpathArr = explode('/', $directory);
|
||||
$level = count($dirpathArr);
|
||||
$open = (1 >= $level) ? true : false;
|
||||
$fileList = glob($directory.'/*');
|
||||
$total = count($fileList); // 目录是否存在任意文件,否则删除该目录
|
||||
if (!empty($total)) {
|
||||
$isExistPic = $this->isExistPic($directory);
|
||||
if (!empty($isExistPic)) {
|
||||
$arr_file[] = [
|
||||
'id' => $num,
|
||||
'url' => url('Uploadify/get_images_path',['num'=>$param['num'],'func'=>$param['func'],'lang'=>$param['lang'],'images_path'=>$directory]),
|
||||
'target' => 'content_body',
|
||||
'isParent' => true,
|
||||
'open' => $open,
|
||||
'dirpath' => $directory,
|
||||
'level' => $level,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
@rmdir("$directory");
|
||||
}
|
||||
}
|
||||
if (!empty($mydir)) {
|
||||
foreach ($mydir as $key => $dir) {
|
||||
if (stristr("$dir/", 'uploads/soft_tmp/') || stristr("$dir/", 'uploads/tmp/')) {
|
||||
continue;
|
||||
}
|
||||
$num++;
|
||||
$dirname = str_replace('\\', '/', $dir);
|
||||
$dirArr = explode('/', $dirname);
|
||||
$dir = end($dirArr);
|
||||
$mydir2 = glob("$directory/$dir/*", GLOB_ONLYDIR);
|
||||
if(!empty($mydir2) AND ($dir != ".") AND ($dir != ".."))
|
||||
{
|
||||
$this->getDir("$directory/$dir", $arr_file, $num);
|
||||
}
|
||||
else if(($dir != ".") AND ($dir != ".."))
|
||||
{
|
||||
$dirpathArr = explode('/', "$directory/$dir");
|
||||
$level = count($dirpathArr);
|
||||
$fileList = glob("$directory/$dir/*"); // 目录是否存在任意文件,否则删除该目录
|
||||
$total = count($fileList);
|
||||
if (!empty($total)) {
|
||||
// 目录是否存在图片文件,否则删除该目录
|
||||
$isExistPic = $this->isExistPic("$directory/$dir");
|
||||
if (!empty($isExistPic)) {
|
||||
$arr_file[] = [
|
||||
'id' => $num,
|
||||
'url' => url('Uploadify/get_images_path',['num'=>$param['num'],'func'=>$param['func'],'lang'=>$param['lang'],'images_path'=>"$directory/$dir"]),
|
||||
'target' => 'content_body',
|
||||
'isParent' => false,
|
||||
'open' => false,
|
||||
'dirpath' => "$directory/$dir",
|
||||
'level' => $level,
|
||||
'icon' => 'public/plugins/ztree/css/zTreeStyle/img/dir_close.png',
|
||||
'iconOpen' => 'public/plugins/ztree/css/zTreeStyle/img/dir_open.png',
|
||||
'iconClose' => 'public/plugins/ztree/css/zTreeStyle/img/dir_close.png',
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
@rmdir("$directory/$dir");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测指定目录是否存在图片
|
||||
*
|
||||
* @param string $directory 目录路径
|
||||
* @param string $dir_name 显示的目录前缀路径
|
||||
* @param array $arr_file 是否删除空目录
|
||||
* @return boolean
|
||||
*/
|
||||
private function isExistPic($directory, $dir_name='', &$arr_file = [])
|
||||
{
|
||||
if (!file_exists($directory) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($arr_file)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 图片类型数组
|
||||
$image_ext = explode(',', $this->imageExt);
|
||||
$mydir = dir($directory);
|
||||
while($file = $mydir->read())
|
||||
{
|
||||
if((is_dir("$directory/$file")) AND ($file != ".") AND ($file != ".."))
|
||||
{
|
||||
if ($dir_name) {
|
||||
return $this->isExistPic("$directory/$file", "$dir_name/$file", $arr_file);
|
||||
} else {
|
||||
return $this->isExistPic("$directory/$file", "$file", $arr_file);
|
||||
}
|
||||
|
||||
}
|
||||
else if(($file != ".") AND ($file != ".."))
|
||||
{
|
||||
$fileArr = explode('.', $file);
|
||||
$ext = end($fileArr);
|
||||
$ext = strtolower($ext);
|
||||
if (in_array($ext, $image_ext)) {
|
||||
if ($dir_name) {
|
||||
$arr_file[] = "$dir_name/$file";
|
||||
} else {
|
||||
$arr_file[] = "$file";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$mydir->close();
|
||||
|
||||
return $arr_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未开启同步本地功能,并删除本地图片
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function del_local()
|
||||
{
|
||||
if (IS_AJAX_POST) {
|
||||
\think\Session::pause(); // 暂停session,防止session阻塞机制
|
||||
$filename = input('post.filename/s');
|
||||
$filename = strstr($filename, "/uploads/");
|
||||
if (!empty($filename)){
|
||||
$weappList = Db::name('weapp')->field('code,data,status,config')->where([
|
||||
'status' => 1,
|
||||
])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
|
||||
->getAllWithIndex('code');
|
||||
|
||||
if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
|
||||
$weappConfig = json_decode($weappList['Qiniuyun']['config'], true);
|
||||
if (!empty($weappConfig['version']) && 'v1.0.9' <= $weappConfig['version']) {
|
||||
$qnyData = json_decode($weappList['Qiniuyun']['data'], true);
|
||||
if (!empty($qnyData['local_save']) && $qnyData['local_save'] == 1) {
|
||||
$qiniuyunOssModel = new \weapp\Qiniuyun\model\QiniuyunModel;
|
||||
$qiniuyunOssModel->del_local($filename);
|
||||
}
|
||||
}
|
||||
} else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
|
||||
$weappConfig = json_decode($weappList['AliyunOss']['config'], true);
|
||||
if (!empty($weappConfig['version']) && 'v1.0.2' <= $weappConfig['version']) {
|
||||
$ossData = json_decode($weappList['AliyunOss']['data'], true);
|
||||
if (!empty($ossData['local_save']) && $ossData['local_save'] == 1) {
|
||||
$aliyunOssModel = new \weapp\AliyunOss\model\AliyunOssModel;
|
||||
$aliyunOssModel->del_local($filename);
|
||||
}
|
||||
}
|
||||
} else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
|
||||
$cosData = json_decode($weappList['Cos']['data'], true);
|
||||
if (!empty($cosData['local_save']) && $cosData['local_save'] == 1) {
|
||||
$cosModel = new \weapp\Cos\model\CosModel;
|
||||
$cosModel->del_local($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/application/admin/controller/UsersNotice.php
Normal file
10
src/application/admin/controller/UsersNotice.php
Normal file
File diff suppressed because one or more lines are too long
111
src/application/admin/controller/UsersRelease.php
Normal file
111
src/application/admin/controller/UsersRelease.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-07-04
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
|
||||
class UsersRelease extends Base {
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
|
||||
// 会员中心配置信息
|
||||
$this->UsersConfigData = getUsersConfigData('all');
|
||||
$this->assign('userConfig',$this->UsersConfigData);
|
||||
|
||||
// 模型是否开启
|
||||
$channeltype_row = \think\Cache::get('extra_global_channeltype');
|
||||
$this->assign('channeltype_row',$channeltype_row);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商城设置
|
||||
*/
|
||||
public function conf(){
|
||||
if (IS_POST) {
|
||||
$post = input('post.');
|
||||
/*栏目处理*/
|
||||
$typeids = $post['typeids'];
|
||||
unset($post['typeids']);
|
||||
/* END */
|
||||
if (!empty($post)) {
|
||||
foreach ($post as $key => $val) {
|
||||
getUsersConfigData($key, $val);
|
||||
}
|
||||
|
||||
/*设置可投稿的栏目*/
|
||||
$where = [
|
||||
'id' => ['IN', $typeids],
|
||||
];
|
||||
if (0 == $typeids[0]) {
|
||||
$where = [
|
||||
'current_channel' => ['in',[1,3]],
|
||||
'lang' => $this->admin_lang,
|
||||
];
|
||||
}
|
||||
$update = [
|
||||
'is_release' => 1,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
if (!empty($where) && !empty($update)) {
|
||||
/*将全部设置为不可投稿*/
|
||||
Db::name('arctype')->where([
|
||||
'current_channel' => ['in',[1,3]],
|
||||
'lang' => $this->admin_lang,
|
||||
])->update([
|
||||
'is_release' => 0,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
/* END */
|
||||
|
||||
/*设置选择的栏目为可投稿*/
|
||||
Db::name('arctype')->where($where)->update($update);
|
||||
/* END */
|
||||
}
|
||||
/* END */
|
||||
|
||||
$this->success('设置成功!');
|
||||
}
|
||||
}
|
||||
|
||||
// 会员投稿配置信息
|
||||
$UsersC = getUsersConfigData('users');
|
||||
$this->assign('UsersC',$UsersC);
|
||||
|
||||
/*允许发布文档列表的栏目*/
|
||||
$arctype = Db::name('arctype')->where([
|
||||
'current_channel' => ['in',[1,3]],
|
||||
'is_release' => 1,
|
||||
'lang' => $this->admin_lang,
|
||||
])->field('id')->select();
|
||||
$arctype = get_arr_column($arctype,'id');
|
||||
$select_html = allow_release_arctype($arctype, [1,3]);
|
||||
$this->assign('select_html',$select_html);
|
||||
/*--end*/
|
||||
return $this->fetch('conf');
|
||||
}
|
||||
|
||||
public function ajax_users_level_bout()
|
||||
{
|
||||
$UsersLevel = Db::name('users_level')->where('lang',$this->admin_lang)->select();
|
||||
$LevelCount = count($UsersLevel);
|
||||
|
||||
$this->assign('list',$UsersLevel);
|
||||
$this->assign('LevelCount',$LevelCount);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
10
src/application/admin/controller/UsersScore.php
Normal file
10
src/application/admin/controller/UsersScore.php
Normal file
File diff suppressed because one or more lines are too long
1490
src/application/admin/controller/Weapp.php
Normal file
1490
src/application/admin/controller/Weapp.php
Normal file
File diff suppressed because it is too large
Load Diff
3
src/application/admin/controller/debug.txt
Normal file
3
src/application/admin/controller/debug.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
array (
|
||||
'user_name' => 'admin',
|
||||
)
|
||||
23
src/application/admin/html.php
Normal file
23
src/application/admin/html.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
return array(
|
||||
'template' => array(
|
||||
// 模板路径
|
||||
'view_path' => './application/admin/template/',
|
||||
// 模板后缀
|
||||
'view_suffix' => 'htm',
|
||||
),
|
||||
'view_replace_str' => array(),
|
||||
);
|
||||
?>
|
||||
4
src/application/admin/lang/en-us.php
Normal file
4
src/application/admin/lang/en-us.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
);
|
||||
4
src/application/admin/lang/zh-cn.php
Normal file
4
src/application/admin/lang/zh-cn.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return array(
|
||||
|
||||
);
|
||||
786
src/application/admin/logic/AjaxLogic.php
Normal file
786
src/application/admin/logic/AjaxLogic.php
Normal file
@@ -0,0 +1,786 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class AjaxLogic extends Model
|
||||
{
|
||||
private $request = null;
|
||||
private $admin_lang = 'cn';
|
||||
private $main_lang = 'cn';
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->request = request();
|
||||
$this->admin_lang = get_admin_lang();
|
||||
$this->main_lang = get_main_lang();
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入登录页面需要异步处理的业务
|
||||
*/
|
||||
public function login_handle()
|
||||
{
|
||||
$this->saveBaseFile(); // 存储后台入口文件路径,比如:/login.php
|
||||
$this->clear_session_file(); // 清理过期的data/session文件
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入欢迎页面需要异步处理的业务
|
||||
*/
|
||||
public function welcome_handle()
|
||||
{
|
||||
$this->saveBaseFile(); // 存储后台入口文件路径,比如:/login.php
|
||||
$this->renameInstall(); // 重命名安装目录,提高网站安全性
|
||||
$this->del_adminlog(); // 只保留最近一个月的操作日志
|
||||
tpversion(); // 统计装载量,请勿删除,谢谢支持!
|
||||
}
|
||||
|
||||
/**
|
||||
* 只保留最近一个月的操作日志
|
||||
*/
|
||||
private function del_adminlog()
|
||||
{
|
||||
$mtime = strtotime("-1 month");
|
||||
Db::name('admin_log')->where([
|
||||
'log_time' => ['lt', $mtime],
|
||||
])->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名安装目录,提高网站安全性
|
||||
* 在 Admin@login 和 Index@index 操作下
|
||||
*/
|
||||
private function renameInstall()
|
||||
{
|
||||
$install_path = ROOT_PATH.'install';
|
||||
if (is_dir($install_path) && file_exists($install_path)) {
|
||||
$install_time = DEFAULT_INSTALL_DATE;
|
||||
$constsant_path = APP_PATH.'admin/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('INSTALL_DATE') && $install_time = INSTALL_DATE;
|
||||
}
|
||||
$new_path = ROOT_PATH.'install_'.$install_time;
|
||||
@rename($install_path, $new_path);
|
||||
} else { // 修补v1.1.6版本删除的安装文件 install.lock
|
||||
if(!empty($_SESSION['isset_install_lock']))
|
||||
return true;
|
||||
$_SESSION['isset_install_lock'] = 1;
|
||||
|
||||
$install_time = DEFAULT_INSTALL_DATE;
|
||||
$constsant_path = APP_PATH.'admin/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('INSTALL_DATE') && $install_time = INSTALL_DATE;
|
||||
}
|
||||
$filename = ROOT_PATH.'install_'.$install_time.DS.'install.lock';
|
||||
if (!file_exists($filename)) {
|
||||
@file_put_contents($filename, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储后台入口文件路径,比如:/login.php
|
||||
* 在 Admin@login 和 Index@index 操作下
|
||||
*/
|
||||
private function saveBaseFile()
|
||||
{
|
||||
$baseFile = $this->request->baseFile();
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->field('mark')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('web', ['web_adminbasefile'=>$baseFile], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('web', ['web_adminbasefile'=>$baseFile]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理过期的data/session文件
|
||||
*/
|
||||
public function clear_session_file()
|
||||
{
|
||||
$path = \think\Config::get('session.path');
|
||||
if (!empty($path) && file_exists($path)) {
|
||||
$web_login_expiretime = tpCache('web.web_login_expiretime');
|
||||
empty($web_login_expiretime) && $web_login_expiretime = config('login_expire');
|
||||
$files = glob($path.'/sess_*');
|
||||
foreach ($files as $key => $file) {
|
||||
$filemtime = filemtime($file);
|
||||
$filesize = filesize($file);
|
||||
if (empty($filesize) || getTime() - intval($filemtime) > $web_login_expiretime) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级前台会员中心的模板文件
|
||||
*/
|
||||
public function update_template($type = '')
|
||||
{
|
||||
if (!empty($type)) {
|
||||
if ('users' == $type) {
|
||||
if (file_exists(ROOT_PATH.'template/'.TPL_THEME.'pc/users') || file_exists(ROOT_PATH.'template/'.TPL_THEME.'mobile/users')) {
|
||||
$upgrade = getDirFile(DATA_PATH.'backup'.DS.'tpl');
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
delFile(DATA_PATH.'backup'.DS.'template_www');
|
||||
// 升级之前,备份涉及的源文件
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$val_tmp = str_replace("template/", "template/".TPL_THEME, $val);
|
||||
$source_file = ROOT_PATH.$val_tmp;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = DATA_PATH.'backup'.DS.'template_www'.DS.$val_tmp;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
@copy($source_file, $destination_file);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归复制文件夹
|
||||
$this->recurse_copy(DATA_PATH.'backup'.DS.'tpl', rtrim(ROOT_PATH, DS));
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst)
|
||||
{
|
||||
$planPath_pc = "template/".TPL_THEME."pc/";
|
||||
$planPath_m = "template/".TPL_THEME."mobile/";
|
||||
$dir = opendir($src);
|
||||
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$dst_tmp = str_replace('\\', '/', $dst);
|
||||
$dst_tmp = rtrim($dst_tmp, '/').'/';
|
||||
if (stristr($dst_tmp, $planPath_pc) && file_exists($planPath_pc)) {
|
||||
tp_mkdir($dst);
|
||||
} else if (stristr($dst_tmp, $planPath_m) && file_exists($planPath_m)) {
|
||||
tp_mkdir($dst);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$needle = '/template/'.TPL_THEME;
|
||||
$needle = rtrim($needle, '/');
|
||||
$dstfile = $dst . '/' . $file;
|
||||
if (!stristr($dstfile, $needle)) {
|
||||
$dstfile = str_replace('/template', $needle, $dstfile);
|
||||
}
|
||||
$this->recurse_copy($src . '/' . $file, $dstfile);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$rs = true;
|
||||
$src_tmp = str_replace('\\', '/', $src . DIRECTORY_SEPARATOR . $file);
|
||||
if (stristr($src_tmp, $planPath_pc) && !file_exists($planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($src_tmp, $planPath_m) && !file_exists($planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
/*--end*/
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
// 记录当前是多语言还是单语言到文件里
|
||||
public function system_langnum_file()
|
||||
{
|
||||
model('Language')->setLangNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步内置模型内置的附加表字段
|
||||
*/
|
||||
public function admin_logic_model_addfields()
|
||||
{
|
||||
// 修复部分用户的所有模型都不出现编辑器的问题
|
||||
$syn_admin_logic_video_addfields_2 = tpCache('syn.syn_admin_logic_video_addfields_2', [], 'cn');
|
||||
if (empty($syn_admin_logic_video_addfields_2)) {
|
||||
try{
|
||||
$total = Db::name('channelfield_bind')->where(['id'=>['gt', 0]])->count();
|
||||
if (1 == $total) {
|
||||
$channel_id = 5;
|
||||
$field_id = Db::name('channelfield')->where(['channel_id'=>$channel_id,'name'=>'content'])->value('id');
|
||||
if (!empty($field_id)) {
|
||||
$count = Db::name('channelfield_bind')->where(['field_id'=>['NEQ', $field_id]])->count();
|
||||
if (empty($count)) {
|
||||
Db::name('channelfield_bind')->where(['field_id'=>$field_id])->delete();
|
||||
Db::name('channelfield')->where(['channel_id'=>$channel_id])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(\Exception $e){}
|
||||
tpCache('syn', ['syn_admin_logic_video_addfields_2'=>1], 'cn');
|
||||
}
|
||||
|
||||
// 内置视频模型的自定义字段
|
||||
$syn_admin_logic_video_addfields = tpCache('syn.syn_admin_logic_video_addfields', [], 'cn');
|
||||
if ($syn_admin_logic_video_addfields < 5) {
|
||||
try{
|
||||
$channel_id = 5;
|
||||
$result = Db::name('channelfield')->field('id,name,ifmain')->where(['channel_id'=>$channel_id])->getAllWithIndex('name');
|
||||
if (empty($result)) {
|
||||
$fieldLogic = new \app\admin\logic\FieldLogic;
|
||||
$fieldLogic->synChannelTableColumns($channel_id);
|
||||
$result = Db::name('channelfield')->field('id,name,ifmain')->where(['channel_id'=>$channel_id])->getAllWithIndex('name');
|
||||
}
|
||||
|
||||
$bindRow = Db::name('channelfield_bind')->field('field_id')->where(['typeid'=>0])->getAllWithIndex('field_id');
|
||||
if (!empty($bindRow)) {
|
||||
$addData = [];
|
||||
foreach ($result as $key => $val) {
|
||||
if (empty($val['ifmain']) && empty($bindRow[$val['id']])) {
|
||||
$addData[] = [
|
||||
'typeid' => 0,
|
||||
'field_id' => $val['id'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
!empty($addData) && model('ChannelfieldBind')->saveAll($addData);
|
||||
}
|
||||
}catch(\Exception $e){}
|
||||
tpCache('syn', ['syn_admin_logic_video_addfields'=>5], 'cn');
|
||||
}
|
||||
|
||||
// 内置专题模型的自定义字段
|
||||
$syn_admin_logic_special_addfields = tpCache('syn.syn_admin_logic_special_addfields', [], 'cn');
|
||||
if ($syn_admin_logic_special_addfields < 5) {
|
||||
try{
|
||||
$channel_id = 7;
|
||||
$result = Db::name('channelfield')->field('id,name,ifmain')->where(['channel_id'=>$channel_id])->getAllWithIndex('name');
|
||||
if (empty($result)) {
|
||||
$fieldLogic = new \app\admin\logic\FieldLogic;
|
||||
$fieldLogic->synChannelTableColumns($channel_id);
|
||||
$result = Db::name('channelfield')->field('id,name,ifmain')->where(['channel_id'=>$channel_id])->getAllWithIndex('name');
|
||||
}
|
||||
|
||||
$bindRow = Db::name('channelfield_bind')->field('field_id')->where(['typeid'=>0])->getAllWithIndex('field_id');
|
||||
if (!empty($bindRow)) {
|
||||
$addData = [];
|
||||
foreach ($result as $key => $val) {
|
||||
if (empty($val['ifmain']) && empty($bindRow[$val['id']])) {
|
||||
$addData[] = [
|
||||
'typeid' => 0,
|
||||
'field_id' => $val['id'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
!empty($addData) && model('ChannelfieldBind')->saveAll($addData);
|
||||
}
|
||||
}catch(\Exception $e){}
|
||||
tpCache('syn', ['syn_admin_logic_special_addfields'=>5], 'cn');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 补充后台登录logo与背景图
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function admin_logic_1608884981()
|
||||
{
|
||||
$syn_admin_logic_1608884981 = tpCache('syn.syn_admin_logic_1608884981', [], 'cn');
|
||||
if (empty($syn_admin_logic_1608884981)) {
|
||||
$result = Db::name('config')->field('id,desc', true)->where(['name'=>'web_adminlogo'])->select();
|
||||
if (!empty($result)) {
|
||||
$addSave = [];
|
||||
foreach ($result as $key => $val) {
|
||||
$value = $val['value'];
|
||||
|
||||
$val['name'] = 'web_loginlogo';
|
||||
$val['value'] = str_ireplace('logo', 'login-logo', $value);
|
||||
array_push($addSave, $val);
|
||||
|
||||
$val['name'] = 'web_loginbgimg';
|
||||
$val['value'] = str_ireplace('logo', 'login-bg', $value);
|
||||
$val['value'] = str_ireplace('.png', '.jpg', $val['value']);
|
||||
array_push($addSave, $val);
|
||||
}
|
||||
$r = Db::name('config')->insertAll($addSave);
|
||||
if (false !== $r) {
|
||||
tpCache('syn', ['syn_admin_logic_1608884981'=>1], 'cn');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$syn_admin_logic_1608884981_2 = tpCache('syn.syn_admin_logic_1608884981_2', [], 'cn');
|
||||
if (empty($syn_admin_logic_1608884981_2)) {
|
||||
$source = realpath('public/static/admin/images/logo.png');
|
||||
$destination = realpath('public/static/admin/images/login-logo.png');
|
||||
@copy($source, $destination);
|
||||
|
||||
tpCache('syn', ['syn_admin_logic_1608884981_2'=>1], 'cn');
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_logic_1609900642()
|
||||
{
|
||||
$vars1 = 'cGhwLnBo'.'cF9zZXJ2aW'.'NlaW5mbw==';
|
||||
$vars1 = base64_decode($vars1);
|
||||
$data = tpCache($vars1);
|
||||
$data = mchStrCode($data, 'DECODE');
|
||||
$data = json_decode($data, true);
|
||||
if (empty($data['pid']) || 2 > $data['pid']) return true;
|
||||
$file = "./data/conf/{$data['code']}.txt";
|
||||
$vars2 = 'cGhwX3Nl'.'cnZpY2V'.'tZWFs';
|
||||
$vars2 = base64_decode($vars2);
|
||||
if (!file_exists($file)) {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('php', [$vars2=>1], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('php', [$vars2=>1]);
|
||||
}
|
||||
/*--end*/
|
||||
} else {
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('php', [$vars2=>$data['pid']], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('php', [$vars2=>$data['pid']]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内置手机端会员中心底部菜单数据
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function admin_logic_1610086647()
|
||||
{
|
||||
$admin_logic_1610086647 = tpCache('syn.admin_logic_1610086647', [], 'cn');
|
||||
if (empty($admin_logic_1610086647)) {
|
||||
try{
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
$saveData = [
|
||||
[
|
||||
'title' => '首页',
|
||||
'mca' => 'home/Index/index',
|
||||
'icon' => 'shouye',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '下载',
|
||||
'mca' => 'user/Download/index',
|
||||
'icon' => 'xiazai',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '发布',
|
||||
'mca' => 'user/UsersRelease/article_add',
|
||||
'icon' => 'fabu',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '我的',
|
||||
'mca' => 'user/Users/centre',
|
||||
'icon' => 'geren',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
];
|
||||
Db::name('users_bottom_menu')->insertAll($saveData);
|
||||
}
|
||||
} else { // 单语言
|
||||
$saveData = [
|
||||
[
|
||||
'title' => '首页',
|
||||
'mca' => 'home/Index/index',
|
||||
'icon' => 'shouye',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '下载',
|
||||
'mca' => 'user/Download/index',
|
||||
'icon' => 'xiazai',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '发布',
|
||||
'mca' => 'user/UsersRelease/article_add',
|
||||
'icon' => 'fabu',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'title' => '我的',
|
||||
'mca' => 'user/Users/centre',
|
||||
'icon' => 'geren',
|
||||
'sort_order' => 100,
|
||||
'status' => 1,
|
||||
'display' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
];
|
||||
Db::name('users_bottom_menu')->insertAll($saveData);
|
||||
}
|
||||
/*--end*/
|
||||
tpCache('syn', ['admin_logic_1610086647'=>1], 'cn');
|
||||
}catch(\Exception $e){}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内置余额支付开关,控制前台余额支付显示\隐藏 (v1.6.1节点去掉)
|
||||
* 于2021-01-29,v1.5.2版本添加 --- 陈风任
|
||||
*/
|
||||
public function admin_logic_balance_pay()
|
||||
{
|
||||
$syn_admin_logic_balance_pay = tpCache('syn.syn_admin_logic_balance_pay', [], 'cn');
|
||||
if (empty($syn_admin_logic_balance_pay)) {
|
||||
getUsersConfigData('pay', ['pay_balance_open'=>1]);
|
||||
tpCache('syn', ['syn_admin_logic_balance_pay'=>1], 'cn');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 纠正栏目的topid字段值(v1.6.1节点去掉)
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function admin_logic_arctype_topid()
|
||||
{
|
||||
$syn_admin_logic_arctype_topid = tpCache('syn.syn_admin_logic_arctype_topid', [], 'cn');
|
||||
if ($syn_admin_logic_arctype_topid < 2) {
|
||||
$level_0_arr = Db::name('arctype')->field('id, topid')->where('grade', 0)->getAllWithIndex('id');
|
||||
if (!empty($level_0_arr)) {
|
||||
$saveData = [];
|
||||
$level_1_arr = Db::name('arctype')->field('id, parent_id')->where(['grade'=>1, 'topid'=>0])->select();
|
||||
foreach ($level_1_arr as $key => $val) {
|
||||
$topid = !empty($level_0_arr[$val['parent_id']]) ? intval($level_0_arr[$val['parent_id']]['id']) : 0;
|
||||
$saveData[] = [
|
||||
'id' => $val['id'],
|
||||
'topid' => $topid,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
if (!empty($saveData)) {
|
||||
model('Arctype')->saveAll($saveData);
|
||||
}
|
||||
}
|
||||
|
||||
$level_1_arr = Db::name('arctype')->field('id, topid')->where('grade', 1)->getAllWithIndex('id');
|
||||
if (!empty($level_1_arr)) {
|
||||
$saveData = [];
|
||||
$level_2_arr = Db::name('arctype')->field('id, parent_id')->where(['grade'=>2, 'topid'=>0])->select();
|
||||
foreach ($level_2_arr as $key => $val) {
|
||||
$topid = !empty($level_1_arr[$val['parent_id']]) ? intval($level_1_arr[$val['parent_id']]['topid']) : 0;
|
||||
$saveData[] = [
|
||||
'id' => $val['id'],
|
||||
'topid' => $topid,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
if (!empty($saveData)) {
|
||||
model('Arctype')->saveAll($saveData);
|
||||
}
|
||||
}
|
||||
|
||||
\think\Cache::clear("arctype");
|
||||
tpCache('syn', ['syn_admin_logic_arctype_topid'=>2], 'cn');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档图片自适应修改为默认关闭(v1.6.1节点去掉)
|
||||
*/
|
||||
public function admin_logic_1610086648()
|
||||
{
|
||||
$syn_admin_logic_1610086648 = tpCache('syn.syn_admin_logic_1610086648', [], 'cn');
|
||||
if (empty($syn_admin_logic_1610086648)) {
|
||||
$row = Db::name('config')->where(['name'=>'basic_img_style_wh'])->find();
|
||||
if (empty($row)) {
|
||||
tpCache('basic', ['basic_img_style_wh'=>0]);
|
||||
}
|
||||
tpCache('syn', ['syn_admin_logic_1610086648'=>1], 'cn');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 补充站内信模板的数据(v1.6.1节点去掉)
|
||||
*/
|
||||
public function admin_logic_1614829120()
|
||||
{
|
||||
$syn_admin_logic_1614829120 = tpCache('syn.syn_admin_logic_1614829120', [], 'cn');
|
||||
if (empty($syn_admin_logic_1614829120)) {
|
||||
try{
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$saveData = [];
|
||||
$langRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
$i = 1;
|
||||
foreach ($langRow as $key => $val) {
|
||||
$saveData = [
|
||||
[
|
||||
'tpl_id' => 1,
|
||||
'tpl_name' => '留言表单',
|
||||
'tpl_title' => '您有新的留言消息,请到内容管理中查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 1,
|
||||
'is_open' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'tpl_id' => 5,
|
||||
'tpl_name' => '订单付款',
|
||||
'tpl_title' => '您有新的待发货订单消息,请到商城订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 5,
|
||||
'is_open' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'tpl_id' => 6,
|
||||
'tpl_name' => '订单发货',
|
||||
'tpl_title' => '您有新的待收货订单消息,请到会员订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 6,
|
||||
'is_open' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
];
|
||||
if ($i != 1) {
|
||||
foreach ($saveData as $_k => $_v) {
|
||||
unset($saveData[$_k]['tpl_id']);
|
||||
}
|
||||
}
|
||||
Db::name('users_notice_tpl')->insertAll($saveData);
|
||||
$i++;
|
||||
}
|
||||
} else { // 单语言
|
||||
$saveData = [
|
||||
[
|
||||
'tpl_id' => 1,
|
||||
'tpl_name' => '留言表单',
|
||||
'tpl_title' => '您有新的留言消息,请到内容管理中查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 1,
|
||||
'is_open' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'tpl_id' => 5,
|
||||
'tpl_name' => '订单付款',
|
||||
'tpl_title' => '您有新的待发货订单消息,请到商城订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 5,
|
||||
'is_open' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
[
|
||||
'tpl_id' => 6,
|
||||
'tpl_name' => '订单发货',
|
||||
'tpl_title' => '您有新的待收货订单消息,请到会员订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 6,
|
||||
'is_open' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
];
|
||||
Db::name('users_notice_tpl')->insertAll($saveData);
|
||||
}
|
||||
/*--end*/
|
||||
tpCache('syn', ['syn_admin_logic_1614829120'=>1], 'cn');
|
||||
}catch(\Exception $e){}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 补充邮箱/短信模板的数据(v1.6.1节点去掉)
|
||||
*/
|
||||
public function admin_logic_1616123192()
|
||||
{
|
||||
$syn_admin_logic_1616123192 = tpCache('syn.syn_admin_logic_1616123192', [], 'cn');
|
||||
if (empty($syn_admin_logic_1616123192)) {
|
||||
try{
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
/*邮箱模板 start*/
|
||||
Db::name('smtp_tpl')->where(['send_scene'=>5])->update([
|
||||
'tpl_name' => '订单付款',
|
||||
'tpl_title' => '您有新的待发货订单消息,请到商城订单查看!',
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
$saveData = [];
|
||||
$langRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
$saveData = [
|
||||
[
|
||||
'tpl_name' => '订单发货',
|
||||
'tpl_title' => '您有新的待收货订单消息,请到会员订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 6,
|
||||
'is_open' => 1,
|
||||
'lang' => $val['mark'],
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
],
|
||||
];
|
||||
Db::name('smtp_tpl')->insertAll($saveData);
|
||||
}
|
||||
/*邮箱模板 end*/
|
||||
|
||||
/*短信模板 start*/
|
||||
Db::name('sms_template')->where(['send_scene'=>5])->update([
|
||||
'tpl_title' => '订单付款',
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
$saveData = Db::name('sms_template')->field('tpl_id', true)->where(['send_scene'=>5])->select();
|
||||
if (!empty($saveData)) {
|
||||
foreach ($saveData as $key => $val) {
|
||||
$val['tpl_title'] = '订单发货';
|
||||
$val['send_scene'] = 6;
|
||||
$saveData[$key] = $val;
|
||||
}
|
||||
Db::name('sms_template')->insertAll($saveData);
|
||||
}
|
||||
/*短信模板 end*/
|
||||
}
|
||||
else { // 单语言
|
||||
/*邮箱模板 start*/
|
||||
Db::name('smtp_tpl')->where(['send_scene'=>5])->update([
|
||||
'tpl_name' => '订单付款',
|
||||
'tpl_title' => '您有新的待发货订单消息,请到商城订单查看!',
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
Db::name('smtp_tpl')->insert([
|
||||
'tpl_name' => '订单发货',
|
||||
'tpl_title' => '您有新的待收货订单消息,请到会员订单查看!',
|
||||
'tpl_content' => '${content}',
|
||||
'send_scene' => 6,
|
||||
'is_open' => 1,
|
||||
'lang' => get_main_lang(),
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
/*邮箱模板 end*/
|
||||
|
||||
/*短信模板 start*/
|
||||
Db::name('sms_template')->where(['send_scene'=>5])->update([
|
||||
'tpl_title' => '订单付款',
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
$saveData = Db::name('sms_template')->field('tpl_id', true)->where(['send_scene'=>5])->select();
|
||||
if (!empty($saveData)) {
|
||||
foreach ($saveData as $key => $val) {
|
||||
$val['tpl_title'] = '订单发货';
|
||||
$val['send_scene'] = 6;
|
||||
$saveData[$key] = $val;
|
||||
}
|
||||
Db::name('sms_template')->insertAll($saveData);
|
||||
}
|
||||
/*短信模板 end*/
|
||||
}
|
||||
/*--end*/
|
||||
tpCache('syn', ['syn_admin_logic_1616123192'=>1], 'cn');
|
||||
}catch(\Exception $e){}
|
||||
}
|
||||
}
|
||||
}
|
||||
349
src/application/admin/logic/ArchivesLogic.php
Normal file
349
src/application/admin/logic/ArchivesLogic.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
/**
|
||||
* 文档逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
load_trait('controller/Jump');
|
||||
class ArchivesLogic extends Model
|
||||
{
|
||||
use \traits\controller\Jump;
|
||||
|
||||
private $admin_lang = 'cn';
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->admin_lang = get_admin_lang();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文档
|
||||
*/
|
||||
public function del($del_id = array(), $thorough = 0)
|
||||
{
|
||||
if (empty($del_id)) {
|
||||
$del_id = input('del_id/a');
|
||||
}
|
||||
if (empty($thorough)) {
|
||||
$thorough = input('thorough/d');
|
||||
}
|
||||
|
||||
$id_arr = eyIntval($del_id);
|
||||
if(!empty($id_arr)){
|
||||
/*分离并组合相同模型下的文档ID*/
|
||||
$row = Db::name('archives')
|
||||
->alias('a')
|
||||
->field('a.channel,a.aid,b.table,b.ctl_name,b.ifsystem')
|
||||
->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
|
||||
->where([
|
||||
'a.aid' => ['IN', $id_arr],
|
||||
'a.lang' => $this->admin_lang,
|
||||
])
|
||||
->select();
|
||||
$data = array();
|
||||
foreach ($row as $key => $val) {
|
||||
$data[$val['channel']]['aid'][] = $val['aid'];
|
||||
$data[$val['channel']]['table'] = $val['table'];
|
||||
if (empty($val['ifsystem'])) {
|
||||
$ctl_name = 'Custom';
|
||||
} else {
|
||||
$ctl_name = $val['ctl_name'];
|
||||
}
|
||||
$data[$val['channel']]['ctl_name'] = $ctl_name;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if (1 == $thorough) { // 直接删除,跳过回收站
|
||||
$err = 0;
|
||||
foreach ($data as $key => $val) {
|
||||
$r = M('archives')->where('aid','IN',$val['aid'])->delete();
|
||||
if ($r) {
|
||||
if (empty($val['ifsystem'])) {
|
||||
model($val['ctl_name'])->afterDel($val['aid'], $val['table']);
|
||||
} else {
|
||||
model($val['ctl_name'])->afterDel($val['aid']);
|
||||
}
|
||||
adminLog('删除文档-id:'.implode(',', $val['aid']));
|
||||
} else {
|
||||
$err++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$info['is_del'] = 1; // 伪删除状态
|
||||
$info['update_time']= getTime(); // 更新修改时间
|
||||
$info['del_method'] = 1; // 恢复删除方式为默认
|
||||
|
||||
$err = 0;
|
||||
foreach ($data as $key => $val) {
|
||||
$r = M('archives')->where('aid','IN',$val['aid'])->update($info);
|
||||
if ($r) {
|
||||
adminLog('删除文档-id:'.implode(',', $val['aid']));
|
||||
} else {
|
||||
$err++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == $err) {
|
||||
$this->success('删除成功!');
|
||||
} else if ($err < count($data)) {
|
||||
$this->success('删除部分成功!');
|
||||
} else {
|
||||
$this->error('删除失败!');
|
||||
}
|
||||
}else{
|
||||
$this->error('文档不存在!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档模板文件列表
|
||||
*/
|
||||
public function getTemplateList($nid = 'article')
|
||||
{
|
||||
$planPath = 'template/'.TPL_THEME.'pc';
|
||||
$dirRes = opendir($planPath);
|
||||
$view_suffix = config('template.view_suffix');
|
||||
|
||||
/*模板PC目录文件列表*/
|
||||
$templateArr = array();
|
||||
while($filename = readdir($dirRes))
|
||||
{
|
||||
if (in_array($filename, array('.','..'))) {
|
||||
continue;
|
||||
}
|
||||
array_push($templateArr, $filename);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*多语言全部标识*/
|
||||
$markArr = Db::name('language_mark')->column('mark');
|
||||
/*--end*/
|
||||
|
||||
$templateList = array();
|
||||
foreach ($templateArr as $k2 => $v2) {
|
||||
$v2 = iconv('GB2312', 'UTF-8', $v2);
|
||||
preg_match('/^(view)_'.$nid.'(_(.*))?(_'.$this->admin_lang.')?\.'.$view_suffix.'/i', $v2, $matches1);
|
||||
$langtpl = preg_replace('/\.'.$view_suffix.'$/i', "_{$this->admin_lang}.{$view_suffix}", $v2);
|
||||
if (file_exists(realpath($planPath.DS.$langtpl))) {
|
||||
continue;
|
||||
} else if (preg_match('/^(.*)_([a-zA-z]{2,2})\.'.$view_suffix.'$/i',$v2,$matches2)) {
|
||||
if (in_array($matches2[2], $markArr) && $matches2[2] != $this->admin_lang) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($matches1)) {
|
||||
if ('view' == $matches1[1]) {
|
||||
array_push($templateList, $v2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $templateList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文档
|
||||
*/
|
||||
public function batch_copy($aids = [], $typeid, $channel, $num = 1)
|
||||
{
|
||||
// 获取复制栏目的模型ID
|
||||
$channeltypeRow = Db::name('channeltype')->field('nid,table')
|
||||
->where([
|
||||
'id' => $channel,
|
||||
])->find();
|
||||
if (!empty($channeltypeRow)) {
|
||||
// 主表数据
|
||||
$archivesRow = Db::name('archives')->where(['aid'=>['IN', $aids]])->select();
|
||||
// 内容扩展表数据
|
||||
$tableExt = $channeltypeRow['table']."_content";
|
||||
$contentRow = Db::name($tableExt)->field('id', true)->where(['aid'=>['IN', $aids]])->getAllWithIndex('aid');
|
||||
|
||||
// 拥有特性模型的其他数据处理
|
||||
if ('images' == $channeltypeRow['nid']) { // 图集模型的特性表数据
|
||||
$imgUploadRow = Db::name('images_upload')->field('img_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$imgUploadRow = group_same_key($imgUploadRow, 'aid');
|
||||
}
|
||||
else if ('download' == $channeltypeRow['nid']) { // 下载模型的特性表数据
|
||||
// 附件表
|
||||
$downloadFileRow = Db::name('download_file')->field('file_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$downloadFileRow = group_same_key($downloadFileRow, 'aid');
|
||||
// 附件下载记录表
|
||||
$downloadLogRow = Db::name('download_log')->field('log_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$downloadLogRow = group_same_key($downloadLogRow, 'aid');
|
||||
}
|
||||
else if ('product' == $channeltypeRow['nid']) { // 产品模型的特性表数据
|
||||
// 属性值表
|
||||
$productAttrRow = Db::name('product_attr')->field('product_attr_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$productAttrRow = group_same_key($productAttrRow, 'aid');
|
||||
// 产品图集表
|
||||
$productImgRow = Db::name('product_img')->field('img_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$productImgRow = group_same_key($productImgRow, 'aid');
|
||||
// 产品虚拟表
|
||||
$productNetdiskRow = Db::name('product_netdisk')->field('nd_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$productNetdiskRow = group_same_key($productNetdiskRow, 'aid');
|
||||
// 产品规格数据表
|
||||
$productSpecRow = Db::name('product_spec_data')->field('spec_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$productSpecRow = group_same_key($productSpecRow, 'aid');
|
||||
// 产品多规格组装表
|
||||
$productSpecValueRow = Db::name('product_spec_value')->field('value_id', true)->where(['aid'=>['IN', $aids]])->select();
|
||||
$productSpecValueRow = group_same_key($productSpecValueRow, 'aid');
|
||||
}
|
||||
|
||||
foreach ($archivesRow as $key => $val) {
|
||||
// 原先数据的栏目ID
|
||||
$typeid_old = $val['typeid'];
|
||||
|
||||
// 同步数据
|
||||
$archivesData = [];
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
// 主表
|
||||
$archivesInfo = $val;
|
||||
unset($archivesInfo['aid']);
|
||||
$archivesInfo['typeid'] = $typeid;
|
||||
$archivesInfo['add_time'] = getTime();
|
||||
$archivesInfo['update_time'] = getTime();
|
||||
$archivesData[] = $archivesInfo;
|
||||
}
|
||||
if (!empty($archivesData)) {
|
||||
$rdata = model('Archives')->saveAll($archivesData);
|
||||
if ($rdata) {
|
||||
// 内容扩展表的数据
|
||||
$contentData = [];
|
||||
$contentInfo = $contentRow[$val['aid']];
|
||||
|
||||
// 拥有特性模型的其他数据处理
|
||||
$imgUploadInfo = $imgUploadData = [];
|
||||
$downloadFileInfo = $downloadLogInfo = [];
|
||||
$downloadFileData = $downloadLogData = [];
|
||||
$productAttrInfo = $productImgInfo = $productNetdiskInfo = $productSpecInfo = $productSpecValueInfo = [];
|
||||
$productAttrData = $productImgData = $productNetdiskData = $productSpecData = $productSpecValueData = [];
|
||||
if ('images' == $channeltypeRow['nid']) { // 图集模型的特性表数据
|
||||
$imgUploadInfo = !empty($imgUploadRow[$val['aid']]) ? $imgUploadRow[$val['aid']] : [];
|
||||
} else if ('download' == $channeltypeRow['nid']) { // 下载模型的特性表数据
|
||||
$downloadFileInfo = !empty($downloadFileRow[$val['aid']]) ? $downloadFileRow[$val['aid']] : [];
|
||||
$downloadLogInfo = !empty($downloadLogRow[$val['aid']]) ? $downloadLogRow[$val['aid']] : [];
|
||||
} else if ('product' == $channeltypeRow['nid']) { // 新房模型的特性表数据
|
||||
// 属性值表 - 只复制同栏目的属性值
|
||||
if ($typeid_old == $typeid) {
|
||||
$productAttrInfo = !empty($productAttrRow[$val['aid']]) ? $productAttrRow[$val['aid']] : [];
|
||||
}
|
||||
// 产品图集表
|
||||
$productImgInfo = !empty($productImgRow[$val['aid']]) ? $productImgRow[$val['aid']] : [];
|
||||
// 产品虚拟表
|
||||
$productNetdiskInfo = !empty($productNetdiskRow[$val['aid']]) ? $productNetdiskRow[$val['aid']] : [];
|
||||
// 产品规格数据表
|
||||
$productSpecInfo = !empty($productSpecRow[$val['aid']]) ? $productSpecRow[$val['aid']] : [];
|
||||
// 产品多规格组装表
|
||||
$productSpecValueInfo = !empty($productSpecValueRow[$val['aid']]) ? $productSpecValueRow[$val['aid']] : [];
|
||||
}
|
||||
|
||||
// 需要复制的数据与新产生的文档ID进行关联
|
||||
foreach ($rdata as $k1 => $v1) {
|
||||
$aid_new = $v1->getData('aid');
|
||||
|
||||
// 内容扩展表的数据
|
||||
$contentInfo['aid'] = $aid_new;
|
||||
$contentData[] = $contentInfo;
|
||||
|
||||
// 图集模型
|
||||
if ('images' == $channeltypeRow['nid']) {
|
||||
foreach ($imgUploadInfo as $img_k => $img_v) {
|
||||
$img_v['aid'] = $aid_new;
|
||||
$imgUploadData[] = $img_v;
|
||||
}
|
||||
} else if ('download' == $channeltypeRow['nid']) {
|
||||
// 附件表
|
||||
foreach ($downloadFileInfo as $file_k => $file_v) {
|
||||
$file_v['aid'] = $aid_new;
|
||||
$downloadFileData[] = $file_v;
|
||||
}
|
||||
// 附件下载记录表
|
||||
foreach ($downloadLogInfo as $log_k => $log_v) {
|
||||
$log_v['aid'] = $aid_new;
|
||||
$downloadLogData[] = $log_v;
|
||||
}
|
||||
} else if ('product' == $channeltypeRow['nid']) {
|
||||
// 属性值表
|
||||
foreach ($productAttrInfo as $attr_k => $attr_v) {
|
||||
$attr_v['aid'] = $aid_new;
|
||||
$productAttrData[] = $attr_v;
|
||||
}
|
||||
// 产品图集表
|
||||
foreach ($productImgInfo as $img_k => $img_v) {
|
||||
$img_v['aid'] = $aid_new;
|
||||
$productImgData[] = $img_v;
|
||||
}
|
||||
// 产品虚拟表
|
||||
foreach ($productNetdiskInfo as $nd_k => $nd_v) {
|
||||
$nd_v['aid'] = $aid_new;
|
||||
$productNetdiskData[] = $nd_v;
|
||||
}
|
||||
// 产品规格数据表
|
||||
foreach ($productSpecInfo as $spec_k => $spec_v) {
|
||||
$spec_v['aid'] = $aid_new;
|
||||
$productSpecData[] = $spec_v;
|
||||
}
|
||||
// 产品多规格组装表
|
||||
foreach ($productSpecValueInfo as $specv_k => $specv_v) {
|
||||
$specv_v['aid'] = $aid_new;
|
||||
$productSpecValueData[] = $specv_v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量写入内容扩展表
|
||||
if (!empty($contentData)) {
|
||||
Db::name($tableExt)->insertAll($contentData);
|
||||
}
|
||||
// 批量写入图集模型的图片表
|
||||
if ('images' == $channeltypeRow['nid']) {
|
||||
!empty($imgUploadData) && model('ImagesUpload')->saveAll($imgUploadData);
|
||||
} else if ('download' == $channeltypeRow['nid']) {
|
||||
// 附件表
|
||||
!empty($downloadFileData) && model('DownloadFile')->saveAll($downloadFileData);
|
||||
// 附件下载记录表
|
||||
!empty($downloadLogData) && Db::name('download_log')->insertAll($downloadLogData);
|
||||
} else if ('product' == $channeltypeRow['nid']) {
|
||||
// 属性值表
|
||||
!empty($productAttrData) && Db::name('product_attr')->insertAll($productAttrData);
|
||||
// 产品图集表
|
||||
!empty($productImgData) && model('ProductImg')->saveAll($productImgData);
|
||||
// 产品虚拟表
|
||||
!empty($productNetdiskData) && model('ProductNetdisk')->saveAll($productNetdiskData);
|
||||
// 产品规格数据表
|
||||
!empty($productSpecData) && model('ProductSpecData')->saveAll($productSpecData);
|
||||
// 产品多规格组装表
|
||||
!empty($productSpecValueData) && model('ProductSpecValue')->saveAll($productSpecValueData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->error('复制失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->success('复制成功!');
|
||||
} else {
|
||||
$this->error('模型不存在!');
|
||||
}
|
||||
}
|
||||
}
|
||||
525
src/application/admin/logic/AskLogic.php
Normal file
525
src/application/admin/logic/AskLogic.php
Normal file
@@ -0,0 +1,525 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class AskLogic extends Model
|
||||
{
|
||||
private $request = null;
|
||||
private $data_path;
|
||||
private $service_url;
|
||||
private $upgrade_url;
|
||||
private $service_ey;
|
||||
private $planPath_pc;
|
||||
private $planPath_m;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->request = request();
|
||||
$this->service_ey = config('service_ey');
|
||||
$this->data_path = DATA_PATH; //
|
||||
// api_Service_checkVersion
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT1jaGVja1RoZW1lVmVyc2lvbg==';
|
||||
$this->service_url = base64_decode($this->service_ey).base64_decode($tmp_str);
|
||||
$web_basehost = request()->host(true);
|
||||
if (false !== filter_var($web_basehost, FILTER_VALIDATE_IP)) {
|
||||
$web_basehost = tpCache('web.web_basehost');
|
||||
}
|
||||
$web_basehost = preg_replace('/^(([^\:]+):)?(\/\/)?([^\/\:]*)(.*)$/i', '${4}', $web_basehost);
|
||||
$this->upgrade_url = $this->service_url . '&domain='.$web_basehost.'&type=theme_ask&ip='.serverIP();
|
||||
$this->planPath_pc = 'template/'.TPL_THEME.'pc/';
|
||||
$this->planPath_m = 'template/'.TPL_THEME.'mobile/';
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测并第一次从官方同步问答中心的前台模板
|
||||
*/
|
||||
public function syn_theme_ask()
|
||||
{
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
if (!file_exists("./{$this->planPath_pc}ask")) {
|
||||
return $this->OneKeyUpgrade();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测目录权限
|
||||
*/
|
||||
public function checkAuthority($filelist = '')
|
||||
{
|
||||
/*------------------检测目录读写权限----------------------*/
|
||||
$filelist = htmlspecialchars_decode($filelist);
|
||||
$filelist = explode('<br>', $filelist);
|
||||
|
||||
$dirs = array();
|
||||
$i = -1;
|
||||
foreach($filelist as $filename)
|
||||
{
|
||||
if (stristr($filename, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($filename, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tfilename = $filename;
|
||||
$curdir = $this->GetDirName($tfilename);
|
||||
if (empty($curdir)) {
|
||||
continue;
|
||||
}
|
||||
if( !isset($dirs[$curdir]) )
|
||||
{
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
if($dirs[$curdir]['isdir'] == FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$is_pass = true;
|
||||
$msg = '检测通过';
|
||||
if($i > -1)
|
||||
{
|
||||
$n = 0;
|
||||
$dirinfos = '';
|
||||
foreach($dirs as $curdir)
|
||||
{
|
||||
$dirinfos .= $curdir['name']." 状态:";
|
||||
if ($curdir['writeable']) {
|
||||
$dirinfos .= "[√正常]";
|
||||
} else {
|
||||
$is_pass = false;
|
||||
$n++;
|
||||
$dirinfos .= "<font color='red'>[×不可写]</font>";
|
||||
}
|
||||
$dirinfos .= "<br />";
|
||||
}
|
||||
$title = "本次升级需要在下面文件夹写入更新文件,已检测站点有 <font color='red'>{$n}</font> 处没有写入权限:<br />";
|
||||
$title .= "<font color='red'>问题分析(如有问题,请咨询技术支持):<br />";
|
||||
$title .= "1、检查站点目录的用户组与所有者,禁止是 root ;<br />";
|
||||
$title .= "2、检查站点目录的读写权限,一般权限值是 0755 ;<br />";
|
||||
$title .= "</font>涉及更新目录列表如下:<br />";
|
||||
$msg = $title . $dirinfos;
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
if (true === $is_pass) {
|
||||
return ['code'=>1, 'msg'=>$msg];
|
||||
} else {
|
||||
return ['code'=>0, 'msg'=>$msg, 'data'=>['code'=>1]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkVersion() {
|
||||
//error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 1, 'msg' => "<font color='red'>请联系空间商(设置 php.ini 中参数 allow_url_fopen = 1)</font>"];
|
||||
}
|
||||
|
||||
$url = $this->upgrade_url;
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
|
||||
$serviceVersionList = @file_get_contents($url,false,$context);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if(!empty($serviceVersionList))
|
||||
{
|
||||
$upgradeArr = array();
|
||||
$introStr = '';
|
||||
$upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br>'.filter_line_return($val['intro'], '<br>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
foreach ($upgradeArr as $key => $val) {
|
||||
if (stristr($val, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
unset($upgradeArr[$key]);
|
||||
} else if (stristr($val, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
unset($upgradeArr[$key]);
|
||||
}
|
||||
}
|
||||
$upgradeStr = implode('<br>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function OneKeyUpgrade() {
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,设置 php.ini 中参数 allow_url_fopen = 1"];
|
||||
}
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,开启 php.ini 中的php-zip扩展"];
|
||||
}
|
||||
|
||||
$serviceVersionList = @file_get_contents($this->upgrade_url);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if (empty($serviceVersionList)) {
|
||||
return ['code' => 0, 'msg' => "没找到模板包信息"];
|
||||
} else if (isset($serviceVersionList['code']) && empty($serviceVersionList['code'])) {
|
||||
$icon = !empty($serviceVersionList['icon']) ? $serviceVersionList['icon'] : 2;
|
||||
return ['code' => 0, 'msg' => $serviceVersionList['msg'], 'icon'=>$icon];
|
||||
}
|
||||
|
||||
/*最新更新版本信息*/
|
||||
$lastServiceVersion = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
/*--end*/
|
||||
/*批量下载更新包*/
|
||||
$upgradeArr = array(); // 更新的文件列表
|
||||
$folderName = 'ask-'.$lastServiceVersion['key_num'];
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
// 下载更新包
|
||||
$result = $this->downloadFile($val['down_url'], $val['file_md5']);
|
||||
if (!isset($result['code']) || $result['code'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*第一个循环执行的业务*/
|
||||
if ($key == 0) {
|
||||
/*解压到最后一个更新包的文件夹*/
|
||||
$lastDownFileName = explode('/', $lastServiceVersion['down_url']);
|
||||
$lastDownFileName = end($lastDownFileName);
|
||||
$folderName = 'ask-'.str_replace(".zip", "", $lastDownFileName); // 文件夹
|
||||
/*--end*/
|
||||
|
||||
/*解压之前,删除已重复的文件夹*/
|
||||
delFile($this->data_path.'backup'.DS.'theme'.DS.$folderName);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$downFileName = explode('/', $val['down_url']);
|
||||
$downFileName = 'ask-'.end($downFileName);
|
||||
|
||||
/*解压文件*/
|
||||
$zip = new \ZipArchive();//新建一个ZipArchive的对象
|
||||
if ($zip->open($this->data_path.'backup'.DS.'theme'.DS.$downFileName) != true) {
|
||||
return ['code' => 0, 'msg' => "模板包读取失败!"];
|
||||
}
|
||||
$zip->extractTo($this->data_path.'backup'.DS.'theme'.DS.$folderName.DS);//假设解压缩到在当前路径下backup文件夹内
|
||||
$zip->close();//关闭处理的zip文件
|
||||
/*--end*/
|
||||
|
||||
/*更新的文件列表*/
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*将多个更新包重新组建一个新的完全更新包*/
|
||||
$upgradeArr = array_unique($upgradeArr); // 移除文件列表里重复的文件
|
||||
$serviceVersion = $lastServiceVersion;
|
||||
$serviceVersion['upgrade'] = $upgradeArr;
|
||||
/*--end*/
|
||||
|
||||
/*升级之前,备份涉及的源文件*/
|
||||
$upgrade = $serviceVersion['upgrade'];
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$source_file = ROOT_PATH.$val;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = $this->data_path.'backup'.DS.'theme'.DS.$folderName.'_www'.DS.$val;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
$copy_bool = @copy($source_file, $destination_file);
|
||||
if (false == $copy_bool) {
|
||||
return ['code' => 0, 'msg' => "备份文件失败,请检查所有目录是否有读写权限"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 递归复制文件夹
|
||||
$copy_data = $this->recurse_copy($this->data_path.'backup'.DS.'theme'.DS.$folderName, rtrim(ROOT_PATH, DS), $folderName);
|
||||
|
||||
/*删除下载的模板包*/
|
||||
$ziplist = glob($this->data_path.'backup'.DS.'theme'.DS.'ask-*.zip');
|
||||
@array_map('unlink', $ziplist);
|
||||
/*--end*/
|
||||
|
||||
// 推送回服务器 记录升级成功
|
||||
$this->UpgradeLog($serviceVersion['key_num']);
|
||||
|
||||
return ['code' => $copy_data['code'], 'msg' => "更新模板成功{$copy_data['msg']}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @param string $folderName 存放升级包目录名称
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst, $folderName)
|
||||
{
|
||||
static $badcp = 0; // 累计覆盖失败的文件总数
|
||||
static $n = 0; // 累计执行覆盖的文件总数
|
||||
static $total = 0; // 累计更新的文件总数
|
||||
|
||||
$dir = opendir($src);
|
||||
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$dst_tmp = str_replace('\\', '/', $dst);
|
||||
$dst_tmp = rtrim($dst_tmp, '/').'/';
|
||||
if (stristr($dst_tmp, $this->planPath_pc) && file_exists($this->planPath_pc)) {
|
||||
tp_mkdir($dst);
|
||||
} else if (stristr($dst_tmp, $this->planPath_m) && file_exists($this->planPath_m)) {
|
||||
tp_mkdir($dst);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$needle = '/template/'.TPL_THEME;
|
||||
$needle = rtrim($needle, '/');
|
||||
$dstfile = $dst . '/' . $file;
|
||||
if (!stristr($dstfile, $needle)) {
|
||||
$dstfile = str_replace('/template', $needle, $dstfile);
|
||||
}
|
||||
$this->recurse_copy($src . '/' . $file, $dstfile, $folderName);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$rs = true;
|
||||
$src_tmp = str_replace('\\', '/', $src . DIRECTORY_SEPARATOR . $file);
|
||||
if (stristr($src_tmp, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($src_tmp, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
/*--end*/
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
$n++;
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
} else {
|
||||
$n++;
|
||||
$badcp++;
|
||||
}
|
||||
} else {
|
||||
$n++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
$code = 1;
|
||||
$msg = '!';
|
||||
if($badcp > 0)
|
||||
{
|
||||
$code = 2;
|
||||
$msg = ",其中失败 <font color='red'>{$badcp}</font> 个文件,<br />请从模板包目录[<font color='red'>data/backup/theme/{$folderName}</font>]中的取出全部文件覆盖到根目录,完成手工覆盖。";
|
||||
}
|
||||
|
||||
$this->copy_speed($n, $total);
|
||||
|
||||
return ['code'=>$code, 'msg'=>$msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文件进度
|
||||
*/
|
||||
private function copy_speed($n, $total)
|
||||
{
|
||||
$data = false;
|
||||
|
||||
if ($n < $total) {
|
||||
$this->copy_speed($n, $total);
|
||||
} else {
|
||||
$data = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type $fileUrl 下载文件地址
|
||||
* @param type $md5File 文件MD5 加密值 用于对比下载是否完整
|
||||
* @return string 错误或成功提示
|
||||
*/
|
||||
private function downloadFile($fileUrl,$md5File)
|
||||
{
|
||||
$downFileName = explode('/', $fileUrl);
|
||||
$downFileName = 'ask-'.end($downFileName);
|
||||
$saveDir = $this->data_path.'backup'.DS.'theme'.DS.$downFileName; // 保存目录
|
||||
tp_mkdir(dirname($saveDir));
|
||||
$content = @file_get_contents($fileUrl, 0, null, 0, 1);
|
||||
if (false === $content) {
|
||||
$fileUrl = str_replace('http://service', 'https://service', $fileUrl);
|
||||
$content = @file_get_contents($fileUrl, 0, null, 0, 1);
|
||||
}
|
||||
|
||||
if(!$content){
|
||||
return ['code' => 0, 'msg' => '官方问答模板包不存在']; // 文件存在直接退出
|
||||
}
|
||||
|
||||
if (!stristr($fileUrl, 'https://service')) {
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
$file = curl_exec ($ch);
|
||||
} else {
|
||||
$file = httpRequest($fileUrl);
|
||||
}
|
||||
|
||||
if (preg_match('#__HALT_COMPILER()#i', $file)) {
|
||||
return ['code' => 0, 'msg' => '问答模板包损坏,请联系官方客服!'];
|
||||
}
|
||||
|
||||
curl_close ($ch);
|
||||
$fp = fopen($saveDir,'w');
|
||||
fwrite($fp, $file);
|
||||
fclose($fp);
|
||||
if(!eyPreventShell($saveDir) || !file_exists($saveDir) || $md5File != md5_file($saveDir))
|
||||
{
|
||||
return ['code' => 0, 'msg' => '下载保存问答模板包失败,请检查所有目录的权限以及用户组不能为root'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '下载成功'];
|
||||
}
|
||||
|
||||
// 升级记录 log 日志
|
||||
private function UpgradeLog($to_key_num){
|
||||
$serial_number = DEFAULT_SERIALNUMBER;
|
||||
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
|
||||
}
|
||||
$mysqlinfo = \think\Db::query("SELECT VERSION() as version");
|
||||
$mysql_version = $mysqlinfo[0]['version'];
|
||||
$vaules = array(
|
||||
'type' => 'theme_ask',
|
||||
'domain'=>$_SERVER['HTTP_HOST'], //用户域名
|
||||
'key_num'=>'v1.0.0', // 用户版本号
|
||||
'to_key_num'=>$to_key_num, // 用户要升级的版本号
|
||||
'add_time'=>time(), // 升级时间
|
||||
'serial_number'=>$serial_number,
|
||||
'ip' => GetHostByName($_SERVER['SERVER_NAME']),
|
||||
'phpv' => phpversion(),
|
||||
'mysql_version' => $mysql_version,
|
||||
'web_server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
// api_Service_upgradeLog
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT11cGdyYWRlTG9nJg==';
|
||||
$url = base64_decode($this->service_ey).base64_decode($tmp_str).http_build_query($vaules);
|
||||
@file_get_contents($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的目录路径
|
||||
* @param string $filename 文件路径+文件名
|
||||
* @return string
|
||||
*/
|
||||
private function GetDirName($filename)
|
||||
{
|
||||
$dirname = preg_replace("#[\\\\\/]{1,}#", '/', $filename);
|
||||
$dirname = preg_replace("#([^\/]*)$#", '', $dirname);
|
||||
return $dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有读写权限
|
||||
* @param string $dirname 文件目录路径
|
||||
* @return array
|
||||
*/
|
||||
private function TestIsFileDir($dirname)
|
||||
{
|
||||
$dirs = array('name'=>'', 'isdir'=>FALSE, 'writeable'=>FALSE);
|
||||
$dirs['name'] = $dirname;
|
||||
tp_mkdir($dirname);
|
||||
if(is_dir($dirname))
|
||||
{
|
||||
$dirs['isdir'] = TRUE;
|
||||
$dirs['writeable'] = $this->TestWriteAble($dirname);
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有写入权限
|
||||
* @param string $d 目录路劲
|
||||
* @return boolean
|
||||
*/
|
||||
private function TestWriteAble($d)
|
||||
{
|
||||
$tfile = '_eyout.txt';
|
||||
$fp = @fopen($d.$tfile,'w');
|
||||
if(!$fp) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
fclose($fp);
|
||||
$rs = @unlink($d.$tfile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
src/application/admin/logic/DiyExtendLogic.php
Normal file
63
src/application/admin/logic/DiyExtendLogic.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class DiyExtendLogic extends Model
|
||||
{
|
||||
private $request = null; // 当前Request对象实例
|
||||
private $admin_lang = 'cn'; // 后台多语言标识
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
null === $this->request && $this->request = Request::instance();
|
||||
$this->admin_lang = get_admin_lang();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面所在的模型ID
|
||||
* @param string $id 模型ID
|
||||
*/
|
||||
public function getChannelid()
|
||||
{
|
||||
$channeltype = input('param.channeltype/d', 0);
|
||||
$channel = input('param.channel/d', $channeltype);
|
||||
if (!empty($channel)) {
|
||||
return $channel;
|
||||
}
|
||||
|
||||
$controller_name = input('param.controller_name/s', '');
|
||||
if (empty($controller_name)) {
|
||||
$controller_name = $this->request->controller();
|
||||
}
|
||||
|
||||
if ('Custom' != $controller_name) {
|
||||
$channel = Db::name('channeltype')->where([
|
||||
'ctl_name' => $controller_name,
|
||||
])->getField('id');
|
||||
}
|
||||
|
||||
return $channel;
|
||||
}
|
||||
}
|
||||
734
src/application/admin/logic/FieldLogic.php
Normal file
734
src/application/admin/logic/FieldLogic.php
Normal file
@@ -0,0 +1,734 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
/**
|
||||
* 字段逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class FieldLogic extends Model
|
||||
{
|
||||
/**
|
||||
* 获得字段创建信息
|
||||
*
|
||||
* @access public
|
||||
* @param string $dtype 字段类型
|
||||
* @param string $fieldname 字段名称
|
||||
* @param string $dfvalue 默认值
|
||||
* @param string $fieldtitle 字段标题
|
||||
* @return array
|
||||
*/
|
||||
function GetFieldMake($dtype, $fieldname, $dfvalue, $fieldtitle)
|
||||
{
|
||||
$fields = array();
|
||||
if("int" == $dtype)
|
||||
{
|
||||
empty($dfvalue) && $dfvalue = 0;
|
||||
$default_sql = '';
|
||||
if(preg_match("#[0-9]+#", $dfvalue))
|
||||
{
|
||||
$default_sql = "DEFAULT '$dfvalue'";
|
||||
}
|
||||
$maxlen = 10;
|
||||
$fields[0] = " `$fieldname` int($maxlen) NOT NULL $default_sql COMMENT '$fieldtitle';";
|
||||
$fields[1] = "int($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("datetime" == $dtype)
|
||||
{
|
||||
empty($dfvalue) && $dfvalue = 0;
|
||||
$default_sql = '';
|
||||
if(preg_match("#[0-9\-]+#", $dfvalue))
|
||||
{
|
||||
$dfvalue = strtotime($dfvalue);
|
||||
empty($dfvalue) && $dfvalue = 0;
|
||||
$default_sql = "DEFAULT '$dfvalue'";
|
||||
}
|
||||
$maxlen = 11;
|
||||
$fields[0] = " `$fieldname` int($maxlen) NOT NULL $default_sql COMMENT '$fieldtitle';";
|
||||
$fields[1] = "int($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("switch" == $dtype)
|
||||
{
|
||||
if(empty($dfvalue) || preg_match("#[^0-9]+#", $dfvalue))
|
||||
{
|
||||
$dfvalue = 1;
|
||||
}
|
||||
$maxlen = 1;
|
||||
$fields[0] = " `$fieldname` tinyint($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "tinyint($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("float" == $dtype)
|
||||
{
|
||||
empty($dfvalue) && $dfvalue = 0;
|
||||
$default_sql = '';
|
||||
if(preg_match("#[0-9\.]+#", $dfvalue))
|
||||
{
|
||||
$default_sql = "DEFAULT '$dfvalue'";
|
||||
}
|
||||
$maxlen = 9;
|
||||
$fields[0] = " `$fieldname` float($maxlen,2) NOT NULL $default_sql COMMENT '$fieldtitle';";
|
||||
$fields[1] = "float($maxlen,2)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("decimal" == $dtype)
|
||||
{
|
||||
empty($dfvalue) && $dfvalue = 0;
|
||||
$default_sql = '';
|
||||
if(preg_match("#[0-9\.]+#", $dfvalue))
|
||||
{
|
||||
$default_sql = "DEFAULT '$dfvalue'";
|
||||
}
|
||||
$maxlen = 10;
|
||||
$fields[0] = " `$fieldname` decimal($maxlen,2) NOT NULL $default_sql COMMENT '$fieldtitle';";
|
||||
$fields[1] = "decimal($maxlen,2)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("img" == $dtype)
|
||||
{
|
||||
if(empty($dfvalue)) {
|
||||
$dfvalue = '';
|
||||
}
|
||||
$maxlen = 250;
|
||||
$fields[0] = " `$fieldname` varchar($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "varchar($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("imgs" == $dtype)
|
||||
{
|
||||
if(empty($dfvalue)) {
|
||||
$dfvalue = '';
|
||||
}
|
||||
$maxlen = 10001;
|
||||
$fields[0] = " `$fieldname` varchar($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "varchar($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("media" == $dtype)
|
||||
{
|
||||
$maxlen = 200;
|
||||
$fields[0] = " `$fieldname` varchar($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "varchar($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("files" == $dtype)
|
||||
{
|
||||
if(empty($dfvalue)) {
|
||||
$dfvalue = '';
|
||||
}
|
||||
$maxlen = 10002;
|
||||
$fields[0] = " `$fieldname` varchar($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "varchar($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("multitext" == $dtype)
|
||||
{
|
||||
$maxlen = 0;
|
||||
$fields[0] = " `$fieldname` text COMMENT '$fieldtitle';";
|
||||
$fields[1] = "text";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("htmltext" == $dtype)
|
||||
{
|
||||
$maxlen = 0;
|
||||
$fields[0] = " `$fieldname` longtext COMMENT '$fieldtitle';";
|
||||
$fields[1] = "longtext";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("checkbox" == $dtype)
|
||||
{
|
||||
$maxlen = 0;
|
||||
$dfvalueArr = explode(',', $dfvalue);
|
||||
$default_value = '';
|
||||
// $default_value = !empty($dfvalueArr[0]) ? $dfvalueArr[0] : '';
|
||||
$dfvalue = str_replace(',', "','", $dfvalue);
|
||||
$dfvalue = "'".$dfvalue."'";
|
||||
$fields[0] = " `$fieldname` SET($dfvalue) NULL DEFAULT '{$default_value}' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "SET($dfvalue)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else if("select" == $dtype || "radio" == $dtype)
|
||||
{
|
||||
$maxlen = 0;
|
||||
$dfvalueArr = explode(',', $dfvalue);
|
||||
$default_value = !empty($dfvalueArr[0]) ? $dfvalueArr[0] : '';
|
||||
$dfvalue = str_replace(',', "','", $dfvalue);
|
||||
$dfvalue = "'".$dfvalue."'";
|
||||
$fields[0] = " `$fieldname` enum($dfvalue) NULL DEFAULT '{$default_value}' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "enum($dfvalue)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(empty($dfvalue))
|
||||
{
|
||||
$dfvalue = '';
|
||||
}
|
||||
$maxlen = 200;
|
||||
$fields[0] = " `$fieldname` varchar($maxlen) NOT NULL DEFAULT '$dfvalue' COMMENT '$fieldtitle';";
|
||||
$fields[1] = "varchar($maxlen)";
|
||||
$fields[2] = $maxlen;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测频道模型相关的表字段是否已存在,包括:主表和附加表
|
||||
*
|
||||
* @access public
|
||||
* @param string $slave_table 附加表
|
||||
* @return string $fieldname 字段名
|
||||
* @return int $channel_id 模型ID
|
||||
* @param array $filter 过滤哪些字段
|
||||
*/
|
||||
public function checkChannelFieldList($slave_table, $fieldname, $channel_id, $filter = array())
|
||||
{
|
||||
// 栏目表字段
|
||||
$arctypeFieldArr = Db::getTableFields(PREFIX.'arctype');
|
||||
foreach ($arctypeFieldArr as $key => $val) {
|
||||
if (!preg_match('/^type/i',$val)) {
|
||||
array_push($arctypeFieldArr, 'type'.$val);
|
||||
}
|
||||
}
|
||||
$masterFieldArr = Db::getTableFields(PREFIX.'archives'); // 文档主表字段
|
||||
$slaveFieldArr = Db::getTableFields($slave_table); // 文档附加表字段
|
||||
$addfields = ['pageurl','has_children','typelitpic','arcurl','typeurl']; // 额外与字段冲突的变量名
|
||||
$fieldArr = array_merge($slaveFieldArr, $masterFieldArr, $addfields, $arctypeFieldArr); // 合并字段
|
||||
if (!empty($fieldname)) {
|
||||
if (!empty($filter) && is_array($filter)) {
|
||||
foreach ($filter as $key => $val) {
|
||||
$k = array_search($val, $fieldArr);
|
||||
if (false !== $k) {
|
||||
unset($fieldArr[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return in_array($fieldname, $fieldArr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测指定表的字段是否已存在
|
||||
*
|
||||
* @access public
|
||||
* @param string $table 数据表
|
||||
* @return string $fieldname 字段名
|
||||
* @param array $filter 过滤哪些字段
|
||||
*/
|
||||
public function checkTableFieldList($table, $fieldname, $filter = array())
|
||||
{
|
||||
$fieldArr = Db::getTableFields($table); // 表字段
|
||||
if (!empty($fieldname)) {
|
||||
if (!empty($filter) && is_array($filter)) {
|
||||
foreach ($filter as $key => $val) {
|
||||
$k = array_search($val, $fieldArr);
|
||||
if (false !== $k) {
|
||||
unset($fieldArr[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return in_array($fieldname, $fieldArr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定模型的表字段
|
||||
* @param int $id channelfield表ID
|
||||
* @return bool
|
||||
*/
|
||||
public function delChannelField($id)
|
||||
{
|
||||
$code = 0;
|
||||
$msg = '参数有误!';
|
||||
if (!empty($id)) {
|
||||
$id = intval($id);
|
||||
$row = model('Channelfield')->getInfo($id, 'channel_id,name,ifsystem');
|
||||
if (!empty($row['ifsystem'])) {
|
||||
return array('code'=>0, 'msg'=>'禁止删除系统字段!');
|
||||
}
|
||||
$fieldname = $row['name'];
|
||||
$channel_id = $row['channel_id'];
|
||||
$table = M('channeltype')->where('id',$channel_id)->getField('table');
|
||||
$table = PREFIX.$table.'_content';
|
||||
if ($this->checkChannelFieldList($table, $fieldname, $channel_id)) {
|
||||
$sql = "ALTER TABLE `{$table}` DROP COLUMN `{$fieldname}`;";
|
||||
if(false !== Db::execute($sql)) {
|
||||
/*重新生成数据表字段缓存文件*/
|
||||
try {
|
||||
schemaTable($table);
|
||||
} catch (\Exception $e) {}
|
||||
/*--end*/
|
||||
return array('code'=>1, 'msg'=>'删除成功!');
|
||||
} else {
|
||||
$code = 0;
|
||||
$msg = '删除失败!';
|
||||
}
|
||||
} else {
|
||||
$code = 2;
|
||||
$msg = '字段不存在!';
|
||||
}
|
||||
}
|
||||
|
||||
return array('code'=>$code, 'msg'=>$msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除栏目的表字段
|
||||
* @param int $id channelfield表ID
|
||||
* @return bool
|
||||
*/
|
||||
public function delArctypeField($id)
|
||||
{
|
||||
$code = 0;
|
||||
$msg = '参数有误!';
|
||||
if (!empty($id)) {
|
||||
$id = intval($id);
|
||||
$row = model('Channelfield')->getInfo($id, 'name,ifsystem');
|
||||
if (!empty($row['ifsystem'])) {
|
||||
return array('code'=>0, 'msg'=>'禁止删除系统字段!');
|
||||
}
|
||||
$fieldname = $row['name'];
|
||||
$table = PREFIX.'arctype';
|
||||
if ($this->checkTableFieldList($table, $fieldname)) {
|
||||
$sql = "ALTER TABLE `{$table}` DROP COLUMN `{$fieldname}`;";
|
||||
if(false !== Db::execute($sql)) {
|
||||
/*重新生成数据表字段缓存文件*/
|
||||
try {
|
||||
schemaTable($table);
|
||||
} catch (\Exception $e) {}
|
||||
/*--end*/
|
||||
return array('code'=>1, 'msg'=>'删除成功!');
|
||||
} else {
|
||||
$code = 0;
|
||||
$msg = '删除失败!';
|
||||
}
|
||||
} else {
|
||||
$code = 2;
|
||||
$msg = '字段不存在!';
|
||||
}
|
||||
}
|
||||
|
||||
return array('code'=>$code, 'msg'=>$msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步模型附加表的字段记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function synChannelTableColumns($channel_id)
|
||||
{
|
||||
$this->synArchivesTableColumns($channel_id);
|
||||
|
||||
// $cacheKey = "admin-FieldLogic-synChannelTableColumns-{$channel_id}";
|
||||
// $cacheValue = cache($cacheKey);
|
||||
// if (!empty($cacheValue)) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
$channelfieldArr = M('channelfield')->field('name,dtype')->where('channel_id',$channel_id)->getAllWithIndex('name');
|
||||
|
||||
$new_arr = array(); // 表字段数组
|
||||
$addData = array(); // 数据存储变量
|
||||
|
||||
$table = M('channeltype')->where('id',$channel_id)->getField('table');
|
||||
$tableExt = PREFIX.$table.'_content';
|
||||
$rowExt = Db::query("SHOW FULL COLUMNS FROM {$tableExt}");
|
||||
foreach ($rowExt as $key => $val) {
|
||||
$fieldname = $val['Field'];
|
||||
if (in_array($fieldname, array('id','add_time','update_time','aid','typeid'))) {
|
||||
continue;
|
||||
}
|
||||
$new_arr[] = $fieldname;
|
||||
// 对比字段记录 表字段有 字段新增记录没有
|
||||
if (empty($channelfieldArr[$fieldname])) {
|
||||
$ifcontrol = 0;
|
||||
$is_release = 0;
|
||||
$ifeditable = 1;
|
||||
$dtype = $this->toDtype($val['Type']);
|
||||
$dfvalue = $this->toDefault($val['Type'], $val['Default']);
|
||||
if (in_array($fieldname, array('content'))) {
|
||||
$ifsystem = 1;
|
||||
} else {
|
||||
$ifsystem = 0;
|
||||
}
|
||||
$maxlength = preg_replace('/^([^\(]+)\(([^\)]+)\)(.*)/i', '$2', $val['Type']);
|
||||
$maxlength = intval($maxlength);
|
||||
|
||||
/*视频模型附加表内置的系统字段*/
|
||||
if (5 == $channel_id && in_array($fieldname, ['total_video','total_duration','courseware_free','courseware'])) {
|
||||
$ifsystem = 1;
|
||||
$ifcontrol = 1;
|
||||
$is_release = 1;
|
||||
$ifeditable = 0;
|
||||
} else if ($channel_id <= 8 || (50 <= $channel_id && $channel_id <= 100)) {
|
||||
if ('content' == $fieldname) {
|
||||
$is_release = 1;
|
||||
}
|
||||
}
|
||||
/*end*/
|
||||
|
||||
$addData[] = array(
|
||||
'name' => $fieldname,
|
||||
'channel_id' => $channel_id,
|
||||
'title' => !empty($val['Comment']) ? $val['Comment'] : $fieldname,
|
||||
'dtype' => $dtype,
|
||||
'define' => $val['Type'],
|
||||
'maxlength' => $maxlength,
|
||||
'dfvalue' => $dfvalue,
|
||||
'is_release' => $is_release,
|
||||
'ifeditable' => $ifeditable,
|
||||
'ifsystem' => $ifsystem,
|
||||
'ifmain' => 0,
|
||||
'ifcontrol' => $ifcontrol,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($addData)) {
|
||||
M('channelfield')->insertAll($addData);
|
||||
}
|
||||
|
||||
/*字段新增记录有,表字段没有*/
|
||||
foreach($channelfieldArr as $k => $v){
|
||||
if (!in_array($k, $new_arr)) {
|
||||
$map = array(
|
||||
'channel_id' => $channel_id,
|
||||
'ifmain' => 0,
|
||||
'name' => $v['name'],
|
||||
);
|
||||
M('channelfield')->where($map)->delete();
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
\think\Cache::clear('channelfield');
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步文档主表的字段记录到指定模型
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function synArchivesTableColumns($channel_id = '')
|
||||
{
|
||||
$channelfieldArr = M('channelfield')->field('name,dtype')->where('channel_id',$channel_id)->getAllWithIndex('name');
|
||||
|
||||
$new_arr = array(); // 表字段数组
|
||||
$addData = array(); // 数据存储变量
|
||||
|
||||
$controlFields = ['litpic','author'];
|
||||
$channeltype_system_ids = Db::name('channeltype')->where([
|
||||
'ifsystem' => 1,
|
||||
])->column('id');
|
||||
|
||||
$table = PREFIX.'archives';
|
||||
$row = Db::query("SHOW FULL COLUMNS FROM {$table}");
|
||||
$row = array_reverse($row);
|
||||
foreach ($row as $key => $val) {
|
||||
$fieldname = $val['Field'];
|
||||
$new_arr[] = $fieldname;
|
||||
// 对比字段记录 表字段有 字段新增记录没有
|
||||
if (empty($channelfieldArr[$fieldname])) {
|
||||
$dtype = $this->toDtype($val['Type']);
|
||||
$dfvalue = $this->toDefault($val['Type'], $val['Default']);
|
||||
if (in_array($fieldname, $controlFields) && !in_array($channel_id, $channeltype_system_ids)) {
|
||||
$ifcontrol = 0;
|
||||
} else {
|
||||
$ifcontrol = 1;
|
||||
}
|
||||
$maxlength = preg_replace('/^([^\(]+)\(([^\)]+)\)(.*)/i', '$2', $val['Type']);
|
||||
$maxlength = intval($maxlength);
|
||||
$addData[] = array(
|
||||
'name' => $fieldname,
|
||||
'channel_id' => $channel_id,
|
||||
'title' => !empty($val['Comment']) ? $val['Comment'] : $fieldname,
|
||||
'dtype' => $dtype,
|
||||
'define' => $val['Type'],
|
||||
'maxlength' => $maxlength,
|
||||
'dfvalue' => $dfvalue,
|
||||
'ifeditable' => 1,
|
||||
'ifsystem' => 1,
|
||||
'ifmain' => 1,
|
||||
'ifcontrol' => $ifcontrol,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($addData)) {
|
||||
M('channelfield')->insertAll($addData);
|
||||
}
|
||||
|
||||
/*字段新增记录有,表字段没有*/
|
||||
foreach($channelfieldArr as $k => $v){
|
||||
if (!in_array($k, $new_arr)) {
|
||||
$map = array(
|
||||
'channel_id' => $channel_id,
|
||||
'ifmain' => 1,
|
||||
'name' => $v['name'],
|
||||
);
|
||||
M('channelfield')->where($map)->delete();
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步栏目主表的字段记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function synArctypeTableColumns($channel_id = '')
|
||||
{
|
||||
$cacheKey = "admin-FieldLogic-synArctypeTableColumns-{$channel_id}";
|
||||
$cacheValue = cache($cacheKey);
|
||||
if (!empty($cacheValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$channel_id = !empty($channel_id) ? $channel_id : config('global.arctype_channel_id');
|
||||
$channelfieldArr = M('channelfield')->field('name,dtype')->where('channel_id',$channel_id)->getAllWithIndex('name');
|
||||
|
||||
$new_arr = array(); // 表字段数组
|
||||
$addData = array(); // 数据存储变量
|
||||
|
||||
$table = PREFIX.'arctype';
|
||||
$row = Db::query("SHOW FULL COLUMNS FROM {$table}");
|
||||
$row = array_reverse($row);
|
||||
$arctypeTableFields = config('global.arctype_table_fields');
|
||||
foreach ($row as $key => $val) {
|
||||
$fieldname = $val['Field'];
|
||||
$new_arr[] = $fieldname;
|
||||
// 对比字段记录 表字段有 字段新增记录没有
|
||||
if (empty($channelfieldArr[$fieldname])) {
|
||||
$dtype = $this->toDtype($val['Type']);
|
||||
$dfvalue = $this->toDefault($val['Type'], $val['Default']);
|
||||
if (in_array($fieldname, $arctypeTableFields)) {
|
||||
$ifsystem = 1;
|
||||
} else {
|
||||
$ifsystem = 0;
|
||||
}
|
||||
$maxlength = preg_replace('/^([^\(]+)\(([^\)]+)\)(.*)/i', '$2', $val['Type']);
|
||||
$maxlength = intval($maxlength);
|
||||
$addData[] = array(
|
||||
'name' => $fieldname,
|
||||
'channel_id' => $channel_id,
|
||||
'title' => !empty($val['Comment']) ? $val['Comment'] : $fieldname,
|
||||
'dtype' => $dtype,
|
||||
'define' => $val['Type'],
|
||||
'maxlength' => $maxlength,
|
||||
'dfvalue' => $dfvalue,
|
||||
'ifeditable' => 1,
|
||||
'ifsystem' => $ifsystem,
|
||||
'ifmain' => 1,
|
||||
'ifcontrol' => 1,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($addData)) {
|
||||
M('channelfield')->insertAll($addData);
|
||||
}
|
||||
|
||||
/*字段新增记录有,表字段没有*/
|
||||
foreach($channelfieldArr as $k => $v){
|
||||
if (!in_array($k, $new_arr)) {
|
||||
$map = array(
|
||||
'channel_id' => $channel_id,
|
||||
'name' => $v['name'],
|
||||
);
|
||||
M('channelfield')->where($map)->delete();
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*修复v1.1.9版本的admin_id为系统字段*/
|
||||
M('channelfield')->where('name','admin_id')->update(['ifsystem'=>1]);
|
||||
/*--end*/
|
||||
|
||||
\think\Cache::clear('channelfield');
|
||||
\think\Cache::clear("arctype");
|
||||
|
||||
cache($cacheKey, 1, null, 'channelfield');
|
||||
}
|
||||
|
||||
/**
|
||||
* 表字段类型转为自定义字段类型
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function toDtype($fieldtype = '')
|
||||
{
|
||||
if (preg_match('/^int/i', $fieldtype)) {
|
||||
$maxlen = preg_replace('/^int\((.*)\)/i', '$1', $fieldtype);
|
||||
if (11 == $maxlen) {
|
||||
$dtype = 'datetime';
|
||||
} else {
|
||||
$dtype = 'int';
|
||||
}
|
||||
} else if (preg_match('/^longtext/i', $fieldtype)) {
|
||||
$dtype = 'htmltext';
|
||||
} else if (preg_match('/^text/i', $fieldtype)) {
|
||||
$dtype = 'multitext';
|
||||
} else if (preg_match('/^enum/i', $fieldtype)) {
|
||||
$dtype = 'select';
|
||||
} else if (preg_match('/^set/i', $fieldtype)) {
|
||||
$dtype = 'checkbox';
|
||||
} else if (preg_match('/^float/i', $fieldtype)) {
|
||||
$dtype = 'float';
|
||||
} else if (preg_match('/^decimal/i', $fieldtype)) {
|
||||
$dtype = 'decimal';
|
||||
} else if (preg_match('/^tinyint/i', $fieldtype)) {
|
||||
$dtype = 'switch';
|
||||
} else if (preg_match('/^varchar/i', $fieldtype)) {
|
||||
$maxlen = preg_replace('/^varchar\((.*)\)/i', '$1', $fieldtype);
|
||||
if (250 == $maxlen) {
|
||||
$dtype = 'img';
|
||||
} else if (1001 == $maxlen || 10001 == $maxlen) {
|
||||
$dtype = 'imgs';
|
||||
} else if (1002 == $maxlen || 10002 == $maxlen) {
|
||||
$dtype = 'files';
|
||||
} else {
|
||||
$dtype = 'text';
|
||||
}
|
||||
} else {
|
||||
$dtype = 'text';
|
||||
}
|
||||
|
||||
return $dtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表字段的默认值
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function toDefault($fieldtype, $dfvalue = '')
|
||||
{
|
||||
if (preg_match('/^(enum|set)/i', $fieldtype)) {
|
||||
$str = preg_replace('/^(enum|set)\((.*)\)/i', '$2', $fieldtype);
|
||||
$str = str_replace("'", "", $str);
|
||||
} else {
|
||||
$str = $dfvalue;
|
||||
}
|
||||
$str = ("" != $str) ? $str : '';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理栏目自定义字段的值
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function handleAddonField($channel_id, $dataExt)
|
||||
{
|
||||
$nowDataExt = array();
|
||||
if (!empty($dataExt) && !empty($channel_id)) {
|
||||
$fieldTypeList = model('Channelfield')->getListByWhere(array('channel_id'=>$channel_id), 'name,dtype', 'name');
|
||||
foreach ($dataExt as $key => $val) {
|
||||
|
||||
$key = preg_replace('/^(.*)(_eyou_is_remote|_eyou_remote|_eyou_local)$/', '$1', $key);
|
||||
$dtype = !empty($fieldTypeList[$key]) ? $fieldTypeList[$key]['dtype'] : '';
|
||||
switch ($dtype) {
|
||||
|
||||
case 'checkbox':
|
||||
{
|
||||
$val = implode(',', $val);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'switch':
|
||||
case 'int':
|
||||
{
|
||||
$val = intval($val);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'img':
|
||||
{
|
||||
$is_remote = !empty($dataExt[$key.'_eyou_is_remote']) ? $dataExt[$key.'_eyou_is_remote'] : 0;
|
||||
if (1 == $is_remote) {
|
||||
$val = $dataExt[$key.'_eyou_remote'];
|
||||
} else {
|
||||
$val = $dataExt[$key.'_eyou_local'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'imgs':
|
||||
{
|
||||
$imgData = [];
|
||||
$imgsIntroArr = !empty($dataExt[$key.'_eyou_intro']) ? $dataExt[$key.'_eyou_intro'] : [];
|
||||
foreach ($val as $k2 => $v2) {
|
||||
$v2 = trim($v2);
|
||||
if (!empty($v2)) {
|
||||
$imgData[] = [
|
||||
'image_url' => $v2,
|
||||
'intro' => !empty($imgsIntroArr[$k2]) ? $imgsIntroArr[$k2] : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
$val = serialize($imgData);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'files':
|
||||
{
|
||||
foreach ($val as $k2 => $v2) {
|
||||
if (empty($v2)) {
|
||||
unset($val[$k2]);
|
||||
continue;
|
||||
}
|
||||
$val[$k2] = trim($v2);
|
||||
}
|
||||
$val = implode(',', $val);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'datetime':
|
||||
{
|
||||
$val = !empty($val) ? strtotime($val) : getTime();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'decimal':
|
||||
{
|
||||
$moneyArr = explode('.', $val);
|
||||
$money1 = !empty($moneyArr[0]) ? intval($moneyArr[0]) : '0';
|
||||
$money2 = !empty($moneyArr[1]) ? intval(msubstr($moneyArr[1], 0, 2)) : '00';
|
||||
$val = $money1.'.'.$money2;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
$val = trim($val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$nowDataExt[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $nowDataExt;
|
||||
}
|
||||
}
|
||||
393
src/application/admin/logic/FilemanagerLogic.php
Normal file
393
src/application/admin/logic/FilemanagerLogic.php
Normal file
@@ -0,0 +1,393 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\db;
|
||||
/**
|
||||
* 文件管理逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class FilemanagerLogic extends Model
|
||||
{
|
||||
public $globalTpCache = array();
|
||||
public $baseDir = ''; // 服务器站点根目录绝对路径
|
||||
public $maxDir = '';
|
||||
public $replaceImgOpArr = array(); // 替换权限
|
||||
public $editOpArr = array(); // 编辑权限
|
||||
public $renameOpArr = array(); // 改名权限
|
||||
public $delOpArr = array(); // 删除权限
|
||||
public $moveOpArr = array(); // 移动权限
|
||||
public $editExt = array(); // 允许新增/编辑扩展名文件
|
||||
public $disableFuns = array(); // 允许新增/编辑扩展名文件
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->globalTpCache = tpCache('global');
|
||||
$this->baseDir = rtrim(ROOT_PATH, DS); // 服务器站点根目录绝对路径
|
||||
$this->maxDir = $this->globalTpCache['web_templets_dir']; // 默认文件管理的最大级别目录
|
||||
// 替换权限
|
||||
$this->replaceImgOpArr = array('gif','jpg','svg');
|
||||
// 编辑权限
|
||||
$this->editOpArr = array('txt','htm','js','css');
|
||||
// 改名权限
|
||||
$this->renameOpArr = array('dir','gif','jpg','svg','flash','zip','exe','mp3','wmv','rm','txt','htm','js','css','other');
|
||||
// 删除权限
|
||||
$this->delOpArr = array('dir','gif','jpg','svg','flash','zip','exe','mp3','wmv','rm','txt','htm','php','js','css','other');
|
||||
// 移动权限
|
||||
$this->moveOpArr = array('gif','jpg','svg','flash','zip','exe','mp3','wmv','rm','txt','htm','js','css','other');
|
||||
// 允许新增/编辑扩展名文件
|
||||
$this->editExt = array('htm','js','css','txt');
|
||||
// 过滤php危险函数
|
||||
$this->disableFuns = ['phpinfo'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文件
|
||||
*
|
||||
* @access public
|
||||
* @param string $filename 文件名
|
||||
* @param string $activepath 当前路径
|
||||
* @param string $content 文件内容
|
||||
* @return string
|
||||
*/
|
||||
public function editFile($filename, $activepath = '', $content = '')
|
||||
{
|
||||
$fileinfo = pathinfo($filename);
|
||||
$ext = strtolower($fileinfo['extension']);
|
||||
$filename = trim($fileinfo['filename'], '.').'.'.$fileinfo['extension'];
|
||||
|
||||
/*不允许越过指定最大级目录的文件编辑*/
|
||||
$tmp_max_dir = preg_replace("#\/#i", "\/", $this->maxDir);
|
||||
if (!preg_match("#^".$tmp_max_dir."#i", $activepath)) {
|
||||
return '没有操作权限!';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*允许编辑的文件类型*/
|
||||
if (!in_array($ext, $this->editExt)) {
|
||||
return '只允许操作文件类型如下:'.implode('|', $this->editExt);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$file = $this->baseDir."$activepath/$filename";
|
||||
if (!is_writable(dirname($file))) {
|
||||
return "请把模板文件目录设置为可写入权限!";
|
||||
}
|
||||
if ('htm' == $ext) {
|
||||
$content = htmlspecialchars_decode($content, ENT_QUOTES);
|
||||
foreach ($this->disableFuns as $key => $val) {
|
||||
$val_new = msubstr($val, 0, 1).'-'.msubstr($val, 1);
|
||||
$content = preg_replace("/(@)?".$val."(\s*)\(/i", "{$val_new}(", $content);
|
||||
}
|
||||
}
|
||||
$fp = fopen($file, "w");
|
||||
fputs($fp, $content);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param string $dirname 新目录
|
||||
* @param string $activepath 当前路径
|
||||
* @param boolean $replace 是否替换
|
||||
* @param string $type 文件类型:图片image , 附件file , 视频media
|
||||
*/
|
||||
public function upload($fileElementId, $activepath = '', $replace = false, $type = 'image')
|
||||
{
|
||||
$retData = [];
|
||||
$file = request()->file($fileElementId);
|
||||
if (is_object($file) && !is_array($file)) {
|
||||
$retData = $this->uploadfile($file, $activepath, $replace, $type);
|
||||
}
|
||||
else if (!is_object($file) && is_array($file)) {
|
||||
$fileArr = $file;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
foreach ($fileArr as $key => $fileObj) {
|
||||
if (empty($fileObj)) {
|
||||
continue;
|
||||
}
|
||||
$res = $this->uploadfile($fileObj, $activepath, $replace, $type);
|
||||
if(!empty($res['code']) && $res['code'] == 1) {
|
||||
$i++;
|
||||
} else {
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($j == 0) {
|
||||
$retData['code'] = 0;
|
||||
$retData['msg'] = "上传失败 $i 个文件到: $activepath";
|
||||
} else {
|
||||
$retData['code'] = 1;
|
||||
$retData['msg'] = "上传成功!";
|
||||
}
|
||||
}
|
||||
|
||||
return $retData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义上传
|
||||
*
|
||||
* @param object $file 文件对象
|
||||
* @param string $activepath 当前路径
|
||||
* @param boolean $replace 是否替换
|
||||
* @param string $type 文件类型:图片image , 附件file , 视频media
|
||||
*/
|
||||
public function uploadfile($file, $activepath = '', $replace = false, $type = 'image')
|
||||
{
|
||||
$validate = array();
|
||||
|
||||
/*文件类型限制*/
|
||||
switch ($type) {
|
||||
case 'image':
|
||||
$validate_ext = tpCache('basic.image_type');
|
||||
break;
|
||||
|
||||
case 'file':
|
||||
$validate_ext = tpCache('basic.file_type');
|
||||
break;
|
||||
|
||||
case 'media':
|
||||
$validate_ext = tpCache('basic.media_type');
|
||||
break;
|
||||
|
||||
default:
|
||||
$validate_ext = tpCache('basic.image_type');
|
||||
break;
|
||||
}
|
||||
$validate['ext'] = explode('|', $validate_ext);
|
||||
/*--end*/
|
||||
|
||||
/*文件大小限制*/
|
||||
$validate_size = tpCache('basic.file_size');
|
||||
if (!empty($validate_size)) {
|
||||
$validate['size'] = $validate_size * 1024 * 1024; // 单位为b
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*上传文件验证*/
|
||||
if (!empty($validate)) {
|
||||
$is_validate = $file->check($validate);
|
||||
if ($is_validate === false) {
|
||||
return ['code'=>0, 'msg'=>$file->getError()];
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$savePath = !empty($activepath) ? trim($activepath, '/') : UPLOAD_PATH.'temp';
|
||||
if (!file_exists($savePath)) {
|
||||
tp_mkdir($savePath);
|
||||
}
|
||||
|
||||
if (false == $replace) {
|
||||
$fileinfo = $file->getInfo();
|
||||
$filename = pathinfo($fileinfo['name'], PATHINFO_BASENAME); //获取上传文件名
|
||||
} else {
|
||||
$filename = $replace;
|
||||
}
|
||||
$fileExt = pathinfo($filename, PATHINFO_EXTENSION); //获取上传文件扩展名
|
||||
if (!in_array($fileExt, $validate['ext'])) {
|
||||
return ['code'=>0, 'msg'=>'上传文件后缀不允许'];
|
||||
}
|
||||
|
||||
// 使用自定义的文件保存规则
|
||||
$info = $file->move($savePath, $filename, true);
|
||||
if($info){
|
||||
return ['code'=>1, 'msg'=>'上传成功'];
|
||||
}else{
|
||||
return ['code'=>0, 'msg'=>$file->getError()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前目录下的文件列表
|
||||
*/
|
||||
public function getDirFile($directory, $activepath = '', &$arr_file = array()) {
|
||||
|
||||
if (!file_exists($directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fileArr = $dirArr = $parentArr = array();
|
||||
|
||||
$mydir = dir($directory);
|
||||
while(false !== $file = $mydir->read())
|
||||
{
|
||||
$filesize = $filetime = $intro = '';
|
||||
$filemine = 'file';
|
||||
|
||||
if($file != "." && $file != ".." && !is_dir("$directory/$file"))
|
||||
{
|
||||
@$filesize = filesize("$directory/$file");
|
||||
@$filesize = format_bytes($filesize);
|
||||
@$filetime = filemtime("$directory/$file");
|
||||
}
|
||||
|
||||
if ($file == '.')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if($file == "..")
|
||||
{
|
||||
if($activepath == "" || $activepath == $this->maxDir) {
|
||||
continue;
|
||||
}
|
||||
$parentArr = array(
|
||||
array(
|
||||
'filepath' => preg_replace("#[\/][^\/]*$#i", "", $activepath),
|
||||
'filename' => '上级目录',
|
||||
'filesize' => '',
|
||||
'filetime' => '',
|
||||
'filemine' => 'dir',
|
||||
'filetype' => 'dir2',
|
||||
'icon' => 'file_topdir.gif',
|
||||
'intro' => '(当前目录:'.$activepath.')',
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
else if(is_dir("$directory/$file"))
|
||||
{
|
||||
if(preg_match("#^_(.*)$#i", $file)) continue; #屏蔽FrontPage扩展目录和linux隐蔽目录
|
||||
if(preg_match("#^\.(.*)$#i", $file)) continue;
|
||||
$file_info = array(
|
||||
'filepath' => $activepath.'/'.$file,
|
||||
'filename' => $file,
|
||||
'filesize' => '',
|
||||
'filetime' => '',
|
||||
'filemine' => 'dir',
|
||||
'filetype' => 'dir',
|
||||
'icon' => 'dir.gif',
|
||||
'intro' => '',
|
||||
);
|
||||
array_push($dirArr, $file_info);
|
||||
continue;
|
||||
}
|
||||
else if(preg_match("#\.(gif|png)#i",$file))
|
||||
{
|
||||
$filemine = 'image';
|
||||
$filetype = 'gif';
|
||||
$icon = 'gif.gif';
|
||||
}
|
||||
else if(preg_match("#\.(jpg|jpeg|bmp|webp)#i",$file))
|
||||
{
|
||||
$filemine = 'image';
|
||||
$filetype = 'jpg';
|
||||
$icon = 'jpg.gif';
|
||||
}
|
||||
else if(preg_match("#\.(svg)#i",$file))
|
||||
{
|
||||
$filemine = 'image';
|
||||
$filetype = 'svg';
|
||||
$icon = 'jpg.gif';
|
||||
}
|
||||
else if(preg_match("#\.(swf|fla|fly)#i",$file))
|
||||
{
|
||||
$filetype = 'flash';
|
||||
$icon = 'flash.gif';
|
||||
}
|
||||
else if(preg_match("#\.(zip|rar|tar.gz)#i",$file))
|
||||
{
|
||||
$filetype = 'zip';
|
||||
$icon = 'zip.gif';
|
||||
}
|
||||
else if(preg_match("#\.(exe)#i",$file))
|
||||
{
|
||||
$filetype = 'exe';
|
||||
$icon = 'exe.gif';
|
||||
}
|
||||
else if(preg_match("#\.(mp3|wma)#i",$file))
|
||||
{
|
||||
$filetype = 'mp3';
|
||||
$icon = 'mp3.gif';
|
||||
}
|
||||
else if(preg_match("#\.(wmv|api)#i",$file))
|
||||
{
|
||||
$filetype = 'wmv';
|
||||
$icon = 'wmv.gif';
|
||||
}
|
||||
else if(preg_match("#\.(rm|rmvb)#i",$file))
|
||||
{
|
||||
$filetype = 'rm';
|
||||
$icon = 'rm.gif';
|
||||
}
|
||||
else if(preg_match("#\.(txt|inc|pl|cgi|asp|xml|xsl|aspx|cfm)#",$file))
|
||||
{
|
||||
$filetype = 'txt';
|
||||
$icon = 'txt.gif';
|
||||
}
|
||||
else if(preg_match("#\.(htm|html)#i",$file))
|
||||
{
|
||||
$filetype = 'htm';
|
||||
$icon = 'htm.gif';
|
||||
}
|
||||
else if(preg_match("#\.(php)#i",$file))
|
||||
{
|
||||
$filetype = 'php';
|
||||
$icon = 'php.gif';
|
||||
}
|
||||
else if(preg_match("#\.(js)#i",$file))
|
||||
{
|
||||
$filetype = 'js';
|
||||
$icon = 'js.gif';
|
||||
}
|
||||
else if(preg_match("#\.(css)#i",$file))
|
||||
{
|
||||
$filetype = 'css';
|
||||
$icon = 'css.gif';
|
||||
}
|
||||
else
|
||||
{
|
||||
$filetype = 'other';
|
||||
$icon = 'other.gif';
|
||||
}
|
||||
|
||||
$file_info = array(
|
||||
'filepath' => $activepath.'/'.$file,
|
||||
'filename' => $file,
|
||||
'filesize' => $filesize,
|
||||
'filetime' => $filetime,
|
||||
'filemine' => $filemine,
|
||||
'filetype' => $filetype,
|
||||
'icon' => $icon,
|
||||
'intro' => $intro,
|
||||
);
|
||||
array_push($fileArr, $file_info);
|
||||
}
|
||||
$mydir->close();
|
||||
|
||||
$arr_file = array_merge($parentArr, $dirArr, $fileArr);
|
||||
|
||||
return $arr_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将冒号符反替换为反斜杠,适用于IIS服务器在URL上的双重转义限制
|
||||
* @param string $filepath 相对路径
|
||||
* @param string $replacement 目标字符
|
||||
* @param boolean $is_back false为替换,true为还原
|
||||
*/
|
||||
public function replace_path($activepath, $replacement = ':', $is_back = false)
|
||||
{
|
||||
return replace_path($activepath, $replacement, $is_back);
|
||||
}
|
||||
}
|
||||
517
src/application/admin/logic/MemberLogic.php
Normal file
517
src/application/admin/logic/MemberLogic.php
Normal file
@@ -0,0 +1,517 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class MemberLogic extends Model
|
||||
{
|
||||
private $request = null;
|
||||
private $data_path;
|
||||
private $version_txt_path;
|
||||
private $version;
|
||||
private $service_url;
|
||||
private $upgrade_url;
|
||||
private $service_ey;
|
||||
private $planPath_pc;
|
||||
private $planPath_m;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->request = request();
|
||||
$this->service_ey = config('service_ey');
|
||||
$this->data_path = DATA_PATH; //
|
||||
$this->version_txt_path = $this->data_path.'conf'.DS.'version_themeusers.txt'; // 版本文件路径
|
||||
$this->version = getVersion('version_themeusers');
|
||||
// api_Service_checkVersion
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT1jaGVja1RoZW1lVmVyc2lvbg==';
|
||||
$this->service_url = base64_decode($this->service_ey).base64_decode($tmp_str);
|
||||
$this->upgrade_url = $this->service_url . '&domain='.request()->host(true).'&v=' . $this->version.'&type=theme_users';
|
||||
$this->planPath_pc = 'template/'.TPL_THEME.'pc/';
|
||||
$this->planPath_m = 'template/'.TPL_THEME.'mobile/';
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测并第一次从官方同步会员中心的前台模板
|
||||
*/
|
||||
public function syn_theme_users()
|
||||
{
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
if ('v1.0.1' > $this->version) {
|
||||
return $this->OneKeyUpgrade();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测目录权限
|
||||
*/
|
||||
public function checkAuthority($filelist = '')
|
||||
{
|
||||
/*------------------检测目录读写权限----------------------*/
|
||||
$filelist = htmlspecialchars_decode($filelist);
|
||||
$filelist = explode('<br>', $filelist);
|
||||
|
||||
$dirs = array();
|
||||
$i = -1;
|
||||
foreach($filelist as $filename)
|
||||
{
|
||||
if (stristr($filename, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($filename, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tfilename = $filename;
|
||||
$curdir = $this->GetDirName($tfilename);
|
||||
if (empty($curdir)) {
|
||||
continue;
|
||||
}
|
||||
if( !isset($dirs[$curdir]) )
|
||||
{
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
if($dirs[$curdir]['isdir'] == FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$is_pass = true;
|
||||
$msg = '检测通过';
|
||||
if($i > -1)
|
||||
{
|
||||
$n = 0;
|
||||
$dirinfos = '';
|
||||
foreach($dirs as $curdir)
|
||||
{
|
||||
$dirinfos .= $curdir['name']." 状态:";
|
||||
if ($curdir['writeable']) {
|
||||
$dirinfos .= "[√正常]";
|
||||
} else {
|
||||
$is_pass = false;
|
||||
$n++;
|
||||
$dirinfos .= "<font color='red'>[×不可写]</font>";
|
||||
}
|
||||
$dirinfos .= "<br />";
|
||||
}
|
||||
$title = "本次升级需要在下面文件夹写入更新文件,已检测站点有 <font color='red'>{$n}</font> 处没有写入权限:<br />";
|
||||
$title .= "<font color='red'>问题分析(如有问题,请咨询技术支持):<br />";
|
||||
$title .= "1、检查站点目录的用户组与所有者,禁止是 root ;<br />";
|
||||
$title .= "2、检查站点目录的读写权限,一般权限值是 0755 ;<br />";
|
||||
$title .= "</font>涉及更新目录列表如下:<br />";
|
||||
$msg = $title . $dirinfos;
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
if (true === $is_pass) {
|
||||
return ['code'=>1, 'msg'=>$msg];
|
||||
} else {
|
||||
return ['code'=>0, 'msg'=>$msg, 'data'=>['code'=>1]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkVersion() {
|
||||
//error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 1, 'msg' => "<font color='red'>请联系空间商(设置 php.ini 中参数 allow_url_fopen = 1)</font>"];
|
||||
}
|
||||
|
||||
$url = $this->upgrade_url;
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
|
||||
$serviceVersionList = @file_get_contents($url,false,$context);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if(!empty($serviceVersionList))
|
||||
{
|
||||
$upgradeArr = array();
|
||||
$introStr = '';
|
||||
$upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br>'.filter_line_return($val['intro'], '<br>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
foreach ($upgradeArr as $key => $val) {
|
||||
if (stristr($val, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
unset($upgradeArr[$key]);
|
||||
} else if (stristr($val, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
unset($upgradeArr[$key]);
|
||||
}
|
||||
}
|
||||
$upgradeStr = implode('<br>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function OneKeyUpgrade() {
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,设置 php.ini 中参数 allow_url_fopen = 1"];
|
||||
}
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,开启 php.ini 中的php-zip扩展"];
|
||||
}
|
||||
|
||||
$serviceVersionList = @file_get_contents($this->upgrade_url);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if (empty($serviceVersionList)) {
|
||||
if ('v1.0.1' > $this->version) {
|
||||
return ['code' => 0, 'msg' => "请求服务器失败,请检查是否网络故障!"];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => "没找到升级信息"];
|
||||
}
|
||||
}
|
||||
|
||||
clearstatcache(); // 清除文件夹权限缓存
|
||||
if (!is_writeable($this->version_txt_path)) {
|
||||
return ['code' => 0, 'msg' => '文件'.$this->version_txt_path.' 不可写,不能升级!!!'];
|
||||
}
|
||||
/*最新更新版本信息*/
|
||||
$lastServiceVersion = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
/*--end*/
|
||||
/*批量下载更新包*/
|
||||
$upgradeArr = array(); // 更新的文件列表
|
||||
$folderName = 'users-'.$lastServiceVersion['key_num'];
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
// 下载更新包
|
||||
$result = $this->downloadFile($val['down_url'], $val['file_md5']);
|
||||
if (!isset($result['code']) || $result['code'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*第一个循环执行的业务*/
|
||||
if ($key == 0) {
|
||||
/*解压到最后一个更新包的文件夹*/
|
||||
$lastDownFileName = explode('/', $lastServiceVersion['down_url']);
|
||||
$lastDownFileName = end($lastDownFileName);
|
||||
$folderName = 'users-'.str_replace(".zip", "", $lastDownFileName); // 文件夹
|
||||
/*--end*/
|
||||
|
||||
/*解压之前,删除已重复的文件夹*/
|
||||
delFile($this->data_path.'backup'.DS.'theme'.DS.$folderName);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$downFileName = explode('/', $val['down_url']);
|
||||
$downFileName = 'users-'.end($downFileName);
|
||||
|
||||
/*解压文件*/
|
||||
$zip = new \ZipArchive();//新建一个ZipArchive的对象
|
||||
if ($zip->open($this->data_path.'backup'.DS.'theme'.DS.$downFileName) != true) {
|
||||
return ['code' => 0, 'msg' => "升级包读取失败!"];
|
||||
}
|
||||
$zip->extractTo($this->data_path.'backup'.DS.'theme'.DS.$folderName.DS);//假设解压缩到在当前路径下backup文件夹内
|
||||
$zip->close();//关闭处理的zip文件
|
||||
/*--end*/
|
||||
|
||||
if (!file_exists($this->data_path.'backup'.DS.'theme'.DS.$folderName.DS.'data'.DS.'conf'.DS.'version_themeusers.txt')) {
|
||||
return ['code' => 0, 'msg' => "缺少version_themeusers.txt文件,请联系客服"];
|
||||
}
|
||||
|
||||
/*更新的文件列表*/
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*将多个更新包重新组建一个新的完全更新包*/
|
||||
$upgradeArr = array_unique($upgradeArr); // 移除文件列表里重复的文件
|
||||
$serviceVersion = $lastServiceVersion;
|
||||
$serviceVersion['upgrade'] = $upgradeArr;
|
||||
/*--end*/
|
||||
|
||||
/*升级之前,备份涉及的源文件*/
|
||||
$upgrade = $serviceVersion['upgrade'];
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$source_file = ROOT_PATH.$val;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = $this->data_path.'backup'.DS.'theme'.DS.$folderName.'_www'.DS.$val;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
$copy_bool = @copy($source_file, $destination_file);
|
||||
if (false == $copy_bool) {
|
||||
return ['code' => 0, 'msg' => "更新前备份文件失败,请检查所有目录是否有读写权限"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 递归复制文件夹
|
||||
$copy_data = $this->recurse_copy($this->data_path.'backup'.DS.'theme'.DS.$folderName, rtrim(ROOT_PATH, DS), $folderName);
|
||||
|
||||
/*删除下载的升级包*/
|
||||
$ziplist = glob($this->data_path.'backup'.DS.'theme'.DS.'users-*.zip');
|
||||
@array_map('unlink', $ziplist);
|
||||
/*--end*/
|
||||
|
||||
// 推送回服务器 记录升级成功
|
||||
$this->UpgradeLog($serviceVersion['key_num']);
|
||||
|
||||
return ['code' => $copy_data['code'], 'msg' => "升级模板成功{$copy_data['msg']}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @param string $folderName 存放升级包目录名称
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst, $folderName)
|
||||
{
|
||||
static $badcp = 0; // 累计覆盖失败的文件总数
|
||||
static $n = 0; // 累计执行覆盖的文件总数
|
||||
static $total = 0; // 累计更新的文件总数
|
||||
|
||||
$dir = opendir($src);
|
||||
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$dst_tmp = str_replace('\\', '/', $dst);
|
||||
$dst_tmp = rtrim($dst_tmp, '/').'/';
|
||||
if (stristr($dst_tmp, $this->planPath_pc) && file_exists($this->planPath_pc)) {
|
||||
tp_mkdir($dst);
|
||||
} else if (stristr($dst_tmp, $this->planPath_m) && file_exists($this->planPath_m)) {
|
||||
tp_mkdir($dst);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$needle = '/template/'.TPL_THEME;
|
||||
$needle = rtrim($needle, '/');
|
||||
$dstfile = $dst . '/' . $file;
|
||||
if (!stristr($dstfile, $needle)) {
|
||||
$dstfile = str_replace('/template', $needle, $dstfile);
|
||||
}
|
||||
$this->recurse_copy($src . '/' . $file, $dstfile, $folderName);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$rs = true;
|
||||
$src_tmp = str_replace('\\', '/', $src . DIRECTORY_SEPARATOR . $file);
|
||||
if (stristr($src_tmp, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($src_tmp, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
/*--end*/
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
$n++;
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
} else {
|
||||
$n++;
|
||||
$badcp++;
|
||||
}
|
||||
} else {
|
||||
$n++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
$code = 1;
|
||||
$msg = '!';
|
||||
if($badcp > 0)
|
||||
{
|
||||
$code = 2;
|
||||
$msg = ",其中失败 <font color='red'>{$badcp}</font> 个文件,<br />请从升级包目录[<font color='red'>data/backup/theme/{$folderName}</font>]中的取出全部文件覆盖到根目录,完成手工升级。";
|
||||
}
|
||||
|
||||
$this->copy_speed($n, $total);
|
||||
|
||||
return ['code'=>$code, 'msg'=>$msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文件进度
|
||||
*/
|
||||
private function copy_speed($n, $total)
|
||||
{
|
||||
$data = false;
|
||||
|
||||
if ($n < $total) {
|
||||
$this->copy_speed($n, $total);
|
||||
} else {
|
||||
$data = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type $fileUrl 下载文件地址
|
||||
* @param type $md5File 文件MD5 加密值 用于对比下载是否完整
|
||||
* @return string 错误或成功提示
|
||||
*/
|
||||
private function downloadFile($fileUrl,$md5File)
|
||||
{
|
||||
$downFileName = explode('/', $fileUrl);
|
||||
$downFileName = 'users-'.end($downFileName);
|
||||
$saveDir = $this->data_path.'backup'.DS.'theme'.DS.$downFileName; // 保存目录
|
||||
tp_mkdir(dirname($saveDir));
|
||||
if(!file_get_contents($fileUrl, 0, null, 0, 1)){
|
||||
return ['code' => 0, 'msg' => '官方升级包不存在']; // 文件存在直接退出
|
||||
}
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
$file = curl_exec ($ch);
|
||||
curl_close ($ch);
|
||||
$fp = fopen($saveDir,'w');
|
||||
fwrite($fp, $file);
|
||||
fclose($fp);
|
||||
if(!eyPreventShell($saveDir) || !file_exists($saveDir) || $md5File != md5_file($saveDir))
|
||||
{
|
||||
return ['code' => 0, 'msg' => '下载保存升级包失败,请检查所有目录的权限以及用户组不能为root'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '下载成功'];
|
||||
}
|
||||
|
||||
// 升级记录 log 日志
|
||||
private function UpgradeLog($to_key_num){
|
||||
$serial_number = DEFAULT_SERIALNUMBER;
|
||||
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
|
||||
}
|
||||
$mysqlinfo = \think\Db::query("SELECT VERSION() as version");
|
||||
$mysql_version = $mysqlinfo[0]['version'];
|
||||
$vaules = array(
|
||||
'type' => 'theme_users',
|
||||
'domain'=>$_SERVER['HTTP_HOST'], //用户域名
|
||||
'key_num'=>$this->version, // 用户版本号
|
||||
'to_key_num'=>$to_key_num, // 用户要升级的版本号
|
||||
'add_time'=>time(), // 升级时间
|
||||
'serial_number'=>$serial_number,
|
||||
'ip' => GetHostByName($_SERVER['SERVER_NAME']),
|
||||
'phpv' => phpversion(),
|
||||
'mysql_version' => $mysql_version,
|
||||
'web_server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
// api_Service_upgradeLog
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT11cGdyYWRlTG9nJg==';
|
||||
$url = base64_decode($this->service_ey).base64_decode($tmp_str).http_build_query($vaules);
|
||||
@file_get_contents($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的目录路径
|
||||
* @param string $filename 文件路径+文件名
|
||||
* @return string
|
||||
*/
|
||||
private function GetDirName($filename)
|
||||
{
|
||||
$dirname = preg_replace("#[\\\\\/]{1,}#", '/', $filename);
|
||||
$dirname = preg_replace("#([^\/]*)$#", '', $dirname);
|
||||
return $dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有读写权限
|
||||
* @param string $dirname 文件目录路径
|
||||
* @return array
|
||||
*/
|
||||
private function TestIsFileDir($dirname)
|
||||
{
|
||||
$dirs = array('name'=>'', 'isdir'=>FALSE, 'writeable'=>FALSE);
|
||||
$dirs['name'] = $dirname;
|
||||
tp_mkdir($dirname);
|
||||
if(is_dir($dirname))
|
||||
{
|
||||
$dirs['isdir'] = TRUE;
|
||||
$dirs['writeable'] = $this->TestWriteAble($dirname);
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有写入权限
|
||||
* @param string $d 目录路劲
|
||||
* @return boolean
|
||||
*/
|
||||
private function TestWriteAble($d)
|
||||
{
|
||||
$tfile = '_eyout.txt';
|
||||
$fp = @fopen($d.$tfile,'w');
|
||||
if(!$fp) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
fclose($fp);
|
||||
$rs = @unlink($d.$tfile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
355
src/application/admin/logic/ProductLogic.php
Normal file
355
src/application/admin/logic/ProductLogic.php
Normal file
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\db;
|
||||
/**
|
||||
* 产品逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class ProductLogic extends Model
|
||||
{
|
||||
/**
|
||||
* 动态获取产品参数输入框 根据不同的数据返回不同的输入框类型
|
||||
* @param int $aid 产品id
|
||||
* @param int $typeid 产品栏目id
|
||||
*/
|
||||
public function getAttrInput($aid, $typeid)
|
||||
{
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
$aid = intval($aid);
|
||||
$typeid = intval($typeid);
|
||||
$productAttribute = model('ProductAttribute');
|
||||
$attributeList = $productAttribute->where(['typeid'=>$typeid, 'is_del'=>0])->order('sort_order asc, attr_id asc')->select();
|
||||
$str = '';
|
||||
foreach($attributeList as $key => $val)
|
||||
{
|
||||
$attr_id = $val['attr_id'];
|
||||
$curAttrVal = $this->getProductAttrVal(NULL,$aid, $attr_id);
|
||||
//促使他 循环
|
||||
if(empty($curAttrVal))
|
||||
$curAttrVal[] = array('product_attr_id' =>'','aid' => '','attr_id' => '','attr_value' => '');
|
||||
foreach($curAttrVal as $k =>$v)
|
||||
{
|
||||
$str .= "<dl class='row attr_{$attr_id}'>";
|
||||
$addDelAttr = ''; // 加减符号
|
||||
$str .= "<dt class='tit pl5'><label for='attr_{$attr_id}'>$addDelAttr {$val['attr_name']}</label></dt>";
|
||||
|
||||
// 单行文本框
|
||||
if($val['attr_input_type'] == 0)
|
||||
{
|
||||
$str .= "<dd class='opt'><input type='text' size='40' value='".($aid ? $v['attr_value'] : $val['attr_values'])."' name='attr_{$attr_id}[]' /><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
// 下拉列表框(一行代表一个可选值)
|
||||
if($val['attr_input_type'] == 1)
|
||||
{
|
||||
$str .= "<dd class='opt'><select name='attr_{$attr_id}[]'><option value='0'>无</option>";
|
||||
$tmp_option_val = explode(PHP_EOL, $val['attr_values']);
|
||||
foreach($tmp_option_val as $k2=>$v2)
|
||||
{
|
||||
// 编辑的时候 有选中值
|
||||
$v2 = preg_replace("/\s/","",$v2);
|
||||
if($v['attr_value'] == $v2)
|
||||
$str .= "<option selected='selected' value='{$v2}'>{$v2}</option>";
|
||||
else
|
||||
$str .= "<option value='{$v2}'>{$v2}</option>";
|
||||
}
|
||||
$str .= "</select><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
// 多行文本框
|
||||
if($val['attr_input_type'] == 2)
|
||||
{
|
||||
$str .= "<dd class='opt'><textarea cols='40' rows='3' name='attr_{$attr_id}[]'>".($aid ? $v['attr_value'] : $val['attr_values'])."</textarea><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
// 富文本编辑器
|
||||
if($val['attr_input_type'] == 3)
|
||||
{
|
||||
$str .= "<dd class='opt'><textarea class='span12 ckeditor' id='attr_{$attr_id}' name='attr_{$attr_id}[]'>".($aid ? $v['attr_value'] : $val['attr_values'])."</textarea><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
$url = url('Ueditor/index', array('savepath'=>'product'));
|
||||
$str .= <<<EOF
|
||||
<script type="text/javascript">
|
||||
UE.getEditor("attr_{$attr_id}",{
|
||||
serverUrl :"{$url}",
|
||||
zIndex: 999,
|
||||
initialFrameWidth: "100%", //初化宽度
|
||||
initialFrameHeight: 300, //初化高度
|
||||
focus: false, //初始化时,是否让编辑器获得焦点true或false
|
||||
maximumWords: 99999,
|
||||
removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
|
||||
pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴,true为使用纯文本粘贴
|
||||
autoHeightEnabled: false,
|
||||
toolbars: ueditor_toolbars
|
||||
});
|
||||
</script>
|
||||
EOF;
|
||||
}
|
||||
$str .= "</dl>";
|
||||
}
|
||||
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态获取产品参数输入框 根据不同的数据返回不同的输入框类型
|
||||
* @param int $aid 产品id
|
||||
* @param int $typeid 产品栏目id
|
||||
*/
|
||||
public function getShopAttrInput($aid, $typeid, $list_id)
|
||||
{
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
$aid = intval($aid);
|
||||
$typeid = intval($typeid);
|
||||
$list_id = intval($list_id);
|
||||
$where = [
|
||||
'is_del' => 0
|
||||
];
|
||||
if (!empty($list_id)) {
|
||||
$where['list_id'] = $list_id;
|
||||
$where['status'] = 1;
|
||||
}
|
||||
$attributeList = Db::name('ShopProductAttribute')->where($where)->order('sort_order asc, attr_id asc')->select();
|
||||
$str = '';
|
||||
foreach($attributeList as $key => $val) {
|
||||
$attr_id = $val['attr_id'];
|
||||
$curAttrVal = $this->getShopProductAttrVal(NULL, $aid, $attr_id);
|
||||
|
||||
//促使他 循环
|
||||
if(empty($curAttrVal)) $curAttrVal[] = array('product_attr_id'=>'', 'aid'=>'', 'attr_id'=>'', 'attr_value'=>'');
|
||||
|
||||
foreach($curAttrVal as $k =>$v) {
|
||||
$str .= "<dl class='row attr_{$attr_id}'>";
|
||||
$addDelAttr = ''; // 加减符号
|
||||
$str .= "<dt class='tit pl5'><label for='attr_{$attr_id}'>$addDelAttr {$val['attr_name']}</label></dt>";
|
||||
|
||||
// 单行文本框
|
||||
if($val['attr_input_type'] == 0) {
|
||||
$str .= "<dd class='opt'><input type='text' size='40' value='".($aid ? $v['attr_value'] : $val['attr_values'])."' name='shop_attr_{$attr_id}[]' /><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
|
||||
// 下拉列表框(一行代表一个可选值)
|
||||
if($val['attr_input_type'] == 1) {
|
||||
$str .= "<dd class='opt'><select name='shop_attr_{$attr_id}[]'><option value='0'>无</option>";
|
||||
$tmp_option_val = explode(PHP_EOL, $val['attr_values']);
|
||||
foreach($tmp_option_val as $k2=>$v2)
|
||||
{
|
||||
// 编辑的时候 有选中值
|
||||
$v2 = preg_replace("/\s/","",$v2);
|
||||
if($v['attr_value'] == $v2)
|
||||
$str .= "<option selected='selected' value='{$v2}'>{$v2}</option>";
|
||||
else
|
||||
$str .= "<option value='{$v2}'>{$v2}</option>";
|
||||
}
|
||||
$str .= "</select><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
|
||||
// 多行文本框
|
||||
if($val['attr_input_type'] == 2) {
|
||||
$str .= "<dd class='opt'><textarea cols='40' rows='3' name='shop_attr_{$attr_id}[]'>".($aid ? $v['attr_value'] : $val['attr_values'])."</textarea><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
}
|
||||
|
||||
// 富文本编辑器
|
||||
if($val['attr_input_type'] == 3) {
|
||||
$str .= "<dd class='opt'><textarea class='span12 ckeditor' id='attr_{$attr_id}' name='shop_attr_{$attr_id}[]'>".($aid ? $v['attr_value'] : $val['attr_values'])."</textarea><span class='err' tyle='color:#F00; display:none;'></span><p class='notic'></p></dd>";
|
||||
$url = url('Ueditor/index', array('savepath'=>'product'));
|
||||
$str .= <<<EOF
|
||||
<script type="text/javascript">
|
||||
UE.getEditor("attr_{$attr_id}",{
|
||||
serverUrl :"{$url}",
|
||||
zIndex: 999,
|
||||
initialFrameWidth: "100%", //初化宽度
|
||||
initialFrameHeight: 300, //初化高度
|
||||
focus: false, //初始化时,是否让编辑器获得焦点true或false
|
||||
maximumWords: 99999,
|
||||
removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
|
||||
pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴,true为使用纯文本粘贴
|
||||
autoHeightEnabled: false,
|
||||
toolbars: ueditor_toolbars
|
||||
});
|
||||
</script>
|
||||
EOF;
|
||||
}
|
||||
$str .= "</dl>";
|
||||
}
|
||||
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 product_attr 表中指定 aid 指定 attr_id 或者 指定 product_attr_id 的值 可是字符串 可是数组
|
||||
* @param int $product_attr_id product_attr表id
|
||||
* @param int $aid 产品id
|
||||
* @param int $attr_id 产品参数id
|
||||
* @return array 返回数组
|
||||
*/
|
||||
public function getProductAttrVal($product_attr_id = 0 ,$aid = 0, $attr_id = 0)
|
||||
{
|
||||
$product_attr_id = intval($product_attr_id);
|
||||
$aid = intval($aid);
|
||||
$attr_id = intval($attr_id);
|
||||
|
||||
$productAttr = M('ProductAttr');
|
||||
if($product_attr_id > 0)
|
||||
return $productAttr->where(['product_attr_id'=>$product_attr_id])->select();
|
||||
if($aid > 0 && $attr_id > 0)
|
||||
return $productAttr->where(['aid'=>$aid,'attr_id'=>$attr_id])->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 shop_product_attr 表中指定 aid 指定 attr_id 或者 指定 product_attr_id 的值 可是字符串 可是数组
|
||||
* @param int $product_attr_id product_attr表id
|
||||
* @param int $aid 产品id
|
||||
* @param int $attr_id 产品参数id
|
||||
* @return array 返回数组
|
||||
*/
|
||||
public function getShopProductAttrVal($product_attr_id = 0 ,$aid = 0, $attr_id = 0)
|
||||
{
|
||||
$product_attr_id = intval($product_attr_id);
|
||||
$aid = intval($aid);
|
||||
$attr_id = intval($attr_id);
|
||||
|
||||
$ShopProductAttr = M('ShopProductAttr');
|
||||
|
||||
if($product_attr_id > 0) {
|
||||
return $ShopProductAttr->where(['product_attr_id'=>$product_attr_id])->select();
|
||||
}
|
||||
|
||||
if($aid > 0 && $attr_id > 0) {
|
||||
return $ShopProductAttr->where(['aid'=>$aid,'attr_id'=>$attr_id])->select();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定产品添加属性 或修改属性 更新到 product_attr
|
||||
* @param int $aid 产品id
|
||||
* @param int $typeid 产品栏目id
|
||||
*/
|
||||
public function saveProductAttr($aid, $typeid)
|
||||
{
|
||||
$aid = intval($aid);
|
||||
$typeid = intval($typeid);
|
||||
|
||||
$productAttr = M('ProductAttr');
|
||||
|
||||
// 属性类型被更改了 就先删除以前的属性类型 或者没有属性 则删除
|
||||
if($typeid == 0)
|
||||
{
|
||||
$productAttr->where('aid = '.$aid)->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$productAttrList = $productAttr->where('aid = '.$aid)->select();
|
||||
|
||||
$old_product_attr = array(); // 数据库中的的属性 以 attr_id _ 和值的 组合为键名
|
||||
foreach($productAttrList as $k => $v)
|
||||
{
|
||||
$old_product_attr[$v['attr_id'].'_'.$v['attr_value']] = $v;
|
||||
}
|
||||
|
||||
// post 提交的属性 以 attr_id _ 和值的 组合为键名
|
||||
$post = input("post.");
|
||||
foreach($post as $k => $v)
|
||||
{
|
||||
$attr_id = str_replace('attr_','',$k);
|
||||
if(!strstr($k, 'attr_'))
|
||||
continue;
|
||||
foreach ($v as $k2 => $v2)
|
||||
{
|
||||
//$v2 = str_replace('_', '', $v2); // 替换特殊字符
|
||||
//$v2 = str_replace('@', '', $v2); // 替换特殊字符
|
||||
$v2 = trim($v2);
|
||||
|
||||
if(empty($v2))
|
||||
continue;
|
||||
|
||||
$tmp_key = $attr_id."_".$v2;
|
||||
if(!array_key_exists($tmp_key , $old_product_attr)) // 数据库中不存在 说明要做删除操作
|
||||
{
|
||||
$adddata = array(
|
||||
'aid' => $aid,
|
||||
'attr_id' => $attr_id,
|
||||
'attr_value' => $v2,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$productAttr->add($adddata);
|
||||
}
|
||||
unset($old_product_attr[$tmp_key]);
|
||||
}
|
||||
|
||||
}
|
||||
// 没有被 unset($old_product_attr[$tmp_key]); 掉是 说明 数据库中存在 表单中没有提交过来则要删除操作
|
||||
foreach($old_product_attr as $k => $v)
|
||||
{
|
||||
$productAttr->where('product_attr_id = '.$v['product_attr_id'])->delete(); //
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定产品添加属性 或修改属性 更新到 shop_product_attr
|
||||
* @param int $aid 产品id
|
||||
* @param int $typeid 产品栏目id
|
||||
*/
|
||||
public function saveShopProductAttr($aid, $typeid)
|
||||
{
|
||||
$aid = intval($aid);
|
||||
$typeid = intval($typeid);
|
||||
|
||||
$ShopProductAttr = Db::name('ShopProductAttr');
|
||||
// 属性类型被更改了 就先删除以前的属性类型 或者没有属性 则删除
|
||||
if($typeid == 0) {
|
||||
$ShopProductAttr->where('aid = '.$aid)->delete();
|
||||
return false;
|
||||
}
|
||||
|
||||
$productAttrList = $ShopProductAttr->where('aid = '.$aid)->select();
|
||||
$old_product_attr = array(); // 数据库中的的属性 以 attr_id _ 和值的 组合为键名
|
||||
foreach($productAttrList as $k => $v) {
|
||||
$old_product_attr[$v['attr_id'].'_'.$v['attr_value']] = $v;
|
||||
}
|
||||
|
||||
// post 提交的属性 以 attr_id _ 和值的 组合为键名
|
||||
$post = input("post.");
|
||||
foreach($post as $k => $v) {
|
||||
$attr_id = str_replace('shop_attr_', '', $k);
|
||||
if(!strstr($k, 'shop_attr_')) continue;
|
||||
foreach ($v as $k2 => $v2) {
|
||||
$v2 = trim($v2);
|
||||
if(empty($v2)) continue;
|
||||
|
||||
$tmp_key = $attr_id . "_" . $v2;
|
||||
if(!array_key_exists($tmp_key, $old_product_attr)) {
|
||||
// 数据库中不存在 说明要做删除操作
|
||||
$adddata = array(
|
||||
'aid' => $aid,
|
||||
'attr_id' => $attr_id,
|
||||
'attr_value' => $v2,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
$ShopProductAttr->add($adddata);
|
||||
}
|
||||
unset($old_product_attr[$tmp_key]);
|
||||
}
|
||||
}
|
||||
|
||||
// 没有被 unset($old_product_attr[$tmp_key]); 掉是 说明 数据库中存在 表单中没有提交过来则要删除操作
|
||||
foreach($old_product_attr as $k => $v) {
|
||||
$ShopProductAttr->where('product_attr_id = '.$v['product_attr_id'])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
564
src/application/admin/logic/ProductSpecLogic.php
Normal file
564
src/application/admin/logic/ProductSpecLogic.php
Normal file
@@ -0,0 +1,564 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-07-08
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* 用于产品规格逻辑功能处理
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class ProductSpecLogic extends Model
|
||||
{
|
||||
/**
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
// 数组降级返回
|
||||
public function ArrayDowngrade($GetData = array())
|
||||
{
|
||||
$ReturnData = [];
|
||||
foreach ($GetData as $value){
|
||||
foreach ($value as $vv){
|
||||
$ReturnData[] = $vv;
|
||||
}
|
||||
}
|
||||
return $ReturnData;
|
||||
}
|
||||
|
||||
// 一维数组转为二级数组,携带子数组
|
||||
public function GetPresetData($GetData = array())
|
||||
{
|
||||
$GetData = group_same_key($GetData, 'preset_mark_id');
|
||||
$ReturnData = [];
|
||||
foreach ($GetData as $key => $value) {
|
||||
$ReturnData[] = [
|
||||
'preset_id' => $value[0]['preset_id'],
|
||||
'preset_mark_id' => $value[0]['preset_mark_id'],
|
||||
'preset_name' => $value[0]['preset_name'],
|
||||
'spec_sync' => $value[0]['spec_sync'],
|
||||
'sort_order' => $value[0]['sort_order'],
|
||||
'preset_value' => $value,
|
||||
];
|
||||
}
|
||||
return $ReturnData;
|
||||
}
|
||||
|
||||
// 删除规格名称\规格值条件
|
||||
public function GetDeleteSpecWhere($GetData = array())
|
||||
{
|
||||
$where = [];
|
||||
// 删除规格值
|
||||
if (isset($GetData['preset_id']) && !empty($GetData['preset_id'])) {
|
||||
$where = [
|
||||
'lang' => get_admin_lang(),
|
||||
'preset_id' => $GetData['preset_id'],
|
||||
];
|
||||
}
|
||||
// 删除规格名称,包扣规格名称下的所有规格值
|
||||
if (isset($GetData['preset_mark_id']) && !empty($GetData['preset_mark_id'])) {
|
||||
$where = [
|
||||
'lang' => get_admin_lang(),
|
||||
'preset_mark_id' => ['IN', $GetData['preset_mark_id']],
|
||||
];
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
// 拼装预设值下拉选项
|
||||
public function GetPresetValueOption($GetData = array(), $mark_id = null, $aid = null, $type = null)
|
||||
{
|
||||
$result = $PresetValueOption = '';
|
||||
if (!empty($mark_id)) {
|
||||
$where = [
|
||||
'lang' => get_admin_lang(),
|
||||
'aid' => $aid,
|
||||
'spec_is_select' => 0, // 未选中的
|
||||
'spec_mark_id' => ['IN',$mark_id],
|
||||
];
|
||||
$GetData = Db::name('product_spec_data')->where($where)->field('spec_value_id,spec_name,spec_value')->select();
|
||||
$PresetValueOption .= "<option value='0'>选择规格值</option>";
|
||||
foreach($GetData as $value){
|
||||
$PresetValueOption .= "<option value='{$value['spec_value_id']}'>{$value['spec_value']}</option>";
|
||||
}
|
||||
if (2 == $type) {
|
||||
$result = [
|
||||
'PresetName' => $GetData[0]['spec_name'],
|
||||
'PresetValueOption' => $PresetValueOption,
|
||||
];
|
||||
}else{
|
||||
$result = $PresetValueOption;
|
||||
}
|
||||
}else{
|
||||
$result .= "<option value='0'>选择规格值</option>";
|
||||
if(!empty($GetData)){
|
||||
foreach($GetData as $value){
|
||||
$result .= "<option value='{$value['preset_id']}'>{$value['preset_value']}</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 预设规格标记ID数组
|
||||
public function GetPresetMarkIdArray($GetData = array())
|
||||
{
|
||||
$result = '';
|
||||
if (isset($GetData['aid']) && !empty($GetData['aid'])) {
|
||||
$spec_mark_id_arr = $GetData['spec_mark_id_arr'];
|
||||
if (empty($spec_mark_id_arr)) {
|
||||
$result = $GetData['spec_mark_id'];
|
||||
}else{
|
||||
$return_spec_mark_id = $spec_mark_id_arr.','.$GetData['spec_mark_id'];
|
||||
if (3 < count(explode(',', $return_spec_mark_id))) {
|
||||
$result = false;
|
||||
}else{
|
||||
$result = $return_spec_mark_id;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$preset_mark_id_arr = $GetData['preset_mark_id_arr'];
|
||||
if (empty($preset_mark_id_arr)) {
|
||||
$result = $GetData['preset_mark_id'];
|
||||
}else{
|
||||
$return_preset_mark_id = $preset_mark_id_arr.','.$GetData['preset_mark_id'];
|
||||
if (3 < count(explode(',', $return_preset_mark_id))) {
|
||||
$result = false;
|
||||
}else{
|
||||
$result = $return_preset_mark_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 拼装规格名称下拉选项
|
||||
public function GetPresetNameOption($preset_mark_id_arr = null)
|
||||
{
|
||||
$MarkIdWhere = explode(',', $preset_mark_id_arr);
|
||||
$where = [
|
||||
'lang' => get_admin_lang(),
|
||||
'preset_mark_id' => ['NOT IN', $MarkIdWhere],
|
||||
];
|
||||
$PresetName = Db::name('product_spec_preset')->where($where)->field('preset_id,preset_mark_id,preset_name')->group('preset_mark_id')->order('preset_mark_id desc')->select();
|
||||
if($PresetName){
|
||||
// 拼装下拉选项
|
||||
foreach($PresetName as $value){
|
||||
$Option .= "<option value='{$value['preset_mark_id']}'>{$value['preset_name']}</option>";
|
||||
}
|
||||
}
|
||||
$result = [
|
||||
'MarkId' => implode(',', $MarkIdWhere),
|
||||
'Option' => $Option,
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function GetPresetSpecAssembly($GetData = array())
|
||||
{
|
||||
$preset_mark_id = $GetData['preset_mark_id'];
|
||||
if (isset($GetData['aid']) && !empty($GetData['aid'])) {
|
||||
$PresetMarkIdArray = $GetData['spec_mark_id_arr'];
|
||||
}else{
|
||||
$PresetMarkIdArray = $GetData['preset_mark_id_arr'];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
if (!empty($PresetMarkIdArray) && !empty($preset_mark_id)) {
|
||||
$mark_id_arr = explode(',', $PresetMarkIdArray);
|
||||
foreach ($mark_id_arr as $key => $value) {
|
||||
if ($value == $preset_mark_id) {
|
||||
unset($mark_id_arr[$key]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if (!empty($i)) {
|
||||
$PresetMarkIdArray = implode(',', $mark_id_arr);
|
||||
}
|
||||
}
|
||||
|
||||
$HtmlTable = '';
|
||||
if (!empty($i) && !empty($preset_mark_id)) {
|
||||
$spec_arr_ses = session('spec_arr');
|
||||
unset($spec_arr_ses[$preset_mark_id]);
|
||||
session('spec_arr', $spec_arr_ses);
|
||||
$HtmlTable = $this->SpecAssembly($spec_arr_ses);
|
||||
}
|
||||
|
||||
$return = [
|
||||
'HtmlTable' => $HtmlTable,
|
||||
'PresetMarkIdArray' => $PresetMarkIdArray,
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function GetResetPresetNameOption($GetData = array())
|
||||
{
|
||||
$del_mark_id = $GetData['del_mark_id'];
|
||||
$return = [
|
||||
'Option' => '',
|
||||
'MarkId' => '',
|
||||
];
|
||||
if (isset($del_mark_id) && !empty($del_mark_id) && !isset($GetData['del_preset_id'])) {
|
||||
$spec_arr_ses = session('spec_arr');
|
||||
unset($spec_arr_ses[$del_mark_id]);
|
||||
session('spec_arr',$spec_arr_ses);
|
||||
|
||||
/*在数据库中更新所清除的规格名称,更新为未选中状态*/
|
||||
if (isset($GetData['aid']) && !empty($GetData['aid'])) {
|
||||
$WhereData = [
|
||||
'aid' => $GetData['aid'],
|
||||
'spec_mark_id' => $del_mark_id,
|
||||
];
|
||||
$Update = [
|
||||
'spec_is_select' => 0,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
Db::name('product_spec_data')->where($WhereData)->update($Update);
|
||||
}
|
||||
/* END */
|
||||
|
||||
$PresetMarkIdArray = $GetData['preset_mark_id_arr'];
|
||||
if (empty($PresetMarkIdArray)) $PresetMarkIdArray = $GetData['spec_mark_id_arr'];
|
||||
|
||||
if (!empty($PresetMarkIdArray)) {
|
||||
$mark_id_arr = explode(',', $PresetMarkIdArray);
|
||||
foreach ($mark_id_arr as $key => $value) {
|
||||
if ($value == $del_mark_id) {
|
||||
unset($mark_id_arr[$key]);
|
||||
}
|
||||
}
|
||||
$PresetMarkIdArray = implode(',', $mark_id_arr);
|
||||
}
|
||||
$ReturnData = $this->GetPresetNameOption($PresetMarkIdArray);
|
||||
$return = $ReturnData;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function ClearSpecValueID($GetData = array())
|
||||
{
|
||||
// 清除单个规格值
|
||||
$del_mark_id = $GetData['del_mark_id'];
|
||||
$return = [
|
||||
'Option' => '',
|
||||
];
|
||||
if (isset($del_mark_id) && !empty($del_mark_id) && isset($GetData['del_preset_id'])) {
|
||||
$spec_arr_ses = session('spec_arr');
|
||||
foreach ($spec_arr_ses[$del_mark_id] as $key => $value) {
|
||||
if ($value == $GetData['del_preset_id']) {
|
||||
unset($spec_arr_ses[$del_mark_id][$key]);
|
||||
}
|
||||
}
|
||||
if (empty($spec_arr_ses[$del_mark_id])) {
|
||||
unset($spec_arr_ses[$del_mark_id]);
|
||||
}
|
||||
session('spec_arr',$spec_arr_ses);
|
||||
$preset_id = $spec_arr_ses[$del_mark_id];
|
||||
if (empty($GetData['aid'])) {
|
||||
$WhereNew = [
|
||||
'preset_mark_id' => $del_mark_id,
|
||||
'preset_id' => ['NOT IN',$preset_id],
|
||||
];
|
||||
// 加载选中的规格值
|
||||
$PresetValue = Db::name('product_spec_preset')->where($WhereNew)->select();
|
||||
$return['Option'] = $this->GetPresetValueOption($PresetValue);
|
||||
}else{
|
||||
// 更新规格值
|
||||
$Where = [
|
||||
'aid' => $GetData['aid'],
|
||||
'spec_mark_id' => $del_mark_id,
|
||||
'spec_value_id' => $GetData['del_preset_id'],
|
||||
'spec_is_select'=> 1,
|
||||
];
|
||||
Db::name('product_spec_data')->where($Where)->update(['spec_is_select'=>0, 'update_time'=>getTime()]);
|
||||
|
||||
// 拼装新的下拉框数据
|
||||
$WhereNew = [
|
||||
'aid' => $GetData['aid'],
|
||||
'spec_mark_id' => $del_mark_id,
|
||||
'spec_is_select' => 0,
|
||||
];
|
||||
$Data = Db::name('product_spec_data')->where($WhereNew)->field('spec_value_id,spec_value')->select();
|
||||
$return['Option'] .= "<option value='0'>选择规格值</option>";
|
||||
foreach($Data as $value){
|
||||
$return['Option'] .= "<option value='{$value['spec_value_id']}'>{$value['spec_value']}</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function GetSessionPostArrayMerge($GetData = array())
|
||||
{
|
||||
$preset_id = $GetData['preset_id'];
|
||||
$preset_mark_id = $GetData['preset_mark_id'];
|
||||
$spec_arr_ses = session('spec_arr');
|
||||
|
||||
if (!empty($preset_mark_id) && !empty($preset_id)) {
|
||||
$spec_arr_new = [
|
||||
$preset_mark_id => [
|
||||
$preset_id,
|
||||
],
|
||||
];
|
||||
foreach ($spec_arr_new as $key => $value) {
|
||||
if (isset($spec_arr_ses[$key])) {
|
||||
if (in_array($value[0], $spec_arr_ses[$key])) {
|
||||
$msg['error'] = '已有相同规格值,无需重复添加!';
|
||||
return $msg;
|
||||
}else{
|
||||
// session存在数据,但选中参数在数据中还没有,合并数据
|
||||
$spec_arr_ses[$key] = array_merge($spec_arr_ses[$key], $value);
|
||||
}
|
||||
}else{
|
||||
if (!empty($spec_arr_ses)) {
|
||||
// 不存在
|
||||
$spec_arr_ses = $spec_arr_ses + $spec_arr_new;
|
||||
}else{
|
||||
$spec_arr_ses = $spec_arr_new;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
session('spec_arr',$spec_arr_ses);
|
||||
return $spec_arr_ses;
|
||||
}
|
||||
|
||||
public function SpecAssembly($GetData = array())
|
||||
{
|
||||
if (empty($GetData)) return ' ';
|
||||
|
||||
// 参数处理
|
||||
foreach ($GetData as $k => $v) {
|
||||
$spec_arr_sort[$k] = count($v);
|
||||
}
|
||||
asort($spec_arr_sort);
|
||||
foreach ($spec_arr_sort as $key =>$val) {
|
||||
$spec_arr2[$key] = $GetData[$key];
|
||||
}
|
||||
// 获取KEY值
|
||||
$clo_name = array_keys($spec_arr2);
|
||||
// 数据组合
|
||||
$spec_arr2 = $this->DataCombination($spec_arr2);
|
||||
// 查询预设名称
|
||||
$spec = Db::name('product_spec_preset')->group('preset_mark_id')->getField('preset_mark_id,preset_name');
|
||||
// 查询预设值
|
||||
$specItem = Db::name('product_spec_preset')->getField('preset_id,preset_value,preset_mark_id');
|
||||
// 组合HTML
|
||||
$ReturnHtml = "<table class='table table-bordered' id='spec_input_tab' border='1' cellpadding='10' cellspacing='10'><thead><tr>";
|
||||
// 显示第一行的数据
|
||||
foreach ($clo_name as $k => $v) {
|
||||
$ReturnHtml .= "<td><b><input type='hidden' class='prese_name_input_{$v}' name='preset_mark_id[$v][preset_name]' value='{$spec[$v]}'><span class='preset_name_span_{$v}'>{$spec[$v]}</span></b></td>";
|
||||
}
|
||||
$ReturnHtml .= "<td><b>价格 <a href=\"javascript:void(0);\" onclick=\"BulkSetPrice(this);\">批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "<td><b>库存 <a href=\"javascript:void(0);\" onclick=\"BulkSetStock(this);\">批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "<td><b>销量</b></td>";
|
||||
$ReturnHtml .= "</tr></thead><tbody>";
|
||||
|
||||
// 显示第二行开始
|
||||
foreach ($spec_arr2 as $k => $v) {
|
||||
$ReturnHtml .= "<tr id='preset_value_tr_{$v[0]}'>";
|
||||
$preset_key_name = array();
|
||||
foreach($v as $k2 => $v2) {
|
||||
$ReturnHtml .= "<td><input type='hidden' class='preset_value_input_{$v2}' name='preset_id[$v2][preset_value]' value='{$specItem[$v2]['preset_value']}'><span class='preset_value_span_{$v2}'>{$specItem[$v2]['preset_value']}</span></td>";
|
||||
$preset_key_name[$v2] = $spec[$specItem[$v2]['preset_mark_id']].':'.$specItem[$v2]['preset_value'];
|
||||
}
|
||||
ksort($preset_key_name);
|
||||
$preset_key = implode('_', array_keys($preset_key_name));
|
||||
|
||||
$ReturnHtml .="<td><input class='users_price' name='preset_price[$preset_key][users_price]' value='0' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");UpPrice(this);' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")'/></td>";
|
||||
|
||||
$ReturnHtml .="<td><input class='stock_count' name='preset_stock[$preset_key][stock_count]' value='0' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");UpStock(this);' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' data-old_stock='0'/></td>";
|
||||
|
||||
$ReturnHtml .="<td><input type='text' name='spec_sales[$spec_key][spec_sales_num]' value='0' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\")' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")'></td>";
|
||||
|
||||
$ReturnHtml .="</tr>";
|
||||
}
|
||||
$ReturnHtml .= "</tbody>";
|
||||
$ReturnHtml .= "</table>";
|
||||
// $ReturnHtml .= '批量设置:<a href="javascript:void(0);" onclick="BulkSetPrice(this);" >价格</a> <a href="javascript:void(0);" onclick="BulkSetStock(this);" >库存</a>';
|
||||
|
||||
return $ReturnHtml;
|
||||
}
|
||||
|
||||
public function SpecAssemblyEdit($GetData = array(), $aid = null)
|
||||
{
|
||||
if (empty($GetData)) return ' ';
|
||||
// 参数处理
|
||||
foreach ($GetData as $k => $v) {
|
||||
$spec_arr_sort[$k] = count($v);
|
||||
}
|
||||
asort($spec_arr_sort);
|
||||
foreach ($spec_arr_sort as $key =>$val) {
|
||||
$spec_arr2[$key] = $GetData[$key];
|
||||
}
|
||||
// 排序
|
||||
$order = 'spec_value_id asc, spec_id asc, spec_mark_id asc';
|
||||
// 获取KEY值
|
||||
$clo_name = array_keys($spec_arr2);
|
||||
// 数据组合
|
||||
$spec_arr2 = $this->DataCombination($spec_arr2);
|
||||
// 查询规格名称
|
||||
$spec = Db::name('product_spec_data')->where('aid',$aid)->order($order)->group('spec_mark_id')->getField('spec_mark_id, spec_name');
|
||||
// 查询规格值
|
||||
$specItem = Db::name('product_spec_data')->where('aid',$aid)->order($order)->getField('spec_value_id, spec_value, spec_mark_id');
|
||||
// 查询规格价格
|
||||
$specPrice = Db::name('product_spec_value')->where('aid', $aid)->order('spec_price asc')->getField('spec_value_id, spec_price, spec_stock, spec_sales_num');
|
||||
// 组合HTML
|
||||
$ReturnHtml = "<table class='table table-bordered' id='spec_input_tab' border='1' cellpadding='10' cellspacing='10'><thead><tr>";
|
||||
// 显示第一行的数据
|
||||
foreach ($clo_name as $k => $v) {
|
||||
$ReturnHtml .= "<td><b><input type='hidden' class='spec_name_input_{$v}' name='spec_mark_id[$v][spec_name]' value='{$spec[$v]}'><span class='spec_name_span_{$v}'>{$spec[$v]}</span></b></td>";
|
||||
}
|
||||
$ReturnHtml .= "<td><b>价格 <a href=\"javascript:void(0);\" onclick=\"BulkSetPrice(this);\">批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "<td><b>库存 <a href=\"javascript:void(0);\" onclick=\"BulkSetStock(this);\" >批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "<td><b>销量</b></td>";
|
||||
$ReturnHtml .= "</tr></thead><tbody>";
|
||||
|
||||
// 显示第二行开始
|
||||
foreach ($spec_arr2 as $k => $v) {
|
||||
$ReturnHtml .= "<tr>";
|
||||
$spec_key_name = array();
|
||||
foreach($v as $k2 => $v2) {
|
||||
$ReturnHtml .= "<td><input type='hidden' class='spec_value_input_{$v2}' name='spec_value_id[$v2][spec_value]' value='{$specItem[$v2]['spec_value']}'><span class='spec_value_span_{$v2}'>{$specItem[$v2]['spec_value']}</span></td>";
|
||||
$spec_key_name[$v2] = $spec[$specItem[$v2]['spec_mark_id']].':'.$specItem[$v2]['spec_value'];
|
||||
}
|
||||
ksort($spec_key_name);
|
||||
$spec_key = implode('_', array_keys($spec_key_name));
|
||||
|
||||
$ReturnHtml .="<td><input class='users_price' name='spec_price[$spec_key][users_price]' value='{$specPrice[$spec_key]['spec_price']}' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");UpPrice(this);'/></td>";
|
||||
|
||||
$ReturnHtml .="<td><input class='stock_count' name='spec_stock[$spec_key][stock_count]' value='{$specPrice[$spec_key]['spec_stock']}' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");UpStock(this);' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' data-old_stock='{$specPrice[$spec_key]['spec_stock']}'/></td>";
|
||||
|
||||
$ReturnHtml .="<td><input type='text' name='spec_sales[$spec_key][spec_sales_num]' value='{$specPrice[$spec_key]['spec_sales_num']}' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\")' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")'></td>";
|
||||
|
||||
$ReturnHtml .="</tr>";
|
||||
}
|
||||
$ReturnHtml .= "</tbody>";
|
||||
$ReturnHtml .= "</table>";
|
||||
// $ReturnHtml .= '批量设置:<a href="javascript:void(0);" onclick="BulkSetPrice(this);" >批量设置</a> <a href="javascript:void(0);" onclick="BulkSetStock(this);" >批量设置</a>';
|
||||
|
||||
return $ReturnHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2020/12/18 大黄 秒杀 多规格设置
|
||||
*/
|
||||
public function SharpSpecAssemblyEdit($GetData = array(), $aid = null)
|
||||
{
|
||||
if (empty($GetData)) return ' ';
|
||||
// 参数处理
|
||||
foreach ($GetData as $k => $v) {
|
||||
$spec_arr_sort[$k] = count($v);
|
||||
}
|
||||
asort($spec_arr_sort);
|
||||
foreach ($spec_arr_sort as $key =>$val) {
|
||||
$spec_arr2[$key] = $GetData[$key];
|
||||
}
|
||||
// 排序
|
||||
$order = 'spec_value_id asc, spec_id asc, spec_mark_id asc';
|
||||
// 获取KEY值
|
||||
$clo_name = array_keys($spec_arr2);
|
||||
// 数据组合
|
||||
$spec_arr2 = $this->DataCombination($spec_arr2);
|
||||
// 查询规格名称
|
||||
$spec = Db::name('product_spec_data')->where('aid',$aid)->order($order)->group('spec_mark_id')->getField('spec_mark_id, spec_name');
|
||||
// 查询规格值
|
||||
$specItem = Db::name('product_spec_data')->where('aid',$aid)->order($order)->getField('spec_value_id, spec_value, spec_mark_id');
|
||||
// 查询规格价格
|
||||
$specPrice = Db::name('product_spec_value')->where('aid', $aid)->order('spec_price asc')->getField('spec_value_id, spec_price, spec_stock, seckill_price, seckill_stock');
|
||||
// 组合HTML
|
||||
$ReturnHtml = "<table class='table table-bordered' id='spec_input_tab' border='1' cellpadding='10' cellspacing='10'><thead><tr>";
|
||||
// 显示第一行的数据
|
||||
foreach ($clo_name as $k => $v) {
|
||||
$ReturnHtml .= "<td><b><input type='hidden' class='spec_name_input_{$v}' name='spec_mark_id[$v][spec_name]' value='{$spec[$v]}'><span class='spec_name_span_{$v}'>{$spec[$v]}</span></b></td>";
|
||||
}
|
||||
$ReturnHtml .= "<td><b>价格 </b></td>";
|
||||
$ReturnHtml .= "<td><b>库存 </b></td>";
|
||||
$ReturnHtml .= "<td><b><em class='red'>*</em>秒杀价格 <a href=\"javascript:void(0);\" onclick=\"BulkSetPrice(this);\">批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "<td><b><em class='red'>*</em>秒杀库存 <a href=\"javascript:void(0);\" onclick=\"BulkSetStock(this);\" >批量设置 </a></b></td>";
|
||||
$ReturnHtml .= "</tr></thead><tbody>";
|
||||
|
||||
// 显示第二行开始
|
||||
foreach ($spec_arr2 as $k => $v) {
|
||||
$ReturnHtml .= "<tr>";
|
||||
$spec_key_name = array();
|
||||
foreach($v as $k2 => $v2) {
|
||||
$ReturnHtml .= "<td><input type='hidden' class='spec_value_input_{$v2}' name='spec_value_id[$v2][spec_value]' value='{$specItem[$v2]['spec_value']}'><span class='spec_value_span_{$v2}'>{$specItem[$v2]['spec_value']}</span></td>";
|
||||
$spec_key_name[$v2] = $spec[$specItem[$v2]['spec_mark_id']].':'.$specItem[$v2]['spec_value'];
|
||||
}
|
||||
ksort($spec_key_name);
|
||||
$spec_key = implode('_', array_keys($spec_key_name));
|
||||
|
||||
$ReturnHtml .="<td>{$specPrice[$spec_key]['spec_price']}<input type='hidden' class='users_price' name='spec_price[$spec_key][users_price]' value='{$specPrice[$spec_key]['spec_price']}' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");'/></td>";
|
||||
|
||||
$ReturnHtml .="<td>{$specPrice[$spec_key]['spec_stock']}<input type='hidden' class='stock_count' name='spec_stock[$spec_key][stock_count]' value='{$specPrice[$spec_key]['spec_stock']}' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' data-old_stock='{$specPrice[$spec_key]['spec_stock']}'/></td>";
|
||||
|
||||
if ($specPrice[$spec_key]['seckill_price'] > 0){
|
||||
$seckill_price = $specPrice[$spec_key]['seckill_price'];
|
||||
}else{
|
||||
$seckill_price = '';
|
||||
}
|
||||
$ReturnHtml .="<td><input class='spec_seckill_price' name='seckill_price[$spec_key][spec_seckill_price]' value='{$seckill_price}' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");'/></td>";
|
||||
if ($specPrice[$spec_key]['seckill_stock'] > 0){
|
||||
$seckill_stock = $specPrice[$spec_key]['seckill_stock'];
|
||||
}else{
|
||||
$seckill_stock = '';
|
||||
}
|
||||
$ReturnHtml .="<td><input class='spec_seckill_stock' name='seckill_stock[$spec_key][spec_seckill_stock]' value='{$seckill_stock}' onkeyup='this.value=this.value.replace(/[^\d.]/g,\"\");' onpaste='this.value=this.value.replace(/[^\d.]/g,\"\")' data-old_stock='{$specPrice[$spec_key]['seckill_stock']}'/></td>";
|
||||
|
||||
$ReturnHtml .="</tr>";
|
||||
}
|
||||
$ReturnHtml .= "</tbody>";
|
||||
$ReturnHtml .= "</table>";
|
||||
// $ReturnHtml .= '批量设置:<a href="javascript:void(0);" onclick="BulkSetPrice(this);" >批量设置</a> <a href="javascript:void(0);" onclick="BulkSetStock(this);" >批量设置</a>';
|
||||
|
||||
return $ReturnHtml;
|
||||
}
|
||||
|
||||
// 数据组合
|
||||
private function DataCombination()
|
||||
{
|
||||
$data = func_get_args();
|
||||
$data = current($data);
|
||||
$result = array();
|
||||
$arr1 = array_shift($data);
|
||||
foreach($arr1 as $key => $item) {
|
||||
$result[] = array($item);
|
||||
}
|
||||
|
||||
foreach($data as $key => $item) {
|
||||
$result = $this->DataCombinationArray($result, $item);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function DataCombinationArray($arr1, $arr2)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($arr1 as $item1) {
|
||||
foreach ($arr2 as $item2) {
|
||||
$temp = $item1;
|
||||
$temp[] = $item2;
|
||||
$result[] = $temp;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
536
src/application/admin/logic/ShopLogic.php
Normal file
536
src/application/admin/logic/ShopLogic.php
Normal file
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 逻辑定义
|
||||
* Class CatsLogic
|
||||
* @package admin\Logic
|
||||
*/
|
||||
class ShopLogic extends Model
|
||||
{
|
||||
private $request = null;
|
||||
private $data_path;
|
||||
private $version_txt_path;
|
||||
private $version;
|
||||
private $service_url;
|
||||
private $upgrade_url;
|
||||
private $service_ey;
|
||||
private $planPath_pc;
|
||||
private $planPath_m;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
$this->request = request();
|
||||
$this->service_ey = config('service_ey');
|
||||
$this->data_path = DATA_PATH; //
|
||||
$this->version_txt_path = $this->data_path.'conf'.DS.'version_themeshop.txt'; // 版本文件路径
|
||||
$this->version = getVersion('version_themeshop');
|
||||
// api_Service_checkVersion
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT1jaGVja1RoZW1lVmVyc2lvbg==';
|
||||
$this->service_url = base64_decode($this->service_ey).base64_decode($tmp_str);
|
||||
$this->upgrade_url = $this->service_url . '&domain='.request()->host(true).'&v=' . $this->version.'&type=theme_shop&cms_version='.getVersion().'&ip='.serverIP();
|
||||
$this->planPath_pc = 'template/'.TPL_THEME.'pc/';
|
||||
$this->planPath_m = 'template/'.TPL_THEME.'mobile/';
|
||||
}
|
||||
|
||||
// 过期订单预处理
|
||||
public function OverdueOrderHandle()
|
||||
{
|
||||
$ShopOrder = Db::name('shop_order')->where('order_status', 4)->column('order_id');
|
||||
if (!empty($ShopOrder)) {
|
||||
// 删除条件
|
||||
$where['order_id'] = ['IN', $ShopOrder];
|
||||
// 删除订单主表
|
||||
Db::name('shop_order')->where($where)->delete();
|
||||
// 删除订单副表
|
||||
Db::name('shop_order_details')->where($where)->delete();
|
||||
// 删除订单操作记录表
|
||||
Db::name('shop_order_log')->where($where)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测并第一次从官方同步订单中心的前台模板
|
||||
*/
|
||||
public function syn_theme_shop()
|
||||
{
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
if ('v1.0.1' > $this->version) {
|
||||
return $this->OneKeyUpgrade();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测目录权限
|
||||
*/
|
||||
public function checkAuthority($filelist = '')
|
||||
{
|
||||
/*------------------检测目录读写权限----------------------*/
|
||||
$filelist = htmlspecialchars_decode($filelist);
|
||||
$filelist = explode('<br>', $filelist);
|
||||
|
||||
$dirs = array();
|
||||
$i = -1;
|
||||
foreach($filelist as $filename)
|
||||
{
|
||||
if (stristr($filename, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($filename, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tfilename = $filename;
|
||||
$curdir = $this->GetDirName($tfilename);
|
||||
if (empty($curdir)) {
|
||||
continue;
|
||||
}
|
||||
if( !isset($dirs[$curdir]) )
|
||||
{
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
if($dirs[$curdir]['isdir'] == FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$dirs[$curdir] = $this->TestIsFileDir($curdir);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$is_pass = true;
|
||||
$msg = '检测通过';
|
||||
if($i > -1)
|
||||
{
|
||||
$n = 0;
|
||||
$dirinfos = '';
|
||||
foreach($dirs as $curdir)
|
||||
{
|
||||
$dirinfos .= $curdir['name']." 状态:";
|
||||
if ($curdir['writeable']) {
|
||||
$dirinfos .= "[√正常]";
|
||||
} else {
|
||||
$is_pass = false;
|
||||
$n++;
|
||||
$dirinfos .= "<font color='red'>[×不可写]</font>";
|
||||
}
|
||||
$dirinfos .= "<br />";
|
||||
}
|
||||
$title = "本次升级需要在下面文件夹写入更新文件,已检测站点有 <font color='red'>{$n}</font> 处没有写入权限:<br />";
|
||||
$title .= "<font color='red'>问题分析(如有问题,请咨询技术支持):<br />";
|
||||
$title .= "1、检查站点目录的用户组与所有者,禁止是 root ;<br />";
|
||||
$title .= "2、检查站点目录的读写权限,一般权限值是 0755 ;<br />";
|
||||
$title .= "</font>涉及更新目录列表如下:<br />";
|
||||
$msg = $title . $dirinfos;
|
||||
}
|
||||
/*------------------end----------------------*/
|
||||
|
||||
if (true === $is_pass) {
|
||||
return ['code'=>1, 'msg'=>$msg];
|
||||
} else {
|
||||
return ['code'=>0, 'msg'=>$msg, 'data'=>['code'=>1]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkVersion() {
|
||||
//error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 1, 'msg' => "<font color='red'>请联系空间商(设置 php.ini 中参数 allow_url_fopen = 1)</font>"];
|
||||
}
|
||||
|
||||
$url = $this->upgrade_url;
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
|
||||
$serviceVersionList = @file_get_contents($url,false,$context);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if(!empty($serviceVersionList))
|
||||
{
|
||||
$upgradeArr = array();
|
||||
$introStr = '';
|
||||
$upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br>'.filter_line_return($val['intro'], '<br>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
foreach ($upgradeArr as $key => $val) {
|
||||
if (stristr($val, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
unset($upgradeArr[$key]);
|
||||
} else if (stristr($val, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
unset($upgradeArr[$key]);
|
||||
}
|
||||
}
|
||||
$upgradeStr = implode('<br>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function OneKeyUpgrade() {
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,设置 php.ini 中参数 allow_url_fopen = 1"];
|
||||
}
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,开启 php.ini 中的php-zip扩展"];
|
||||
}
|
||||
|
||||
$serviceVersionList = @file_get_contents($this->upgrade_url);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if (empty($serviceVersionList)) {
|
||||
if ('v1.0.1' > $this->version) {
|
||||
return ['code' => 0, 'msg' => "请求服务器失败,请检查是否网络故障!"];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => "没找到升级信息"];
|
||||
}
|
||||
} else if (isset($serviceVersionList['code']) && empty($serviceVersionList['code'])) {
|
||||
$icon = !empty($serviceVersionList['icon']) ? $serviceVersionList['icon'] : 2;
|
||||
return ['code' => 0, 'msg' => $serviceVersionList['msg'], 'icon'=>$icon];
|
||||
}
|
||||
|
||||
clearstatcache(); // 清除文件夹权限缓存
|
||||
if (!is_writeable($this->version_txt_path)) {
|
||||
return ['code' => 0, 'msg' => '文件'.$this->version_txt_path.' 不可写,不能升级!!!'];
|
||||
}
|
||||
/*最新更新版本信息*/
|
||||
$lastServiceVersion = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
/*--end*/
|
||||
/*批量下载更新包*/
|
||||
$upgradeArr = array(); // 更新的文件列表
|
||||
$folderName = 'shop-'.$lastServiceVersion['key_num'];
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
// 下载更新包
|
||||
$result = $this->downloadFile($val['down_url'], $val['file_md5']);
|
||||
if (!isset($result['code']) || $result['code'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*第一个循环执行的业务*/
|
||||
if ($key == 0) {
|
||||
/*解压到最后一个更新包的文件夹*/
|
||||
$lastDownFileName = explode('/', $lastServiceVersion['down_url']);
|
||||
$lastDownFileName = end($lastDownFileName);
|
||||
$folderName = 'shop-'.str_replace(".zip", "", $lastDownFileName); // 文件夹
|
||||
/*--end*/
|
||||
|
||||
/*解压之前,删除已重复的文件夹*/
|
||||
delFile($this->data_path.'backup'.DS.'theme'.DS.$folderName);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$downFileName = explode('/', $val['down_url']);
|
||||
$downFileName = 'shop-'.end($downFileName);
|
||||
|
||||
/*解压文件*/
|
||||
$zip = new \ZipArchive();//新建一个ZipArchive的对象
|
||||
if ($zip->open($this->data_path.'backup'.DS.'theme'.DS.$downFileName) != true) {
|
||||
return ['code' => 0, 'msg' => "升级包读取失败!"];
|
||||
}
|
||||
$zip->extractTo($this->data_path.'backup'.DS.'theme'.DS.$folderName.DS);//假设解压缩到在当前路径下backup文件夹内
|
||||
$zip->close();//关闭处理的zip文件
|
||||
/*--end*/
|
||||
|
||||
if (!file_exists($this->data_path.'backup'.DS.'theme'.DS.$folderName.DS.'data'.DS.'conf'.DS.'version_themeshop.txt')) {
|
||||
return ['code' => 0, 'msg' => "缺少version_themeshop.txt文件,请联系客服"];
|
||||
}
|
||||
|
||||
/*更新的文件列表*/
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*将多个更新包重新组建一个新的完全更新包*/
|
||||
$upgradeArr = array_unique($upgradeArr); // 移除文件列表里重复的文件
|
||||
$serviceVersion = $lastServiceVersion;
|
||||
$serviceVersion['upgrade'] = $upgradeArr;
|
||||
/*--end*/
|
||||
|
||||
/*升级之前,备份涉及的源文件*/
|
||||
$upgrade = $serviceVersion['upgrade'];
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$source_file = ROOT_PATH.$val;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = $this->data_path.'backup'.DS.'theme'.DS.$folderName.'_www'.DS.$val;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
$copy_bool = @copy($source_file, $destination_file);
|
||||
if (false == $copy_bool) {
|
||||
return ['code' => 0, 'msg' => "更新前备份文件失败,请检查所有目录是否有读写权限"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 递归复制文件夹
|
||||
$copy_data = $this->recurse_copy($this->data_path.'backup'.DS.'theme'.DS.$folderName, rtrim(ROOT_PATH, DS), $folderName);
|
||||
|
||||
/*删除下载的升级包*/
|
||||
$ziplist = glob($this->data_path.'backup'.DS.'theme'.DS.'shop-*.zip');
|
||||
@array_map('unlink', $ziplist);
|
||||
/*--end*/
|
||||
|
||||
// 推送回服务器 记录升级成功
|
||||
$this->UpgradeLog($serviceVersion['key_num']);
|
||||
|
||||
return ['code' => $copy_data['code'], 'msg' => "升级模板成功{$copy_data['msg']}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @param string $folderName 存放升级包目录名称
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst, $folderName)
|
||||
{
|
||||
static $badcp = 0; // 累计覆盖失败的文件总数
|
||||
static $n = 0; // 累计执行覆盖的文件总数
|
||||
static $total = 0; // 累计更新的文件总数
|
||||
|
||||
$dir = opendir($src);
|
||||
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$dst_tmp = str_replace('\\', '/', $dst);
|
||||
$dst_tmp = rtrim($dst_tmp, '/').'/';
|
||||
if (stristr($dst_tmp, $this->planPath_pc) && file_exists($this->planPath_pc)) {
|
||||
tp_mkdir($dst);
|
||||
} else if (stristr($dst_tmp, $this->planPath_m) && file_exists($this->planPath_m)) {
|
||||
tp_mkdir($dst);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$needle = '/template/'.TPL_THEME;
|
||||
$needle = rtrim($needle, '/');
|
||||
$dstfile = $dst . '/' . $file;
|
||||
if (!stristr($dstfile, $needle)) {
|
||||
$dstfile = str_replace('/template', $needle, $dstfile);
|
||||
}
|
||||
$this->recurse_copy($src . '/' . $file, $dstfile, $folderName);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
/*pc和mobile目录存在的情况下,才拷贝会员模板到相应的pc或mobile里*/
|
||||
$rs = true;
|
||||
$src_tmp = str_replace('\\', '/', $src . DIRECTORY_SEPARATOR . $file);
|
||||
if (stristr($src_tmp, $this->planPath_pc) && !file_exists($this->planPath_pc)) {
|
||||
continue;
|
||||
} else if (stristr($src_tmp, $this->planPath_m) && !file_exists($this->planPath_m)) {
|
||||
continue;
|
||||
}
|
||||
/*--end*/
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
$n++;
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
} else {
|
||||
$n++;
|
||||
$badcp++;
|
||||
}
|
||||
} else {
|
||||
$n++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
$code = 1;
|
||||
$msg = '!';
|
||||
if($badcp > 0)
|
||||
{
|
||||
$code = 2;
|
||||
$msg = ",其中失败 <font color='red'>{$badcp}</font> 个文件,<br />请从升级包目录[<font color='red'>data/backup/theme/{$folderName}</font>]中的取出全部文件覆盖到根目录,完成手工升级。";
|
||||
}
|
||||
|
||||
$this->copy_speed($n, $total);
|
||||
|
||||
return ['code'=>$code, 'msg'=>$msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文件进度
|
||||
*/
|
||||
private function copy_speed($n, $total)
|
||||
{
|
||||
$data = false;
|
||||
|
||||
if ($n < $total) {
|
||||
$this->copy_speed($n, $total);
|
||||
} else {
|
||||
$data = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type $fileUrl 下载文件地址
|
||||
* @param type $md5File 文件MD5 加密值 用于对比下载是否完整
|
||||
* @return string 错误或成功提示
|
||||
*/
|
||||
private function downloadFile($fileUrl,$md5File)
|
||||
{
|
||||
$downFileName = explode('/', $fileUrl);
|
||||
$downFileName = 'shop-'.end($downFileName);
|
||||
$saveDir = $this->data_path.'backup'.DS.'theme'.DS.$downFileName; // 保存目录
|
||||
tp_mkdir(dirname($saveDir));
|
||||
if(!file_get_contents($fileUrl, 0, null, 0, 1)){
|
||||
return ['code' => 0, 'msg' => '官方升级包不存在']; // 文件存在直接退出
|
||||
}
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
$file = curl_exec ($ch);
|
||||
curl_close ($ch);
|
||||
$fp = fopen($saveDir,'w');
|
||||
fwrite($fp, $file);
|
||||
fclose($fp);
|
||||
if(!eyPreventShell($saveDir) || !file_exists($saveDir) || $md5File != md5_file($saveDir))
|
||||
{
|
||||
return ['code' => 0, 'msg' => '下载保存升级包失败,请检查所有目录的权限以及用户组不能为root'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '下载成功'];
|
||||
}
|
||||
|
||||
// 升级记录 log 日志
|
||||
private function UpgradeLog($to_key_num){
|
||||
$serial_number = DEFAULT_SERIALNUMBER;
|
||||
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
|
||||
}
|
||||
$mysqlinfo = \think\Db::query("SELECT VERSION() as version");
|
||||
$mysql_version = $mysqlinfo[0]['version'];
|
||||
$vaules = array(
|
||||
'type' => 'theme_shop',
|
||||
'domain'=>$_SERVER['HTTP_HOST'], //用户域名
|
||||
'key_num'=>$this->version, // 用户版本号
|
||||
'to_key_num'=>$to_key_num, // 用户要升级的版本号
|
||||
'add_time'=>time(), // 升级时间
|
||||
'serial_number'=>$serial_number,
|
||||
'ip' => GetHostByName($_SERVER['SERVER_NAME']),
|
||||
'phpv' => phpversion(),
|
||||
'mysql_version' => $mysql_version,
|
||||
'web_server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
// api_Service_upgradeLog
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVVwZ3JhZGUmYT11cGdyYWRlTG9nJg==';
|
||||
$url = base64_decode($this->service_ey).base64_decode($tmp_str).http_build_query($vaules);
|
||||
@file_get_contents($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的目录路径
|
||||
* @param string $filename 文件路径+文件名
|
||||
* @return string
|
||||
*/
|
||||
private function GetDirName($filename)
|
||||
{
|
||||
$dirname = preg_replace("#[\\\\\/]{1,}#", '/', $filename);
|
||||
$dirname = preg_replace("#([^\/]*)$#", '', $dirname);
|
||||
return $dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有读写权限
|
||||
* @param string $dirname 文件目录路径
|
||||
* @return array
|
||||
*/
|
||||
private function TestIsFileDir($dirname)
|
||||
{
|
||||
$dirs = array('name'=>'', 'isdir'=>FALSE, 'writeable'=>FALSE);
|
||||
$dirs['name'] = $dirname;
|
||||
tp_mkdir($dirname);
|
||||
if(is_dir($dirname))
|
||||
{
|
||||
$dirs['isdir'] = TRUE;
|
||||
$dirs['writeable'] = $this->TestWriteAble($dirname);
|
||||
}
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试目录路径是否有写入权限
|
||||
* @param string $d 目录路劲
|
||||
* @return boolean
|
||||
*/
|
||||
private function TestWriteAble($d)
|
||||
{
|
||||
$tfile = '_eyout.txt';
|
||||
$fp = @fopen($d.$tfile,'w');
|
||||
if(!$fp) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
fclose($fp);
|
||||
$rs = @unlink($d.$tfile);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
561
src/application/admin/logic/UpgradeLogic.php
Normal file
561
src/application/admin/logic/UpgradeLogic.php
Normal file
@@ -0,0 +1,561 @@
|
||||
<?php
|
||||
/**
|
||||
* eyoucms
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class UpgradeLogic extends Model
|
||||
{
|
||||
public $root_path;
|
||||
public $data_path;
|
||||
public $version_txt_path;
|
||||
public $curent_version;
|
||||
public $service_url;
|
||||
public $upgrade_url;
|
||||
public $service_ey;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->service_ey = config('service_ey');
|
||||
$this->root_path = ROOT_PATH; //
|
||||
$this->data_path = DATA_PATH; //
|
||||
$this->version_txt_path = $this->data_path.'conf'.DS.'version.txt'; // 版本文件路径
|
||||
$this->curent_version = getCmsVersion();
|
||||
// api_Service_checkVersion
|
||||
$upgrade_dev = config('global.upgrade_dev');
|
||||
/*安全补丁*/
|
||||
$security_patch = tpSetting('upgrade.upgrade_security_patch'); // 是否开启
|
||||
$version_security = getVersion('version_security'); // 补丁版本号
|
||||
/* END */
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVNlcnZpY2UmYT1jaGVja1ZlcnNpb24=';
|
||||
$this->service_url = base64_decode($this->service_ey).base64_decode($tmp_str);
|
||||
$this->upgrade_url = $this->service_url . '&domain='.request()->host(true).'&v=' . $this->curent_version . '&dev=' . $upgrade_dev . '&security_patch=' . $security_patch . '&version_security=' . $version_security;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkVersion() {
|
||||
//error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 1, 'msg' => "<font color='red'>请联系空间商(设置 php.ini 中参数 allow_url_fopen = 1)</font>"];
|
||||
}
|
||||
|
||||
$url = $this->upgrade_url;
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 5,'method'=>'GET')));
|
||||
$serviceVersionList = @file_get_contents($url,false,$context);
|
||||
if (false === $serviceVersionList) {
|
||||
$serviceVersionList = httpRequest($url);
|
||||
}
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if(!empty($serviceVersionList))
|
||||
{
|
||||
$upgradeArr = array();
|
||||
$introStr = '';
|
||||
$upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br>'.filter_line_return($val['intro'], '<br>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
$upgradeStr = implode('<br>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
tpCache('system', ['system_upgrade_filelist'=>base64_encode($lastupgrade['upgrade'])]);
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有安全补丁包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkSecurityVersion() {
|
||||
// error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (empty($allow_url_fopen)) {
|
||||
return ['code' => 1, 'msg' => "<font color='red'>请联系空间商(设置 php.ini 中参数 allow_url_fopen = 1)</font>"];
|
||||
}
|
||||
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 5, 'method' => 'GET')));
|
||||
$serviceVersionList = @file_get_contents($this->upgrade_url, false, $context);
|
||||
if (false === $serviceVersionList) {
|
||||
$serviceVersionList = httpRequest($this->upgrade_url);
|
||||
}
|
||||
$serviceVersionList = json_decode($serviceVersionList, true);
|
||||
if(!empty($serviceVersionList)) {
|
||||
/* 插件过期则执行 */
|
||||
if (isset($serviceVersionList['maturity']) && 1 == $serviceVersionList['maturity']) {
|
||||
$WeappUrl = weapp_url('Security/Security/index');
|
||||
$msg = '<a href="'. $WeappUrl .'"> [安全补丁升级] </a>';
|
||||
$remind = str_replace("[安全补丁升级]", $msg, $serviceVersionList['remind']);
|
||||
return ['code' => 0, 'msg' => $remind];
|
||||
}
|
||||
/* END */
|
||||
|
||||
$upgradeArr = array();
|
||||
$introStr = $upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br>' . filter_line_return($val['intro'], '<br>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
$upgradeStr = implode('<br>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
tpCache('system', ['system_upgrade_filelist' => base64_encode($lastupgrade['upgrade'])]);
|
||||
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新补丁版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询安全补丁升级插件订单
|
||||
*/
|
||||
public function checkSecurityOrder() {
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 5, 'method' => 'GET')));
|
||||
$SecurityOrder = @file_get_contents($this->upgrade_url . '&get_order=1', false, $context);
|
||||
if (false === $SecurityOrder) {
|
||||
$SecurityOrder = httpRequest($this->upgrade_url);
|
||||
}
|
||||
$SecurityOrder = json_decode($SecurityOrder, true);
|
||||
if (!empty($SecurityOrder)) return $SecurityOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键更新
|
||||
*/
|
||||
public function OneKeyUpgrade(){
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,设置 php.ini 中参数 allow_url_fopen = 1"];
|
||||
}
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,开启 php.ini 中的php-zip扩展"];
|
||||
}
|
||||
|
||||
$serviceVersionList = @file_get_contents($this->upgrade_url);
|
||||
if (false === $serviceVersionList) {
|
||||
$serviceVersionList = httpRequest($this->upgrade_url);
|
||||
}
|
||||
if (false === $serviceVersionList) {
|
||||
return ['code' => 0, 'msg' => "无法连接远程升级服务器!"];
|
||||
} else {
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if (empty($serviceVersionList)) {
|
||||
return ['code' => 0, 'msg' => "当前没有可升级的版本!"];
|
||||
}
|
||||
}
|
||||
|
||||
clearstatcache(); // 清除文件夹权限缓存
|
||||
/*$quanxuan = substr(base_convert(@fileperms($this->data_path),10,8),-4);
|
||||
if(!in_array($quanxuan,array('0777','0755','0666','0662','0622','0222')))
|
||||
return "网站根目录不可写,无法升级.";*/
|
||||
if (!is_writeable($this->version_txt_path)) {
|
||||
return ['code' => 0, 'msg' => '文件'.$this->version_txt_path.' 不可写,不能升级!!!'];
|
||||
}
|
||||
/*最新更新版本信息*/
|
||||
$lastServiceVersion = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
/*--end*/
|
||||
/*批量下载更新包*/
|
||||
$upgradeArr = array(); // 更新的文件列表
|
||||
$sqlfileArr = array(); // 更新SQL文件列表
|
||||
$folderName = $lastServiceVersion['key_num'];
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
// 下载更新包
|
||||
$result = $this->downloadFile($val['down_url'], $val['file_md5']);
|
||||
if (!isset($result['code']) || $result['code'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*第一个循环执行的业务*/
|
||||
if ($key == 0) {
|
||||
/*解压到最后一个更新包的文件夹*/
|
||||
$lastDownFileName = explode('/', $lastServiceVersion['down_url']);
|
||||
$lastDownFileName = end($lastDownFileName);
|
||||
$folderName = str_replace(".zip", "", $lastDownFileName); // 文件夹
|
||||
/*--end*/
|
||||
|
||||
/*解压之前,删除已重复的文件夹*/
|
||||
delFile($this->data_path.'backup'.DS.$folderName);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$downFileName = explode('/', $val['down_url']);
|
||||
$downFileName = end($downFileName);
|
||||
|
||||
/*解压文件*/
|
||||
$zip = new \ZipArchive();//新建一个ZipArchive的对象
|
||||
if ($zip->open($this->data_path.'backup'.DS.$downFileName) != true) {
|
||||
return ['code' => 0, 'msg' => "升级包读取失败!"];
|
||||
}
|
||||
$zip->extractTo($this->data_path.'backup'.DS.$folderName.DS);//假设解压缩到在当前路径下backup文件夹内
|
||||
$zip->close();//关闭处理的zip文件
|
||||
/*--end*/
|
||||
|
||||
if (!file_exists($this->data_path.'backup'.DS.$folderName.DS.'www'.DS.'data'.DS.'conf'.DS.'version.txt')) {
|
||||
return ['code' => 0, 'msg' => "缺少version.txt文件,请联系客服"];
|
||||
}
|
||||
|
||||
if (file_exists($this->data_path.'backup'.DS.$folderName.DS.'www'.DS.'application'.DS.'database.php')) {
|
||||
return ['code' => 0, 'msg' => "不得修改数据库配置文件,请联系客服"];
|
||||
}
|
||||
|
||||
/*更新的文件列表*/
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
/*--end*/
|
||||
|
||||
/*更新的SQL文件列表*/
|
||||
$sql_file = !empty($val['sql_file']) ? $val['sql_file'] : array();
|
||||
$sqlfileArr = array_merge($sqlfileArr, $val['sql_file']);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*将多个更新包重新组建一个新的完全更新包*/
|
||||
$upgradeArr = array_unique($upgradeArr); // 移除文件列表里重复的文件
|
||||
$sqlfileArr = array_unique($sqlfileArr); // 移除文件列表里重复的文件
|
||||
$serviceVersion = $lastServiceVersion;
|
||||
$serviceVersion['upgrade'] = $upgradeArr;
|
||||
$serviceVersion['sql_file'] = $sqlfileArr;
|
||||
/*--end*/
|
||||
|
||||
/*升级之前,备份涉及的源文件*/
|
||||
$upgrade = $serviceVersion['upgrade'];
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$source_file = $this->root_path.$val;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = $this->data_path.'backup'.DS.$this->curent_version.'_www'.DS.$val;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
$copy_bool = @copy($source_file, $destination_file);
|
||||
if (false == $copy_bool) {
|
||||
return ['code' => 0, 'msg' => "更新前备份文件失败,请检查所有目录是否有读写权限"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*升级的 sql文件*/
|
||||
if(!empty($serviceVersion['sql_file']))
|
||||
{
|
||||
foreach($serviceVersion['sql_file'] as $key => $val)
|
||||
{
|
||||
//读取数据文件
|
||||
$sqlpath = $this->data_path.'backup'.DS.$folderName.DS.'sql'.DS.trim($val);
|
||||
$execute_sql = file_get_contents($sqlpath);
|
||||
$sqlFormat = $this->sql_split($execute_sql, PREFIX);
|
||||
/**
|
||||
* 执行SQL语句
|
||||
*/
|
||||
try {
|
||||
$counts = count($sqlFormat);
|
||||
|
||||
for ($i = 0; $i < $counts; $i++) {
|
||||
$sql = trim($sqlFormat[$i]);
|
||||
|
||||
if (stristr($sql, 'CREATE TABLE')) {
|
||||
Db::execute($sql);
|
||||
} else {
|
||||
if(trim($sql) == '')
|
||||
continue;
|
||||
Db::execute($sql);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ['code' => -2, 'msg' => "数据库执行中途失败,请查看官方解决教程,否则将影响后续的版本升级!"];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 递归复制文件夹
|
||||
$copy_data = $this->recurse_copy($this->data_path.'backup'.DS.$folderName.DS.'www', rtrim($this->root_path, DS), $folderName);
|
||||
|
||||
/*覆盖自定义后台入口文件*/
|
||||
$login_php = 'login.php';
|
||||
$rootLoginFile = $this->data_path.'backup'.DS.$folderName.DS.'www'.DS.$login_php;
|
||||
if (file_exists($rootLoginFile)) {
|
||||
$adminbasefile = preg_replace('/^(.*)\/([^\/]+)$/i', '$2', request()->baseFile());
|
||||
if ($login_php != $adminbasefile && is_writable($this->root_path.$adminbasefile)) {
|
||||
if (!@copy($rootLoginFile, $this->root_path.$adminbasefile)) {
|
||||
return ['code' => 0, 'msg' => "更新入口文件失败,请第一时间请求技术支持,否则将影响部分功能的使用!"];
|
||||
}
|
||||
@unlink($this->root_path.$login_php);
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('system',['system_version'=>$serviceVersion['key_num']], $val['mark']); // 记录版本号
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('system',['system_version'=>$serviceVersion['key_num']]); // 记录版本号
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 清空缓存
|
||||
delFile(rtrim(RUNTIME_PATH, '/'));
|
||||
tpCache('global');
|
||||
|
||||
// 清空检测标记
|
||||
$s_key = 'aXNzZXRfYXV0aG9y';
|
||||
$s_key = base64_decode($s_key);
|
||||
session($s_key, null);
|
||||
|
||||
/*删除下载的升级包*/
|
||||
$ziplist = glob($this->data_path.'backup'.DS.'*.zip');
|
||||
@array_map('unlink', $ziplist);
|
||||
/*--end*/
|
||||
|
||||
// 推送回服务器 记录升级成功
|
||||
$this->UpgradeLog($serviceVersion['key_num']);
|
||||
|
||||
return ['code' => $copy_data['code'], 'msg' => "升级成功{$copy_data['msg']}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @param string $folderName 存放升级包目录名称
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst, $folderName)
|
||||
{
|
||||
static $badcp = 0; // 累计覆盖失败的文件总数
|
||||
static $n = 0; // 累计执行覆盖的文件总数
|
||||
static $total = 0; // 累计更新的文件总数
|
||||
$dir = opendir($src);
|
||||
tp_mkdir($dst);
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$this->recurse_copy($src . '/' . $file, $dst . '/' . $file, $folderName);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
$n++;
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
} else {
|
||||
$n++;
|
||||
$badcp++;
|
||||
}
|
||||
} else {
|
||||
$n++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
$code = 1;
|
||||
$msg = '!';
|
||||
if($badcp > 0)
|
||||
{
|
||||
$code = 2;
|
||||
$msg = ",其中失败 <font color='red'>{$badcp}</font> 个文件,<br />请从升级包目录[<font color='red'>data/backup/{$folderName}/www</font>]中的取出全部文件覆盖到根目录,完成手工升级。";
|
||||
}
|
||||
|
||||
$this->copy_speed($n, $total);
|
||||
|
||||
return ['code'=>$code, 'msg'=>$msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文件进度
|
||||
*/
|
||||
private function copy_speed($n, $total)
|
||||
{
|
||||
$data = false;
|
||||
|
||||
if ($n < $total) {
|
||||
$this->copy_speed($n, $total);
|
||||
} else {
|
||||
$data = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function sql_split($sql, $tablepre) {
|
||||
|
||||
if ($tablepre != "ey_")
|
||||
$sql = str_replace("`ey_", '`'.$tablepre, $sql);
|
||||
|
||||
$sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
|
||||
|
||||
$sql = str_replace("\r", "\n", $sql);
|
||||
$ret = array();
|
||||
$num = 0;
|
||||
$queriesarray = explode(";\n", trim($sql));
|
||||
unset($sql);
|
||||
foreach ($queriesarray as $query) {
|
||||
$ret[$num] = '';
|
||||
$queries = explode("\n", trim($query));
|
||||
$queries = array_filter($queries);
|
||||
foreach ($queries as $query) {
|
||||
$str1 = substr($query, 0, 1);
|
||||
if ($str1 != '#' && $str1 != '-')
|
||||
$ret[$num] .= $query;
|
||||
}
|
||||
$num++;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type $fileUrl 下载文件地址
|
||||
* @param type $md5File 文件MD5 加密值 用于对比下载是否完整
|
||||
* @return string 错误或成功提示
|
||||
*/
|
||||
private function downloadFile($fileUrl,$md5File)
|
||||
{
|
||||
$downFileName = explode('/', $fileUrl);
|
||||
$downFileName = end($downFileName);
|
||||
$saveDir = $this->data_path.'backup'.DS.$downFileName; // 保存目录
|
||||
tp_mkdir(dirname($saveDir));
|
||||
$content = @file_get_contents($fileUrl, 0, null, 0, 1);
|
||||
if (false === $content) {
|
||||
$fileUrl = str_replace('http://service', 'https://service', $fileUrl);
|
||||
$content = @file_get_contents($fileUrl, 0, null, 0, 1);
|
||||
if (false === $content) {
|
||||
$content = httpRequest($fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$content){
|
||||
return ['code' => 0, 'msg' => '官方升级包不存在']; // 文件存在直接退出
|
||||
}
|
||||
|
||||
if (!stristr($fileUrl, 'https://service')) {
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
$file = curl_exec ($ch);
|
||||
} else {
|
||||
$file = httpRequest($fileUrl);
|
||||
}
|
||||
|
||||
if (preg_match('#__HALT_COMPILER()#i', $file)) {
|
||||
return ['code' => 0, 'msg' => '下载包损坏,请联系官方客服!'];
|
||||
}
|
||||
|
||||
curl_close ($ch);
|
||||
$fp = fopen($saveDir,'w');
|
||||
fwrite($fp, $file);
|
||||
fclose($fp);
|
||||
if(!eyPreventShell($saveDir) || !file_exists($saveDir) || $md5File != md5_file($saveDir))
|
||||
{
|
||||
return ['code' => 0, 'msg' => '下载保存升级包失败,请检查所有目录的权限以及用户组不能为root'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '下载成功'];
|
||||
}
|
||||
|
||||
// 升级记录 log 日志
|
||||
private function UpgradeLog($to_key_num){
|
||||
$serial_number = DEFAULT_SERIALNUMBER;
|
||||
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
|
||||
}
|
||||
$mysqlinfo = \think\Db::query("SELECT VERSION() as version");
|
||||
$mysql_version = $mysqlinfo[0]['version'];
|
||||
$vaules = array(
|
||||
'domain'=>$_SERVER['HTTP_HOST'], //用户域名
|
||||
'key_num'=>$this->curent_version, // 用户版本号
|
||||
'to_key_num'=>$to_key_num, // 用户要升级的版本号
|
||||
'add_time'=>time(), // 升级时间
|
||||
'serial_number'=>$serial_number,
|
||||
'ip' => GetHostByName($_SERVER['SERVER_NAME']),
|
||||
'phpv' => phpversion(),
|
||||
'mysql_version' => $mysql_version,
|
||||
'web_server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
// api_Service_upgradeLog
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVNlcnZpY2UmYT11cGdyYWRlTG9nJg==';
|
||||
$url = base64_decode($this->service_ey).base64_decode($tmp_str).http_build_query($vaules);
|
||||
httpRequest($url);
|
||||
}
|
||||
}
|
||||
?>
|
||||
568
src/application/admin/logic/WeappLogic.php
Normal file
568
src/application/admin/logic/WeappLogic.php
Normal file
@@ -0,0 +1,568 @@
|
||||
<?php
|
||||
/**
|
||||
* eyoucms
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class WeappLogic extends Model
|
||||
{
|
||||
public $root_path;
|
||||
public $weapp_path;
|
||||
public $data_path;
|
||||
// public $config_path;
|
||||
// public $curent_version;
|
||||
public $service_url;
|
||||
// public $upgrade_url;
|
||||
public $service_ey;
|
||||
// public $code;
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct() {
|
||||
// $this->code = input('param.code/s', '');
|
||||
// $this->curent_version = getWeappVersion($this->code);
|
||||
$this->service_ey = config('service_ey');
|
||||
$this->root_path = ROOT_PATH; //
|
||||
$this->weapp_path = WEAPP_DIR_NAME.DS; //
|
||||
$this->data_path = DATA_PATH; //
|
||||
// $this->config_path = $this->weapp_path.$this->code.DS.'config.php'; // 版本配置文件路径
|
||||
// api_Weapp_checkVersion
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVdlYXBwJmE9Y2hlY2tWZXJzaW9u';
|
||||
$this->service_url = base64_decode($this->service_ey).base64_decode($tmp_str).'&domain='.request()->host(true);
|
||||
// $this->upgrade_url = $this->service_url.'&code='.$this->code.'&v='.$this->curent_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新插件到数据库
|
||||
* @param $weapp_list array 本地插件数组
|
||||
*/
|
||||
public function insertWeapp()
|
||||
{
|
||||
$row = M('weapp')->field('id,code,config,is_buy')->getAllWithIndex('code'); // 数据库
|
||||
$new_arr = array(); // 本地
|
||||
$addData = array(); // 数据存储变量
|
||||
$updateData = array(); // 数据存储变量
|
||||
$weapp_list = $this->scanWeapp();
|
||||
// 本地对比数据库
|
||||
foreach($weapp_list as $k=>$v){
|
||||
$code = isset($v['code']) ? $v['code'] : 'error_'.date('Ymd');
|
||||
/*初步过滤不规范插件*/
|
||||
if ($k != $code) {
|
||||
continue;
|
||||
}
|
||||
/*--end*/
|
||||
$new_arr[] = $code;
|
||||
// 对比数据库 本地有 数据库没有
|
||||
$data = array(
|
||||
'code' => $code,
|
||||
'name' => isset($v['name']) ? $v['name'] : '配置信息不完善',
|
||||
'config' => empty($v) ? '' : json_encode($v),
|
||||
'position' => isset($v['position']) ? $v['position'] : 'default',
|
||||
'sort_order' => 100,
|
||||
);
|
||||
if(empty($row[$code])){ // 新增插件
|
||||
$data['add_time'] = getTime();
|
||||
$addData[] = $data;
|
||||
} else { // 更新插件
|
||||
if ($row[$code]['config'] != json_encode($v)) {
|
||||
$data['id'] = $row[$code]['id'];
|
||||
$data['update_time'] = getTime();
|
||||
$updateData[] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($addData)) {
|
||||
model('weapp')->saveAll($addData);
|
||||
}
|
||||
if (!empty($updateData)) {
|
||||
model('weapp')->saveAll($updateData);
|
||||
}
|
||||
//数据库有 本地没有
|
||||
foreach($row as $k => $v){
|
||||
if (!in_array($v['code'], $new_arr) && $v['is_buy'] < 1) {//is_buy 0->本地安装,1-线上购买
|
||||
M('weapp')->where($v)->cache(true, null, 'weapp')->delete();
|
||||
}
|
||||
}
|
||||
|
||||
\think\Cache::clear('weapp');
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件目录扫描
|
||||
* @return array 返回目录数组
|
||||
*/
|
||||
private function scanWeapp(){
|
||||
$dir = WEAPP_DIR_NAME;
|
||||
$weapp_list = $this->dirscan($dir);
|
||||
foreach($weapp_list as $k=>$v){
|
||||
if (!is_dir(WEAPP_DIR_NAME.DS.$v) || !file_exists(WEAPP_DIR_NAME.DS.$v.'/config.php')) {
|
||||
unset($weapp_list[$k]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$weapp_list[$v] = include(WEAPP_DIR_NAME.DS.$v.'/config.php');
|
||||
unset($weapp_list[$k]);
|
||||
}
|
||||
}
|
||||
return $weapp_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件目录列表
|
||||
* @param $dir
|
||||
* @return array
|
||||
*/
|
||||
private function dirscan($dir){
|
||||
$dirArray = array();
|
||||
if (false != ($handle = opendir($dir))) {
|
||||
$i = 0;
|
||||
while ( false !== ($file = readdir ($handle)) ) {
|
||||
//去掉"“.”、“..”以及带“.xxx”后缀的文件
|
||||
if ($file != "." && $file != ".." && !strpos($file,".")) {
|
||||
$dirArray[$i] = $file;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
//关闭句柄
|
||||
closedir($handle);
|
||||
}
|
||||
return $dirArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件基类构造方法
|
||||
* sm:module 插件模块
|
||||
* sc:controller 插件控制器
|
||||
* sa:action 插件操作
|
||||
*/
|
||||
public function checkInstall()
|
||||
{
|
||||
$msg = true;
|
||||
if(!array_key_exists("sm", request()->param())){
|
||||
$msg = '无效插件URL!';
|
||||
} else {
|
||||
$module = request()->param('sm');
|
||||
$module = $module ?: request()->param('sc');
|
||||
$row = M('Weapp')->field('code, name, status')
|
||||
->where(array('code'=>$module))
|
||||
->find();
|
||||
if (empty($row)) {
|
||||
$msg = "插件【{$row['name']}】不存在";
|
||||
} else {
|
||||
if ($row['status'] == -1) {
|
||||
$msg = "请先启用插件【{$row['name']}】";
|
||||
} else if (intval($row['status']) == 0) {
|
||||
$msg = "请先安装插件【{$row['name']}】";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkVersion($code, $serviceVersionList = false) {
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
$lastupgrade = array();
|
||||
if (false === $serviceVersionList) {
|
||||
$curent_version = getWeappVersion($code);
|
||||
$url = $this->service_url.'&code='.$code.'&v='.$curent_version;
|
||||
$context = stream_context_set_default(array('http' => array('timeout' => 3,'method'=>'GET')));
|
||||
$serviceVersionList = @file_get_contents($url,false,$context);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
}
|
||||
if(!empty($serviceVersionList))
|
||||
{
|
||||
$upgradeArr = array();
|
||||
$introStr = '';
|
||||
$upgradeStr = '';
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
$introStr .= '<br/>'.filter_line_return($val['intro'], '<br/>');
|
||||
}
|
||||
$upgradeArr = array_unique($upgradeArr);
|
||||
$upgradeStr = implode('<br/>', $upgradeArr); // 升级提示需要覆盖哪些文件
|
||||
|
||||
$introArr = explode('<br/>', $introStr);
|
||||
$introStr = '更新日志:';
|
||||
foreach ($introArr as $key => $val) {
|
||||
if (empty($val)) {
|
||||
continue;
|
||||
}
|
||||
$introStr .= "<br/>{$key}、".$val;
|
||||
}
|
||||
|
||||
$lastupgrade = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
if (!empty($lastupgrade['upgrade_title'])) {
|
||||
$introStr .= '<br/>'.$lastupgrade['upgrade_title'];
|
||||
}
|
||||
$lastupgrade['intro'] = htmlspecialchars_decode($introStr);
|
||||
$lastupgrade['upgrade'] = htmlspecialchars_decode($upgradeStr); // 升级提示需要覆盖哪些文件
|
||||
/*升级公告*/
|
||||
if (!empty($lastupgrade['notice'])) {
|
||||
$lastupgrade['notice'] = htmlspecialchars_decode($lastupgrade['notice']) . '<br>';
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return ['code' => 2, 'msg' => $lastupgrade];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '已是最新版'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量检查是否有更新包
|
||||
* @return type 提示语
|
||||
*/
|
||||
public function checkBatchVersion($upgradeArr)
|
||||
{
|
||||
$result = array();
|
||||
if (is_array($upgradeArr) && !empty($upgradeArr)) {
|
||||
foreach ($upgradeArr as $key => $upgrade) {
|
||||
if ($key == 'Sample') {
|
||||
tpCache('system', ['system_usecodelist'=>$upgradeArr['Sample']]);
|
||||
} else {
|
||||
$result[$key] = $this->checkVersion($key, $upgrade);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键更新
|
||||
*/
|
||||
public function OneKeyUpgrade($code){
|
||||
error_reporting(0);//关闭所有错误报告
|
||||
if (empty($code)) {
|
||||
return ['code' => 0, 'msg' => "URL传参错误,缺少插件标识参数值!"];
|
||||
}
|
||||
|
||||
$allow_url_fopen = ini_get('allow_url_fopen');
|
||||
if (!$allow_url_fopen) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,设置 php.ini 中参数 allow_url_fopen = 1"];
|
||||
}
|
||||
|
||||
if (!extension_loaded('zip')) {
|
||||
return ['code' => 0, 'msg' => "请联系空间商,开启 php.ini 中的php-zip扩展"];
|
||||
}
|
||||
|
||||
$curent_version = getWeappVersion($code);
|
||||
$upgrade_dev = config('global.upgrade_dev');
|
||||
$upgrade_url = $this->service_url.'&code='.$code.'&dev='.$upgrade_dev.'&v='.$curent_version;
|
||||
$serviceVersionList = file_get_contents($upgrade_url);
|
||||
$serviceVersionList = json_decode($serviceVersionList,true);
|
||||
if (empty($serviceVersionList)) {
|
||||
return ['code' => 0, 'msg' => "没找到升级包"];
|
||||
}
|
||||
|
||||
clearstatcache(); // 清除文件夹权限缓存
|
||||
$config_path = $this->weapp_path.$code.DS.'config.php'; // 版本配置文件路径
|
||||
if(!is_writeable($config_path)) {
|
||||
return ['code' => 0, 'msg' => '文件'.$config_path.' 不可写,不能升级!!!'];
|
||||
}
|
||||
/*最新更新版本信息*/
|
||||
$lastServiceVersion = $serviceVersionList[count($serviceVersionList) - 1];
|
||||
/*--end*/
|
||||
/*批量下载更新包*/
|
||||
$upgradeArr = array(); // 更新的文件列表
|
||||
$sqlfileArr = array(); // 更新SQL文件列表
|
||||
$folderName = $code.'-'.$lastServiceVersion['key_num'];
|
||||
foreach ($serviceVersionList as $key => $val) {
|
||||
// 下载更新包
|
||||
$result = $this->downloadFile($val['down_url'], $val['file_md5']);
|
||||
if (!isset($result['code']) || $result['code'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*第一个循环执行的业务*/
|
||||
if ($key == 0) {
|
||||
/*解压到最后一个更新包的文件夹*/
|
||||
$lastDownFileName = explode('/', $lastServiceVersion['down_url']);
|
||||
$lastDownFileName = end($lastDownFileName);
|
||||
$folderName = $code.'-'.str_replace(".zip", "", $lastDownFileName); // 文件夹
|
||||
/*--end*/
|
||||
|
||||
/*解压之前,删除已重复的文件夹*/
|
||||
delFile($this->data_path.'backup'.DS.$folderName);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$downFileName = explode('/', $val['down_url']);
|
||||
$downFileName = end($downFileName);
|
||||
|
||||
/*解压文件*/
|
||||
$zip = new \ZipArchive();//新建一个ZipArchive的对象
|
||||
if($zip->open($this->data_path.'backup'.DS.$downFileName) != true) {
|
||||
return ['code' => 0, 'msg' => "升级包读取失败!"];
|
||||
}
|
||||
$zip->extractTo($this->data_path.'backup'.DS.$folderName.DS);//假设解压缩到在当前路径下backup文件夹内
|
||||
$zip->close();//关闭处理的zip文件
|
||||
/*--end*/
|
||||
|
||||
if(!file_exists($this->data_path.'backup'.DS.$folderName.DS.'www'.DS.'weapp'.DS.$code.DS.'config.php')) {
|
||||
return ['code' => 0, 'msg' => $code."插件目录缺少config.php文件,请联系客服"];
|
||||
}
|
||||
|
||||
/*更新的文件列表*/
|
||||
$upgrade = !empty($val['upgrade']) ? $val['upgrade'] : array();
|
||||
$upgradeArr = array_merge($upgradeArr, $upgrade);
|
||||
/*--end*/
|
||||
|
||||
/*更新的SQL文件列表*/
|
||||
$sql_file = !empty($val['sql_file']) ? $val['sql_file'] : array();
|
||||
$sqlfileArr = array_merge($sqlfileArr, $val['sql_file']);
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*将多个更新包重新组建一个新的完全更新包*/
|
||||
$upgradeArr = array_unique($upgradeArr); // 移除文件列表里重复的文件
|
||||
$sqlfileArr = array_unique($sqlfileArr); // 移除文件列表里重复的文件
|
||||
$serviceVersion = $lastServiceVersion;
|
||||
$serviceVersion['upgrade'] = $upgradeArr;
|
||||
$serviceVersion['sql_file'] = $sqlfileArr;
|
||||
/*--end*/
|
||||
|
||||
/*升级之前,备份涉及的源文件*/
|
||||
$upgrade = $serviceVersion['upgrade'];
|
||||
if (!empty($upgrade) && is_array($upgrade)) {
|
||||
foreach ($upgrade as $key => $val) {
|
||||
$source_file = $this->root_path.$val;
|
||||
if (file_exists($source_file)) {
|
||||
$destination_file = $this->data_path.'backup'.DS.$code.'-'.$curent_version.'_www'.DS.$val;
|
||||
tp_mkdir(dirname($destination_file));
|
||||
$copy_bool = @copy($source_file, $destination_file);
|
||||
if (false == $copy_bool) {
|
||||
return ['code' => 0, 'msg' => "更新前备份文件失败,请检查所有目录是否有读写权限"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*升级的 sql文件*/
|
||||
if(!empty($serviceVersion['sql_file']))
|
||||
{
|
||||
foreach($serviceVersion['sql_file'] as $key => $val)
|
||||
{
|
||||
//读取数据文件
|
||||
$sqlpath = $this->data_path.'backup'.DS.$folderName.DS.'sql'.DS.trim($val);
|
||||
$execute_sql = file_get_contents($sqlpath);
|
||||
$sqlFormat = $this->sql_split($execute_sql, PREFIX);
|
||||
/**
|
||||
* 执行SQL语句
|
||||
*/
|
||||
try {
|
||||
$counts = count($sqlFormat);
|
||||
|
||||
for ($i = 0; $i < $counts; $i++) {
|
||||
$sql = trim($sqlFormat[$i]);
|
||||
|
||||
if (stristr($sql, 'CREATE TABLE')) {
|
||||
Db::execute($sql);
|
||||
} else {
|
||||
if(trim($sql) == '')
|
||||
continue;
|
||||
Db::execute($sql);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ['code' => 0, 'msg' => "数据库执行中途失败,请第一时间请求技术支持,否则将影响该插件后续的版本升级!"];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 递归复制文件夹
|
||||
$copy_data = $this->recurse_copy($this->data_path.'backup'.DS.$folderName.DS.'www', rtrim($this->root_path, DS), $folderName);
|
||||
|
||||
// 清空缓存
|
||||
delFile(RUNTIME_PATH.'cache');
|
||||
delFile(RUNTIME_PATH.'temp');
|
||||
tpCache('global');
|
||||
|
||||
/*删除下载的升级包*/
|
||||
$ziplist = glob($this->data_path.'backup'.DS.'*.zip');
|
||||
@array_map('unlink', $ziplist);
|
||||
/*--end*/
|
||||
|
||||
// 推送回服务器 记录升级成功
|
||||
$this->UpgradeLog($code, $serviceVersion['key_num']);
|
||||
|
||||
return ['code' => $copy_data['code'], 'msg' => "升级成功{$copy_data['msg']}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义函数递归的复制带有多级子目录的目录
|
||||
* 递归复制文件夹
|
||||
*
|
||||
* @param string $src 原目录
|
||||
* @param string $dst 复制到的目录
|
||||
* @param string $folderName 存放升级包目录名称
|
||||
* @return string
|
||||
*/
|
||||
//参数说明:
|
||||
//自定义函数递归的复制带有多级子目录的目录
|
||||
private function recurse_copy($src, $dst, $folderName)
|
||||
{
|
||||
static $badcp = 0; // 累计覆盖失败的文件总数
|
||||
static $n = 0; // 累计执行覆盖的文件总数
|
||||
static $total = 0; // 累计更新的文件总数
|
||||
$dir = opendir($src);
|
||||
tp_mkdir($dst);
|
||||
while (false !== $file = readdir($dir)) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($src . '/' . $file)) {
|
||||
$this->recurse_copy($src . '/' . $file, $dst . '/' . $file, $folderName);
|
||||
}
|
||||
else {
|
||||
if (file_exists($src . DIRECTORY_SEPARATOR . $file)) {
|
||||
$rs = @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file);
|
||||
if($rs) {
|
||||
$n++;
|
||||
@unlink($src . DIRECTORY_SEPARATOR . $file);
|
||||
} else {
|
||||
$n++;
|
||||
$badcp++;
|
||||
}
|
||||
} else {
|
||||
$n++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
$code = 1;
|
||||
$msg = '!';
|
||||
if($badcp > 0)
|
||||
{
|
||||
$code = 2;
|
||||
$msg = ",其中失败 <font color='red'>{$badcp}</font> 个文件,<br />请从升级包目录[<font color='red'>data/backup/{$folderName}/www</font>]中的取出全部文件覆盖到根目录,完成手工升级。";
|
||||
}
|
||||
|
||||
$this->copy_speed($n, $total);
|
||||
|
||||
return ['code'=>$code, 'msg'=>$msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制文件进度
|
||||
*/
|
||||
private function copy_speed($n, $total)
|
||||
{
|
||||
$data = false;
|
||||
|
||||
if ($n < $total) {
|
||||
$this->copy_speed($n, $total);
|
||||
} else {
|
||||
$data = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function sql_split($sql, $tablepre) {
|
||||
|
||||
$sql = str_replace("`#@__", '`'.$tablepre, $sql);
|
||||
|
||||
$sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
|
||||
|
||||
$sql = str_replace("\r", "\n", $sql);
|
||||
$ret = array();
|
||||
$num = 0;
|
||||
$queriesarray = explode(";\n", trim($sql));
|
||||
unset($sql);
|
||||
foreach ($queriesarray as $query) {
|
||||
$ret[$num] = '';
|
||||
$queries = explode("\n", trim($query));
|
||||
$queries = array_filter($queries);
|
||||
foreach ($queries as $query) {
|
||||
$str1 = substr($query, 0, 1);
|
||||
if ($str1 != '#' && $str1 != '-')
|
||||
$ret[$num] .= $query;
|
||||
}
|
||||
$num++;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type $fileUrl 下载文件地址
|
||||
* @param type $md5File 文件MD5 加密值 用于对比下载是否完整
|
||||
* @return string 错误或成功提示
|
||||
*/
|
||||
private function downloadFile($fileUrl,$md5File)
|
||||
{
|
||||
$downFileName = explode('/', $fileUrl);
|
||||
$downFileName = end($downFileName);
|
||||
$saveDir = $this->data_path.'backup'.DS.$downFileName; // 保存目录
|
||||
tp_mkdir(dirname($saveDir));
|
||||
if(!file_get_contents($fileUrl, 0, null, 0, 1)){
|
||||
return ['code' => 0, 'msg' => '官方插件升级包不存在']; // 文件存在直接退出
|
||||
}
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
$file = curl_exec ($ch);
|
||||
curl_close ($ch);
|
||||
$fp = fopen($saveDir,'w');
|
||||
fwrite($fp, $file);
|
||||
fclose($fp);
|
||||
if(!eyPreventShell($saveDir) || !file_exists($saveDir) || $md5File != md5_file($saveDir))
|
||||
{
|
||||
// 下载保存升级包失败,请检查所有目录的权限以及用户组不能为root
|
||||
return ['code' => 0, 'msg' => 'data目录不可写入,无法执行更新,请检查该目录权限以及用户组再重试'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '下载成功'];
|
||||
}
|
||||
|
||||
// 升级记录 log 日志
|
||||
private function UpgradeLog($code, $to_key_num){
|
||||
$serial_number = DEFAULT_SERIALNUMBER;
|
||||
|
||||
$constsant_path = APP_PATH.MODULE_NAME.'/conf/constant.php';
|
||||
if (file_exists($constsant_path)) {
|
||||
require_once($constsant_path);
|
||||
defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
|
||||
}
|
||||
$mysqlinfo = \think\Db::query("SELECT VERSION() as version");
|
||||
$mysql_version = $mysqlinfo[0]['version'];
|
||||
$vaules = array(
|
||||
'domain'=>$_SERVER['HTTP_HOST'], //用户域名
|
||||
'code' => $code, // 插件标识
|
||||
'key_num'=>getWeappVersion($code), // 用户版本号
|
||||
'to_key_num'=>$to_key_num, // 用户要升级的版本号
|
||||
'add_time'=>time(), // 升级时间
|
||||
'serial_number'=>$serial_number,
|
||||
'ip' => GetHostByName($_SERVER['SERVER_NAME']),
|
||||
'phpv' => phpversion(),
|
||||
'mysql_version' => $mysql_version,
|
||||
'web_server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
);
|
||||
// api_Weapp_upgradeLog
|
||||
$tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVdlYXBwJmE9dXBncmFkZUxvZyY=';
|
||||
$url = base64_decode($this->service_ey).base64_decode($tmp_str).http_build_query($vaules);
|
||||
file_get_contents($url);
|
||||
}
|
||||
}
|
||||
?>
|
||||
30
src/application/admin/model/Ad.php
Normal file
30
src/application/admin/model/Ad.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 广告表
|
||||
*/
|
||||
class Ad extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
}
|
||||
75
src/application/admin/model/AdPosition.php
Normal file
75
src/application/admin/model/AdPosition.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 广告分类
|
||||
*/
|
||||
class AdPosition extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($id, $field = '*')
|
||||
{
|
||||
$result = Db::name('AdPosition')->field($field)->find($id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByIds($ids, $field = '*')
|
||||
{
|
||||
$map = array(
|
||||
'id' => array('IN', $ids),
|
||||
'lang' => get_admin_lang(),
|
||||
);
|
||||
$result = Db::name('AdPosition')->field($field)
|
||||
->where($map)
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认获取广告分类,包括有效、无效等分类
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getAll($field = '*', $index_key = '')
|
||||
{
|
||||
$result = Db::name('AdPosition')->field($field)
|
||||
->where([
|
||||
'lang' => get_admin_lang(),
|
||||
])->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
201
src/application/admin/model/Archives.php
Normal file
201
src/application/admin/model/Archives.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 文档主表
|
||||
*/
|
||||
class Archives extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计每个栏目文档数
|
||||
* @param int $aid 产品id
|
||||
*/
|
||||
public function afterSave($aid, $post)
|
||||
{
|
||||
if (isset($post['aid']) && intval($post['aid']) > 0) {
|
||||
$opt = 'edit';
|
||||
M('article_content')->where('aid', $aid)->update($post);
|
||||
} else {
|
||||
$opt = 'add';
|
||||
$post['aid'] = $aid;
|
||||
M('article_content')->insert($post);
|
||||
}
|
||||
|
||||
// --处理TAG标签
|
||||
model('Taglist')->savetags($aid, $post['typeid'], $post['tags'],$post['arcrank']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($aid, $field = '', $isshowbody = true)
|
||||
{
|
||||
$result = array();
|
||||
if ($isshowbody) {
|
||||
$field = !empty($field) ? $field : 'b.*, a.*, a.aid as aid';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->alias('a')
|
||||
->join('__ARTICLE_CONTENT__ b', 'b.aid = a.aid', 'LEFT')
|
||||
->find($aid);
|
||||
} else {
|
||||
$field = !empty($field) ? $field : 'a.*';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->alias('a')
|
||||
->find($aid);
|
||||
}
|
||||
|
||||
// 文章TAG标签
|
||||
if (!empty($result)) {
|
||||
$typeid = isset($result['typeid']) ? $result['typeid'] : 0;
|
||||
$tags = model('Taglist')->getListByAid($aid, $typeid);
|
||||
$result['tags'] = $tags['tag_arr'];
|
||||
$result['tag_id'] = $tags['tid_arr'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 伪删除栏目下所有文档
|
||||
*/
|
||||
public function pseudo_del($typeidArr)
|
||||
{
|
||||
// 伪删除文档
|
||||
M('archives')->where([
|
||||
'typeid' => ['IN', $typeidArr],
|
||||
'is_del' => 0,
|
||||
])
|
||||
->update([
|
||||
'is_del' => 1,
|
||||
'del_method' => 2,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除栏目下所有文档
|
||||
*/
|
||||
public function del($typeidArr)
|
||||
{
|
||||
/*获取栏目下所有文档,并取得每个模型下含有的文档ID集合*/
|
||||
$channelAidList = array(); // 模型下的文档ID列表
|
||||
$arcrow = M('archives')->where(array('typeid'=>array('IN', $typeidArr)))
|
||||
->order('channel asc')
|
||||
->select();
|
||||
foreach ($arcrow as $key => $val) {
|
||||
if (!isset($channelAidList[$val['channel']])) {
|
||||
$channelAidList[$val['channel']] = array();
|
||||
}
|
||||
array_push($channelAidList[$val['channel']], $val['aid']);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*在相关模型下删除文档残余的关联记录*/
|
||||
$sta = M('archives')->where(array('typeid'=>array('IN', $typeidArr)))->delete(); // 删除文档
|
||||
if ($sta) {
|
||||
foreach ($channelAidList as $key => $val) {
|
||||
$aidArr = $val;
|
||||
/*删除其余相关联的表记录*/
|
||||
switch ($key) {
|
||||
case '1': // 文章模型
|
||||
model('Article')->afterDel($aidArr);
|
||||
break;
|
||||
|
||||
case '2': // 产品模型
|
||||
model('Product')->afterDel($aidArr);
|
||||
M('product_attribute')->where(array('typeid'=>array('IN', $typeidArr)))->delete();
|
||||
break;
|
||||
|
||||
case '3': // 图集模型
|
||||
model('Images')->afterDel($aidArr);
|
||||
break;
|
||||
|
||||
case '4': // 下载模型
|
||||
model('Download')->afterDel($aidArr);
|
||||
break;
|
||||
|
||||
case '6': // 单页模型
|
||||
model('Single')->afterDel($typeidArr);
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*删除留言模型下的关联内容*/
|
||||
$guestbookList = M('guestbook')->where(array('typeid'=>array('IN', $typeidArr)))->select();
|
||||
if (!empty($guestbookList)) {
|
||||
$aidArr = get_arr_column($guestbookList, 'aid');
|
||||
$typeidArr = get_arr_column($guestbookList, 'typeid');
|
||||
if ($aidArr && $typeidArr) {
|
||||
$sta = M('guestbook')->where(array('typeid'=>array('IN', $typeidArr)))->delete();
|
||||
if ($sta) {
|
||||
M('guestbook_attribute')->where(array('typeid'=>array('IN', $typeidArr)))->delete();
|
||||
model('Guestbook')->afterDel($aidArr);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author 陈风任 by 2020-06-08
|
||||
*/
|
||||
public function UnifiedGetInfo($aid, $field = '', $isshowbody = true)
|
||||
{
|
||||
$result = array();
|
||||
$field = !empty($field) ? $field : '*';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->where([
|
||||
'aid' => $aid,
|
||||
'lang' => get_admin_lang(),
|
||||
])
|
||||
->find();
|
||||
if ($isshowbody) {
|
||||
$tableName = M('channeltype')->where('id','eq',$result['channel'])->getField('table');
|
||||
$result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
|
||||
}
|
||||
|
||||
// 产品TAG标签
|
||||
if (!empty($result)) {
|
||||
$typeid = isset($result['typeid']) ? $result['typeid'] : 0;
|
||||
$tags = model('Taglist')->getListByAid($aid, $typeid);
|
||||
$result['tags'] = $tags;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
47
src/application/admin/model/ArchivesFlag.php
Normal file
47
src/application/admin/model/ArchivesFlag.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 文档属性
|
||||
*/
|
||||
class ArchivesFlag extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用的文档属性列表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getList($where = [])
|
||||
{
|
||||
if (empty($where)) {
|
||||
$where['status'] = ['gt', 0];
|
||||
}
|
||||
$result = Db::name('archives_flag')->where($where)
|
||||
->order("sort_order asc, id asc")
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'archives_flag')
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
93
src/application/admin/model/Article.php
Normal file
93
src/application/admin/model/Article.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
*/
|
||||
class Article extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置操作方法
|
||||
* 自定义的一个函数 用于数据保存后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid 产品id
|
||||
* @param array $post post数据
|
||||
* @param string $opt 操作
|
||||
*/
|
||||
public function afterSave($aid, $post, $opt)
|
||||
{
|
||||
$post['aid'] = $aid;
|
||||
$addonFieldExt = !empty($post['addonFieldExt']) ? $post['addonFieldExt'] : array();
|
||||
model('Field')->dealChannelPostData($post['channel'], $post, $addonFieldExt);
|
||||
|
||||
// --处理TAG标签
|
||||
model('Taglist')->savetags($aid, $post['typeid'], $post['tags'], $post['arcrank'], $opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($aid, $field = null, $isshowbody = true)
|
||||
{
|
||||
$result = array();
|
||||
$field = !empty($field) ? $field : '*';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->where([
|
||||
'aid' => $aid,
|
||||
'lang' => get_admin_lang(),
|
||||
])
|
||||
->find();
|
||||
if ($isshowbody) {
|
||||
$tableName = M('channeltype')->where('id','eq',$result['channel'])->getField('table');
|
||||
$result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
|
||||
}
|
||||
|
||||
// 文章TAG标签
|
||||
if (!empty($result)) {
|
||||
$typeid = isset($result['typeid']) ? $result['typeid'] : 0;
|
||||
$tags = model('Taglist')->getListByAid($aid, $typeid);
|
||||
$result['tags'] = $tags['tag_arr'];
|
||||
$result['tag_id'] = $tags['tid_arr'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除的后置操作方法
|
||||
* 自定义的一个函数 用于数据删除后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid
|
||||
*/
|
||||
public function afterDel($aidArr = array())
|
||||
{
|
||||
if (is_string($aidArr)) {
|
||||
$aidArr = explode(',', $aidArr);
|
||||
}
|
||||
// 同时删除内容
|
||||
M('article_content')->where(array('aid'=>array('IN', $aidArr)))->delete();
|
||||
// 同时删除TAG标签
|
||||
model('Taglist')->delByAids($aidArr);
|
||||
}
|
||||
}
|
||||
140
src/application/admin/model/AuthRole.php
Normal file
140
src/application/admin/model/AuthRole.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class AuthRole extends Model{
|
||||
protected $name = 'auth_role';
|
||||
|
||||
protected $type = array(
|
||||
'language' => 'serialize',
|
||||
'cud' => 'serialize',
|
||||
'permission' => 'serialize',
|
||||
);
|
||||
|
||||
protected function initialize(){
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function getRole($where){
|
||||
$result = M($this->name)->where($where)->find();
|
||||
if (!empty($result)) {
|
||||
$result['language'] = unserialize($result['language']);
|
||||
$result['cud'] = unserialize($result['cud']);
|
||||
$result['permission'] = unserialize($result['permission']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getRoleAll($where = ['status'=>1]){
|
||||
$result = M($this->name)->where($where)->order('id asc')->select();
|
||||
foreach ($result as $key => $val) {
|
||||
$val['language'] = unserialize($val['language']);
|
||||
$val['cud'] = unserialize($val['cud']);
|
||||
$val['permission'] = unserialize($val['permission']);
|
||||
$result[$key] = $val;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveAuthRole($input, $batchAdminRole = false){
|
||||
|
||||
$permission = $input['permission'] ? $input['permission'] : null;
|
||||
|
||||
// 角色权限
|
||||
$permission_rules = !empty($permission['rules']) ? $permission['rules'] : [];
|
||||
/*栏目与内容权限*/
|
||||
if (!empty($permission['arctype'])) {
|
||||
$permission_rules[] = 2; // 内容管理的权限ID,在conf/auth_rule.php配置文件
|
||||
}
|
||||
/*--end*/
|
||||
/*插件应用权限*/
|
||||
if (!empty($permission['plugins'])) {
|
||||
$permission_rules[] = 15; // 插件应用的权限ID,在conf/auth_rule.php配置文件
|
||||
}
|
||||
/*--end*/
|
||||
$permission['rules'] = $permission_rules;
|
||||
|
||||
$data = array(
|
||||
'name' => trim($input['name']),
|
||||
'pid' => ! empty($input['pid']) ? (int)$input['pid'] : 0,
|
||||
'grade' => ! empty($input['grade']) ? (int)$input['grade'] : 0,
|
||||
'remark' => ! empty($input['remark']) ? $input['remark'] : '',
|
||||
'language' => ! empty($input['language']) ? $input['language'] : null,
|
||||
'online_update' => ! empty($input['online_update']) ? (int)$input['online_update'] : 0,
|
||||
'editor_visual' => ! empty($input['editor_visual']) ? (int)$input['editor_visual'] : 0,
|
||||
'only_oneself' => ! empty($input['only_oneself']) ? (int)$input['only_oneself'] : 0,
|
||||
'check_oneself' => ! empty($input['check_oneself']) ? (int)$input['check_oneself'] : 0,
|
||||
'cud' => ! empty($input['cud']) ? $input['cud'] : null,
|
||||
'permission' => $permission,
|
||||
'status' => ! empty($input['status']) ? (int)$input['status'] : 1,
|
||||
'sort_order' => ! empty($input['sort_order']) ? (int)$input['sort_order'] : 100,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
);
|
||||
|
||||
if(! empty($input['id']) && $input['id'] > 0){
|
||||
$data['id'] = $input['id'];
|
||||
$rs = parent::update($data);
|
||||
$rs = !empty($rs) ? $input['id'] : $rs;
|
||||
}else{
|
||||
$data['admin_id'] = session('admin_info.admin_id');
|
||||
parent::save($data);
|
||||
$rs = M($this->name)->getLastInsID();
|
||||
}
|
||||
|
||||
\think\Cache::clear('auth_role');
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步栏目ID到权限组,默认是赋予该栏目的权限
|
||||
* @param int $typeid
|
||||
*/
|
||||
public function syn_auth_role($typeid = 0)
|
||||
{
|
||||
if (0 < intval($typeid)) {
|
||||
$roleRow = $this->getRoleAll();
|
||||
if (!empty($roleRow)) {
|
||||
$saveData = [];
|
||||
foreach ($roleRow as $key => $val) {
|
||||
$permission = $val['permission'];
|
||||
$rules = !empty($permission['rules']) ? $permission['rules'] : [];
|
||||
if (!in_array(1, $rules)) {
|
||||
continue;
|
||||
}
|
||||
$arctype = !empty($permission['arctype']) ? $permission['arctype'] : [];
|
||||
if (!empty($arctype)) {
|
||||
array_push($arctype, $typeid);
|
||||
$permission['arctype'] = $arctype;
|
||||
}
|
||||
$saveData[] = array(
|
||||
'id' => $val['id'],
|
||||
'permission' => $permission,
|
||||
);
|
||||
}
|
||||
$r = $this->saveAll($saveData);
|
||||
if (false != $r && 0 < intval(session('admin_info.role_id'))) {
|
||||
/*及时更新当前管理员权限*/
|
||||
$auth_role_info = $this->getRole(array('id' => session('admin_info.role_id')));
|
||||
session('admin_info.auth_role_info', $auth_role_info);
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/application/admin/model/ChannelfieldBind.php
Normal file
28
src/application/admin/model/ChannelfieldBind.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 栏目绑定自定义字段表
|
||||
*/
|
||||
class ChannelfieldBind extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
93
src/application/admin/model/Custom.php
Normal file
93
src/application/admin/model/Custom.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-7
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 标签索引
|
||||
*/
|
||||
class Custom extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置操作方法
|
||||
* 自定义的一个函数 用于数据保存后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid 产品id
|
||||
* @param array $post post数据
|
||||
* @param string $opt 操作
|
||||
*/
|
||||
public function afterSave($aid, $post, $opt)
|
||||
{
|
||||
$post['aid'] = $aid;
|
||||
$addonFieldExt = !empty($post['addonFieldExt']) ? $post['addonFieldExt'] : array();
|
||||
model('Field')->dealChannelPostData($post['channel'], $post, $addonFieldExt);
|
||||
|
||||
// --处理TAG标签
|
||||
model('Taglist')->savetags($aid, $post['typeid'], $post['tags'], $post['arcrank'], $opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($aid, $field = null, $isshowbody = true)
|
||||
{
|
||||
$result = array();
|
||||
$field = !empty($field) ? $field : '*';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->where([
|
||||
'aid' => $aid,
|
||||
'lang' => get_admin_lang(),
|
||||
])
|
||||
->find();
|
||||
if ($isshowbody) {
|
||||
$tableName = M('channeltype')->where('id','eq',$result['channel'])->getField('table');
|
||||
$result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
|
||||
}
|
||||
|
||||
// 文章TAG标签
|
||||
if (!empty($result)) {
|
||||
$typeid = isset($result['typeid']) ? $result['typeid'] : 0;
|
||||
$tags = model('Taglist')->getListByAid($aid, $typeid);
|
||||
$result['tags'] = $tags['tag_arr'];
|
||||
$result['tag_id'] = $tags['tid_arr'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除的后置操作方法
|
||||
* 自定义的一个函数 用于数据删除后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid
|
||||
*/
|
||||
public function afterDel($aidArr = array(), $table)
|
||||
{
|
||||
if (is_string($aidArr)) {
|
||||
$aidArr = explode(',', $aidArr);
|
||||
}
|
||||
// 同时删除内容
|
||||
M($table.'_content')->where(array('aid'=>array('IN', $aidArr)))->delete();
|
||||
// 同时删除TAG标签
|
||||
model('Taglist')->delByAids($aidArr);
|
||||
}
|
||||
}
|
||||
202
src/application/admin/model/Download.php
Normal file
202
src/application/admin/model/Download.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 下载文章
|
||||
*/
|
||||
class Download extends Model
|
||||
{
|
||||
// 模型标识
|
||||
public $nid = 'download';
|
||||
// 模型ID
|
||||
public $channeltype = '';
|
||||
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
$channeltype_list = config('global.channeltype_list');
|
||||
$this->channeltype = $channeltype_list[$this->nid];
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置操作方法
|
||||
* 自定义的一个函数 用于数据保存后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid 产品id
|
||||
* @param array $post post数据
|
||||
* @param string $opt 操作
|
||||
*/
|
||||
public function afterSave($aid, $post, $opt)
|
||||
{
|
||||
$post['aid'] = $aid;
|
||||
$addonFieldExt = !empty($post['addonFieldExt']) ? $post['addonFieldExt'] : array();
|
||||
model('Field')->dealChannelPostData($post['channel'], $post, $addonFieldExt);
|
||||
|
||||
// ---------多文件
|
||||
model('DownloadFile')->savefile($aid, $post);
|
||||
// ---------end
|
||||
|
||||
// --处理TAG标签
|
||||
model('Taglist')->savetags($aid, $post['typeid'], $post['tags'], $post['arcrank'], $opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($aid, $field = '', $isshowbody = true)
|
||||
{
|
||||
$result = array();
|
||||
$field = !empty($field) ? $field : '*';
|
||||
$result = Db::name('archives')->field($field)
|
||||
->where([
|
||||
'aid' => $aid,
|
||||
'lang' => get_admin_lang(),
|
||||
])
|
||||
->find();
|
||||
if ($isshowbody) {
|
||||
$tableName = M('channeltype')->where('id','eq',$result['channel'])->getField('table');
|
||||
$result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
|
||||
}
|
||||
|
||||
// 文章TAG标签
|
||||
if (!empty($result)) {
|
||||
$typeid = isset($result['typeid']) ? $result['typeid'] : 0;
|
||||
$tags = model('Taglist')->getListByAid($aid, $typeid);
|
||||
$result['tags'] = $tags['tag_arr'];
|
||||
$result['tag_id'] = $tags['tid_arr'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取多条记录
|
||||
* @author lindaoyun by 2017-9-18
|
||||
*/
|
||||
public function getListByLimit($map = array(), $limit = 15, $field = '*', $order = 'a.aid desc')
|
||||
{
|
||||
$data = array();
|
||||
$field_arr = explode(',', $field);
|
||||
foreach ($field_arr as $key => $val) {
|
||||
array_push($data, 'a.'.trim($val));
|
||||
}
|
||||
$field = implode(',', $data);
|
||||
$field .= ', b.typename, b.dirname';
|
||||
|
||||
if (!empty($map) && is_array($map)) {
|
||||
foreach ($map as $key => $val) {
|
||||
if (preg_match("/^(a\.)/i", $val) == 0) {
|
||||
$map['a.'.$key] = $val;
|
||||
unset($map[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$map['a.channel'] = $this->channeltype;
|
||||
|
||||
$result = Db::name('archives')
|
||||
->field($field)
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'b.id = a.typeid', 'LEFT')
|
||||
->where($map)
|
||||
->order($order)
|
||||
->limit($limit)
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByClick($limit = 10, $map = array(), $field = '*')
|
||||
{
|
||||
$map['channel'] = $this->channeltype;
|
||||
$map['status'] = 1;
|
||||
$result = Db::name('archives')
|
||||
->field($field)
|
||||
->where($map)
|
||||
// ->cache(true,EYOUCMS_CACHE_TIME)
|
||||
->order('click desc')
|
||||
->limit($limit)
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前文章的所有上下级分类
|
||||
*/
|
||||
public function getAllCateByTypeid($typeid)
|
||||
{
|
||||
$result = M('arctype')->field('id,parent_id,typename')
|
||||
->where(array('id|parent_id'=>$typeid, 'status'=>1))
|
||||
->order('parent_id asc, sort_order asc')
|
||||
->getAllWithIndex('id');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除的后置操作方法
|
||||
* 自定义的一个函数 用于数据删除后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid
|
||||
*/
|
||||
public function afterDel($aidArr = array())
|
||||
{
|
||||
if (is_string($aidArr)) {
|
||||
$aidArr = explode(',', $aidArr);
|
||||
}
|
||||
// 同时删除内容
|
||||
M('download_content')->where(
|
||||
array(
|
||||
'aid'=>array('IN', $aidArr)
|
||||
)
|
||||
)
|
||||
->delete();
|
||||
// 同时删除软件
|
||||
$result = M('download_file')->field('file_url')
|
||||
->where(
|
||||
array(
|
||||
'aid'=>array('IN', $aidArr)
|
||||
)
|
||||
)
|
||||
->select();
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $key => $val) {
|
||||
$file_url = preg_replace('#^(/[/\w]+)?(/public/upload/|/uploads/)#i', '$2', $val['file_url']);
|
||||
if (!is_http_url($file_url) && file_exists('.'.$file_url) && preg_match('#^(/uploads/|/public/upload/)(.*)/([^/]+)\.([a-z]+)$#i', $file_url)) {
|
||||
@unlink(realpath('.'.$file_url));
|
||||
}
|
||||
}
|
||||
$r = M('download_file')->where(
|
||||
array(
|
||||
'aid'=>array('IN', $aidArr)
|
||||
)
|
||||
)->delete();
|
||||
if ($r !== false) {
|
||||
M('download_log')->where(array('aid'=>array('IN', $aidArr)))->delete();
|
||||
}
|
||||
}
|
||||
// 同时删除TAG标签
|
||||
model('Taglist')->delByAids($aidArr);
|
||||
}
|
||||
}
|
||||
163
src/application/admin/model/DownloadFile.php
Normal file
163
src/application/admin/model/DownloadFile.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
class DownloadFile extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条下载文章的所有文件
|
||||
* @author 小虎哥 by 2018-4-3
|
||||
*/
|
||||
public function getDownFile($aid, $field = '*')
|
||||
{
|
||||
$result = Db::name('DownloadFile')->field($field)
|
||||
->where('aid', $aid)
|
||||
->order('sort_order asc')
|
||||
->select();
|
||||
|
||||
foreach ($result as $key => $val) {
|
||||
if (!empty($val['file_url'])) {
|
||||
$result[$key]['file_url'] = handle_subdir_pic($val['file_url'], 'soft');
|
||||
}
|
||||
if (!isset($val['server_name'])) {
|
||||
$result[$key]['server_name'] = $result[$key]['file_name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单条下载文章的所有文件
|
||||
* @author 小虎哥 by 2018-4-3
|
||||
*/
|
||||
public function delDownFile($aid = array())
|
||||
{
|
||||
if (!is_array($aid)) {
|
||||
$aid = array($aid);
|
||||
}
|
||||
$result = Db::name('DownloadFile')->where(array('aid'=>array('IN', $aid)))->delete();
|
||||
if ($result !== false) {
|
||||
Db::name('download_log')->where(array('aid'=>array('IN', $aid)))->delete();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存下载文章的文件
|
||||
* @author 小虎哥 by 2018-4-3
|
||||
*/
|
||||
public function savefile($aid, $post = array())
|
||||
{
|
||||
// 拼装本地链接数据
|
||||
$data = array();
|
||||
$fileupload = isset($post['fileupload']) ? $post['fileupload'] : array();
|
||||
if (!empty($fileupload)) {
|
||||
$sort_order = 0;
|
||||
foreach($fileupload['file_url'] as $key => $val)
|
||||
{
|
||||
if($val == null || empty($val)) continue;
|
||||
$title = !empty($post['title']) ? $post['title'] : '';
|
||||
$file_size = isset($post['fileupload']['file_size'][$key]) ? $post['fileupload']['file_size'][$key] : 0;
|
||||
$file_mime = isset($post['fileupload']['file_mime'][$key]) ? $post['fileupload']['file_mime'][$key] : '';
|
||||
$uhash = isset($post['fileupload']['uhash'][$key]) ? $post['fileupload']['uhash'][$key] : '';
|
||||
$md5file = isset($post['fileupload']['md5file'][$key]) ? $post['fileupload']['md5file'][$key] : '';
|
||||
$file_name = isset($post['fileupload']['file_name'][$key]) ? $post['fileupload']['file_name'][$key] : '';
|
||||
$file_ext = isset($post['fileupload']['file_ext'][$key]) ? $post['fileupload']['file_ext'][$key] : '';
|
||||
$server_name = isset($post['fileupload']['server_name'][$key]) ? $post['fileupload']['server_name'][$key] : '';
|
||||
++$sort_order;
|
||||
$data[] = array(
|
||||
'aid' => $aid,
|
||||
'title' => $title,
|
||||
'file_url' => $val,
|
||||
'extract_code' => '',
|
||||
'file_size' => $file_size,
|
||||
'file_ext' => $file_ext,
|
||||
'file_name' => $file_name,
|
||||
'file_mime' => $file_mime,
|
||||
'uhash' => $uhash,
|
||||
'md5file' => $md5file,
|
||||
'server_name' => $server_name,
|
||||
'is_remote' => 0,
|
||||
'sort_order' => $sort_order,
|
||||
'add_time' => getTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 拼装远程链接数据
|
||||
$data_new = array();
|
||||
if (!empty($post['remote_file'])) {
|
||||
$sort_order = $sort_order;
|
||||
foreach($post['remote_file'] as $kkk => $vvv)
|
||||
{
|
||||
if($vvv == null || empty($vvv)) continue;
|
||||
$server_name = !empty($post['server_name'][$kkk]) ? trim($post['server_name'][$kkk]) : '';
|
||||
$extract_code = !empty($post['extract_code'][$kkk]) ? trim($post['extract_code'][$kkk]) : '';
|
||||
++$sort_order;
|
||||
$data_new[] = array(
|
||||
'aid' => $aid,
|
||||
'title' => $post['title'],
|
||||
'file_url' => $vvv,
|
||||
'extract_code' => $extract_code,
|
||||
'file_size' => '0',
|
||||
'file_ext' => '',
|
||||
'file_name' => $server_name,
|
||||
'file_mime' => '',
|
||||
'uhash' => md5($vvv),
|
||||
'md5file' => md5($vvv),
|
||||
'server_name' => $server_name,
|
||||
'is_remote' => 1,
|
||||
'sort_order' => $sort_order,
|
||||
'add_time' => getTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$data_new_new = [];
|
||||
if (!empty($data) && !empty($data_new)) {
|
||||
// 数组合并
|
||||
$data_new_new = array_merge($data,$data_new);
|
||||
}else if (!empty($data)) {
|
||||
$data_new_new = $data;
|
||||
}else if (!empty($data_new)) {
|
||||
$data_new_new = $data_new;
|
||||
}
|
||||
|
||||
// 删除
|
||||
$this->delDownFile($aid);
|
||||
|
||||
// 添加到数据库
|
||||
if (!empty($data_new_new)) {
|
||||
// 批量添加
|
||||
M('DownloadFile')->insertAll($data_new_new);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user