This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

30
app/admin/behavior/CheckIp.php Executable file
View File

@@ -0,0 +1,30 @@
<?php
namespace app\admin\behavior;
use think\Request;
use think\Config;
load_trait('controller/Jump');
/**
* Description of CheckIp
* 检测用户访问的ip
*/
class CheckIp {
use \traits\controller\Jump;
/**
* 检测用户IP
*/
public function run() {
$allow_ip = Config::get('admin_allow_ip');
$ip = Request::instance()->ip();
if (!is_administrator() && $allow_ip) {
!in_array($ip, explode(',', $allow_ip)) && $this->error('禁止访问'); // 检查IP地址访问
}
\think\Log::record("[ 访问者IP ]" . $ip);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace app\admin\behavior;
use think\Config;
use think\Cache;
use think\Loader;
use think\App;
use think\Log;
class SystemConfig {
/**
* 系统配置读取并缓存
*/
public function run() {
$config = Cache::get('admin_config_data');
if (empty($config)) {
$config = Loader::model('Sysconfig')->configLists();
Cache::tag('sysconfig')->set('admin_config_data', $config);
App::$debug && Log::record("[ 系统配置 ]:初始化成功");
}
//header('content-type:text/html;charset=utf-8;');
//var_export($config);exit;
Config::set($config);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace app\admin\behavior;
use think\Log;
use think\Request;
use think\Session;
class UserAction {
private $Request;
/**
* 日志记录
*/
public function run($call) {
$this->Request = Request::instance();
$domainurl = $this->Request->url(true);
$module = $this->Request->module();
$controller = $this->Request->controller();
$action = $this->Request->action();
$method = $this->Request->method();
switch ($controller) {
case 'Translate':
action_log($controller . '控制器' . $action . '动作操作记录', "翻译操作记录{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
break;
case 'Webuploader':
action_log($controller . '控制器' . $action . '动作操作记录', "文件管理操作记录{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
break;
case 'Dbmanager':
action_log($controller . '控制器' . $action . '动作操作记录', "数据管理操作记录{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
break;
case 'Sysconfig':
action_log($controller . '控制器' . $action . '动作操作记录', "系统配置管理操作记录{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
break;
case 'Ueditor':
action_log($controller . '控制器' . $action . '动作操作记录', "编辑器操作记录{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
break;
default:
$actions = ['create', 'update', 'delete', 'deletes', 'distory', 'distorys', 'recovery', 'recoverys', 'setting', 'recycle', 'recommends'];
if (in_array($action, $actions) || stripos($action, 'toggle') === 0 || stripos($action, 'update') === 0) {
action_log($controller . '控制器' . $action . '动作操作记录', "{$module}-{$controller}-{$action}-{$method}-" . date('Y-m-d H:i:s'), null);
}
break;
}
}
}

163
app/admin/common.php Executable file
View File

@@ -0,0 +1,163 @@
<?php
use think\Request;
use think\Loader;
/**
* 记录日志
*/
function action_log($title = '日志名称', $content = null, $user_id = 0, $param = array()) {
$request = Request::instance();
//参数检查
if (empty($title) || empty($content)) {
return '参数不能为空';
}
$user_id = $user_id > 0 ? $user_id : (isset($user_id) ? 0 : is_session_login('user'));
// if ($user_id == 1) {
// return 'debug';
// }
//插入日志
$data['title'] = $title;
$data['user_id'] = $user_id;
$data['ip'] = $request->ip();
$data['url'] = $request->url(true);
$data['module'] = $request->module();
$data['controller'] = $request->controller();
$data['action'] = $request->action();
$data['param'] = empty($param) ? serialize($request->param()) : serialize($param);
$data['content'] = is_array($content) ? serialize($content) : $content;
$data['addtime'] = time();
Loader::model('ActionLog')->data($data)->save();
}
//获取指定模块中的控制器名
function get_ctrl_names($module, $retrun = 'string') {
$ctrlPath = APP_PATH . ltrim($module, '/') . '/controller';
$ctrlOption = '';
$ctrlArray = [];
if (is_dir($ctrlPath)) {
$dirResource = opendir($ctrlPath);
while ($dir = readdir($dirResource)) {
if (!in_array($dir, array('.', '..', '.svn'))) {
$ctrlArray[] = $val = basename($dir, '.php');
$ctrlOption .= "<option value='" . $val . "'>" . $val . "</option>";
}
}
closedir($dirResource);
}
if ($retrun == 'string') {
return $ctrlOption;
} else {
return $ctrlArray;
}
}
//获取指定控制器中的动作名
function get_action_names($controller, $namespace = '', $retrun = 'string') {
$class_name = is_object($controller) ? $controller : $namespace . str_replace('.php', '', $controller);
$current_actions = get_class_methods($class_name);
if (!isset($current_actions)) {
return '指定的控制器无效';
}
$parent_class_name = get_parent_class($class_name);
$parent_actions = $parent_class_name ? get_class_methods($parent_class_name) : ['__construct', '_initialize'];
$actionArray = array_diff($current_actions, $parent_actions);
$actionOption = '';
foreach ($actionArray as $val) {
$actionOption .= "<option value='" . $val . "'>" . $val . "</option>";
}
if ($retrun == 'string') {
return $actionOption;
} else {
return $actionArray;
}
}
if (!function_exists('is_administrator')) {
/**
* 检测当前用户是否为管理员
* @param null $uid
* @return bool true-管理员false-非管理员
*/
function is_administrator($uid = null) {
$user_id = !empty($uid) ? $uid : is_session_login('user');
return is_int($user_id) && ((int) $user_id === (int) config('user_administrator'));
}
}
/**
* 分析枚举类型配置值
* 格式 a:名称1,b:名称2
* @param $string 配置值
* @return array
*/
function parse_config_attr($string) {
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
if (strpos($string, ':')) {
$value = [];
foreach ($array as $val) {
list($k, $v) = explode(':', $val);
$value[$k] = $v;
}
} else {
$value = $array;
}
return $value;
}
function editor($selector = '#content', $type = 'string') {
$rootDir = request()->root();
if (is_array($selector)) {
$KindEditor = "\n";
foreach ($selector as $s) {
$KindEditor .="KindEditor.ready(function(K) {K.create('{$s}', {allowFileManager: true});});\n";
}
} else {
$KindEditor = "KindEditor.ready(function(K) {K.create('{$selector}', {allowFileManager: true});});";
}
$editor = <<<EDITOR
<link rel="stylesheet" href="{$rootDir}/backend/adminlte/kindeditor/themes/default/default.min.css" />
<link rel="stylesheet" href="{$rootDir}/backend/adminlte/kindeditor/themes/default/custom.css" />
<script charset="utf-8" src="{$rootDir}/backend/adminlte/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript">
$KindEditor
</script>
EDITOR;
return $editor;
}
/**
* 国家选择
* @cit $string 国家
* @view $string 表
* */
function city($cit = '',$view = ''){
$cit = strtolower($cit);
switch ($cit){
case '':
return Loader::model($view);
break;
case 'zh':
return Loader::model($view);
break;
case 'en':
return Loader::model($view.'En');
break;
case 'us':
return Loader::model($view.'Us');
break;
case 'id':
return Loader::model($view.'Id');
break;
case 'th':
return Loader::model($view.'Th');
break;
case 'vn':
return Loader::model($view.'Vn');
break;
default:
}
}

41
app/admin/config.php Executable file
View File

@@ -0,0 +1,41 @@
<?php
return [
'app_debug' => true,
'exception_tmpl' => APP_PATH . 'common' . DS . 'view' . DS . 'tpl' . DS . 'think_exception.tpl',
//管理员用户ID
'user_administrator' => 1,
// 默认跳转页面对应的模板文件
'dispatch_success_tmpl' => APP_PATH . 'common' . DS . 'view' . DS . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => APP_PATH . 'common' . DS . 'view' . DS . 'tpl' . DS . 'dispatch_jump.tpl',
// +----------------------------------------------------------------------
// | 异常及错误设置
// +----------------------------------------------------------------------
// 异常页面的模板文件
'exception_tmpl' => APP_PATH . 'common' . DS . 'view' . DS . 'tpl' . DS . 'think_exception.tpl',
//是否启用布局
'template' => [
'layout_on' => true,
'layout_name' => 'public/layout',
// 模板路径
//'view_path' => __DIR__ . '/view/',
// 模板后缀
//'view_suffix' => 'phtml',
// 模板文件名分隔符
//'view_depr' => DS,
],
'view_replace_str' => [
'__PUBLIC__' => '/backend',
//'__TEMPLATE__' => '/public/static',
'__PREFIX__' => '',
],
//分页配置
'paginate' => [
'type' => '\pagination\Bootstrap',
'var_page' => 'page',
'list_rows' => 15,
],
'image_upload_limit_size' => 1024*1024*1, //上传图片大小限制
'file_upload_limit_size' => 1024 * 1024 * 100, //上传文件大小限制
];

View File

@@ -0,0 +1,122 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class ActionLog extends BaseController {
public function index() {
$this->redirect('/admin/action_log/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('al.stat' => 0);
$arg_order = array('al.id' => 'desc');
$arg_field = array('al.id' => 'id', 'al.title' => 'title', 'al.content' => 'content', 'al.ip' => 'ip', 'al.addtime' => 'addtime', 'u.username' => 'username', 'al.stat' => 'stat');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['title|ip|content'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('ActionLog')->getPageLists($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$value = array();
$id = intval($id);
if ($id > 0) {
$action_log = Loader::model('ActionLog')->getRow($id);
if (empty($action_log)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['action_log'] = $action_log;
}
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['title' => 'require'];
$validatemsg = ['title.require' => 'title ' . Lang::get('can not be empty')];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = Loader::model('ActionLog')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('ActionLog')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('ActionLog')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function clear_log() {
$tableName = Loader::model('ActionLog')->getTable();
$result = Loader::model('ActionLog')->execute("TRUNCATE TABLE {$tableName};");
if ($result == 0) {
return $this->success(Lang::get('operation successed'), null, $result);
} else {
return $this->error(Lang::get('operation failed'), null, $result);
}
}
public function clear_log3() {
$result = Loader::model('ActionLog')->where(['addtime' => ['lt', strtotime('-3 month')]])->delete();
if ($result) {
return $this->success(Lang::get('operation successed'), null, $result);
} else {
return $this->error(Lang::get('operation failed'));
}
}
}

399
app/admin/controller/Ad.php Executable file
View File

@@ -0,0 +1,399 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Ad extends BaseController {
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['b.siteid' => $this->siteid, 'b.country_code' => $this->country_code];
$arg_order = ['b.id' => 'desc'];
$arg_field = ['b.*', 'bt.id' => 'typeid', 'bt.name' => 'typename'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['b.name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('ad')->getAdLists($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add($typeid = 0) {
$typeid = is_numeric($typeid) ? intval($typeid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = model('ad_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value = ['typeOption' => $typeOption];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$href = isset($data['ad_normbody']['href']) ? addslashes($data['ad_normbody']['href']) : '/';
if ($data['normbody']['style'] == 'htmlcode') {
$data['normbody'] = addslashes($data['normbody']['htmlcode']);
} else if ($data['normbody']['style'] == 'text') {
$style = "style=\"";
if (!empty($data['normbody']['size'])) {
$style .= "font-size:{$data['normbody']['size']};";
}
if (!empty($data['normbody']['color'])) {
$style.= "color:{$data['normbody']['color']};";
}
$style.="\"";
$data['normbody'] = "<a href=\"{$href}\" {$style}>{$data['normbody']['text']}</a>";
} else if ($data['normbody']['style'] == 'image') {
$style = "style=\"";
if (!empty($data['normbody']['width'])) {
$style .= "width:{$data['normbody']['width']};";
}
if (!empty($data['normbody']['height'])) {
$style.= "height:{$data['normbody']['height']};";
}
$style.="border:0px;\"";
$data['normbody'] = "<a href=\"{$href}\" target=\"_blank\"><img src=\"{$data['normbody']['src']}\" {$style}/></a>";
} else {
$data['normbody'] = addslashes($data['normbody']['flash']);
}
if (($timestamp = strtotime($data['starttime'])) === false) {
$data['starttime'] = time();
} else {
$data['starttime'] = $timestamp;
}
if (($timestamp = strtotime($data['endtime'])) === false) {
$data['endtime'] = time();
} else {
$data['endtime'] = $timestamp;
}
$set = array(
'typeid' => $data['typeid'],
'name' => $data['name'],
'sort' => intval($data['sort']),
'tags' => trim($data['tags']),
'timeset' => $data['timeset'],
'starttime' => $data['starttime'],
'endtime' => $data['endtime'],
'normbody' => $data['normbody'],
'expbody' => $data['expbody'],
'siteid' => $this->siteid,
'country_code' => $this->country_code
);
$model = model('ad')->insertRow($set);
if ($model && $model->getData('id')) {
$this->cacheClear('adTag');
return $this->redirect(url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$ad = model('ad')->getRow($id);
if (empty($ad)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['ad'] = $ad;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$typeid = isset($ad['typeid']) ? $ad['typeid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = model('ad_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value['typeOption'] = $typeOption;
$value['typeid'] = $typeid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['id' => 'require', 'name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['id.require' => 'ID不能为空', 'name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (($timestamp = strtotime($data['starttime'])) === false) {
$data['starttime'] = time();
} else {
$data['starttime'] = $timestamp;
}
if (($timestamp = strtotime($data['endtime'])) === false) {
$data['endtime'] = time();
} else {
$data['endtime'] = $timestamp;
}
$set = array(
'typeid' => $data['typeid'],
'name' => $data['name'],
'sort' => intval($data['sort']),
'tags' => trim($data['tags']),
'timeset' => $data['timeset'],
'starttime' => $data['starttime'],
'endtime' => $data['endtime'],
'normbody' => $data['normbody'],
'expbody' => $data['expbody'],
'id' => $data['id'],
);
$model = model('ad')->updateRow($set);
if ($model && $id = $model->getData('id')) {
$this->cacheClear('adTag');
return $this->redirect(url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function preview() {
$id = $this->request->param('id', 0);
$id = intval($id);
if ($this->request->isAjax() && $id > 0) {
$jscode = '<script src="' . url('index/ad/index', ['id' => $id]) . '" type="text/javascript"></script>';
$showhtml = "<xmp style='color:#333333;background-color:#ffffff'>\r\n\r\n$jscode\r\n\r\n</xmp>";
$iframesrc = url('/index/ad/previewjs', ['id' => $id]);
$value = ['showhtml' => $showhtml, 'iframesrc' => $iframesrc,];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
return $this->error(Lang::get('incorrect operation'));
}
public function clear_cache() {
$this->cacheClear('adTag');
return $this->success(Lang::get('operation successed'));
}
public function togglerecommend() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($this->request->isGet() && $id) {
$model = model('ad')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($this->request->isAjax() && $id) {
$model = model('ad')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('ad')->deleteRow($id);
if ($model && $model->getData('id')) {
$this->cacheClear('adTag');
return $this->success(Lang::get('operation successed'), url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
//echo json_encode(['code' => false, 'msg' => print_r($in_ids, true)]);exit;
$result = model('ad')->deleteRows($in_ids);
if ($result) {
$this->cacheClear('adTag');
return $this->success(Lang::get('operation successed'), url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $in_ids) {
$result = model('ad')->updateRow(['recommend' => 1], ['id' => ['in', $in_ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/ad/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//类别
public function typelists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'name', 'description', 'createtime');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('ad_type')->getPageList($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function typeedit($id = 0) {
$id = intval($id);
if ($id > 0) {
$adtype = model('ad_type')->getRow($id);
if (empty($adtype)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['adtype'] = $adtype;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$this->assign($value);
return $this->fetch();
}
public function typeupdate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = model('ad_type')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/ad/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typeadd() {
return $this->fetch();
}
public function typecreate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$model = model('ad_type')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/ad/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedelete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('ad_type')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/ad/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedeletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('ad_type')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/ad/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

61
app/admin/controller/Agent.php Executable file
View File

@@ -0,0 +1,61 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Agent extends BaseController
{
public function index(){
$agent = Db('agent');
$where = ['stat'=>0];
$list = $agent->where($where)->select();
$count = count($list);
$list = $agent->where($where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('page',$page);
$this->assign('list',$list);;
return $this->fetch();
}
public function add(){
return $this->fetch();
}
public function creat(){
$data = $_POST;
$data['stat'] = 0;
$adent = Db('agent');
$inster = $adent->insert($data);
if($inster){
return $this->success('添加成功');
}else{
return $this->error('添加失败');
}
}
public function edit(){
$where = ['id '=>$_GET['id'],'stat'=>0];
$agent = Db('agent');
$data = $agent->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$adent = Db('agent');
$inster = $adent->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
}

138
app/admin/controller/Agents.php Executable file
View File

@@ -0,0 +1,138 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Agents extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$agent = Db('agents');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['name|interest|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $agent->where($arg_where)->select();
$count = count($list);
$list = $agent->where($arg_where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
public function edit(){
$where = ['id '=>$_GET['id'],'stat'=>0];
$agent = Db('agents');
$data = $agent->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$adent = Db('agents');
$inster = $adent->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$agent = Db('agents');
$data = $agent->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制删除
public function delete($id = 0) {
//echo "<pre>====="; print_r($id);die;
$id = intval($id);
if ($id > 0) {
$result = model('agents')->deleteRow($id);
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/agent/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('agents')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/agent/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

544
app/admin/controller/Article.php Executable file
View File

@@ -0,0 +1,544 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Article extends BaseController {
public function index() {
$this->redirect('/admin/article/lists');
}
private function init_search(&$search)
{
$search['name'] = '';
$search['tags'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists() {
$data = $this->request->param();
$cid = isset($data['cid']) ? intval($data['cid']) : 0;
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != '')
{
$arg_where['a.name'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if (isset($data['tags']) && $data['tags'] != '')
{
$arg_where['a.tags'] = ['like', "%$data[tags]%"];
$search['tags'] = $data['tags'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != ''))
{
// 时间有一个不为空就初始化
$arg_where['a.createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = strtotime($data['timebegin']);
array_push($arg_where['a.createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = strtotime($data['timeend']);
array_push($arg_where['a.createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
}
$arg_order = ['a.createtime' => 'desc', 'a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.id,a.picture,a.name,a.sort,a.headline,a.createtime,a.stat,a.cid,a.tags,a.siteid,a.country_code,a.ishot,a.recommend', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if ($cid > 0) {
$arg_where['a.cid'] = $cid;
}
$dataObject = model('article')->getArticleLists($arg_where, $arg_order, $arg_field, 12);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions($cid, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'cid' => $cid,
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add($cid = 0) {
$cid = is_numeric($cid) ? intval($cid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$seriesOptions = model('ProductSeries')->getSeriesOptions(
['stat' => 0, 'country_code' => $this->country_code],
['sort' => 'asc', 'id' => 'asc'],
['id', 'name', 'sort']
);
$value = ['categoryOptions' => $categoryOptions, 'seriesOptions' => $seriesOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['user_id'] = $this->user_id;
$data['country_code'] = $this->country_code;
$model = model('article')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$article = model('article')->getRow($id);
if (empty($article)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['article'] = $article;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$cid = isset($article['cid']) ? $article['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$seriesOptions = model('ProductSeries')->getSeriesOptions(
['stat' => 0, 'country_code' => $this->country_code],
['sort' => 'asc', 'id' => 'asc'],
['id', 'name', 'sort'],
null,
explode(",", $article['product_series'])
);
$value['categoryOptions'] = $categoryOptions;
$value['seriesOptions'] = $seriesOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$model = model('article')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('article')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleheadline() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article')->updateRow(['id' => $id, 'headline' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$article = model('article')->getRow($id);
if (empty($article)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['article'] = $article;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$cid = isset($article['cid']) ? $article['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function movecategory() {
$cid = $this->request->post('cid', 0);
$ids = $this->request->post('ids');
$cid = intval($cid);
if ($this->request->isPost() && $cid && $ids) {
$result = model('article')->updateRows(['cid' => $cid,'jump_link' => ''], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('article')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('article')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('article')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$arg_order = ['a.createtime' => 'desc', 'a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name|a.tags'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('article')->getRecycleLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('article')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recoverys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('article')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('article')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('article')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function export() {
$arg_where = ['a.stat' => 0, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$data = $this->request->param();
if (isset($data['name']) && $data['name']) {
$arg_where['a.name'] = ['like', '%' . $data['name'] . '%'];
$search['name'] = $data['name'];
} else {
$search['name'] = '';
}
if (isset($data['cid']) && $data['cid']) {
$childIDArray = city(session('cit'),'ArticleCategory')->getChildIDArray($data['cid']);
$arg_where['a.cid'] = count($childIDArray) == 1 ? $data['cid'] : ['in', $childIDArray];
$search['cid'] = $data['cid'];
} else {
$search['cid'] = 0;
}
if (isset($data['tags']) && $data['tags']) {
$arg_where['a.tags'] = ['like', '%' . $data['tags'] . '%'];
$search['tags'] = $data['tags'];
} else {
$search['tags'] = '';
}
$search['timebegin'] = isset($data['timebegin']) ? strtotime($data['timebegin']) : 0;
$search['timeend'] = isset($data['timeend']) ? strtotime($data['timeend']) : 0;
if ($search['timeend'] - $search['timebegin'] > 0) {
$arg_where['a.createtime'] = ['between', [$search['timebegin'], $search['timeend']]];
} else {
if ($search['timebegin'] > 0 && empty($search['timeend'])) {
$arg_where['a.createtime'] = ['gt', $search['timebegin']];
}
}
if (!empty($data['field'])) {
$fields = array_merge(array('id' => 'ID'), $data['field']);
} else {
$fields = array('id' => 'ID', 'cid' => '所属分类', 'name' => '名称', 'sort' => '排序', 'headline' => '首页推荐', 'picture' => '图片',
'writer' => '新闻作者', 'source' => '新闻来源', 'viewcount' => '浏览数量', 'zancount' => '点赞数量', /* 'commentcount' => '评论数量', */
'description' => '新闻描述', 'picture' => '新闻图片', 'tags' => '新闻标签', 'content' => '内容详情',
'seo_title' => 'SEO标题', 'seo_keyword' => 'SEO关键词', 'seo_description' => 'SEO描述', 'createtime' => '发布时间');
}
$argc_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('articleCategory')->getCategoryOptions($search['cid'], $argc_where, $argc_order, $argc_field, 100);
if (empty($data['submit'])) {
$value = ['categoryOptions' => $categoryOptions, 'fields' => $fields];
$this->assign($value);
return $this->fetch();
}
$arg_order = ['a.createtime' => 'desc', 'a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = array_map(function($value) {
return 'a.' . $value;
}, array_keys($fields));
$arg_field['c.id'] = 'categoryid';
$arg_field['c.name'] = 'categoryname';
set_time_limit(36000);
ini_set('memory_limit', '512M');
$total = model('article')->getExportSearchArticleLists($arg_where, $arg_order, null, true);
$page_size = 1000;
$totalpage = ceil($total / $page_size);
$sheet_size = 5 * $page_size;
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
Loader::import('phpexcel.Classes.PHPExcel', EXTEND_PATH);
Loader::import('phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
$objPHPExcel = new \PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Call of Duty")
->setLastModifiedBy("Call of Duty")
->setTitle("Office 2007 XLSX Cod Document")
->setSubject("Office 2007 XLSX Cod Document")
->setDescription("Cod document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Cod result file");
$page = 0;
$sheet = 0;
do {
$start_index = $page * $page_size;
$datainfo = model('article')->getExportSearchArticleLists($arg_where, $arg_order, [$start_index, $page_size], false, $arg_field);
if (!empty($datainfo)) {
if (($start_index % $sheet_size) == 0) {
if ($sheet) {
$objPHPExcel->createSheet();
}
$sheet++;
$i = 0;
foreach ($fields as $key => $field) {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . '1', $field);
$i++;
}
$objPHPExcel->getActiveSheet()->setTitle('sheet' . $sheet);
$index = 1;
}
foreach ($datainfo as $row) {
if (isset($row['cid'])) {
$row->data('cid', $row['categoryname']);
}
if (isset($row['createtime'])) {
$row->data('createtime', date('Y-m-d H:i:s', $row['createtime']));
}
$index++;
$i = 0;
foreach ($fields as $key => $field) {
if ($key == 'picture') {
$image = '.' . $this->request->root() . $row['picture'];
if (@fopen($image, 'r')) {
$objDrawing = new \PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($image);
$objDrawing->setHeight(50);
$objDrawing->setWidth(50);
$objDrawing->setCoordinates($cellName[$i] . $index);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
}
} else {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . $index, $row[$key]);
}
$i++;
}
}
usleep(10000);
}
$page++;
if ($page > 650) {
break;
}
} while ($page < $totalpage);
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client's web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
}

View File

@@ -0,0 +1,297 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class ArticleCategory extends BaseController {
public function index() {
$this->redirect('/admin/article_category/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$category_list = model('article_category')->getCategoryLists($arg_where, $arg_order, $arg_field, 24);
$value = ['list' => $category_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('article_category')->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions, 'pid' => $pid];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$categoryModel = model('article_category');
if (isset($data['pid']) && $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/article_category/lists'));
//return $this->success(Lang::get('operation successed'), url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$categoryModel = model('article_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['article_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$categoryModel = model('article_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['article_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$oldpid = $data['oldpid'];
unset($data['oldpid']);
$categoryModel = model('article_category');
$where = ['stat' => 0, 'country_code' => $this->country_code];
$childIDArray = $categoryModel->getChildIDArray($data['id'], $where);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
if (isset($data['pid']) && $data['pid'] && $oldpid != $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->updateRow($data);
if (isset($oldpid) && $oldpid && $oldpid != $data['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $oldpid]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $oldpid, 'haschild' => 1]);
}
}
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function subcolumn() {
$column = $this->request->get('subcolumn/s', '', 'urldecode');
$columns = explode(',', $column);
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$category_list = model('article_category')->getCategoryTree($arg_where, $arg_order, $arg_field, 20);
$value = ['list' => $category_list, 'columns' => $columns,];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function listcategory($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$categoryModel = model('article_category');
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = $categoryModel->getList($arg_where, $arg_order, $arg_field, 50);
$category_breadcrumb = $categoryModel->getBreadCrumb($pid);
$value = ['list' => $category_list, 'pid' => $pid, 'breadcrumb' => $category_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0) {
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = model('article_category')->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $category_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
if ($id && $sort < 2147483647) {
$model = model('article_category')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article_category')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article_category')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('article_category')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/article_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$row = model('article')->getRow(['cid' => $id, 'stat' => 0], ['id', 'name']);
if ($row) {
return $this->error('此节点包含内容[ID:' . $row['id'] . '名称:' . $row['name'] . '],不能进行删除');
}
$categoryModel = model('article_category');
$category = $categoryModel->getRow(['id' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($category && $category['haschild']) {
$child = $categoryModel->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
}
if ($category && $category['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $category['pid'], 'id' => ['neq', $category['id']]]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $category['pid'], 'haschild' => 1]);
}
}
$result = $categoryModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

147
app/admin/controller/Ask.php Executable file
View File

@@ -0,0 +1,147 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Ask extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$inquiry = Db('ask');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['name|email'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['create_time'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['create_time'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['create_time'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['create_time'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['create_time'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $inquiry->where($arg_where)->select();
$count = count($list);
$list = $inquiry->where($arg_where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
public function edit(){
$where = ['id '=>$_GET['id']];
$inquiry = Db('ask');
$data = $inquiry->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$inquiry = Db('inquiry');
$inster = $inquiry->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$inquiry = Db('ask');
$data = $inquiry->where($where)->find();
$data['create_time'] = date("Y-m-d H:i:s", $data['create_time']);
if($data['attachment']) {
$attachment = unserialize($data['attachment']);
}
else{
$attachment = '';
}
$this->assign('attachment',$attachment);
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制删除
public function delete($id = 0) {
//echo "<pre>====="; print_r($id);die;
$id = intval($id);
if ($id > 0) {
$result = model('ask')->deleteRow($id);
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/ask/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('ask')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/ask/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,167 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class AuthAccess extends BaseController {
public function index() {
$this->redirect('/admin/auth_access/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('aa.stat' => 0);
$arg_order = array('aa.id' => 'asc');
$arg_field = array('aa.id', 'aa.name', 'aa.gid', 'ag.name' => 'group', 'aa.access', 'aa.stat', 'aa.module');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['aa.name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('AuthAccess')->getAuthAccessLists($arg_where, $arg_order, $arg_field, 24);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$auth_access = Loader::model('AuthAccess')->getRow($id);
if (empty($auth_access)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['auth_access'] = $auth_access;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$groupOption = Loader::model('AuthGroup')->getOption($auth_access['gid'], ['stat' => 0], ['id' => 'asc'], ['id', 'name',], 50);
$value['groupOption'] = $groupOption;
$ctrlOption = get_ctrl_names('admin');
$value['ctrlOption'] = $ctrlOption;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['id' => 'require', 'name' => 'require', 'gid' => 'between:0,2147483647', 'module' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'gid.between' => '权限组不能为空', 'module.require' => '模块不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$access_row['id'] = $data['id'];
$access_row['name'] = $data['name'];
$access_row['gid'] = $data['gid'];
$access_row['module'] = $data['module'];
$access_row['access'] = implode(',', $data['access']);
$model = Loader::model('AuthAccess')->updateRow($access_row);
if ($model && $model->getData('id')) {
$this->cacheClear('AuthAccessTag');
return $this->redirect(url('/admin/auth_access/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function add() {
$groupOption = Loader::model('AuthGroup')->getOption(0, ['stat' => 0], ['id' => 'asc'], [ 'id', 'name',], 50);
$value['groupOption'] = $groupOption;
$ctrlOption = get_ctrl_names('admin');
$value['ctrlOption'] = $ctrlOption;
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require', 'gid' => 'between:0,2147483647', 'module' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'gid.between' => '权限组不能为空', 'module.require' => '模块不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$access_row['name'] = $data['name'];
$access_row['gid'] = $data['gid'];
$access_row['module'] = $data['module'];
$access_row['access'] = implode(',', $data['access']);
$model = Loader::model('AuthAccess')->insertRow($access_row);
if ($model && $model->getData('id')) {
$this->cacheClear('AuthAccessTag');
return $this->redirect(url('/admin/auth_access/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('operation failed'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('AuthAccess')->deleteRow($id);
if ($result) {
$this->cacheClear('AuthAccessTag');
return $this->success(Lang::get('operation successed'), url('/admin/auth_access/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$data = $this->request->post();
if ($this->request->isPost() && $data['ids']) {
$result = Loader::model('AuthAccess')->deleteRows($data['ids']);
if ($result) {
$this->cacheClear('AuthAccessTag');
return $this->success(Lang::get('operation successed'), url('/admin/auth_access/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class AuthGroup extends BaseController {
public function index() {
$this->redirect('/admin/auth_group/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => 0);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'name', 'description', 'stat');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('AuthGroup')->getPageList($arg_where, $arg_order, $arg_field, 24);
//$groupOption = Loader::model('AuthGroup')->getOption(0, $arg_where, $arg_order, ['id', 'name',], 50);
$value = [
//'groupOption' => $groupOption,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$auth_group = Loader::model('AuthGroup')->getRow($id);
if (empty($auth_group)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['auth_group'] = $auth_group;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:auth_group,name', 'description' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
$model = Loader::model('AuthGroup')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/auth_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function add() {
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:auth_group,name', 'description' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
//$data['siteid'] = $this->siteid;
$model = Loader::model('AuthGroup')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/auth_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('AuthGroup')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/auth_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $in_ids) {
$result = Loader::model('AuthGroup')->deleteRows($in_ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/auth_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use app\common\controller\BaseController as Base;
class Authcode extends Base {
public function index($id = "") {
$verify = new \verify\Verify((array) Config::get('captcha'));
return $verify->entry($id);
}
/**
* 验证码
*/
public function check($code, $id = '') {
return $this->verify_check($code, $id);
}
/**
* 验证码
*/
public function verify($id = '') {
ob_clean();
return $this->verify_build($id);
}
}

326
app/admin/controller/Banner.php Executable file
View File

@@ -0,0 +1,326 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Banner extends BaseController {
public function index() {
$this->redirect('/admin/banner/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['b.siteid' => $this->siteid, 'b.country_code' => $this->country_code];
$arg_order = ['b.id' => 'desc'];
$arg_field = ['b.*', 'bt.id' => 'typeid', 'bt.name' => 'typename'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['b.name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('banner')->getBannerLists($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add($typeid = 0) {
$typeid = is_numeric($typeid) ? intval($typeid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = model('banner_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value = ['typeOption' => $typeOption];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['alt'] = $data['alt'];
$data['videourl'] = empty($data['videourl']) ? '' : $data['videourl'];
$data['descolor'] = empty($data['descolor']) ? $data['alt'] : $data['descolor'];
$data['btncolor'] = empty($data['btncolor']) ? $data['alt'] : $data['btncolor'];
$data['style'] = empty($data['style']) ? 1 : $data['style'];
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$model = model('banner')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$banner = model('banner')->getRow($id);
if (empty($banner)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['banner'] = $banner;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$typeid = isset($banner['typeid']) ? $banner['typeid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
// tiaoshi($banner);die;
$typeOption = model('banner_type')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value['typeOption'] = $typeOption;
$value['typeid'] = $typeid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['videourl'] = empty($data['videourl']) ? '' : $data['videourl'];
$data['sort'] = intval($data['sort']);
$data['descolor'] = empty($data['descolor']) ? $data['alt'] : $data['descolor'];
$data['btncolor'] = empty($data['btncolor']) ? $data['alt'] : $data['btncolor'];
$data['style'] = empty($data['style']) ? 1 : $data['style'];
$model = model('banner')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($this->request->isGet() && $id) {
$model = model('banner')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($this->request->isAjax() && $id) {
$model = model('banner')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('banner')->deleteRow($id);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
$result = model('banner')->deleteRows($in_ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $in_ids) {
$result = model('banner')->updateRow(['recommend' => 1], ['id' => ['in', $in_ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//类别
public function typelists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'name', 'description', 'createtime');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('banner_type')->getPageList($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function typeedit($id = 0) {
$id = intval($id);
if ($id > 0) {
$bannertype = model('banner_type')->getRow($id);
if (empty($bannertype)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['bannertype'] = $bannertype;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$this->assign($value);
return $this->fetch();
}
public function typeupdate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = model('banner_type')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/banner/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typeadd() {
return $this->fetch();
}
public function typecreate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$model = model('banner_type')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/banner/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedelete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('banner_type')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedeletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('banner_type')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/banner/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,255 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use app\common\controller\BaseController as Base;
class BaseController extends Base {
//当前用户
protected $user_id;
//当前是否管理员 0:否 1:是
protected $administrator = 0;
public function __construct() {
parent::__construct();
}
// 初始化
protected function _initialize() {
parent::_initialize();
$this->user_id = is_session_login('user');
if ($this->user_id <= 0) {
abort(redirect(url('/signin'))->remember());
}
$this->administrator = is_administrator();
$role_id = Session::get('user_auth.role_id');
$base_role = Loader::model('UserRole')->getRow(['id' => $role_id]);
$menu_list = $this->getMenuList($base_role['yesorno'], $base_role['rbac_acl'], $this->module, $this->controller, $this->action);
//echo "<pre>=="; print_r($menu_list); die;
$this->view->assign('menu_list', $menu_list);
$this->view->assign('user_id', $this->user_id);
$this->view->assign('administrator', $this->administrator);
$this->adminlang = $this->request->langset();
$this->view->assign('adminlang', $this->adminlang);
$this->country_code = session('cit') != '' ? strtoupper(session('cit')) : 'ZH';
$product_country_code = "products_".strtolower($this->country_code)."_color";
$productColor = config($product_country_code);
$this->view->assign('productColor', $productColor);
$this->view->assign('country_code', $this->country_code);
}
protected function getMenuList($yesorno, $act_list, $module, $controller, $action) {
//无需验证的操作
$uncheck = array('login', 'logout', 'register');
if (strpos($controller, 'ajax') !== false || in_array($action, $uncheck)) {
//所有ajax请求不需要验证权限
return '';
}
//$menu_list = $this->cacheGet('menu_list');
// $menu_list = [];
if (empty($menu_list)) {
$menu_list = Loader::model('Dept')->getMenu(['pid' => 0, 'stat' => 0,], ['sort' => 'asc', 'id' => 'desc']);
$this->cacheTag('DeptTag')->set('menu_list', $menu_list);
}
foreach($menu_list as $kn => $items) {
$menu_list[$kn]['ctrls'] = array();
if(sizeof($items)){
$ctrls = array();
foreach($items['child'] as $kd => $item) {
$ctrls[] = strtolower($item['ctrl']);
}
$menu_list[$kn]['ctrls'] = array_unique($ctrls);
}
}
//echo "<pre>++++++++++"; print_r($menu_list); die;
if ($act_list == 'all') {
if ($this->request->isAjax())
return '';
$menu = '<ul class="sidebar-menu" data-widget="tree">' . "\n";
$menu .=$this->getAllHtmlMenuList($menu_list, $menu_list, $module, $controller);
$menu .='</ul>' . "\n";
} else {
$access = $this->cacheGet($act_list);
// $access = [];
if (empty($access)) {
$access = Loader::model('AuthAccess')->getList(['id' => [$yesorno ? 'in' : 'not in', $act_list], 'module' => $module], null, ['access']);
$this->cacheTag('AuthAccessTag')->set($act_list, $access);
}
$role_right = '';
// $permission = [];
foreach ($access as $val) {
$role_right .= $val['access'] . ',';
}
$permission = explode(',', trim($role_right, ','));
$permission[] = 'Index@index';
//检查是否拥有此操作权限
if (!in_array($controller . '@' . $action, $permission)) {
$this->error(_lang_('no permission to operate') . '[' . ($controller . '@' . $action) . ']', url('/admin/Index/index'));
}
if ($this->request->isAjax())
return '';
//$this->getForMenuList($menu_list, $permission, $module);
$menu = '<ul class="sidebar-menu" data-widget="tree">' . "\n";
$menu .=$this->getHtmlMenuList($menu_list, $permission, $module, $controller);
$menu .='</ul>' . "\n";
}
return $menu;
}
protected function getHtmlMenuList($list, $permission, $module, $controller) {
// tiaoshi($permission);
// tiaoshi($module);
// tiaoshi($list[2]);die;
//
$menu = '';
if(is_array($list) && sizeof($list)) {
foreach ($list as $k1 => $list1) {
// tiaoshi($list[$k1]['child']);die;
switch ($list1['functype']) {
case 0:
if (!in_array($list1['url'], $permission)) {
continue;
}
if ($list1['hidden']) {
continue;
}
if ($list1['haschild'] && !empty($list1['child'])) {
$active = in_array(strtolower($controller), $list1['ctrls']) ? "active" : "";
$menu .= '<li class="treeview '.$active.'">
<a href="#">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>' . "\n";
$menu .= '<ul class="treeview-menu">';
$menu .= $this->getHtmlMenuList($list[$k1]['child'], $permission, $module, $controller);
$menu .= '</ul>' . "\n" . '</li>' . "\n";
} else {
$menu .= '<li>
<a href="#">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><small class="label pull-right bg-green">temp</small></span>
</a>
</li>' . "\n";
}
break;
case 1:
if (!in_array($list1['ctrl'] . '@' . $list1['action'], $permission)) {
continue;
}
if ($list1['hidden']) {
continue;
}
$menu .= '<li data-ctrl="' . $list1['ctrl'] . '" data-action="' . $list1['action'] . '">
<a href="' . url($list1['url']) . '">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>
</li>' . "\n";
break;
case 2:
if (!in_array($list1['url'], $permission)) {
continue;
}
if ($list1['hidden']) {
continue;
}
$menu .= '<li>
<a href="' . $list1['url'] . '">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>
</li>';
break;
default:
continue;
break;
}
}
return $menu;
}
}
protected function getAllHtmlMenuList(&$list, &$permission, $module, $controller) {
$menu = '';
foreach ($list as $k1 => $list1) {
switch ($list1['functype']) {
case 0:
if ($list1['hidden']) {
continue;
}
if ($list1['haschild'] && !empty($list1['child'])) {
$active = in_array(strtolower($controller), $list1['ctrls']) ? "active" : "";
$menu .= '<li class="treeview '.$active.'">
<a href="#">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>' . "\n";
$menu .= '<ul class="treeview-menu">';
$menu .=$this->getAllHtmlMenuList($list[$k1]['child'], $permission, $module, $controller);
$menu .= '</ul>' . "\n" . '</li>' . "\n";
} else {
$menu .= '<li>
<a href="#">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><small class="label pull-right bg-green">temp</small></span>
</a>
</li>' . "\n";
}
break;
case 1:
if ($list1['hidden']) {
continue;
}
$menu .= '<li data-ctrl="' . $list1['ctrl'] . '" data-action="' . $list1['action'] . '">
<a href="' . url($list1['url']) . '">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>
</li>' . "\n";
break;
case 2:
if ($list1['hidden']) {
continue;
}
$menu .= '<li>
<a href="' . $list1['url'] . '">
<i class="' . $list1['icon'] . '"></i> <span>' . $list1['name'] . '</span>
<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
</a>
</li>';
break;
default:
continue;
break;
}
}
return $menu;
}
}

236
app/admin/controller/Blog.php Executable file
View File

@@ -0,0 +1,236 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Blog extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$agent = Db('blog');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in', '0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['title'] = ['like', "%$data[name]%"];
$search['title'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['public_time'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['public_time'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['public_time'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['public_time'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
//echo "_________";
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['public_time'], ['<=', $time]);
}
}
// echo "<pre>";print_r($arg_where);die;
//$where = ['stat'=>0];
//$where = [];
$list = $agent->where($arg_where)->select();
//echo "<pre>==".$agent->getlastsql();die;
$count = count($list);
$list = $agent->where($arg_where)->paginate(20,$count);
$page = $list->render();
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);;
return $this->fetch();
}
public function add(){
return $this->fetch();
}
public function creat(){
$data = $_POST;
$data['stat'] = 0;
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
if($data['public_time'] == '') {
$data['public_time'] = date("Y-m-d H:i:s");
}
$data['add_time'] = date("Y-m-d H:i:s");
$validaterule = ['title' => 'require', 'visit_count' => 'number|between:0,2147483647',];
$validatemsg = ['title.require' => '名称不能为空', 'visit_count.between' => '浏览量不能为空',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$adent = Db('blog');
$inster = $adent->insert($data);
if($inster){
return $this->success('添加成功');
}else{
return $this->error('添加失败');
}
}
public function edit($id = 0) {
$id = intval($id);
$where = ['id '=>$id];
$agent = Db('blog');
$data = $agent->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$adent = Db('blog');
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$inster = $adent->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
//2021-05-29 申邵 控制blog更新保存
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['title' => 'require'];
$validatemsg = ['title.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$update_data = [
'id' => $data['id'],
'title' => $data['title'],
'content' => $data['content'],
'icon' => $data['icon'],
'h5_icon' => $data['h5_icon'],
'visit_count' => $data['visit_count'],
'is_top' => $data['is_top'],
'public_time' => $data['public_time'],
'seo_title' => $data['seo_title'],
'seo_description' => $data['seo_description'],
'seo_keyword' => $data['seo_keyword']
];
//echo "<pre>=="; print_r($data);die;
$blog = Db('blog');
$model = $blog->update($update_data);
//$model = model('blog')->updateRow($update_data);
return $this->redirect(url('/admin/blog/lists'));
}
return $this->error(Lang::get('incorrect operation'));
}
//2021-05-29 申邵 控制blog删除
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('blog')->deleteRow($id);
//echo "<pre>====="; print_r($result);die;
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('blog')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//2021-05-29 申邵 控制置顶是否启用
public function toggletop() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('blog')->updateRow(['id' => $id, 'is_top' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//2021-05-29 申邵 控制状态是否启用
public function toggleshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('blog')->updateRow(['id' => $id, 'stat' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

138
app/admin/controller/Bulk.php Executable file
View File

@@ -0,0 +1,138 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Bulk extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$bulk = Db('bulk');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['first_name|last_name|interested|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $bulk->where($arg_where)->select();
$count = count($list);
$list = $bulk->where($arg_where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
public function edit(){
$where = ['id '=>$_GET['id'],'stat'=>0];
$bulk = Db('bulk');
$data = $bulk->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$adent = Db('bulk');
$inster = $adent->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$bulk = Db('bulk');
$data = $bulk->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制删除
public function delete($id = 0) {
//echo "<pre>====="; print_r($id);die;
$id = intval($id);
if ($id > 0) {
$result = model('bulk')->deleteRow($id);
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/bulk/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('bulk')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/bulk/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class BulkInquiry extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$BulkInquiry = Db('bulk_inquiry');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['first_name']) && $data['first_name'] != ''){
$arg_where['first_name|last_name|interest|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $BulkInquiry->where($arg_where)->select();
$count = count($list);
$list = $BulkInquiry->where($arg_where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
public function edit(){
$where = ['id '=>$_GET['id'],'stat'=>0];
$BulkInquiry = Db('bulk_inquiry');
$data = $BulkInquiry->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$BulkInquiry = Db('bulk_inquiry');
$inster = $BulkInquiry->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$BulkInquiry = Db('bulk_inquiry');
$data = $BulkInquiry->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制删除
public function delete($id = 0) {
//echo "<pre>====="; print_r($id);die;
$id = intval($id);
if ($id > 0) {
$result = model('bulk_inquiry')->deleteRow($id);
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/bulk_inquiry/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('bulk_inquiry')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/bulk_inquiry/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

210
app/admin/controller/Country.php Executable file
View File

@@ -0,0 +1,210 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-12-10
* Time: 13:48
*/
namespace app\admin\controller;
use think\Session;
use think\Lang;
class Country extends BaseController
{
public function index(){
// session_start();
$ct= session('cit',$_GET['cit']);
$ct = session('cit');
if($ct){
$this->success('修改成功');
}else{
$this->error('修改国家失败');
}
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = null;
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['country_name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('country')->getLists($arg_where, ['sort' => 'asc'], null, 20);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add() {
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'country_name' => 'require',
'code' => 'require',
'url' => 'require',
'icon' => 'require',
'stat' => 'require',
'sort' => 'require|min:0|max:10000',
];
//验证提示信息
$validatemsg = [
'country_name.require' => '国家名不能为空',
'code.require' => '国家标记码不能为空',
'url.require' => '链接不能为空',
'icon.require' => '图标不能为空',
'sort.require' => '排序不能为空',
'stat.require' => '状态不能为空',
'sort.min' => '排序有效值为0-10000',
'sort.max' => '排序有效值为0-10000',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$insert_data = [
'country_name' => $data['country_name'],
'code' => $data['code'],
'url' => $data['url'],
'icon' => $data['icon'],
'sort' => $data['sort'],
'stat' => $data['stat'],
'create_time' => time(),
];
$model = model('country')->insertRow($insert_data);
if ($model && $model->getData('id')) {
$this->cacheDelete('country_list');
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$country = model('country')->where('id', $id)->find();
if (empty($country)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['country'] = $country;
$this->assign($value);
return $this->fetch();
} else {
return $this->fetch('add');
}
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'id' => 'require',
'country_name' => 'require',
'url' => 'require',
'code' => 'require',
'icon' => 'require',
'stat' => 'require',
'sort' => 'require|min:0|max:10000',
];
//验证提示信息
$validatemsg = [
'id.require' => 'id不能为空',
'country_name.require' => '国家名不能为空',
'code.require' => '国家标记码不能为空',
'url.require' => '链接不能为空',
'icon.require' => '图标不能为空',
'stat.require' => '状态不能为空',
'sort.require' => '排序不能为空',
'sort.min' => '排序有效值为0-10000',
'sort.max' => '排序有效值为0-10000',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$update_data = [
'id' => $data['id'],
'country_name' => $data['country_name'],
'code' => $data['code'],
'url' => $data['url'],
'icon' => $data['icon'],
'sort' => $data['sort'],
'stat' => $data['stat'],
'create_time' => time(),
];
$model = model('country')->updateRow($update_data);
if ($model && $model->getData('id')) {
if ($this->cacheHas('country_list')) {
$this->cacheDelete('country_list');
}
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('country')->where('id', $id)->update(['stat' => 1]);
if ($result) {
if ($this->cacheHas('country_list')) {
$this->cacheDelete('country_list');
}
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = model('country')->deleteRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

318
app/admin/controller/Customer.php Executable file
View File

@@ -0,0 +1,318 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use storage\Storage;
class Customer extends BaseController {
/**
* 后台用户首页
*/
public function index() {
$this->redirect('/admin/customer/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['c.firstname|c.email|c.telephone'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$arg_where['c.stat'] = ['in', '0,1'];
$dataObject = Loader::model('Customer')->getCustomerLists($arg_where, null, ['c.*', 'cg.name' => 'group_name'], 24);
//$groupOption = Loader::model('CustomerGroup')->getOption($customer['group_id'], ['stat' => 0, 'id' => ['neq', $this->user_id == 1 ? 0 : 1]], ['id' => 'desc'], ['id', 'name',], 50);
$value = [
//'groupOption' => $groupOption,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$customer = Loader::model('Customer')->getRow(['id' => $id, 'stat' => ['gt', '-1']]);
if (empty($customer)) {
return $this->error('数据有误,请检查后再操作');
}
$value['customer'] = $customer;
$groupOption = Loader::model('CustomerGroup')->getOption($customer['group_id'], ['stat' => 0], ['id' => 'desc'], ['id', 'name'], 50);
$value['groupOption'] = $groupOption;
$value['hangye'] = (array) Config::get('website_hangye');
$value['zhiye'] = (array) Config::get('website_zhiye');
$this->assign($value);
return $this->fetch();
} else {
return $this->fetch('add');
}
}
public function getajaxcustomer() {
$pid = $this->request->get('pid', 0);
$id = $this->request->get('id', 0);
$id = intval($id);
if ($this->request->isAjax() && $id > 0) {
$arg_where = array('stat' => 0);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'customername');
$customerOption = Loader::model('Customer')->getOption($id, $arg_where, $arg_order, $arg_field, 100);
return $this->result($customerOption, true, Lang::get('operation successed'));
}
return $this->error(Lang::get('incorrect operation'));
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'firstname' => 'require|length:2,32|unique:customer,firstname',
'email' => 'email|unique:customer,email',
'telephone' => ['regex' => '^1[345789]\d{9}$|^([0-9]{3,4}-?)?[0-9]{7,8}$', 'unique' => 'customer,telephone',],
'group_id' => 'require|between:0,2147483647',
];
//验证提示信息
$validatemsg = [
'firstname.require' => '用户名不能为空',
'firstname.unique' => '用户名已经被使用',
'firstname.length' => '用户名在2-32个字符之间',
'email.email' => '邮箱格式错误',
'email.unique' => '邮箱已经被使用',
'telephone.regex' => '电话格式错误',
'telephone.unique' => '电话已经被使用',
'group_id.require' => '用户组不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$set = [
'id' => $data['id'],
'email' => isset($data['email']) ? $data['email'] : '',
'telephone' => isset($data['telephone']) ? $data['telephone'] : '',
'firstname' => $data['firstname'],
'lastname' => isset($data['lastname']) ? $data['lastname'] : '',
'stat' => $data['stat'],
'safe' => $data['safe'],
'hangye' => isset($data['hangye']) ? $data['hangye'] : '',
'zhiye' => isset($data['zhiye']) ? $data['zhiye'] : '',
'sex' => isset($data['sex']) ? $data['sex'] : '',
'birthday' => isset($data['birthday']) ? $data['birthday'] : '',
'qq' => isset($data['qq']) ? $data['qq'] : '',
];
$model = Loader::model('Customer')->updateRow($set);
if ($model && $customer_id = $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function add() {
$groupOption = Loader::model('CustomerGroup')->getOption(0, ['stat' => 0, 'id' => ['neq', $this->user_id == 1 ? 0 : 1]], ['id' => 'desc'], ['id', 'name',], 50);
$value = ['groupOption' => $groupOption,];
$value['hangye'] = (array) Config::get('website_hangye');
$value['zhiye'] = (array) Config::get('website_zhiye');
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'firstname' => 'require|length:2,32|unique:customer,firstname',
'email' => 'email|unique:customer,email',
'telephone' => ['regex' => '^1[345789]\d{9}$|^([0-9]{3,4}-?)?[0-9]{7,8}$', 'unique' => 'customer,telephone',],
'password' => 'require|min:6|max:32',
'repassword' => 'require|confirm:password',
'group_id' => 'require|between:0,2147483647',
'item' => 'accepted',
];
//验证提示信息
$validatemsg = [
'firstname.require' => '用户名不能为空',
'firstname.unique' => '用户名已经被使用',
'firstname.length' => '用户名在2-32个字符之间',
'email.email' => '邮箱格式错误',
'email.unique' => '邮箱已经被使用',
'telephone.regex' => '电话格式错误',
'telephone.unique' => '电话已经被使用',
'password.require' => '密码不能为空',
'password.min' => '密码不少于6个字符',
'password.max' => '密码不多于32个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
'group_id.require' => '用户组不能为空',
'item' => '请确认服务条款',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$set = [
'group_id' => $data['group_id'],
'email' => isset($data['email']) ? $data['email'] : '',
'telephone' => isset($data['telephone']) ? $data['telephone'] : '',
'firstname' => $data['firstname'],
'lastname' => isset($data['lastname']) ? $data['lastname'] : '',
'newsletter' => isset($data['newsletter']) ? $data['newsletter'] : 0,
'salt' => $data['password'],
'password' => md5($data['password']),
'stat' => 0,
'safe' => 1,
'code' => '',
'item' => isset($data['item']) ? $data['item'] : 0,
'token' => isset($data['token']) ? $data['token'] : '',
'wishlist' => isset($data['wishlist']) ? $data['wishlist'] : '',
'ip' => isset($data['ip']) ? $data['ip'] : '',
'fenxiang' => isset($data['fenxiang']) ? $data['fenxiang'] : 0,
'guanzhu' => isset($data['guanzhu']) ? $data['guanzhu'] : 0,
'hangye' => isset($data['hangye']) ? $data['hangye'] : '',
'zhiye' => isset($data['zhiye']) ? $data['zhiye'] : '',
'sex' => isset($data['sex']) ? $data['sex'] : '',
'birthday' => isset($data['birthday']) ? $data['birthday'] : '',
'qq' => isset($data['qq']) ? $data['qq'] : '',
'addtime' => time(),
'custom_field' => json_encode([]),
];
$model = Loader::model('Customer')->insertRow($set);
if ($model && $customer_id = $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Customer')->deleteRow($id);
if ($result) {
if ($id == Session::get('customer_auth.id')) {
Session::delete('customer_auth', null);
Session::delete('customer_auth_sign', null);
}
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = Loader::model('Customer')->deleteRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Customer')->destroyCustomer($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = Loader::model('Customer')->destroyRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatepassword() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'id' => "require",
'newpassword' => 'require|min:6',
'repassword' => 'require|confirm:newpassword',
];
if (!$this->administrator) {
$validaterule['oldpassword'] = 'require|min:6';
}
//验证提示信息
$validatemsg = [
'id.require' => 'ID参数错误',
'oldpassword.require' => '密码不能为空',
'oldpassword.min' => '密码最低6个字符',
'newpassword.require' => '密码不能为空',
'newpassword.min' => '密码最低6个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$customersModel = Loader::model('Customer');
if (!$this->administrator) {
$customer = $customersModel->getCustomer($data['id'], ['password', 'salt', 'id']);
if (empty($customer)) {
return $this->error('数据有误,请检查后再操作');
}
if ($customer['password'] != md5($data['oldpassword'])) {
return $this->error('旧密码输入错误');
}
}
$model = $customersModel->updatePassword($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/customer/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class CustomerGroup extends BaseController {
public function index() {
$this->redirect('/admin/customer_group/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => 0);
$arg_order = array('id' => 'asc');
$arg_field = array('id', 'name', 'description', 'sort', 'stat');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name|description'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('CustomerGroup')->getPageList($arg_where, $arg_order, $arg_field, 12);
//$groupOption = $customer_groupModel->getCustomerGroupOption(0, $arg_where, $arg_order, ['id', 'name',], 50);
$value = [
//'groupOption' => $groupOption,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$customer_group = Loader::model('CustomerGroup')->getRow($id);
if (empty($customer_group)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['customer_group'] = $customer_group;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:customer_group,name', 'description' => 'require', 'agree' => 'require|eq:on',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.eq' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
$model = Loader::model('CustomerGroup')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/customer_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function add() {
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:customer_group,name', 'description' => 'require', 'agree' => 'require|eq:on',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.eq' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
//$data['siteid'] = $this->siteid;
$model = Loader::model('CustomerGroup')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/customer_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('CustomerGroup')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/customer_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('CustomerGroup')->deleteRows($ids);
//$result = Loader::model('Language')->updateRow(['stat' => -1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/customer_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
if ($this->request->isGet() && $id) {
$model = Loader::model('CustomerGroup')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/customer_group/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,196 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\DB;
use dbmanage\DbManage;
class Dbmanager extends BaseController {
protected $db;
protected $config = array(
'path' => './../databases/', //数据库备份路径
'part' => 20971520, //数据库备份卷大小
'compress' => 0, //数据库备份文件是否启用压缩 0不压缩 1 压缩
'level' => 9 //数据库备份文件压缩级别 1普通 4 一般 9最高
);
// 初始化
protected function _initialize() {
parent::_initialize();
$this->db = new DbManage($this->config);
$this->db->setTimeout(3600);
//ini_set('memory_limit', '512M');
}
public function index() {
return $this->fetch();
}
public function lists() {
$dbtables = $this->db->dataList();
$total = 0;
foreach ($dbtables as $k => $v) {
$dbtables[$k]['size'] = format_bytes($v['data_length'] + $v['index_length'], '', 2);
$total += $v['data_length'] + $v['index_length'];
}
$this->assign('list', $dbtables);
$this->assign('total', format_bytes($total, '', 2));
$this->assign('tablenums', count($dbtables));
return $this->fetch();
}
//备份数据库
public function backupall() {
if ($this->request->isAjax() && $this->request->isPost()) {
$dbtables = $this->db->dataList();
if (!empty($dbtables)) {//备份数据表
$file = ['name' => date('Ymd-His'), 'part' => 1]; //date('Ymd-His');
foreach ($dbtables as $table) {
$this->db->setFile($file)->backup($table['name'], 0);
}
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
}
}
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
//备份文件列表
public function databaklist() {
$this->assign('databaklist', $this->db->fileList());
return $this->fetch();
}
//还原数据库
public function restore() {
if ($this->request->isAjax()) {
$tablename = $this->request->post('tablename', '');
if (!empty($tablename)) {
$this->db->setFile(['1' => './../databases/' . date('Ymd-His', $tablename) . '-1.sql', 'name' => date('Ymd-His', $tablename), 'part' => 1])->import(0);
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
}
}
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
//备份下载
public function download() {
$tablename = $this->request->param('tablename', '');
if (!empty($tablename)) {
$this->db->downloadFile($tablename);
} else {
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
}
//删除备份文件
public function delete() {
$tablename = $this->request->param('tablename', '');
if (!empty($tablename)) {
$res = $this->db->delFile($tablename);
if ($res) {
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
} else {
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
} else {
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
}
//备份数据表
public function backup() {
if ($this->request->isAjax()) {
$tablename = $this->request->post('tablename', '');
if (!empty($tablename)) {
$file = ['name' => date('Ymd-His'), 'part' => 1]; //$tablename . date('Ymd-His');
$this->db->setFile($file)->backup($tablename, 0);
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
}
}
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
//数据表优化
public function optimize() {
$tables = $this->request->param('tablename');
if (!empty($tables)) {
$this->db->optimize($tables);
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
} else {
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
}
//数据表修复
public function repair() {
$tables = $this->request->param('tablename');
if (!empty($tables)) {
$this->db->repair($tables);
$this->success(Lang::get('operation successed'), url('admin/dbmanager/lists'));
} else {
$this->error(Lang::get('operation failed'), url('admin/dbmanager/lists'));
}
}
public function sqlquery() {
if ($this->request->isAjax() && $this->request->isPost()) {
$querytype = $this->request->post('querytype');
$sqlquery = $this->request->post('sqlquery');
$sqlquery = trim(stripslashes($sqlquery));
if (preg_match("#drop(.*)table#i", $sqlquery) || preg_match("#drop(.*)database#", $sqlquery) || empty($sqlquery)) {
$this->result([], 2, "<span style='font-size:10pt'>删除 '数据表' '数据库' 或空的语句不允许在这里执行。</span>");
}
//运行查询语句
if (preg_match("#^select #i", $sqlquery)) {
$sqlqueryarr = explode(';', $sqlquery);
if (!preg_match("#limit#i", $sqlqueryarr[0])) {
$sqlquery = $sqlqueryarr[0] . ' limit 0,10;';
} else {
$sqlquery = $sqlqueryarr[0];
}
$result = DbManage::connect()->query($sqlquery);
if (DbManage::connect()->getNumRows() <= 0) {
$this->result([], 2, "运行SQL{$sqlquery},无返回记录!");
} else {
$this->result($result, 1, "运行SQL{$sqlquery},共有" . DbManage::connect()->getNumRows() . "条记录最大返回10条");
}
}
if ($querytype == 2) {
//普通的SQL语句
$sqlquery = str_replace("\r", "", $sqlquery);
$sqls = preg_split("#;[ \t]{0,}\n#", $sqlquery);
$nerrCode = "";
$i = 0;
foreach ($sqls as $q) {
$q = trim($q);
if ($q == "") {
continue;
}
$number = DbManage::connect()->execute($q);
$errCode = trim(DbManage::connect()->getError());
if ($number) {
$i++;
} else {
$nerrCode .= "执行: <font color='blue'>$q</font> 出错,错误提示:<font color='red'>" . $errCode . "</font><br>";
}
}
$this->result([], 2, "成功执行{$i}个SQL语句<br><br>" . $nerrCode);
} else {
$sqlqueryarr = explode(';', $sqlquery);
$sqlquery = $sqlqueryarr[0];
//$dsql->ExecuteNoneQuery($sqlquery);
DbManage::connect()->execute($sqlquery);
$nerrCode = trim(DbManage::connect()->getError());
$this->result([], 2, "成功执行1个SQL语句<br><br>" . $nerrCode);
}
} else {
$this->result([], false, "数据有误,或者不存在,请检查后再操作");
}
}
}

228
app/admin/controller/Dept.php Executable file
View File

@@ -0,0 +1,228 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Dept extends BaseController {
public function index() {
$this->redirect('/admin/dept/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('*');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dept_list = Loader::model('Dept')->getDeptLists($arg_where, $arg_order, $arg_field, 20);
$value = ['list' => $dept_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0) {
$pid = isset($pid) ? (int) $pid : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$deptOptions = Loader::model('Dept')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['deptOptions' => $deptOptions, 'pid' => $pid];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'between:0,2147483647', 'module' => 'require', 'url' => 'require',];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$deptModel = Loader::model('Dept');
if (isset($data['pid']) && $data['pid']) {
$deptModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $deptModel->insertRow($data);
if ($model && $model->getData('id')) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$dept = Loader::model('Dept')->getRow($id);
if (!$dept && !is_array($dept)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['dept'] = $dept;
}
$pid = isset($dept['pid']) ? (int) $dept['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$deptOptions = Loader::model('Dept')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['deptOptions'] = $deptOptions;
$ctrlOption = get_ctrl_names($dept['module']);
$value['ctrlOption'] = $ctrlOption;
$actionOption = get_action_names($dept['ctrl'], 'app\\' . $dept['module'] . '\\controller\\');
$value['actionOption'] = $actionOption;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'between:0,2147483647', 'module' => 'require', 'url' => 'require',];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$deptModel = Loader::model('Dept');
$childIDArray = $deptModel->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
if (isset($data['pid']) && $data['pid']) {
$deptModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$oldpid = $data['oldpid'];
unset($data['oldpid']);
$model = $deptModel->updateRow($data);
if (isset($oldpid) && $oldpid) {
$oneObject = $deptModel->getRow(['pid' => $oldpid]);
if (!$oneObject) {
$deptModel::update(['haschild' => 0], ['id' => $oldpid, 'haschild' => 1]);
}
}
if ($model && $model->getData('id')) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = Loader::model('Dept')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Dept')->updateRow(['id' => $id, 'hidden' => !$flag]);
if ($model && $model->getData('id')) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Dept')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$categoryModel = Loader::model('Dept');
$category = $categoryModel->getRow(['id' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($category && $category['haschild']) {
$child = $categoryModel->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
}
$model = $categoryModel->deleteRow($id);
if ($model && $model->getData('id')) {
if ($category && $category['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $category['pid'], 'id' => ['neq', $category['id']]]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $category['pid'], 'haschild' => 1]);
}
}
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Dept')->deleteRow($id);
if ($result) {
$this->cacheClear('DeptTag');
return $this->success(Lang::get('operation successed'), url('/admin/dept/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

428
app/admin/controller/Download.php Executable file
View File

@@ -0,0 +1,428 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Download extends BaseController {
public function index() {
$this->redirect('/admin/download/lists');
}
private function init_search(&$search)
{
$search['name'] = '';
$search['tags'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists($cid = 0) {
$data = $this->request->param();
$cid = isset($data['cid']) ? intval($data['cid']) : 0;
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != '')
{
$arg_where['a.name'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if (isset($data['tags']) && $data['tags'] != '')
{
$arg_where['a.tags'] = ['like', "%$data[tags]%"];
$search['tags'] = $data['tags'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != ''))
{
// 时间有一个不为空就初始化
$arg_where['a.createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = strtotime($data['timebegin']);
array_push($arg_where['a.createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = strtotime($data['timeend']);
array_push($arg_where['a.createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
}
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if ($cid > 0) {
$arg_where['a.cid'] = $cid;
}
$dataObject = model('download')->getCategoryDownloadLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add($cid = 0) {
$cid = is_numeric($cid) ? intval($cid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$downloadpath = [];
$downloadpath64 = [];
if (isset($data['downloadpath'])) {
foreach ($data['downloadpath'] as $k => $dl) {
if (empty($dl) && empty($data['downloadpath64'][$k]))
break;
$downloadpath[] = $dl;
$downloadpath64[] = empty($data['downloadpath64'][$k]) ? '下载' : $data['downloadpath64'][$k];
}
}
$data['downloadpath'] = trim(implode(',', $downloadpath), ',');
$data['downloadpath64'] = trim(implode(',', $downloadpath64), ',');
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['user_id'] = $this->user_id;
$data['country_code'] = $this->country_code;
$model = model('download')->insertRow($data);
//$model = Loader::model('Download')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$download = model('download')->getRow($id);
if (empty($download)) {
return $this->error(lang::get('incorrect operation'));
}
$value['download'] = $download;
} else {
return $this->error(lang::get('incorrect operation'));
}
$cid = isset($download['cid']) ? $download['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$downloadpath = [];
$downloadpath64 = [];
if (isset($data['downloadpath'])) {
foreach ($data['downloadpath'] as $k => $dl) {
if (empty($dl) && empty($data['downloadpath64'][$k]))
break;
$downloadpath[] = $dl;
$downloadpath64[] = empty($data['downloadpath64'][$k]) ? '下载' : $data['downloadpath64'][$k];
}
}
$data['downloadpath'] = trim(implode(',', $downloadpath), ',');
$data['downloadpath64'] = trim(implode(',', $downloadpath64), ',');
$data['sort'] = intval($data['sort']);
$model = model('download')->updateRow($data);
//$model = Loader::model('Download')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('download')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleheadline() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'headline' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$download = model('download')->getRow($id);
if (empty($download)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['download'] = $download;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$cid = isset($download['cid']) ? $download['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function movecategory() {
$cid = $this->request->post('cid', 0);
$ids = $this->request->post('ids');
$cid = intval($cid);
if ($this->request->isPost() && $cid && $ids) {
$result = model('download')->updateRows(['cid' => $cid], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('download')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name|a.tags'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('download')->getRecycleLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recoverys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('download')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,304 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class DownloadCategory extends BaseController {
public function index() {
$this->redirect('/admin/download_category/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$category_list = model('download_category')->getCategoryLists($arg_where, $arg_order, $arg_field, 24);
$value = ['list' => $category_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions, 'pid' => $pid];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$categoryModel = model('download_category');
if (isset($data['pid']) && $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$categoryModel = model('download_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['download_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$categoryModel = model('download_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['download_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$oldpid = $data['oldpid'];
unset($data['oldpid']);
$categoryModel = model('download_category');
$childIDArray = $categoryModel->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
if (isset($data['pid']) && $data['pid'] && $oldpid != $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->updateRow($data);
if (isset($oldpid) && $oldpid && $oldpid != $data['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $oldpid]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $oldpid, 'haschild' => 1]);
}
}
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function subcolumn() {
$column = $this->request->get('subcolumn/s', '', 'urldecode');
$columns = explode(',', $column);
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$category_list = model('download_category')->getCategoryTree($arg_where, $arg_order, $arg_field, 20);
$value = ['list' => $category_list, 'columns' => $columns,];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function listcategory($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$categoryModel = model('download_category');
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = $categoryModel->getList($arg_where, $arg_order, $arg_field, 50);
$category_breadcrumb = $categoryModel->getBreadCrumb($pid);
$value = ['list' => $category_list, 'pid' => $pid, 'breadcrumb' => $category_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0) {
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = model('download_category')->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $category_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
if ($id && $sort < 2147483647) {
$model = model('download_category')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download_category')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download_category')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download_category')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$row = model('download_category')->getRow(['cid' => $id, 'stat' => 0], ['id', 'name']);
if ($row) {
return $this->error('此节点包含内容[ID:' . $row['id'] . '名称:' . $row['name'] . '],不能进行删除');
}
$categoryModel = model('download_category');
$category = $categoryModel->getRow(['id' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($category && $category['haschild']) {
$child = $categoryModel->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
}
if ($category && $category['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $category['pid'], 'id' => ['neq', $category['id']]]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $category['pid'], 'haschild' => 1]);
}
}
$result = $categoryModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

315
app/admin/controller/Flink.php Executable file
View File

@@ -0,0 +1,315 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Flink extends BaseController {
public function index() {
$this->redirect('/admin/flink/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['b.siteid' => $this->siteid];
$arg_order = ['b.id' => 'desc'];
$arg_field = ['b.*', 'bt.id' => 'typeid', 'bt.name' => 'typename'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['b.name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('Flink')->getFlinkLists($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add($typeid = 0) {
$typeid = is_numeric($typeid) ? intval($typeid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = Loader::model('FlinkType')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value = ['typeOption' => $typeOption];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['alt'] = empty($data['alt']) ? $data['name'] : $data['alt'];
$data['siteid'] = $this->siteid;
$model = Loader::model('Flink')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$flink = Loader::model('Flink')->getRow($id);
if (empty($flink)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['flink'] = $flink;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$typeid = isset($flink['typeid']) ? $flink['typeid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'pid', 'name');
$typeOption = Loader::model('FlinkType')->getOption($typeid, $arg_where, $arg_order, $arg_field, 100);
$value['typeOption'] = $typeOption;
$value['typeid'] = $typeid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'typeid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'typeid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$model = Loader::model('Flink')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($this->request->isGet() && $id) {
$model = Loader::model('Flink')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($this->request->isAjax() && $id) {
$model = Loader::model('Flink')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Flink')->deleteRow($id);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
//echo json_encode(['code' => false, 'msg' => print_r($in_ids, true)]);exit;
$result = Loader::model('Flink')->deleteRows($in_ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $in_ids) {
$result = Loader::model('Flink')->updateRow(['recommend' => 1], ['id' => ['in', $in_ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//类别
public function typelists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'name', 'description', 'createtime');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('FlinkType')->getPageList($arg_where, $arg_order, $arg_field);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function typeedit($id = 0) {
$id = intval($id);
if ($id > 0) {
$flinktype = Loader::model('FlinkType')->getRow($id);
if (empty($flinktype)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['flinktype'] = $flinktype;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$this->assign($value);
return $this->fetch();
}
public function typeupdate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = Loader::model('FlinkType')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/flink/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typeadd() {
return $this->fetch();
}
public function typecreate() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['siteid'] = $this->siteid;
$model = Loader::model('FlinkType')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/flink/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedelete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('FlinkType')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function typedeletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('FlinkType')->deleteRows($ids);
//$result = Loader::model('FlinkType')->updateRow(['stat' => -1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/flink/typelists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

211
app/admin/controller/Fq.php Executable file
View File

@@ -0,0 +1,211 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Fq extends BaseController {
public function index() {
$this->redirect('/admin/fq/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$arg_where['stat'] = 0;
$arg_where['country_code'] = $this->country_code;
$arg_order = ['sort' => 'asc', 'id' => 'desc'];
$dataObject = model('fq')->getPageList($arg_where, $arg_order);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add() {
$value = [];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
// dump($data);die;
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'name' => 'require',
'content' => 'require',
'picture' => 'require',
];
//验证提示信息
$validatemsg = [
'name.require' => '名称需要填写',
'content.require' => '内容需要填写',
'picture.require' => '图片需要填写',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['country_code'] = $this->country_code;
$insert_data = [
'name' => $data['name'],
'content' => $data['content'],
'picture' => $data['picture'],
'sort' => $data['sort'],
'is_home' => $data['is_home'],
'create_time' => time(),
'country_code' => $data['country_code'],
];
$model = model('fq')->insertRow($insert_data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/fq/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$fq = model('fq')->getRow($id);
if (empty($fq)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['fq'] = $fq;
} else {
return $this->error(Lang::get('incorrect operation'));
}
// tiaoshi($fq);die;
$value['id'] = $id;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'id' => 'require',
'name' => 'require',
'content' => 'require',
'picture' => 'require',
];
//验证提示信息
$validatemsg = [
'id.require' => 'id需要填写',
'name.require' => '名称需要填写',
'content.require' => '内容需要填写',
'picture.require' => '图片需要填写',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$update_data = [
'id' => $data['id'],
'name' => $data['name'],
'content' => $data['content'],
'picture' => $data['picture'],
'sort' => $data['sort'],
'is_home' => $data['is_home'],
];
$model = model('fq')->updateRow($update_data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/fq/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('incorrect operation'));
}
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 20000) {
$model = model('fq')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/fq/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatestate() {
$id = $this->request->param('id', 0);
$isHome = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('fq')->updateRow(['id' => $id, 'is_home' => $isHome]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/fq/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('fq')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('fq')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

124
app/admin/controller/Index.php Executable file
View File

@@ -0,0 +1,124 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class Index extends BaseController {
//class Index{
public function test01(){
$key = 'mochengTest1';
$fieldArr = array(
"id"=>"0",
"name"=>"1",
"age"=>"0",
"text"=>"1"
);
$zhArr = array(
"id"=>1,
"name"=>"我的名字",
"age"=>"19",
"text"=>"再来测试一个"
);
$unique = 7;
$enArr = array(
"id"=>$unique,
"name"=>"我的名字第二(enTest)",
"age"=>"199",
"text"=>"再来测试一个第二(enTest)"
);
$zhArr5 = array(
"id"=>$unique,
"name"=>"我的名字第3",
"age"=>"19",
"text"=>"再来测试一个第3"
);
$trans = new TransDb();
//struct 新增 过
$isTranToDb = $trans->addStruct($key, $fieldArr, $zhArr, true);
dump( $isTranToDb); //返回多少条翻译
// //total 新增 过
// dump($key);
// dump($zhArr5);
// $isAdd = $trans->addStructTotal($key, $zhArr5, true);
// dump($isAdd);
// echo "结构体列表";
// $allStruct = $trans->selectAllStruct();
// dump($allStruct);
//total up 过
//$trans->upStructTotal($allStruct[0], 'en', $enArr, false);
//total 查询 过
// $totalList = $trans->selectStructTotal($allStruct[0],$unique, 'en');
//没有 $unique 返回 $unique集合
//$trans->delStructTotal($allStruct[0],$unique);
// $totalList = $totalList = $trans->selectStructTotal($key);
// dump($totalList);
//total 删除 过
// foreach ($totalList as $value){
// $trans->delStructTotal($key,1);
// }
$delStruct =$trans->delStruct($key);
dump($delStruct);
exit;
}
public function index() {
//$mysql = db()->query('select version() as version');
$mysql = isset($mysql[0]['version']) ? $mysql[0]['version'] : '未知';
//系统信息
$data = array(
'OPERATING_SYSTEM' => PHP_OS, //操作系统
'OPERATING_ENVIRONMENT' => $_SERVER["SERVER_SOFTWARE"], //运行环境
'PHP_VERSION' => PHP_VERSION, //PHP版本
'MYSQL_VERSION' => $mysql, //MYSQL版本
'GD_VERSION' => function_exists('gd_info') ? (gd_info()['GD Version']) : '未知',
'SAFE_MODE' => ini_get('safe_mode') ? 'YES' : 'NO',
'ALLOW_URL_FOPEN' => ini_get("allow_url_fopen") ? 'YES' : 'NO',
'ZLIB' => function_exists('gzclose') ? 'YES' : 'NO',
'TIMEZONE' => function_exists("date_default_timezone_get") ? date_default_timezone_get() : '未知',
'PHP_CURL' => function_exists('curl_init') ? 'YES' : 'NO',
'IPv4_ADDRESS' => gethostbyname($_SERVER['SERVER_NAME']),
'HTTP_HOST' => $_SERVER['HTTP_HOST'],
'UPLOAD_MAX_FILESIZE' => ini_get('upload_max_filesize'), //上传附件限制
'MAX_EXECUTION_TIME' => ini_get('max_execution_time') . 's', //执行时间限制
//'SET_TIME_LIMIT' => function_exists("set_time_limit") ? 'YES' : 'NO',
'MEMORY_LIMIT' => ini_get('memory_limit'),
//'Register_Globals' => ini_get("register_globals") ? 'On' : 'Off',
//'Magic_Quotes_Gpc' => ini_get("magic_quotes_gpc") ? 'On' : 'Off',
'SELF_VERSION' => '1.0.0',
);
$value['sys_info'] = $data;
$this->assign($value);
return $this->fetch();
}
public function lang($adminlang = 'cn') {
//$adminlang = $adminlang ? $adminlang : $this->request->param('adminlang');
switch ($adminlang) {
case 'cn':
cookie('think_adminvar', 'zh-cn');
break;
case 'en':
cookie('think_adminvar', 'en-us');
break;
//其它语言
}
return $this->success(Lang::get('operation successed'));
}
public function home() {
return $this->fetch();
}
public function clear_cache() {
$this->cacheClear();
return $this->success(Lang::get('operation successed'));
}
}

138
app/admin/controller/Inquiry.php Executable file
View File

@@ -0,0 +1,138 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Inquiry extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$inquiry = Db('inquiry');
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['first_name|last_name|inquiry|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $inquiry->where($arg_where)->select();
$count = count($list);
$list = $inquiry->where($arg_where)->paginate(20,$count);
$page = $list->render();
//dump($page);die;
$this->assign('search',$search);
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
public function edit(){
$where = ['id '=>$_GET['id'],'stat'=>0];
$inquiry = Db('inquiry');
$data = $inquiry->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
public function save(){
$data = $_POST;
$inquiry = Db('inquiry');
$inster = $inquiry->insert($data);
if($inster){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$inquiry = Db('Inquiry');
$data = $inquiry->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制删除
public function delete($id = 0) {
//echo "<pre>====="; print_r($id);die;
$id = intval($id);
if ($id > 0) {
$result = model('Inquiry')->deleteRow($id);
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/Inquiry/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('Inquiry')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/Inquiry/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

737
app/admin/controller/Job.php Executable file
View File

@@ -0,0 +1,737 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Db;
class Job extends BaseController {
public function index() {
$this->redirect('/admin/job/lists');
}
public function lists() {
$where = null;
$order = ['stat' => 'asc', 'sort' => 'asc', 'publish_time' => 'desc'];
$field = ['id', 'department', 'job_name', 'count', 'job_address', 'experience_requirement', 'education', 'sort', 'publish_time', 'end_time', 'stat'];
$dataObject = model('job')->getJobLists($where, $order, $field, 12);
// tiaoshi($dataObject);die;
$value = [
'page' => $dataObject->render(),
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
];
// tiaoshi($dataObject->items());die;
$this->assign($value);
return $this->fetch();
}
public function add() {
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
// tiaoshi($id);die;
if ($id > 0) {
$job = model('job')->find($id);
if (!$job && !is_array($job)) {
return $this->error('数据有误,请检查后再操作');
}
$value['job'] = $job;
} else {
return $this->error('数据有误,请检查后再操作');
}
// dump($job);die;
$this->assign($value);
return $this->fetch();
}
public function qiyong()
{
$id = $this->request->param('id');
if ($id < 0)
{
return $this->json(-1, 'id错误');
}
$result = model('job')->where(['id' => $id])->update(['stat' => 0]);
if (!$result)
{
return $this->json(-2, '修改失败');
}
return $this->json(200, 'ok');
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('job')->where(['id' => $id])->update(['stat' => 1]);
// echo \think\Db::table('job')->getLastSql();die;
// tiaoshi($result);die;
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/job/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'department' => 'require',
'job_name' => 'require',
'count' => 'require',
'experience_requirement' => 'require',
'education' => 'require',
'job_address' => 'require',
'salary' => 'require',
'workfare' => 'require',
'job_responsibility' => 'require',
'job_requirement' => 'require',
'publish_time' => 'require',
'end_time' => 'require',
];
$validatemsg = [
'job_name.require' => '岗位名称不能为空',
'department.require' => '部门不能为空',
'count.require' => '招聘人数不能为空',
'experience_requirement.require' => '经验要求不能为空',
'education.require' => '学历要求不能为空',
'job_address.require' => '工作地址不能为空',
'salary.require' => '薪资待遇不能为空',
'workfare.require' => '福利不能为空',
'job_responsibility.require' => '岗位职责不能为空',
'job_requirement.require' => '岗位要求不能为空',
// 'cid.between' => '所属上级值无效',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
return $this->error($valid_result);
}
$sort = intval($data['sort']);
$insert_data = [
'department' => $data['department'],
'job_name' => $data['job_name'],
'count' => $data['count'],
'experience_requirement' => $data['experience_requirement'],
'education' => $data['education'],
'job_address' => $data['job_address'],
'salary' => $data['salary'],
'workfare' => $data['workfare'],
'sort' => $sort,
'publish_time' => date('Y-m-d', strtotime($data['publish_time'])),
'end_time' => date('Y-m-d', strtotime($data['end_time'])),
'job_responsibility' => $data['job_responsibility'],
'job_requirement' => $data['job_requirement'],
'stat' => 0,
'create_time' => date('Y-m-d H:i:s', time()),
];
$result = model('job')->insertRow($insert_data);
if (empty($result)) {
$this->error('新增失败');
}
$this->success('新增成功', url('/admin/job/lists'));
}
}
public function update() {
$data = $this->request->post();
if (empty($data) || !is_array($data) || !$data['id']) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'department' => 'require',
'job_name' => 'require',
'count' => 'require',
'experience_requirement' => 'require',
'education' => 'require',
'job_address' => 'require',
'salary' => 'require',
'workfare' => 'require',
'job_responsibility' => 'require',
'job_requirement' => 'require',
'publish_time' => 'require',
'end_time' => 'require',
];
$validatemsg = [
'job_name.require' => '岗位名称不能为空',
'department.require' => '部门不能为空',
'count.require' => '招聘人数不能为空',
'experience_requirement.require' => '经验要求不能为空',
'education.require' => '学历要求不能为空',
'job_address.require' => '工作地址不能为空',
'salary.require' => '薪资待遇不能为空',
'workfare.require' => '福利不能为空',
'job_responsibility.require' => '岗位职责不能为空',
'job_requirement.require' => '岗位要求不能为空',
// 'cid.between' => '所属上级值无效',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
return $this->error($valid_result);
}
$sort = intval($data['sort']);
$update_data = [
'department' => $data['department'],
'job_name' => $data['job_name'],
'count' => $data['count'],
'experience_requirement' => $data['experience_requirement'],
'education' => $data['education'],
'job_address' => $data['job_address'],
'salary' => $data['salary'],
'workfare' => $data['workfare'],
'sort' => $sort,
'publish_time' => date('Y-m-d', strtotime($data['publish_time'])),
'end_time' => date('Y-m-d', strtotime($data['end_time'])),
'job_responsibility' => $data['job_responsibility'],
'job_requirement' => $data['job_requirement'],
'stat' => 0,
// 'create_time' => date('Y-m-d H:i:s', time()),
];
$result = model('job')->where(['id' => $data['id']])->update($update_data);
if (empty($result)) {
$this->error('更新失败');
}
$this->success('更新成功', url('/admin/job/lists'));
}
public function content() {
$aid = $this->request->param('id', 0);
$aid = intval($aid);
if ($aid > 0) {
$addproduct = Loader::model('ProductAddition')->getRow(['aid' => $aid], ['id', 'aid', 'content']);
if (empty($addproduct)) {
return $this->error(Lang::get('incorrect operation'));
}
$value = [
'addproduct' => $addproduct,
];
$this->assign($value);
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
return $this->fetch();
}
return $this->error(Lang::get('incorrect operation'));
}
public function modallists() {
$inputid = $this->request->param('inputid', '', 'urldecode');
$titleid = $this->request->param('titleid', '', 'urldecode');
$callback = $this->request->param('callback', '', 'urldecode');
$filter_name = $this->request->param('filter_name', '', 'urldecode');
$arg_where = array('stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'name', 'item_number', 'tags', 'list_bk_img',);
if (!empty($filter_name)) {
$arg_where['brand_id'] = ['like', '%' . trim($filter_name) . '%'];
//$arg_where['brand_id'] = ['like', '%' . trim($filter_name) . '%'];
}
Config::set('url_common_param', true);
Config::set('paginate.query', array_filter(['inputid' => $inputid, 'titleid' => $titleid, 'callback' => $callback, 'filter_name' => $filter_name])); //分页参数
$dataObject = city(session('cit'),'Product')->getPageList($arg_where, $arg_order, $arg_field, 12, false);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'total' => $dataObject->total(),
'inputid' => $inputid,
'titleid' => $titleid,
'callback' => $callback,
'filter_name' => $filter_name,
];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort <= 9999) {
$model = model('job')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisnew() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'isnew' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleonsale() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$result = city(session('cit'),'Product')->updateRow(['id' => $id, 'is_onsale' => $flag]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$product = city(session('cit'),'Product')->getRow($id);
if (empty($product)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product'] = $product;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$value['addproduct'] = Loader::model('ProductAddition')->getRow(['aid' => $id]);
$cid = isset($product['cid']) ? $product['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = city(session('cit'),'ProductCategory')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$arg_where = array('stat' => 0);
$arg_order = array('id' => 'asc');
$arg_field = array('id', 'name');
$brandOption = Loader::model('Brand')->getOption($product['brand_id'], $arg_where, $arg_order, $arg_field, 100);
$typeOption = Loader::model('AttributeType')->getOption($product['type_id'], $arg_where, $arg_order, $arg_field, 100);
$supplierOption = Loader::model('Supplier')->getOption($product['supplier_id'], $arg_where, $arg_order, $arg_field, 100);
$value['supplierOption'] = $supplierOption;
$value['typeOption'] = $typeOption;
$value['brandOption'] = $brandOption;
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function movecategory() {
$cid = $this->request->post('cid', 0);
$ids = $this->request->post('ids');
$cid = intval($cid);
if ($this->request->isPost() && $cid && $ids) {
$result = city(session('cit'),'Product')->updateRows(['cid' => $cid], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = city(session('cit'),'Product')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name|a.description'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = city(session('cit'),'Product')->getRecycleLists($arg_where, $arg_order, $arg_field, 12);
$argc_where = array('pid' => 0, 'stat' => 0);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = city(session('cit'),'ProductCategory')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recoverys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = city(session('cit'),'Product')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = city(session('cit'),'Product')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = city(session('cit'),'Product')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function cont(){
$data = $_POST;
$id = $data['product'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
foreach ($id as $where ){
$where = ['a.id'=>$where,
'a.stat'=>0
];
$result = city(session('cit'),'product')->getProductLists($where,$arg_order,$arg_field,12);
}
dump($result);die;
$this->assign($result);
return $this->fetch('product/add');
}
public function productreated(){
$inputid = $this->request->param('inputid', '', 'urldecode');
$titleid = $this->request->param('titleid', '', 'urldecode');
$callback = $this->request->param('callback', '', 'urldecode');
$filter_name = $this->request->param('filter_name', '', 'urldecode');
$arg_where = array('stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'name', 'item_number', 'tags', 'picture',);
if (!empty($filter_name)) {
$arg_where['name'] = ['like', '%' . trim($filter_name) . '%'];
}
Config::set('url_common_param', true);
Config::set('paginate.query', array_filter(['inputid' => $inputid, 'titleid' => $titleid, 'callback' => $callback, 'filter_name' => $filter_name])); //分页参数
$dataObject = city(session('cit'),'Product')->getPageList($arg_where, $arg_order, $arg_field, 12, false);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'total' => $dataObject->total(),
'inputid' => $inputid,
'titleid' => $titleid,
'callback' => $callback,
'filter_name' => $filter_name,
];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
return $this->fetch();
}
public function chickbrandid($id){
$where = ['brand_id'=>$id];
$product = city(session('cit'),'Product')->where($where)->find();
if($product){
echo '产品型号已经存在,无需重新添加';
}
exit;
}
public function export() {
$arg_where = ['a.stat' => 0, 'a.siteid' => $this->siteid];
$data = $this->request->param();
if (isset($data['name']) && $data['name']) {
$arg_where['a.name'] = ['like', '%' . $data['name'] . '%'];
$search['name'] = $data['name'];
} else {
$search['name'] = '';
}
if (isset($data['cid']) && $data['cid']) {
$childIDArray = city(session('cit'),'product_category')->getChildIDArray($data['cid']);
$arg_where['a.cid'] = count($childIDArray) == 1 ? $data['cid'] : ['in', $childIDArray];
$search['cid'] = $data['cid'];
} else {
$search['cid'] = 0;
}
if (isset($data['tags']) && $data['tags']) {
$arg_where['a.tags'] = ['like', '%' . $data['tags'] . '%'];
$search['tags'] = $data['tags'];
} else {
$search['tags'] = '';
}
$search['timebegin'] = isset($data['timebegin']) ? strtotime($data['timebegin']) : 0;
$search['timeend'] = isset($data['timeend']) ? strtotime($data['timeend']) : 0;
if ($search['timeend'] - $search['timebegin'] > 0) {
$arg_where['a.createtime'] = ['between', [$search['timebegin'], $search['timeend']]];
} else {
if ($search['timebegin'] > 0 && empty($search['timeend'])) {
$arg_where['a.createtime'] = ['gt', $search['timebegin']];
}
}
if (!empty($data['field'])) {
$fields = $data['field'];
} else {
$fields = array('id' => 'ID', 'brand_id' => '产品型号', 'url' => '产品链接', 'cid' => '所属分类', 'name' => '产品名称', 'shortname' => '副标题', 'recommend' => '是否推荐', 'ishot' => '是否热门', 'multi_color' => '是否有多颜色', 'list_bk_img' => '是否有一级列表图' , 'is_list2' => '是否有二级列表图', 'url_tm' => '天猫链接', 'url_jd' => '京东链接', 'seo_title' => 'SEO标题', 'seo_keyword' => 'SEO关键词', 'seo_description' => 'SEO描述', 'product_view' => '产品参数', 'related_product' => '关联产品', 'driver' => '是否有驱动', 'is_comment' => '是否有评论', 'createtime' => '发布时间');
}
$argc_where = array('pid' => 0, 'stat' => 0);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = city(session('cit'),'product_category')->getCategoryOptions($search['cid'], $argc_where, $argc_order, $argc_field, 100);
if (empty($data['submit'])) {
$value = ['categoryOptions' => $categoryOptions, 'fields' => $fields];
$this->assign($value);
return $this->fetch();
}
$arg_order = ['c.sort' => 'asc', 'c.id' => 'asc'];
$arg_field = array_map(function($value) {return 'a.' . $value;}, array_keys($fields));
$arg_field['c.id'] = 'categoryid';
$arg_field['c.name'] = 'categoryname';
$arg_field['c.pid'] = 'pid';
set_time_limit(36000);
ini_set('memory_limit', '512M');
$total = city(session('cit'),'product')->getExportSearchProductLists($arg_where, $arg_order, null, true);
$page_size = 1000;
$totalpage = ceil($total / $page_size);
$sheet_size = 5 * $page_size;
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
Loader::import('phpexcel.Classes.PHPExcel', EXTEND_PATH);
Loader::import('phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
$objPHPExcel = new \PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Call of Duty")
->setLastModifiedBy("Call of Duty")
->setTitle("Office 2007 XLSX Cod Document")
->setSubject("Office 2007 XLSX Cod Document")
->setDescription("Cod document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Cod result file");
$page = 0;
$sheet = 0;
do {
$start_index = $page * $page_size;
$arg_order = ['a.cid' => 'asc', 'a.id' => 'asc'];
$datainfo = city(session('cit'),'product')->getExportSearchProductLists($arg_where, $arg_order, [$start_index, $page_size], false, $arg_field);
if (!empty($datainfo)) {
if (($start_index % $sheet_size) == 0) {
if ($sheet) {
$objPHPExcel->createSheet();
}
$sheet++;
$i = 0;
foreach ($fields as $key => $value) {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . '1', $value);
$i++;
}
$objPHPExcel->getActiveSheet()->setTitle('sheet' . $sheet);
$index = 1;
}
foreach ($datainfo as $value) {
if (isset($value['cid'])) {
$value->data('cid', $value['categoryname']);
}
if (isset($value['list_bk_img']) && $value['list_bk_img'] != '') {
$value->data('list_bk_img', 1);
} else {
$value->data('list_bk_img', 0);
}
if (isset($value['createtime'])) {
$value->data('createtime', date('Y-m-d H:i:s', $value['createtime']));
}
if (isset($value['related_product'])) {
$value->data('related_product', $value['related_product']);
}
if (isset($value['product_view'])) {
$value->data('product_view', json_encode(unserialize($value['product_view']), JSON_UNESCAPED_UNICODE));
}
if (isset($value['driver'])) {
$value->data('driver', $value['driver']);
}
$index++;
$i = 0;
foreach ($fields as $key => $field) {
if ($key == 'picture') {
$image = '.' . $this->request->root() . $value['picture'];
if (@fopen($image, 'r')) {
$objDrawing = new \PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($image);
$objDrawing->setHeight(50);
$objDrawing->setWidth(50);
$objDrawing->setCoordinates($cellName[$i] . $index);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
}
} else {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . $index, $value[$key]);
}
$i++;
}
}
usleep(10000);
}
$page++;
if ($page > 650) {
break;
}
} while ($page < $totalpage);
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client's web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
}

240
app/admin/controller/Msgform.php Executable file
View File

@@ -0,0 +1,240 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Msgform extends BaseController {
public function index() {
$this->redirect('/admin/msgform/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['stat' => ['eq', 0]];
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['cname|content'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('Msgform')->getPageList($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function modalview($id) {
$id = intval($id);
if ($id > 0) {
$msgform = Loader::model('Msgform')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
$value['msgform'] = $msgform;
}
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
return $this->fetch();
}
public function view($id) {
$id = intval($id);
if ($id > 0) {
$msgform = Loader::model('Msgform')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
if (empty($msgform)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['msgform'] = $msgform;
}
if($msgform['attachment']) {
$attachment = json_decode($msgform['attachment'], true);
}
else{
$attachment = '';
}
$this->assign('attachment',$attachment);
//echo "<pre>=="; print_r($attachment); die;
//echo "<pre>=="; print_r($msgform['attachment']);die;
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'name' => 'require',
'tel' => ['regex' => '^1[345789]\d{9}$|^([0-9]{3,4}-?)?[0-9]{7,8}$'],
//'content' => 'require',
];
$validatemsg = [
'pid.require' => 'p不能为空',
'tel.regex' => '电话格式错误',
//'content.require' => '内容不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$addtime = date('Y-m-d H:i:s');
$set = [
'name' => isset($data['name']) ? $data['name'] : 'Name',
'type' => isset($data['type']) ? $data['type'] : 'Article',
'msg' => isset($data['msg']) ? $data['msg'] : '',
'content' => isset($data['content']) ? $data['content'] : '',
'content' => $data['content'],
'addtime' => $addtime,
];
$model = Loader::model('Msgform')->insertRow($set);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id) {
$id = intval($id);
if ($id > 0) {
$msgform = Loader::model('Msgform')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
if (empty($msgform)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['msgform'] = $msgform;
}
$value['feedback_type'] = (array) Config::get('website_feedback_type');
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'id' => 'require',
];
$validatemsg = [
'id.require' => 'id不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = Loader::model('Msgform')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
if ($this->request->isGet() && $id) {
$model = Loader::model('Msgform')->updateRow(['id' => $id, 'stat' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Msgform')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function checked() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('Msgform')->updateRow(['display' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function unchecked() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('Msgform')->updateRow(['display' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Msgform')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('Msgform')->deleteRows($ids);
//$result = Loader::model('Msgform')->updateRow(['stat' => -1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/msgform/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,554 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Cookie;
use think\Config;
class Navigation extends BaseController {
private function init_search(&$search)
{
$search['name'] = '';
$search['tags'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function index() {
$this->redirect('/admin/navigation/lists');
}
public function lists() {
$data = $this->request->param();
$arg_where = ['country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != '')
{
$arg_where['name'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if (isset($data['nav_type']) && $data['nav_type'] != '')
{
$arg_where['nav_type'] =$data['nav_type'];
$search['nav_type'] = $data['nav_type'];
}
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
// 获取数据
$where1 = $arg_where;
$where1['pid'] = 0;
$dataObject = model('navigation')->getNavigationLists($where1, $arg_order, $arg_field);
//echo model('navigation')->getLastSql(); die;
$dataList = self::NavigationHandle(self::navDataHandling($dataObject->items()));
$result = [];
if(!empty($dataList))
{
// 子级数据组合
$where2 = $arg_where;
$where2['pid'] = ['in', array_column($dataList, 'id')];
//echo "<pre>==="; print_r($where2);
$data2Object = model('navigation')->getNavigationLists($where2, $arg_order, $arg_field);
$items_data = self::NavigationHandle(self::navDataHandling($data2Object->items()));
//echo model('navigation')->getLastSql(); die;
$items_group = [];
if(!empty($items_data))
{
foreach($items_data as $tv)
{
$items_group[$tv['pid']][] = $tv;
}
}
// 数据集合
if(!empty($items_group))
{
foreach($dataList as $dv)
{
if(array_key_exists($dv['id'], $items_group))
{
$dv['is_sub_data'] = 1;
$result[] = $dv;
$result = array_merge($result, $items_group[$dv['id']]);
} else {
$result[] = $dv;
}
}
} else {
$result = $dataList;
}
}
$dataType = config('common_data_type_list');
//echo model('navigation')->getLastSql();
//echo "<pre>==="; print_r($result);die;
$value = [
'list' => $result,
'page' => $dataObject->render(),
'search' => $search,
'dataType' => $dataType,
];
$this->assign($value);
//获取文章数据
return $this->fetch();
}
public function add() {
$value['typeOption'] = config('common_nav_type_list');
$value['dataType'] = config('common_data_type_list');
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'nav_type' => 'require',];
$validatemsg = ['name.require' => '名称不能为空', 'nav_type.require' => '导航类型不能为空',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['pid'] = empty($data['pid']) ? 0 : $data['pid'];
$data['url'] = empty($data['url']) ? '' : $data['url'];
$data['value'] = empty($data['value']) ? '' : $data['value'];
$data['sort'] = intval($data['sort']);
$data['stat'] = empty($data['stat']) ? 0 : $data['stat'];
$data['is_new_window_open'] = $data['is_new_window_open'];
$data['country_code'] = $this->country_code;
$model = model('navigation')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/navigation/lists'));
} else {
return $this->error(Lang::get('Operation Failed'));
}
}
return $this->error(Lang::get('Incorrect Operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$navigation = model('navigation')->where('id', $id)->find();
//echo model('navigation')->getLastSql();
//echo "<pre>=="; print_r($navigation); die;
if (empty($navigation)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['navigation'] = $navigation;
$value['nav_header_pid_list'] = self::LevelOneNav(['nav_type'=>$navigation['nav_type']]);
} else {
return $this->error(Lang::get('incorrect operation'));
}
$value['typeOption'] = config('common_nav_type_list');
$value['dataType'] = config('common_data_type_list');
//获取分类层级目录
$argc_where = array('isshow' => 1, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'sort', 'description', 'isshow', 'recommend', 'picture', 'icon', 'image', 'm_icon', 'unique_id'];
$categoryList = Loader::model('product_category')->getList($argc_where,$argc_order, $argc_field);
$value['categoryList'] = $this->list_to_tree($categoryList);
//获取文章
$article_list = self::articleCategoryListContent();
$value['article_list'] = $article_list;
//echo "<pre>=="; print_r($value['categoryList']); die;
$value['blog_list'] = self::blogListContent();
$this->assign($value);
return $this->fetch();
}
protected function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'child', $root = 0) {
//header('content-type:text/html;charset=utf-8;');
// 创建Tree
$tree = [];
if (is_array($list)) {
// 创建基于主键的数组引用
$refer = [];
foreach ($list as $key => $data) {
$list[$key] = $data->toArray();
$refer[$data[$pk]] = & $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] = & $list[$key];
} else {
if (isset($refer[$parentId])) {
$parent = & $refer[$parentId];
$parent[$child][] = & $list[$key];
}
}
}
}
return $tree;
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['id' => 'require', 'name' => 'require', 'nav_type' => 'require',];
$validatemsg = ['id.require' => 'ID不能为空','name.require' => '名称不能为空', 'nav_type.require' => '导航类型不能为空',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['pid'] = empty($data['pid']) ? '0' : $data['pid'];
$data['url'] = empty($data['url']) ? '' : $data['url'];
$data['sort'] = intval($data['sort']);
$data['stat'] = empty($data['stat']) ? 0 : $data['stat'];
$data['is_new_window_open'] = $data['is_new_window_open'];
$data['country_code'] = $this->country_code;
$data['id'] = $data['id'];
$model = model('navigation')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/navigation/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($this->request->isAjax() && $id) {
$model = model('navigation')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/navigation/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('navigation')->deleteRow($id);
if ($model) {
return $this->success(Lang::get('operation successed'), url('/admin/navigation/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
$result = model('navigation')->deleteRows($in_ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/navigation/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Navigation')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/Navigation/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
//获取导航数据
public function navDataAll($nav_type=''){
$argc_where = array('pid' => 0, 'is_show' => 1,'nav_type'=>$nav_type);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'url', 'name', 'stat', 'sort','value','data_type','is_new_window_open');
$NavOptions = model('Navigation')->getCategoryOptions($argc_where, $argc_order, $argc_field, 100);
// 获取导航数据
$data = self::navDataHandling($NavOptions);
if(!empty($data))
{
// 获取子数据
$items = [];
$ids = array_column($data, 'id');
$new_where = array('pid' => $ids, 'is_show' => 1,'nav_type'=>$nav_type);
$itemsOptions = model('Navigation')->getCategoryOptions($new_where, $argc_order, $argc_field, 100);
$items_data = self::navDataHandling($itemsOptions);
if(!empty($items_data))
{
foreach($items_data as $it)
{
$items[$it['pid']][] = $it;
}
}
// 数据组合
foreach($data as &$v)
{
$v['items'] = isset($items[$v['id']]) ? $items[$v['id']] : [];
}
}
// 没数据则赋空数组值
if(empty($data))
{
$data = [];
}
// 缓存
$this->cacheSet('cache_home_nav_'.$nav_type.'_key', $data, 3600);
return $data;
}
//导航数据处理
public function navDataHandling($data = []){
if(!empty($data) && is_array($data))
{
foreach($data as $k=>$v)
{
// url处理
switch($v['data_type'])
{
// 文章
case 'article':
$v['url'] = url_rewrite('index/article/index', ['id'=>$v['value']]);
break;
// 博客
case 'article':
$v['url'] = url_rewrite('index/blog/index', ['id'=>$v['value']]);
break;
// 自定义页面=>'customview':
// 商品分类
case 'goods_category':
$v['url'] = url_rewrite('index/search/index', ['cid'=>$v['value']]);
break;
}
$data[$k] = $v;
}
}
return $data;
}
//获取分类和所有文章
public function articleCategoryListContent(){
$arg_where = array('pid' => 0, 'isshow' => 1, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$data = model('article_category')->getCategoryLists($arg_where, $arg_order, $arg_field, 24);
if(!empty($data))
{
foreach($data as &$v)
{
$new_where = array('a.country_code' => $this->country_code);
$new_order = ['a.createtime' => 'desc', 'a.sort' => 'asc', 'a.id' => 'desc'];
$new_field = ['a.id,a.cid,a.name,a.sort,a.ishot,a.recommend,a.picture'];
if ($v['id'] > 0) {
$arg_where['a.cid'] = $v['id'];
}
$items = model('article')->getArticleLists($new_where, $new_order, $new_field, 12);
//echo model('article')->getLastSql(); die;
if(!empty($items))
{
foreach($items as &$vs)
{
// url
$vs['url'] = url_rewrite('article', array('id' => $vs['id']));
}
}
$v['items'] = $items;
}
}
return $data;
}
//获取博客和所有内容
public function blogListContent(){
$arg_where = array('stat' => 1, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('public_time' => 'desc', 'id' => 'asc');
$arg_field = array('id', 'title', 'icon', 'h5_icon', 'is_top', 'public_time', 'add_time');
$data = model('blog')->getBlotLists($arg_where, $arg_order, $arg_field, 24);
if(!empty($data))
{
foreach($data as &$v)
{
$v['url'] = url_rewrite('blog', array('id' => $v['id']));
}
}
return $data;
}
//导航数据处理
public function NavigationHandle($data=[]){
if(!empty($data) && is_array($data))
{
$nav_type_list = config('common_nav_type_list');
foreach($data as &$v)
{
// 数据类型
$v['data_type_text'] = isset($nav_type_list[$v['data_type']]) ? $nav_type_list[$v['data_type']] : '';
// 时间
$v['add_time'] = date('Y-m-d H:i:s', $v['createtime']);
$v['upd_time'] = empty($v['updtime']) ? '' : date('Y-m-d H:i:s', $v['updtime']);
}
}
return $data;
}
//获取一级导航列表
public function LevelOneNav($params = [])
{
if(empty($params['nav_type']))
{
return [];
}
$arg_where = array('pid' => 0, 'stat' => 0, 'nav_type' => $params['nav_type'], 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('*');
$data = model('navigation')->getNavigationLists($arg_where, $arg_order, $arg_field, 24);
return $data;
//return $this->json(200, 'ok', $data);
}
public function fetchLevelOneNav()
{
if ($this->request->isPost()) {
$nav_type = $this->request->post('nav_type');
$arg_where = array('pid' => 0, 'stat' => 0, 'nav_type' => $nav_type, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('*');
$data = model('navigation')->getNavigationLists($arg_where, $arg_order, $arg_field, 24);
//echo "<pre>=="; print_r($data);die;
return $this->json(200, 'ok', $data);
}
}
public function checkType($params = []){
if ($this->request->isPost()) {
$nav_type = $this->request->post('nav_type');
$nav_value = $this->request->post('value');
$value['nav_type'] = $nav_type;
$value['value'] = $nav_value;
if($nav_type == 'article'){
//获取文章
$article_list = self::articleCategoryListContent();
$value['list'] = $article_list;
}elseif($nav_type == 'blog'){
$value['list'] = self::blogListContent();
}
elseif($nav_type == 'goods_category'){
//获取分类层级目录
$argc_where = array('isshow' => 1, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'sort', 'description', 'isshow', 'recommend', 'picture', 'icon', 'image', 'm_icon', 'unique_id'];
$categoryList = Loader::model('product_category')->getList($argc_where,$argc_order, $argc_field);
$value['list'] = $this->list_to_tree($categoryList);
}
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use app\common\controller\BaseController as Base;
class Passport extends Base {
public function index() {
if (is_session_login('user')) {
return $this->redirect(url('/admin/index/index'));
}
$this->view->engine->layout(false);
return $this->view->fetch();
}
/**
* 用户登录
* @param string $username 用户名
* @param string $password 密码
* @param string $verify 验证码
*/
public function login() {
if (is_session_login('user')) {
return $this->redirect(url('/admin/index/index'));
}
// $this->request->isPost() || $this->error(Lang::get('illegal request')); //判断是否ajax登录
$data = $this->request->post();
$this->verify_check($data['captcha'], 'authcode') || $this->json(-1, '验证码有误');
// $validaterule = [
// //'captcha|验证码' => 'captcha:authcode',
// //管理员登陆字段验证
// 'admin_username|' . Lang::get('user name') => 'require|min:2',
// 'admin_password|' . Lang::get('user password') => 'require|min:6',
// ];
// // 数据验证
// $valid_result = $this->validate($data, $validaterule);
// if (true !== $valid_result) {
// // 验证失败 输出错误信息
// return $this->error($valid_result);
// }
// $validate = new Validate($validaterule);
// $res = $validate->check($data);
// if (!$res) {
// // 验证失败 输出错误信息
// $this->error($validate->getError());
// }
$result = Loader::model('User')->login($data['admin_username'], $data['admin_password']);
// tiaoshi($result);die;
$result['status'] !== true && $this->json(-2, $result['msg']); //登录失败
return $result['id'] ? $this->json(200, '登录成功') : $this->json(-3, Lang::get('unknown error'));
}
/**
* 退出登录
*/
public function logout() {
if (!is_session_login('user')) {
return $this->redirect(url('/signin'));
}
$content = '用户' . Session::get('user_auth.username') . '(' . Session::get('user_auth.id') . ')退出登录时间:' . date('Y-m-d H:i:s');
action_log('退出登录', $content, Session::get('user_auth.id'));
//Loader::model('User')->logout();
Session::delete('user_auth', null);
Session::delete('user_auth_sign', null);
return $this->success(Lang::get('success'), url('/signin'));
}
public function register() {
if (is_session_login('user')) {
return $this->redirect(url('/admin/index/index'));
}
$this->view->engine->layout(false);
return $this->view->fetch();
}
public function forgetpwd() {
if (is_session_login('user')) {
return $this->redirect(url('/admin/index/index'));
}
$this->view->engine->layout(false);
return $this->view->fetch();
}
}

287
app/admin/controller/Pinglun.php Executable file
View File

@@ -0,0 +1,287 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Pinglun extends BaseController {
public function index() {
$this->redirect('/admin/pinglun/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['stat' => ['eq', 0]];
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['cname|content'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
//$dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
$dataObject = model('pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0) {
// if ($pid > 0) {
// $pinglun = Loader::model('Pinglun')->getRow(['id' => $pid, 'stat' => ['gt', -1]]);
// if (empty($pinglun)) {
// return $this->error(Lang::get('incorrect operation'));
// }
// $value['pinglun'] = $pinglun;
// }
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function reply($id = 0) {
if ($id > 0) {
$pinglun = model('pinglun')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
if (empty($pinglun)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['pinglun'] = $pinglun;
}
$this->assign($value);
return $this->fetch();
}
public function addreply() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'content_id' => 'require',
'typeid' => 'require',
'content' => 'require',
];
$validatemsg = [
'content_id.require' => '不能为空',
'typeid.require' => '不能为空',
'content.require' => '不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$addtime = date('Y-m-d H:i:s');
$txarr = [1, 2, 3, 4, 5];
shuffle($txarr);
$set = [
'customer_id' => 1,
'cname' => isset($data['cname']) ? $data['cname'] : session('user_auth.username'),
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
'pid' => isset($data['pid']) ? $data['pid'] : 0,
'content_id' => isset($data['content_id']) ? $data['content_id'] : 0,
'content' => $data['content'],
'tx' => $txarr[0],
'display' => $data['display'],
'createtime' => $addtime,
'lasttime' => $addtime,
];
$model = model('pinglun')->insertRow($set);
if ($model && $model->getData('id')) {
//(isset($set['content_id']) && isset($set['typeid'])) ? Loader::model($set['typeid'])->where(['id' => $set['content_id']])->setInc('commentcount') : '';
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'content_id' => 'require',
'typeid' => 'require',
'content' => 'require',
];
$validatemsg = [
'content_id.require' => '不能为空',
'typeid.require' => '不能为空',
'content.require' => '不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$addtime = date('Y-m-d H:i:s');
$txarr = [1, 2, 3, 4, 5];
shuffle($txarr);
$set = [
'customer_id' => 1,
'cname' => isset($data['cname']) ? $data['cname'] : session('user_auth.username'),
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
'pid' => isset($data['pid']) ? $data['pid'] : 0,
'content_id' => isset($data['content_id']) ? $data['content_id'] : 0,
'content' => $data['content'],
'tx' => $txarr[0],
'display' => $data['display'],
'createtime' => $addtime,
'lasttime' => $addtime,
];
$model = model('pinglun')->insertRow($set);
if ($model && $model->getData('id')) {
(isset($set['content_id']) && isset($set['typeid'])) ? Loader::model($set['typeid'])->where(['id' => $set['content_id']])->setInc('commentcount') : '';
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id) {
$id = intval($id);
if ($id > 0) {
$pinglun = model('pinglun')->getRow(['id' => $id, 'stat' => ['gt', -1]]);
if (empty($pinglun)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['pinglun'] = $pinglun;
}
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'id' => 'require',
'content' => 'require',
];
$validatemsg = [
'id.require' => 'id不能为空',
'content.require' => '不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = model('pinglun')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
if ($this->request->isGet() && $id) {
$model = model('pinglun')->updateRow(['id' => $id, 'stat' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('pinglun')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function checked() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('pinglun')->updateRow(['display' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function unchecked() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = city(session('cit'),'Pinglun')->updateRow(['display' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('pinglun')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$ids = explode(",", $ids);
// $result = city(session('cit'),'Pinglun')->deleteRows($ids);
$result = model('tbpl')->where('id', 'in', $ids)->update(['stat' => -1]);
// echo \think\Db::table('tbpl')->getLastSql();die;
// tiaoshi($result);die;
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/pinglun/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

2603
app/admin/controller/Product.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,442 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class ProductCategory extends BaseController
{
public function index()
{
$this->redirect('/admin/product_category/lists');
}
public function lists()
{
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$category_list = model('product_category')->getCategoryList($arg_where, $arg_order, $arg_field, 500);
} else {
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$search['skeyword'] = '';
$category_list = model('product_category')->getCategoryLists($arg_where, $arg_order, $arg_field, 24);
}
$value = ['list' => $category_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0)
{
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('product_category')->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$sql = "SELECT max(unique_id) as unique_id FROM cod_product_category WHERE country_code='$this->country_code'";
$max_unique_id = \think\db::query($sql)[0]['unique_id'];
$value = ['categoryOptions' => $categoryOptions, 'pid' => $pid, 'max_unique_id' => $max_unique_id];
$this->assign($value);
return $this->fetch();
}
public function create()
{
if ($this->request->isPost()) {
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if ($this->country_code != 'ZH' && $data['unique_id'] == '') {
return $this->error(Lang::get('唯一id不能为空'));
}
if ($this->country_code != 'ZH') {
$cate = model('product_category')->where(['stat' => 0, 'unique_id' => $data['unique_id'], 'country_code' => $this->country_code])->find();
if (!empty($cate))
return $this->error(Lang::get('唯一id不能重复'));
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$categoryModel = model('product_category');
if (isset($data['pid']) && $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->insertGetId($data);
if ($model) {
$this->cacheClear('ProductCategoryTag');
return $this->redirect(url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function create_unique_code()
{
die;
$countries = ['US', 'ID', 'TH', 'VN'];
foreach ($countries as $key => $value) {
$i = 1;
$cate_list = model('product_category')->where(['stat' => 0, 'country_code' => $value])->order(['id' => 'asc'])->limit(110)->select();
foreach ($cate_list as $k => $v) {
model('product_category')->where(['id' => $v['id']])->update(['unique_id' => $i]);
$i++;
}
}
echo 'ok';
}
public function copy($id = 0)
{
$categoryModel = model('product_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (!$category && !is_array($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0)
{
$categoryModel = model('product_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
if (false !== strpos($category['name'], '"')) {
$category['name'] = htmlspecialchars($category['name']);
}
$value['product_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$sql = "SELECT max(unique_id) as unique_id FROM cod_product_category WHERE country_code='$this->country_code'";
$max_unique_id = \think\db::query($sql)[0]['unique_id'];
$tcoCategory = \think\Db::name('product_tco_category')->where('id', '>', 0)->where('country_code', '=', $this->country_code)->select();
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$value['max_unique_id'] = $max_unique_id;
$value['tcoCategoryOptions'] = $this->buildTcoCategoryToTree($tcoCategory, 0, 0, $id);
$this->assign($value);
return $this->fetch();
}
private function buildTcoCategoryToTree($data, $pid = 0, $level = 0, $value = 0)
{
$options = '';
foreach ($data as $val) {
if ($val['tco_pid'] == $pid) {
$emsp = str_repeat("&emsp;", $level);
if ($value != 0 && $val['category_id'] == $value) {
$options .= '<option value="' . $val['id'] . '" selected="selected">' . $emsp . $val['name'] . '</option>' . "\n";
} else {
$options .= '<option value="' . $val['id'] . '">' . $emsp . $val['name'] . '</option>' . "\n";
}
$sub_options = $this->buildTcoCategoryToTree($data, $val['tco_id'], $level + 1, $value);
if (!empty($sub_options)) {
$options .= $sub_options;
}
}
}
return $options;
}
public function update()
{
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$product_category = model('product_category')->find($data['id']);
if (empty($product_category))
return $this->error(Lang::get('产品分类不存在'));
if ($this->country_code != 'ZH' && $data['unique_id'] == '')
return $this->error(Lang::get('唯一id不能为空'));
if ($this->country_code != 'ZH') {
$cate = model('product_category')->where(['stat' => 0, 'unique_id' => $data['unique_id'], 'country_code' => $this->country_code])->find();
if (!empty($cate) && $cate['id'] != $product_category['id'])
return $this->error(Lang::get('唯一id不能重复'));
}
$data['sort'] = intval($data['sort']);
$oldpid = $data['oldpid'];
unset($data['oldpid']);
$categoryModel = model('product_category');
$childIDArray = $categoryModel->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
if (isset($data['pid']) && $data['pid'] && $oldpid != $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$tcoCategory = !empty($data['tco_category']) ? $data['tco_category'] : null;
unset($data['tco_category']);
$model = $categoryModel->updateRow($data);
if (isset($oldpid) && $oldpid && $oldpid != $data['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $oldpid]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $oldpid, 'haschild' => 1]);
}
}
if (!empty($tcoCategory)) {
\think\Db::name('product_tco_category')->where('id', 'in', $tcoCategory)->update(['category_id' => $data['id']]);
}
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->redirect(url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function subcolumn()
{
$column = $this->request->get('subcolumn/s', '', 'urldecode');
$columns = explode(',', $column);
$categoryModel = model('product_category');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$category_list = $categoryModel->getCategoryTree($arg_where, $arg_order, $arg_field, 240);
$value = ['list' => $category_list, 'columns' => $columns,];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function catcolumn()
{
$column = $this->request->get('catcolumn/s', '', 'urldecode');
$inputid = $this->request->param('inputid', '', 'urldecode');
$titleid = $this->request->param('titleid', '', 'urldecode');
$callback = $this->request->param('callback', '', 'urldecode');
$columns = explode(',', $column);
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$category_list = model('product_category')->getCategoryTree($arg_where, $arg_order, $arg_field, 240);
$value = [
'list' => $category_list,
'columns' => $columns,
'inputid' => $inputid,
'titleid' => $titleid,
'callback' => $callback,
];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function listcategory($pid = 0)
{
$pid = is_numeric($pid) ? intval($pid) : 0;
$categoryModel = model('product_category');
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = $categoryModel->getList($arg_where, $arg_order, $arg_field, 50);
$category_breadcrumb = $categoryModel->getBreadCrumb($pid);
$value = ['list' => $category_list, 'pid' => $pid, 'breadcrumb' => $category_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0)
{
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
//$pid = is_numeric($pid) ? intval($pid) : 0;
$categoryModel = model('product_category');
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = $categoryModel->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $category_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function updatesort()
{
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id && $sort < 2147483647) {
$model = model('product_category')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat()
{
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_category')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow()
{
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_category')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend()
{
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_category')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0)
{
$id = intval($id);
if ($id > 0) {
$row = model('product')->getRow(['cid' => $id, 'stat' => 0], ['id', 'name']);
if ($row) {
return $this->error('此节点包含内容[ID:' . $row['id'] . '名称:' . $row['name'] . '],不能进行删除');
}
$categoryModel = model('product_category');
$category = $categoryModel->getRow(['id' => $id, 'stat' => 0]);
if ($category && $category['haschild']) {
$child = $categoryModel->getRow(['pid' => $id, 'stat' => 0]);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
}
if ($category && $category['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $category['pid'], 'id' => ['neq', $category['id']]]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $category['pid'], 'haschild' => 1]);
}
}
$result = $categoryModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-12-19
* Time: 16:57
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Db;
class ProductCont extends BaseController
{
public function index(){
print_r($_POST);die;
}
}

View File

@@ -0,0 +1,322 @@
<?php
namespace app\admin\controller;
use PHPExcel;
use think\Db;
use think\Loader;
use think\Validate;
Loader::import('phpexcel.Classes.PHPExcel', EXTEND_PATH);
Loader::import('phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
class ProductPurchaseLinks extends BaseController
{
/**
* 列表
*/
public function index()
{
$list = Db::name('product_purchase_links')->alias('links')
->field([
'links.id',
'links.product_id',
'product.name',
'product.brand_id' => 'spu',
'links.platform_id',
'links.link',
'product.is_show'
])
->join('product', 'product.id=links.product_id')
->where(function ($query) {
$query->where('product.is_show', '=', 0)
->where('links.country_code', '=', $this->country_code);
if (request()->has('skeyword')) {
$query->where(function ($q) {
$keyword = request()->get('skeyword');
$q->where('product.brand_id', 'like', '%' . $keyword . '%')
->whereOr('product.name', 'like', '%' . $keyword . '%');
});
}
})
->order('links.id', 'sort')
->group('links.product_id')
->paginate(10);
$data = [];
foreach ($list as $val) {
if (empty($data[$val['spu']])) {
$val['rowspan'] = 1;
$data[$val['spu']] = $val;
}
}
if (!$list->isEmpty()) {
$others = Db::name('product_purchase_links')->alias('links')
->field([
'links.id',
'product.name',
'product.brand_id' => 'spu',
'links.platform_id',
'links.link',
'product.is_show'
])
->join('product', 'product.id=links.product_id')
->where('links.country_code', '=', $this->country_code)
->where('links.id', 'not in', array_column($list->items(), 'id'))
->where('links.product_id', 'in', array_column($list->items(), 'product_id'))
->select();
foreach ($others as $val) {
if (!empty($data[$val['spu']]) && $data[$val['spu']]['id'] != $val['id']) {
if (empty($data[$val['spu']]['children'])) {
$data[$val['spu']]['children'] = [];
}
$data[$val['spu']]['children'][] = $val;
$data[$val['spu']]['rowspan'] = count($data[$val['spu']]['children']) + 1;
}
}
}
$this->assign('list', $data);
$this->assign('page', $list->render());
$platforms = Db::name('product_purchase_link_platforms')
->field(['id', 'platform'])
->where('id', '>', 0)
->where('country_code', '=', $this->country_code)
->select();
$this->assign('platforms', $platforms);
return $this->fetch();
}
/**
* 更新
*/
public function update()
{
$post = request()->post();
if (empty($post['id'])) {
return $this->error('请确认操作数据');
}
$id = $post['id'];
unset($post['id']);
// 验证链接
if (!empty($post['link'])) {
$validate = new Validate([
'link' => 'url|max:255'
], [
'link.url' => '连接地址格式错误',
'link.max' => '连接址不能超过255个字符'
]);
if (!$validate->check($post)) {
return $this->error($validate->getError());
}
}
// 验证平台
if (!empty($post['platform_id'])) {
$proid = Db::name('product_purchase_links')->where('id', '=', $id)->value('product_id');
$exists = Db::name('product_purchase_links')
->where('product_id', '=', $proid)
->where('platform_id', '=', $post['platform_id'])
->value('id');
if ($exists) {
$platform = Db::name('product_purchase_link_platforms')
->where('id', '=', $post['platform_id'])
->value('platform');
return $this->error(sprintf('该型号已存在【%s】链接', $platform));
}
}
$ret = Db::name('product_purchase_links')->where('id', '=', $id)->update($post);
if (!$ret) {
return $this->error('操作失败');
}
return $this->success('操作成功');
}
/**
* 导入
*/
public function import()
{
ini_set('max_execution_time', '0');
$file = request()->file('file');
if ($file->getSize() > 20 * 1024 * 1024) {
return $this->error('上传文件不能超过20M');
}
// 创建读取器
$reader = \PHPExcel_IOFactory::createReader('Excel2007');
// 加载表格
$spreadsheet = $reader->load($file->getRealPath());
// 读取sheet
$sheet = $spreadsheet->getSheet(0);
$rows = $sheet->getHighestRow(); //总行数
$xlsx = [];
for($i = 2; $i <= $rows; $i++) {
// $xlsx[行号] = 数据
$xlsx[$i] = [
'spu' => $sheet->getCellByColumnAndRow(0, $i)->getValue(),
'platform' => $sheet->getCellByColumnAndRow(1, $i)->getValue(),
'link' => $sheet->getCellByColumnAndRow(2, $i)->getValue(),
];
}
// 错误提示
$errors = [];
// 验证成功数据
$valid_data = [];
// 购买平台数据
$platforms = Db::name('product_purchase_link_platforms')
->where('id', '>', 0)
->where('country_code', '=', $this->country_code)
->column('id', 'platform');
$xlsx_chunks = array_chunk($xlsx, 500, true);
// 分批次验证 spu
foreach ($xlsx_chunks as $x) {
$spus = array_column($x, 'spu');
$products = Db::name('product')
->where('brand_id', 'in', $spus)
->where('country_code', '=', $this->country_code)
->column('id', 'brand_id');
if (empty($products)) {
$errors[] = sprintf('第%s行, 型号不存在', implode(',', array_keys($x)));
continue;
}
$items = [];
foreach ($x as $k => $v) {
if (empty($products[$v['spu']])) {
$errors[] = sprintf('第%s行, 型号不存在', $k);
continue;
}
if (empty($platforms[$v['platform']])) {
$errors[] = sprintf("第%s行, 平台名称错误", $k);
continue;
}
if (
!empty($v['link']) &&
!\think\helper\Str::startsWith($v['link'], 'http://') &&
!\think\helper\Str::startsWith($v['link'], 'https://')
) {
$errors[] = sprintf("第%s行, 链接地址格式错误", $k);
continue;
}
$items[] = [
'product_id' => $products[$v['spu']],
'platform_id' => $platforms[$v['platform']],
'link' => $v['link'],
'country_code' => $this->country_code,
];
}
if (!empty($items)) {
$valid_data[] = $items;
}
}
if (!empty($valid_data)) {
// 组装 SQL
$sql = 'REPLACE INTO `cod_product_purchase_links`(`id`, `product_id`, `platform_id`, `link`, `country_code`) VALUES ';
foreach ($valid_data as $val) {
$proids = array_column($val, 'product_id');
$links = Db::name('product_purchase_links')
->field(['id', 'product_id', 'platform_id'])
->where('product_id', 'in', $proids)
->where('country_code', '=', $this->country_code)
->select();
if (!empty($links)) {
$links_mapping = [];
foreach ($links as $l) {
$links_mapping[$l['product_id'] . "_" . $l['platform_id']] = $l['id'];
}
}
foreach ($val as $v) {
$id = null;
if (!empty($links_mapping[$v['product_id'] . '_' . $v['platform_id']])) {
$id = $links_mapping[$v['product_id'] . '_' . $v['platform_id']];
}
$sql .= sprintf('(%d, %d, %d, "%s", "%s"),', $id, $v['product_id'], $v['platform_id'], $v['link'], $v['country_code']);
}
}
Db::execute(\think\helper\Str::substr($sql, 0, \think\helper\Str::length($sql) - 1));
}
if (!empty($errors)) {
return $this->error(implode(";\n", $errors));
}
return $this->success('导入成功');
}
/**
* 导出
*/
public function export()
{
$data = Db::name('product_purchase_links')->alias('links')
->field([
'product.brand_id' => 'spu',
'platforms.platform',
'links.link'
])
->join('product_purchase_link_platforms platforms', 'platforms.id=links.platform_id')
->join('product', 'product.id=links.product_id')
->where(function($query) {
$query->where('product.is_show', '=', 0)->where('links.country_code', '=', $this->country_code);
if (request()->has('skeyword')) {
$query->where(function ($q) {
$keyword = request()->get('skeyword');
$q->where('product.brand_id', 'like', '%' . $keyword . '%')
->whereOr('product.name', 'like', '%' . $keyword . '%');
});
}
})
->select();
$excel = new \PHPExcel();
$excel->getProperties()->setCreator("Call of Duty")
->setLastModifiedBy("Call of Duty")
->setTitle("Office 2007 XLSX Cod Document")
->setSubject("Office 2007 XLSX Cod Document")
->setDescription("Cod document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Cod result file");
$excel->createSheet();
$excel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, '型号');
$excel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, '平台');
$excel->getActiveSheet()->setCellValueByColumnAndRow(2, 1, '链接');
foreach ($data as $i => $v) {
$excel->getActiveSheet()->setCellValueByColumnAndRow(0, $i + 2, $v['spu']);
$excel->getActiveSheet()->setCellValueByColumnAndRow(1, $i + 2, $v['platform']);
$excel->getActiveSheet()->setCellValueByColumnAndRow(2, $i + 2, $v['link']);
}
ob_end_clean();
$writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream"); //文件流
header("Content-Type: application/download"); //下载文件
header('Content-Disposition: attachment;filename="' . date('YmdHis') . '-' . $this->country_code . '.xlsx"');
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //上一次修改时间
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache"); //不缓存页面
$writer->save('php://output');
exit;
}
}

View File

@@ -0,0 +1,258 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class ProductSeries extends BaseController {
public function index() {
$this->redirect('/admin/product_series/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort', 'isshow', 'picture');
if (!empty($skeyword)) {
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$series_list = model('product_series')->getSeriesList($arg_where, $arg_order, $arg_field, 500);
} else {
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$search['skeyword'] = '';
$series_list = model('product_series')->getSeriesList($arg_where, $arg_order, $arg_field, 24);
}
$value = ['list' => $series_list, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add() {
$arg_where = array( 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = model('product_series')->getSeriesOptions( $arg_where, $arg_order, $arg_field, 100);
$value = ['seriesOptions' => $seriesOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$seriesModel = model('product_series');
$model = $seriesModel->insertGetId($data);
if ($model) {
return $this->redirect(url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function copy($id = 0) {
$seriesModel = model('product_series');
$id = intval($id);
if ($id > 0) {
$series = $seriesModel->getRow($id);
if (!$series && !is_array($series)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product_series'] = $series;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = $seriesModel->getSeriesOptions($arg_where, $arg_order, $arg_field, 100);
$value['seriesOptions'] = $seriesOptions;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$seriesModel = model('product_series');
$id = intval($id);
if ($id > 0) {
$series = $seriesModel->getRow($id);
if (empty($series)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product_series'] = $series;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$arg_where = array( 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = $seriesModel->getSeriesOptions($arg_where, $arg_order, $arg_field, 100);
$value['seriesOptions'] = $seriesOptions;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$product_series = model('product_series')->find($data['id']);
if (empty($product_series)){
return $this->error(Lang::get('产品系列名称不存在'));
}
$data['sort'] = intval($data['sort']);
$seriesModel = model('product_series');
$model = $seriesModel->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function listseries() {
$seriesModel = model('product_series');
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort', 'isshow', 'picture');
$series_list = $seriesModel->getList($arg_where, $arg_order, $arg_field, 50);
$series_breadcrumb = $seriesModel->getBreadCrumb();
$value = ['list' => $series_list, 'breadcrumb' => $series_breadcrumb];
$this->assign($value);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id && $sort < 2147483647) {
$model = model('product_series')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_series')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_series')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$seriesModel = model('product_series');
$series= $seriesModel->getRow(['id' => $id, 'stat' => 0]);
$result = $seriesModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,199 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class ProductSpecial extends BaseController {
public function index() {
$this->redirect('/admin/product_special/lists');
}
public function lists() {
$list = model('product_special')->where(['stat' => 0, 'country_code' => $this->country_code])->select();
$value = ['list' => $list];
$this->assign($value);
return $this->fetch();
}
public function add_product()
{
$id = $this->request->param('id');
if ($id <= 0)
return $this->error('id错误');
$product_special = model('product_special')->where(['stat' => 0, 'id' => $id, 'country_code' => $this->country_code])->find();
if (empty($product_special))
return $this->error('专题不存在');
$list = db('special_product_relation')->where(['special_id' => $id, 'stat' => 0])->select();
$this->assign('special_id', $id);
$this->assign('list', $list);
return $this->fetch();
}
public function update_product()
{
$data = $this->request->param();
// tiaoshi($data);die;
if (!is_array($data))
return $this->error('数据错误');
$id = $data['id'];
$arr_product_id = $data['product_id'];
$type = $data['type'];
$image = $data['picture'];
$product_special = db('special_product_relation')->where(['stat' => 0, 'country_code' => $this->country_code, 'special_id' => $id])->find();
if (!empty($product_special))
{
db('special_product_relation')->where(['stat' => 0, 'country_code' => $this->country_code, 'special_id' => $id])->update(['stat' => 1]);
}
foreach ($arr_product_id as $key => $value)
{
$insert_data = [
'special_id' => $id,
'product_id' => $value,
'type' => $type[$key],
'img' => $image[$key],
'country_code' => $this->country_code,
];
$result = db('special_product_relation')->insert($insert_data);
if (!$result)
return $this->error('添加失败');
}
return $this->success('添加成功', url('/admin/product_special/lists'));
}
public function add()
{
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result)
return $this->error($valid_result);
$data['sort'] = intval($data['sort']);
$data['country_code'] = $this->country_code;
$data['create_time'] = time();
$model = model('product_special')->insertGetId($data);
if ($model)
return $this->redirect(url('/admin/product_special/lists'));
else
return $this->error(Lang::get('operation failed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$product_special = model('product_special')->where(['id' => $id, 'country_code' => $this->country_code])->find();
if (empty($product_special))
return $this->error(Lang::get('incorrect operation'));
$value['product_special'] = $product_special;
} else
return $this->error(Lang::get('incorrect operation'));
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data))
return $this->error(Lang::get('incorrect operation'));
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result)
return $this->error($valid_result);
$product_special = model('product_special')->where(['id' => $data['id'], 'country_code' => $this->country_code])->find();
if (empty($product_special))
return $this->error('专题不存在');
$data['sort'] = intval($data['sort']);
$model = model('product_special')->updateRow($data);
if ($model)
return $this->redirect(url('/admin/product_special/lists'));
else
return $this->error(Lang::get('operation failed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id && $sort < 2147483647) {
$model = model('product_special')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_special/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_special')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
$this->cacheClear('ProductCategoryTag');
return $this->success(Lang::get('operation successed'), url('/admin/product_special/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('product_special')->where(['id' => $id])->update(['stat' => 1]);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

197
app/admin/controller/Question.php Executable file
View File

@@ -0,0 +1,197 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Question extends BaseController {
public function index() {
$this->redirect('/admin/question/lists');
}
public function lists() {
$data = $this->request->get();
//echo "<pre>=="; print_r($data); die;
$skeyword = $this->request->param('skeyword');
$search['skeyword'] = '';
if (!empty($skeyword))
{
$where['a.title|b.name'] = ['like', "%$skeyword%"];
$search['skeyword'] = $skeyword;
}
$where['a.stat'] = 0;
$where['a.country_code'] = $this->country_code;
$order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$field = ['a.*', 'b.name' => 'cate_name'];
$list = model('question')->alias('a')->join('question_category b', 'a.cid = b.id', 'LEFT')->where($where)->field($field)->order($order)->paginate(12);
// echo model('question')->getLastSql();die;
// $dataObject = model('question')->getPageList($arg_where, $arg_order);
$value = [
'list' => $list->isEmpty() ? null : $list->items(),
'page' => $list->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add() {
$question_catelist = model('question_category')->select();
$this->assign('question_catelist', $question_catelist);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['title' => 'require',];
//验证提示信息
$validatemsg = ['title.require' => '标题需要填写'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['country_code'] = $this->country_code;
$model = model('question')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$question = model('question')->getRow($id);
if (empty($question)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['question'] = $question;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$question_catelist = model('question_category')->select();
$value['question_catelist'] = $question_catelist;
$value['id'] = $id;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['title' => 'require',];
//验证提示信息
$validatemsg = ['title.require' => '名称需要填写',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = model('question')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('incorrect operation'));
}
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('question')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleheadline() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('question')->updateRow(['id' => $id, 'headline' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('question')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('question')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('question')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,140 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class QuestionCategory extends BaseController {
public function lists() {
$where['stat'] = 0;
$where['country_code'] = $this->country_code;
$question_catelist = model('question_category')->where($where)->select();
$this->assign('question_catelist', $question_catelist);
return $this->fetch();
}
public function add() {
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['name' => 'require',];
//验证提示信息
$validatemsg = ['name.require' => '标题需要填写'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['country_code'] = $this->country_code;
$data['stat'] = 0;
$data['create_time'] = time();
$model = model('question_category')->insertGetId($data);
if ($model) {
return $this->redirect(url('/admin/question_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$question_category = model('question_category')->getRow($id);
if (empty($question_category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['question_category'] = $question_category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$value['id'] = $id;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['name' => 'require',];
//验证提示信息
$validatemsg = ['name.require' => '名称需要填写',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = model('question_category')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/question_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('incorrect operation'));
}
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('question_category')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/question_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('question_category')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('question_category')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/question_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,248 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController as Base;
use \think\Validate;
class Operate_Of_ReceiveSync
{
const Add = 'add';
const Update = 'update';
const Enable = 'enable';
const Disable = 'disable';
}
// 接收来自产品目录系统的同步
class ReceiveSync extends Base
{
// 接收分类同步
public function category()
{
$data = request()->post();
if (empty($data)) {
return json(['code' => 0, 'msg' => '请确认同步数据']);
}
$query = new \think\db\Query();
$language = $data['lang'] == 'zh-cn' ? 'ZH' : 'US';
try {
$record = [
'name' => $data['name'],
'tco_id' => $data['tco_id'],
'tco_pid' => $data['tco_pid'],
'tco_path' => $data['tco_path'],
'erp_id' => $data['erp_id'],
'erp_pid' => $data['erp_pid'],
'erp_code' => $data['erp_code'],
'erp_path' => $data['erp_path'],
'country_code' => $language,
'sync_time' => strtotime($data['created_at'])
];
if (Operate_Of_ReceiveSync::Disable == $data['operate']) {
$record['disabled'] = 1;
}
$validate = new Validate([
'name|分类名称' => 'require',
'erp_code|分类ERP编码' => 'require',
]);
if (!$validate->check($record)) {
throw new \Exception((string)$validate->getError());
}
$mp = $query->name('product_tco_category')
->field(['id', 'category_id', 'sync_time'])
->where('erp_code', '=', $record['erp_code'])
->where('country_code', '=', $record['country_code'])
->find();
if (empty($mp)) {
$record['created_at'] = date('Y-m-d H:i:s');
$query->transaction(function () use ($query, $language, $record) {
$pid = 0;
if (!empty($record['tco_pid'])) {
$prev = $query->name('product_tco_category')
->where('tco_id', '=', $record['tco_pid'])
->where('country_code', '=', $language)
->find();
if (!empty($prev) && !empty($prev['category_id'])) {
$pid = $prev['category_id'];
// 更新上级分类
$query->name('product_category')->where('id', '=', $pid)->update(['haschild' => 1]);
}
}
// 同步新增官网分类
$record['category_id'] = $query->name('product_category')->insertGetId([
'pid' => $pid,
'name' => $record['name'],
'sort' => 9999,
'isshow' => 1,
'content' => '',
'classtype' => 2,
'siteid' => 32267,
'country_code' => $record['country_code'],
]);
if (empty($record['category_id'])) {
throw new \Exception('同步新增失败');
}
// 新增官网与产品目录关联分类
$ok = $query->name('product_tco_category')->insert($record);
if (!$ok) {
throw new \Exception('同步新增失败');
}
});
} else {
// 同步时间检查,防止脏数据
if ($mp['sync_time'] < $record['sync_time']) {
$record['updated_at'] = date('Y-m-d H:i:s');
$ok = $query->name('product_tco_category')->where('id', '=', $mp['id'])->update($record);
if (!$ok) {
throw new \Exception('同步更新失败');
}
$children = $query->name('product_tco_category')->where('tco_pid', '=', $mp['tco_id'])->find();
if (empty($children)) {
$query->name('product_category')->where('id', '=', $mp['category_id'])->update(['haschild' => 0]);
}
}
}
} catch (\Throwable $th) {
return json([
'code' => 0,
'msg' => sprintf("Exception %s %s:%d", $th->getMessage(), $th->getFile(), $th->getLine()),
]);
}
return json([
'code' => 1,
'msg' => '成功',
]);
}
// 接收产品同步
public function product()
{
$data = request()->post();
if (empty($data)) {
return json(['code' => 0, 'msg' => '请确认同步数据']);
}
$query = new \think\db\Query();
try {
$validate = new Validate([
'spu' => 'require',
'name' => 'require',
'category_erp_code' => 'require',
'lang' => 'require',
'created_at' => 'require',
]);
if (!$validate->check($data)) {
throw new \Exception((string)$validate->getError());
}
$language = $data['lang'] == 'zh-cn' ? 'ZH' : 'US';
$record = [
'name' => $data['name'],
'brand_id' => $data['spu'],
'country_code' => $language,
'synctime' => strtotime($data['created_at'])
];
// 执行下架
if (Operate_Of_ReceiveSync::Disable == $data['operate']) {
$record['is_show'] = -1;
}
// 如果 spu_before_modification 存在则根据 spu_before_modification 更新型号
$spu = !empty($data['spu_before_modification']) ? $data['spu_before_modification'] : $data['spu'];
$mp = $query->name('product')
->field(['id', 'cid', 'synctime'])
->where('brand_id', '=', $spu)
->where('country_code', '=', $language)
->find();
if (empty($mp)) {
// 避免 spu_before_modification 更新型号时,人为删除了旧型号导致的新增,从而出现重复型号问题,而进行再次验证
$exists = $query->name('product')->where('brand_id', '=', $data['spu'])->where('country_code', '=', $language)->value('id');
if ($exists) {
throw new \Exception(sprintf('【%s】该型号已存在', $data['spu']));
}
$record['stock_quantity'] = 0; // 库存
$record['sort'] = 9999; // 排序值
$record['isnew'] = 1; // 是否新品
$record['ishot'] = 0; // 是否热门
$record['recommend'] = 0; // 是否爆款
$record['isfeatured'] = 0; // 是否特色
$record['stat'] = 0; // 状态
$record['is_show'] = -1; // 是否上架0为上架-1为不上架
$record['createtime'] = time();
$record['product_desc'] = serialize([]);
$record['siteid'] = 32267;
// 关联分类
$category_id = $query->name('product_tco_category')
->where('erp_code', '=', $data['category_erp_code'])
->where('country_code', '=', $language)
->value('category_id');
if (empty($category_id)) {
throw new \Exception('官网未找到关联的分类');
}
$record['cid'] = $category_id;
$ok = $query->name('product')->insert($record);
if (!$ok) {
throw new \Exception('同步新增失败');
}
} else {
// 同步时间检查,防止脏数据
if ($mp['synctime'] < $record['synctime']) {
$category_id = $query->name('product_tco_category')
->where('erp_code', '=', $data['category_erp_code'])
->where('country_code', '=', $language)
->value('category_id');
// 关联分类
if (empty($mp['cid'])) {
// 如果产品未设置所属分类,则根据分类关联关系设置
if (empty($category_id)) {
throw new \Exception('官网未找到关联的分类');
}
$record['cid'] = $category_id;
} else {
// 如果产品设置了所属分类,分类映射关系未配置,则根据产品分类配置分类关系,否则更新产品分类
if (empty($category_id)) {
$query->name('product_tco_category')
->where('erp_code', '=', $data['category_erp_code'])
->where('country_code', '=', $language)
->update(['category_id' => $mp['cid']]);
} else {
$record['cid'] = $category_id;
}
}
// 不更新产品名称
unset($record['name']);
$record['updatetime'] = time();
$ok = $query->name('product')->where('id', '=', $mp['id'])->update($record);
if (!$ok) {
throw new \Exception('同步更新失败');
}
}
}
} catch (\Throwable $th) {
return json([
'code' => 0,
'msg' => sprintf("Exception %s %s:%d", $th->getMessage(), $th->getFile(), $th->getLine()),
]);
}
return json([
'code' => 1,
'msg' => '成功',
]);
}
}

151
app/admin/controller/Remark.php Executable file
View File

@@ -0,0 +1,151 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-15
* Time: 11:01
*/
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Remark extends BaseController
{
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists(){
$agent = Db('article_comment');
$arg_where = ['a.country_code' => $this->country_code];
$data = $this->request->param();
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['a.name|a.content|c.title'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
//$where['a.title|b.name'] = ['like', "%$skeyword%"];
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['a.add_time'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['a.add_time'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['a.add_time'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['a.add_time'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['a.add_time'], ['<=', $time]);
}
}
// dump($arg_where); die;
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.*, c.name as title, c.stat as c_stat' ];
$dataObject = model('article_comment')->getRemarkLists($arg_where, $arg_order, $arg_field, 24);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
];
//echo model('article_comment')->getLastsql();die;
$this->assign('search',$search);
$this->assign('list',$dataObject->isEmpty() ? null : $dataObject->items());
//$this->assign('list',$list);;
//
//echo "<pre>+++++++"; print_r($dataObject->items()); die;
$this->assign('page',$dataObject->render());
return $this->fetch();
}
public function update($id = 0, $stat=0) {
$id = intval($id);
if ($id > 0) {
$data = array(
'id' => $id,
'stat' => $stat
);
//echo "<pre>+++"; print_r($data);die;
$model = model('article_comment')->updateRow($data);
//echo $model->getData('id'); die;
if ($model && $model->getData('id')) {
//$feed = $this->redirect(url('/admin/remark/lists'));
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('incorrect operation'));
}
return $this->error(Lang::get('incorrect operation'));
}
public function view($id = 0){
$id = intval($id);
$where = ['id '=>$id];
$agent = Db('article_comment');
$data = $agent->where($where)->find();
$this->assign('data',$data);
return $this->fetch();
}
//2021-05-29 申邵 控制blog删除
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('article_comment')->deleteRow($id);
//echo "<pre>====="; print_r($result);die;
if ($result) {
//echo $id."<pre>=+++++++++"; print_r($result);die;
return $this->success(Lang::get('operation successed'), url('/admin/remark/lists'));
} else {
//echo "<pre>====="; print_r($result);die;
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('article_comment')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/remark/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

83
app/admin/controller/Report.php Executable file
View File

@@ -0,0 +1,83 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Report extends BaseController {
public function test()
{
return view();
}
public function index() {
$this->redirect('/admin/report/lists');
}
public function lists() {
$arg_where['stat'] = 0;
$arg_order = ['id' => 'desc'];
$dataObject = model('report')->getPageList($arg_where, $arg_order);
// tiaoshi($dataObject->items());die;
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
];
$this->assign($value);
return $this->fetch();
}
public function handle_report()
{
$id = $this->request->param('id');
if ($id < 0)
return $this->error('数据错误');
model('report')->where(['id' => $id])->update(['status' => 1]);
return $this->success('处理成功', url('/admin/report/lists'));
}
public function detail()
{
$id = $this->request->param('id');
if ($id < 0)
return $this->error('数据错误');
$report = model('report')->where(['id' => $id, 'stat' => 0])->find();
if (empty($report))
return $this->error('举报信息有误');
$this->assign('report', $report);
return $this->fetch();
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('report')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/report/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('report')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/report/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,225 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-05
* Time: 13:58
*/
namespace app\admin\controller;
use app\admin\model\Tbpl;
use tbpls\Tbpls;
use think\Db;
use think\Jdtbpl;
use think\Loader;
use think\Model;
class Shopselle extends BaseController
{
private function init_search(&$search)
{
$search['product_id'] = '';
$search['item_id'] = '';
}
public function index() {
$param = $this->request->param();
$search = [];
$this->init_search($search);
$where = ['stat' => 0];
if (isset($param['product_id']) && $param['product_id'] != '')
{
$where['product_id'] = $param['product_id'];
$search['product_id'] = $param['product_id'];
}
if (isset($param['item_id']) && $param['item_id'] != '')
{
$where['item_id'] = $param['item_id'];
$search['item_id'] = $param['item_id'];
}
$order = ['id' => 'desc'];
$dataObject = db('tbpl')->where($where)->order($order)->paginate(20);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add(){
return $this->fetch();
}
public function creatpl(){
$item_id = $this->request->post('item_id');
$seller_id = $this->request->post('seller_id');
$current_page = $this->request->post('current_page');
$product_id = $this->request->post('pid');
$shopselle_list = model('shopselle')->where(['product_id' => $product_id, 'stat' => 0])->select();
$shopselle_list = json_decode(json_encode($shopselle_list), true);
$count = count($shopselle_list);
if ($count >= 50)
{
return $this->error('当前产品评论数量超过50,请先删除部分评论');
}
$tbpl = new Tbpl();
$findpl = Db('tbpl')->where(['product_id' => $product_id, 'item_id' => $item_id, 'stat' => 0])->find();
if (!empty($findpl))
{
$tbpl_id = $findpl['id'];
}
else
{
$insert_data = [
'product_id' => $product_id,
'item_id' => $item_id,
'create_time' => date('Y-m-d H:i:s'),
'stat' => 0
];
$tbpl_id = $tbpl->insertGetId($insert_data);
if (!$tbpl_id)
{
return $this->error('添加评论失败');
}
}
$pl = new Jdtbpl($item_id,$seller_id,$current_page);
$plBack = $pl->getPl();
$pl_list = json_decode(json_decode(json_decode($plBack, true), true)['result']['ret_body'], true)['rateList'];
if (empty($pl_list))
{
return $this->error('当前页没有评论');
}
$plid_list = array_column($shopselle_list, 'plid');
foreach ($pl_list as $key => $value) {
if (in_array($value['id'], $plid_list))
continue;
$count++;
if ($count > 50)
break;
$insert_data = [];
$insert_data['pics'] = json_encode($value['pics']);
$insert_data['auctionSku'] = $value['auctionSku'];
$insert_data['headPic'] = $value['headPic'];
$insert_data['cmsSource'] = $value['cmsSource'];
$insert_data['displayUserNick'] = $value['displayUserNick'];
$insert_data['plid'] = $value['id'];
$insert_data['rateContent'] = $value['rateContent'];
$insert_data['rateDate'] = $value['rateDate'];
$insert_data['reply'] = $value['reply'];
$insert_data['memberIcon'] = $value['memberIcon'];
$insert_data['tamllSweetLevel'] = $value['tamllSweetLevel'];
$insert_data['useful'] = $value['useful'] == 'true' ? 0 : 1; // 0可用1不可用
$insert_data['stat'] = 0;
$insert_data['product_id'] = $product_id;
$insert_data['tbpl_id'] = $tbpl_id;
model('shopselle')->insert($insert_data);
}
return $this->success('添加成功');
}
public function pllist($id,$page=''){
$id = intval($id);
$where = ['tbpl_id' => $id, 'stat' => 0];
$count = Db('shopselle')->where($where)->count();
$list = Db('shopselle')->where($where)->paginate(10,$count);
$page = $list->render();
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
# 清空评论
public function clear_by_tbpl_id()
{
$tbpl_id = $this->request->param('tbpl_id');
if ($tbpl_id == '')
{
return $this->json(-1, '评论id错误');
}
model('shopselle')->where(['stat' => 0, 'tbpl_id' => $tbpl_id])->update(['stat' => 1]);
return $this->json(200, '清空成功');
}
public function delete_by_tbpl_id()
{
$tbpl_id = $this->request->param('tbpl_id');
if ($tbpl_id == '')
{
return $this->json(-1, '评论id错误');
}
model('shopselle')->where(['stat' => 0, 'tbpl_id' => $tbpl_id])->update(['stat' => 1]);
model('tbpl')->where(['id' => $tbpl_id])->update(['stat' => 1]);
return $this->json(200, '删除成功');
}
public function edit($id,$pid){
$id = intval($id);
$pid = intval($pid);
$where = ['id'=>$pid];//dump($where);die;
$tbpl = new Tbpl();
$find = $tbpl->where($where)->field('reply')->select();
//$find = $tbpl->getPageList($where);
$find=collection($find)->toArray();//把对象转成数组
//dump($find);die;
$reply = $find[0]['reply'];
$value = json_decode($reply);
$value = collection($value)->toArray();
$value = $value['result'];
$value = collection($value)->toArray();
$value = $value['ret_body'];
$value = json_decode($value);
$value = collection($value)->toArray();
$value = $value['rateList'];
foreach ($value as $k => $v){
$value = collection($v)->toArray();
}
dump($value);die;
}
public function delete() {
$id = $this->request->post('id');
$result = model('shopselle')->where('id', $id)->update(['stat' => 1]);
if ($result) {
return $this->json(1, '操作成功');
} else {
return $this->json(-2, '操作失败');
}
}
public function batchDelete() {
if ($this->administrator != 1) {
return $this->json(-1, '无权限');
}
$ids = rtrim($this->request->post('ids'), ',');
$ids = explode(",", $ids);
$data = [];
foreach ($ids as $key => $value) {
$result = model('shopselle')->where('id', $value)->update(['stat' => 1]);
if (!$result) {
return $this->json(-2, $value . '操作失败');
}
}
return $this->json(1, '操作成功');
}
}

View File

@@ -0,0 +1,312 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Singlepage extends BaseController {
public function index() {
$this->redirect('/admin/singlepage/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture', 'content');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$singlepage_list = Loader::model('Singlepage')->getSinglepageLists($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $singlepage_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function listcategory($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
$singlepage_list = Loader::model('Singlepage')->getSinglepageList($arg_where, $arg_order, $arg_field, 24);
$singlepage_breadcrumb = Loader::model('Singlepage')->getBreadCrumb($pid);
$value = ['list' => $singlepage_list, 'pid' => $pid, 'breadcrumb' => $singlepage_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0) {
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
//$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
$singlepage_list = Loader::model('Singlepage')->getList($arg_where, $arg_order, $arg_field, 24);
$value = ['list' => $singlepage_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function add($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['singlepageOptions' => $singlepageOptions, 'pid' => $pid];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$model = Loader::model('Singlepage')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$singlepage = Loader::model('Singlepage')->getRow($id);
if (empty($singlepage)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['singlepage'] = $singlepage;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($singlepage['pid']) ? $singlepage['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['singlepageOptions'] = $singlepageOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$singlepage = Loader::model('Singlepage')->getRow($id);
if (empty($singlepage)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['singlepage'] = $singlepage;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($singlepage['pid']) ? $singlepage['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'name', 'sort');
$singlepageOptions = Loader::model('Singlepage')->getOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['singlepageOptions'] = $singlepageOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$childIDArray = Loader::model('Singlepage')->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
$model = Loader::model('Singlepage')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => ['lt', 0], 'siteid' => $this->siteid);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'pid', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$singlepage_list = Loader::model('Singlepage')->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $singlepage_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = Loader::model('Singlepage')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$child = Loader::model('Singlepage')->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
$result = Loader::model('Singlepage')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
$ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $ids) {
$singlepageModel = Loader::model('Singlepage');
foreach ($ids as $id) {
$child = $singlepageModel->getRow(['pid' => $id, 'stat' => 0], 'id');
if ($child) {
return $this->error(Lang::get('ID=' . $id . '的节点包含子节点,不能进行删除'));
}
}
$result = $singlepageModel->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('Singlepage')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = Loader::model('Singlepage')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/singlepage/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Statistics extends BaseController {
public function index() {
return view();
}
public function get_click_sum() {
$params = $this->request->get();
$begin_datetime = $params['begin_datetime'];
$end_datetime = $params['end_datetime'];
$type = $params['type'];
$code = $params['code'];
if ($begin_datetime == '') {
$begin_datetime = date('Y-m-01 00:00:00');
$end_datetime = date('Y-m-t H:i:s');
}
$where = [];
if ($type != '') {
$where['type'] = $type;
}
if ($code != '') {
$where['code'] = $code;
}
$result = model('click_sum')->field('year(create_time) y, month(create_time) m, day(create_time) d, count(id) click_count')->group('year(create_time), month(create_time), day(create_time)')->whereTime('create_time', 'between', [$begin_datetime, $end_datetime])->where($where)->select();
// tiaoshi($result);die;
$tmp_click_sum = [];
foreach ($result as $key => $value) {
$k = $value['m'] . '-' . $value['d'];
$v = $value['click_count'];
$tmp_click_sum[$k] = $v;
}
$begin_time = strtotime($begin_datetime);
$end_time = strtotime($end_datetime);
$click_sum = [];
$j = 0;
for($i=$begin_time;$i<=$end_time;$i+=86400) {
$k = $this->filter_date(date('m-d', $i));
$click_sum[$j]['date'] = $k;
$click_sum[$j]['click_count'] = isset($tmp_click_sum[$k]) ? $tmp_click_sum[$k] : 0;
$j++;
}
$data = [
'click_sum' => $click_sum,
];
return $this->json(200, 'ok', $data);
}
// 06-09 -> 6-9
private function filter_date($date) {
$m = substr($date, 0, strpos($date, "-"));
$d = substr($date, strpos($date, "-") + 1);
if (substr($m, 0, 1) == 0) {
$m = substr($m, 1);
}
if (substr($d, 0, 1) == 0) {
$d = substr($d, 1);
}
return $m . '-' . $d;
}
}

View File

@@ -0,0 +1,232 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Sysconfig extends BaseController {
public function index() {
$this->redirect('/admin/sysconfig/lists');
}
public function lists($group = 0) {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => 0);
$arg_order = array('id' => 'desc', 'group' => 'asc', 'sort' => 'asc',);
$arg_field = array('id', 'name', 'group', 'type', 'sort', 'title');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name|title'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('sysconfig')->getPageList($arg_where, $arg_order, $arg_field, 15);
$value = [
'group_id' => (int) $group,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$value['groupList'] = (array) Config::get('config_group_list');
$value['typeList'] = (array) Config::get('config_type_list');
$this->assign($value);
return $this->fetch();
}
public function webconfig() {
$sysconfigs = model('sysconfig')->getGroupLists(array('stat' => 0), array('group' => 'asc', 'sort' => 'asc', 'id' => 'asc'), null);
foreach ($sysconfigs as $key => $val) {
$configs[$val->group][] = $val->toArray();
}
$value['configs'] = isset($configs) ? $configs : [];
$value['groupList'] = (array) Config::get('config_group_list');
$value['typeList'] = (array) Config::get('config_type_list');
$this->assign($value);
return $this->fetch();
}
public function add() {
$value['groupList'] = (array) Config::get('config_group_list');
$value['typeList'] = (array) Config::get('config_type_list');
$this->assign($value);
return $this->fetch();
}
/**
* 网站设置创建
*/
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'title' => 'require|max:30',
'agree' => 'require|accepted',
'name' => 'require|alphaDash|unique:sysconfig,name',
];
$validatemsg = [
'title.require' => '标题不能为空',
'title.max' => '标题最多不能超过30个字符',
'agree.require' => '请勾选确认框',
'agree.accepted' => '请勾选确认框',
'name.require' => '配置名称不能为空',
'name.alphaDash' => '配置名称的值是否为字母数字下划线',
'name.unique' => '配置名称已经存在'
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
$model = model('sysconfig')->insertRow($data);
if ($model && $model->getData('id')) {
$this->cacheClear('sysconfig');
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
/**
* 网站设置编辑
*/
public function edit($id) {
$id = intval($id);
if ($id > 0) {
$sysconfig = model('sysconfig')->getRow($id);
if (empty($sysconfig)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['config'] = $sysconfig;
}
$value['groupList'] = (array) Config::get('config_group_list');
$value['typeList'] = (array) Config::get('config_type_list');
$this->assign($value);
return $this->fetch();
}
/**
* 网站设置更新
*/
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'title' => 'require|max:30',
'name' => 'require|alphaDash',
'agree' => 'require|accepted',
'id' => 'require',
];
$validatemsg = [
'title.require' => '标题不能为空',
'title.max' => '标题最多不能超过30个字符',
'name.require' => '配置名称不能为空',
'name.alphaDash' => '配置名称的值是否为字母数字下划线',
'agree.require' => '请勾选确认框',
'agree.accepted' => '请勾选确认框',
'id.require' => '配置ID不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
$model = model('sysconfig')->updateRow($data);
if ($model && $model->getData('id')) {
$this->cacheClear('sysconfig');
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
/**
* 网站设置更新
*/
public function updategrp() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [
'config' => 'require|array',
'group' => 'require|number',
'agree' => 'require|accepted',
];
$validatemsg = [
'config.require' => '配置不能为空',
'config.array' => '配置应是一个数组',
'group.require' => '配置组不能为空',
'group.number' => '配置组应为数字',
'agree.require' => '请勾选确认框',
'agree.accepted' => '请勾选确认框',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if (isset($data['agree'])) {
unset($data['agree']);
}
foreach ($data['config'] as $key => $value) {
$object = model('sysconfig')->updateRow(['value' => $value], ['name' => $key, 'group' => $data['group']]);
if (!$object) {
break;
}
}
$this->cacheClear('sysconfig');
if ($object !== false) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
/**
* 网站设置删除
*/
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('sysconfig')->deleteRow($id);
if ($result) {
$this->cacheClear('sysconfig');
return $this->success(Lang::get('operation successed'), url('/admin/sysconfig/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

658
app/admin/controller/Test.php Executable file
View File

@@ -0,0 +1,658 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Test extends BaseController {
public function test() {
$map = [
'12' => 64,
'34' => 99,
'100' => 1000
];
$str[] = '<a href="/usmobile/product/detail/id/12">
<div class="img-responsive"><img src="/uploads/mobile/zh_mobile/HOT-K27660.jpg"></div>
<div class="hot_product_text text_center text_white">
<span class="title">Quick Power Bank</span>
<span class="subtitle">ORICO K27660</span>
</div>
</a> ';
$str[] = '<a href="/id/product/detail/34.html" target="_blank"><img src="/uploads/uk/list_one/Entertainment/Ad-2041.jpg" style="border:0px;"/></a>';
$str[] = ' <div class="rmcon">
<div class="rmcp">
<div class="rmimg img-responsive">
<a href="/id/product/detail/100.html"><img src="/uploads/uk/list_one/Phone/HOT-W27660.jpg"></a>
</div>
</div>
</div>
';
tiaoshi($str);die;
}
public function jianzhan()
{
echo 1;die;
set_time_limit(0);
$begin_time = time();
$country_code = 'de';
// ---------同步产品分类begin----------
$product_cat_us = model('product_category')->where(['country_code' => 'US', 'stat' => 0])->select();
$product_cat_us_map = [];
foreach ($product_cat_us as $key => $value) {
$old_product_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_product_cat_id = model('product_category')->insertGetId($value);
if (!$new_product_cat_id)
{
echo $key, ' ', $value, ' error';
}
$product_cat_us_map[$old_product_cat_id] = $new_product_cat_id;
}
// 改pid
$product_cat = model('product_category')->where(['country_code' => strtoupper($country_code)])->select();
foreach ($product_cat as $key => $value) {
if ($value['pid'] == 0) {
continue;
}
model('product_category')->where(['id' => $value['id']])->update(['pid' => $product_cat_us_map[$value['pid']]]);
}
// ---------同步产品分类e n d----------
// ---------同步横幅begin----------
$banner_cat_us = model('banner_type')->where(['country_code' => 'US', 'stat' => 0])->select();
$banner_cat_us_map = [];
foreach ($banner_cat_us as $key => $value) {
$old_banner_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_banner_cat_id = model('banner_type')->insertGetId($value);
$banner_cat_us_map[$old_banner_cat_id] = $new_banner_cat_id;
}
$banner_us = model('banner')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($banner_us as $key => $value) {
unset($value['id']);
$value['typeid'] = isset($banner_cat_us_map[$value['typeid']]) ? $banner_cat_us_map[$value['typeid']] : 0;
$cate_id = $value['categoryid'];
if ($cate_id != '')
{
$arr_cate_id = explode(",", $cate_id);
foreach ($arr_cate_id as $k => $v) {
if (isset($product_cat_us_map[$v]))
{
$arr_cate_id[$k] = $product_cat_us_map[$v];
}
$value['categoryid'] = implode(",", $arr_cate_id);
}
}
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_banner_id = model('banner')->insertGetId($value);
}
// ---------同步横幅e n d----------
// ---------同步产品begin----------
$product_us_map = [];
$product_us = model('product')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_us as $k => $v) {
$old_product_id = $v['id'];
unset($v['id']);
$v['cid'] = isset($product_cat_us_map[$v['cid']]) ? $product_cat_us_map[$v['cid']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_id = model('product')->insertGetId($v);
$product_us_map[$old_product_id] = $new_product_id;
}
// ---------同步产品e n d----------
// ---------同步广告begin----------
$ad_cat_us = model('ad_type')->where(['country_code' => 'US', 'stat' => 0])->select();
$ad_cat_us_map = [];
foreach ($ad_cat_us as $key => $value) {
$old_ad_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_ad_cat_id = model('ad_type')->insertGetId($value);
$ad_cat_us_map[$old_ad_cat_id] = $new_ad_cat_id;
}
$ad_us = model('ad')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($ad_us as $key => $value) {
unset($value['id']);
if ($value['typeid'] != 0 && isset($ad_cat_us_map[$value['typeid']]))
{
$value['typeid'] = $ad_cat_us_map[$value['typeid']];
}
else
{
$value['typeid'] = 0;
}
foreach ($product_cat_us_map as $k => $v) {
$tmp = substr($value['tags'], strrpos($value['tags'], '_') + 1);
if ($tmp == (string) $k)
{
$value['tags'] = str_replace((string) $k, (string) $v, $value['tags']);
}
}
$normbody = $value['normbody'];
if (strpos($normbody, 'mobile/product/detail/id/') !== false)
{
$len = strpos($normbody, '">') - (strpos($normbody, 'mobile/product/detail/id/') + 25);
$tmp = substr($normbody, strpos($normbody, 'mobile/product/detail/id/') + 25, $len);
foreach ($product_us_map as $k => $v) {
if ($tmp == $k)
{
$normbody = str_replace((string) $tmp, (string) $v, $normbody);
}
}
}
else if (strpos($normbody, '/product/detail/') !== false)
{
$len = strpos($normbody, '.html') - (strpos($normbody, '/product/detail/') + 16);
$tmp = substr($normbody, strpos($normbody, '/product/detail/') + 16, $len);
foreach ($product_us_map as $k => $v) {
if ($tmp == $k)
{
$normbody = str_replace((string) $tmp, (string) $v, $normbody);
}
}
}
$value['normbody'] = $normbody;
$value = json_decode($value, true);
$value['country_code'] = strtoupper($country_code);
$new_ad_id = model('ad')->insertGetId($value);
}
// ---------同步广告e n d----------
// ---------同步产品下载begin----------
$product_dl_us = model('product_dl')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_dl_us as $k => $v) {
if ($v['product_id'] == 0) {
continue;
}
unset($v['id']);
$v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_dl_id = model('product_dl')->insertGetId($v);
}
// ---------同步产品下载e n d----------
// ---------同步产品图片begin----------
$product_image_us = model('product_image')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_image_us as $k => $v) {
if ($v['product_id'] == 0) {
continue;
}
unset($v['id']);
$v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_image_id = model('product_image')->insertGetId($v);
}
// ---------同步产品图片e n d----------
// ---------同步关联产品begin----------
$product_related_us = model('product_related')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_related_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['related_product_id']]) || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v['related_product_id'] = $product_us_map[$v['related_product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_related_id = model('product_related')->insertGetId($v);
}
// ---------同步关联产品e n d----------
// ---------同步产品2级列表图begin----------
$product_two_img_us = model('product_two_img')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_two_img_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_two_img_id = model('product_two_img')->insertGetId($v);
}
// ---------同步产品2级列表图e n d----------
// ---------同步产品背景图begin----------
$product_bk_img_us = model('product_bk_img')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($product_bk_img_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_bk_img_id = model('product_bk_img')->insertGetId($v);
}
// ---------同步产品背景图e n d----------
$article_cat_us = model('article_category')->where(['country_code' => 'US', 'stat' => 0])->select();
$cat_us_map = [];
foreach ($article_cat_us as $key => $value) {
$old_article_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_article_cat_id = model('article_category')->insertGetId($value);
$cat_us_map[$old_article_cat_id] = $new_article_cat_id;
}
$article_us = model('article')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($article_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_article_id = model('article')->insertGetId($value);
}
$video_cat_us = model('video_category')->where(['country_code' => 'US', 'stat' => 0])->select();
$cat_us_map = [];
foreach ($video_cat_us as $key => $value) {
$old_video_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_video_cat_id = model('video_category')->insertGetId($value);
$cat_us_map[$old_video_cat_id] = $new_video_cat_id;
}
$video_us = model('video')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($video_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_video_id = model('video')->insertGetId($value);
}
$download_cat_us = model('download_category')->where(['country_code' => 'US', 'stat' => 0])->select();
$cat_us_map = [];
foreach ($download_cat_us as $key => $value) {
$old_download_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_download_cat_id = model('download_category')->insertGetId($value);
$cat_us_map[$old_download_cat_id] = $new_download_cat_id;
}
$download_us = model('download')->where(['country_code' => 'US', 'stat' => 0])->select();
foreach ($download_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_download_id = model('download')->insertGetId($value);
}
$end_time = time();
echo $end_time - $begin_time;die;
}
public function tongbu_product() {
die;
set_time_limit(0);
$begin_time = time();
$country_code = 'vn';
// ---------同步产品分类begin----------
$product_cat_us = model('product_category_' . $country_code)->select();
$product_cat_us_map = [];
foreach ($product_cat_us as $key => $value) {
$old_product_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_product_cat_id = model('product_category')->insertGetId($value);
if (!$new_product_cat_id)
{
echo $key, ' ', $value, ' error';
}
$product_cat_us_map[$old_product_cat_id] = $new_product_cat_id;
}
// 改pid
$product_cat = model('product_category')->where(['country_code' => strtoupper($country_code)])->select();
foreach ($product_cat as $key => $value) {
if ($value['pid'] == 0) {
continue;
}
model('product_category')->where(['id' => $value['id']])->update(['pid' => $product_cat_us_map[$value['pid']]]);
}
// ---------同步产品分类e n d----------
// ---------同步横幅begin----------
$banner_cat_us = model('banner_type_' . $country_code)->select();
$banner_cat_us_map = [];
foreach ($banner_cat_us as $key => $value) {
$old_banner_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_banner_cat_id = model('banner_type')->insertGetId($value);
$banner_cat_us_map[$old_banner_cat_id] = $new_banner_cat_id;
}
$banner_us = model('banner_' . $country_code)->select();
foreach ($banner_us as $key => $value) {
unset($value['id']);
$value['typeid'] = isset($banner_cat_us_map[$value['typeid']]) ? $banner_cat_us_map[$value['typeid']] : 0;
$cate_id = $value['categoryid'];
if ($cate_id != '')
{
$arr_cate_id = explode(",", $cate_id);
foreach ($arr_cate_id as $k => $v) {
if (isset($product_cat_us_map[$v]))
{
$arr_cate_id[$k] = $product_cat_us_map[$v];
}
$value['categoryid'] = implode(",", $arr_cate_id);
}
}
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_banner_id = model('banner')->insertGetId($value);
}
// ---------同步横幅e n d----------
// ---------同步产品begin----------
$product_us_map = [];
$product_us = model('product_' . $country_code)->select();
foreach ($product_us as $k => $v) {
$old_product_id = $v['id'];
unset($v['id']);
$v['cid'] = isset($product_cat_us_map[$v['cid']]) ? $product_cat_us_map[$v['cid']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_id = model('product')->insertGetId($v);
$product_us_map[$old_product_id] = $new_product_id;
}
// ---------同步产品e n d----------
// ---------同步广告begin----------
$ad_cat_us = model('ad_type_' . $country_code)->select();
$ad_cat_us_map = [];
foreach ($ad_cat_us as $key => $value) {
$old_ad_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_ad_cat_id = model('ad_type')->insertGetId($value);
$ad_cat_us_map[$old_ad_cat_id] = $new_ad_cat_id;
}
$ad_us = model('ad_' . $country_code)->select();
foreach ($ad_us as $key => $value) {
unset($value['id']);
if ($value['typeid'] != 0 && isset($ad_cat_us_map[$value['typeid']]))
{
$value['typeid'] = $ad_cat_us_map[$value['typeid']];
}
else
{
$value['typeid'] = 0;
}
foreach ($product_cat_us_map as $k => $v) {
$tmp = substr($value['tags'], strrpos($value['tags'], '_') + 1);
if ($tmp == (string) $k)
{
$value['tags'] = str_replace((string) $k, (string) $v, $value['tags']);
}
}
$normbody = $value['normbody'];
if (strpos($normbody, 'mobile/product/detail/id/') !== false)
{
$len = strpos($normbody, '">') - (strpos($normbody, 'mobile/product/detail/id/') + 25);
$tmp = substr($normbody, strpos($normbody, 'mobile/product/detail/id/') + 25, $len);
foreach ($product_us_map as $k => $v) {
if ($tmp == $k)
{
$normbody = str_replace((string) $tmp, (string) $v, $normbody);
}
}
}
else if (strpos($normbody, '/product/detail/') !== false)
{
$len = strpos($normbody, '.html') - (strpos($normbody, '/product/detail/') + 16);
$tmp = substr($normbody, strpos($normbody, '/product/detail/') + 16, $len);
foreach ($product_us_map as $k => $v) {
if ($tmp == $k)
{
$normbody = str_replace((string) $tmp, (string) $v, $normbody);
}
}
}
$value['normbody'] = $normbody;
$value = json_decode($value, true);
$value['country_code'] = strtoupper($country_code);
$new_ad_id = model('ad')->insertGetId($value);
}
// ---------同步广告e n d----------
// ---------同步产品下载begin----------
$product_dl_us = model('product_dl_' . $country_code)->select();
foreach ($product_dl_us as $k => $v) {
if ($v['product_id'] == 0) {
continue;
}
unset($v['id']);
$v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_dl_id = model('product_dl')->insertGetId($v);
}
// ---------同步产品下载e n d----------
// ---------同步产品图片begin----------
$product_image_us = model('product_image_' . $country_code)->select();
foreach ($product_image_us as $k => $v) {
if ($v['product_id'] == 0) {
continue;
}
unset($v['id']);
$v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0;
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_image_id = model('product_image')->insertGetId($v);
}
// ---------同步产品图片e n d----------
// ---------同步关联产品begin----------
$product_related_us = model('product_related_' . $country_code)->select();
foreach ($product_related_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['related_product_id']]) || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v['related_product_id'] = $product_us_map[$v['related_product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_related_id = model('product_related')->insertGetId($v);
}
// ---------同步关联产品e n d----------
// ---------同步产品2级列表图begin----------
$product_two_img_us = model('product_two_img_' . $country_code)->select();
foreach ($product_two_img_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_two_img_id = model('product_two_img')->insertGetId($v);
}
// ---------同步产品2级列表图e n d----------
// ---------同步产品背景图begin----------
$product_bk_img_us = model('product_bk_img_' . $country_code)->select();
foreach ($product_bk_img_us as $k => $v) {
if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) {
continue;
}
unset($v['id']);
$v['product_id'] = $product_us_map[$v['product_id']];
$v = json_decode(json_encode($v), true);
$v['country_code'] = strtoupper($country_code);
$new_product_bk_img_id = model('product_bk_img')->insertGetId($v);
}
// ---------同步产品背景图e n d----------
$end_time = time();
echo $end_time - $begin_time;die;
}
public function tongbu_article() {
die;
$country_code = 'vn';
$article_cat_us = model('article_category_' . $country_code)->select();
$cat_us_map = [];
foreach ($article_cat_us as $key => $value) {
$old_article_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_article_cat_id = model('article_category')->insertGetId($value);
$cat_us_map[$old_article_cat_id] = $new_article_cat_id;
}
$article_us = model('article_' . $country_code)->select();
foreach ($article_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_article_id = model('article')->insertGetId($value);
}
echo 1;die;
}
public function tongbu_video() {
die;
$country_code = 'vn';
$video_cat_us = model('video_category_' . $country_code)->select();
$cat_us_map = [];
foreach ($video_cat_us as $key => $value) {
$old_video_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_video_cat_id = model('video_category')->insertGetId($value);
$cat_us_map[$old_video_cat_id] = $new_video_cat_id;
}
$video_us = model('video_' . $country_code)->select();
foreach ($video_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_video_id = model('video')->insertGetId($value);
}
echo 2;die;
}
public function tongbu_download() {
die;
$country_code = 'vn';
$download_cat_us = model('download_category_' . $country_code)->select();
$cat_us_map = [];
foreach ($download_cat_us as $key => $value) {
$old_download_cat_id = $value['id'];
unset($value['id']);
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_download_cat_id = model('download_category')->insertGetId($value);
$cat_us_map[$old_download_cat_id] = $new_download_cat_id;
}
$download_us = model('download_' . $country_code)->select();
foreach ($download_us as $key => $value) {
unset($value['id']);
$value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0;
$value = json_decode(json_encode($value), true);
$value['country_code'] = strtoupper($country_code);
$new_download_id = model('download')->insertGetId($value);
}
echo 3;die;
}
}

357
app/admin/controller/Tool.php Executable file
View File

@@ -0,0 +1,357 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use pagination\Pagination;
use sitemap\Sitemap;
class Tool extends BaseController {
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Shanghai");
error_reporting(E_ERROR | E_WARNING);
//Config::set('url_common_param', true);
//header("Content-Type: text/html; charset=utf-8");
}
public function sitemapxml() {
$site = new Sitemap();
$domain = $this->request->domain();
$site->AddItem($domain, 0);
$site->AddItem(url_rewrite('product', [], $domain), 1);
$productcategory = Loader::model('ProductCategory')->getList(['stat' => ['eq', '0']], ['sort' => 'asc', 'id' => 'desc'], array('id', 'name'));
foreach ($productcategory as $pc) {
$site->AddItem(url_rewrite('product', ['id' => $pc['id']], $domain), 1);
}
$product = Loader::model('Product')->getList(['stat' => ['eq', '0']], ['sort' => 'asc', 'id' => 'desc'], array('id', 'name'));
foreach ($product as $p) {
$site->AddItem(url_rewrite('productdetail', ['id' => $p['id']], $domain), 1);
}
$res = $site->SaveToFile('sitemap.xml');
if ($res) {
return $this->success(Lang::get('operation successed'), url('/admin/index/index'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function icon() {
$iconName = $this->request->get('iconName', 'undefined');
$value = ['iconName' => $iconName];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function getajaxctrl() {
$module = $this->request->get('module', 'index');
if ($this->request->isGet() && $module) {
$html = get_ctrl_names($module);
echo $html;
exit;
} else {
echo Lang::get('operation failed');
exit;
}
}
public function getajaxaction() {
$ctrl = $this->request->get('controller', '');
$module = $this->request->get('module', 'index');
if ($this->request->isGet() && $ctrl) {
$html = get_action_names($ctrl, 'app\\' . $module . '\\controller\\');
echo $html;
exit;
} else {
echo Lang::get('operation failed');
exit;
}
}
public function show() {
Config::set('url_common_param', true);
header("Content-Type: text/html; charset=utf-8");
if (Config::get('template.index.view_base')) {
$this->basePath = Config::get('template.index.view_base') . DS;
} else {
$this->basePath = Config::get('template.index.view_path');
if (empty($this->basePath)) {
$this->basePath = APP_PATH . 'index' . DS . 'view' . DS;
}
}
$this->basePath = rtrim($this->basePath, '\/\\');
$filter_name = $this->request->get('filter_name', '', 'urldecode');
if (!empty($filter_name)) {
$filter_name = trim(str_replace(['/../', '../', '*'], '', $filter_name), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
$type = $this->request->get('type', 'file');
$target = $this->request->get('target', '');
$func = $this->request->get('func', 'undefined');
$url = array();
$url['target'] = $target;
$data['target'] = $target;
$url['type'] = $type;
$data['type'] = $type;
$url['func'] = $func;
$data['func'] = $func;
//Config::set('url_common_param', true);
//$config = Config::get('paginate');
$page = $this->request->request('page/d', 1);
$page = $page < 1 ? 1 : $page;
$directories = array();
$files = array();
$data['images'] = array();
if (substr($directory . '/' . $filter_name, 0, strlen($this->basePath)) == $this->basePath) {
// Get directories
$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
if (!$directories) {
$directories = array();
}
switch ($type) {
case 'image':
// Get files
$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
break;
case 'file':
// Get files
$files = glob($directory . '/' . $filter_name . '*.*', GLOB_BRACE);
break;
default:
// Get files
$files = glob($directory . '/' . $filter_name . '*', GLOB_BRACE);
break;
}
if (!$files) {
$files = array();
}
}
// Merge directories and files
$images = array_merge($directories, $files);
// Get total number of files and directories
$image_total = count($images);
// Split the array based on current page number and max number of items per page of 10
$images = array_splice($images, ($page - 1) * 16, 16);
foreach ($images as $image) {
$name = basename($image);
if (is_dir($image)) {
$path = substr($image, strlen($this->basePath));
$url['directory'] = urlencode(substr($image, strlen($this->basePath)));
$data['images'][] = array(
'name' => $name,
'type' => 'directory',
'path' => $path,
'href' => url('/admin/tool/show', array_filter($url), true)
);
} elseif (is_file($image)) {
$path = substr($image, strlen($this->basePath));
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
switch ($ext) {
case 'jpg': case 'png': case 'gif': case 'bmp': case 'jpeg':
$data['images'][] = array(
'name' => $name,
'type' => 'image',
'path' => $path,
'href' => $this->request->domain() . $path
);
break;
case 'html': case 'phtml': case 'php': case 'htm': case 'js': case 'css': case 'txt':
$data['images'][] = array(
'name' => $name,
'type' => 'text',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
case 'avi': case 'mp4': case 'rmvb': case 'mkv': case 'wmv':
$data['images'][] = array(
'name' => $name,
'type' => 'video',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
case 'zip': case 'rar': case 'gz': case 'tar': case 'tgz': case 'gz': case 'iso':
$data['images'][] = array(
'name' => $name,
'type' => 'archive',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
default:
$data['images'][] = array(
'name' => $name,
'type' => 'other',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
}
}
}
$data['filter_name'] = $filter_name;
$url['directory'] = urlencode($relativepath);
$data['directory'] = urlencode($relativepath);
// Refresh
$data['refresh'] = url('/admin/tool/show', array_filter($url), true);
if (!empty($relativepath)) {
$pos = strrpos($relativepath, '/');
if ($pos) {
$url['directory'] = urlencode(substr($relativepath, 0, $pos));
} else {
$url['directory'] = '';
}
}
// Parent
if (!empty($relativepath)) {
$pos = strrpos($relativepath, '/');
if ($pos) {
$url['directory'] = urlencode(substr($relativepath, 0, $pos));
} else {
$url['directory'] = '';
}
}
$data['parent'] = url('/admin/tool/show', array_filter($url), true);
//Pagination
if (!empty($relativepath)) {
$url['directory'] = urlencode($relativepath);
}
if (!empty($filter_name)) {
$url['filter_name'] = urlencode($filter_name);
}
$url['page'] = '{page}';
$pagination = new Pagination();
$pagination->total = $image_total;
$pagination->page = $page;
$pagination->limit = 16;
$pagination->url = url('/admin/tool/show', array_filter($url), true);
$data['pagination'] = $pagination->render();
$this->assign($data);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function showcontent() {
Config::set('url_common_param', true);
header("Content-Type: text/html; charset=utf-8");
if (Config::get('template.index.view_base')) {
$this->basePath = Config::get('template.index.view_base') . '/';
} else {
$this->basePath = Config::get('template.index.view_path');
if (empty($this->basePath)) {
$this->basePath = APP_PATH . 'index' . '/' . 'view' . '/';
}
}
$this->basePath = rtrim($this->basePath, '\/\\');
$filename = $this->request->get('filename', '', 'urldecode');
if (!empty($filename)) {
$filename = trim(str_replace(['/../', '../', '*'], '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$file = $this->basePath . '/' . $filename;
//print_r(is_file($file));exit;
if (is_file($file)) {
$data['filename'] = '/' . $filename;
$data['content'] = file_get_contents($file);
$this->assign($data);
}
}
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function updatecontent() {
if (Config::get('template.index.view_base')) {
$this->basePath = Config::get('template.index.view_base') . '/';
} else {
$this->basePath = Config::get('template.index.view_path');
if (empty($this->basePath)) {
$this->basePath = APP_PATH . 'index' . '/' . 'view' . '/';
}
}
$this->basePath = rtrim($this->basePath, '\/\\');
$content = $this->request->param('filecontent', '', 'urldecode');
$filename = $this->request->param('filename', '', 'urldecode');
if (!empty($filename)) {
$filename = trim(str_replace(['/../', '../', '*'], '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$file = $this->basePath . '/' . $filename;
//print_r(is_file($file));exit;
if (is_file($file)) {
$result = file_put_contents($file, $content);
return $this->result([], $result, '更新成功');
}
}
return $this->result([], false, '未知错误');
}
public function rename() {
if (Config::get('template.index.view_base')) {
$this->basePath = Config::get('template.index.view_base') . DS;
} else {
$this->basePath = Config::get('template.index.view_path');
if (empty($this->basePath)) {
$this->basePath = APP_PATH . 'index' . DS . 'view' . DS;
}
}
$this->basePath = rtrim($this->basePath, '\/\\');
$json = array();
// Make sure we have the correct directory
$relativepath = $this->request->get('directory', '', 'urldecode');
if (isset($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
// Check its a directory
if (!is_dir($directory) || substr($directory, 0, strlen($this->basePath)) != $this->basePath) {
$json['error'] = '路径错误';
echo json_encode($json);
exit;
}
if ($this->request->isPost()) {
// Sanitize the folder name
$path = $this->request->post('path', '', 'urldecode');
$pathinfo = pathinfo($path);
$filenewname = $this->request->post('filenewname', '', 'urldecode');
// Validate the filename length
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $filenewname)) {
$json['error'] = $filenewname . '文件名称不是由数字字母下划线组成';
echo json_encode($json);
exit;
}
// Validate the filename length
if ((strlen($filenewname) < 3) || (strlen($filenewname) > 128)) {
$json['error'] = $filenewname . '文件名长度错误,至少3个字符以上';
echo json_encode($json);
exit;
}
// Check if directory already exists or not
if (!file_exists($directory . '/' . $pathinfo['basename']) || !(file_exists($this->basePath . $path))) {
$json['error'] = $pathinfo['filename'] . '文件不存在';
echo json_encode($json);
exit;
}
if (!isset($json['error'])) {
rename($this->basePath . $path, $directory . '/' . $filenewname . ($pathinfo['extension'] ? '.' . $pathinfo['extension'] : ''));
$json['success'] = '文件重命名成功';
}
}
echo json_encode($json);
exit;
}
}

468
app/admin/controller/Ueditor.php Executable file
View File

@@ -0,0 +1,468 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use image\Image;
class Ueditor extends BaseController {
private $basePath = '/';
private $saveDirectory = 'default';
private $config; //配置信息
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Shanghai");
$this->docDir = $this->request->server('DOCUMENT_ROOT');
$this->rootDir = $this->request->root();
$this->basePath = $this->docDir . $this->rootDir . '/uploads';
$this->saveDirectory = 'temp';
error_reporting(E_ERROR | E_WARNING);
Config::set('url_common_param', true);
header("Content-Type: text/html; charset=utf-8");
}
//上传文件
private function upFile($fileField, $config = array()) {
$result = array('state' => "ERROR_UNKNOWN 未知错误");
$file = $this->request->file($fileField);
if (empty($file)) {
$file = $this->request->file('upfile');
}
// $error = $this->validate(
// ['file' => $file], ['file' => 'image|fileSize:40000000|fileExt:jpg,jpeg,gif,png'], ['file.image' => '上传文件必须为图片', 'file.fileSize' => '上传文件过大', 'file.fileExt' => '上传文件后缀名必须为jpg,jpeg,gif,png']
// );
$error = true;
if (true !== $error || empty($file)) {
return json_encode(['state' => "ERROR " . $error]);
} else {
// 移动到框架应用根目录/public/uploads/ 目录下
$saveDirectory = $this->saveDirectory . '/' . date('Y/md') . '/';
// 使用自定义的文件保存规则
$info = $file->rule(function($file) {
return md5(mt_rand());
})->move($this->basePath . '/' . $saveDirectory);
if ($info) {
$result = array(
'state' => 'SUCCESS',
'url' => '/uploads/' . $saveDirectory . $info->getFilename(),
'title' => $info->getFilename(),
'original' => $info->getFilename(),
'type' => '.' . $info->getExtension(),
'size' => $info->getSize(),
);
//图片加水印
$ext = strtolower($info->getExtension());
if (in_array($ext, ['gif', 'jpg', 'jpeg', 'png', 'bmp'])) {
$this->watermark('/uploads/' . $saveDirectory . $info->getFilename());
}
} else {
$result['state'] = 'ERROR ' . $file->getError();
}
}
return json_encode($result);
}
/*
* 处理base64编码的图片上传
* 例如:涂鸦图片上传
*/
private function upBase64($fileField, $config) {
$base64Data = $this->request->post($fileField);
$img = base64_decode($base64Data);
$dirname = $this->basePath . '/' . $this->saveDirectory . '/';
$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);
}
//列出图片
private function listFile($allowFiles, $listSize, $get) {
$dirname = $this->basePath . '/' . $this->saveDirectory . '/';
$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 (!count($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];
}
// /* 倒序 */
// for ($i = $end, $list = array(); $i < $len && $i < $end; $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, strlen($_SERVER['DOCUMENT_ROOT'])),
'mtime' => filemtime($path2)
);
}
}
}
}
return $files;
}
/**
* 拉取远程图片
* @return mixed
*/
private function saveRemotess($fieldName, $config) {
$imgUrl = htmlspecialchars($fieldName);
$imgUrl = str_replace("&amp;", "&", $imgUrl);
//http开头验证
if (strpos($imgUrl, "http") !== 0) {
$data = array(
'state' => '链接不是http链接',
);
return json_encode($data);
}
//获取请求头并检测死链
$heads = get_headers($imgUrl);
if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
$data = array(
'state' => '链接不可用',
);
return json_encode($data);
}
//格式验证(扩展名验证和Content-Type验证)
$fileType = strtolower(strrchr($imgUrl, '.'));
if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
$data = array(
'state' => '链接contentType不正确',
);
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 = $this->basePath . '/' . $this->saveDirectory . '/' . date('Y/md') . '/';
$file['oriName'] = $m ? $m[1] : "";
$file['filesize'] = strlen($img);
$file['ext'] = strtolower(strrchr($config['oriName'], '.'));
$file['name'] = md5(mt_rand()) . $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' => substr($file['fullName'], strlen($this->docDir . $this->rootDir)),
'title' => $file['name'],
'original' => $file['oriName'],
'type' => $file['ext'],
'size' => $file['filesize'],
);
}
return json_encode($data);
}
/**
* 拉取远程图片
* @return mixed
*/
private function saveRemote($fileField, $config = array()) {
$imgUrl = htmlspecialchars($fileField);
$imgUrl = str_replace("&amp;", "&", $imgUrl);
//http开头验证
if (strpos($imgUrl, "http") !== 0) {
$data = array(
'state' => '链接不是http链接',
);
return json_encode($data);
}
preg_match('/(^https*:\/\/[^:\/]+)/', $imgUrl, $matches);
$host_with_protocol = count($matches) > 1 ? $matches[1] : '';
// 判断是否是合法 url
if (!filter_var($host_with_protocol, FILTER_VALIDATE_URL)) {
$data = array(
'state' => 'INVALID_URL',
);
return json_encode($data);
}
preg_match('/^https*:\/\/(.+)/', $host_with_protocol, $matches);
$host_without_protocol = count($matches) > 1 ? $matches[1] : '';
// 此时提取出来的可能是 ip 也有可能是域名,先获取 ip
$ip = gethostbyname($host_without_protocol);
// 判断是否是私有 ip
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
$data = array(
'state' => 'INVALID_IP',
);
return json_encode($data);
}
//获取请求头并检测死链
$heads = get_headers($imgUrl);
if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
$data = array(
'state' => '链接不可用',
);
return json_encode($data);
}
//格式验证(扩展名验证和Content-Type验证)
$fileType = strtolower(strrchr($imgUrl, '.'));
if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
$data = array(
'state' => '链接contentType不正确',
);
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 = $this->basePath . '/' . $this->saveDirectory . '/' . date('Y/md') . '/';
$file['oriName'] = $m ? $m[1] : "";
$file['filesize'] = strlen($img);
$file['ext'] = strtolower(strrchr($config['oriName'], '.'));
$file['name'] = md5(mt_rand()) . $file['ext'];
$file['fullName'] = $dirname . $file['name'];
$fullName = $file['fullName'];
//检查文件大小是否超出限制
if ($file['filesize'] >= ($config["maxSize"])) {
$data = array(
'state' => '文件大小超出网站限制',
);
return json_encode($data);
}
//创建目录失败
if (!is_dir($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) && is_file($fullName))) { //移动失败
$data = array(
'state' => '写入文件内容错误',
);
return json_encode($data);
} else { //移动成功
//$this->watermark(substr($file['fullName'], strlen($this->docDir . $this->rootDir)));
$data = array(
'state' => 'SUCCESS',
'url' => substr($file['fullName'], strlen($this->docDir . $this->rootDir)),
'title' => $file['name'],
'original' => $file['oriName'],
'type' => $file['ext'],
'size' => $file['filesize'],
);
}
return json_encode($data);
}
public function watermark($return_url = '/uploads/nopic.jpg') {
$iswatermark = Config::get('watermark');
$return_data = ['watermark' => $iswatermark];
if ($iswatermark) {
$wmconfig = [
'watermark' => $iswatermark,
'mark_type' => Config::get('mark_type'),
'mark_image' => Config::get('mark_image'),
'mark_width_height' => Config::get('mark_width_height'),
'mark_text' => Config::get('mark_text'),
'mark_text_color' => Config::get('mark_text_color'),
'mark_degree' => Config::get('mark_degree'),
'mark_quality' => Config::get('mark_quality'),
'mark_position' => Config::get('mark_position'),
];
$imgresource = '.' . $return_url;
$image = Image::open($imgresource);
//$image->open($imgresource);
$return_data['mark_type'] = $wmconfig['mark_type'];
if ($image->width() > $wmconfig['mark_width_height']['width'] && $image->height() > $wmconfig['mark_width_height']['height']) {
$save_filename = $this->basePath . '/original_image' . substr($return_url, 8); //截取 /uploads 后的内容
if (!is_dir(dirname($save_filename))) {
mkdir(dirname($save_filename), 0777, true);
}
$image->save($save_filename, null, 100);
if ($wmconfig['mark_type'] == 'text') {
//$image->text($wmconfig['mark_text'],'./hgzb.ttf',20,'#000000',9)->save($imgresource);
$ttf = './hgzb.ttf';
if (file_exists($ttf)) {
$size = $wmconfig['mark_text_size'] ? $wmconfig['mark_text_size'] : 30;
$color = $wmconfig['mark_text_color'] ? : '#000000';
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
$color = '#000000';
}
$transparency = intval((100 - $wmconfig['mark_degree']) * (127 / 100));
$color .= dechex($transparency);
$image->open($imgresource)->text($wmconfig['mark_text'], $ttf, $size, $color, $wmconfig['mark_position'])->save($imgresource);
$return_data['mark_text'] = $wmconfig['mark_text'];
}
} else {
//$image->water('.'.$wmconfig['mark_img'],9,$wmconfig['mark_degree'])->save($imgresource);
$waterPath = '.' . $wmconfig['mark_image'];
$quality = $wmconfig['mark_quality'] ? $wmconfig['mark_quality'] : 80;
$waterTempPath = dirname($waterPath) . '/temp_' . basename($waterPath);
$image->open($waterPath)->save($waterTempPath, null, $quality);
$image->open($imgresource)->water($waterTempPath, $wmconfig['mark_position'], $wmconfig['mark_degree'])->save($imgresource);
@unlink($waterTempPath);
}
}
}
return $return_data;
}
/**
* 规则替换命名文件
* @param $path
* @return string
*/
private function getFullPath($path) {
//替换日期事件
$t = time();
$d = explode('-', date("Y-y-m-d-H-i-s"));
$format = $path;
$format = str_replace("{yyyy}", $d[0], $format);
$format = str_replace("{yy}", $d[1], $format);
$format = str_replace("{mm}", $d[2], $format);
$format = str_replace("{dd}", $d[3], $format);
$format = str_replace("{hh}", $d[4], $format);
$format = str_replace("{ii}", $d[5], $format);
$format = str_replace("{ss}", $d[6], $format);
$format = str_replace("{uid}", $this->user_id, $format);
return $format;
}
private function format_exts($exts) {
$data = array();
foreach ($exts as $key => $value) {
$data[] = ltrim($value, '.');
}
return $data;
}
}

281
app/admin/controller/User.php Executable file
View File

@@ -0,0 +1,281 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
class User extends BaseController {
public function index() {
$this->redirect('/admin/user/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['u.username'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$arg_where['u.stat'] = ['gt', '-1'];
$dataObject = Loader::model('User')->getPageLists($arg_where, null, ['u.*', 'ur.name' => 'role'], 24);
//$roleOption = Loader::model('UserRole')->getOption($user['role_id'], ['stat' => 0, 'id' => ['neq', $this->user_id == 1 ? 0 : 1]], ['id' => 'desc'], ['id', 'name',], 50);
$value = [
//'roleOption' => $roleOption,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function setting() {
if ($this->user_id) {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$data['id'] = $this->user_id;
$model = Loader::model('User')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success('操作成功,重新登录后信息会同步更新');
} else {
return $this->error(Lang::get('operation failed'));
}
}
$user = Loader::model('User')->getRow((int) $this->user_id);
if (empty($user)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['user'] = $user;
$this->assign($value);
return $this->fetch();
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
if ($id == 1 && !$this->administrator) {
return $this->error(Lang::get('incorrect operation'));
}
$user = Loader::model('User')->getRow(['id' => $id, 'stat' => ['gt', '-1']]);
if (empty($user)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['user'] = $user;
$roleOption = Loader::model('UserRole')->getOption($user['role_id'], ['stat' => 0, 'id' => ['neq', $this->administrator ? 0 : 1]], ['id' => 'desc'], ['id', 'name',], 50);
$value['roleOption'] = $roleOption;
$this->assign($value);
return $this->fetch();
} else {
return $this->fetch('add');
}
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'id' => 'require',
'username' => 'require|length:2,64|unique:user,username',
'role_id' => 'require|between:0,2147483647',
];
//验证提示信息
$validatemsg = [
'id.require' => 'ID参数错误',
'username.requier' => '用户名不能为空',
'username.unique' => '用户名已经被注册',
'username.length' => '用户名在2-64个字符之间',
'role_id.require' => '用户角色不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
if ($data['id'] == 1 && !$this->administrator) {
return $this->error(Lang::get('incorrect operation'));
}
$model = Loader::model('User')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function add() {
$roleOption = Loader::model('UserRole')->getOption(0, ['stat' => 0, 'id' => ['neq', $this->administrator ? 0 : 1]], ['id' => 'desc'], ['id', 'name',], 50);
$value = ['roleOption' => $roleOption,];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'username' => 'require|length:2,64|unique:user,username',
'password' => 'require|min:6',
'repassword' => 'require|confirm:password',
'role_id' => 'require|between:0,2147483647',
];
//验证提示信息
$validatemsg = [
'username.require' => '用户名不能为空',
'username.unique' => '用户名已经被注册',
'username.length' => '用户名在2-64个字符之间',
'password.require' => '密码不能为空',
'password.min' => '密码最低6个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
'role_id.require' => '用户角色不能为空',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$model = Loader::model('User')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('User')->deleteRow($id);
if ($result) {
if ($id == Session::get('user_auth.id')) {
Session::delete('user_auth', null);
Session::delete('user_auth_sign', null);
}
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = Loader::model('User')->deleteRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('User')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = Loader::model('User')->destroyRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatepassword() {
// echo 1;die;
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'id' => "require",
'newpassword' => 'require|min:6',
'repassword' => 'require|confirm:newpassword',
];
if (!$this->administrator) {
$validaterule['oldpassword'] = 'require|min:6';
}
//验证提示信息
$validatemsg = [
'id.require' => 'ID参数错误',
'oldpassword.require' => '密码不能为空',
'oldpassword.min' => '密码最低6个字符',
'newpassword.require' => '密码不能为空',
'newpassword.min' => '密码最低6个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$usersModel = Loader::model('User');
if (!$this->administrator) {
$user = $usersModel->find($this->user_id);
if (empty($user)) {
return $this->error(Lang::get('incorrect operation'));
}
if ($user['password'] != md5($data['oldpassword'])) {
return $this->error('旧密码输入错误');
}
$data['id'] = $this->user_id;
}
$model = $usersModel->updatePassword($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/user/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('operation failed'));
}
}

181
app/admin/controller/UserRole.php Executable file
View File

@@ -0,0 +1,181 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class UserRole extends BaseController {
public function index() {
$this->redirect('/admin/user_role/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('stat' => 0, 'id' => ['neq', 1]);
$arg_order = array('id' => 'desc');
$arg_field = array('id', 'name', 'rbac_acl', 'description', 'stat');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('UserRole')->getPageList($arg_where, $arg_order, $arg_field, 24);
//$roleOption = Loader::model('UserRole')->getOption(0, $arg_where, $arg_order, ['id', 'name',], 50);
$value = [
//'roleOption' => $roleOption,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$user_role = Loader::model('UserRole')->getRow($id);
if (empty($user_role)) {
return $this->error(Lang::get('incorrect operation'));
}
$user_role['rbac_acl'] = explode(',', $user_role['rbac_acl']);
$value['user_role'] = $user_role;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$auth_group_list = Loader::model('AuthGroup')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name',]);
$auth_access_list = Loader::model('AuthAccess')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name', 'gid',]);
$access_list = [];
foreach ($auth_access_list as $k => $val) {
$access_list[$val['gid']][] = $val;
}
$value['access_list'] = $access_list;
$value['group_list'] = $auth_group_list;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:user_role,name', 'description' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$role_row['rbac_acl'] = is_array($data['acl']) ? implode(',', $data['acl']) : '';
if (empty($role_row['rbac_acl'])) {
return $this->error("请选择权限!");
}
$role_row['id'] = $data['id'];
$role_row['name'] = $data['name'];
$role_row['description'] = $data['description'];
$role_row['yesorno'] = $data['yesorno'];
$model = Loader::model('UserRole')->updateRow($role_row);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/user_role/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function add() {
$auth_group_list = Loader::model('AuthGroup')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name',], 24);
$auth_access_list = Loader::model('AuthAccess')->getList(['stat' => 0], ['id' => 'asc'], ['id', 'name', 'gid',], 24);
$access_list = [];
foreach ($auth_access_list as $k => $val) {
$access_list[$val['gid']][] = $val;
}
$value['access_list'] = $access_list;
$value['group_list'] = $auth_group_list;
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
} else {
foreach ($data as $k => $v) {
if (is_string($v)) {
$data[$k] = trim($v);
}
}
}
$validaterule = ['name' => 'require|unique:user_role,name', 'description' => 'require', 'agree' => 'require|accepted',];
$validatemsg = ['name.require' => '名称不能为空', 'name.unique' => '名称已存在', 'description.require' => '描述不能为空',
'agree.require' => '请勾选确认框', 'agree.accepted' => '请勾选确认框',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$role_row['rbac_acl'] = is_array($data['acl']) ? implode(',', $data['acl']) : '';
if (empty($role_row['rbac_acl'])) {
return $this->error("请选择权限!");
}
$role_row['name'] = $data['name'];
$role_row['description'] = $data['description'];
$role_row['yesorno'] = $data['yesorno'];
$model = Loader::model('UserRole')->insertRow($role_row);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/user_role/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = Loader::model('UserRole')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/user_role/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
$in_ids = explode(',', trim($ids, ','));
if ($this->request->isPost() && $in_ids) {
$result = Loader::model('UserRole')->deleteRows($in_ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/user_role/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

569
app/admin/controller/Video.php Executable file
View File

@@ -0,0 +1,569 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Video extends BaseController {
public function index() {
$this->redirect('/admin/video/lists');
}
private function init_search(&$search)
{
$search['name'] = '';
$search['tags'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists() {
$data = $this->request->param();
$cid = isset($data['cid']) ? intval($data['cid']) : 0;
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != '')
{
$arg_where['a.name'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if (isset($data['tags']) && $data['tags'] != '')
{
$arg_where['a.tags'] = ['like', "%$data[tags]%"];
$search['tags'] = $data['tags'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != ''))
{
// 时间有一个不为空就初始化
$arg_where['a.createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = strtotime($data['timebegin']);
array_push($arg_where['a.createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = strtotime($data['timeend']);
array_push($arg_where['a.createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
}
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if ($cid > 0) {
$arg_where['a.cid'] = $cid;
}
$dataObject = model('video')->getCategoryVideoLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($cid, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add($cid = 0) {
$cid = is_numeric($cid) ? intval($cid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['user_id'] = $this->user_id;
$data['country_code'] = $this->country_code;
$model = model('video')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$video = model('video')->getRow($id);
if (empty($video)) {
return $this->error(lang::get('incorrect operation'));
}
$value['video'] = $video;
} else {
return $this->error(lang::get('incorrect operation'));
}
$cid = isset($video['cid']) ? $video['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$model = model('video')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function modallists() {
$inputid = $this->request->param('inputid', '', 'urldecode');
$titleid = $this->request->param('titleid', '', 'urldecode');
$callback = $this->request->param('callback', '', 'urldecode');
$filter_name = $this->request->param('filter_name', '', 'urldecode');
$arg_where = array('stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'desc');
$arg_field = array('id', 'name', 'tags', 'picture', 'videopath','videourl',);
if (!empty($filter_name)) {
$arg_where['name'] = ['like', '%' . trim($filter_name) . '%'];
}
Config::set('url_common_param', true);
Config::set('paginate.query', array_filter(['inputid' => $inputid, 'titleid' => $titleid, 'callback' => $callback, 'filter_name' => $filter_name])); //分页参数
$dataObject = model('video')->getPageList($arg_where, $arg_order, $arg_field, 12, false);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'total' => $dataObject->total(),
'inputid' => $inputid,
'titleid' => $titleid,
'callback' => $callback,
'filter_name' => $filter_name,
];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('video')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleheadline() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video')->updateRow(['id' => $id, 'headline' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$video = model('video')->getRow($id);
if (empty($video)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['video'] = $video;
//$value['goods'] = Loader::model('Product')->getRow($video['product']);
} else {
return $this->error(Lang::get('incorrect operation'));
}
$cid = isset($video['cid']) ? $video['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function movecategory() {
$cid = $this->request->post('cid', 0);
$ids = $this->request->post('ids');
$cid = intval($cid);
if ($this->request->isPost() && $cid && $ids) {
$result = model('video')->updateRows(['cid' => $cid], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('video')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('video')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('video')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name|a.tags'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('video')->getRecycleLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('video')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recoverys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('video')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('video')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('video')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/video/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function export() {
$arg_where = ['a.stat' => 0, 'a.siteid' => $this->siteid, 'country_code' => $this->country_code];
$data = $this->request->param();
if (isset($data['name']) && $data['name']) {
$arg_where['a.name'] = ['like', '%' . $data['name'] . '%'];
$search['name'] = $data['name'];
} else {
$search['name'] = '';
}
if (isset($data['cid']) && $data['cid']) {
$childIDArray = city(session('cit'),'product_category')->getChildIDArray($data['cid']);
$arg_where['a.cid'] = count($childIDArray) == 1 ? $data['cid'] : ['in', $childIDArray];
$search['cid'] = $data['cid'];
} else {
$search['cid'] = 0;
}
if (isset($data['tags']) && $data['tags']) {
$arg_where['a.tags'] = ['like', '%' . $data['tags'] . '%'];
$search['tags'] = $data['tags'];
} else {
$search['tags'] = '';
}
$search['timebegin'] = isset($data['timebegin']) ? strtotime($data['timebegin']) : 0;
$search['timeend'] = isset($data['timeend']) ? strtotime($data['timeend']) : 0;
if ($search['timeend'] - $search['timebegin'] > 0) {
$arg_where['a.createtime'] = ['between', [$search['timebegin'], $search['timeend']]];
} else {
if ($search['timebegin'] > 0 && empty($search['timeend'])) {
$arg_where['a.createtime'] = ['gt', $search['timebegin']];
}
}
if (!empty($data['field'])) {
$fields = $data['field'];
} else {
$fields = array('id' => 'ID', 'cid' => '视频分类', 'name' => '视频名称', 'description' => '视频描述', 'createtime' => '发布时间');
}
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($search['cid'], $argc_where, $argc_order, $argc_field, 100);
if (empty($data['submit'])) {
$value = ['categoryOptions' => $categoryOptions, 'fields' => $fields];
$this->assign($value);
return $this->fetch();
}
$arg_order = ['a.cid' => 'asc', 'a.sort' => 'asc', 'a.id' => 'asc'];
$arg_field = array_map(function($value) {
return 'a.' . $value;
}, array_keys($fields));
$arg_field['c.id'] = 'categoryid';
$arg_field['c.name'] = 'categoryname';
$arg_field['c.pid'] = 'pid';
set_time_limit(36000);
ini_set('memory_limit', '512M');
$total = model('video')->getExportSearchProductLists($arg_where, $arg_order, null, true);
$page_size = 1000;
$totalpage = ceil($total / $page_size);
$sheet_size = 5 * $page_size;
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
Loader::import('phpexcel.Classes.PHPExcel', EXTEND_PATH);
Loader::import('phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
$objPHPExcel = new \PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Call of Duty")
->setLastModifiedBy("Call of Duty")
->setTitle("Office 2007 XLSX Cod Document")
->setSubject("Office 2007 XLSX Cod Document")
->setDescription("Cod document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Cod result file");
$page = 0;
$sheet = 0;
do {
$start_index = $page * $page_size;
$datainfo = model('video')->getExportSearchProductLists($arg_where, $arg_order, [$start_index, $page_size], false, $arg_field);
// echo \think\Db::table('video')->getLastSql();die;
// tiaoshi($datainfo);die;
if (!empty($datainfo)) {
if (($start_index % $sheet_size) == 0) {
if ($sheet) {
$objPHPExcel->createSheet();
}
$sheet++;
$i = 0;
foreach ($fields as $key => $value) {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . '1', $value);
$i++;
}
$objPHPExcel->getActiveSheet()->setTitle('sheet' . $sheet);
$index = 1;
}
foreach ($datainfo as $value) {
if (isset($value['createtime'])) {
$value->data('createtime', date('Y-m-d H:i:s', $value['createtime']));
}
if (isset($value['cid'])) {
$value->data('cid', $value['categoryname']);
}
$index++;
$i = 0;
foreach ($fields as $key => $field) {
if ($key == 'picture') {
$image = '.' . $this->request->root() . $value['picture'];
if (@fopen($image, 'r')) {
$objDrawing = new \PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($image);
$objDrawing->setHeight(50);
$objDrawing->setWidth(50);
$objDrawing->setCoordinates($cellName[$i] . $index);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
}
} else {
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . $index, $value[$key]);
}
$i++;
}
}
usleep(10000);
}
$page++;
if ($page > 650) {
break;
}
} while ($page < $totalpage);
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client's web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
}

View File

@@ -0,0 +1,296 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class VideoCategory extends BaseController {
public function index() {
$this->redirect('/admin/video_category/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$category_list = model('video_category')->getCategoryLists($arg_where, $arg_order, $arg_field, 24);
$value = ['list' => $category_list, 'pid' => 0, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('video_category')->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions, 'pid' => $pid];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$categoryModel = model('video_category');
if (isset($data['pid']) && $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/video_category/lists'));
//return $this->success(Lang::get('operation successed'), url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$categoryModel = model('video_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['video_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$categoryModel = model('video_category');
$id = intval($id);
if ($id > 0) {
$category = $categoryModel->getRow($id);
if (empty($category)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['video_category'] = $category;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$pid = isset($category['pid']) ? $category['pid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = $categoryModel->getCategoryOptions($pid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['pid'] = $pid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require', 'pid' => 'number|between:0,2147483647',];
$validatemsg = ['name.require' => '名称不能为空', 'pid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$oldpid = $data['oldpid'];
unset($data['oldpid']);
$categoryModel = model('video_category');
$childIDArray = $categoryModel->getChildIDArray($data['id']);
if (in_array($data['pid'], $childIDArray)) {
return $this->error('不可选择自己的子节点作为父节点');
}
if (isset($data['pid']) && $data['pid'] && $oldpid != $data['pid']) {
$categoryModel::update(['haschild' => 1], ['id' => $data['pid'], 'haschild' => 0]);
}
$model = $categoryModel->updateRow($data);
if (isset($oldpid) && $oldpid && $oldpid != $data['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $oldpid]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $oldpid, 'haschild' => 1]);
}
}
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function subcolumn() {
$column = $this->request->get('subcolumn/s', '', 'urldecode');
$columns = explode(',', $column);
$arg_where = array('pid' => 0, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$category_list = model('video_category')->getCategoryTree($arg_where, $arg_order, $arg_field, 20);
$value = ['list' => $category_list, 'columns' => $columns,];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function listcategory($pid = 0) {
$pid = is_numeric($pid) ? intval($pid) : 0;
$categoryModel = model('video_category');
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = $categoryModel->getList($arg_where, $arg_order, $arg_field, 50);
$category_breadcrumb = $categoryModel->getBreadCrumb($pid);
$value = ['list' => $category_list, 'pid' => $pid, 'breadcrumb' => $category_breadcrumb, 'level' => 0];
$this->assign($value);
return $this->fetch();
}
public function childcat($pid = 0) {
$pid = $this->request->get('pid', 0);
$level = $this->request->get('level', 1);
//$pid = is_numeric($pid) ? intval($pid) : 0;
$arg_where = array('pid' => $pid, 'stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort', 'isshow', 'recommend', 'picture');
$category_list = model('video_category')->getList($arg_where, $arg_order, $arg_field, 50);
$value = ['list' => $category_list, 'pid' => $pid, 'level' => $level + 1];
$this->assign($value);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
if ($id && $sort < 2147483647) {
$model = model('video_category')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video_category')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video_category')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('video_category')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/video_category/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$row = model('video')->getRow(['cid' => $id, 'stat' => 0], ['id', 'name']);
if ($row) {
return $this->error('此节点包含内容[ID:' . $row['id'] . '名称:' . $row['name'] . '],不能进行删除');
}
$categoryModel = model('video_category');
$category = $categoryModel->getRow(['id' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($category && $category['haschild']) {
$child = $categoryModel->getRow(['pid' => $id, 'stat' => 0], ['id', 'pid', 'haschild', 'name']);
if ($child) {
return $this->error('此节点包含子节点[ID:' . $child['id'] . '],不能进行删除');
}
}
if ($category && $category['pid']) {
$oneObject = $categoryModel->getRow(['stat' => 0, 'pid' => $category['pid'], 'id' => ['neq', $category['id']]]);
if (!$oneObject) {
$categoryModel::update(['haschild' => 0], ['id' => $category['pid'], 'haschild' => 1]);
}
}
$result = $categoryModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,733 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use image\Image;
use pagination\Pagination;
class Webuploader extends BaseController {
private $basePath = '/';
private $saveDirectory = 'default';
private $num = '10';
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Shanghai");
$this->docDir = $this->request->server('DOCUMENT_ROOT');
$this->rootDir = $this->request->root();
$this->basePath = $this->docDir . $this->rootDir . '/uploads';
$this->saveDirectory = '';
error_reporting(E_ERROR | E_WARNING);
Config::set('url_common_param', true);
header("Content-Type: text/html; charset=utf-8");
}
public function show() {
$filter_name = $this->request->get('filter_name', '', 'urldecode');
if (!empty($filter_name)) {
$filter_name = trim(str_replace(['/../', '../', '*'], '', $filter_name), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
$type = $this->request->get('type', '');
$target = $this->request->get('target', '');
$thumb = $this->request->get('thumb', '');
$func = $this->request->get('func', 'undefined');
$num = $this->request->get('num/d', 1);
$url = array();
$url['target'] = $target;
$data['target'] = $target;
$url['thumb'] = $thumb;
$data['thumb'] = $thumb;
$url['type'] = $type;
$data['type'] = $type;
$url['func'] = $func;
$data['func'] = $func;
$url['num'] = $num;
$data['num'] = $num;
//Config::set('url_common_param', true);
//$config = Config::get('paginate');
$page = $this->request->request('page/d', 1);
$page = $page < 1 ? 1 : $page;
$directories = array();
$files = array();
$data['images'] = array();
if (mb_substr($directory . '/' . $filter_name, 0, mb_strlen($this->basePath)) == $this->basePath) {
// Get directories
$directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR);
if (!$directories) {
$directories = array();
}
switch ($type) {
case 'image':
// Get files
$files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE);
break;
case 'video':
// Get files
$files = glob($directory . '/' . $filter_name . '*.{avi,mp4,rmvb,mkv,wmv,ogg,webm,AVI,MP4,RMVB,MKV,WMV,OGG,WEBM}', GLOB_BRACE);
break;
case 'file':
// Get files
$files = glob($directory . '/' . $filter_name . '*.*', GLOB_BRACE);
break;
default:
break;
}
if (!$files) {
$files = array();
}
}
// Merge directories and files
$images = array_merge(array_diff($directories, [$this->basePath . '/smallimg', $this->basePath . '/allimg']), $files);
// Get total number of files and directories
$image_total = count($images);
// Split the array based on current page number and max number of items per page of 10
$images = array_splice($images, ($page - 1) * 16, 16);
foreach ($images as $image) {
$name = str_split(basename($image), 24);
if (is_dir($image)) {
$path = mb_substr($image, mb_strlen($this->docDir . $this->rootDir));
$url['directory'] = urlencode(mb_substr($image, mb_strlen($this->basePath)));
$data['images'][] = array(
'thumb' => '',
'name' => implode(' ', $name),
'type' => 'directory',
'path' => $path,
'href' => url('/admin/webuploader/show', array_filter($url), true)
);
} elseif (is_file($image)) {
$path = mb_substr($image, mb_strlen($this->docDir . $this->rootDir));
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
switch ($ext) {
case 'jpg': case 'png': case 'gif': case 'bmp': case 'jpeg':
$data['images'][] = array(
'thumb' => $path,
'name' => implode(' ', $name),
'type' => 'image',
'path' => $path,
'href' => $this->request->domain() . $path
);
break;
case 'html': case 'htm': case 'js': case 'php': case 'txt':
$data['images'][] = array(
'thumb' => $path,
'name' => implode(' ', $name),
'type' => 'text',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
case 'avi': case 'mp4': case 'rmvb': case 'mkv': case 'wmv': case 'ogg': case 'webm':
$data['images'][] = array(
'thumb' => $path,
'name' => implode(' ', $name),
'type' => 'video',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
case 'zip': case 'rar': case 'gz': case 'tar': case 'tgz': case 'gz': case 'iso':
$data['images'][] = array(
'thumb' => $path,
'name' => implode(' ', $name),
'type' => 'archive',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
default:
$data['images'][] = array(
'thumb' => $path,
'name' => implode(' ', $name),
'type' => 'other',
'path' => $path,
'href' => 'javascript:void(0);'
);
break;
}
}
}
$data['filter_name'] = $filter_name;
$url['directory'] = urlencode($relativepath);
$data['directory'] = urlencode($relativepath);
//Upload
$data['webuploader'] = url('/admin/webuploader/modal', array_filter($url), true);
// Refresh
$data['refresh'] = url('/admin/webuploader/show', array_filter($url), true);
if (!empty($relativepath)) {
$pos = strrpos($relativepath, '/');
if ($pos) {
$url['directory'] = urlencode(mb_substr($relativepath, 0, $pos));
} else {
$url['directory'] = '';
}
}
// Parent
if (!empty($relativepath)) {
$pos = strrpos($relativepath, '/');
if ($pos) {
$url['directory'] = urlencode(mb_substr($relativepath, 0, $pos));
} else {
$url['directory'] = '';
}
}
$data['parent'] = url('/admin/webuploader/show', array_filter($url), true);
//Pagination
if (!empty($relativepath)) {
$url['directory'] = urlencode($relativepath);
}
if (!empty($filter_name)) {
$url['filter_name'] = urlencode($filter_name);
}
$url['page'] = '{page}';
$pagination = new Pagination();
$pagination->total = $image_total;
$pagination->page = $page;
$pagination->limit = 16;
$pagination->url = url('/admin/webuploader/show', array_filter($url), true);
$data['pagination'] = $pagination->render();
$this->assign($data);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function modal() {
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$func = $this->request->get('func', 'undefined');
$num = $this->num;
$type = $this->request->get('type', '');
$target = $this->request->get('target', '');
$thumb = $this->request->get('thumb', '');
$url = array();
$url['target'] = $target;
$data['target'] = $target;
$url['thumb'] = $thumb;
$data['thumb'] = $thumb;
$url['type'] = $type;
$data['type'] = $type;
$url['func'] = $func;
$data['func'] = $func;
$url['num'] = $num;
$data['num'] = $num;
//$url['directory'] = urlencode($relativepath);
//$data['directory'] = urlencode($relativepath);
$url['directory'] = $relativepath;
$data['directory'] = $relativepath;
//Uploadiframe
$data['uploadiframe'] = url('/admin/webuploader/uploadiframe', array_filter($url), true);
//Webuploader
$data['webuploader'] = url('/admin/webuploader/modal', array_filter($url), true);
// Refresh
$data['refresh'] = url('/admin/webuploader/show', array_filter($url), true);
// Parent
if (!empty($relativepath)) {
$pos = strrpos($relativepath, '/');
if ($pos) {
$url['directory'] = urlencode(mb_substr($relativepath, 0, $pos));
} else {
$url['directory'] = '';
}
}
$data['parent'] = url('/admin/webuploader/show', array_filter($url), true);
//url
$data['filter_name'] = '';
$this->assign($data);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]);
return $this->fetch();
}
public function uploadiframe() {
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$func = $this->request->get('func', 'undefined');
//$num = $this->request->get('num/d', 1);
$num = $this->num;
$type = $this->request->get('type', '');
$target = $this->request->get('target', '');
$thumb = $this->request->get('thumb', '');
$url = array();
//$url['target'] = $target;
$data['target'] = $target;
//$url['thumb'] = $thumb;
$data['thumb'] = $thumb;
//$url['type'] = $type;
$data['type'] = $type;
//$url['func'] = empty($func) ? 'undefined' : $func;
$data['func'] = empty($func) ? 'undefined' : $func;
//$url['num'] = $num;
$data['num'] = $num;
$url['directory'] = urlencode($relativepath);
$data['directory'] = urlencode($relativepath);
if ($type == 'image') {
$data['uploadurl'] = url('/admin/webuploader/imageupload', array_filter($url), true);
$data['deleteurl'] = url('/admin/webuploader/deluploadimage', array_filter($url), true);
$data['ext'] = 'jpg,png,gif,jpeg';
//$data['mimetype']='jpg,png,gif,jpeg';
} else {
$data['uploadurl'] = url('/admin/webuploader/fileupload', array_filter($url), true);
$data['deleteurl'] = url('/admin/webuploader/deluploadfile', array_filter($url), true);
$data['ext'] = '*';
//$data['mimetype']='*/*';
}
$this->assign($data);
Config::set('default_ajax_return', 'html');
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
$content = $this->fetch();
$tpl_replace_string = $this->view->engine->config('tpl_replace_string');
return str_replace(array_keys($tpl_replace_string), array_values($tpl_replace_string), $content);
}
public function imageupload() {
// 上传图片框中的描述表单名称,
$title = $this->request->get('pictitle');
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$this->saveDirectory = $relativepath? : 'default';
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file');
// if (empty($file))
// $file = request()->file('upfile');
$image_upload_limit_size = Config::get('image_upload_limit_size');
$result = $this->validate(
['file' => $file], ['file' => 'image|fileSize:' . $image_upload_limit_size . '|fileExt:jpg,jpeg,gif,png'], ['file.image' => '上传文件必须为图片', 'file.fileSize' => '上传文件过大', 'file.fileExt' => '上传文件后缀名必须为jpg,jpeg,gif,png']
);
if (true !== $result || !$file) {
$state = "ERROR " . $result;
} else {
$saveDirectory = $this->saveDirectory . '/' . date('Y/md') . '/';
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->move($this->basePath . '/' . $saveDirectory, false);
if ($info) {
$state = "SUCCESS";
} else {
$state = "ERROR " . $file->getError();
}
$return_url = '/uploads/' . $saveDirectory . $info->getFilename();
$return_data['url'] = str_replace('\\', '/', $return_url);
}
if ($state == 'SUCCESS') {
$this->watermark($return_url);
}
$return_data['title'] = $title;
$return_data['original'] = ''; // 这里好像没啥用 暂时注释起来
$return_data['state'] = $state;
$return_data['directory'] = $this->saveDirectory;
echo json_encode($return_data);
exit;
}
public function fileupload() {
// 上传图片框中的描述表单名称,
$title = $this->request->get('pictitle');
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
}
$this->saveDirectory = $relativepath? : 'default';
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file');
// if (empty($file))
// $file = request()->file('upfile');
$file_upload_limit_size = Config::get('file_upload_limit_size');
$result = $this->validate(
['file' => $file], ['file' => 'fileSize:' . $file_upload_limit_size], ['file.fileSize' => '上传文件过大']
);
if (true !== $result || !$file) {
$state = "ERROR " . $result;
} else {
$saveDirectory = $this->saveDirectory . '/' . date('Y/md') . '/';
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->move($this->basePath . '/' . $saveDirectory, false);
if ($info) {
$state = "SUCCESS";
} else {
$state = "ERROR " . $file->getError();
}
$return_url = '/uploads/' . $saveDirectory . $info->getFilename();
$return_data['url'] = str_replace('\\', '/', $return_url);
}
$return_data['title'] = $title;
$return_data['state'] = $state;
$return_data['directory'] = $this->saveDirectory;
echo json_encode($return_data);
exit;
}
/*
删除上传的图片
*/
public function deluploadimage() {
$action = $this->request->get('action', 'del');
$filename = $this->request->get('filename');
$filename = empty($filename) ? $this->request->get('url') : $filename;
// $filename = str_replace('../', '', $filename);
// $filename = trim($filename, "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$filename = trim(str_replace('../', '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$filename = './' . $filename;
if ($action == 'del' && !empty($filename) && is_file($filename)) {
$size = getimagesize($filename);
$filetype = explode('/', $size['mime']);
if ($filetype[0] != 'image') {
exit(0);
}
if (unlink($filename)) {
echo 1;
} else {
echo 0;
}
}
exit;
}
/*
删除上传的文件
*/
public function deluploadfile() {
$action = $this->request->get('action', 'del');
$filename = $this->request->get('filename');
$filename = empty($filename) ? $this->request->get('url') : $filename;
// $filename = str_replace('../', '', $filename);
// $filename = trim($filename, "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$filename = trim(str_replace('../', '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$filename = './' . $filename;
if ($action == 'del' && !empty($filename) && is_file($filename)) {
if (unlink($filename)) {
echo 1;
} else {
echo 0;
}
}
exit;
}
public function preview() {
// 此页面用来协助 IE6/7 预览图片,因为 IE 6/7 不支持 base64
$DIR = 'preview';
// Create target dir
if (!file_exists($DIR)) {
@mkdir($DIR);
}
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
if ($cleanupTargetDir) {
if (!is_dir($DIR) || !$dir = opendir($DIR)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
}
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $DIR . DIRECTORY_SEPARATOR . $file;
// Remove temp file if it is older than the max age and is not the current file
if (@filemtime($tmpfilePath) < time() - $maxFileAge) {
@unlink($tmpfilePath);
}
}
closedir($dir);
}
$src = file_get_contents('php://input');
if (preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)) {
$previewUrl = sprintf(
"%s://%s%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']
);
$previewUrl = str_replace("preview.php", "", $previewUrl);
$base64 = $matches[2];
$type = $matches[1];
if ($type === 'jpeg') {
$type = 'jpg';
}
$filename = md5($base64) . ".$type";
$filePath = $DIR . DIRECTORY_SEPARATOR . $filename;
if (file_exists($filePath)) {
die('{"jsonrpc" : "2.0", "result" : "' . $previewUrl . 'preview/' . $filename . '", "id" : "id"}');
} else {
$data = base64_decode($base64);
file_put_contents($filePath, $data);
die('{"jsonrpc" : "2.0", "result" : "' . $previewUrl . 'preview/' . $filename . '", "id" : "id"}');
}
} else {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "un recoginized source"}}');
}
}
public function upload() {
$json = array();
// Make sure we have the correct directory
$relativepath = $this->request->get('directory', '', 'urldecode');
if (!empty($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
// Check its a directory
if (!is_dir($directory) || mb_substr($directory, 0, mb_strlen($this->basePath)) != $this->basePath) {
$json['error'] = '路径错误';
}
if (!$json) {
$file_upload_limit_size = Config::get('file_upload_limit_size');
// Check if multiple files are uploaded or just one
//获取上传的文件类型
//$type = $this->request->get('type', '');
// 获取表单上传文件
$files = $this->request->file('file');
foreach ($files as $k => $file) {
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['size' => $file_upload_limit_size])->move($directory, false);
if ($info) {
// 成功上传后 获取上传信息
$ext = strtolower($info->getExtension());
if (in_array($ext, ['gif', 'jpg', 'jpeg', 'png', 'bmp'])) {
$image_upload_limit_size = Config::get('image_upload_limit_size');
$chick = $info->getInfo();
if ($chick['size']>=$image_upload_limit_size) {
$json['success'] = "文件大小超过1M";
} else {
$this->watermark('/uploads/' . $relativepath . '/' . $info->getFilename());
}
}
} else {
// 上传失败获取错误信息
$json['error'] = '';
$json['error'] .= '文件' . $k . $file->getError();
}
}
}
if (!$json) {
$json['success'] = '文件上传成功';
}
echo json_encode($json);
exit;
}
public function folder() {
$json = array();
// Make sure we have the correct directory
$relativepath = $this->request->get('directory', '', 'urldecode');
if (isset($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
// Check its a directory
if (!is_dir($directory) || mb_substr($directory, 0, mb_strlen($this->basePath)) != $this->basePath) {
$json['error'] = '路径错误';
echo json_encode($json);
exit;
}
if ($this->request->isPost()) {
// Sanitize the folder name
$folder = basename($this->request->post('folder', '', 'urldecode'));
// Validate the filename length
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $folder)) {
$json['error'] = $folder . '文件夹名称不是由数字字母下划线组成';
echo json_encode($json);
exit;
}
// Validate the filename length
if ((mb_strlen($folder) < 3) || (mb_strlen($folder) > 128)) {
$json['error'] = $folder . '文件夹长度错误';
echo json_encode($json);
exit;
}
// Check if directory already exists or not
if (is_dir($directory . '/' . $folder)) {
$json['error'] = $folder . '文件夹已存在';
echo json_encode($json);
exit;
}
}
if (!isset($json['error'])) {
mkdir($directory . '/' . $folder, 0777);
chmod($directory . '/' . $folder, 0777);
@touch($directory . '/' . $folder . '/' . 'index.html');
$json['success'] = '文件夹创建成功';
}
echo json_encode($json);
exit;
}
public function rename() {
$json = array();
// Make sure we have the correct directory
$relativepath = $this->request->get('directory', '', 'urldecode');
if (isset($relativepath)) {
$relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
$directory = $this->basePath . '/' . $relativepath;
} else {
$directory = $this->basePath;
}
// Check its a directory
if (!is_dir($directory) || mb_substr($directory, 0, mb_strlen($this->basePath)) != $this->basePath) {
$json['error'] = '路径错误';
echo json_encode($json);
exit;
}
if ($this->request->isPost()) {
// Sanitize the folder name
$path = $this->request->post('path', '', 'urldecode');
$pathinfo = pathinfo($path);
$filenewname = $this->request->post('filenewname', '', 'urldecode');
// Validate the filename length
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $filenewname)) {
$json['error'] = $filenewname . '文件名称不是由数字字母下划线组成';
echo json_encode($json);
exit;
}
// Validate the filename length
if ((mb_strlen($filenewname) < 3) || (mb_strlen($filenewname) > 128)) {
$json['error'] = $filenewname . '文件名长度错误,至少3个字符以上';
echo json_encode($json);
exit;
}
// Check if directory already exists or not
if (!file_exists($directory . '/' . $pathinfo['basename']) || !(file_exists('.' . $path))) {
$json['error'] = $pathinfo['filename'] . '文件不存在';
echo json_encode($json);
exit;
}
if (!isset($json['error'])) {
rename('.' . $path, $directory . '/' . $filenewname . ($pathinfo['extension'] ? '.' . $pathinfo['extension'] : ''));
$json['success'] = '文件重命名成功';
}
}
echo json_encode($json);
exit;
}
public function delete() {
$json = array();
$paths = $this->request->post();
if (isset($paths['path'])) {
$paths = $paths['path'];
} else {
$paths = array();
}
// Loop through each path to run validations
foreach ($paths as $path) {
$path = trim(str_replace(['/../', '../', '*'], '', $path), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
// Check path exsists
if ($path == 'uploads' || mb_substr($this->docDir . $this->rootDir . '/' . $path, 0, mb_strlen($this->basePath)) != $this->basePath) {
$json['error'] = '删除错误';
break;
}
}
if (!$json) {
// Loop through each path
foreach ($paths as $path) {
$path = $this->docDir . $this->rootDir . '/' . trim(str_replace(['/../', '../', '*'], '', $path), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F");
// If path is just a file delete it
if (is_file($path)) {
unlink($path);
// If path is a directory beging deleting each file and sub folder
} elseif (is_dir($path)) {
$files = array();
// Make path into an array
$path = array($path . '*');
// While the path array is still populated keep looping through
while (count($path) != 0) {
$next = array_shift($path);
foreach (glob($next) as $file) {
// If directory add to path array
if (is_dir($file)) {
$path[] = $file . '/*';
}
// Add the file to the files to be deleted array
$files[] = $file;
}
}
// Reverse sort the file array
rsort($files);
foreach ($files as $file) {
// If file just delete
if (is_file($file)) {
unlink($file);
// If directory use the remove directory function
} elseif (is_dir($file)) {
rmdir($file);
}
}
}
}
$json['success'] = '删除成功';
}
echo json_encode($json);
exit;
}
public function watermark($return_url = '/uploads/nopic.jpg') {
$iswatermark = Config::get('watermark');
$return_data = ['watermark' => $iswatermark];
if ($iswatermark) {
$wmconfig = [
'watermark' => $iswatermark,
'mark_type' => Config::get('mark_type'),
'mark_image' => Config::get('mark_image'),
'mark_width_height' => Config::get('mark_width_height'),
'mark_text' => Config::get('mark_text'),
'mark_text_color' => Config::get('mark_text_color'),
'mark_degree' => Config::get('mark_degree'),
'mark_quality' => Config::get('mark_quality'),
'mark_position' => Config::get('mark_position'),
];
$imgresource = '.' . $return_url;
$image = Image::open($imgresource);
//$image->open($imgresource);
$return_data['mark_type'] = $wmconfig['mark_type'];
if ($image->width() > $wmconfig['mark_width_height']['width'] && $image->height() > $wmconfig['mark_width_height']['height']) {
$save_filename = $this->basePath . '/original_image' . mb_substr($return_url, 8); //截取 /uploads 后的内容
if (!is_dir(dirname($save_filename))) {
mkdir(dirname($save_filename), 0777, true);
}
$image->save($save_filename, null, 100);
if ($wmconfig['mark_type'] == 'text') {
//$image->text($wmconfig['mark_text'],'./hgzb.ttf',20,'#000000',9)->save($imgresource);
$ttf = './hgzb.ttf';
if (file_exists($ttf)) {
$size = $wmconfig['mark_text_size'] ? $wmconfig['mark_text_size'] : 30;
$color = $wmconfig['mark_text_color'] ? : '#000000';
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
$color = '#000000';
}
$transparency = intval((100 - $wmconfig['mark_degree']) * (127 / 100));
$color .= dechex($transparency);
$image->open($imgresource)->text($wmconfig['mark_text'], $ttf, $size, $color, $wmconfig['mark_position'])->save($imgresource);
$return_data['mark_text'] = $wmconfig['mark_text'];
}
} else {
//$image->water('.'.$wmconfig['mark_img'],9,$wmconfig['mark_degree'])->save($imgresource);
$waterPath = '.' . $wmconfig['mark_image'];
$quality = $wmconfig['mark_quality'] ? $wmconfig['mark_quality'] : 80;
$waterTempPath = dirname($waterPath) . '/temp_' . basename($waterPath);
$image->open($waterPath)->save($waterTempPath, null, $quality);
$image->open($imgresource)->water($waterTempPath, $wmconfig['mark_position'], $wmconfig['mark_degree'])->save($imgresource);
@unlink($waterTempPath);
}
}
}
return $return_data;
}
}

31
app/admin/model/ActionLog.php Executable file
View File

@@ -0,0 +1,31 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ActionLog extends Model {
use \app\common\traits\AdminModel;
public function getPageLists($where = null, $order = null, $field = null, $limit = null, $level = 0) {
$this->alias('al')->join('user u', 'al.user_id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$object = $this->paginate($limit);
return $object;
}
}

46
app/admin/model/Ad.php Executable file
View File

@@ -0,0 +1,46 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Ad extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
protected $update = [];
public function getAdLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('b')->join('ad_type bt', 'b.typeid=bt.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['b.stat' => 0], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

109
app/admin/model/AdType.php Executable file
View File

@@ -0,0 +1,109 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class AdType extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id])->field('id')->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = self::getChildIDArray($val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
$options.=self::getOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

84
app/admin/model/Agents.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Agents extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getAgentLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getAgentList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

147
app/admin/model/Article.php Executable file
View File

@@ -0,0 +1,147 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Article extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['updatetime'];
protected $update = ['updatetime'];
public function getCategoryArticleList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getArticleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')
->join('article_category c', 'a.cid=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getExportSearchArticleLists($where = null, $order = 'id', $limit = null, $count = false, $field = '*') {
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
if (is_array($where)) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
//$object->fetchsql(true);
if ($count) {
$result = $this->count();
return $result;
}
if ($field) {
$this->field($field);
}
if ($limit) {
if (is_array($limit)) {
//$limit = ['offset' => 1, 'length' => 1];
$limit = array_values($limit);
$this->limit($limit[0], $limit[1]);
} else {
$this->limit($limit);
}
}
$result = $this->select();
// header("content-type:text/html;charset=utf8;");
// print_r($result);
// exit;
return $result;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
if (empty($value)) {
return time();
} else {
return strtotime($value);
}
}
// 属性修改器 更新时间
protected function setUpdatetimeAttr($value, $data) {
return time();
}
// 属性修改器 设置注册ip
protected function setIpAttr() {
return Request::instance()->ip();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
// $content = $purifier->purify($content);
}
return $content;
}
}

View File

@@ -0,0 +1,240 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ArticleCategory extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getCategoryLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$row['level'] = $level;
$alldata[] = $row;
$where['pid'] = $row['id'];
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
}
}
return $alldata;
}
public function getCategoryList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
if (!$id) {
return array();
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
$data = $this->field(['id', 'name', 'pid'])->get($id);
$catarr[] = $data;
if (isset($data['pid']) && $data['pid']) {
self::getBreadCrumb($data['pid'], $where, $catarr);
} else {
return array_reverse($catarr);
}
return $catarr;
}
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$row['level'] = $level;
$where['pid'] = $row['id'];
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$result[] = $row;
}
}
return $result;
}
public function deleteRow($id, $stat = -1) {
//$result = $this::destroy($id);
$data = ['id' => $id, 'pid' => 0, 'haschild' => 0, 'stat' => $stat,];
$object = $this::update($data);
return $object;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ArticleComment extends Model {
use \app\common\traits\AdminModel;
public function getRemarkList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('article c', 'a.article_id=c.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['in','0,1'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
//echo $this->getLastsql(); die;
return $data;
}
public function getRemarkLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('article c', 'a.article_id=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['in','0,1']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('article c', 'a.article_id=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getExportSearchArticleLists($where = null, $order = 'id', $limit = null, $count = false, $field = '*') {
$this->alias('a')->join('article c', 'a.article_id=c.id', 'LEFT');
if (is_array($where)) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
//$object->fetchsql(true);
if ($count) {
$result = $this->count();
return $result;
}
if ($field) {
$this->field($field);
}
if ($limit) {
if (is_array($limit)) {
//$limit = ['offset' => 1, 'length' => 1];
$limit = array_values($limit);
$this->limit($limit[0], $limit[1]);
} else {
$this->limit($limit);
}
}
$result = $this->select();
// header("content-type:text/html;charset=utf8;");
// print_r($result);
// exit;
return $result;
}
// 属性修改器 设置注册ip
protected function setIpAttr() {
return Request::instance()->ip();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

80
app/admin/model/Ask.php Executable file
View File

@@ -0,0 +1,80 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Ask extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['create_time'];
//protected $update = [];
public function getAskLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getAskList($where = null, $order = null, $field = null, $limit = null) {
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

38
app/admin/model/AuthAccess.php Executable file
View File

@@ -0,0 +1,38 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class AuthAccess extends Model {
use \app\common\traits\AdminModel;
public function getAuthAccessLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('aa')->join('auth_group ag', 'aa.gid=ag.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['aa.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$object = $this->paginate($limit);
return $object;
}
protected function setNameAttr($value) {
return htmlspecialchars($value);
}
}

45
app/admin/model/AuthGroup.php Executable file
View File

@@ -0,0 +1,45 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class AuthGroup extends Model {
use \app\common\traits\AdminModel;
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
//$options = '<option value="0">请选择...</option>' . "\n";
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
protected function setNameAttr($value) {
return htmlspecialchars($value);
}
}

46
app/admin/model/Banner.php Executable file
View File

@@ -0,0 +1,46 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Banner extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
protected $update = [];
public function getBannerLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('b')->join('banner_type bt', 'b.typeid=bt.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['b.stat' => 0], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

109
app/admin/model/BannerType.php Executable file
View File

@@ -0,0 +1,109 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class BannerType extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id])->field('id')->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = self::getChildIDArray($val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
$options.=self::getOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

84
app/admin/model/Blog.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Blog extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['add_time'];
//protected $update = [];
public function getBlotLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getBlogList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

133
app/admin/model/BlogRemark.php Executable file
View File

@@ -0,0 +1,133 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class BlogRemark extends Model {
use \app\common\traits\AdminModel;
public function getRemarkList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('blog c', 'a.b_id=c.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['in','0,1'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
//echo $this->getLastsql(); die;
return $data;
}
public function getRemarkLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('blog c', 'a.b_id=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['in','0,1']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('blog c', 'a.b_id=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getExportSearchArticleLists($where = null, $order = 'id', $limit = null, $count = false, $field = '*') {
$this->alias('a')->join('blog c', 'a.b_id=c.id', 'LEFT');
if (is_array($where)) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
//$object->fetchsql(true);
if ($count) {
$result = $this->count();
return $result;
}
if ($field) {
$this->field($field);
}
if ($limit) {
if (is_array($limit)) {
//$limit = ['offset' => 1, 'length' => 1];
$limit = array_values($limit);
$this->limit($limit[0], $limit[1]);
} else {
$this->limit($limit);
}
}
$result = $this->select();
// header("content-type:text/html;charset=utf8;");
// print_r($result);
// exit;
return $result;
}
// 属性修改器 设置注册ip
protected function setIpAttr() {
return Request::instance()->ip();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

84
app/admin/model/Bulk.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Bulk extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getBulkLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getBulkList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

84
app/admin/model/BulkInquiry.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class BulkInquiry extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getBulkInquiryLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getBulkInquiryList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

34
app/admin/model/Country.php Executable file
View File

@@ -0,0 +1,34 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
use think\Session;
class Country extends Model {
use \app\common\traits\AdminModel;
public function getLists($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => 0], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$object = $this->paginate($limit);
return $object;
}
}

224
app/admin/model/Customer.php Executable file
View File

@@ -0,0 +1,224 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
use think\Session;
class Customer extends Model {
use \app\common\traits\AdminModel;
public function getLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('u')
->join('customer_dept ud', 'u.id=ud.id', 'LEFT')
->join('dept d', 'ud.dept_id=d.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['stat' => ['neq', '-1']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$object = $this->paginate($limit);
return $object;
}
public function getRoleCustomers($where = null, $order = null, $field = null, $limit = null) {
$this->alias('u')->join('auth_role ar', 'u.role_id=ar.id', 'LEFT');
if (is_array($where)) {
$where = array_merge([], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$this->group('u.id');
//$this->having('max(ud.dept_id)');
$object = $this->paginate($limit);
return $object;
}
/**
* 获取数据库中的配置列表
* @return array
*/
public function getCustomerLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('c')->join('customer_group cg', 'c.group_id=cg.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['c.stat' => 0], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
$object = $this->paginate($limit);
return $object;
}
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['customername'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['customername'] . '</option>' . "\n";
}
}
}
return $options;
}
/*
public function insertRow($data, $siteid = 32267) {
if (isset($data['password'])) {
//$salt = getstr_random();
//$row['password'] = md5($data['password'] . $salt);
$row['salt'] = $data['password'];
$row['password'] = md5($data['password']);
}
$row['siteid'] = $siteid;
$object = $this::create($row);
return $object;
}
*/
/**
* 更新用户密码
*/
public function updatePassword($data) {
//$salt = getstr_random();
$row = array(
'id' => $data['id'],
'password' => md5($data['newpassword']),
'salt' => $data['newpassword'],
);
$object = $this::update($row);
return $object;
}
/**
* 用户登录认证
* @param string $condition 验证条件如用户名邮箱手机号ID
* @param string $password 用户密码
* @param integer $type 用户名类型 1-用户名2-邮箱3-手机4-UID
* @return integer 登录成功-用户ID登录失败-错误编号
*/
public function login($condition, $password, $type = 1) {
$where = [];
switch ($type) {
case 1:$where['customername'] = $condition;
break;
case 2:$where['email'] = $condition;
break;
case 3:$where['mobile'] = $condition;
break;
case 4:$where['id'] = $condition;
break;
default:
return ['status' => false, 'msg' => '参数错误', 'id' => 0]; //参数错误
}
/* 获取用户数据 */
$row = $this->where($where)->field('id,customername,password,salt,picture,position,role_id,stat,last_login_time')->find();
if (empty($row) || (int) $row->stat !== 1) {
return ['status' => false, 'msg' => '用户不存在或被禁用', 'id' => 0];
}
/* 验证用户密码 */
if (md5($password) !== $row->password) {
return ['status' => false, 'msg' => '密码错误', 'id' => 0];
}
unset($row->password);
unset($row->salt);
/* 登录用户 */
$this->autoLogin($row->toArray());
return ['status' => false, 'msg' => '登录成功', 'id' => $row->id]; //登录成功返回用户ID
}
/**
* 自动登录用户
* @param integer $row 用户信息数组
*/
private function autoLogin($row) {
/* 更新登录信息 */
$data = [
'id' => $row['id'],
//'login' => \think\Db::raw('`login`+1'),
'last_login_time' => Request::instance()->time(),
'last_login_ip' => Request::instance()->ip()
];
$this::update($data);
/* 记录登录SESSION和COOKIES */
Session::set('customer_auth', $row);
Session::set('customer_auth_sign', data_auth_sign($row));
unset($row);
//记录行为
// $param = ['action' => 'customer_login', 'model' => 'member', 'record_id' => $row['id']];
// Hook::listen('customer_behavior', $param);
}
/**
* 注销当前用户
* @return void
*/
public function logout() {
Session::delete('customer_auth', null);
Session::delete('customer_auth_sign', null);
}
protected function setRegisterTimeAttr($value, $data) {
return time();
}
protected function setLastLoginTimeAttr($value, $data) {
return time();
}
protected function setLastUpdateTimeAttr($value, $data) {
return time();
}
protected function setRegisterIpAttr() {
return Request::instance()->ip();
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class CustomerGroup extends Model {
use \app\common\traits\AdminModel;
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['gt', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
protected function setNameAttr($value) {
return htmlspecialchars($value);
}
}

214
app/admin/model/Dept.php Executable file
View File

@@ -0,0 +1,214 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
use think\Session;
class Dept extends Model {
use \app\common\traits\AdminModel;
public function getDeptLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$row['level'] = $level;
$alldata[] = $row;
$where['pid'] = $row['id'];
!$row['haschild'] ? '' : self::getDeptLists($where, $order, $field, $limit, $level + 1, $alldata);
}
}
return $alldata;
}
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if (is_array($where)) {
$where = array_merge([ 'stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options .= '<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '' ) . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '' ) . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
$options.=!$row['haschild'] ? '' : self::getOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
public function getDeptTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$row['level'] = $level;
$where['pid'] = $row['id'];
$row['child'] = !$row['haschild'] ? [] : self:: getDeptTree($where, $order, $field, $limit, $level + 1);
$result[] = $row->toArray();
}
}
return $result;
}
public function getMenu($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$row['level'] = $level;
$where['pid'] = $row['id'];
$row['child'] = !$row['haschild'] ? [] : self::getMenu($where, $order, $field, $limit, $level + 1);
$result[] = $row->toArray();
}
}
return $result;
}
public function getChildIDArray($id) {
$list = $this->where([ 'pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int)
$val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function deleteRow($id, $stat = -1) {
//$result = $this::destroy($id);
$data = ['id' => $id, 'pid' => 0, 'haschild' => 0, 'stat' => $stat,];
$object = $this::update($data);
return $object;
}
protected function setUrlAttr($value, $data) {
return trim($value, '/');
}
}

113
app/admin/model/Download.php Executable file
View File

@@ -0,0 +1,113 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Download extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime', 'updatetime'];
protected $update = ['updatetime'];
public function getCategoryDownloadList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('download_category c', 'a.cid=c.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getCategoryDownloadLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')
->join('download_category c', 'a.cid=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
//$this->where('c.stat', ['eq', '0'], ['null', ''], 'or');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
// $this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')
->join('download_category c', 'a.cid=c.id', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
// 属性修改器 更新时间
protected function setUpdatetimeAttr($value, $data) {
return time();
}
// 属性修改器 设置注册ip
protected function setIpAttr() {
return Request::instance()->ip();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

View File

@@ -0,0 +1,220 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class DownloadCategory extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getCategoryLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$row['level'] = $level;
$alldata[] = $row;
$where['pid'] = $row['id'];
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
}
}
return $alldata;
}
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
if (!$id) {
return array();
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
$data = $this->field(['id', 'name', 'pid'])->get($id);
$catarr[] = $data;
if (isset($data['pid']) && $data['pid']) {
self::getBreadCrumb($data['pid'], $where, $catarr);
} else {
return array_reverse($catarr);
}
return $catarr;
}
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$row['level'] = $level;
$where['pid'] = $row['id'];
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$result[] = $row;
}
}
return $result;
}
public function deleteRow($id, $stat = -1) {
//$result = $this::destroy($id);
$data = ['id' => $id, 'pid' => 0, 'haschild' => 0, 'stat' => $stat,];
$object = $this::update($data);
return $object;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

46
app/admin/model/Flink.php Executable file
View File

@@ -0,0 +1,46 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Flink extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
protected $update = [];
public function getFlinkLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('b')->join('flink_type bt', 'b.typeid=bt.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['b.stat' => 0], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

137
app/admin/model/FlinkType.php Executable file
View File

@@ -0,0 +1,137 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class FlinkType extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getFlinkTypeLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$flinktypes = $this->select();
if ($flinktypes) {
foreach ($flinktypes as $k => $flinktype) {
$flinktype['level'] = $level;
$alldata[] = $flinktype;
$where['pid'] = $flinktype['id'];
self::getFlinkTypeLists($where, $order, $field, $limit, $level + 1, $alldata);
}
}
return $alldata;
}
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id])->field('id')->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = self::getChildIDArray($val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = 20, $level = 0) {
$options = '';
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('&#160;&#160;&#160;&#160;', $level) . '&#8970;' : '') . $row['name'] . '</option>' . "\n";
}
$where['pid'] = $row['id'];
$options.=self::getOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
}

12
app/admin/model/Fq.php Executable file
View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Fq extends Model {
use \app\common\traits\AdminModel;
}

84
app/admin/model/Inquiry.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Inquiry extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getInquiryLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$alldata[] = $row;
}
}
return $alldata;
}
public function getInquiryList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

36
app/admin/model/Job.php Executable file
View File

@@ -0,0 +1,36 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Job extends Model {
use \app\common\traits\AdminModel;
public function getJobLists($where = null, $order = null, $field = null, $limit = null) {
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
}

32
app/admin/model/Msgform.php Executable file
View File

@@ -0,0 +1,32 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Msgform extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['stat' => 0, 'ip', 'createtime'];
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
if (empty($value)) {
return time();
} else {
return strtotime($value);
}
}
protected function setContentAttr($value) {
return htmlspecialchars($value);
}
protected function setIpAttr() {
return Request::instance()->ip();
}
}

71
app/admin/model/Navigation.php Executable file
View File

@@ -0,0 +1,71 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Navigation extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime','updatetime'];
protected $update = ['updatetime'];
public function getNavigationList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['in', '0,1']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getNavigationLists($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['in', '0,1']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
if (empty($value)) {
return time();
} else {
return strtotime($value);
}
}
}

23
app/admin/model/Pinglun.php Executable file
View File

@@ -0,0 +1,23 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Pinglun extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['stat' => 0, 'ip'];
protected function setContentAttr($value) {
return htmlspecialchars($value);
}
protected function setIpAttr() {
return Request::instance()->ip();
}
}

293
app/admin/model/Product.php Executable file
View File

@@ -0,0 +1,293 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Product extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime', 'updatetime'];
protected $update = ['updatetime'];
public function getCategoryProductList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')->join('product_category c', 'a.cid=c.id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getProductLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')
// ->join('product_category c', 'a.cid=c.id', 'LEFT');
->join('product_category c', 'a.cid=c.id AND c.stat=0', 'LEFT');
//->join('user u', 'a.id=u.id', 'LEFT');
//$this->where('c.stat', ['eq', '0'], ['null', ''], 'or');
if (is_array($where)) {
// $where = array_merge(['a.stat' => ['eq', '0'], 'c.stat' => ['eq', '0']], $where);
$where = array_merge(['a.stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
public function getRelatedProductList($where = null, $order = null, $field = null, $limit = null) {
$this->alias('p')->join('product_related pr', 'p.id=pr.related_product_id', 'LEFT');
if (is_array($where)) {
$where = array_merge(['p.stat' => ['eq', '0'], 'pr.stat' => ['eq', '0'], 'pr.product_id' => '0'], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
private function getAllCate($pid, &$cate_name='') {
if ($pid) {
$cate_info = model('product_category')->field('name, pid')->find($pid);
if ($cate_name == '') {
$cate_name = $cate_info['name'];
} else {
$cate_name = $cate_info['name'] . '->' . $cate_name;
}
self::getAllCate($cate_info['pid'], $cate_name);
}
return $cate_name;
}
public function getExportSearchProductLists($where = null, $order = null, $limit = null, $count = false, $field = '*') {
# 是否需要有关联产品
$flag2 = 0;
# 是否需要有相关驱动
$flag3 = 0;
# 是否需要有多颜色
$flag4 = 0;
# 是否需要有二级列表图
$flag5 = 0;
# 是否需要有链接
$flag6 = 0;
if (is_array($field)) {
foreach ($field as $key => $value) {
if ($value == 'a.is_comment') {
unset($field[$key]);
$flag1 = 1;
continue;
}
if ($value == 'a.related_product') {
unset($field[$key]);
$flag2 = 1;
continue;
}
if ($value == 'a.driver') {
$flag3 = 1;
unset($field[$key]);
continue;
}
if ($value == 'a.multi_color') {
$flag4 = 1;
unset($field[$key]);
continue;
}
if ($value == 'a.is_list2') {
$flag5 = 1;
unset($field[$key]);
continue;
}
if ($value == 'a.url') {
$flag6 = 1;
unset($field[$key]);
continue;
}
}
}
$this->alias('a')->join('product_category c', 'a.cid = c.id', 'LEFT');
// if ($flag === 0) {
// // 如果不需要有评论的产品列表
// $this->alias('a')
// ->join('product_category c', 'a.cid = c.id', 'LEFT')
// ->join('product_related r', 'a.id=r.related_product_id', 'LEFT')
// ->join('product_dl d', 'a.id=d.product_id', 'LEFT');
// } else {
// // 需要有评论的产品列表
// $this->alias('a')
// ->join('product_category c', 'a.cid = c.id', 'LEFT')
// ->join('product_related r', 'a.id=r.product_id', 'LEFT')
// ->join('product_dl d', 'a.id=d.product_id', 'LEFT')
// ->join('shopselle s', 'a.id=s.pid', 'RIGHT');
// }
if (is_array($where)) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
//$object->fetchsql(true);
if ($count) {
$result = $this->count();
return $result;
}
if ($field) {
$this->field($field);
}
if ($limit) {
if (is_array($limit)) {
//$limit = ['offset' => 1, 'length' => 1];
$limit = array_values($limit);
$this->limit($limit[0], $limit[1]);
} else {
$this->limit($limit);
}
}
$result = $this->select();
foreach ($result as $key => $value) {
if($this->getAllCate($value['pid'])) {
$result[$key]['categoryname'] = $this->getAllCate($value['pid']) . '->' . $value['categoryname'];
}
else{
$result[$key]['categoryname'] = $value['categoryname'];
}
}
foreach ($result as $key => $value) {
if ($flag2 === 1) {
// 有关联产品
$related_product_list = model('product_related')->alias('a')->join('product b', 'a.related_product_id = b.id', 'LEFT')->where(['a.stat' => 0, 'b.stat' => 0, 'a.product_id' => $value['id']])->field('b.brand_id')->select();
if (!empty($related_product_list)) {
$related_product = '';
foreach ($related_product_list as $k => $v) {
$related_product .= $v['brand_id'] . ', ';
}
$result[$key]['related_product'] = rtrim($related_product, ', ');
} else {
$result[$key]['related_product'] = '';
}
}
if ($flag3 == 1) {
// 有相关驱动
$driver = model('product_dl')->where(['product_id' => $value['id'], 'stat' => 0])->limit(1)->select();
if (!empty($driver)) {
$result[$key]['driver'] = 1;
} else {
$result[$key]['driver'] = 0;
}
}
if ($flag4 == 1) {
// 有多颜色
$count_product_two_img = model('product_two_img')->where(['product_id' => $value['id'], 'stat' => 0])->count();
if ($count_product_two_img > 1) {
$result[$key]['multi_color'] = 1;
} else {
$result[$key]['multi_color'] = 0;
}
}
if ($flag5 == 1) {
// 有二级列表图
if ($count_product_two_img > 0) {
$result[$key]['is_list2'] = 1;
} else {
$count_product_two_img = model('product_two_img')->where(['product_id' => $value['id'], 'stat' => 0])->count();
if ($count_product_two_img > 0) {
$result[$key]['is_list2'] = 1;
} else {
$result[$key]['is_list2'] = 0;
}
}
}
if ($flag6 == 1) {
// 有链接
$result[$key]['url'] = $_SERVER['HTTP_HOST'] . '/product/detail/' . $value['id'] . '.html';
}
}
return $result;
}
public function getRecycleLists($where = null, $order = null, $field = null, $limit = null) {
$this->alias('a')
->join('product_category c', 'a.cid=c.id', 'LEFT')
->join('user u', 'a.id=u.id', 'LEFT');
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
//$this->fetchsql(true);
$object = $this->paginate($limit);
// header("content-type:text/html;charset=utf8;");
// print_r($object);
// exit;
return $object;
}
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
// 属性修改器 更新时间
protected function setUpdatetimeAttr($value, $data) {
return time();
}
// 属性修改器 设置注册ip
protected function setIpAttr() {
return Request::instance()->ip();
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-10-22
* Time: 11:42
*/
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductBkImg extends Model {
use \app\common\traits\AdminModel;
}

View File

@@ -0,0 +1,247 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductCategory extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getCategoryLists($where = null, $order = null, $field = null, $limit = null, $level = 0, array &$alldata = array()) {
if ($level > 5) {
return;
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$row['level'] = $level;
$alldata[] = $row;
$where['pid'] = $row['id'];
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
}
}
return $alldata;
}
public function getCategoryList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getChildIDArray($id) {
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
$childIDArray = array((int) $id);
if ($list) {
foreach ($list as $val) {
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
$childIDArray = array_merge($childIDArray, $childArray);
}
}
return $childIDArray;
}
public function getTopParentID($id, $where = null) {
$data = $this::get(function($query)use($id, $where) {
$query->where(['id' => $id]);
if ($where) {
$query->where($where);
}
$query->field(['id', 'pid']);
});
if (isset($data['pid']) && $data['pid']) {
$topid = self::getTopParentID($data['pid'], $where);
} else {
$topid = $id;
}
return $topid;
}
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
if (!$id) {
return array();
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
$data = $this->field(['id', 'name', 'pid'])->get($id);
$catarr[] = $data;
if (isset($data['pid']) && $data['pid']) {
self::getBreadCrumb($data['pid'], $where, $catarr);
} else {
return array_reverse($catarr);
}
return $catarr;
}
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
$options = '';
$disable = '';
$separator = '';
$selected = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
if ($level) {
$separator = str_repeat('&#160;&#160;&#160;&#160;', $level);
} else {
// $controller = Request::instance()->controller();
// $disable = $controller == 'ProductCategory' ? '' : ' disabled="disabled"';
}
foreach ($list as $k => $row) {
$selected = ($row['id'] == $id) ? ' selected="selected"' : '';
$options.='<option value="' . $row['id'] . '"' . $disable . $selected . '>' . $separator . $row['name'] . '</option>' . "\n";
$where['pid'] = $row['id'];
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
}
}
return $options;
}
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$row['level'] = $level;
$where['pid'] = $row['id'];
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
$result[] = $row;
}
}
return $result;
}
public function deleteRow($id, $stat = -1) {
//$result = $this::destroy($id);
$data = ['id' => $id, 'pid' => 0, 'haschild' => 0, 'stat' => $stat,];
$object = $this::update($data);
return $object;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

12
app/admin/model/ProductDl.php Executable file
View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductDl extends Model {
use \app\common\traits\AdminModel;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductImage extends Model {
use \app\common\traits\AdminModel;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductRelated extends Model {
use \app\common\traits\AdminModel;
}

View File

@@ -0,0 +1,207 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductSeries extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
//protected $update = [];
public function getSeriesLists($where = null, $order = null, $field = null, $limit = null, array &$alldata = array()) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
$row['level'] = $level;
$alldata[] = $row;
}
}
return $alldata;
}
public function getSeriesList($where = null, $order = null, $field = null, $limit = null) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($field) {
$this->field($field);
}
if ($order) {
$this->order($order);
}
if ($limit) {
$this->limit($limit);
}
$data = $this->select();
return $data;
}
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
if (!$id) {
return array();
}
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
$data = $this->field(['id', 'name'])->get($id);
$catarr[] = $data;
return $catarr;
}
public function getSeriesOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
$options = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if ($row['id'] == $id) {
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
} else {
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
}
}
}
return $options;
}
public function getSeriesOptions($where = null, $order = null, $field = null, $limit = null, $id = 0) {
$options = '';
$disable = '';
$separator = '';
$selected = '';
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if (empty($limit)) {
$limit = Config::get('list_rows');
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select();
if ($list) {
foreach ($list as $k => $row) {
if (is_array($id)) {
$selected = in_array($row['id'], $id) ? ' selected="selected"' : '';
} else {
$selected = ($row['id'] == $id) ? ' selected="selected"' : '';
}
$options.='<option value="' . $row['id'] . '"' . $disable . $selected . '>' . $separator . $row['name'] . '</option>' . "\n";
}
}
return $options;
}
public function getSeriesTree($where = null, $order = null, $field = null, $limit = 50) {
if (is_array($where)) {
$where = array_merge(['stat' => ['eq', '0']], $where);
}
$result = array();
if ($level > 5) {
return $result;
}
if ($where) {
$this->where($where);
}
if ($order) {
$this->order($order);
}
if ($field) {
$this->field($field);
}
if ($limit) {
$this->limit($limit);
}
$list = $this->select(); // 获取
if ($list) {
foreach ($list as $row) {
$result[] = $row;
}
}
return $result;
}
public function deleteRow($id, $stat = -1) {
//$result = $this::destroy($id);
$data = ['id' => $id, 'stat' => $stat,];
$object = $this::update($data);
return $object;
}
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

12
app/admin/model/ProductSku.php Executable file
View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductSku extends Model {
use \app\common\traits\AdminModel;
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-10-22
* Time: 10:37
*/
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class ProductTwoImg extends Model {
use \app\common\traits\AdminModel;
}

29
app/admin/model/Question.php Executable file
View File

@@ -0,0 +1,29 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class Question extends Model {
use \app\common\traits\AdminModel;
protected $insert = ['createtime'];
// 属性修改器 创建时间
protected function setCreatetimeAttr($value, $data) {
return time();
}
protected function setContentAttr($content, $data) {
if (!empty($content)) {
$config = \HTMLPurifier_Config::createDefault();
$purifier = new \HTMLPurifier($config);
$content = $purifier->purify($content);
}
return $content;
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Request;
use think\Config;
class QuestionCategory extends Model {
use \app\common\traits\AdminModel;
}

Some files were not shown because too many files have changed in this diff Show More