Commit bd5a188cec79c1855e01a0ddf7d7b74a822f29ee

Authored by u123231312
1 parent a51514e8

no message

Too many changes to show.

To preserve performance only 36 of 36+ files are displayed.

ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
... ...
0.1
\ No newline at end of file
CLTPHP5.6
===============
CLTPHP5.6.5内容管理系统:
+ 升级TP框架到TP5.1.19
+ 新增后台栏目权限
+ 管理员登录状态bug
+ 后台日期插件优化
+ 分页后点击搜索未重置初始页码的bug
> CLTPHP5.6的运行环境要求PHP5.6以上。
> CLTPHP5.6及后续版本运行目录: public/
## 目录结构
初始的目录结构如下:
~~~
www WEB部署目录(或者子目录)
├─application 应用目录
│ ├─common 公共模块目录(可以更改)
│ ├─module_name 模块目录
│ │ ├─common.php 模块函数文件
│ │ ├─controller 控制器目录
│ │ ├─model 模型目录
│ │ ├─view 视图目录
│ │ └─ ... 更多类库目录
│ │
│ ├─command.php 命令行定义文件
│ ├─common.php 公共函数文件
│ └─tags.php 应用行为扩展定义文件
│
├─config 应用配置目录
│ ├─module_name 模块配置目录
│ │ ├─database.php 数据库配置
│ │ ├─cache 缓存配置
│ │ └─ ...
│ │
│ ├─app.php 应用配置
│ ├─cache.php 缓存配置
│ ├─cookie.php Cookie配置
│ ├─database.php 数据库配置
│ ├─log.php 日志配置
│ ├─session.php Session配置
│ ├─template.php 模板引擎配置
│ └─trace.php Trace配置
│
├─route 路由定义目录
│ ├─route.php 路由定义
│ └─... 更多
│
├─public WEB目录(对外访问目录)
│ ├─index.php 入口文件
│ ├─static 静态资源文件目录
│ ├─router.php 快速测试文件
│ └─.htaccess 用于apache的重写
│
├─thinkphp 框架系统目录
│ ├─lang 语言文件目录
│ ├─library 框架类库目录
│ │ ├─think Think类库包目录
│ │ └─traits 系统Trait目录
│ │
│ ├─tpl 系统模板目录
│ ├─base.php 基础定义文件
│ ├─console.php 控制台入口文件
│ ├─convention.php 框架惯例配置文件
│ ├─helper.php 助手函数文件
│ ├─phpunit.xml phpunit配置文件
│ └─start.php 框架入口文件
│
├─extend 扩展类库目录
├─runtime 应用的运行时目录(可写,可定制)
├─vendor 第三方类库目录(Composer依赖库)
├─build.php 自动生成定义文件(参考)
├─composer.json composer 定义文件
├─LICENSE.txt 授权说明文件
├─README.md README 文件
├─think 命令行入口文件
~~~
... ...
deny from all
\ No newline at end of file
... ...
<?php
return [
'pathinfo_depr' => '/',
];
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
class Ad extends Common
{
public function initialize(){
parent::initialize();
}
//广告列表
public function index(){
if(Request::isAjax()) {
$key = input('post.key');
$this->assign('testkey', $key);
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = Db::table(config('database.prefix') . 'ad')->alias('a')
->join(config('database.prefix') . 'ad_type at', 'a.type_id = at.type_id', 'left')
->field('a.*,at.name as typename')
->where('a.name', 'like', "%" . $key . "%")
->order('a.sort')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
public function add(){
if(Request::isAjax()) {
//构建数组
$data = Request::except('file');
$data['addtime'] = time();
db('ad')->insert($data);
$result['code'] = 1;
$result['msg'] = '广告添加成功!';
cache('adList', NULL);
$result['url'] = url('index');
return $result;
}else{
$adtypeList=db('ad_type')->order('sort')->select();
$this->assign('adtypeList',json_encode($adtypeList,true));
$this->assign('title',lang('add').lang('ad'));
$this->assign('info','null');
$this->assign('selected', 'null');
return $this->fetch('form');
}
}
public function edit(){
if(Request::isAjax()) {
$data = Request::except('file');
db('ad')->update($data);
$result['code'] = 1;
$result['msg'] = '广告修改成功!';
cache('adList', NULL);
$result['url'] = url('index');
return $result;
}else{
$adtypeList=db('ad_type')->order('sort')->select();
$ad_id=input('ad_id');
$adInfo=db('ad')->where(array('ad_id'=>$ad_id))->find();
$this->assign('adtypeList',json_encode($adtypeList,true));
$selected = db('ad_type')->where('type_id',$adInfo['type_id'])->find();
$this->assign('selected',json_encode($selected,true));
$this->assign('info',json_encode($adInfo,true));
$this->assign('title',lang('edit').lang('ad'));
return $this->fetch('form');
}
}
//设置广告状态
public function editState(){
$id=input('post.id');
$open=input('post.open');
if(db('ad')->where('ad_id='.$id)->update(['open'=>$open])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function adOrder(){
$ad=db('ad');
$data = input('post.');
if($ad->update($data)!==false){
cache('adList', NULL);
return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function del(){
db('ad')->where(array('ad_id'=>input('ad_id')))->delete();
cache('adList', NULL);
return ['code'=>1,'msg'=>'删除成功!'];
}
public function delall(){
$map[] =array('ad_id','in',input('param.ids/a'));
db('ad')->where($map)->delete();
cache('adList', NULL);
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
return $result;
}
/***************************位置*****************************/
//位置
public function type(){
if(Request::isAjax()) {
$key = input('key');
$this->assign('testkey', $key);
$list = db('ad_type')->where('name', 'like', "%" . $key . "%")->order('sort')->select();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return $this->fetch();
}
public function typeOrder(){
$ad_type=db('ad_type');
$data = input('post.');
if($ad_type->update($data)!==false){
return $result = ['msg' => '操作成功!','url'=>url('type'), 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function addType(){
if(Request::isAjax()) {
db('ad_type')->insert(input('post.'));
$result['code'] = 1;
$result['msg'] = '广告位保存成功!';
$result['url'] = url('type');
return $result;
}else{
$this->assign('title',lang('add').lang('ad').'位');
$this->assign('info','null');
return $this->fetch('typeForm');
}
}
public function editType(){
if(Request::isAjax()) {
db('ad_type')->update(input('post.'));
$result['code'] = 1;
$result['msg'] = '广告位修改成功!';
$result['url'] = url('type');
return $result;
}else{
$type_id=input('param.type_id');
$info=db('ad_type')->where('type_id',$type_id)->find();
$this->assign('title',lang('edit').lang('ad').'位');
$this->assign('info',json_encode($info,true));
return $this->fetch('typeForm');
}
}
public function delType(){
$map['type_id'] = input('param.type_id');
db('ad_type')->where($map)->delete();//删除广告位
db('ad')->where($map)->delete();//删除该广告位所有广告
return ['code'=>1,'msg'=>'删除成功!'];
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
//use think\{Controller,Db,Input};//
use think\Controller;
use think\Db;
use think\Input;
class Ajax extends Common{
public function getRegion(){
$Region=db("region");
$map['pid']=input("pid");
$map['type']=input("type");
$list=$Region->where($map)->select();
echo json_encode($list);
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use function MongoDB\BSON\toJSON;
use think\Db;
use clt\Leftnav;
use app\admin\model\Admin;
use app\admin\model\AuthGroup;
use app\admin\model\authRule;
use think\facade\Request;
use think\Validate;
class Auth extends Common
{
//管理员列表
public function adminList(){
if(Request::isAjax()){
$val=input('val');
$url['val'] = $val;
$this->assign('testval',$val);
$map='';
if($val){
$map['username|email|tel']= array('like',"%".$val."%");
}
if (session('aid')!=1){
$map='admin_id='.session('aid');
}
$list=Db::table(config('database.prefix').'admin')->alias('a')
->join(config('database.prefix').'auth_group ag','a.group_id = ag.group_id','left')
->field('a.*,ag.title')
->where($map)
->select();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return view();
}
public function adminAdd(){
if(Request::isAjax()){
$data = input('post.');
$check_user = Admin::get(['username'=>$data['username']]);
if ($check_user) {
return $result = ['code'=>0,'msg'=>'用户已存在,请重新输入用户名!'];
}
$data['pwd'] = input('post.pwd', '', 'md5');
$data['add_time'] = time();
$data['ip'] = request()->ip();
//验证
$msg = $this->validate($data,'app\admin\validate\Admin');
if($msg!='true'){
return $result = ['code'=>0,'msg'=>$msg];
}
//单独验证密码
$checkPwd = Validate::make([input('post.pwd')=>'require']);
if (false === $checkPwd) {
return $result = ['code'=>0,'msg'=>'密码不能为空!'];
}
//添加
if (Admin::create($data)) {
return ['code'=>1,'msg'=>'管理员添加成功!','url'=>url('adminList')];
} else {
return ['code'=>0,'msg'=>'管理员添加失败!'];
}
}else{
$auth_group = AuthGroup::all();
$this->assign('authGroup',$auth_group);
$this->assign('title',lang('add').lang('admin'));
$this->assign('info','null');
$this->assign('selected', 'null');
return view('adminForm');
}
}
//删除管理员
public function adminDel(){
$admin_id=input('post.admin_id');
if (session('aid')==1){
Admin::where('admin_id','=',$admin_id)->delete();
return $result = ['code'=>1,'msg'=>'删除成功!'];
}else{
return $result = ['code'=>0,'msg'=>'您没有删除管理员的权限!'];
}
}
//修改管理员状态
public function adminState(){
$id=input('post.id');
$is_open=input('post.is_open');
if (empty($id)){
$result['status'] = 0;
$result['info'] = '用户ID不存在!';
$result['url'] = url('adminList');
return $result;
}
db('admin')->where('admin_id='.$id)->update(['is_open'=>$is_open]);
$result['status'] = 1;
$result['info'] = '用户状态修改成功!';
$result['url'] = url('adminList');
return $result;
}
//更新管理员信息
public function adminEdit(){
if(request()->isPost()){
$data = input('post.');
$pwd=input('post.pwd');
$map[] = ['admin_id','<>',$data['admin_id']];
$where['admin_id'] = $data['admin_id'];
if($data['username']){
$map[] = ['username','=',$data['username']];
$check_user = Admin::where($map)->find();
if ($check_user) {
return $result = ['code'=>0,'msg'=>'用户已存在,请重新输入用户名!'];
}
}
if ($pwd){
$data['pwd']=input('post.pwd','','md5');
}else{
unset($data['pwd']);
}
$msg = $this->validate($data,'app\admin\validate\Admin');
if($msg!='true'){
return $result = ['code'=>0,'msg'=>$msg];
}
Admin::update($data,$where);
if( $data['admin_id'] == session('aid')){
session('username',$data['username']);
$avatar = $data['avatar']==''?'/static/admin/images/0.jpg':$data['avatar'];
session('avatar',$avatar);
}
return $result = ['code'=>1,'msg'=>'管理员修改成功!','url'=>url('adminList')];
}else{
$auth_group = AuthGroup::all();
$admin = new Admin();
$info = $admin->getInfo(input('admin_id'));
$this->assign('info', json_encode($info,true));
$this->assign('authGroup',$auth_group);
$this->assign('title',lang('edit').lang('admin'));
return view('adminForm');
}
}
/*-----------------------用户组管理----------------------*/
//用户组管理
public function adminGroup(){
if(request()->isPost()){
$list = AuthGroup::all();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return view();
}
//删除管理员分组
public function groupDel(){
AuthGroup::where('group_id','=',input('id'))->delete();
return $result = ['code'=>1,'msg'=>'删除成功!'];
}
//添加分组
public function groupAdd(){
if(request()->isPost()){
$data=input('post.');
$data['addtime']=time();
AuthGroup::create($data);
$result['msg'] = '用户组添加成功!';
$result['url'] = url('adminGroup');
$result['code'] = 1;
return $result;
}else{
$this->assign('title','添加用户组');
$this->assign('info','null');
return $this->fetch('groupForm');
}
}
//修改分组
public function groupEdit(){
if(request()->isPost()) {
$data=input('post.');
$where['group_id'] = $data['group_id'];
AuthGroup::update($data,$where);
$result = ['code'=>1,'msg'=>'用户组修改成功!','url'=>url('adminGroup')];
return $result;
}else{
$id = input('id');
$info = AuthGroup::get(['group_id'=>$id]);
$this->assign('info', json_encode($info,true));
$this->assign('title','编辑用户组');
return $this->fetch('groupForm');
}
}
//分组配置规则
public function groupAccess(){
$nav = new Leftnav();
$admin_rule=db('auth_rule')->field('id,pid,title')->order('sort asc')->select();
$rules = db('auth_group')->where('group_id',input('id'))->value('rules');
$arr = $nav->auth($admin_rule,$pid=0,$rules);
$arr[] = array(
"id"=>0,
"pid"=>0,
"title"=>"全部",
"open"=>true
);
$this->assign('data',json_encode($arr,true));
return $this->fetch();
}
public function groupSetaccess(){
$rules = input('post.rules');
if(empty($rules)){
return array('msg'=>'请选择权限!','code'=>0);
}
$data = input('post.');
$where['group_id'] = $data['group_id'];
if(AuthGroup::update($data,$where)){
return array('msg'=>'权限配置成功!','url'=>url('adminGroup'),'code'=>1);
}else{
return array('msg'=>'保存错误','code'=>0);
}
}
/********************************权限管理*******************************/
public function adminRule(){
if(request()->isPost()){
$nav = new Leftnav();
$arr = cache('authRuleList');
if(!$arr){
$authRule = authRule::all(function($query){
$query->order('sort', 'asc');
});
$arr = $nav->menu($authRule);
cache('authRuleList', $arr, 3600);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$arr,'rel'=>1];
}
return view();
}
public function ruleAdd(){
if(request()->isPost()){
$data = input('post.');
$data['addtime'] = time();
authRule::create($data);
cache('authRule', NULL);
cache('authRuleList', NULL);
return $result = ['code'=>1,'msg'=>'权限添加成功!','url'=>url('adminRule')];
}else{
$nav = new Leftnav();
$arr = cache('authRuleList');
if(!$arr){
$authRule = authRule::all(function($query){
$query->order('sort', 'asc');
});
$arr = $nav->menu($authRule);
cache('authRuleList', $arr, 3600);
}
$this->assign('admin_rule',$arr);//权限列表
return $this->fetch();
}
}
public function ruleOrder(){
$auth_rule=db('auth_rule');
$data = input('post.');
if($auth_rule->update($data)!==false){
cache('authRuleList', NULL);
cache('authRule', NULL);
return $result = ['code'=>1,'msg'=>'排序更新成功!','url'=>url('adminRule')];
}else{
return $result = ['code'=>0,'msg'=>'排序更新失败!'];
}
}
//设置权限菜单显示或者隐藏
public function ruleState(){
$id=input('post.id');
$menustatus=input('post.menustatus');
if(db('auth_rule')->where('id='.$id)->update(['menustatus'=>$menustatus])!==false){
cache('authRule', NULL);
cache('authRuleList', NULL);
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
//设置权限是否验证
public function ruleTz(){
$id=input('post.id');
$authopen=input('post.authopen');
if(db('auth_rule')->where('id='.$id)->update(['authopen'=>$authopen])!==false){
cache('authRule', NULL);
cache('authRuleList', NULL);
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function ruleDel(){
authRule::destroy(['id'=>input('param.id')]);
cache('authRule', NULL);
cache('authRuleList', NULL);
return $result = ['code'=>1,'msg'=>'删除成功!'];
}
public function ruleEdit(){
if(request()->isPost()) {
$datas = input('post.');
if(authRule::update($datas)) {
cache('authRule', NULL);
cache('authRuleList', NULL);
return json(['code' => 1, 'msg' => '保存成功!', 'url' => url('adminRule')]);
} else {
return json(['code' => 0, 'msg' =>'保存失败!']);
}
}else{
$admin_rule = authRule::get(function($query){
$query->where(['id'=>input('id')])->field('id,href,title,icon,sort,menustatus');
});
$this->assign('rule',$admin_rule);
return $this->fetch();
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use clt\Tree;
use think\facade\Request;
use think\facade\Env;
class Category extends Common
{
protected $dao, $categorys , $module,$groupId;
function initialize()
{
parent::initialize();
foreach ((array)$this->module as $rw){
if($rw['type']==1 && $rw['status']==1){
$data['module'][$rw['id']] = $rw;
}
}
$this->module=$data['module'];
$this->assign($data);
unset($data);
$this->dao = db('category');
$this->groupId = Db::name('admin')->where('admin_id',session('aid'))->value('group_id');
}
public function index()
{
if ($this->categorys) {
foreach ($this->categorys as $r) {
if(session('aid')==1){
if ($r['module'] == 'page') {
$r['str_manage'] = '<a class="orange" href="' . url('page/edit', array('id' => $r['id'])) . '" title="修改内容"><i class="icon icon-file-text2"></i></a> | ';
} else {
$r['str_manage'] = '';
}
$r['str_manage'] .= '<a class="blue" title="添加子栏目" href="' . url('Category/add', array('parentid' => $r['id'])) . '"> <i class="icon icon-plus"></i></a> | <a class="green" href="' . url('Category/edit', array('id' => $r['id'])) . '" title="修改"><i class="icon icon-pencil2"></i></a> | <a class="red" href="javascript:del(\'' . $r['id'] . '\')" title="删除"><i class="icon icon-bin"></i></a> ';
$r['modulename'] = $this->module[$r['moduleid']]['title'];
$r['dis'] = $r['ismenu'] == 1 ? '<font color="green">显示</font>' : '<font color="red">不显示</font>';
$array[] = $r;
}else{
$groupArr = explode(',',$r['readgroup']);
if(in_array($this->groupId,$groupArr)){
if ($r['module'] == 'page') {
$r['str_manage'] = '<a class="orange" href="' . url('page/edit', array('id' => $r['id'])) . '" title="修改内容"><i class="icon icon-file-text2"></i></a> | ';
} else {
$r['str_manage'] = '';
}
$r['str_manage'] .= '<a class="blue" title="添加子栏目" href="' . url('Category/add', array('parentid' => $r['id'])) . '"> <i class="icon icon-plus"></i></a> | <a class="green" href="' . url('Category/edit', array('id' => $r['id'])) . '" title="修改"><i class="icon icon-pencil2"></i></a> | <a class="red" href="javascript:del(\'' . $r['id'] . '\')" title="删除"><i class="icon icon-bin"></i></a> ';
$r['modulename'] = $this->module[$r['moduleid']]['title'];
$r['dis'] = $r['ismenu'] == 1 ? '<font color="green">显示</font>' : '<font color="red">不显示</font>';
$array[] = $r;
}
}
}
$str = "<tr><td class='visible-lg visible-md'>\$id</td>";
$str .= "<td class='text-left'>\$spacer<a href='/admin/\$module/\$action/\$files/\$id.html' class='green' title='查看内容'>\$catname </a>&nbsp;</td>";
$str .= "<td class='visible-lg visible-md'>\$modulename</td><td class='visible-lg visible-md'>\$dis</td>";
$str .= "<td><input type='text' size='10' data-id='\$id' value='\$sort' class='layui-input list_order'></td><td>\$str_manage</td></tr>";
$tree = new Tree ($array);
$tree->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
$categorys = $tree->get_tree(0, $str);
$this->assign('categorys', $categorys);
}
$this->assign('title','栏目列表');
return $this->fetch();
}
public function add(){
$parentid = input('param.parentid');
//模型列表
$module = db('module')->where('status',1)->field('id,title,name')->select();
$this->assign('modulelist',$module);
//父级模型ID
//父级模型ID
if($parentid){
$vo['moduleid'] =$this->categorys[$parentid]['moduleid'];
$this->assign('module', $vo);
}
//栏目选择列表
foreach($this->categorys as $r) {
$array[] = $r;
}
$str = "<option value='\$id' \$selected>\$spacer \$catname</option>";
$tree = new Tree ($array);
$categorys = $tree->get_tree(0, $str,$parentid);
$this->assign('categorys', $categorys);
//模版
$templates= template_file();
$this->assign ( 'templates',$templates );
//管理员权限组
$usergroup=db('auth_group')->select();
$this->assign('rlist',$usergroup);
$this->assign('title','添加栏目');
return $this->fetch();
}
public function insert(){
$data = $data = Request::except('file');
if(!empty($data['readgroup'])){
$data['readgroup'] = implode(',',$data['readgroup']);
}else{
$data['readgroup'] = $this->groupId;
}
$data['module'] = $this->module[$data['moduleid']]['name'];
$data['child'] = isset($data['child'])?1:0;
$id = db('category')->insertGetId($data);
if($id) {
if($data['module']=='page'){
$data2['id']=$id;
if($data['title']==''){
$data2['title'] = $data['catname'];
$data2['content'] = '';
}
$page=db('page');
$page->insert($data2);
}
$this->repair();
$this->repair();
savecache('Category');
$result['msg'] = '栏目添加成功!';
cache('cate', NULL);
$result['url'] = url('index');
$result['code'] = 1;
return $result;
}else{
$result['msg'] = '栏目添加失败!';
$result['code'] = 0;
return $result;
}
}
public function edit(){
$id = input('id');
$this->assign('module',$this->categorys[$id]['moduleid']);
$module = db('module')->field('id,title,name')->select();
$this->assign('modulelist',$module);
$record = $this->categorys[$id];
$record['imgUrl'] = imgUrl($record['image']);
$record['readgroup'] = explode(',',$record['readgroup']);
$parentid = intval($record['parentid']);
$result = $this->categorys;
foreach($result as $r) {
if($r['type']==1) continue;
$r['selected'] = $r['id'] == $parentid ? 'selected' : '';
$array[] = $r;
}
$str = "<option value='\$id' \$selected>\$spacer \$catname</option>";
$tree = new Tree ($array);
$categorys = $tree->get_tree(0, $str,$parentid);
$this->assign('categorys', $categorys);
$this->assign('record', $record);
$usergroup=db('auth_group')->select();
$this->assign('rlist',$usergroup);
$this->assign('title','编辑栏目');
//模版
$templates= template_file();
$this->assign ( 'templates',$templates );
return $this->fetch();
}
public function catUpdate(){
$data = $data = Request::except('file');
$data['module'] = db('module')->where(array('id'=>$data['moduleid']))->value('name');
if(!empty($data['readgroup'])){
$data['readgroup'] = implode(',',$_POST['readgroup']);
}else{
$data['readgroup']='';
}
$data['arrparentid'] = $this->get_arrparentid($data['id']);
$data['child'] = isset($data['child']) ? '1' : '0';
if (false !==db('category')->update($data)) {
if($data['child']==1){
$arrchildid = $this->get_arrchildid($data['id']);
$data2['ismenu'] = $data['ismenu'];
$data2['pagesize'] = $data['pagesize'];
$data2['readgroup'] = $data['readgroup'];
db('category')->where( ' id in ('.$arrchildid.')')->update($data2);
}
$this->repair();
$this->repair();
savecache('Category');
$result['msg'] = '栏目修改成功!';
cache('cate', NULL);
$result['url'] = url('index');
$result['code'] = 1;
return $result;
} else {
$result['msg'] = '栏目修改失败!';
$result['code'] = 0;
return $result;
}
}
public function repair() {
@set_time_limit(500);
$this->categorys = $categorys = array();
$categorys = db('category')->where("parentid=0")->order('sort ASC,id ASC')->select();
$this->set_categorys($categorys);
if(is_array($this->categorys)) {
foreach($this->categorys as $id => $cat) {
if($id == 0 || $cat['type']==1) continue;
$this->categorys[$id]['arrparentid'] = $arrparentid = $this->get_arrparentid($id);
$this->categorys[$id]['arrchildid'] = $arrchildid = $this->get_arrchildid($id);
$this->categorys[$id]['parentdir'] = $parentdir = $this->get_parentdir($id);
db('category')->update(array('parentdir'=>$parentdir,'arrparentid'=>$arrparentid,'arrchildid'=>$arrchildid,'id'=>$id));
}
}
}
public function set_categorys($categorys = array()) {
if (is_array($categorys) && !empty($categorys)) {
foreach ($categorys as $id => $c) {
$this->categorys[$c['id']] = $c;
$r = db('category')->where(array("parentid"=>$c['id']))->Order('sort ASC,id ASC')->select();
$this->set_categorys($r);
}
}
return true;
}
public function get_arrparentid($id, $arrparentid = '') {
if(!is_array($this->categorys) || !isset($this->categorys[$id])) return false;
$parentid = $this->categorys[$id]['parentid'];
$arrparentid = $arrparentid ? $parentid.','.$arrparentid : $parentid;
if($parentid) {
$arrparentid = $this->get_arrparentid($parentid, $arrparentid);
} else {
$this->categorys[$id]['arrparentid'] = $arrparentid;
}
return $arrparentid;
}
public function get_arrchildid($id) {
$arrchildid = $id;
if(is_array($this->categorys)) {
foreach($this->categorys as $catid => $cat) {
if($cat['parentid'] && $id != $catid) {
$arrparentids = explode(',', $cat['arrparentid']);
if(in_array($id, $arrparentids)){
$arrchildid .= ','.$catid;
}
}
}
}
return $arrchildid;
}
public function get_parentdir($id) {
if($this->categorys[$id]['parentid']==0){
return '';
}
$arrparentid = $this->categorys[$id]['arrparentid'];
unset($r);
if ($arrparentid) {
$arrparentid = explode(',', $arrparentid);
$arrcatdir = array();
foreach($arrparentid as $pid) {
if($pid==0) continue;
$arrcatdir[] = $this->categorys[$pid]['catdir'];
}
return implode('/', $arrcatdir).'/';
}
}
public function del() {
$catid = input('param.id');
$modules = $this->categorys[$catid]['module'];
$modulesId = $this->categorys[$catid]['moduleid'];
$scount = $this->dao->where(array('parentid'=>$catid))->count();
if($scount){
$result['info'] = '请先删除其子栏目!';
$result['status'] = 0;
return $result;
}
$module = db($modules);
$arrchildid = $this->categorys[$catid]['arrchildid'];
if($modules != 'page'){
$fields = cache($modulesId.'_Field');
$fieldse=array();
foreach ($fields as $k=>$v){
$fieldse[] = $k;
}
if(in_array('catid',$fieldse)){
$count = $module->where('catid','in',$arrchildid)->count();
}else{
$count = $module->count();
}
if($count){
$result['info'] = '请先删除该栏目下所有数据!';
$result['status'] = 0;
return $result;
}
}
$pid = $this->categorys[$catid]['parentid'];
$scat = $this->dao->where(array('parentid'=>$pid))->count();
if($scat==1){
db('category')->where(array('id'=>$pid))->update(array('child'=>0));
}
db('category')->where('id','in',$arrchildid)->delete();
$arr=explode(',',$arrchildid);
foreach((array)$arr as $r){
if($this->categorys[$r]['module']=='page'){
$module=db('page');
$module->delete($r);
}
}
$this->repair();
savecache('Category');
$result['info'] = '栏目删除成功!';
cache('cate', NULL);
$result['url'] = url('index');
$result['status'] = 1;
return $result;
}
public function cOrder(){
$data = input('post.');
$this->dao->update($data);
$result = ['msg' => '排序成功!', 'code' => 1,'url'=>url('index')];
savecache('Category');
cache('cate', NULL);
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
class Common extends Controller
{
protected $mod,$role,$system,$nav,$menudata,$cache_model,$categorys,$module,$moduleid,$adminRules,$HrefId;
public function initialize()
{
//判断管理员是否登录
if (!session('aid')) {
$this->redirect('admin/login/index');
}
define('MODULE_NAME',strtolower(request()->controller()));
define('ACTION_NAME',strtolower(request()->action()));
//权限管理
//当前操作权限ID
if(session('aid')!=1){
$this->HrefId = db('auth_rule')->where('href',MODULE_NAME.'/'.ACTION_NAME)->value('id');
//当前管理员权限
$map['a.admin_id'] = session('aid');
$rules=Db::table(config('database.prefix').'admin')->alias('a')
->join(config('database.prefix').'auth_group ag','a.group_id = ag.group_id','left')
->where($map)
->value('ag.rules');
$this->adminRules = explode(',',$rules);
if($this->HrefId){
if(!in_array($this->HrefId,$this->adminRules)){
$this->error('您无此操作权限');
}
}
}
$this->cache_model=array('Module','AuthRule','Category','Posid','Field','System','cm');
foreach($this->cache_model as $r){
if(!cache($r)){
savecache($r);
}
}
$this->system = cache('System');
$this->categorys = cache('Category');
$this->module = cache('Module');
$this->mod = cache('Mod');
$this->rule = cache('AuthRule');
$this->cm = cache('cm');
}
//空操作
public function _empty(){
return $this->error('空操作,返回上次访问页面中...');
}
}
... ...
<?php
namespace app\admin\controller;
use think\Db;
use \tp5er\Backup;
class Database extends Common
{
protected $db = '', $datadir;
function initialize(){
parent::initialize();
$this->config=array(
'path' => './Data/',//数据库备份路径
'part' => 20971520,//数据库备份卷大小
'compress' => 0,//数据库备份文件是否启用压缩 0不压缩 1 压缩
'level' => 9 //数据库备份文件压缩级别 1普通 4 一般 9最高
);
$this->db = new Backup($this->config);
}
public function database(){
if(request()->isPost()){
$list = $this->db->dataList();
$total = 0;
foreach ($list as $k => $v) {
$list[$k]['size'] = format_bytes($v['data_length']);
$total += $v['data_length'];
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'total'=>format_bytes($total),'tableNum'=>count($list),'rel'=>1];
}
return view();
}
//优化
public function optimize() {
$tables = input('tables/a');
if (empty($tables)) {
return ['code'=>0,'msg'=>'请选择要优化的表!'];
}
if($this->db->optimize($tables)){
return ['code'=>1,'msg'=>'数据表优化成功!'];
}else{
return ['code'=>0,'msg'=>'数据表优化出错请重试!'];
}
}
//修复
public function repair() {
$tables = input('tables/a');
if (empty($tables)) {
return ['code'=>0,'msg'=>'请选择要修复的表!'];
}
if($this->db->repair($tables)){
return ['code'=>1,'msg'=>'数据表修复成功!'];
}else{
return ['code'=>0,'msg'=>'数据表修复出错请重试!'];
}
}
//备份
public function backup(){
$tables = input('post.tables/a');
if (!empty($tables)) {
foreach ($tables as $table) {
$this->db->setFile()->backup($table, 0);
}
return ['code'=>1,'msg'=>'备份成功!'];
} else {
return ['code'=>0,'msg'=>'请选择要备份的表!'];
}
}
//备份列表
public function restore(){
if(request()->isPost()){
$list = $this->db->fileList();
return ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return view();
}
//执行还原数据库操作
public function import($time) {
$list = $this->db->getFile('timeverif',$time);
$this->db->setFile($list)->import(1);
return ['code'=>1,'msg'=>'还原成功!'];
}
//下载
public function downFile($time) {
$this->db->downloadFile($time);
}
//删除sql文件
public function delSqlFiles() {
$time = input('post.time');
if($this->db->delFile($time)){
return ['code'=>1,'msg'=>"备份文件删除成功!"];
}else{
return ['code'=>0,'msg'=>"备份文件删除失败,请检查权限!"];
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
class Debris extends Common
{
public function index(){
if(Request::isAjax()) {
$key = input('post.key');
$this->assign('testkey', $key);
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = Db::table(config('database.prefix') . 'debris')->alias('d')
->join(config('database.prefix') . 'debris_type dt', 'd.type_id = dt.id', 'left')
->field('d.*,dt.title as typename')
->where('d.title', 'like', "%" . $key . "%")
->order('d.sort')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
public function add(){
if(Request::isAjax()) {
//构建数组
$data = Request::except('file');
$data['addtime'] = time();
$typeId = explode(':',$data['type_id']);
$data['type_id'] =$typeId[1];
db('debris')->insert($data);
$result['code'] = 1;
$result['msg'] = '碎片添加成功!';
$result['url'] = url('index');
return $result;
}else{
$debrisTypeList=db('debris_type')->order('sort')->select();//获取所有广告位
$this->assign('debrisTypeList',json_encode($debrisTypeList,true));
$this->assign('title',lang('add').lang('debris'));
$this->assign('info','null');
return $this->fetch('form');
}
}
public function edit(){
if(Request::isAjax()) {
$data = Request::except('file');
$typeId = explode(':',$data['type_id']);
$data['type_id'] =$typeId[1];
db('debris')->where('id',$data['id'])->update($data);
$result['code'] = 1;
$result['msg'] = '碎片修改成功!';
$result['url'] = url('index');
return $result;
}else{
$id=input('id');
$info=db('debris')->where(array('id'=>$id))->find();
$this->assign('info',json_encode($info,true));
$debrisTypeList=db('debris_type')->order('sort')->select();//获取所有广告位
$this->assign('debrisTypeList',json_encode($debrisTypeList,true));
$this->assign('title',lang('edit').lang('debris'));
return $this->fetch('form');
}
}
public function del(){
db('debris')->where('id',input('post.id'))->delete();
return ['code'=>1,'msg'=>'删除成功!'];
}
public function debrisOrder(){
$data = input('post.');
if(db('debris')->update($data)!==false){
return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function delall(){
$map['id'] =array('in',input('param.ids/a'));
db('debris')->where($map)->delete();
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
return $result;
}
/*************************类别*************************/
public function type(){
if(request()->isPost()) {
$key = input('key');
$this->assign('testkey', $key);
$list = db('debris_type')->where('title', 'like', "%" . $key . "%")->order('sort')->select();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return $this->fetch();
}
public function addType(){
if(request()->isPost()) {
db('debris_type')->insert(input('post.'));
$result['code'] = 1;
$result['msg'] = '碎片分类保存成功!';
$result['url'] = url('type');
return $result;
}else{
$this->assign('title',lang('add').'碎片分类');
$this->assign('info','null');
return $this->fetch('typeForm');
}
}
public function editType(){
if(request()->isPost()) {
db('debris_type')->update(input('post.'));
$result['code'] = 1;
$result['msg'] = '碎片分类修改成功!';
$result['url'] = url('type');
return $result;
}else{
$id=input('param.id');
$info=db('debris_type')->where('id',$id)->find();
$this->assign('title',lang('edit').'碎片分类');
$this->assign('info',json_encode($info,true));
return $this->fetch('typeForm');
}
}
public function typeOrder(){
$debris_type=db('debris_type');
$data = input('post.');
if($debris_type->update($data)!==false){
return $result = ['msg' => '操作成功!','url'=>url('type'), 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function delType(){
$id = input('post.id');
db('debris_type')->where(['id'=>$id])->delete();//删除广告位
db('debris')->where(['type_id'=>$id])->delete();//删除该广告位所有广告
return ['code'=>1,'msg'=>'删除成功!'];
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\facade\Request;
class Donation extends Common
{
//捐赠列表
public function index(){
if(Request::isAjax()) {
$key=input('post.key');
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = db('donation')
->where('name', 'like', "%" . $key . "%")
->order('addtime desc')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
$list['data'][$k]['mnum'] = $v['money']*100;
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
public function add(){
if(Request::isAjax()) {
//构建数组
$data = input('post.');
$data['addtime'] = time();
db('donation')->insert($data);
$result['code'] = 1;
$result['msg'] = '捐赠名单添加成功!';
$result['url'] = url('index');
return $result;
}else{
$this->assign('title',lang('add').'捐赠名单');
$this->assign('info','null');
return $this->fetch('form');
}
}
public function edit(){
if(Request::isAjax()) {
$data = input('post.');
db('donation')->update($data);
$result['code'] = 1;
$result['msg'] = '捐赠名单修改成功!';
$result['url'] = url('index');
return $result;
}else{
$id=input('id');
$info=db('donation')->where(array('id'=>$id))->find();
$this->assign('info',json_encode($info,true));
$this->assign('title',lang('edit').'捐赠名单');
return $this->fetch('form');
}
}
public function del(){
db('donation')->where(array('id'=>input('id')))->delete();
return ['code'=>1,'msg'=>'删除成功!'];
}
public function delall(){
$map[] =array('id','in',input('param.ids/a'));
db('donation')->where($map)->delete();
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
use clt\Form;
class EmptyController extends Common{
protected $dao,$fields;
public function initialize()
{
parent::initialize();
$this->moduleid = $this->mod[MODULE_NAME];
$this->dao = db(MODULE_NAME);
$fields = cache($this->moduleid.'_Field');
foreach($fields as $key => $res){
$res['setup']=string2array($res['setup']);
$this->fields[$key]=$res;
}
unset($fields);
unset($res);
$this->assign ('fields',$this->fields);
}
public function index(){
if(Request::isAjax()){
$request = Request::instance();
$modelname = strtolower($request->controller());
$model = db($modelname);
$keyword=input('post.key');
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$order = "sort asc,id desc";
if (input('post.catid')) {
$catids = db('category')->where(array('parentid'=>input('post.catid')))->column('id');
if($catids){
$catid = input('post.catid').','.implode(',',$catids);
}else{
$catid = input('post.catid');
}
}
$cinfo= db('category')->where(array('id'=>input('post.catid')))->field('catdir,is_show')->find();
if(!empty($keyword) ){
$map[]=array('title','like','%'.$keyword.'%');
}
$prefix=config('database.prefix');
$Fields=Db::getConnection()->getFields($prefix.$modelname);
foreach ($Fields as $k=>$v){
$field[$k] = $k;
}
if(in_array('catid',$field)){
$map[]=array('catid','in',$catid);
}
$list = $model
->where($map)
->order($order)
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
$rsult['code'] = 0;
$rsult['msg'] = "获取成功";
$lists = $list['data'];
foreach ($lists as $k=>$v ){
$lists[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
$lists[$k]['catdir'] = $cinfo['catdir'];
$lists[$k]['is_show'] = $cinfo['is_show'];
$lists[$k]['url'] = url('home/'.$cinfo['catdir'].'/info',['id'=>$v['id'],'catId'=>$v['catid']]);
}
$rsult['data'] = $lists;
$rsult['count'] = $list['total'];
$rsult['rel'] = 1;
return $rsult;
}else{
return $this->fetch ('content/index');
}
}
public function edit(){
$id = input('id');
$request = Request::instance();
$controllerName = $request->controller();
if($controllerName=='Page'){
$p = $this->dao->where('id',$id)->find();
if(empty($p)){
$data['id']=$id;
$data['title'] = $this->categorys[$id]['catname'];
$data['keywords'] = $this->categorys[$id]['keywords'];
$this->dao->insert($data);
}
}
$info = $this->dao->where('id',$id)->find();
$form=new Form($info);
$returnData['vo'] = $info;
$returnData['form'] = $form;
$this->assign ('info', $info );
$this->assign ( 'form', $form );
$this->assign ( 'title', '编辑内容' );
return $this->fetch('content/edit');
}
function update(){
$request = Request::instance();
$controllerName = $request->controller();
$model = $this->dao;
$fields = $this->fields;
$data = $this->checkfield($fields,Request::except('file'));
if(isset($data['code'])){
return ['code'=>0,'msg'=>$data['msg']];
}
if(isset($fields['updatetime'])) {
$data['userid'] = session('aid');
}
if(isset($fields['updatetime'])) {
$data['updatetime'] = time();
}
$title_style ='';
if (isset($data['style_color'])) {
$title_style .= 'color:' . $data['style_color'].';';
unset($data['style_color']);
}else{
$title_style .= 'color:#222;';
}
if (isset($data['style_bold'])) {
$title_style .= 'font-weight:' . $data['style_bold'].';';
unset($data['style_bold']);
}else{
$title_style .= 'font-weight:normal;';
}
if($fields['title']['setup']['style']==1) {
$data['title_style'] = $title_style;
}
if($controllerName!='Page') {
$data['updatetime'] = time();
}
unset($data['aid']);
unset($data['pics_name']);
//编辑多图和多文件
foreach ($fields as $k=>$v){
if($v['type']=='files' ){
if(!$data[$k]){
$data[$k]='';
}
$data[$v['field']] = $data['images'];
}
if($v['type']=='images'){
if(!isset($data[$k])){
$data[$k]='';
}
if($data[$k]){
$data[$v['field']] = implode(';',$data[$k]);
}
}
}
$list=$model->strict(false)->update($data);
if (false !== $list) {
if($controllerName=='Page'){
$result['url'] = url("admin/category/index");
}else{
$result['url'] = url("admin/".$controllerName."/index",array('catid'=>$data['catid']));
}
$result['msg'] = '修改成功!';
$result['code'] = 1;
return $result;
} else {
$result['msg'] = '修改失败!';
$result['code'] = 0;
return $result;
}
}
public function set_categorys($categorys = array()) {
if (is_array($categorys) && !empty($categorys)) {
foreach ($categorys as $id => $c) {
$this->categorys[$c['id']] = $c;
$r = db('category')->where("parentid = $c[id]")->order('listorder ASC,id ASC')->select();
$this->set_categorys($r);
}
}
return true;
}
function checkfield($fields,$post){
foreach ( $post as $key => $val ) {
if(isset($fields[$key])){
$setup=$fields[$key]['setup'];
if(!empty($fields[$key]['required']) && empty($post[$key])){
$result['msg'] = $fields[$key]['errormsg']?$fields[$key]['errormsg']:'缺少必要参数!';
$result['code'] = 0;
return $result;
}
if(isset($setup['multiple'])){
if(is_array($post[$key])){
$post[$key] = implode(',',$post[$key]);
}
}
if(isset($setup['inputtype'])){
if($setup['inputtype']=='checkbox'){
$post[$key] = implode(',',$post[$key]);
}
}
if(isset($setup['fieldtype'])){
if($fields[$key]['type']=='checkbox'){
$post[$key] = implode(',',$post[$key]);
}
}
if($fields[$key]['type']=='datetime'){
$post[$key] =strtotime($post[$key]);
}elseif($fields[$key]['type']=='textarea'){
$post[$key]=addslashes($post[$key]);
}elseif($fields[$key]['type']=='linkage'){
if($post[$key][0]){
$post[$key] = implode(',',$post[$key]);
}else{
unset($post[$key]);
}
}elseif($fields[$key]['type']=='editor'){
if(isset($post['add_description']) && $post['description'] == '' && isset($post['content'])) {
$content = stripslashes($post['content']);
$description_length = intval($post['description_length']);
$post['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;'), '', strip_tags($content)),$description_length);
$post['description'] = addslashes($post['description']);
}
if(isset($post['auto_thumb']) && $post['thumb'] == '' && isset($post['content'])) {
$content = $content ? $content : stripslashes($post['content']);
$auto_thumb_no = intval($post['auto_thumb_no']) * 3;
if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
$post['thumb'] = $matches[$auto_thumb_no][0];
}
}
}
}
}
return $post;
}
public function add(){
$form=new Form();
$this->assign ( 'form', $form );
$this->assign ( 'title', '添加内容' );
return $this->fetch('content/edit');
}
public function insert(){
$request = Request::instance();
$controllerName = $request->controller();
$model = $this->dao;
$fields = $this->fields;
$data = $this->checkfield($fields,Request::except('file'));
if(isset($data['code']) && $data['code']==0){
return $data;
}
if(isset($fields['createtime']) && !isset($data['createtime']) ){
$data['createtime'] = time();
}
if(isset($fields['updatetime']) && !isset($data['updatetime']) ) {
$data['updatetime'] = time();
}
if($controllerName!='Page') {
if (isset($fields['updatetime'])){
$data['updatetime'] = $data['createtime'];
}
}
$data['userid'] = session('aid');
$data['username'] = session('username');
$title_style ='';
if (isset($data['style_color'])) {
$title_style .= 'color:' . $data['style_color'].';';
unset($data['style_color']);
}else{
$title_style .= 'color:#222;';
}
if (isset($data['style_bold'])) {
$title_style .= 'font-weight:' . $data['style_bold'].';';
unset($data['style_bold']);
}else{
$title_style .= 'font-weight:normal;';
}
if($fields['title']['setup']['style']==1) {
$data['title_style'] = $title_style;
}
unset($data['style_color']);
unset($data['style_bold']);
unset($data['aid']);
unset($data['pics_name']);
//编辑多图和多文件
foreach ($fields as $k=>$v){
if($v['type']=='files' ){
if(!$data[$k]){
$data[$k]='';
}
$data[$v['field']] = $data['images'];
}
if($v['type']=='images'){
if(!isset($data[$k])){
$data[$k]='';
}
if($data[$k]){
$data[$v['field']] = implode(';',$data[$k]);
}
}
}
$id= $model->insertGetId($data);
if ($id !==false) {
if($controllerName=='page'){
$result['url'] = url("admin/category/index");
}else{
$result['url'] = url("admin/".$controllerName."/index",array('catid'=>$data['catid']));
}
$result['msg'] = '添加成功!';
$result['code'] = 1;
return $result;
} else {
$result['msg'] = '添加失败!';
$result['code'] = 0;
return $result;
}
}
public function listDel(){
$id = input('post.id');
$model = $this->dao;
$model->where(array('id'=>$id))->delete();//转入回收站
return ['code'=>1,'msg'=>'删除成功!'];
}
public function delAll(){
$map[] =array('id','in',input('post.ids/a'));
$model = $this->dao;
$model->where($map)->delete();
$result['code'] = 1;
$result['msg'] = '删除成功!';
$result['url'] = url('index',array('catid'=>input('post.catid')));
return $result;
}
public function listorder(){
$model = $this->dao;
$catid = input('catid');
$data = input('post.');
$model->update($data);
$result = ['msg' => '排序成功!','url'=>url('index',array('catid'=>$catid)), 'code' => 1];
return $result;
}
public function delImg(){
if(!input('post.url')){
return ['code'=>0,'请指定要删除的图片资源'];
}
$file = ROOT_PATH.__PUBLIC__.input('post.url');
if(file_exists($file) && trim(input('post.url'))!=''){
is_dir($file) ? dir_delete($file) : unlink($file);
}
if(input('post.id')){
$picurl = input('post.picurl');
$picurlArr = explode(':',$picurl);
$pics = substr(implode(":::",$picurlArr),0,-3);
$model = $this->dao;
$map['id'] =input('post.id');
$model->where($map)->update(array('pics'=>$pics));
}
$result['msg'] = '删除成功!';
$result['code'] = 1;
return $result;
}
public function getRegion(){
$Region=db("region");
$map['pid'] = input("pid");
$list=$Region->where($map)->select();
return $list;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
use think\Controller;
class Feast extends Common
{
public function index(){
if(request()->isPost()) {
$key = input('post.key');
$this->assign('testkey', $key);
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = Db::name('feast')
->where('title', 'like', "%" . $key . "%")
->order('sort')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:i',$v['addtime']);
$list['data'][$k]['type'] = $v['type']==1?'阳历':'农历';
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
public function add(){
if(request()->isPost()) {
//构建数组
$data = input('post.');
$data['addtime'] = time();
db('feast')->insert($data);
return ['code'=>1,'msg'=>'节日添加成功!','url'=>url('index')];
}else{
$this->assign('title',lang('add').'节日');
$this->assign('info','null');
return $this->fetch('form');
}
}
public function edit(){
if(request()->isPost()) {
$data = input('post.');
if(db('feast')->update($data)!==false){
return ['code'=>1,'msg'=>'节日修改成功!','url'=>url('index')];
}else{
return ['code'=>0,'msg'=>'节日修改失败!'];
}
}else{
$id=input('id');
$adInfo=db('feast')->where(array('id'=>$id))->find();
$this->assign('info',json_encode($adInfo,true));
$this->assign('title',lang('edit').'节日');
return $this->fetch('form');
}
}
//设置节日状态
public function editState(){
$id=input('post.id');
$open=input('post.open');
if(db('feast')->where('id='.$id)->update(['open'=>$open])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function feastOrder(){
$feast=db('feast');
$data = input('post.');
if($feast->update($data)!==false){
return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function del(){
db('feast')->where(array('id'=>input('id')))->delete();
return ['code'=>1,'msg'=>'删除成功!'];
}
/***********************节日元素列表****************************************************************/
public function element(){
if(request()->isPost()) {
$key = input('post.key');
$this->assign('testkey', $key);
$page =input('page')?input('page'):1;
$pid = input('pid');
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = Db::name('feast_element')
->where([['title','like', "%" . $key . "%"],['pid','=',$pid]])
->order('sort')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:i',$v['addtime']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
public function add_element(){
if(request()->isPost()) {
//构建数组
$data = input('post.');
$data['addtime'] = time();
$data['pid'] = input('pid');
db('feast_element')->insert($data);
return ['code'=>1,'msg'=>'节日元素添加成功!','url'=>url('element',array('pid'=>input('pid')))];
}else{
$this->assign('title',lang('add').'节日元素');
$this->assign('info','null');
return $this->fetch('element_form');
}
}
public function edit_element(){
if(request()->isPost()) {
$data = input('post.');
if(db('feast_element')->update($data)!==false){
return ['code'=>1,'msg'=>'节日元素修改成功!','url'=>url('element',array('pid'=>input('pid')))];
}else{
return ['code'=>0,'msg'=>'节日元素修改失败!'];
}
}else{
$id=input('id');
$adInfo=db('feast_element')->where(array('id'=>$id))->find();
$this->assign('info',json_encode($adInfo,true));
$this->assign('title',lang('edit').'节日元素');
return $this->fetch('element_form');
}
}
//设置节日元素状态
public function elementState(){
$id=input('post.id');
$open=input('post.open');
if(db('feast_element')->where('id='.$id)->update(['open'=>$open])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function elementOrder(){
$data = input('post.');
if(db('feast_element')->update($data)!==false){
return $result = ['msg' => '操作成功!', 'code' =>1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
public function delElement(){
db('feast_element')->where(array('id'=>input('id')))->delete();
return ['code'=>1,'msg'=>'删除成功!'];
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Env;
class Index extends Common
{
public function initialize(){
parent::initialize();
}
public function index(){
//导航
// 获取缓存数据
$authRule = cache('authRule');
if(!$authRule){
$authRule = db('auth_rule')->where('menustatus=1')->order('sort')->select();
cache('authRule', $authRule, 3600);
}
//声明数组
$menus = array();
foreach ($authRule as $key=>$val){
$authRule[$key]['href'] = url($val['href']);
if($val['pid']==0){
if(session('aid')!=1){
if(in_array($val['id'],$this->adminRules)){
$menus[] = $val;
}
}else{
$menus[] = $val;
}
}
}
foreach ($menus as $k=>$v){
foreach ($authRule as $kk=>$vv){
if($v['id']==$vv['pid']){
if(session('aid')!=1) {
if (in_array($vv['id'], $this->adminRules)) {
$menus[$k]['children'][] = $vv;
}
}else{
$menus[$k]['children'][] = $vv;
}
}
}
}
$this->assign('menus',json_encode($menus,true));
return $this->fetch();
}
public function main(){
$version = Db::query('SELECT VERSION() AS ver');
$config = [
'url' => $_SERVER['HTTP_HOST'],
'document_root' => $_SERVER['DOCUMENT_ROOT'],
'server_os' => PHP_OS,
'server_port' => $_SERVER['SERVER_PORT'],
'server_ip' => $_SERVER['SERVER_ADDR'],
'server_soft' => $_SERVER['SERVER_SOFTWARE'],
'php_version' => PHP_VERSION,
'mysql_version' => $version[0]['ver'],
'max_upload_size' => ini_get('upload_max_filesize')
];
$this->assign('config', $config);
return $this->fetch();
}
public function welcome(){
$config = "Welcome";
$this->assign('config', $config);
return $this->fetch();
}
public function navbar(){
return $this->fetch();
}
public function nav(){
return $this->fetch();
}
public function clear(){
$R = Env::get('runtime_path');
if ($this->_deleteDir($R)) {
$result['info'] = '清除缓存成功!';
$result['status'] = 1;
} else {
$result['info'] = '清除缓存失败!';
$result['status'] = 0;
}
$result['url'] = url('admin/index/index');
return $result;
}
private function _deleteDir($R)
{
$handle = opendir($R);
while (($item = readdir($handle)) !== false) {
if ($item != '.' and $item != '..') {
if (is_dir($R . '/' . $item)) {
$this->_deleteDir($R . '/' . $item);
} else {
if (!unlink($R . '/' . $item))
die('error!');
}
}
}
closedir($handle);
return rmdir($R);
}
//退出登陆
public function logout(){
session(null);
$this->redirect('login/index');
}
}
... ...
<?php
namespace app\admin\controller;
class Link extends Common
{
public function index(){
if(request()->isPost()) {
$val=input('post.val');
$map = '';
if (!empty($val)){
$map['name|url'] = array('like',"%".$val."%");
}
$link=db('link')->where($map)->order('sort')->select();
foreach ($link as $k=>$v){
$link[$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$link,'rel'=>1];
}
return $this->fetch();
}
//修改友情链接状态
public function linkState(){
$id=input('post.id');
$open=input('post.open');
if(db('link')->where('link_id='.$id)->update(['open'=>$open])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function listOrder(){
$data = input('post.');
if(db('link')->update($data)!==false){
cache('linkList', NULL);
return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' => 1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
//添加
public function add(){
if(request()->isPost()){
$data = input('post.');
$data['addtime'] = time();
db('link')->insert($data);
$result['code'] = 1;
$result['msg'] = '友情链接添加成功!';
$result['url'] = url('index');
cache('linkList', NULL);
return $result;
}else{
$this->assign('title',lang('add').lang('link'));
$this->assign('info','null');
return $this->fetch('form');
}
}
//修改友情链接
public function edit(){
if(request()->isPost()){
$data = input('post.');
db('link')->update($data);
$result['code'] = 1;
$result['msg'] = '友情链接修改成功!';
$result['url'] = url('index');
cache('linkList', NULL);
return $result;
}else{
$link_id=input('param.link_id');
$info=db('link')->where(array('link_id'=>$link_id))->find();
$this->assign('info',json_encode($info,true));
$this->assign('title',lang('edit').lang('link'));
return $this->fetch('form');
}
}
public function del(){
db('link')->where(array('link_id'=>input('link_id')))->delete();
cache('linkList', NULL);
return ['code'=>1,'msg'=>'删除成功!'];
}
public function delall(){
$map[] =array('link_id','IN',input('param.ids/a'));
db('link')->where($map)->delete();
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
cache('linkList', NULL);
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Admin;
use think\captcha\Captcha;
class Login extends Controller
{
private $cache_model,$system;
public function initialize(){
if (session('aid')) {
$this->redirect('admin/index/index');
}
$this->cache_model=array('Module','AuthRule','Category','Posid','Field','System');
$this->system = cache('System');
$this->assign('system',$this->system);
if(empty($this->system)){
foreach($this->cache_model as $r){
savecache($r);
}
}
}
public function index(){
if(request()->isPost()) {
$data = input('post.');
$admin = new Admin();
$return = $admin->login($data,$this->system['code']);
return ['code' => $return['code'], 'msg' => $return['msg']];
}else{
return $this->fetch();
}
}
public function verify(){
$config = [
// 验证码字体大小
'fontSize' => 25,
// 验证码位数
'length' => 4,
// 关闭验证码杂点
'useNoise' => false,
'bg' => [255,255,255],
];
$captcha = new Captcha($config);
return $captcha->entry();
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
class Message extends Common
{
public function index(){
if(request()->isPost()) {
$key=input('post.key');
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = db('message')
->where('name|tel|content', 'like', "%" . $key . "%")
->order('addtime desc')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
//删除留言
public function del(){
$map['message_id']=input('message_id');
db('message')->where($map)->delete();
return $result = ['code'=>1,'msg'=>'删除成功!'];
}
public function delall(){
$map[] =array('message_id','IN',input('param.ids/a'));
db('message')->where($map)->delete();
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
class Module extends Common
{
protected $dao;
function initialize()
{
parent::initialize();
$this->dao=db('module');
$field_pattern = [
['name'=>'defaul','title'=>'默认'],
['name'=>'email','title'=>'电子邮件'],
['name'=>'url','title'=>'网址'],
['name'=>'date','title'=>'日期'],
['name'=>'number','title'=>'有效的数值'],
['name'=>'digits','title'=>'数字'],
['name'=>'creditcard','title'=>'信用卡号码'],
['name'=>'equalTo','title'=>'再次输入相同的值'],
['name'=>'ip4','title'=>'IP'],
['name'=>'mobile','title'=>'手机号码'],
['name'=>'zipcode','title'=>'邮编'],
['name'=>'qq','title'=>'QQ'],
['name'=>'idcard','title'=>'身份证号'],
['name'=>'chinese','title'=>'中文字符'],
['name'=>'cn_username','title'=>'中文英文数字和下划线'],
['name'=>'tel','title'=>'电话号码'],
['name'=>'english','title'=>'英文'],
['name'=>'en_num','title'=>'英文数字和下划线'],
];
$this->assign('pattern', json_encode($field_pattern,true));
}
public function index(){
if(Request::isAjax()) {
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = db('module')->order('sort asc')
->paginate($pageSize)
->toArray();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}else{
return $this->fetch();
}
}
public function edit(){
if(request()->isPost()){
$data = Request::except('name');
if(db('module')->update($data)!==false){
savecache('Module');
return array('code'=>1,'url'=>url('index'),'msg'=>'修改成功!');
}else{
return array('code'=>0,'url'=>url('index'),'msg'=>'修改失败!');
}
}else{
$map['id'] = input('param.id');
$info = db('module')->field('id,title,name,description,listfields')->where($map)->find();
$this->assign('title',lang('edit').lang('module'));
$this->assign('info', json_encode($info,true));
return $this->fetch('form');
}
}
public function add(){
if(request()->isPost()){
//获取数据库所有表名
$tables = Db::getConnection()->getTables();
//组装表名
$prefix = config('database.prefix');
$tablename = $prefix.input('post.name');
//判断表名是否已经存在
if(in_array($tablename,$tables)){
$result['code'] = 0;
$result['info'] = '该表已经存在!';
return $result;
}
$name = ucfirst(input('post.name'));
$data = Request::except('emptytable');
$data['type'] = 1;
$moduleid = db('module')->insertGetId($data);
if(empty($moduleid)){
$result['code'] = 0;
$result['msg'] = '添加模型失败!';
return $result;
}
$emptytable =input('post.emptytable');
if($emptytable=='0'){
Db::execute("CREATE TABLE `".$tablename."` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`catid` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '分类ID',
`userid` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
`username` varchar(40) NOT NULL DEFAULT '' COMMENT '用户名',
`title` varchar(120) NOT NULL DEFAULT '' COMMENT '标题',
`title_style` varchar(225) NOT NULL DEFAULT '' COMMENT '标题样式',
`thumb` varchar(225) NOT NULL DEFAULT '' COMMENT '缩略图',
`keywords` varchar(120) NOT NULL DEFAULT '' COMMENT '关键词',
`description` mediumtext NOT NULL COMMENT '描述',
`content` mediumtext NOT NULL COMMENT '内容',
`template` varchar(40) NOT NULL DEFAULT '' COMMENT '模板',
`posid` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '推荐位',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态',
`recommend` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '允许评论',
`readgroup` varchar(100) NOT NULL DEFAULT '' COMMENT '访问权限',
`readpoint` smallint(5) NOT NULL DEFAULT '0' COMMENT '阅读权限',
`sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
`hits` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击',
`createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updatetime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `status` (`id`,`status`,`sort`),
KEY `catid` (`id`,`catid`,`status`),
KEY `sort` (`id`,`catid`,`status`,`sort`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'catid', '栏目', '', '1', '1', '6', '', '必须选择一个栏目', '', 'catid', '','1','', '1', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'title', '标题', '', '1', '1', '80', '', '标题必须为1-80个字符', '', 'title', 'array (\n \'thumb\' => \'1\',\n \'style\' => \'1\',\n \'size\' => \'55\',\n)','1','', '2', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'keywords', '关键词', '', '0', '0', '80', '', '', '', 'text', 'array (\n \'size\' => \'55\',\n \'default\' => \'\',\n \'ispassword\' => \'0\',\n \'fieldtype\' => \'varchar\',\n)','1','', '3', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'description', 'SEO简介', '', '0', '0', '0', '', '', '', 'textarea', 'array (\n \'fieldtype\' => \'mediumtext\',\n \'rows\' => \'4\',\n \'cols\' => \'55\',\n \'default\' => \'\',\n)','1','', '4', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'content', '内容', '', '0', '0', '0', '', '', '', 'editor', 'array (\n \'toolbar\' => \'full\',\n \'default\' => \'\',\n \'height\' => \'\',\n \'showpage\' => \'1\',\n \'enablekeylink\' => \'0\',\n \'replacenum\' => \'\',\n \'enablesaveimage\' => \'0\',\n \'flashupload\' => \'1\',\n \'alowuploadexts\' => \'\',\n)','1','', '5', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'createtime', '发布时间', '', '1', '0', '0', 'date', '', 'createtime', 'datetime', '','1','', '6', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'status', '状态', '', '0', '0', '0', '', '', '', 'radio', 'array (\n \'options\' => \'发布|1\r\n定时发布|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'75\',\n \'default\' => \'1\',\n)','1','','7', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'recommend', '允许评论', '', '0', '0', '1', '', '', '', 'radio', 'array (\n \'options\' => \'允许评论|1\r\n不允许评论|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'\',\n \'default\' => \'\',\n)','1','', '8', '0', '0')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'readpoint', '阅读收费', '', '0', '0', '5', '', '', '', 'number', 'array (\n \'size\' => \'5\',\n \'numbertype\' => \'1\',\n \'decimaldigits\' => \'0\',\n \'default\' => \'0\',\n)','1','', '9', '0', '0')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'hits', '点击次数', '', '0', '0', '8', '', '', '', 'number', 'array (\n \'size\' => \'10\',\n \'numbertype\' => \'1\',\n \'decimaldigits\' => \'0\',\n \'default\' => \'0\',\n)','1','', '10', '0', '0')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'readgroup', '访问权限', '', '0', '0', '0', '', '', '', 'groupid', 'array (\n \'inputtype\' => \'checkbox\',\n \'fieldtype\' => \'tinyint\',\n \'labelwidth\' => \'85\',\n \'default\' => \'\',\n)','1','', '11', '0', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'posid', '推荐位', '', '0', '0', '0', '', '', '', 'posid', '','1','', '12', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'template', '模板', '', '0', '0', '0', '', '', '', 'template', '','1','', '13', '1', '1')");
}else{
Db::execute("CREATE TABLE `".$tablename."` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`title` varchar(120) NOT NULL DEFAULT '' COMMENT '标题',
`title_style` varchar(225) NOT NULL DEFAULT '' COMMENT '标题样式',
`thumb` varchar(225) NOT NULL DEFAULT '' COMMENT '缩略图',
`hits` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态',
`userid` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
`username` varchar(40) NOT NULL DEFAULT '' COMMENT '用户名',
`sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
`createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updatetime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`lang` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '语言',
`template` varchar(40) NOT NULL DEFAULT '' COMMENT '模板',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ('".$moduleid."', 'title', '标题', '', '1', '1', '80', '', '标题必须为1-80个字符', '', 'title', 'array (\n \'thumb\' => \'1\',\n \'style\' => \'1\',\n \'size\' => \'55\',\n)','1','', '2', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'hits', '点击次数', '', '0', '0', '8', '', '', '', 'number', 'array (\n \'size\' => \'10\',\n \'numbertype\' => \'1\',\n \'decimaldigits\' => \'0\',\n \'default\' => \'0\',\n)','1','', '8', '0', '0')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'createtime', '发布时间', '', '1', '0', '0', 'date', '', 'createtime', 'datetime', '','1','', '97', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'template', '模板', '', '0', '0', '0', '', '', '', 'template', '','1','', '99', '1', '1')");
Db::execute("INSERT INTO `".$prefix."field` (`moduleid`,`field`,`name`,`tips`,`required`,`minlength`,`maxlength`,`pattern`,`errormsg`,`class`,`type`,`setup`,`ispost`,`unpostgroup`,`sort`,`status`,`issystem`) VALUES ( '".$moduleid."', 'status', '状态', '', '0', '0', '0', '', '', '', 'radio', 'array (\n \'options\' => \'发布|1\r\n定时发布|0\',\n \'fieldtype\' => \'tinyint\',\n \'numbertype\' => \'1\',\n \'labelwidth\' => \'75\',\n \'default\' => \'1\',\n)','1','', '98', '1', '1')");
}
if ($moduleid !==false) {
savecache('Module');
$result['code'] = 1;
$result['msg'] = '添加模型成功!';
$result['url'] = url('index');
return $result;
}
}else{
$this->assign('title',lang('add').lang('module'));
$this->assign('info','null');
return $this->fetch('form');
}
}
//模型状态
public function moduleState(){
$id=input('post.id');
$status=input('post.status');
if(db('module')->where('id='.$id)->update(['status'=>$status])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
//删除模型
function del() {
$id =input('param.id');
$r = db('module')->find($id);
if(!empty($r)){
$tablename = config('database.prefix').$r['name'];
$m = db('module')->delete($id);
if($m){
Db::execute("DROP TABLE IF EXISTS `".$tablename."`");
db('Field')->where(array('moduleid'=>$id))->delete();
}
}
savecache('Module');
return ['code'=>1,'msg'=>'删除成功!'];
}
/****************************模型字段******************************/
public function field(){
if(request()->isPost()){
$nodostatus = array('catid','title','status','createtime');
$sysfield = array('catid','userid','username','title','thumb','keywords','description','posid','status','createtime','url','template');
$list = db('field')->where("moduleid=".input('param.id'))->order('sort asc,id asc')->select();
foreach ($list as $k=>$v){
if($v['status']==1){
if(in_array($v['field'],$nodostatus)){
$list[$k]['disable']=2;
}else{
$list[$k]['disable']=0;
}
}else{
$list[$k]['disable']=1;
}
if(in_array($v['field'],$sysfield)){
$list[$k]['delStatus']=1;
}else{
$list[$k]['delStatus']=0;
}
}
$this->assign('list', $list);
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}else{
return $this->fetch();
}
}
//修改状态
public function fieldStatus(){
$map['id']=input('post.id');
//判断当前状态情况
$field = db('field');
$status=$field->where($map)->value('status');
if($status==1){
$data['status'] = 0;
}else{
$data['status'] = 1;
}
$field->where($map)->setField($data);
return $data;
}
//添加字段
public function fieldAdd(){
if(Request::isAjax()){
if(input('isajax')) {
$this->assign(input('get.'));
$this->assign(input('post.'));
$name = db('module')->where(array('id' => input('moduleid')))->value('name');
if (input('name')) {
$files = Db::getTableFields(config('database.prefix') . $name);
if(isset($files['type'][input('name')])){
$fieldtype = $files['type'][input('name')];
}else{
$fieldtype = '';
}
$this->assign('fieldtype', $fieldtype);
return view('fieldType');
} else {
return view('fieldAddType');
}
}else{
$data = input('post.');
$fieldName=$data['field'];
$prefix=config('database.prefix');
$name = db('module')->where(array('id'=>$data['moduleid']))->value('name');
$tablename=$prefix.$name;
$Fields=Db::getTableFields($tablename);
if(in_array($fieldName,$Fields)){
$result['msg'] = '字段名已经存在!';
$result['code'] = 0;
return $result;
}
$addfieldsql =$this->get_tablesql($data,'add');
if(isset($data['setup'])) {
$data['setup'] = array2string($data['setup']);
}
$data['status'] =1;
if($data['pattern']=='?'){
$data['pattern'] = 'defaul';
}else{
$pattern= explode(':',$data['pattern']);
$data['pattern'] = $pattern[1];
}
if(empty($data['class'])){
$data['class'] = $data['field'];
}
$model = db('field');
if ($model->insert($data) !==false) {
savecache('Field',$data['moduleid']);
if(is_array($addfieldsql)){
foreach($addfieldsql as $sql){
$model->execute($sql);
}
}else{
$model->execute($addfieldsql);
}
$result['msg'] = '添加成功!';
$result['code'] = 1;
$result['url'] = url('field',array('id'=>input('post.moduleid')));
return $result;
} else {
$result['msg'] = '添加失败!';
$result['code'] = 0;
return $result;
}
}
}else{
$moduleid =input('moduleid');
$this->assign('moduleid',$moduleid);
$this->assign('title',lang('add').lang('field'));
$this->assign('info','null');
return $this->fetch('fieldForm');
}
}
//编辑字段
public function fieldEdit(){
if(Request::isAjax()){
$data = Request::except('oldfield');
$oldfield = input('oldfield');
$fieldName=$data['field'];
$name = db('module')->where(array('id'=>$data['moduleid']))->value('name');
$prefix=config('database.prefix');
if($this->_iset_field($prefix.$name,$fieldName) && $oldfield!=$fieldName){
$result['msg'] = '字段名重复!';
$result['code'] = 0;
return $result;
}
$editfieldsql =$this->get_tablesql(input('post.'),'edit');
if($data['setup']){
$data['setup']=array2string($data['setup']);
}
if(!empty($data['unpostgroup'])){
$data['setup'] = implode(',',$data['unpostgroup']);
}
if($data['pattern']=='?'){
$data['pattern'] = 'defaul';
}else{
$pattern= explode(':',$data['pattern']);
$data['pattern'] = $pattern[1];
}
if(empty($data['class'])){
$data['class'] = $data['field'];
}
$model = db('field');
if (false !== $model->update($data)) {
savecache('Field',$data['moduleid']);
if(is_array($editfieldsql)){
foreach($editfieldsql as $sql){
$model->execute($sql);
}
}else{
$editfieldsql;
$model->execute($editfieldsql);
}
$result['msg'] = '修改成功!';
$result['code'] = 1;
$result['url'] = url('field',array('id'=>input('post.moduleid')));
return $result;
} else {
$result['msg'] = '修改失败!';
$result['code'] = 0;
return $result;
}
}else{
$model = db('field');
$id = input('param.id');
if(empty($id)){
$result['msg'] = '缺少必要的参数!';
$result['code'] = 0;
return $result;
}
$fieldInfo = $model->where(array('id'=>$id))->find();
if($fieldInfo['setup']) $fieldInfo['setup']=string2array($fieldInfo['setup']);
$this->assign('info',json_encode($fieldInfo,true));
$this->assign('title',lang('edit').lang('field'));
$this->assign('moduleid', input('param.moduleid'));
return $this->fetch('fieldForm');
}
}
//字段排序
public function listOrder(){
$model =db('field');
$data = input('post.');
if($model->update($data)!==false){
return $result = ['msg' => '操作成功!','url'=>url('field',array('id'=>input('post.moduleid'))), 'code' => 1];
}else{
return $result = ['code'=>0,'msg'=>'操作失败!'];
}
}
function fieldDel() {
$id=input('id');
$r = db('field')->find($id);
db('field')->delete($id);
$moduleid = $r['moduleid'];
$field = $r['field'];
$prefix=config('database.prefix');
$name = db('module')->where(array('id'=>$moduleid))->value('name');
$tablename=$prefix.$name;
db('field')->execute("ALTER TABLE `$tablename` DROP `$field`");
return ['code'=>1,'msg'=>'删除成功!'];
}
public function get_tablesql($info,$do){
$comment = $info['name'];
$fieldtype = $info['type'];
if(isset($info['setup']['fieldtype'])){
$fieldtype=$info['setup']['fieldtype'];
}
$moduleid = $info['moduleid'];
$default = '';
if(isset($info['setup']['default'])){
$default=$info['setup']['default'];
}
$field = $info['field'];
$prefix = config('database.prefix');
$name = db('module')->where(array('id'=>$moduleid))->value('name');
$tablename=$prefix.$name;
$maxlength = intval($info['maxlength']);
$minlength = intval($info['minlength']);
$numbertype = '';
if(isset($info['setup']['numbertype'])){
$numbertype=$info['setup']['numbertype'];
}
if($do=='add'){
$do = ' ADD ';
}else{
$oldfield = $info['oldfield'];
$do = " CHANGE `".$oldfield."` ";
}
switch($fieldtype) {
case 'varchar':
if(!$maxlength){$maxlength = 255;}
$maxlength = min($maxlength, 255);
$sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'title':
$thumb = $info['setup']['thumb'];
$style = $info['setup']['style'];
if(!$maxlength){$maxlength = 255;}
$maxlength = min($maxlength, 255);
$sql[] = "ALTER TABLE `$tablename` $do `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT '$default' COMMENT '$comment'";
if(!$this->_iset_field($tablename,'thumb')){
if($thumb==1) {
$sql[] = "ALTER TABLE `$tablename` ADD `thumb` VARCHAR( 100 ) NOT NULL DEFAULT '' COMMENT '缩略图'";
}
}else{
if($thumb==0) {
$sql[] = "ALTER TABLE `$tablename` drop column `thumb`";
}
}
if(!$this->_iset_field($tablename,'title_style')){
if($style==1) {
$sql[] = "ALTER TABLE `$tablename` ADD `title_style` VARCHAR( 100 ) NOT NULL DEFAULT '' COMMENT '标题样式'";
}
}else{
if($style==0) {
$sql[] = "ALTER TABLE `$tablename` drop column `title_style`";
}
}
break;
case 'catid':
$sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
break;
case 'number':
$decimaldigits = $info['setup']['decimaldigits'];
$default = $decimaldigits == 0 ? intval($default) : floatval($default);
$sql = "ALTER TABLE `$tablename` $do `$field` ".($decimaldigits == 0 ? 'INT' : 'decimal( 10,'.$decimaldigits.' )')." ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'tinyint':
if(!$maxlength) $maxlength = 3;
$maxlength = min($maxlength,3);
$default = intval($default);
$sql = "ALTER TABLE `$tablename` $do `$field` TINYINT( $maxlength ) ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'smallint':
$default = intval($default);
$sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'int':
$default = intval($default);
$sql = "ALTER TABLE `$tablename` $do `$field` INT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'mediumint':
$default = intval($default);
$sql = "ALTER TABLE `$tablename` $do `$field` INT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
break;
case 'mediumtext':
$sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
break;
case 'text':
$sql = "ALTER TABLE `$tablename` $do `$field` TEXT NOT NULL COMMENT '$comment'";
break;
case 'posid':
$sql = "ALTER TABLE `$tablename` $do `$field` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
break;
//case 'typeid':
//$sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0'";
//break;
case 'datetime':
$sql = "ALTER TABLE `$tablename` $do `$field` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
break;
case 'editor':
$sql = "ALTER TABLE `$tablename` $do `$field` TEXT NOT NULL COMMENT '$comment'";
break;
case 'image':
$sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
break;
case 'images':
$sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
break;
case 'file':
$sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
break;
case 'files':
$sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
break;
case 'template':
$sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
break;
case 'linkage':
$sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
break;
}
return $sql;
}
protected function _iset_field($table,$field){
$fields = Db::getTableFields($table);
return array_search($field,$fields);
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Env;
class Plugin extends Common{
public function initialize(){
parent::initialize();
// 更新插件
$this->insertPlugin($this->scanPlugin());
}
public function index(){
if(Request::isAjax()) {
$list = db('plugin')->select();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return $this->fetch();
}
public function set(){
$condition['type'] = input('param.type');
$condition['code'] = input('param.code');
$model = db('plugin');
$info = $model->where($condition)->find();
if(!$info){
exit($this->error("不存在该插件"));
}
$this->assign('title','配置登录插件');
$info['config'] = unserialize($info['config']);
$this->assign('info',$info);
$this->assign('config_value',unserialize($info['config_value']));
return $this->fetch();
}
public function update(){
$condition['type'] = input('post.type');
$condition['code'] = input('post.code');
$model = db('plugin');
$config = input('post.config/a');
//空格过滤
$config = trim_array_element($config);
if($config){
$config = serialize($config);
}
$row = $model->where($condition)->update(array('config_value'=>$config));
if($row!==false){
$result['code'] = 1;
$result['msg'] = '修改成功!';
}else{
$result['code'] = 0;
$result['msg'] = '修改失败!';
}
return $result;
}
/**
* 插件安装卸载
*/
public function install(){
$condition['type'] = input('post.type');
$condition['code'] = input('post.code');
$update['status'] = input('post.install');
$model = db('plugin');
//卸载插件时 删除配置信息
if($update['status']==0){
$row = db('plugin')->where($condition)->delete();
}else{
$row = $model->where($condition)->update($update);
}
if($row){
$info['code'] = 1;
$info['url'] = url($condition['type']);
$info['msg'] = $update['status'] ? '安装成功!' : '卸载成功!';
}else{
$info['code'] = 0;
$info['msg'] = $update['status'] ? '安装失败' : '卸载失败';
}
return $info;
}
/**
* 插件目录扫描
* @return array 返回目录数组
*/
private function scanPlugin(){
$plugin_field = array();
$field = Env::get('root_path')."/plugins";
$plugin_field = $this->dirscan($field);
$plugin_list=array();
foreach($plugin_field as $k=>$v){
$plugin_list[$v] = $this->dirscan($field.'/'.$v);
}
foreach($plugin_list as $k=>$v){
foreach($v as $k2=>$v2){
if(!file_exists(Env::get('root_path').'/plugins/'.$k.'/'.$v2.'/config.php')){
unset($plugin_list[$k][$k2]);
}else {
$plugin_list[$k][$v2] = include(Env::get('root_path').'/plugins/'.$k.'/'.$v2.'/config.php');
unset($plugin_list[$k][$k2]);
}
}
}
//dump($plugin_list);
return $plugin_list;
}
/**
* 获取插件目录列表
* @param $dir
* @return array
*/
private function dirscan($dir){
$dirArray = array();
if (false != ($handle = opendir($dir))) {
$i=0;
while ( false !== ($file = readdir ( $handle )) ) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".."&&!strpos($file,".")) {
$dirArray[$i]=$file;
$i++;
}
}
//关闭句柄
closedir ( $handle );
}
return $dirArray;
}
/**
* 更新插件到数据库
* @param $plugin_list 本地插件数组
*/
private function insertPlugin($plugin_list){
$d_list = db('plugin')->field('code,type')->select(); // 数据库
$cv = array();
$new_arr = array(); // 本地
//插件类型
foreach($plugin_list as $pt=>$pv){
// 本地对比数据库
foreach($pv as $t=>$v){
foreach ($v['config'] as $key=>$val){
$cv[$val['name']] = $val['value'];
}
$tmp['code'] = $v['code'];
$tmp['type'] = $pt;
$new_arr[] = $tmp;
// 对比数据库 本地有 数据库没有
$is_exit = db('plugin')->where(array('type'=>$pt,'code'=>$v['code']))->find();
if(empty($is_exit)){
$add['code'] = $v['code'];
$add['name'] = $v['name'];
$add['version'] = $v['version'];
$add['icon'] = $v['icon'];
$add['author'] = $v['author'];
$add['desc'] = $v['desc'];
if(isset($v['bank_code'])){
$add['bank_code'] = serialize($v['bank_code']);
}
$add['type'] = $pt;
$add['scene'] = $v['scene'];
$add['config'] = empty($v['config']) ? '' : serialize($v['config']);
$add['config_value'] = empty($cv) ? '' : serialize($cv);
db('plugin')->insert($add);
}
}
}
foreach($d_list as $k=>$v){
if(!in_array($v,$new_arr)){
db('plugin')->where($v)->delete();
}
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
class System extends Common
{
/********************************站点管理*******************************/
//站点设置
public function system($sys_id=1){
$table = db('system');
if(Request::isAjax()) {
$data = Request::except('file');
if($table->where('id',1)->update($data)!==false) {
savecache('System');
return json(['code' => 1, 'msg' => '站点设置保存成功!', 'url' => url('system/system')]);
} else {
return json(array('code' => 0, 'msg' =>'站点设置保存失败!'));
}
}else{
$system = $table->find($sys_id);
$this->assign('system', json_encode($system,true));
return $this->fetch();
}
}
public function email(){
if(Request::isAjax()) {
$datas = input('post.');
foreach ($datas as $k=>$v){
Db::name('config')->where([['name','=',$k],['inc_type','=','smtp']])->update(['value'=>$v]);
}
return json(['code' => 1, 'msg' => '邮箱设置成功!', 'url' => url('system/email')]);
}else{
$smtp = Db::name('config')->where('inc_type','smtp')->select();
$info = convert_arr_kv($smtp,'name','value');
$this->assign('info', json_encode($info,true));
return $this->fetch();
}
}
public function trySend(){
$sender = input('email');
//检查是否邮箱格式
if (!is_email($sender)) {
return json(['code' => 0, 'msg' => '测试邮箱码格式有误']);
}
$arr = db('config')->where('inc_type','smtp')->select();
$config = convert_arr_kv($arr,'name','value');
$content = $config['test_eamil_info'];
$send = send_email($sender, '测试邮件',$content);
if ($send) {
return json(['code' => 1, 'msg' => '邮件发送成功!']);
} else {
return json(['code' => 0, 'msg' => '邮件发送失败!']);
}
}
}
... ...
<?php
namespace app\admin\controller;
use think\facade\Env;
class Template extends Common{
protected $filepath,$publicpath,$viewSuffix;
function initialize()
{
parent::initialize();
$viewPath = config('template.view_path');
$this->viewSuffix = config('template.view_suffix');
$viewPath = $viewPath ? $viewPath : 'view';
$this->filepath = Env::get('app_path').strtolower(config('default_module')).'/'.$viewPath.'/';
$this->publicpath = 'static/home/';
$this->assign ( 'viewSuffix',$this->viewSuffix );
}
/*public function index(){
$type= input('param.type') ? input('param.type') : $this->viewSuffix;
if($type==$this->viewSuffix){
$path=$this->filepath;
}else{
$path=$this->publicpath.$type.'/';
}
$files = dir_list($path,$type);
$templates = array();
foreach ($files as $key=>$file){
$filename = basename($file);
$templates[$key]['value'] = substr($filename,0,strrpos($filename, '.'));
$templates[$key]['filename'] = $filename;
$templates[$key]['filepath'] = $file;
$templates[$key]['filesize']=byte_format(filesize($file));
$templates[$key]['filemtime']=filemtime($file);
$templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)));
}
$this->assign ( 'templates',$templates );
return $this->fetch();
}*/
/*public function add(){
$this->assign ( 'title','添加模版' );
return $this->fetch();
}
public function insert(){
$filename = input('post.file');
$type = input('post.type');
$path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
$file = $path.$filename.'.'.$type;
if(file_exists($file)){
$result['msg'] = '文件已经存在!';
$result['status'] = 0;
return $result;
}
file_put_contents($file,stripslashes(input('post.content')));
$result['msg'] = '添加成功!';
if($type==$this->viewSuffix){
$result['url'] = url('index');
}else{
$result['url'] = url('index',array('type'=>$type));
}
$result['code'] = 1;
return $result;
}
public function edit(){
$filename = input('param.file');
if(input('param.type')){
$type = input('param.type');
}else{
$type = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
}
$path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
$file = $path.$filename;
if(file_exists($file)){
$file=iconv('gb2312','utf-8',$file);
$content = file_get_contents($file);
$this->assign ( 'filename',$filename );
$this->assign ( 'title','修改模版内容' );
$this->assign ( 'file',$file );
$this->assign ( 'content',$content );
}else{
$this->error('文件不存在!');
}
return $this->fetch();
}
public function update(){
$filename = input('post.file');
$type= input('param.type') ? input('param.type') : $this->viewSuffix;
$path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
$file = $path.$filename;
if(file_exists($file)){
file_put_contents($file,stripslashes(input('content')));
$result['msg'] = '修改成功!';
if($type==$this->viewSuffix){
$result['url'] = url('index');
}else{
$result['url'] = url('index',array('type'=>$type));
}
$result['code'] = 1;
return $result;
}else{
$result['msg'] = '文件不存在!';
$result['code'] = 0;
return $result;
}
}
public function delete(){
$filename = input('param.file');
$type = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
$path = $type==$this->viewSuffix ? $path=$this->filepath : $this->publicpath.$type.'/';
$file = $path.$filename;
if(file_exists($file)){
unlink($file);
if($type==$this->viewSuffix){
$this->redirect('index');
}else{
$this->redirect('index',array('type'=>$type));
}
}else{
if($type==$this->viewSuffix){
$this->redirect('index');
}else{
$this->redirect('index',array('type'=>$type));
}
}
}
public function images(){
$path = $this->publicpath.'images/'.input('folder').'/';
$uppath = explode('/',input('folder'));
$leve = count($uppath)-1;
unset($uppath[$leve]);
if($leve>1){
unset($uppath[$leve-1]);
$uppath = implode('/',$uppath).'/';
}else{
$uppath = '';
}
$this->assign ( 'leve',$leve);
$this->assign ( 'uppath',$uppath);
$files = glob($path.'*');
$folders=array();
foreach($files as $key => $file) {
$filename = basename($file);
if(is_dir($file)){
$folders[$key]['filename'] = $filename;
$folders[$key]['filepath'] = $file;
$folders[$key]['ext'] = 'folder';
}else{
$templates[$key]['filename'] = $filename;
$templates[$key]['filepath'] = $file;
$templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
if(!in_array($templates[$key]['ext'],array('gif','jpg','png','bmp'))) $templates[$key]['ico'] =1;
}
}
$this->assign ( 'title','媒体文件' );
$this->assign ( 'path',$path);
$this->assign ( 'folders',$folders );
$this->assign ( 'files',$templates );
return $this->fetch();
}
public function imgDel(){
$path = $this->publicpath.'images/'.input('post.folder');
$file=$path.input('post.filename');
if(file_exists($file)){
is_dir($file) ? dir_delete($file) : unlink($file);
$result['msg'] = '删除成功!';
$result['code'] = 1;
return $result;
}else{
$result['msg'] = '文件不存在!';
$result['code'] = 0;
return $result;
}
}*/
public function index(){
$path = $this->publicpath.'images/'.input('folder').'/';
$uppath = explode('/',input('folder'));
$leve = count($uppath)-1;
unset($uppath[$leve]);
if($leve>1){
unset($uppath[$leve-1]);
$uppath = implode('/',$uppath).'/';
}else{
$uppath = '';
}
$this->assign ( 'leve',$leve);
$this->assign ( 'uppath',$uppath);
$files = glob($path.'*');
$folders=array();
foreach($files as $key => $file) {
$filename = basename($file);
if(is_dir($file)){
$folders[$key]['filename'] = $filename;
$folders[$key]['filepath'] = $file;
$folders[$key]['ext'] = 'folder';
}else{
$templates[$key]['filename'] = $filename;
$templates[$key]['filepath'] = $file;
$templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
if(!in_array($templates[$key]['ext'],array('zip','gif','jpg','png','bmp'))) $templates[$key]['favicon.ico'] =1;
}
}
$this->assign ( 'title','二维码管理' );
$this->assign ( 'path',$path);
$this->assign ( 'folders',$folders );
$this->assign ( 'files',$templates );
return $this->fetch();
}
public function PackzipDownload(){
$path = $this->publicpath.'images/'.input('post.folder');
$file=$path.input('post.filename');
//首先判断是图片还是路径
if($this->isImage($file)!==false){
//是图片
$zip = new \ZipArchive;
//压缩文件名
$filename = $path.'download.zip';
//新建zip压缩包
$obj = $zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
//把图片一张一张加进去压缩
$zip->addFile($file);
//打包zip
$zip->close();
//可以直接重定向下载
//header('Location:'.$filename);
//或者输出下载
/*header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filename)); //文件名
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
return @readfile($filename);*/
}else{
//目录
$zip = new \ZipArchive;
//压缩文件名
$filename = $path.'download.zip';
//新建zip压缩包
$obj = $zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
//把图片一张一张加进去压缩
$files = glob($file.'/*');
foreach($files as $key=>$val){
$zip->addFile($val);
}
//打包zip
$zip->close();
//可以直接重定向下载
header('Location:'.$filename);exit;
//或者输出下载
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filename)); //文件名
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
return @readfile($filename);
}
}
/**
* 判断所传文件是否是图片
*/
public function isImage($filename)
{
$types = '.gif|.jpeg|.png|.bmp'; //定义检查的图片类型
if(file_exists($filename))
{
if (($info = @getimagesize($filename)))
return 0;
$ext = image_type_to_extension($info['2']);
return stripos($types,$ext);
}
else
{
return false;
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
use think\Controller;
use think\facade\Env;
class UpFiles extends Common
{
public function upload(){
// 获取上传文件表单字段名
$fileKey = array_keys(request()->file());
// 获取表单上传文件
$file = request()->file($fileKey['0']);
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move('uploads');
if($info){
$result['code'] = 1;
$result['info'] = '图片上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$result['url'] = '/uploads/'. $path;
return $result;
}else{
// 上传失败获取错误信息
$result['code'] =0;
$result['info'] = $file->getError();
$result['url'] = '';
return $result;
}
}
public function file(){
$fileKey = array_keys(request()->file());
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file($fileKey['0']);
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'zip,rar,pdf,swf,ppt,psd,ttf,txt,xls,doc,docx'])->move('uploads');
if($info){
$result['code'] = 0;
$result['info'] = '文件上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$result['url'] = '/uploads/'. $path;
$result['ext'] = $info->getExtension();
$result['size'] = byte_format($info->getSize(),2);
return $result;
}else{
// 上传失败获取错误信息
$result['code'] =1;
$result['info'] = '文件上传失败!';
$result['url'] = '';
return $result;
}
}
public function pic(){
// 获取上传文件表单字段名
$fileKey = array_keys(request()->file());
// 获取表单上传文件
$file = request()->file($fileKey['0']);
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
if($info){
$result['code'] = 1;
$result['info'] = '图片上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$result['url'] = '/uploads/'. $path;
return json_encode($result,true);
}else{
// 上传失败获取错误信息
$result['code'] =0;
$result['info'] = '图片上传失败!';
$result['url'] = '';
return json_encode($result,true);
}
}
//编辑器图片上传
public function editUpload(){
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file');
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
if($info){
$result['code'] = 0;
$result['msg'] = '图片上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$result['data']['src'] = '/uploads/'. $path;
$result['data']['title'] = $path;
return json_encode($result,true);
}else{
// 上传失败获取错误信息
$result['code'] =1;
$result['msg'] = '图片上传失败!';
$result['data'] = '';
return json_encode($result,true);
}
}
//多图上传
public function upImages(){
$fileKey = array_keys(request()->file());
// 获取表单上传文件
$file = request()->file($fileKey['0']);
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
if($info){
$result['code'] = 0;
$result['msg'] = '图片上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$result["src"] = '/uploads/'. $path;
return $result;
}else{
// 上传失败获取错误信息
$result['code'] =1;
$result['msg'] = '图片上传失败!';
return $result;
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use app\admin\model\Users as UsersModel;
class Users extends Common{
//会员列表
public function index(){
if(request()->isPost()){
$key=input('post.key');
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list=db('users')->alias('u')
->join(config('database.prefix').'user_level ul','u.level = ul.level_id','left')
->field('u.*,ul.level_name')
->where('u.email|u.mobile|u.username','like',"%".$key."%")
->order('u.id desc')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
foreach ($list['data'] as $k=>$v){
$list['data'][$k]['reg_time'] = date('Y-m-d H:s',$v['reg_time']);
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
return $this->fetch();
}
//设置会员状态
public function usersState(){
$id=input('post.id');
$is_lock=input('post.is_lock');
if(db('users')->where('id='.$id)->update(['is_lock'=>$is_lock])!==false){
return ['status'=>1,'msg'=>'设置成功!'];
}else{
return ['status'=>0,'msg'=>'设置失败!'];
}
}
public function edit($id=''){
if(request()->isPost()){
$user = db('users');
$data = input('post.');
$level =explode(':',$data['level']);
$data['level'] = $level[1];
$province =explode(':',$data['province']);
$data['province'] = isset( $province[1])?$province[1]:'';
$city =explode(':',$data['city']);
$data['city'] = isset( $city[1])?$city[1]:'';
$district =explode(':',$data['district']);
$data['district'] = isset( $district[1])?$district[1]:'';
if(empty($data['password'])){
unset($data['password']);
}else{
$data['password'] = md5($data['password']);
}
if ($user->update($data)!==false) {
$result['msg'] = '会员修改成功!';
$result['url'] = url('index');
$result['code'] = 1;
} else {
$result['msg'] = '会员修改失败!';
$result['code'] = 0;
}
return $result;
}else{
$province = db('Region')->where ( array('pid'=>1) )->select ();
$user_level=db('user_level')->order('sort')->select();
$info = UsersModel::get($id);
$this->assign('info',json_encode($info,true));
$this->assign('title',lang('edit').lang('user'));
$this->assign('province',json_encode($province,true));
$this->assign('user_level',json_encode($user_level,true));
$city = db('Region')->where ( array('pid'=>$info['province']) )->select ();
$this->assign('city',json_encode($city,true));
$district = db('Region')->where ( array('pid'=>$info['city']) )->select ();
$this->assign('district',json_encode($district,true));
return $this->fetch();
}
}
public function getRegion(){
$Region=db("region");
$pid = input("pid");
$arr = explode(':',$pid);
$map['pid']=$arr[1];
$list=$Region->where($map)->select();
return $list;
}
public function usersDel(){
db('users')->delete(['id'=>input('id')]);
db('oauth')->delete(['uid'=>input('id')]);
return $result = ['code'=>1,'msg'=>'删除成功!'];
}
public function delall(){
$map[] =array('id','IN',input('param.ids/a'));
db('users')->where($map)->delete();
$result['msg'] = '删除成功!';
$result['code'] = 1;
$result['url'] = url('index');
return $result;
}
/***********************************会员组***********************************/
public function userGroup(){
if(request()->isPost()){
$userLevel=db('user_level');
$list=$userLevel->order('sort')->select();
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
}
return $this->fetch();
}
public function groupAdd(){
if(request()->isPost()){
$data = input('post.');
db('user_level')->insert($data);
$result['msg'] = '会员组添加成功!';
$result['url'] = url('userGroup');
$result['code'] = 1;
return $result;
}else{
$this->assign('title',lang('add')."会员组");
$this->assign('info','null');
return $this->fetch('groupForm');
}
}
public function groupEdit(){
if(request()->isPost()) {
$data = input('post.');
db('user_level')->update($data);
$result['msg'] = '会员组修改成功!';
$result['url'] = url('userGroup');
$result['code'] = 1;
return $result;
}else{
$map['level_id'] = input('param.level_id');
$info = db('user_level')->where($map)->find();
$this->assign('title',lang('edit')."会员组");
$this->assign('info',json_encode($info,true));
return $this->fetch('groupForm');
}
}
public function groupDel(){
$level_id=input('level_id');
if (empty($level_id)){
return ['code'=>0,'msg'=>'会员组ID不存在!'];
}
db('user_level')->where(array('level_id'=>$level_id))->delete();
return ['code'=>1,'msg'=>'删除成功!'];
}
public function groupOrder(){
$userLevel=db('user_level');
$data = input('post.');
$userLevel->update($data);
$result['msg'] = '排序更新成功!';
$result['url'] = url('userGroup');
$result['code'] = 1;
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use think\Db;
use clt\WchatOauth;
use think\facade\Request;
class Wechat extends Common{
private $return = array();
protected $instance_id;
/**
* 微信账户设置
*/
public function config()
{
$info = db('wx_config')->where([ 'key' => 'SHOPWCHAT'])->field('value')->find();
if (empty($info['value'])) {
$info= array(
'value' => array(
'appid' => '',
'appsecret' => '',
'token' => ''
),
'is_use' => 1
);
} else {
$info['value'] = json_decode($info['value'], true);
}
$wchat_config = $info;
// 获取当前域名
$domain_name = Request::domain();
$url = $domain_name.Request::root();
// 去除链接的http://头部
$url_top = substr($url, 7);
// 去除链接的尾部index.php
$url_top = str_replace('/index.php', '', $url_top);
$call_back_url = $domain_name.'/wchat/wchat/relateWeixin';
$this->assign("url", $url_top);
$this->assign("call_back_url", $call_back_url);
$this->assign('wchat_config', $wchat_config["value"]);
$this->assign('title', '微信账户设置');
return $this->fetch();
}
public function setWechatConfig(){
$data = input('post.');
$value['value'] = json_encode($data);
$value['modify_time'] = time();
$value['is_use'] = 1;
db('wx_config')->where([ 'key' => 'SHOPWCHAT'])->update($value);
return json(['code' => 1, 'msg' => '设置成功!', 'url' => url('config')]);
}
/**
*微信菜单
*/
function getInstanceWchatMenu($instance_id)
{
$wx_menu = db('wx_menu');
$foot_menu = $wx_menu->where(['instance_id'=>$instance_id,'pid'=>0])->order('sort asc')->select();
if (! empty($foot_menu)) {
foreach ($foot_menu as $k => $v) {
$foot_menu[$k]['child'] = '';
$second_menu = $wx_menu->where(['instance_id'=>$instance_id,'pid'=>$v['menu_id']])->order('sort asc')->select();
if (! empty($second_menu)) {
$foot_menu[$k]['child'] = $second_menu;
$foot_menu[$k]['child_count'] = count($second_menu);
} else {
$foot_menu[$k]['child_count'] = 0;
}
}
}
return $foot_menu;
}
public function menu(){
error_reporting(0);
$menu_list = $this->getInstanceWchatMenu(0);
$default_menu_info = array(); // 默认显示菜单
$menu_list_count = count($menu_list);
$class_index = count($menu_list);
if ($class_index > 0) {
if ($class_index == MAX_MENU_LENGTH) {
$class_index = MAX_MENU_LENGTH - 1;
}
}
if ($menu_list_count > 0) {
$default_menu_info = $menu_list[$menu_list_count - 1];
} else {
$default_menu_info["menu_name"] = "";
$default_menu_info["menu_id"] = 0;
$default_menu_info["child_count"] = 0;
$default_menu_info["media_id"] = 0;
$default_menu_info["menu_event_url"] = "";
$default_menu_info["menu_event_type"] = 1;
}
$media_detail = array();
if ($default_menu_info["media_id"]) {
// 查询图文消息
$media_detail = $this->gwmd($default_menu_info["media_id"]);
$media_detail["item_list_count"] = count($media_detail["item_list"]);
} else {
$media_detail["create_time"] = "";
$media_detail["title"] = "";
$media_detail["item_list_count"] = 0;
}
$default_menu_info["media_list"] = $media_detail;
$this->assign("wx_name",$this->system['name']);
$this->assign("pagesize",2);
$this->assign("menu_list", $menu_list);
$this->assign("MAX_MENU_LENGTH", MAX_MENU_LENGTH); // 一级菜单数量
$this->assign("MAX_SUB_MENU_LENGTH", MAX_SUB_MENU_LENGTH); // 二级菜单数量
$this->assign("menu_list_count", $menu_list_count);
//dump($default_menu_info);
$this->assign("default_menu_info", $default_menu_info);
$this->assign("class_index", $class_index);
return $this->fetch();
}
public function getweixinmediadetail()
{
$media_id = input('media_id');
$res = $this->gwmd($media_id);
return $res;
}
public function gwmd($media_id)
{
$wx_media = db('wx_media');
$weixin_media_info = $wx_media->find($media_id);
$weixin_media_info['create_time'] = toDate($weixin_media_info['create_time'],'Y-m-d H:i:s');
if (! empty($weixin_media_info)) {
$item_list = db('wx_media_item')->where(['media_id' => $media_id])->select();
$weixin_media_info['item_list'] = $item_list;
}
return $weixin_media_info;
}
public function addweixinmenu(){
$menu = input('menu');
if (! empty($menu)) {
$menu = json_decode($menu, true);
$instance_id = 0;
$menu_name = $menu["menu_name"]; // 菜单名称
$ico = ""; // 菜图标单
$pid = $menu["pid"]; // 父级菜单(一级菜单)
$menu_event_type = $menu["menu_event_type"]; // '1普通url 2 图文素材 3 功能',
$menu_event_url = $menu["menu_event_url"]; // '菜单url',
$media_id = $menu["media_id"]; // '图文消息ID',
$sort = $menu["sort"]; // 排序
$res = $this->addwm($instance_id, $menu_name, $ico, $pid, $menu_event_type, $menu_event_url, $media_id, $sort);
return $res;
}
return - 1;
}
public function addwm($instance_id, $menu_name, $ico, $pid, $menu_event_type, $menu_event_url, $media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'menu_name' => $menu_name,
'ico' => $ico,
'pid' => $pid,
'menu_event_type' => $menu_event_type,
'menu_event_url' => $menu_event_url,
'media_id' => $media_id,
'sort' => $sort,
'create_date' => time()
);
return db('wx_menu')->insertGetId($data);
}
public function updateweixinmenuname()
{
$wx_menu = db('wx_menu');
$data = input('post.');
if(! empty($data['menu_name'])){
$retval = $wx_menu->update($data);
return $retval;
}
return -1;
}
public function deleteWeixinMenu()
{
$menu_id = input('menu_id');
if (! empty($menu_id)) {
$res = db('wx_menu')->where("menu_id=$menu_id or pid=$menu_id")->delete();
return $res;
}
return - 1;
}
public function updateweixinmenueventtype()
{
$data = input('post.');
if (! empty($data['menu_event_type'])) {
$retval = db('wx_menu')->update($data);
return $retval;
}
return - 1;
}
public function updateweixinmenumessage()
{
$menu_event_type = request()->post('menu_event_type', '');
$menu_id = request()->post('menu_id', '');
$media_id = request()->post('media_id', '');
if (! empty($menu_event_type)) {
$retval =db('wx_menu')->where(['menu_id'=>$menu_id])->update(["media_id" => $media_id, "menu_event_type" => $menu_event_type]);
return $retval;
}
return - 1;
}
public function updateweixinmenuurl()
{
$data = input('post.');
if (! empty($data['menu_event_url'])) {
$retval = db('wx_menu')->update($data);
return $retval;
}
return - 1;
}
public function updateweixinmenuSort()
{
$menu_id_arr = input('menu_id_arr');
if (! empty($menu_id_arr)) {
$weixin_menu = db('wx_menu');
$menu_id_arr = explode(",", $menu_id_arr);
$retval = 0;
foreach ($menu_id_arr as $k => $v) {
$data = array(
'sort' => $k + 1,
'modify_date' => time(),
'menu_id'=>$v
);
$retval += $weixin_menu->update($data);
}
return $retval;
}
return - 1;
}
//ajax 加载 选择素材 弹框数据
public function onloadMaterial()
{
$type = request()->post('type', 0);
$search_text = request()->post('search_text', '');
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$condition = array();
if ($type != 0) {
$condition[] = ['type','=',$type];
}
$condition[] = array('title','like', '%' . $search_text . '%');
$wx_media = Db::name('wx_media');
$list = $wx_media->where($condition)->order('sort')->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
if (! empty($list)) {
foreach ($list['data'] as $k => $v) {
$item_list = Db::name('wx_media_item')->where(['media_id' => $v['media_id']])->select();
$list['data'][$k]['item_list'] = $item_list;
$list['data'][$k]['create_time'] = toDate($v['create_time']);
}
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
/**
* 添加 消息
*/
public function addMedia()
{
if (request()->isAjax()) {
$type = request()->post('type', '');
$title = request()->post('title', '');
$content = request()->post('content', '');
$sort = 0;
$res = $this->addWeixinMedia($title, 0, $type, $sort, $content);
return $res;
}
return view('addMedia');
}
public function addWeixinMedia($title, $instance_id, $type, $sort, $content)
{
$wx_media = db('wx_media');
$wx_media->startTrans();
try {
$data_media = array(
'title' => $title,
'instance_id' => $instance_id,
'type' => $type,
'sort' => $sort,
'create_time' => time()
);
$media_id = $wx_media->insertGetId($data_media);
if ($type == 1) {
$this->addWeixinMediaItem($media_id, $title, '', '', '', '', '', '', 0);
} else if ($type == 2) {
$info = explode('`|`', $content);
$this->addWeixinMediaItem($media_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6], 0);
} else if ($type == 3) {
$list = explode('`$`', $content);
foreach ($list as $k => $v) {
$arr = Array();
$arr = explode('`|`', $v);
$this->addWeixinMediaItem($media_id, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], 0);
}
}
$wx_media->commit();
return ['code'=>1,'message'=>'添加成功!','url'=>url('menu')];
} catch (\Exception $e) {
$wx_media->rollback();
return $e->getMessage();
}
// TODO Auto-generated method stub
}
public function addWeixinMediaItem($media_id, $title, $author, $cover, $show_cover_pic, $summary, $content, $content_source_url, $sort)
{
$weixin_media_item = db('wx_media_item');
$data = array(
'media_id' => $media_id,
'title' => $title,
'author' => $author,
'cover' => $cover,
'show_cover_pic' => $show_cover_pic,
'summary' => $summary,
'content' => $content,
'content_source_url' => $content_source_url,
'sort' => $sort
);
$retval = $weixin_media_item->insert($data);
return $retval;
}
public function upload(){
// 获取上传文件表单字段名
$fileKey = array_keys(request()->file());
// 获取表单上传文件
$file = request()->file($fileKey['0']);
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move('uploads');
if($info){
$this->return['code'] = 1;
$this->return['message'] = '图片上传成功!';
$path=str_replace('\\','/',$info->getSaveName());
$this->return['data'] = '/uploads/'. $path;
}else{
// 上传失败获取错误信息
$this->return['code'] =0;
$this->return['message'] = '图片上传失败!';
$this->return['url'] = '';
}
$this->ajaxFileReturn();
}
/**
* 上传文件后,ajax返回信息
*
* 2017年6月9日 19:54:46 王永杰
*
* @param array $return
*/
private function ajaxFileReturn()
{
if (empty($this->return['code']) || null == $this->return['code'] || "" == $this->return['code']) {
$this->return['code'] = 0; // 错误码
}
if (empty($this->return['message']) || null == $this->return['message'] || "" == $this->return['message']) {
$this->return['message'] = ""; // 消息
}
if (empty($this->return['data']) || null == $this->return['data'] || "" == $this->return['data']) {
$this->return['data'] = ""; // 数据
}
echo json_encode($this->return);
//return json_encode($this->return);
}
public function materialmessage()
{
if (request()->isAjax()) {
$type = request()->post('type', 0);
$search_text = request()->post('search_text', '');
$page =input('page',1);
$pageSize =input('limit',config('pageSize'));
$condition = array();
if ($type != 0) {
$condition[] = ['type','=',$type];
}
$condition[] = array('title','like', '%' . $search_text . '%');
$condition = array_filter($condition);
$list = db('wx_media')->where($condition)->order('create_time desc')
->paginate(array('list_rows'=>$pageSize,'page'=>$page))
->toArray();
if (! empty($list)) {
foreach ($list['data'] as $k => $v) {
$item_list = db('wx_media_item')->where(['media_id'=>$v['media_id']])->column('title');
$list['data'][$k]['item_list'] = $item_list;
$list['data'][$k]['create_time'] = toDate($v['create_time']);
}
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
$type = input('param.type',0);
$child_menu_list = array(
array(
'url' => url('materialmessage'),
'menu_name' => "全部",
"active" => $type == 0 ? 1 : 0
),
array(
'url' => url('materialmessage',['type'=>1]),
'menu_name' => "文本",
"active" => $type == 1 ? 1 : 0
),
array(
'url' => url('materialmessage',['type'=>2]),
'menu_name' => "单图文",
"active" => $type == 2 ? 1 : 0
),
array(
'url' => url('materialmessage',['type'=>3]),
'menu_name' => "多图文",
"active" => $type == 3 ? 1 : 0
)
);
$this->assign('type', $type);
$this->assign('child_menu_list', $child_menu_list);
return view('materialmessage');
}
public function updatemedia(){
if (request()->isAjax()) {
$media_id = request()->post('media_id', 0);
$type = request()->post('type', '');
$title = request()->post('title', '');
$content = request()->post('content', '');
$sort = 0;
$res = $this->updateWeixinMedia($media_id, $title, 0, $type, $sort, $content);
return json($res);
}
$media_id = input('media_id', 0);
$weixin_media = db('wx_media');
$weixin_media_info = $weixin_media->where(['media_id'=>$media_id])->find();
if (! empty($weixin_media_info)) {
$weixin_media_item = db('wx_media_item');
$item_list = $weixin_media_item->where(['media_id' => $media_id])->select();
$weixin_media_info['item_list'] = $item_list;
}
$this->assign('info', $weixin_media_info);
return view();
}
public function updateWeixinMedia($media_id, $title, $instance_id, $type, $sort, $content)
{
$weixin_media = db('wx_media');
$weixin_media->startTrans();
try {
// 先修改 图文消息表
$data_media = array(
'title' => $title,
'instance_id' => $instance_id,
'type' => $type,
'sort' => $sort,
'create_time' => time()
);
$weixin_media->where(['media_id' => $media_id])->update($data_media);
// 修改 图文消息内容的时候 先删除了图文消息内容再添加一次
$weixin_media_item = db('wx_media_item');
$weixin_media_item->where(['media_id'=>$media_id])->delete();
if ($type == 1) {
$this->addWeixinMediaItem($media_id, $title, '', '', '', '', '', '', 0);
} else if ($type == 2) {
$info = explode('`|`', $content);
$this->addWeixinMediaItem($media_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6], 0);
} else if ($type == 3) {
$list = explode('`$`', $content);
foreach ($list as $k => $v) {
$arr = Array();
$arr = explode('`|`', $v);
$this->addWeixinMediaItem($media_id, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], 0);
}
}
$weixin_media->commit();
return ['code'=>1,'message'=>'修改成功!'];
} catch (\Exception $e) {
$weixin_media->rollback();
return $e->getMessage();
}
}
public function deleteweixinmediadetail(){
$id = input('id', '');
$res = 0;
if (! empty($id)) {
$weixin_media_item = db('wx_media_item');
$res = $weixin_media_item->where("id=$id")->delete();
return $res;
}
return $res;
}
public function updatemenutoweixin(){
$this->instance_id=0;
$result = $this->updateInstanceMenuToWeixin($this->instance_id);
$auth_info = $this->getInstanceWchatConfig($this->instance_id);
$res='';
if (! empty($auth_info['value']['appid']) && ! empty($auth_info['value']['appsecret'])) {
$wchat_auth = new WchatOauth();
$res = $wchat_auth->menu_create($result);
if (! empty($res)) {
$res = json_decode($res, true);
if ($res['errcode'] == 0) {
$retval = 1;
} else {
$retval = $res['errmsg'];
}
} else {
$retval = 0;
}
} else {
$retval = "当前未配置微信授权";
}
return ['code' => $retval,'wxcode'=>$res['errcode'], 'message' => '操作成功'];
}
public function getInstanceWchatConfig($instance_id)
{
$info = db('wx_config')->where(['key' => 'SHOPWCHAT', 'instance_id' => $instance_id])->field('value')->find();
if (empty($info['value'])) {
return array(
'value' => array(
'appid' => '',
'appsecret' => ''
),
'is_use' => 1
);
} else {
$info['value'] = json_decode($info['value'], true);
return $info;
}
}
public function updateInstanceMenuToWeixin($instance_id)
{
$menu = array();
$menu_list = $this->getInstanceWchatMenu($instance_id);
if (! empty($menu_list)) {
foreach ($menu_list as $k => $v) {
if (! empty($v)) {
$menu_item = array(
'name' => ''
);
$menu_item['name'] = $v['menu_name'];
if (! empty($v['child'])) {
foreach ($v['child'] as $k_child => $v_child) {
if (! empty($v_child)) {
$sub_menu = array();
$sub_menu['name'] = $v_child['menu_name'];
if ($v_child['menu_event_type'] == 1) {
$sub_menu['type'] = 'view';
$sub_menu['url'] = $v_child['menu_event_url'];
} else {
$sub_menu['type'] = 'click';
$sub_menu['key'] = $v_child['menu_id'];
}
$menu_item['sub_button'][] = $sub_menu;
}
}
} else {
if ($v['menu_event_type'] == 1) {
$menu_item['type'] = 'view';
$menu_item['url'] = $v['menu_event_url'];
} else {
$menu_item['type'] = 'click';
$menu_item['key'] = $v['menu_id'];
}
}
$menu[] = $menu_item;
}
}
}
$menu_array = array();
$menu_array['button'] = array();
foreach ($menu as $k => $v) {
$menu_array['button'][] = $v;
}
$menu_array = json_encode($menu_array,JSON_UNESCAPED_UNICODE);
return $menu_array;
}
/*******************************回复设置********************************/
/**
* 关键字 回复
*/
public function keyReplayList()
{
$page =input('page')?input('page'):1;
$pageSize =input('limit')?input('limit'):config('pageSize');
$list = db('wx_key_replay')->order('sort')->paginate(array('list_rows'=>$pageSize,'page'=>$page))->toArray();
if (! empty($list)) {
foreach ($list['data'] as $k => $v) {
$list['data'][$k]['match_type'] = $v['match_type']==2?'全部匹配':'模糊匹配';
$list['data'][$k]['create_time'] = toDate($v['create_time']);
}
}
return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
}
public function replay(){
$type = input('type', 1);
$child_menu_list = array(
array(
'url' => url('replay',['type'=>1]),
'menu_name' => "关注时回复",
"active" => $type == 1 ? 1 : 0
),
array(
'url' => url('replay',['type'=>2]),
'menu_name' => "关键字回复",
"active" => $type == 2 ? 1 : 0
),
array(
'url' => url('replay',['type'=>3]),
'menu_name' => "默认回复",
"active" => $type == 3 ? 1 : 0
)
);
$this->assign('child_menu_list', $child_menu_list);
$this->assign('type', $type);
if ($type == 1) {
$info = db('wxFollowReplay')->where(['instance_id' => 0])->find();
if ($info['reply_media_id'] > 0) {
$weixin_media_info = db('wx_media')->where(['media_id'=>$info['reply_media_id']])->find();
if (! empty($weixin_media_info)) {
$item_list = db('wx_media_item')->where(['media_id'=>$info['reply_media_id']])->select();
$weixin_media_info['item_list'] = $item_list;
}
$info['media_info'] = $weixin_media_info;
}
$this->assign('info', $info);
} else if ($type == 2) {
} else if ($type == 3) {
$info = db('wx_default_replay')->where(['instance_id' => 0])->find();
if ($info['reply_media_id'] > 0) {
$weixin_media_info = db('wx_media')->where(['media_id' => $info['reply_media_id']])->find();
if (!empty($weixin_media_info)) {
$item_list = db('wx_media_item')->where(['media_id' => $info['reply_media_id']])->select();
$weixin_media_info['item_list'] = $item_list;
}
$info['media_info'] = $weixin_media_info;
}
$this->assign('info', $info);
}
return view();
}
/**
* 添加 或 修改 关注时回复
*/
public function addorupdatefollowreply()
{
$id = input('id',0);
$replay_media_id = input('media_id', 0);
if($id==0){
if ($replay_media_id > 0) {
$res = $this->addFollowReplay(0, $replay_media_id, 0);
} else {
return ['code'=>0,'msg'=>'添加失败'];
}
}else{
if ($replay_media_id > 0) {
$res = $this->updateFollowReplay($id, 0, $replay_media_id, 0);
} else {
return ['code'=>0,'msg'=>'修改失败'];
}
}
return $res;
}
public function addFollowReplay($instance_id, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'create_time' => time()
);
$id = db('wx_follow_replay')->insertGetId($data);
if($id){
return ['code'=>$id,'msg'=>'添加成功'];
}else{
return ['code'=>0,'msg'=>'添加失败'];
}
}
public function updateFollowReplay($id, $instance_id, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'modify_time' => time()
);
if(db('wx_follow_replay')->where(['id' => $id])->update($data)!==false){
return ['code'=>1,'msg'=>'修改成功'];
}else{
return ['code'=>0,'msg'=>'修改失败'];
}
}
/**
* 删除 回复
* @return unknown[]
*/
public function delReply()
{
$type = request()->post('type', '');
if ($type == '') {
return ['code'=>0];
} else {
if ($type == 1) {
db('wx_follow_replay')->where(['instance_id'=>0])->delete();
return ['code'=>1,'msg'=>'删除成功!','url'=>url('replay',['type'=>1])];
} else if ($type == 3) {
// 删除 默认回复
db('wx_default_replay')->where(['instance_id'=>0])->delete();
return ['code'=>1,'msg'=>'删除成功!','url'=>url('replay',['type'=>3])];
}
}
}
/**
* 添加 或 修改 默认回复
*/
public function addOrUpdateDefaultReply()
{
$id = input('id',0);
$replay_media_id = input('media_id', 0);
if ($id == 0) {
if ($replay_media_id > 0) {
$res = $this->addDefaultReplay(0, $replay_media_id, 0);
} else {
return ['code'=>0,'msg'=>'添加失败'];
}
} else{
if ($replay_media_id > 0) {
$res = $this->updateDefaultReplay($id, 0, $replay_media_id, 0);
} else {
return ['code'=>0,'msg'=>'修改失败'];
}
}
return $res;
}
public function updateDefaultReplay($id, $instance_id, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'modify_time' => time()
);
if(db('wx_default_replay')->where(['id' => $id])->update($data)!==false){
return ['code'=>1,'msg'=>'修改成功'];
}else{
return ['code'=>0,'msg'=>'修改失败'];
}
}
public function addDefaultReplay($instance_id, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'create_time' => time()
);
$id = db('wx_default_replay')->insertGetId($data);
if($id){
return ['code'=>$id,'msg'=>'添加成功'];
}else{
return ['code'=>0,'msg'=>'添加失败'];
}
}
/**
* 添加 或 修改 关键字 回复
*/
public function addorupdatekeyreplay()
{
if (request()->isAjax()) {
$id = input('id');
$key = input('key', '');
$match_type = input('match_type', 1);
$replay_media_id = input('media_id', 0);
$sort = 0;
if ($id > 0) {
$res = $this->updateKeyReplay($id, 0, $key, $match_type, $replay_media_id, $sort);
}else{
$res = $this->addKeyReplay(0, $key, $match_type, $replay_media_id, $sort);
}
return $res;
}
$id = input('id',0);
$this->assign('id', $id);
$info = array(
'key' => '',
'match_type' => 1,
'reply_media_id' => 0,
'madie_info' => array()
);
if ($id > 0) {
$info = Db::name('wx_key_replay')->where('id',$id)->find();
if ($info['reply_media_id'] > 0) {
$weixin_media_info = Db::name('wx_media')->where('media_id',$info['reply_media_id'])->find();
if (! empty($weixin_media_info)) {
$item_list = Db::name('wx_media_item')->where('media_id' ,$info['reply_media_id'])->select();
$weixin_media_info['item_list'] = $item_list;
}
$info['media_info'] = $weixin_media_info;
}
}
$secend_menu['module_name'] = "编辑回复";
$this->assign("title", "编辑回复");
$child_menu_list = array(
array(
'url' => "Wchat/addOrUpdateKeyReplay.html?id=" . $id,
'menu_name' => "编辑回复",
"active" => 1
)
);
if (! empty($id)) {
$this->assign("secend_menu", $secend_menu);
$this->assign('child_menu_list', $child_menu_list);
}
$this->assign('info', $info);
return view();
}
public function updateKeyReplay($id, $instance_id, $key, $match_type, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'key' => $key,
'match_type' => $match_type,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'create_time' => time()
);
if(db('wx_key_replay')->where('id' , $id)->update($data)!==false){
return ['code'=>1,'msg'=>'修改成功'];
}else{
return ['code'=>0,'msg'=>'修改失败'];
}
}
public function addKeyReplay($instance_id, $key, $match_type, $replay_media_id, $sort)
{
$data = array(
'instance_id' => $instance_id,
'key' => $key,
'match_type' => $match_type,
'reply_media_id' => $replay_media_id,
'sort' => $sort,
'create_time' => time()
);
$id = db('wx_key_replay')->insertGetId($data);
if($id){
return ['code'=>$id,'msg'=>'添加成功'];
}else{
return ['code'=>0,'msg'=>'添加失败'];
}
}
/**
* 删除图文消息
*
* @return number
*/
public function deleteWeixinMedia(){
$media_id = input('media_id', '');
db('wx_media')->where(['media_id'=>$media_id])->delete();
return ['code'=>1,'msg'=>'删除成功'];
}
/**
* 删除 回复
*
* @return unknown[]
*/
public function delKeyReply()
{
$id = input('id');
db('wx_key_replay')->where(['id'=>$id])->delete();
return ['code'=>1,'msg'=>'删除成功'];
}
}
\ No newline at end of file
... ...
<?php
return [
'hello' => '欢迎使用CLTPHP',
'adminInfo' => '个人信息',
'logout' =>'注销',
'home' =>'浏览网站',
'clearCache' =>'清除缓存',
'pleaseEnter' =>'请输入',
'systemInfo' =>'系统信息',
'system' =>'系统',
'systemSet' =>'系统设置',
'websiteName' =>'网站名称',
'WebsiteUrl' =>'网站地址',
'seoTitle' =>'SEO标题',
'seoKeyword' =>'SEO关键字',
'description' =>'SEO描述',
'recordNum' =>'备案号',
'companyAddress' =>'公司地址',
'admin'=>'管理员',
'module'=>'模型',
'user'=>'会员',
'nickname'=>'昵称',
'man'=>'男',
'woman'=>'女',
'message'=>'留言',
'link'=>'链接',
'ad'=>'广告',
'back'=>'返回',
'submit'=>'提交',
'reset'=>'重置',
'open'=>'开启',
'enabled'=>'已开启',
'close'=>'关闭',
'disabled'=>'已禁用',
'yes'=>'是',
'no'=>'否',
'edit'=>'编辑',
'del'=>'删除',
'add'=>'添加',
'list'=>'列表',
'field'=>'字段',
'search'=>'搜索',
'debris'=>'碎片',
'hit'=>'点击',
'name'=>'名称',
'table'=>'表名',
'detail'=>'详述',
'username'=>'用户名',
'userGroup'=>'用户组',
'pwd'=>'密码',
'email'=>'邮箱账号',
'tel'=>'联系电话',
'sex'=>'性别',
'qq'=>'QQ',
'status'=>'状态',
'ip'=>'IP地址',
'action'=>'操作',
'icon'=>'图标',
'order'=>'排序',
'id'=>'编号',
'address'=>'地址',
'content'=>'内容',
'time'=>'时间',
'title'=>'标题',
'Super administrator cannot be deleted'=>'超级管理员不可删除!',
'Are you sure you want to delete it'=>'你确定要删除吗?'
];
\ No newline at end of file
... ...
<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Admin extends Model
{
protected $pk = 'admin_id';
public function login($data,$code){
if($code=='open'){
if(!$this->check($data['vercode'])){
return ['code' => 0, 'msg' => '验证码错误'];
}
}
$user=Db::name('admin')->where('username',$data['username'])->find();
if($user) {
if ($user['is_open']==1 && $user['pwd'] == md5($data['password'])){
session('username', $user['username']);
session('aid', $user['admin_id']);
$avatar = $user['avatar'] == '' ? '/static/admin/images/0.jpg' : $user['avatar'];
session('avatar', $avatar);
return ['code' => 1, 'msg' => '登录成功!']; //信息正确
}else{
return ['code' => 0, 'msg' => '用户名或者密码错误,重新输入!']; //密码错误
}
}else{
return ['code' => 0, 'msg' => '用户不存在!']; //用户不存在
}
}
public function getInfo($admin_id){
$info = Db::name('admin')->field('pwd',true)->find($admin_id);
return $info;
}
public function check($code){
return captcha_check($code);
}
}
... ...
<?php
namespace app\admin\model;
use think\Model;
class AuthGroup extends Model
{
protected $type = [
// 设置addtime为时间戳类型(整型)
'addtime' => 'timestamp:Y-m-d H:i:s',
];
}
\ No newline at end of file
... ...
<?php
namespace app\admin\model;
use think\Model;
class System extends Model
{
protected $name = 'system';
}
\ No newline at end of file
... ...
<?php
namespace app\admin\model;
use think\Model;
class Users extends Model
{
protected $name = 'users';
protected $type = [
// 设置addtime为时间戳类型(整型)
'reg_time' => 'timestamp:Y-m-d H:i:s',
];
// birthday修改器
protected function setpwdAttr($value){
return md5($value);
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\model;
use think\Model;
class authRule extends Model
{
}
\ No newline at end of file
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Admin extends Validate
{
protected $rule = [
'username' => 'require|length:3,25',
'email' =>'email'
];
protected $message = [
'username.require' => '用户名不能为空',
'username.length' => '用户名在3到25个字符之间',
'email.email' => '邮箱格式不正确',
];
}
\ No newline at end of file
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Member extends Validate
{
protected $rule = [
['group_id', 'require', '会员所属用户组必须选择'],
['username', 'require', '用户名不能为空'],
['pwd', 'require|length:6,25', '登录密码不能为空|登录密码位数不能少于6位或者大于15位'],
['petname', 'require', '昵称不能为空'],
['tel', 'checkName:tel|unique:member', '手机号码格式不正确|该手机已注册'],
['email', 'email|unique:member', '邮箱格式不正确|该邮箱已注册'],
];
// 自定义验证规则
protected function checkName($value,$rule,$data){
if(is_mobile_phone($value)){
return true;
}else{
return '手机号码格式不正确';
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Sys extends Validate
{
protected $rule = [
['sys_name', 'require', '站点名称不能为空!'],
['sys_url', 'require', '站点网址不能为空!']
];
}
\ No newline at end of file
... ...
{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
<fieldset class="layui-elem-field layui-field-title">
<legend>{$title}</legend>
</fieldset>
<form class="layui-form layui-form-pane">
<div class="layui-form-item">
<label class="layui-form-label">所属位置</label>
<div class="layui-input-4">
<select name="type_id" lay-verify="required" ng-model="selected" ng-options="v.type_id as v.name for v in group track by v.type_id">
<option value="">请选择所属广告位</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">广告名称</label>
<div class="layui-input-4">
<input type="text" name="name" ng-model="field.name" lay-verify="required" placeholder="{:lang('pleaseEnter')}广告名称" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">广告图片</label>
<input type="hidden" name="pic" id="pic" value="{{field.pic}}">
<div class="layui-input-block">
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
<div class="layui-upload-list">
<img class="layui-upload-img" id="adPic">
<p id="demoText"></p>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">{:lang('ad')}URL</label>
<div class="layui-input-4">
<input type="text" name="url" ng-model="field.url" lay-verify="url" placeholder="{:lang('pleaseEnter')}{:lang('ad')}URL" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">是否审核</label>
<div class="layui-input-block">
<input type="radio" name="open" ng-model="field.open" ng-checked="field.open==1" ng-value="1" title="{:lang('open')}">
<input type="radio" name="open" ng-model="field.open" ng-checked="field.open==0" ng-value="0" title="{:lang('close')}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">{:lang('order')}</label>
<div class="layui-input-4">
<input type="text" name="sort" ng-model="field.sort" value="" placeholder="从小到大排序" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">内容</label>
<div class="layui-input-block">
<textarea ng-model="field.content" placeholder="请输广告内容" name="content" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
<a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
</div>
</div>
</form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/angular.min.js"></script>
<script>
var m = angular.module('hd',[]);
m.controller('ctrl',['$scope',function($scope) {
$scope.field = '{$info|raw}'!='null'?{$info|raw}:{type_id:'',ad_id:'',name:'',url:'',open:1,sort:50,pic:'',content:''};
$scope.group = {$adtypeList|raw};
$scope.selected = {$selected|raw};
layui.use(['form', 'layer','upload'], function () {
var form = layui.form, $ = layui.jquery, upload = layui.upload;
if($scope.field.pic){
adPic.src = $scope.field.pic;
}
form.on('submit(submit)', function (data) {
// 提交到方法 默认为本身
data.field.ad_id = $scope.field.ad_id;
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post("", data.field, function (res) {
layer.close(loading);
if (res.code > 0) {
layer.msg(res.msg, {time: 1800, icon: 1}, function () {
location.href = res.url;
});
} else {
layer.msg(res.msg, {time: 1800, icon: 2});
}
});
});
//普通图片上传
var uploadInst = upload.render({
elem: '#adBtn'
,url: '{:url("UpFiles/upload")}'
,before: function(obj){
//预读本地文件示例,不支持ie8
obj.preview(function(index, file, result){
$('#adPic').attr('src', result); //图片链接(base64)
});
},
done: function(res){
if(res.code>0){
$('#pic').val(res.url);
}else{
//如果上传失败
return layer.msg('上传失败');
}
}
,error: function(){
//演示失败状态,并实现重传
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function(){
uploadInst.upload();
});
}
});
});
}]);
</script>
\ No newline at end of file
... ...
{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
<fieldset class="layui-elem-field layui-field-title">
<legend>{:lang('ad')}管理</legend>
</fieldset>
<div class="demoTable">
<div class="layui-inline">
<input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
</div>
<button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
<a href="{:url('index')}" class="layui-btn">显示全部</a>
<button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
<a href="{:url('add')}" class="layui-btn" style="float:right;"><i class="fa fa-plus" aria-hidden="true"></i>{:lang('add')}{:lang('ad')}</a>
<div style="clear: both;"></div>
</div>
<table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="name">
{{d.name}}{{# if(d.pic){ }}<img src="/static/admin/images/image.gif" onmouseover="layer.tips('<img src={{d.pic}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">{{# } }}
</script>
<script type="text/html" id="order">
<input name="{{d.ad_id}}" data-id="{{d.ad_id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="open">
<input type="checkbox" name="open" value="{{d.ad_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
<a href="{:url('edit')}?ad_id={{d.ad_id}}" class="layui-btn layui-btn-xs">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['table','form'], function() {
var table = layui.table,form = layui.form,$ = layui.jquery;
var tableIn = table.render({
id: 'ad',
elem: '#list',
url: '{:url("index")}',
method: 'post',
page:true,
cols: [[
{checkbox: true, fixed: true},
{field: 'ad_id', title: '{:lang("id")}', width: 80, fixed: true},
{field: 'name', title: '广告名称', width: 400,templet: '#name'},
{field: 'typename', title: '所属位置', width: 160},
{field: 'addtime', title: '{:lang("add")}{:lang("time")}',width: 150},
{field: 'sort', align: 'center', title: '{:lang("order")}', width: 120, templet: '#order'},
{field: 'open', align: 'center', title: '{:lang("status")}', width: 100, toolbar: '#open'},
{width: 160, align: 'center', toolbar: '#action'}
]],
limit:10
});
form.on('switch(open)', function(obj){
loading =layer.load(1, {shade: [0.1,'#fff']});
var id = this.value;
var open = obj.elem.checked===true?1:0;
$.post('{:url("editState")}',{'id':id,'open':open},function (res) {
layer.close(loading);
if (res.status==1) {
tableIn.reload();
}else{
layer.msg(res.msg,{time:1000,icon:2});
return false;
}
})
});
//搜索
$('#search').on('click', function () {
var key = $('#key').val();
if ($.trim(key) === '') {
layer.msg('{:lang("pleaseEnter")}关键字!', {icon: 0});
return;
}
tableIn.reload({ page: {page: 1}, where: {key: key}});
});
table.on('tool(list)', function(obj) {
var data = obj.data;
if (obj.event === 'del'){
layer.confirm('您确定要删除该广告吗?', function(index){
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post("{:url('del')}",{ad_id:data.ad_id},function(res){
layer.close(loading);
if(res.code===1){
layer.msg(res.msg,{time:1000,icon:1});
tableIn.reload();
}else{
layer.msg('操作失败!',{time:1000,icon:2});
}
});
layer.close(index);
});
}
});
$('body').on('blur','.list_order',function() {
var ad_id = $(this).attr('data-id');
var sort = $(this).val();
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post('{:url("adOrder")}',{ad_id:ad_id,sort:sort},function(res){
layer.close(loading);
if(res.code === 1){
layer.msg(res.msg, {time: 1000, icon: 1});
tableIn.reload();
}else{
layer.msg(res.msg,{time:1000,icon:2});
}
})
});
$('#delAll').click(function(){
layer.confirm('确认要删除选中的广告吗?', {icon: 3}, function(index) {
layer.close(index);
var checkStatus = table.checkStatus('ad'); //test即为参数id设定的值
var ids = [];
$(checkStatus.data).each(function (i, o) {
ids.push(o.ad_id);
});
if(ids==''){
layer.msg('请选择要删除的数据!', {time: 1000, icon: 2});
return false;
}
var loading = layer.load(1, {shade: [0.1, '#fff']});
$.post("{:url('delall')}", {ids: ids}, function (data) {
layer.close(loading);
if (data.code === 1) {
layer.msg(data.msg, {time: 1000, icon: 1});
tableIn.reload();
} else {
layer.msg(data.msg, {time: 1000, icon: 2});
}
});
});
})
})
</script>
\ No newline at end of file
... ...