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.

  1 +
  2 +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
  3 +版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
  4 +All rights reserved。
  5 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
  6 +
  7 +Apache Licence是著名的非盈利开源组织Apache采用的协议。
  8 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
  9 +允许代码修改,再作为开源或商业软件发布。需要满足
  10 +的条件:
  11 +1. 需要给代码的用户一份Apache Licence ;
  12 +2. 如果你修改了代码,需要在被修改的文件中说明;
  13 +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
  14 +带有原来代码中的协议,商标,专利声明和其他原来作者规
  15 +定需要包含的说明;
  16 +4. 如果再发布的产品中包含一个Notice文件,则在Notice文
  17 +件中需要带有本协议内容。你可以在Notice中增加自己的
  18 +许可,但不可以表现为对Apache Licence构成更改。
  19 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
  20 +
  21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24 +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25 +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27 +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30 +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31 +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32 +POSSIBILITY OF SUCH DAMAGE.
1 -0.1  
  1 +CLTPHP5.6
  2 +===============
  3 +
  4 +CLTPHP5.6.5内容管理系统:
  5 +
  6 + + 升级TP框架到TP5.1.19
  7 + + 新增后台栏目权限
  8 + + 管理员登录状态bug
  9 + + 后台日期插件优化
  10 + + 分页后点击搜索未重置初始页码的bug
  11 +
  12 +
  13 +> CLTPHP5.6的运行环境要求PHP5.6以上。
  14 +
  15 +> CLTPHP5.6及后续版本运行目录: public/
  16 +
  17 +
  18 +## 目录结构
  19 +
  20 +初始的目录结构如下:
  21 +
  22 +~~~
  23 +www WEB部署目录(或者子目录)
  24 +├─application 应用目录
  25 +│ ├─common 公共模块目录(可以更改)
  26 +│ ├─module_name 模块目录
  27 +│ │ ├─common.php 模块函数文件
  28 +│ │ ├─controller 控制器目录
  29 +│ │ ├─model 模型目录
  30 +│ │ ├─view 视图目录
  31 +│ │ └─ ... 更多类库目录
  32 +│ │
  33 +│ ├─command.php 命令行定义文件
  34 +│ ├─common.php 公共函数文件
  35 +│ └─tags.php 应用行为扩展定义文件
  36 +│
  37 +├─config 应用配置目录
  38 +│ ├─module_name 模块配置目录
  39 +│ │ ├─database.php 数据库配置
  40 +│ │ ├─cache 缓存配置
  41 +│ │ └─ ...
  42 +│ │
  43 +│ ├─app.php 应用配置
  44 +│ ├─cache.php 缓存配置
  45 +│ ├─cookie.php Cookie配置
  46 +│ ├─database.php 数据库配置
  47 +│ ├─log.php 日志配置
  48 +│ ├─session.php Session配置
  49 +│ ├─template.php 模板引擎配置
  50 +│ └─trace.php Trace配置
  51 +│
  52 +├─route 路由定义目录
  53 +│ ├─route.php 路由定义
  54 +│ └─... 更多
  55 +│
  56 +├─public WEB目录(对外访问目录)
  57 +│ ├─index.php 入口文件
  58 +│ ├─static 静态资源文件目录
  59 +│ ├─router.php 快速测试文件
  60 +│ └─.htaccess 用于apache的重写
  61 +│
  62 +├─thinkphp 框架系统目录
  63 +│ ├─lang 语言文件目录
  64 +│ ├─library 框架类库目录
  65 +│ │ ├─think Think类库包目录
  66 +│ │ └─traits 系统Trait目录
  67 +│ │
  68 +│ ├─tpl 系统模板目录
  69 +│ ├─base.php 基础定义文件
  70 +│ ├─console.php 控制台入口文件
  71 +│ ├─convention.php 框架惯例配置文件
  72 +│ ├─helper.php 助手函数文件
  73 +│ ├─phpunit.xml phpunit配置文件
  74 +│ └─start.php 框架入口文件
  75 +│
  76 +├─extend 扩展类库目录
  77 +├─runtime 应用的运行时目录(可写,可定制)
  78 +├─vendor 第三方类库目录(Composer依赖库)
  79 +├─build.php 自动生成定义文件(参考)
  80 +├─composer.json composer 定义文件
  81 +├─LICENSE.txt 授权说明文件
  82 +├─README.md README 文件
  83 +├─think 命令行入口文件
  84 +~~~
  1 +deny from all
  1 +<?php
  2 +return [
  3 + 'pathinfo_depr' => '/',
  4 +];
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Request;
  5 +class Ad extends Common
  6 +{
  7 + public function initialize(){
  8 + parent::initialize();
  9 + }
  10 + //广告列表
  11 + public function index(){
  12 + if(Request::isAjax()) {
  13 + $key = input('post.key');
  14 + $this->assign('testkey', $key);
  15 + $page =input('page')?input('page'):1;
  16 + $pageSize =input('limit')?input('limit'):config('pageSize');
  17 + $list = Db::table(config('database.prefix') . 'ad')->alias('a')
  18 + ->join(config('database.prefix') . 'ad_type at', 'a.type_id = at.type_id', 'left')
  19 + ->field('a.*,at.name as typename')
  20 + ->where('a.name', 'like', "%" . $key . "%")
  21 + ->order('a.sort')
  22 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  23 + ->toArray();
  24 + foreach ($list['data'] as $k=>$v){
  25 + $list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
  26 + }
  27 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  28 + }
  29 + return $this->fetch();
  30 + }
  31 + public function add(){
  32 + if(Request::isAjax()) {
  33 + //构建数组
  34 + $data = Request::except('file');
  35 + $data['addtime'] = time();
  36 + db('ad')->insert($data);
  37 + $result['code'] = 1;
  38 + $result['msg'] = '广告添加成功!';
  39 + cache('adList', NULL);
  40 + $result['url'] = url('index');
  41 + return $result;
  42 + }else{
  43 + $adtypeList=db('ad_type')->order('sort')->select();
  44 + $this->assign('adtypeList',json_encode($adtypeList,true));
  45 +
  46 + $this->assign('title',lang('add').lang('ad'));
  47 + $this->assign('info','null');
  48 + $this->assign('selected', 'null');
  49 + return $this->fetch('form');
  50 + }
  51 + }
  52 + public function edit(){
  53 + if(Request::isAjax()) {
  54 + $data = Request::except('file');
  55 + db('ad')->update($data);
  56 + $result['code'] = 1;
  57 + $result['msg'] = '广告修改成功!';
  58 + cache('adList', NULL);
  59 + $result['url'] = url('index');
  60 + return $result;
  61 + }else{
  62 + $adtypeList=db('ad_type')->order('sort')->select();
  63 + $ad_id=input('ad_id');
  64 + $adInfo=db('ad')->where(array('ad_id'=>$ad_id))->find();
  65 + $this->assign('adtypeList',json_encode($adtypeList,true));
  66 +
  67 + $selected = db('ad_type')->where('type_id',$adInfo['type_id'])->find();
  68 + $this->assign('selected',json_encode($selected,true));
  69 +
  70 + $this->assign('info',json_encode($adInfo,true));
  71 + $this->assign('title',lang('edit').lang('ad'));
  72 + return $this->fetch('form');
  73 + }
  74 + }
  75 + //设置广告状态
  76 + public function editState(){
  77 + $id=input('post.id');
  78 + $open=input('post.open');
  79 + if(db('ad')->where('ad_id='.$id)->update(['open'=>$open])!==false){
  80 + return ['status'=>1,'msg'=>'设置成功!'];
  81 + }else{
  82 + return ['status'=>0,'msg'=>'设置失败!'];
  83 + }
  84 + }
  85 + public function adOrder(){
  86 + $ad=db('ad');
  87 + $data = input('post.');
  88 + if($ad->update($data)!==false){
  89 + cache('adList', NULL);
  90 + return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
  91 + }else{
  92 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  93 + }
  94 + }
  95 + public function del(){
  96 + db('ad')->where(array('ad_id'=>input('ad_id')))->delete();
  97 + cache('adList', NULL);
  98 + return ['code'=>1,'msg'=>'删除成功!'];
  99 + }
  100 + public function delall(){
  101 + $map[] =array('ad_id','in',input('param.ids/a'));
  102 + db('ad')->where($map)->delete();
  103 + cache('adList', NULL);
  104 + $result['msg'] = '删除成功!';
  105 + $result['code'] = 1;
  106 + $result['url'] = url('index');
  107 + return $result;
  108 + }
  109 +
  110 + /***************************位置*****************************/
  111 + //位置
  112 + public function type(){
  113 + if(Request::isAjax()) {
  114 + $key = input('key');
  115 + $this->assign('testkey', $key);
  116 + $list = db('ad_type')->where('name', 'like', "%" . $key . "%")->order('sort')->select();
  117 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  118 + }
  119 + return $this->fetch();
  120 + }
  121 + public function typeOrder(){
  122 + $ad_type=db('ad_type');
  123 + $data = input('post.');
  124 + if($ad_type->update($data)!==false){
  125 + return $result = ['msg' => '操作成功!','url'=>url('type'), 'code' =>1];
  126 + }else{
  127 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  128 + }
  129 + }
  130 + public function addType(){
  131 + if(Request::isAjax()) {
  132 + db('ad_type')->insert(input('post.'));
  133 + $result['code'] = 1;
  134 + $result['msg'] = '广告位保存成功!';
  135 + $result['url'] = url('type');
  136 + return $result;
  137 + }else{
  138 + $this->assign('title',lang('add').lang('ad').'位');
  139 + $this->assign('info','null');
  140 + return $this->fetch('typeForm');
  141 + }
  142 + }
  143 + public function editType(){
  144 + if(Request::isAjax()) {
  145 + db('ad_type')->update(input('post.'));
  146 + $result['code'] = 1;
  147 + $result['msg'] = '广告位修改成功!';
  148 + $result['url'] = url('type');
  149 + return $result;
  150 + }else{
  151 + $type_id=input('param.type_id');
  152 + $info=db('ad_type')->where('type_id',$type_id)->find();
  153 + $this->assign('title',lang('edit').lang('ad').'位');
  154 + $this->assign('info',json_encode($info,true));
  155 + return $this->fetch('typeForm');
  156 + }
  157 + }
  158 + public function delType(){
  159 + $map['type_id'] = input('param.type_id');
  160 + db('ad_type')->where($map)->delete();//删除广告位
  161 + db('ad')->where($map)->delete();//删除该广告位所有广告
  162 + return ['code'=>1,'msg'=>'删除成功!'];
  163 + }
  164 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +//use think\{Controller,Db,Input};//
  4 +use think\Controller;
  5 +use think\Db;
  6 +use think\Input;
  7 +
  8 +class Ajax extends Common{
  9 + public function getRegion(){
  10 + $Region=db("region");
  11 + $map['pid']=input("pid");
  12 + $map['type']=input("type");
  13 + $list=$Region->where($map)->select();
  14 + echo json_encode($list);
  15 + }
  16 +
  17 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use function MongoDB\BSON\toJSON;
  4 +use think\Db;
  5 +use clt\Leftnav;
  6 +use app\admin\model\Admin;
  7 +use app\admin\model\AuthGroup;
  8 +use app\admin\model\authRule;
  9 +use think\facade\Request;
  10 +use think\Validate;
  11 +class Auth extends Common
  12 +{
  13 + //管理员列表
  14 + public function adminList(){
  15 + if(Request::isAjax()){
  16 + $val=input('val');
  17 + $url['val'] = $val;
  18 + $this->assign('testval',$val);
  19 + $map='';
  20 + if($val){
  21 + $map['username|email|tel']= array('like',"%".$val."%");
  22 + }
  23 + if (session('aid')!=1){
  24 + $map='admin_id='.session('aid');
  25 + }
  26 + $list=Db::table(config('database.prefix').'admin')->alias('a')
  27 + ->join(config('database.prefix').'auth_group ag','a.group_id = ag.group_id','left')
  28 + ->field('a.*,ag.title')
  29 + ->where($map)
  30 + ->select();
  31 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  32 + }
  33 + return view();
  34 + }
  35 +
  36 + public function adminAdd(){
  37 + if(Request::isAjax()){
  38 + $data = input('post.');
  39 + $check_user = Admin::get(['username'=>$data['username']]);
  40 + if ($check_user) {
  41 + return $result = ['code'=>0,'msg'=>'用户已存在,请重新输入用户名!'];
  42 + }
  43 + $data['pwd'] = input('post.pwd', '', 'md5');
  44 + $data['add_time'] = time();
  45 + $data['ip'] = request()->ip();
  46 + //验证
  47 + $msg = $this->validate($data,'app\admin\validate\Admin');
  48 + if($msg!='true'){
  49 + return $result = ['code'=>0,'msg'=>$msg];
  50 + }
  51 + //单独验证密码
  52 + $checkPwd = Validate::make([input('post.pwd')=>'require']);
  53 + if (false === $checkPwd) {
  54 + return $result = ['code'=>0,'msg'=>'密码不能为空!'];
  55 + }
  56 + //添加
  57 + if (Admin::create($data)) {
  58 + return ['code'=>1,'msg'=>'管理员添加成功!','url'=>url('adminList')];
  59 + } else {
  60 + return ['code'=>0,'msg'=>'管理员添加失败!'];
  61 + }
  62 + }else{
  63 + $auth_group = AuthGroup::all();
  64 + $this->assign('authGroup',$auth_group);
  65 + $this->assign('title',lang('add').lang('admin'));
  66 + $this->assign('info','null');
  67 + $this->assign('selected', 'null');
  68 + return view('adminForm');
  69 + }
  70 + }
  71 + //删除管理员
  72 + public function adminDel(){
  73 + $admin_id=input('post.admin_id');
  74 + if (session('aid')==1){
  75 + Admin::where('admin_id','=',$admin_id)->delete();
  76 + return $result = ['code'=>1,'msg'=>'删除成功!'];
  77 + }else{
  78 + return $result = ['code'=>0,'msg'=>'您没有删除管理员的权限!'];
  79 + }
  80 + }
  81 + //修改管理员状态
  82 + public function adminState(){
  83 + $id=input('post.id');
  84 + $is_open=input('post.is_open');
  85 + if (empty($id)){
  86 + $result['status'] = 0;
  87 + $result['info'] = '用户ID不存在!';
  88 + $result['url'] = url('adminList');
  89 + return $result;
  90 + }
  91 + db('admin')->where('admin_id='.$id)->update(['is_open'=>$is_open]);
  92 + $result['status'] = 1;
  93 + $result['info'] = '用户状态修改成功!';
  94 + $result['url'] = url('adminList');
  95 + return $result;
  96 + }
  97 + //更新管理员信息
  98 + public function adminEdit(){
  99 + if(request()->isPost()){
  100 + $data = input('post.');
  101 + $pwd=input('post.pwd');
  102 + $map[] = ['admin_id','<>',$data['admin_id']];
  103 + $where['admin_id'] = $data['admin_id'];
  104 +
  105 + if($data['username']){
  106 + $map[] = ['username','=',$data['username']];
  107 + $check_user = Admin::where($map)->find();
  108 + if ($check_user) {
  109 + return $result = ['code'=>0,'msg'=>'用户已存在,请重新输入用户名!'];
  110 + }
  111 + }
  112 + if ($pwd){
  113 + $data['pwd']=input('post.pwd','','md5');
  114 + }else{
  115 + unset($data['pwd']);
  116 + }
  117 + $msg = $this->validate($data,'app\admin\validate\Admin');
  118 + if($msg!='true'){
  119 + return $result = ['code'=>0,'msg'=>$msg];
  120 + }
  121 + Admin::update($data,$where);
  122 + if( $data['admin_id'] == session('aid')){
  123 + session('username',$data['username']);
  124 + $avatar = $data['avatar']==''?'/static/admin/images/0.jpg':$data['avatar'];
  125 + session('avatar',$avatar);
  126 + }
  127 + return $result = ['code'=>1,'msg'=>'管理员修改成功!','url'=>url('adminList')];
  128 + }else{
  129 + $auth_group = AuthGroup::all();
  130 + $admin = new Admin();
  131 + $info = $admin->getInfo(input('admin_id'));
  132 + $this->assign('info', json_encode($info,true));
  133 + $this->assign('authGroup',$auth_group);
  134 + $this->assign('title',lang('edit').lang('admin'));
  135 + return view('adminForm');
  136 + }
  137 + }
  138 + /*-----------------------用户组管理----------------------*/
  139 + //用户组管理
  140 + public function adminGroup(){
  141 + if(request()->isPost()){
  142 + $list = AuthGroup::all();
  143 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  144 + }
  145 + return view();
  146 + }
  147 + //删除管理员分组
  148 + public function groupDel(){
  149 + AuthGroup::where('group_id','=',input('id'))->delete();
  150 + return $result = ['code'=>1,'msg'=>'删除成功!'];
  151 + }
  152 + //添加分组
  153 + public function groupAdd(){
  154 + if(request()->isPost()){
  155 + $data=input('post.');
  156 + $data['addtime']=time();
  157 + AuthGroup::create($data);
  158 + $result['msg'] = '用户组添加成功!';
  159 + $result['url'] = url('adminGroup');
  160 + $result['code'] = 1;
  161 + return $result;
  162 + }else{
  163 + $this->assign('title','添加用户组');
  164 + $this->assign('info','null');
  165 + return $this->fetch('groupForm');
  166 + }
  167 + }
  168 + //修改分组
  169 + public function groupEdit(){
  170 + if(request()->isPost()) {
  171 + $data=input('post.');
  172 + $where['group_id'] = $data['group_id'];
  173 + AuthGroup::update($data,$where);
  174 + $result = ['code'=>1,'msg'=>'用户组修改成功!','url'=>url('adminGroup')];
  175 + return $result;
  176 + }else{
  177 + $id = input('id');
  178 + $info = AuthGroup::get(['group_id'=>$id]);
  179 + $this->assign('info', json_encode($info,true));
  180 + $this->assign('title','编辑用户组');
  181 + return $this->fetch('groupForm');
  182 + }
  183 + }
  184 + //分组配置规则
  185 + public function groupAccess(){
  186 + $nav = new Leftnav();
  187 + $admin_rule=db('auth_rule')->field('id,pid,title')->order('sort asc')->select();
  188 + $rules = db('auth_group')->where('group_id',input('id'))->value('rules');
  189 + $arr = $nav->auth($admin_rule,$pid=0,$rules);
  190 + $arr[] = array(
  191 + "id"=>0,
  192 + "pid"=>0,
  193 + "title"=>"全部",
  194 + "open"=>true
  195 + );
  196 + $this->assign('data',json_encode($arr,true));
  197 + return $this->fetch();
  198 + }
  199 + public function groupSetaccess(){
  200 + $rules = input('post.rules');
  201 + if(empty($rules)){
  202 + return array('msg'=>'请选择权限!','code'=>0);
  203 + }
  204 + $data = input('post.');
  205 + $where['group_id'] = $data['group_id'];
  206 + if(AuthGroup::update($data,$where)){
  207 + return array('msg'=>'权限配置成功!','url'=>url('adminGroup'),'code'=>1);
  208 + }else{
  209 + return array('msg'=>'保存错误','code'=>0);
  210 + }
  211 + }
  212 +
  213 + /********************************权限管理*******************************/
  214 + public function adminRule(){
  215 + if(request()->isPost()){
  216 + $nav = new Leftnav();
  217 + $arr = cache('authRuleList');
  218 + if(!$arr){
  219 + $authRule = authRule::all(function($query){
  220 + $query->order('sort', 'asc');
  221 + });
  222 + $arr = $nav->menu($authRule);
  223 + cache('authRuleList', $arr, 3600);
  224 + }
  225 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$arr,'rel'=>1];
  226 + }
  227 + return view();
  228 + }
  229 + public function ruleAdd(){
  230 + if(request()->isPost()){
  231 + $data = input('post.');
  232 + $data['addtime'] = time();
  233 + authRule::create($data);
  234 + cache('authRule', NULL);
  235 + cache('authRuleList', NULL);
  236 + return $result = ['code'=>1,'msg'=>'权限添加成功!','url'=>url('adminRule')];
  237 + }else{
  238 + $nav = new Leftnav();
  239 + $arr = cache('authRuleList');
  240 + if(!$arr){
  241 + $authRule = authRule::all(function($query){
  242 + $query->order('sort', 'asc');
  243 + });
  244 + $arr = $nav->menu($authRule);
  245 + cache('authRuleList', $arr, 3600);
  246 + }
  247 + $this->assign('admin_rule',$arr);//权限列表
  248 + return $this->fetch();
  249 + }
  250 + }
  251 + public function ruleOrder(){
  252 + $auth_rule=db('auth_rule');
  253 + $data = input('post.');
  254 + if($auth_rule->update($data)!==false){
  255 + cache('authRuleList', NULL);
  256 + cache('authRule', NULL);
  257 + return $result = ['code'=>1,'msg'=>'排序更新成功!','url'=>url('adminRule')];
  258 + }else{
  259 + return $result = ['code'=>0,'msg'=>'排序更新失败!'];
  260 + }
  261 + }
  262 + //设置权限菜单显示或者隐藏
  263 + public function ruleState(){
  264 + $id=input('post.id');
  265 + $menustatus=input('post.menustatus');
  266 + if(db('auth_rule')->where('id='.$id)->update(['menustatus'=>$menustatus])!==false){
  267 + cache('authRule', NULL);
  268 + cache('authRuleList', NULL);
  269 + return ['status'=>1,'msg'=>'设置成功!'];
  270 + }else{
  271 + return ['status'=>0,'msg'=>'设置失败!'];
  272 + }
  273 + }
  274 + //设置权限是否验证
  275 + public function ruleTz(){
  276 + $id=input('post.id');
  277 + $authopen=input('post.authopen');
  278 + if(db('auth_rule')->where('id='.$id)->update(['authopen'=>$authopen])!==false){
  279 + cache('authRule', NULL);
  280 + cache('authRuleList', NULL);
  281 + return ['status'=>1,'msg'=>'设置成功!'];
  282 + }else{
  283 + return ['status'=>0,'msg'=>'设置失败!'];
  284 + }
  285 + }
  286 + public function ruleDel(){
  287 + authRule::destroy(['id'=>input('param.id')]);
  288 + cache('authRule', NULL);
  289 + cache('authRuleList', NULL);
  290 + return $result = ['code'=>1,'msg'=>'删除成功!'];
  291 + }
  292 +
  293 + public function ruleEdit(){
  294 + if(request()->isPost()) {
  295 + $datas = input('post.');
  296 + if(authRule::update($datas)) {
  297 + cache('authRule', NULL);
  298 + cache('authRuleList', NULL);
  299 + return json(['code' => 1, 'msg' => '保存成功!', 'url' => url('adminRule')]);
  300 + } else {
  301 + return json(['code' => 0, 'msg' =>'保存失败!']);
  302 + }
  303 + }else{
  304 + $admin_rule = authRule::get(function($query){
  305 + $query->where(['id'=>input('id')])->field('id,href,title,icon,sort,menustatus');
  306 + });
  307 + $this->assign('rule',$admin_rule);
  308 + return $this->fetch();
  309 + }
  310 + }
  311 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use clt\Tree;
  5 +use think\facade\Request;
  6 +use think\facade\Env;
  7 +class Category extends Common
  8 +{
  9 + protected $dao, $categorys , $module,$groupId;
  10 + function initialize()
  11 + {
  12 + parent::initialize();
  13 + foreach ((array)$this->module as $rw){
  14 + if($rw['type']==1 && $rw['status']==1){
  15 + $data['module'][$rw['id']] = $rw;
  16 + }
  17 + }
  18 + $this->module=$data['module'];
  19 + $this->assign($data);
  20 + unset($data);
  21 + $this->dao = db('category');
  22 + $this->groupId = Db::name('admin')->where('admin_id',session('aid'))->value('group_id');
  23 + }
  24 + public function index()
  25 + {
  26 + if ($this->categorys) {
  27 + foreach ($this->categorys as $r) {
  28 + if(session('aid')==1){
  29 + if ($r['module'] == 'page') {
  30 + $r['str_manage'] = '<a class="orange" href="' . url('page/edit', array('id' => $r['id'])) . '" title="修改内容"><i class="icon icon-file-text2"></i></a> | ';
  31 + } else {
  32 + $r['str_manage'] = '';
  33 + }
  34 + $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> ';
  35 +
  36 + $r['modulename'] = $this->module[$r['moduleid']]['title'];
  37 +
  38 + $r['dis'] = $r['ismenu'] == 1 ? '<font color="green">显示</font>' : '<font color="red">不显示</font>';
  39 + $array[] = $r;
  40 + }else{
  41 + $groupArr = explode(',',$r['readgroup']);
  42 + if(in_array($this->groupId,$groupArr)){
  43 + if ($r['module'] == 'page') {
  44 + $r['str_manage'] = '<a class="orange" href="' . url('page/edit', array('id' => $r['id'])) . '" title="修改内容"><i class="icon icon-file-text2"></i></a> | ';
  45 + } else {
  46 + $r['str_manage'] = '';
  47 + }
  48 + $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> ';
  49 +
  50 + $r['modulename'] = $this->module[$r['moduleid']]['title'];
  51 +
  52 + $r['dis'] = $r['ismenu'] == 1 ? '<font color="green">显示</font>' : '<font color="red">不显示</font>';
  53 + $array[] = $r;
  54 + }
  55 + }
  56 +
  57 + }
  58 +
  59 + $str = "<tr><td class='visible-lg visible-md'>\$id</td>";
  60 + $str .= "<td class='text-left'>\$spacer<a href='/admin/\$module/\$action/\$files/\$id.html' class='green' title='查看内容'>\$catname </a>&nbsp;</td>";
  61 +
  62 + $str .= "<td class='visible-lg visible-md'>\$modulename</td><td class='visible-lg visible-md'>\$dis</td>";
  63 + $str .= "<td><input type='text' size='10' data-id='\$id' value='\$sort' class='layui-input list_order'></td><td>\$str_manage</td></tr>";
  64 + $tree = new Tree ($array);
  65 + $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
  66 + $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
  67 + $categorys = $tree->get_tree(0, $str);
  68 +
  69 + $this->assign('categorys', $categorys);
  70 + }
  71 + $this->assign('title','栏目列表');
  72 + return $this->fetch();
  73 + }
  74 +
  75 + public function add(){
  76 + $parentid = input('param.parentid');
  77 + //模型列表
  78 + $module = db('module')->where('status',1)->field('id,title,name')->select();
  79 + $this->assign('modulelist',$module);
  80 +
  81 + //父级模型ID
  82 + //父级模型ID
  83 + if($parentid){
  84 + $vo['moduleid'] =$this->categorys[$parentid]['moduleid'];
  85 + $this->assign('module', $vo);
  86 + }
  87 + //栏目选择列表
  88 + foreach($this->categorys as $r) {
  89 + $array[] = $r;
  90 + }
  91 + $str = "<option value='\$id' \$selected>\$spacer \$catname</option>";
  92 + $tree = new Tree ($array);
  93 + $categorys = $tree->get_tree(0, $str,$parentid);
  94 + $this->assign('categorys', $categorys);
  95 + //模版
  96 + $templates= template_file();
  97 + $this->assign ( 'templates',$templates );
  98 + //管理员权限组
  99 + $usergroup=db('auth_group')->select();
  100 + $this->assign('rlist',$usergroup);
  101 + $this->assign('title','添加栏目');
  102 + return $this->fetch();
  103 + }
  104 + public function insert(){
  105 + $data = $data = Request::except('file');
  106 + if(!empty($data['readgroup'])){
  107 + $data['readgroup'] = implode(',',$data['readgroup']);
  108 + }else{
  109 + $data['readgroup'] = $this->groupId;
  110 + }
  111 + $data['module'] = $this->module[$data['moduleid']]['name'];
  112 + $data['child'] = isset($data['child'])?1:0;
  113 + $id = db('category')->insertGetId($data);
  114 + if($id) {
  115 + if($data['module']=='page'){
  116 + $data2['id']=$id;
  117 + if($data['title']==''){
  118 + $data2['title'] = $data['catname'];
  119 + $data2['content'] = '';
  120 + }
  121 + $page=db('page');
  122 + $page->insert($data2);
  123 + }
  124 + $this->repair();
  125 + $this->repair();
  126 + savecache('Category');
  127 + $result['msg'] = '栏目添加成功!';
  128 + cache('cate', NULL);
  129 + $result['url'] = url('index');
  130 + $result['code'] = 1;
  131 + return $result;
  132 + }else{
  133 + $result['msg'] = '栏目添加失败!';
  134 + $result['code'] = 0;
  135 + return $result;
  136 + }
  137 + }
  138 +
  139 + public function edit(){
  140 + $id = input('id');
  141 + $this->assign('module',$this->categorys[$id]['moduleid']);
  142 + $module = db('module')->field('id,title,name')->select();
  143 + $this->assign('modulelist',$module);
  144 +
  145 + $record = $this->categorys[$id];
  146 + $record['imgUrl'] = imgUrl($record['image']);
  147 + $record['readgroup'] = explode(',',$record['readgroup']);
  148 + $parentid = intval($record['parentid']);
  149 + $result = $this->categorys;
  150 + foreach($result as $r) {
  151 + if($r['type']==1) continue;
  152 + $r['selected'] = $r['id'] == $parentid ? 'selected' : '';
  153 + $array[] = $r;
  154 + }
  155 + $str = "<option value='\$id' \$selected>\$spacer \$catname</option>";
  156 + $tree = new Tree ($array);
  157 + $categorys = $tree->get_tree(0, $str,$parentid);
  158 + $this->assign('categorys', $categorys);
  159 + $this->assign('record', $record);
  160 + $usergroup=db('auth_group')->select();
  161 + $this->assign('rlist',$usergroup);
  162 + $this->assign('title','编辑栏目');
  163 + //模版
  164 + $templates= template_file();
  165 + $this->assign ( 'templates',$templates );
  166 + return $this->fetch();
  167 + }
  168 + public function catUpdate(){
  169 + $data = $data = Request::except('file');
  170 + $data['module'] = db('module')->where(array('id'=>$data['moduleid']))->value('name');
  171 + if(!empty($data['readgroup'])){
  172 + $data['readgroup'] = implode(',',$_POST['readgroup']);
  173 + }else{
  174 + $data['readgroup']='';
  175 + }
  176 + $data['arrparentid'] = $this->get_arrparentid($data['id']);
  177 + $data['child'] = isset($data['child']) ? '1' : '0';
  178 + if (false !==db('category')->update($data)) {
  179 + if($data['child']==1){
  180 + $arrchildid = $this->get_arrchildid($data['id']);
  181 + $data2['ismenu'] = $data['ismenu'];
  182 + $data2['pagesize'] = $data['pagesize'];
  183 + $data2['readgroup'] = $data['readgroup'];
  184 + db('category')->where( ' id in ('.$arrchildid.')')->update($data2);
  185 + }
  186 + $this->repair();
  187 + $this->repair();
  188 + savecache('Category');
  189 + $result['msg'] = '栏目修改成功!';
  190 + cache('cate', NULL);
  191 + $result['url'] = url('index');
  192 + $result['code'] = 1;
  193 + return $result;
  194 + } else {
  195 + $result['msg'] = '栏目修改失败!';
  196 + $result['code'] = 0;
  197 + return $result;
  198 + }
  199 + }
  200 +
  201 +
  202 + public function repair() {
  203 + @set_time_limit(500);
  204 + $this->categorys = $categorys = array();
  205 + $categorys = db('category')->where("parentid=0")->order('sort ASC,id ASC')->select();
  206 + $this->set_categorys($categorys);
  207 + if(is_array($this->categorys)) {
  208 + foreach($this->categorys as $id => $cat) {
  209 + if($id == 0 || $cat['type']==1) continue;
  210 + $this->categorys[$id]['arrparentid'] = $arrparentid = $this->get_arrparentid($id);
  211 + $this->categorys[$id]['arrchildid'] = $arrchildid = $this->get_arrchildid($id);
  212 + $this->categorys[$id]['parentdir'] = $parentdir = $this->get_parentdir($id);
  213 + db('category')->update(array('parentdir'=>$parentdir,'arrparentid'=>$arrparentid,'arrchildid'=>$arrchildid,'id'=>$id));
  214 + }
  215 + }
  216 +
  217 + }
  218 + public function set_categorys($categorys = array()) {
  219 + if (is_array($categorys) && !empty($categorys)) {
  220 + foreach ($categorys as $id => $c) {
  221 + $this->categorys[$c['id']] = $c;
  222 + $r = db('category')->where(array("parentid"=>$c['id']))->Order('sort ASC,id ASC')->select();
  223 + $this->set_categorys($r);
  224 + }
  225 + }
  226 + return true;
  227 + }
  228 + public function get_arrparentid($id, $arrparentid = '') {
  229 + if(!is_array($this->categorys) || !isset($this->categorys[$id])) return false;
  230 + $parentid = $this->categorys[$id]['parentid'];
  231 + $arrparentid = $arrparentid ? $parentid.','.$arrparentid : $parentid;
  232 + if($parentid) {
  233 + $arrparentid = $this->get_arrparentid($parentid, $arrparentid);
  234 + } else {
  235 + $this->categorys[$id]['arrparentid'] = $arrparentid;
  236 + }
  237 + return $arrparentid;
  238 + }
  239 + public function get_arrchildid($id) {
  240 + $arrchildid = $id;
  241 + if(is_array($this->categorys)) {
  242 + foreach($this->categorys as $catid => $cat) {
  243 + if($cat['parentid'] && $id != $catid) {
  244 + $arrparentids = explode(',', $cat['arrparentid']);
  245 + if(in_array($id, $arrparentids)){
  246 + $arrchildid .= ','.$catid;
  247 + }
  248 + }
  249 + }
  250 + }
  251 + return $arrchildid;
  252 + }
  253 + public function get_parentdir($id) {
  254 + if($this->categorys[$id]['parentid']==0){
  255 + return '';
  256 + }
  257 + $arrparentid = $this->categorys[$id]['arrparentid'];
  258 + unset($r);
  259 + if ($arrparentid) {
  260 + $arrparentid = explode(',', $arrparentid);
  261 + $arrcatdir = array();
  262 + foreach($arrparentid as $pid) {
  263 + if($pid==0) continue;
  264 + $arrcatdir[] = $this->categorys[$pid]['catdir'];
  265 + }
  266 + return implode('/', $arrcatdir).'/';
  267 + }
  268 + }
  269 +
  270 +
  271 + public function del() {
  272 + $catid = input('param.id');
  273 + $modules = $this->categorys[$catid]['module'];
  274 +
  275 + $modulesId = $this->categorys[$catid]['moduleid'];
  276 + $scount = $this->dao->where(array('parentid'=>$catid))->count();
  277 +
  278 + if($scount){
  279 + $result['info'] = '请先删除其子栏目!';
  280 + $result['status'] = 0;
  281 + return $result;
  282 + }
  283 +
  284 + $module = db($modules);
  285 + $arrchildid = $this->categorys[$catid]['arrchildid'];
  286 +
  287 + if($modules != 'page'){
  288 + $fields = cache($modulesId.'_Field');
  289 + $fieldse=array();
  290 + foreach ($fields as $k=>$v){
  291 + $fieldse[] = $k;
  292 + }
  293 + if(in_array('catid',$fieldse)){
  294 + $count = $module->where('catid','in',$arrchildid)->count();
  295 + }else{
  296 + $count = $module->count();
  297 + }
  298 + if($count){
  299 + $result['info'] = '请先删除该栏目下所有数据!';
  300 + $result['status'] = 0;
  301 + return $result;
  302 + }
  303 + }
  304 + $pid = $this->categorys[$catid]['parentid'];
  305 +
  306 + $scat = $this->dao->where(array('parentid'=>$pid))->count();
  307 + if($scat==1){
  308 + db('category')->where(array('id'=>$pid))->update(array('child'=>0));
  309 + }
  310 + db('category')->where('id','in',$arrchildid)->delete();
  311 + $arr=explode(',',$arrchildid);
  312 + foreach((array)$arr as $r){
  313 + if($this->categorys[$r]['module']=='page'){
  314 + $module=db('page');
  315 + $module->delete($r);
  316 + }
  317 + }
  318 + $this->repair();
  319 + savecache('Category');
  320 + $result['info'] = '栏目删除成功!';
  321 + cache('cate', NULL);
  322 + $result['url'] = url('index');
  323 + $result['status'] = 1;
  324 + return $result;
  325 + }
  326 +
  327 + public function cOrder(){
  328 + $data = input('post.');
  329 + $this->dao->update($data);
  330 + $result = ['msg' => '排序成功!', 'code' => 1,'url'=>url('index')];
  331 + savecache('Category');
  332 + cache('cate', NULL);
  333 + return $result;
  334 + }
  335 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\Controller;
  5 +class Common extends Controller
  6 +{
  7 + protected $mod,$role,$system,$nav,$menudata,$cache_model,$categorys,$module,$moduleid,$adminRules,$HrefId;
  8 + public function initialize()
  9 + {
  10 + //判断管理员是否登录
  11 + if (!session('aid')) {
  12 + $this->redirect('admin/login/index');
  13 + }
  14 + define('MODULE_NAME',strtolower(request()->controller()));
  15 + define('ACTION_NAME',strtolower(request()->action()));
  16 + //权限管理
  17 + //当前操作权限ID
  18 + if(session('aid')!=1){
  19 + $this->HrefId = db('auth_rule')->where('href',MODULE_NAME.'/'.ACTION_NAME)->value('id');
  20 + //当前管理员权限
  21 + $map['a.admin_id'] = session('aid');
  22 + $rules=Db::table(config('database.prefix').'admin')->alias('a')
  23 + ->join(config('database.prefix').'auth_group ag','a.group_id = ag.group_id','left')
  24 + ->where($map)
  25 + ->value('ag.rules');
  26 + $this->adminRules = explode(',',$rules);
  27 + if($this->HrefId){
  28 + if(!in_array($this->HrefId,$this->adminRules)){
  29 + $this->error('您无此操作权限');
  30 + }
  31 + }
  32 + }
  33 + $this->cache_model=array('Module','AuthRule','Category','Posid','Field','System','cm');
  34 + foreach($this->cache_model as $r){
  35 + if(!cache($r)){
  36 + savecache($r);
  37 + }
  38 + }
  39 + $this->system = cache('System');
  40 + $this->categorys = cache('Category');
  41 + $this->module = cache('Module');
  42 + $this->mod = cache('Mod');
  43 + $this->rule = cache('AuthRule');
  44 + $this->cm = cache('cm');
  45 + }
  46 + //空操作
  47 + public function _empty(){
  48 + return $this->error('空操作,返回上次访问页面中...');
  49 + }
  50 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use \tp5er\Backup;
  5 +class Database extends Common
  6 +{
  7 + protected $db = '', $datadir;
  8 + function initialize(){
  9 + parent::initialize();
  10 + $this->config=array(
  11 + 'path' => './Data/',//数据库备份路径
  12 + 'part' => 20971520,//数据库备份卷大小
  13 + 'compress' => 0,//数据库备份文件是否启用压缩 0不压缩 1 压缩
  14 + 'level' => 9 //数据库备份文件压缩级别 1普通 4 一般 9最高
  15 + );
  16 + $this->db = new Backup($this->config);
  17 + }
  18 + public function database(){
  19 + if(request()->isPost()){
  20 + $list = $this->db->dataList();
  21 + $total = 0;
  22 + foreach ($list as $k => $v) {
  23 + $list[$k]['size'] = format_bytes($v['data_length']);
  24 + $total += $v['data_length'];
  25 + }
  26 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'total'=>format_bytes($total),'tableNum'=>count($list),'rel'=>1];
  27 + }
  28 + return view();
  29 + }
  30 + //优化
  31 + public function optimize() {
  32 + $tables = input('tables/a');
  33 + if (empty($tables)) {
  34 + return ['code'=>0,'msg'=>'请选择要优化的表!'];
  35 + }
  36 + if($this->db->optimize($tables)){
  37 + return ['code'=>1,'msg'=>'数据表优化成功!'];
  38 + }else{
  39 + return ['code'=>0,'msg'=>'数据表优化出错请重试!'];
  40 + }
  41 + }
  42 + //修复
  43 + public function repair() {
  44 + $tables = input('tables/a');
  45 + if (empty($tables)) {
  46 + return ['code'=>0,'msg'=>'请选择要修复的表!'];
  47 + }
  48 + if($this->db->repair($tables)){
  49 + return ['code'=>1,'msg'=>'数据表修复成功!'];
  50 + }else{
  51 + return ['code'=>0,'msg'=>'数据表修复出错请重试!'];
  52 + }
  53 + }
  54 + //备份
  55 + public function backup(){
  56 + $tables = input('post.tables/a');
  57 + if (!empty($tables)) {
  58 + foreach ($tables as $table) {
  59 + $this->db->setFile()->backup($table, 0);
  60 + }
  61 + return ['code'=>1,'msg'=>'备份成功!'];
  62 + } else {
  63 + return ['code'=>0,'msg'=>'请选择要备份的表!'];
  64 + }
  65 + }
  66 + //备份列表
  67 + public function restore(){
  68 + if(request()->isPost()){
  69 + $list = $this->db->fileList();
  70 + return ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  71 + }
  72 + return view();
  73 + }
  74 + //执行还原数据库操作
  75 + public function import($time) {
  76 + $list = $this->db->getFile('timeverif',$time);
  77 + $this->db->setFile($list)->import(1);
  78 + return ['code'=>1,'msg'=>'还原成功!'];
  79 + }
  80 +
  81 + //下载
  82 + public function downFile($time) {
  83 + $this->db->downloadFile($time);
  84 + }
  85 + //删除sql文件
  86 + public function delSqlFiles() {
  87 + $time = input('post.time');
  88 + if($this->db->delFile($time)){
  89 + return ['code'=>1,'msg'=>"备份文件删除成功!"];
  90 + }else{
  91 + return ['code'=>0,'msg'=>"备份文件删除失败,请检查权限!"];
  92 + }
  93 + }
  94 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Request;
  5 +class Debris extends Common
  6 +{
  7 + public function index(){
  8 + if(Request::isAjax()) {
  9 + $key = input('post.key');
  10 + $this->assign('testkey', $key);
  11 + $page =input('page')?input('page'):1;
  12 + $pageSize =input('limit')?input('limit'):config('pageSize');
  13 + $list = Db::table(config('database.prefix') . 'debris')->alias('d')
  14 + ->join(config('database.prefix') . 'debris_type dt', 'd.type_id = dt.id', 'left')
  15 + ->field('d.*,dt.title as typename')
  16 + ->where('d.title', 'like', "%" . $key . "%")
  17 + ->order('d.sort')
  18 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  19 + ->toArray();
  20 + foreach ($list['data'] as $k=>$v){
  21 + $list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
  22 + }
  23 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  24 + }
  25 + return $this->fetch();
  26 + }
  27 + public function add(){
  28 + if(Request::isAjax()) {
  29 + //构建数组
  30 + $data = Request::except('file');
  31 + $data['addtime'] = time();
  32 + $typeId = explode(':',$data['type_id']);
  33 + $data['type_id'] =$typeId[1];
  34 + db('debris')->insert($data);
  35 + $result['code'] = 1;
  36 + $result['msg'] = '碎片添加成功!';
  37 + $result['url'] = url('index');
  38 + return $result;
  39 + }else{
  40 + $debrisTypeList=db('debris_type')->order('sort')->select();//获取所有广告位
  41 + $this->assign('debrisTypeList',json_encode($debrisTypeList,true));
  42 +
  43 + $this->assign('title',lang('add').lang('debris'));
  44 + $this->assign('info','null');
  45 + return $this->fetch('form');
  46 + }
  47 + }
  48 + public function edit(){
  49 + if(Request::isAjax()) {
  50 + $data = Request::except('file');
  51 + $typeId = explode(':',$data['type_id']);
  52 + $data['type_id'] =$typeId[1];
  53 + db('debris')->where('id',$data['id'])->update($data);
  54 + $result['code'] = 1;
  55 + $result['msg'] = '碎片修改成功!';
  56 + $result['url'] = url('index');
  57 + return $result;
  58 + }else{
  59 + $id=input('id');
  60 + $info=db('debris')->where(array('id'=>$id))->find();
  61 + $this->assign('info',json_encode($info,true));
  62 +
  63 + $debrisTypeList=db('debris_type')->order('sort')->select();//获取所有广告位
  64 + $this->assign('debrisTypeList',json_encode($debrisTypeList,true));
  65 +
  66 + $this->assign('title',lang('edit').lang('debris'));
  67 + return $this->fetch('form');
  68 + }
  69 + }
  70 + public function del(){
  71 + db('debris')->where('id',input('post.id'))->delete();
  72 + return ['code'=>1,'msg'=>'删除成功!'];
  73 + }
  74 + public function debrisOrder(){
  75 + $data = input('post.');
  76 + if(db('debris')->update($data)!==false){
  77 + return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
  78 + }else{
  79 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  80 + }
  81 + }
  82 +
  83 + public function delall(){
  84 + $map['id'] =array('in',input('param.ids/a'));
  85 + db('debris')->where($map)->delete();
  86 +
  87 + $result['msg'] = '删除成功!';
  88 + $result['code'] = 1;
  89 + $result['url'] = url('index');
  90 + return $result;
  91 + }
  92 +
  93 + /*************************类别*************************/
  94 + public function type(){
  95 + if(request()->isPost()) {
  96 + $key = input('key');
  97 + $this->assign('testkey', $key);
  98 + $list = db('debris_type')->where('title', 'like', "%" . $key . "%")->order('sort')->select();
  99 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  100 + }
  101 + return $this->fetch();
  102 + }
  103 + public function addType(){
  104 + if(request()->isPost()) {
  105 + db('debris_type')->insert(input('post.'));
  106 + $result['code'] = 1;
  107 + $result['msg'] = '碎片分类保存成功!';
  108 + $result['url'] = url('type');
  109 + return $result;
  110 + }else{
  111 + $this->assign('title',lang('add').'碎片分类');
  112 + $this->assign('info','null');
  113 + return $this->fetch('typeForm');
  114 + }
  115 + }
  116 + public function editType(){
  117 + if(request()->isPost()) {
  118 + db('debris_type')->update(input('post.'));
  119 + $result['code'] = 1;
  120 + $result['msg'] = '碎片分类修改成功!';
  121 + $result['url'] = url('type');
  122 + return $result;
  123 + }else{
  124 + $id=input('param.id');
  125 + $info=db('debris_type')->where('id',$id)->find();
  126 + $this->assign('title',lang('edit').'碎片分类');
  127 + $this->assign('info',json_encode($info,true));
  128 + return $this->fetch('typeForm');
  129 + }
  130 + }
  131 + public function typeOrder(){
  132 + $debris_type=db('debris_type');
  133 + $data = input('post.');
  134 + if($debris_type->update($data)!==false){
  135 + return $result = ['msg' => '操作成功!','url'=>url('type'), 'code' =>1];
  136 + }else{
  137 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  138 + }
  139 + }
  140 + public function delType(){
  141 + $id = input('post.id');
  142 + db('debris_type')->where(['id'=>$id])->delete();//删除广告位
  143 + db('debris')->where(['type_id'=>$id])->delete();//删除该广告位所有广告
  144 + return ['code'=>1,'msg'=>'删除成功!'];
  145 + }
  146 +
  147 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\facade\Request;
  4 +class Donation extends Common
  5 +{
  6 + //捐赠列表
  7 + public function index(){
  8 + if(Request::isAjax()) {
  9 + $key=input('post.key');
  10 + $page =input('page')?input('page'):1;
  11 + $pageSize =input('limit')?input('limit'):config('pageSize');
  12 + $list = db('donation')
  13 + ->where('name', 'like', "%" . $key . "%")
  14 + ->order('addtime desc')
  15 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  16 + ->toArray();
  17 + foreach ($list['data'] as $k=>$v){
  18 + $list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
  19 + $list['data'][$k]['mnum'] = $v['money']*100;
  20 + }
  21 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  22 + }
  23 + return $this->fetch();
  24 + }
  25 + public function add(){
  26 + if(Request::isAjax()) {
  27 + //构建数组
  28 + $data = input('post.');
  29 + $data['addtime'] = time();
  30 + db('donation')->insert($data);
  31 + $result['code'] = 1;
  32 + $result['msg'] = '捐赠名单添加成功!';
  33 + $result['url'] = url('index');
  34 + return $result;
  35 + }else{
  36 + $this->assign('title',lang('add').'捐赠名单');
  37 + $this->assign('info','null');
  38 + return $this->fetch('form');
  39 + }
  40 + }
  41 + public function edit(){
  42 + if(Request::isAjax()) {
  43 + $data = input('post.');
  44 + db('donation')->update($data);
  45 + $result['code'] = 1;
  46 + $result['msg'] = '捐赠名单修改成功!';
  47 + $result['url'] = url('index');
  48 + return $result;
  49 + }else{
  50 + $id=input('id');
  51 + $info=db('donation')->where(array('id'=>$id))->find();
  52 + $this->assign('info',json_encode($info,true));
  53 + $this->assign('title',lang('edit').'捐赠名单');
  54 + return $this->fetch('form');
  55 + }
  56 + }
  57 + public function del(){
  58 + db('donation')->where(array('id'=>input('id')))->delete();
  59 + return ['code'=>1,'msg'=>'删除成功!'];
  60 + }
  61 + public function delall(){
  62 + $map[] =array('id','in',input('param.ids/a'));
  63 + db('donation')->where($map)->delete();
  64 + $result['msg'] = '删除成功!';
  65 + $result['code'] = 1;
  66 + $result['url'] = url('index');
  67 + return $result;
  68 + }
  69 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Request;
  5 +use clt\Form;
  6 +class EmptyController extends Common{
  7 + protected $dao,$fields;
  8 + public function initialize()
  9 + {
  10 + parent::initialize();
  11 + $this->moduleid = $this->mod[MODULE_NAME];
  12 + $this->dao = db(MODULE_NAME);
  13 + $fields = cache($this->moduleid.'_Field');
  14 + foreach($fields as $key => $res){
  15 + $res['setup']=string2array($res['setup']);
  16 + $this->fields[$key]=$res;
  17 + }
  18 + unset($fields);
  19 + unset($res);
  20 + $this->assign ('fields',$this->fields);
  21 + }
  22 + public function index(){
  23 + if(Request::isAjax()){
  24 + $request = Request::instance();
  25 + $modelname = strtolower($request->controller());
  26 + $model = db($modelname);
  27 + $keyword=input('post.key');
  28 + $page =input('page')?input('page'):1;
  29 + $pageSize =input('limit')?input('limit'):config('pageSize');
  30 + $order = "sort asc,id desc";
  31 + if (input('post.catid')) {
  32 + $catids = db('category')->where(array('parentid'=>input('post.catid')))->column('id');
  33 + if($catids){
  34 + $catid = input('post.catid').','.implode(',',$catids);
  35 + }else{
  36 + $catid = input('post.catid');
  37 + }
  38 + }
  39 + $cinfo= db('category')->where(array('id'=>input('post.catid')))->field('catdir,is_show')->find();
  40 + if(!empty($keyword) ){
  41 + $map[]=array('title','like','%'.$keyword.'%');
  42 + }
  43 + $prefix=config('database.prefix');
  44 + $Fields=Db::getConnection()->getFields($prefix.$modelname);
  45 + foreach ($Fields as $k=>$v){
  46 + $field[$k] = $k;
  47 + }
  48 + if(in_array('catid',$field)){
  49 + $map[]=array('catid','in',$catid);
  50 + }
  51 + $list = $model
  52 + ->where($map)
  53 + ->order($order)
  54 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  55 + ->toArray();
  56 + $rsult['code'] = 0;
  57 + $rsult['msg'] = "获取成功";
  58 + $lists = $list['data'];
  59 + foreach ($lists as $k=>$v ){
  60 + $lists[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
  61 + $lists[$k]['catdir'] = $cinfo['catdir'];
  62 + $lists[$k]['is_show'] = $cinfo['is_show'];
  63 + $lists[$k]['url'] = url('home/'.$cinfo['catdir'].'/info',['id'=>$v['id'],'catId'=>$v['catid']]);
  64 + }
  65 + $rsult['data'] = $lists;
  66 + $rsult['count'] = $list['total'];
  67 + $rsult['rel'] = 1;
  68 + return $rsult;
  69 + }else{
  70 + return $this->fetch ('content/index');
  71 + }
  72 + }
  73 +
  74 + public function edit(){
  75 + $id = input('id');
  76 + $request = Request::instance();
  77 + $controllerName = $request->controller();
  78 + if($controllerName=='Page'){
  79 + $p = $this->dao->where('id',$id)->find();
  80 + if(empty($p)){
  81 + $data['id']=$id;
  82 + $data['title'] = $this->categorys[$id]['catname'];
  83 + $data['keywords'] = $this->categorys[$id]['keywords'];
  84 + $this->dao->insert($data);
  85 + }
  86 + }
  87 + $info = $this->dao->where('id',$id)->find();
  88 + $form=new Form($info);
  89 + $returnData['vo'] = $info;
  90 + $returnData['form'] = $form;
  91 + $this->assign ('info', $info );
  92 + $this->assign ( 'form', $form );
  93 + $this->assign ( 'title', '编辑内容' );
  94 + return $this->fetch('content/edit');
  95 + }
  96 + function update(){
  97 + $request = Request::instance();
  98 +
  99 + $controllerName = $request->controller();
  100 + $model = $this->dao;
  101 + $fields = $this->fields;
  102 + $data = $this->checkfield($fields,Request::except('file'));
  103 + if(isset($data['code'])){
  104 + return ['code'=>0,'msg'=>$data['msg']];
  105 + }
  106 + if(isset($fields['updatetime'])) {
  107 + $data['userid'] = session('aid');
  108 + }
  109 +
  110 + if(isset($fields['updatetime'])) {
  111 + $data['updatetime'] = time();
  112 + }
  113 +
  114 + $title_style ='';
  115 + if (isset($data['style_color'])) {
  116 + $title_style .= 'color:' . $data['style_color'].';';
  117 + unset($data['style_color']);
  118 + }else{
  119 + $title_style .= 'color:#222;';
  120 + }
  121 + if (isset($data['style_bold'])) {
  122 + $title_style .= 'font-weight:' . $data['style_bold'].';';
  123 + unset($data['style_bold']);
  124 + }else{
  125 + $title_style .= 'font-weight:normal;';
  126 + }
  127 + if($fields['title']['setup']['style']==1) {
  128 + $data['title_style'] = $title_style;
  129 + }
  130 + if($controllerName!='Page') {
  131 + $data['updatetime'] = time();
  132 + }
  133 + unset($data['aid']);
  134 + unset($data['pics_name']);
  135 + //编辑多图和多文件
  136 + foreach ($fields as $k=>$v){
  137 + if($v['type']=='files' ){
  138 + if(!$data[$k]){
  139 + $data[$k]='';
  140 + }
  141 + $data[$v['field']] = $data['images'];
  142 + }
  143 + if($v['type']=='images'){
  144 + if(!isset($data[$k])){
  145 + $data[$k]='';
  146 + }
  147 + if($data[$k]){
  148 + $data[$v['field']] = implode(';',$data[$k]);
  149 + }
  150 + }
  151 + }
  152 + $list=$model->strict(false)->update($data);
  153 + if (false !== $list) {
  154 + if($controllerName=='Page'){
  155 + $result['url'] = url("admin/category/index");
  156 + }else{
  157 + $result['url'] = url("admin/".$controllerName."/index",array('catid'=>$data['catid']));
  158 + }
  159 + $result['msg'] = '修改成功!';
  160 + $result['code'] = 1;
  161 + return $result;
  162 + } else {
  163 + $result['msg'] = '修改失败!';
  164 + $result['code'] = 0;
  165 + return $result;
  166 + }
  167 + }
  168 + public function set_categorys($categorys = array()) {
  169 + if (is_array($categorys) && !empty($categorys)) {
  170 + foreach ($categorys as $id => $c) {
  171 + $this->categorys[$c['id']] = $c;
  172 + $r = db('category')->where("parentid = $c[id]")->order('listorder ASC,id ASC')->select();
  173 + $this->set_categorys($r);
  174 + }
  175 + }
  176 + return true;
  177 + }
  178 + function checkfield($fields,$post){
  179 + foreach ( $post as $key => $val ) {
  180 + if(isset($fields[$key])){
  181 + $setup=$fields[$key]['setup'];
  182 + if(!empty($fields[$key]['required']) && empty($post[$key])){
  183 + $result['msg'] = $fields[$key]['errormsg']?$fields[$key]['errormsg']:'缺少必要参数!';
  184 + $result['code'] = 0;
  185 + return $result;
  186 + }
  187 + if(isset($setup['multiple'])){
  188 + if(is_array($post[$key])){
  189 + $post[$key] = implode(',',$post[$key]);
  190 + }
  191 + }
  192 + if(isset($setup['inputtype'])){
  193 + if($setup['inputtype']=='checkbox'){
  194 + $post[$key] = implode(',',$post[$key]);
  195 + }
  196 + }
  197 + if(isset($setup['fieldtype'])){
  198 + if($fields[$key]['type']=='checkbox'){
  199 + $post[$key] = implode(',',$post[$key]);
  200 + }
  201 + }
  202 + if($fields[$key]['type']=='datetime'){
  203 + $post[$key] =strtotime($post[$key]);
  204 + }elseif($fields[$key]['type']=='textarea'){
  205 + $post[$key]=addslashes($post[$key]);
  206 + }elseif($fields[$key]['type']=='linkage'){
  207 + if($post[$key][0]){
  208 + $post[$key] = implode(',',$post[$key]);
  209 + }else{
  210 + unset($post[$key]);
  211 + }
  212 + }elseif($fields[$key]['type']=='editor'){
  213 + if(isset($post['add_description']) && $post['description'] == '' && isset($post['content'])) {
  214 + $content = stripslashes($post['content']);
  215 + $description_length = intval($post['description_length']);
  216 + $post['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;'), '', strip_tags($content)),$description_length);
  217 + $post['description'] = addslashes($post['description']);
  218 + }
  219 + if(isset($post['auto_thumb']) && $post['thumb'] == '' && isset($post['content'])) {
  220 + $content = $content ? $content : stripslashes($post['content']);
  221 + $auto_thumb_no = intval($post['auto_thumb_no']) * 3;
  222 + if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
  223 + $post['thumb'] = $matches[$auto_thumb_no][0];
  224 + }
  225 + }
  226 + }
  227 + }
  228 + }
  229 + return $post;
  230 + }
  231 +
  232 + public function add(){
  233 + $form=new Form();
  234 + $this->assign ( 'form', $form );
  235 + $this->assign ( 'title', '添加内容' );
  236 + return $this->fetch('content/edit');
  237 + }
  238 + public function insert(){
  239 + $request = Request::instance();
  240 + $controllerName = $request->controller();
  241 + $model = $this->dao;
  242 + $fields = $this->fields;
  243 + $data = $this->checkfield($fields,Request::except('file'));
  244 + if(isset($data['code']) && $data['code']==0){
  245 + return $data;
  246 + }
  247 + if(isset($fields['createtime']) && !isset($data['createtime']) ){
  248 + $data['createtime'] = time();
  249 + }
  250 + if(isset($fields['updatetime']) && !isset($data['updatetime']) ) {
  251 + $data['updatetime'] = time();
  252 + }
  253 + if($controllerName!='Page') {
  254 + if (isset($fields['updatetime'])){
  255 + $data['updatetime'] = $data['createtime'];
  256 + }
  257 + }
  258 + $data['userid'] = session('aid');
  259 + $data['username'] = session('username');
  260 +
  261 + $title_style ='';
  262 + if (isset($data['style_color'])) {
  263 + $title_style .= 'color:' . $data['style_color'].';';
  264 + unset($data['style_color']);
  265 + }else{
  266 + $title_style .= 'color:#222;';
  267 + }
  268 + if (isset($data['style_bold'])) {
  269 + $title_style .= 'font-weight:' . $data['style_bold'].';';
  270 + unset($data['style_bold']);
  271 + }else{
  272 + $title_style .= 'font-weight:normal;';
  273 + }
  274 + if($fields['title']['setup']['style']==1) {
  275 + $data['title_style'] = $title_style;
  276 + }
  277 +
  278 + unset($data['style_color']);
  279 + unset($data['style_bold']);
  280 + unset($data['aid']);
  281 + unset($data['pics_name']);
  282 + //编辑多图和多文件
  283 + foreach ($fields as $k=>$v){
  284 + if($v['type']=='files' ){
  285 + if(!$data[$k]){
  286 + $data[$k]='';
  287 + }
  288 + $data[$v['field']] = $data['images'];
  289 + }
  290 + if($v['type']=='images'){
  291 + if(!isset($data[$k])){
  292 + $data[$k]='';
  293 + }
  294 + if($data[$k]){
  295 + $data[$v['field']] = implode(';',$data[$k]);
  296 + }
  297 + }
  298 + }
  299 + $id= $model->insertGetId($data);
  300 + if ($id !==false) {
  301 + if($controllerName=='page'){
  302 + $result['url'] = url("admin/category/index");
  303 + }else{
  304 + $result['url'] = url("admin/".$controllerName."/index",array('catid'=>$data['catid']));
  305 + }
  306 + $result['msg'] = '添加成功!';
  307 + $result['code'] = 1;
  308 + return $result;
  309 + } else {
  310 + $result['msg'] = '添加失败!';
  311 + $result['code'] = 0;
  312 + return $result;
  313 + }
  314 +
  315 + }
  316 +
  317 +
  318 + public function listDel(){
  319 + $id = input('post.id');
  320 + $model = $this->dao;
  321 + $model->where(array('id'=>$id))->delete();//转入回收站
  322 + return ['code'=>1,'msg'=>'删除成功!'];
  323 + }
  324 + public function delAll(){
  325 + $map[] =array('id','in',input('post.ids/a'));
  326 + $model = $this->dao;
  327 + $model->where($map)->delete();
  328 + $result['code'] = 1;
  329 + $result['msg'] = '删除成功!';
  330 + $result['url'] = url('index',array('catid'=>input('post.catid')));
  331 + return $result;
  332 + }
  333 + public function listorder(){
  334 + $model = $this->dao;
  335 + $catid = input('catid');
  336 + $data = input('post.');
  337 + $model->update($data);
  338 + $result = ['msg' => '排序成功!','url'=>url('index',array('catid'=>$catid)), 'code' => 1];
  339 + return $result;
  340 + }
  341 + public function delImg(){
  342 + if(!input('post.url')){
  343 + return ['code'=>0,'请指定要删除的图片资源'];
  344 + }
  345 + $file = ROOT_PATH.__PUBLIC__.input('post.url');
  346 + if(file_exists($file) && trim(input('post.url'))!=''){
  347 + is_dir($file) ? dir_delete($file) : unlink($file);
  348 + }
  349 + if(input('post.id')){
  350 + $picurl = input('post.picurl');
  351 + $picurlArr = explode(':',$picurl);
  352 + $pics = substr(implode(":::",$picurlArr),0,-3);
  353 + $model = $this->dao;
  354 + $map['id'] =input('post.id');
  355 + $model->where($map)->update(array('pics'=>$pics));
  356 + }
  357 + $result['msg'] = '删除成功!';
  358 + $result['code'] = 1;
  359 + return $result;
  360 + }
  361 + public function getRegion(){
  362 + $Region=db("region");
  363 + $map['pid'] = input("pid");
  364 + $list=$Region->where($map)->select();
  365 + return $list;
  366 + }
  367 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\Request;
  5 +use think\Controller;
  6 +class Feast extends Common
  7 +{
  8 + public function index(){
  9 + if(request()->isPost()) {
  10 + $key = input('post.key');
  11 + $this->assign('testkey', $key);
  12 + $page =input('page')?input('page'):1;
  13 + $pageSize =input('limit')?input('limit'):config('pageSize');
  14 + $list = Db::name('feast')
  15 + ->where('title', 'like', "%" . $key . "%")
  16 + ->order('sort')
  17 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  18 + ->toArray();
  19 + foreach ($list['data'] as $k=>$v){
  20 + $list['data'][$k]['addtime'] = date('Y-m-d H:i',$v['addtime']);
  21 + $list['data'][$k]['type'] = $v['type']==1?'阳历':'农历';
  22 + }
  23 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  24 + }
  25 + return $this->fetch();
  26 + }
  27 + public function add(){
  28 + if(request()->isPost()) {
  29 + //构建数组
  30 + $data = input('post.');
  31 + $data['addtime'] = time();
  32 + db('feast')->insert($data);
  33 + return ['code'=>1,'msg'=>'节日添加成功!','url'=>url('index')];
  34 + }else{
  35 + $this->assign('title',lang('add').'节日');
  36 + $this->assign('info','null');
  37 + return $this->fetch('form');
  38 + }
  39 + }
  40 + public function edit(){
  41 + if(request()->isPost()) {
  42 + $data = input('post.');
  43 + if(db('feast')->update($data)!==false){
  44 + return ['code'=>1,'msg'=>'节日修改成功!','url'=>url('index')];
  45 + }else{
  46 + return ['code'=>0,'msg'=>'节日修改失败!'];
  47 + }
  48 + }else{
  49 + $id=input('id');
  50 + $adInfo=db('feast')->where(array('id'=>$id))->find();
  51 + $this->assign('info',json_encode($adInfo,true));
  52 + $this->assign('title',lang('edit').'节日');
  53 + return $this->fetch('form');
  54 + }
  55 + }
  56 + //设置节日状态
  57 + public function editState(){
  58 + $id=input('post.id');
  59 + $open=input('post.open');
  60 + if(db('feast')->where('id='.$id)->update(['open'=>$open])!==false){
  61 + return ['status'=>1,'msg'=>'设置成功!'];
  62 + }else{
  63 + return ['status'=>0,'msg'=>'设置失败!'];
  64 + }
  65 + }
  66 + public function feastOrder(){
  67 + $feast=db('feast');
  68 + $data = input('post.');
  69 + if($feast->update($data)!==false){
  70 + return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' =>1];
  71 + }else{
  72 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  73 + }
  74 + }
  75 + public function del(){
  76 + db('feast')->where(array('id'=>input('id')))->delete();
  77 + return ['code'=>1,'msg'=>'删除成功!'];
  78 + }
  79 + /***********************节日元素列表****************************************************************/
  80 + public function element(){
  81 + if(request()->isPost()) {
  82 + $key = input('post.key');
  83 + $this->assign('testkey', $key);
  84 +
  85 + $page =input('page')?input('page'):1;
  86 + $pid = input('pid');
  87 + $pageSize =input('limit')?input('limit'):config('pageSize');
  88 + $list = Db::name('feast_element')
  89 + ->where([['title','like', "%" . $key . "%"],['pid','=',$pid]])
  90 + ->order('sort')
  91 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  92 + ->toArray();
  93 + foreach ($list['data'] as $k=>$v){
  94 + $list['data'][$k]['addtime'] = date('Y-m-d H:i',$v['addtime']);
  95 + }
  96 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  97 + }
  98 + return $this->fetch();
  99 + }
  100 + public function add_element(){
  101 + if(request()->isPost()) {
  102 + //构建数组
  103 + $data = input('post.');
  104 + $data['addtime'] = time();
  105 + $data['pid'] = input('pid');
  106 + db('feast_element')->insert($data);
  107 + return ['code'=>1,'msg'=>'节日元素添加成功!','url'=>url('element',array('pid'=>input('pid')))];
  108 + }else{
  109 + $this->assign('title',lang('add').'节日元素');
  110 + $this->assign('info','null');
  111 + return $this->fetch('element_form');
  112 + }
  113 + }
  114 + public function edit_element(){
  115 + if(request()->isPost()) {
  116 + $data = input('post.');
  117 + if(db('feast_element')->update($data)!==false){
  118 + return ['code'=>1,'msg'=>'节日元素修改成功!','url'=>url('element',array('pid'=>input('pid')))];
  119 + }else{
  120 + return ['code'=>0,'msg'=>'节日元素修改失败!'];
  121 + }
  122 + }else{
  123 + $id=input('id');
  124 + $adInfo=db('feast_element')->where(array('id'=>$id))->find();
  125 + $this->assign('info',json_encode($adInfo,true));
  126 + $this->assign('title',lang('edit').'节日元素');
  127 + return $this->fetch('element_form');
  128 + }
  129 + }
  130 + //设置节日元素状态
  131 + public function elementState(){
  132 + $id=input('post.id');
  133 + $open=input('post.open');
  134 + if(db('feast_element')->where('id='.$id)->update(['open'=>$open])!==false){
  135 + return ['status'=>1,'msg'=>'设置成功!'];
  136 + }else{
  137 + return ['status'=>0,'msg'=>'设置失败!'];
  138 + }
  139 + }
  140 + public function elementOrder(){
  141 + $data = input('post.');
  142 + if(db('feast_element')->update($data)!==false){
  143 + return $result = ['msg' => '操作成功!', 'code' =>1];
  144 + }else{
  145 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  146 + }
  147 + }
  148 + public function delElement(){
  149 + db('feast_element')->where(array('id'=>input('id')))->delete();
  150 + return ['code'=>1,'msg'=>'删除成功!'];
  151 + }
  152 +
  153 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Env;
  5 +class Index extends Common
  6 +{
  7 + public function initialize(){
  8 + parent::initialize();
  9 + }
  10 + public function index(){
  11 + //导航
  12 + // 获取缓存数据
  13 + $authRule = cache('authRule');
  14 + if(!$authRule){
  15 + $authRule = db('auth_rule')->where('menustatus=1')->order('sort')->select();
  16 + cache('authRule', $authRule, 3600);
  17 + }
  18 + //声明数组
  19 + $menus = array();
  20 + foreach ($authRule as $key=>$val){
  21 + $authRule[$key]['href'] = url($val['href']);
  22 + if($val['pid']==0){
  23 + if(session('aid')!=1){
  24 + if(in_array($val['id'],$this->adminRules)){
  25 + $menus[] = $val;
  26 + }
  27 + }else{
  28 + $menus[] = $val;
  29 + }
  30 + }
  31 + }
  32 + foreach ($menus as $k=>$v){
  33 + foreach ($authRule as $kk=>$vv){
  34 + if($v['id']==$vv['pid']){
  35 + if(session('aid')!=1) {
  36 + if (in_array($vv['id'], $this->adminRules)) {
  37 + $menus[$k]['children'][] = $vv;
  38 + }
  39 + }else{
  40 + $menus[$k]['children'][] = $vv;
  41 + }
  42 + }
  43 + }
  44 + }
  45 + $this->assign('menus',json_encode($menus,true));
  46 + return $this->fetch();
  47 + }
  48 + public function main(){
  49 + $version = Db::query('SELECT VERSION() AS ver');
  50 + $config = [
  51 + 'url' => $_SERVER['HTTP_HOST'],
  52 + 'document_root' => $_SERVER['DOCUMENT_ROOT'],
  53 + 'server_os' => PHP_OS,
  54 + 'server_port' => $_SERVER['SERVER_PORT'],
  55 + 'server_ip' => $_SERVER['SERVER_ADDR'],
  56 + 'server_soft' => $_SERVER['SERVER_SOFTWARE'],
  57 + 'php_version' => PHP_VERSION,
  58 + 'mysql_version' => $version[0]['ver'],
  59 + 'max_upload_size' => ini_get('upload_max_filesize')
  60 + ];
  61 + $this->assign('config', $config);
  62 + return $this->fetch();
  63 + }
  64 + public function welcome(){
  65 + $config = "Welcome";
  66 + $this->assign('config', $config);
  67 + return $this->fetch();
  68 + }
  69 + public function navbar(){
  70 + return $this->fetch();
  71 + }
  72 + public function nav(){
  73 + return $this->fetch();
  74 + }
  75 + public function clear(){
  76 + $R = Env::get('runtime_path');
  77 + if ($this->_deleteDir($R)) {
  78 + $result['info'] = '清除缓存成功!';
  79 + $result['status'] = 1;
  80 + } else {
  81 + $result['info'] = '清除缓存失败!';
  82 + $result['status'] = 0;
  83 + }
  84 + $result['url'] = url('admin/index/index');
  85 + return $result;
  86 + }
  87 + private function _deleteDir($R)
  88 + {
  89 + $handle = opendir($R);
  90 + while (($item = readdir($handle)) !== false) {
  91 + if ($item != '.' and $item != '..') {
  92 + if (is_dir($R . '/' . $item)) {
  93 + $this->_deleteDir($R . '/' . $item);
  94 + } else {
  95 + if (!unlink($R . '/' . $item))
  96 + die('error!');
  97 + }
  98 + }
  99 + }
  100 + closedir($handle);
  101 + return rmdir($R);
  102 + }
  103 +
  104 + //退出登陆
  105 + public function logout(){
  106 + session(null);
  107 + $this->redirect('login/index');
  108 + }
  109 +
  110 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +class Link extends Common
  4 +{
  5 + public function index(){
  6 + if(request()->isPost()) {
  7 + $val=input('post.val');
  8 + $map = '';
  9 + if (!empty($val)){
  10 + $map['name|url'] = array('like',"%".$val."%");
  11 + }
  12 + $link=db('link')->where($map)->order('sort')->select();
  13 + foreach ($link as $k=>$v){
  14 + $link[$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
  15 + }
  16 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$link,'rel'=>1];
  17 + }
  18 + return $this->fetch();
  19 + }
  20 + //修改友情链接状态
  21 + public function linkState(){
  22 + $id=input('post.id');
  23 + $open=input('post.open');
  24 + if(db('link')->where('link_id='.$id)->update(['open'=>$open])!==false){
  25 + return ['status'=>1,'msg'=>'设置成功!'];
  26 + }else{
  27 + return ['status'=>0,'msg'=>'设置失败!'];
  28 + }
  29 + }
  30 + public function listOrder(){
  31 + $data = input('post.');
  32 + if(db('link')->update($data)!==false){
  33 + cache('linkList', NULL);
  34 + return $result = ['msg' => '操作成功!','url'=>url('index'), 'code' => 1];
  35 + }else{
  36 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  37 + }
  38 + }
  39 + //添加
  40 + public function add(){
  41 + if(request()->isPost()){
  42 + $data = input('post.');
  43 + $data['addtime'] = time();
  44 + db('link')->insert($data);
  45 + $result['code'] = 1;
  46 + $result['msg'] = '友情链接添加成功!';
  47 + $result['url'] = url('index');
  48 + cache('linkList', NULL);
  49 + return $result;
  50 + }else{
  51 + $this->assign('title',lang('add').lang('link'));
  52 + $this->assign('info','null');
  53 + return $this->fetch('form');
  54 + }
  55 + }
  56 + //修改友情链接
  57 + public function edit(){
  58 + if(request()->isPost()){
  59 + $data = input('post.');
  60 + db('link')->update($data);
  61 + $result['code'] = 1;
  62 + $result['msg'] = '友情链接修改成功!';
  63 + $result['url'] = url('index');
  64 + cache('linkList', NULL);
  65 + return $result;
  66 + }else{
  67 + $link_id=input('param.link_id');
  68 + $info=db('link')->where(array('link_id'=>$link_id))->find();
  69 + $this->assign('info',json_encode($info,true));
  70 + $this->assign('title',lang('edit').lang('link'));
  71 + return $this->fetch('form');
  72 + }
  73 + }
  74 + public function del(){
  75 + db('link')->where(array('link_id'=>input('link_id')))->delete();
  76 + cache('linkList', NULL);
  77 + return ['code'=>1,'msg'=>'删除成功!'];
  78 + }
  79 + public function delall(){
  80 + $map[] =array('link_id','IN',input('param.ids/a'));
  81 + db('link')->where($map)->delete();
  82 + $result['msg'] = '删除成功!';
  83 + $result['code'] = 1;
  84 + $result['url'] = url('index');
  85 + cache('linkList', NULL);
  86 + return $result;
  87 + }
  88 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Controller;
  4 +use app\admin\model\Admin;
  5 +use think\captcha\Captcha;
  6 +class Login extends Controller
  7 +{
  8 + private $cache_model,$system;
  9 + public function initialize(){
  10 + if (session('aid')) {
  11 + $this->redirect('admin/index/index');
  12 + }
  13 + $this->cache_model=array('Module','AuthRule','Category','Posid','Field','System');
  14 + $this->system = cache('System');
  15 + $this->assign('system',$this->system);
  16 + if(empty($this->system)){
  17 + foreach($this->cache_model as $r){
  18 + savecache($r);
  19 + }
  20 + }
  21 + }
  22 + public function index(){
  23 + if(request()->isPost()) {
  24 + $data = input('post.');
  25 + $admin = new Admin();
  26 + $return = $admin->login($data,$this->system['code']);
  27 + return ['code' => $return['code'], 'msg' => $return['msg']];
  28 + }else{
  29 + return $this->fetch();
  30 + }
  31 + }
  32 + public function verify(){
  33 + $config = [
  34 + // 验证码字体大小
  35 + 'fontSize' => 25,
  36 + // 验证码位数
  37 + 'length' => 4,
  38 + // 关闭验证码杂点
  39 + 'useNoise' => false,
  40 + 'bg' => [255,255,255],
  41 + ];
  42 + $captcha = new Captcha($config);
  43 + return $captcha->entry();
  44 + }
  45 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +class Message extends Common
  4 +{
  5 + public function index(){
  6 + if(request()->isPost()) {
  7 + $key=input('post.key');
  8 + $page =input('page')?input('page'):1;
  9 + $pageSize =input('limit')?input('limit'):config('pageSize');
  10 + $list = db('message')
  11 + ->where('name|tel|content', 'like', "%" . $key . "%")
  12 + ->order('addtime desc')
  13 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  14 + ->toArray();
  15 + foreach ($list['data'] as $k=>$v){
  16 + $list['data'][$k]['addtime'] = date('Y-m-d H:s',$v['addtime']);
  17 + }
  18 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  19 + }
  20 + return $this->fetch();
  21 + }
  22 + //删除留言
  23 + public function del(){
  24 + $map['message_id']=input('message_id');
  25 + db('message')->where($map)->delete();
  26 + return $result = ['code'=>1,'msg'=>'删除成功!'];
  27 + }
  28 + public function delall(){
  29 + $map[] =array('message_id','IN',input('param.ids/a'));
  30 + db('message')->where($map)->delete();
  31 + $result['msg'] = '删除成功!';
  32 + $result['code'] = 1;
  33 + $result['url'] = url('index');
  34 + return $result;
  35 + }
  36 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Request;
  5 +class Module extends Common
  6 +{
  7 + protected $dao;
  8 + function initialize()
  9 + {
  10 + parent::initialize();
  11 + $this->dao=db('module');
  12 + $field_pattern = [
  13 + ['name'=>'defaul','title'=>'默认'],
  14 + ['name'=>'email','title'=>'电子邮件'],
  15 + ['name'=>'url','title'=>'网址'],
  16 + ['name'=>'date','title'=>'日期'],
  17 + ['name'=>'number','title'=>'有效的数值'],
  18 + ['name'=>'digits','title'=>'数字'],
  19 + ['name'=>'creditcard','title'=>'信用卡号码'],
  20 + ['name'=>'equalTo','title'=>'再次输入相同的值'],
  21 + ['name'=>'ip4','title'=>'IP'],
  22 + ['name'=>'mobile','title'=>'手机号码'],
  23 + ['name'=>'zipcode','title'=>'邮编'],
  24 + ['name'=>'qq','title'=>'QQ'],
  25 + ['name'=>'idcard','title'=>'身份证号'],
  26 + ['name'=>'chinese','title'=>'中文字符'],
  27 + ['name'=>'cn_username','title'=>'中文英文数字和下划线'],
  28 + ['name'=>'tel','title'=>'电话号码'],
  29 + ['name'=>'english','title'=>'英文'],
  30 + ['name'=>'en_num','title'=>'英文数字和下划线'],
  31 + ];
  32 + $this->assign('pattern', json_encode($field_pattern,true));
  33 + }
  34 + public function index(){
  35 + if(Request::isAjax()) {
  36 + $pageSize =input('limit')?input('limit'):config('pageSize');
  37 + $list = db('module')->order('sort asc')
  38 + ->paginate($pageSize)
  39 + ->toArray();
  40 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  41 + }else{
  42 + return $this->fetch();
  43 + }
  44 + }
  45 + public function edit(){
  46 + if(request()->isPost()){
  47 + $data = Request::except('name');
  48 + if(db('module')->update($data)!==false){
  49 + savecache('Module');
  50 + return array('code'=>1,'url'=>url('index'),'msg'=>'修改成功!');
  51 + }else{
  52 + return array('code'=>0,'url'=>url('index'),'msg'=>'修改失败!');
  53 + }
  54 + }else{
  55 + $map['id'] = input('param.id');
  56 + $info = db('module')->field('id,title,name,description,listfields')->where($map)->find();
  57 + $this->assign('title',lang('edit').lang('module'));
  58 + $this->assign('info', json_encode($info,true));
  59 + return $this->fetch('form');
  60 + }
  61 + }
  62 + public function add(){
  63 + if(request()->isPost()){
  64 + //获取数据库所有表名
  65 + $tables = Db::getConnection()->getTables();
  66 +
  67 + //组装表名
  68 + $prefix = config('database.prefix');
  69 + $tablename = $prefix.input('post.name');
  70 + //判断表名是否已经存在
  71 + if(in_array($tablename,$tables)){
  72 + $result['code'] = 0;
  73 + $result['info'] = '该表已经存在!';
  74 + return $result;
  75 + }
  76 + $name = ucfirst(input('post.name'));
  77 + $data = Request::except('emptytable');
  78 + $data['type'] = 1;
  79 +
  80 + $moduleid = db('module')->insertGetId($data);
  81 + if(empty($moduleid)){
  82 + $result['code'] = 0;
  83 + $result['msg'] = '添加模型失败!';
  84 + return $result;
  85 + }
  86 + $emptytable =input('post.emptytable');
  87 + if($emptytable=='0'){
  88 + Db::execute("CREATE TABLE `".$tablename."` (
  89 + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  90 + `catid` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '分类ID',
  91 + `userid` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  92 + `username` varchar(40) NOT NULL DEFAULT '' COMMENT '用户名',
  93 + `title` varchar(120) NOT NULL DEFAULT '' COMMENT '标题',
  94 + `title_style` varchar(225) NOT NULL DEFAULT '' COMMENT '标题样式',
  95 + `thumb` varchar(225) NOT NULL DEFAULT '' COMMENT '缩略图',
  96 + `keywords` varchar(120) NOT NULL DEFAULT '' COMMENT '关键词',
  97 + `description` mediumtext NOT NULL COMMENT '描述',
  98 + `content` mediumtext NOT NULL COMMENT '内容',
  99 + `template` varchar(40) NOT NULL DEFAULT '' COMMENT '模板',
  100 + `posid` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '推荐位',
  101 + `status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态',
  102 + `recommend` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '允许评论',
  103 + `readgroup` varchar(100) NOT NULL DEFAULT '' COMMENT '访问权限',
  104 + `readpoint` smallint(5) NOT NULL DEFAULT '0' COMMENT '阅读权限',
  105 + `sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
  106 + `hits` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击',
  107 + `createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  108 + `updatetime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
  109 + PRIMARY KEY (`id`),
  110 + KEY `status` (`id`,`status`,`sort`),
  111 + KEY `catid` (`id`,`catid`,`status`),
  112 + KEY `sort` (`id`,`catid`,`status`,`sort`)
  113 + ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
  114 + 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')");
  115 + 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')");
  116 + 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')");
  117 + 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')");
  118 + 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')");
  119 + 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')");
  120 + 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')");
  121 + 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')");
  122 + 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')");
  123 + 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')");
  124 + 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')");
  125 + 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')");
  126 + 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')");
  127 +
  128 + }else{
  129 + Db::execute("CREATE TABLE `".$tablename."` (
  130 + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  131 + `title` varchar(120) NOT NULL DEFAULT '' COMMENT '标题',
  132 + `title_style` varchar(225) NOT NULL DEFAULT '' COMMENT '标题样式',
  133 + `thumb` varchar(225) NOT NULL DEFAULT '' COMMENT '缩略图',
  134 + `hits` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '点击',
  135 + `status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态',
  136 + `userid` int(8) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  137 + `username` varchar(40) NOT NULL DEFAULT '' COMMENT '用户名',
  138 + `sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
  139 + `createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  140 + `updatetime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
  141 + `lang` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '语言',
  142 + `template` varchar(40) NOT NULL DEFAULT '' COMMENT '模板',
  143 + PRIMARY KEY (`id`)
  144 + ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8");
  145 +
  146 + 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')");
  147 + 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')");
  148 + 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')");
  149 + 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')");
  150 + 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')");
  151 + }
  152 + if ($moduleid !==false) {
  153 + savecache('Module');
  154 + $result['code'] = 1;
  155 + $result['msg'] = '添加模型成功!';
  156 + $result['url'] = url('index');
  157 + return $result;
  158 + }
  159 + }else{
  160 + $this->assign('title',lang('add').lang('module'));
  161 + $this->assign('info','null');
  162 + return $this->fetch('form');
  163 + }
  164 + }
  165 + //模型状态
  166 + public function moduleState(){
  167 + $id=input('post.id');
  168 + $status=input('post.status');
  169 + if(db('module')->where('id='.$id)->update(['status'=>$status])!==false){
  170 + return ['status'=>1,'msg'=>'设置成功!'];
  171 + }else{
  172 + return ['status'=>0,'msg'=>'设置失败!'];
  173 + }
  174 + }
  175 + //删除模型
  176 + function del() {
  177 + $id =input('param.id');
  178 + $r = db('module')->find($id);
  179 + if(!empty($r)){
  180 + $tablename = config('database.prefix').$r['name'];
  181 +
  182 + $m = db('module')->delete($id);
  183 + if($m){
  184 + Db::execute("DROP TABLE IF EXISTS `".$tablename."`");
  185 + db('Field')->where(array('moduleid'=>$id))->delete();
  186 + }
  187 + }
  188 + savecache('Module');
  189 + return ['code'=>1,'msg'=>'删除成功!'];
  190 + }
  191 +
  192 + /****************************模型字段******************************/
  193 + public function field(){
  194 + if(request()->isPost()){
  195 + $nodostatus = array('catid','title','status','createtime');
  196 + $sysfield = array('catid','userid','username','title','thumb','keywords','description','posid','status','createtime','url','template');
  197 +
  198 + $list = db('field')->where("moduleid=".input('param.id'))->order('sort asc,id asc')->select();
  199 + foreach ($list as $k=>$v){
  200 + if($v['status']==1){
  201 + if(in_array($v['field'],$nodostatus)){
  202 + $list[$k]['disable']=2;
  203 + }else{
  204 + $list[$k]['disable']=0;
  205 + }
  206 + }else{
  207 + $list[$k]['disable']=1;
  208 + }
  209 +
  210 + if(in_array($v['field'],$sysfield)){
  211 + $list[$k]['delStatus']=1;
  212 + }else{
  213 + $list[$k]['delStatus']=0;
  214 + }
  215 + }
  216 + $this->assign('list', $list);
  217 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  218 + }else{
  219 + return $this->fetch();
  220 + }
  221 + }
  222 + //修改状态
  223 + public function fieldStatus(){
  224 + $map['id']=input('post.id');
  225 + //判断当前状态情况
  226 + $field = db('field');
  227 + $status=$field->where($map)->value('status');
  228 + if($status==1){
  229 + $data['status'] = 0;
  230 + }else{
  231 + $data['status'] = 1;
  232 + }
  233 + $field->where($map)->setField($data);
  234 + return $data;
  235 + }
  236 + //添加字段
  237 + public function fieldAdd(){
  238 + if(Request::isAjax()){
  239 + if(input('isajax')) {
  240 + $this->assign(input('get.'));
  241 + $this->assign(input('post.'));
  242 + $name = db('module')->where(array('id' => input('moduleid')))->value('name');
  243 + if (input('name')) {
  244 + $files = Db::getTableFields(config('database.prefix') . $name);
  245 + if(isset($files['type'][input('name')])){
  246 + $fieldtype = $files['type'][input('name')];
  247 + }else{
  248 + $fieldtype = '';
  249 + }
  250 + $this->assign('fieldtype', $fieldtype);
  251 + return view('fieldType');
  252 + } else {
  253 + return view('fieldAddType');
  254 + }
  255 + }else{
  256 + $data = input('post.');
  257 + $fieldName=$data['field'];
  258 + $prefix=config('database.prefix');
  259 + $name = db('module')->where(array('id'=>$data['moduleid']))->value('name');
  260 + $tablename=$prefix.$name;
  261 + $Fields=Db::getTableFields($tablename);
  262 + if(in_array($fieldName,$Fields)){
  263 + $result['msg'] = '字段名已经存在!';
  264 + $result['code'] = 0;
  265 + return $result;
  266 + }
  267 + $addfieldsql =$this->get_tablesql($data,'add');
  268 + if(isset($data['setup'])) {
  269 + $data['setup'] = array2string($data['setup']);
  270 + }
  271 + $data['status'] =1;
  272 + if($data['pattern']=='?'){
  273 + $data['pattern'] = 'defaul';
  274 + }else{
  275 + $pattern= explode(':',$data['pattern']);
  276 + $data['pattern'] = $pattern[1];
  277 + }
  278 + if(empty($data['class'])){
  279 + $data['class'] = $data['field'];
  280 + }
  281 + $model = db('field');
  282 + if ($model->insert($data) !==false) {
  283 + savecache('Field',$data['moduleid']);
  284 + if(is_array($addfieldsql)){
  285 + foreach($addfieldsql as $sql){
  286 + $model->execute($sql);
  287 + }
  288 + }else{
  289 + $model->execute($addfieldsql);
  290 + }
  291 + $result['msg'] = '添加成功!';
  292 + $result['code'] = 1;
  293 + $result['url'] = url('field',array('id'=>input('post.moduleid')));
  294 + return $result;
  295 + } else {
  296 + $result['msg'] = '添加失败!';
  297 + $result['code'] = 0;
  298 + return $result;
  299 + }
  300 + }
  301 + }else{
  302 + $moduleid =input('moduleid');
  303 + $this->assign('moduleid',$moduleid);
  304 + $this->assign('title',lang('add').lang('field'));
  305 + $this->assign('info','null');
  306 + return $this->fetch('fieldForm');
  307 + }
  308 + }
  309 + //编辑字段
  310 + public function fieldEdit(){
  311 + if(Request::isAjax()){
  312 + $data = Request::except('oldfield');
  313 + $oldfield = input('oldfield');
  314 + $fieldName=$data['field'];
  315 + $name = db('module')->where(array('id'=>$data['moduleid']))->value('name');
  316 + $prefix=config('database.prefix');
  317 + if($this->_iset_field($prefix.$name,$fieldName) && $oldfield!=$fieldName){
  318 + $result['msg'] = '字段名重复!';
  319 + $result['code'] = 0;
  320 + return $result;
  321 + }
  322 +
  323 + $editfieldsql =$this->get_tablesql(input('post.'),'edit');
  324 + if($data['setup']){
  325 + $data['setup']=array2string($data['setup']);
  326 + }
  327 + if(!empty($data['unpostgroup'])){
  328 + $data['setup'] = implode(',',$data['unpostgroup']);
  329 + }
  330 + if($data['pattern']=='?'){
  331 + $data['pattern'] = 'defaul';
  332 + }else{
  333 + $pattern= explode(':',$data['pattern']);
  334 + $data['pattern'] = $pattern[1];
  335 + }
  336 + if(empty($data['class'])){
  337 + $data['class'] = $data['field'];
  338 + }
  339 +
  340 +
  341 + $model = db('field');
  342 + if (false !== $model->update($data)) {
  343 + savecache('Field',$data['moduleid']);
  344 + if(is_array($editfieldsql)){
  345 + foreach($editfieldsql as $sql){
  346 + $model->execute($sql);
  347 + }
  348 + }else{
  349 + $editfieldsql;
  350 + $model->execute($editfieldsql);
  351 + }
  352 + $result['msg'] = '修改成功!';
  353 + $result['code'] = 1;
  354 + $result['url'] = url('field',array('id'=>input('post.moduleid')));
  355 + return $result;
  356 + } else {
  357 + $result['msg'] = '修改失败!';
  358 + $result['code'] = 0;
  359 + return $result;
  360 + }
  361 + }else{
  362 + $model = db('field');
  363 + $id = input('param.id');
  364 + if(empty($id)){
  365 + $result['msg'] = '缺少必要的参数!';
  366 + $result['code'] = 0;
  367 + return $result;
  368 + }
  369 + $fieldInfo = $model->where(array('id'=>$id))->find();
  370 + if($fieldInfo['setup']) $fieldInfo['setup']=string2array($fieldInfo['setup']);
  371 + $this->assign('info',json_encode($fieldInfo,true));
  372 + $this->assign('title',lang('edit').lang('field'));
  373 + $this->assign('moduleid', input('param.moduleid'));
  374 + return $this->fetch('fieldForm');
  375 + }
  376 + }
  377 + //字段排序
  378 + public function listOrder(){
  379 + $model =db('field');
  380 + $data = input('post.');
  381 + if($model->update($data)!==false){
  382 + return $result = ['msg' => '操作成功!','url'=>url('field',array('id'=>input('post.moduleid'))), 'code' => 1];
  383 + }else{
  384 + return $result = ['code'=>0,'msg'=>'操作失败!'];
  385 + }
  386 + }
  387 +
  388 + function fieldDel() {
  389 + $id=input('id');
  390 + $r = db('field')->find($id);
  391 + db('field')->delete($id);
  392 +
  393 + $moduleid = $r['moduleid'];
  394 +
  395 + $field = $r['field'];
  396 +
  397 + $prefix=config('database.prefix');
  398 + $name = db('module')->where(array('id'=>$moduleid))->value('name');
  399 + $tablename=$prefix.$name;
  400 +
  401 + db('field')->execute("ALTER TABLE `$tablename` DROP `$field`");
  402 +
  403 + return ['code'=>1,'msg'=>'删除成功!'];
  404 + }
  405 +
  406 +
  407 + public function get_tablesql($info,$do){
  408 + $comment = $info['name'];
  409 + $fieldtype = $info['type'];
  410 + if(isset($info['setup']['fieldtype'])){
  411 + $fieldtype=$info['setup']['fieldtype'];
  412 + }
  413 + $moduleid = $info['moduleid'];
  414 + $default = '';
  415 + if(isset($info['setup']['default'])){
  416 + $default=$info['setup']['default'];
  417 + }
  418 + $field = $info['field'];
  419 + $prefix = config('database.prefix');
  420 + $name = db('module')->where(array('id'=>$moduleid))->value('name');
  421 + $tablename=$prefix.$name;
  422 + $maxlength = intval($info['maxlength']);
  423 + $minlength = intval($info['minlength']);
  424 + $numbertype = '';
  425 + if(isset($info['setup']['numbertype'])){
  426 + $numbertype=$info['setup']['numbertype'];
  427 + }
  428 + if($do=='add'){
  429 + $do = ' ADD ';
  430 + }else{
  431 + $oldfield = $info['oldfield'];
  432 + $do = " CHANGE `".$oldfield."` ";
  433 + }
  434 + switch($fieldtype) {
  435 + case 'varchar':
  436 + if(!$maxlength){$maxlength = 255;}
  437 + $maxlength = min($maxlength, 255);
  438 + $sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT '$default' COMMENT '$comment'";
  439 + break;
  440 + case 'title':
  441 + $thumb = $info['setup']['thumb'];
  442 + $style = $info['setup']['style'];
  443 + if(!$maxlength){$maxlength = 255;}
  444 + $maxlength = min($maxlength, 255);
  445 + $sql[] = "ALTER TABLE `$tablename` $do `$field` VARCHAR( $maxlength ) NOT NULL DEFAULT '$default' COMMENT '$comment'";
  446 +
  447 +
  448 + if(!$this->_iset_field($tablename,'thumb')){
  449 + if($thumb==1) {
  450 + $sql[] = "ALTER TABLE `$tablename` ADD `thumb` VARCHAR( 100 ) NOT NULL DEFAULT '' COMMENT '缩略图'";
  451 + }
  452 + }else{
  453 + if($thumb==0) {
  454 + $sql[] = "ALTER TABLE `$tablename` drop column `thumb`";
  455 + }
  456 + }
  457 +
  458 + if(!$this->_iset_field($tablename,'title_style')){
  459 + if($style==1) {
  460 + $sql[] = "ALTER TABLE `$tablename` ADD `title_style` VARCHAR( 100 ) NOT NULL DEFAULT '' COMMENT '标题样式'";
  461 + }
  462 + }else{
  463 + if($style==0) {
  464 + $sql[] = "ALTER TABLE `$tablename` drop column `title_style`";
  465 + }
  466 + }
  467 + break;
  468 + case 'catid':
  469 + $sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
  470 + break;
  471 +
  472 + case 'number':
  473 + $decimaldigits = $info['setup']['decimaldigits'];
  474 + $default = $decimaldigits == 0 ? intval($default) : floatval($default);
  475 + $sql = "ALTER TABLE `$tablename` $do `$field` ".($decimaldigits == 0 ? 'INT' : 'decimal( 10,'.$decimaldigits.' )')." ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
  476 + break;
  477 +
  478 + case 'tinyint':
  479 + if(!$maxlength) $maxlength = 3;
  480 + $maxlength = min($maxlength,3);
  481 + $default = intval($default);
  482 + $sql = "ALTER TABLE `$tablename` $do `$field` TINYINT( $maxlength ) ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
  483 + break;
  484 +
  485 +
  486 + case 'smallint':
  487 + $default = intval($default);
  488 + $sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
  489 + break;
  490 +
  491 + case 'int':
  492 + $default = intval($default);
  493 + $sql = "ALTER TABLE `$tablename` $do `$field` INT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
  494 + break;
  495 +
  496 + case 'mediumint':
  497 + $default = intval($default);
  498 + $sql = "ALTER TABLE `$tablename` $do `$field` INT ".($numbertype ==1 ? 'UNSIGNED' : '')." NOT NULL DEFAULT '$default' COMMENT '$comment'";
  499 + break;
  500 +
  501 + case 'mediumtext':
  502 + $sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
  503 + break;
  504 +
  505 + case 'text':
  506 + $sql = "ALTER TABLE `$tablename` $do `$field` TEXT NOT NULL COMMENT '$comment'";
  507 + break;
  508 +
  509 + case 'posid':
  510 + $sql = "ALTER TABLE `$tablename` $do `$field` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
  511 + break;
  512 +
  513 + //case 'typeid':
  514 + //$sql = "ALTER TABLE `$tablename` $do `$field` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0'";
  515 + //break;
  516 +
  517 + case 'datetime':
  518 + $sql = "ALTER TABLE `$tablename` $do `$field` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '$comment'";
  519 + break;
  520 +
  521 + case 'editor':
  522 + $sql = "ALTER TABLE `$tablename` $do `$field` TEXT NOT NULL COMMENT '$comment'";
  523 + break;
  524 +
  525 + case 'image':
  526 + $sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
  527 + break;
  528 +
  529 + case 'images':
  530 + $sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
  531 + break;
  532 +
  533 + case 'file':
  534 + $sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
  535 + break;
  536 +
  537 + case 'files':
  538 + $sql = "ALTER TABLE `$tablename` $do `$field` MEDIUMTEXT NOT NULL COMMENT '$comment'";
  539 + break;
  540 + case 'template':
  541 + $sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
  542 + break;
  543 + case 'linkage':
  544 + $sql = "ALTER TABLE `$tablename` $do `$field` VARCHAR( 80 ) NOT NULL DEFAULT '' COMMENT '$comment'";
  545 + break;
  546 + }
  547 + return $sql;
  548 + }
  549 + protected function _iset_field($table,$field){
  550 + $fields = Db::getTableFields($table);
  551 + return array_search($field,$fields);
  552 + }
  553 +
  554 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\facade\Request;
  4 +use think\facade\Env;
  5 +class Plugin extends Common{
  6 + public function initialize(){
  7 + parent::initialize();
  8 + // 更新插件
  9 + $this->insertPlugin($this->scanPlugin());
  10 + }
  11 + public function index(){
  12 + if(Request::isAjax()) {
  13 + $list = db('plugin')->select();
  14 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  15 + }
  16 + return $this->fetch();
  17 + }
  18 + public function set(){
  19 + $condition['type'] = input('param.type');
  20 + $condition['code'] = input('param.code');
  21 + $model = db('plugin');
  22 + $info = $model->where($condition)->find();
  23 + if(!$info){
  24 + exit($this->error("不存在该插件"));
  25 + }
  26 + $this->assign('title','配置登录插件');
  27 + $info['config'] = unserialize($info['config']);
  28 + $this->assign('info',$info);
  29 + $this->assign('config_value',unserialize($info['config_value']));
  30 + return $this->fetch();
  31 + }
  32 + public function update(){
  33 + $condition['type'] = input('post.type');
  34 + $condition['code'] = input('post.code');
  35 + $model = db('plugin');
  36 + $config = input('post.config/a');
  37 + //空格过滤
  38 + $config = trim_array_element($config);
  39 + if($config){
  40 + $config = serialize($config);
  41 + }
  42 +
  43 + $row = $model->where($condition)->update(array('config_value'=>$config));
  44 + if($row!==false){
  45 + $result['code'] = 1;
  46 + $result['msg'] = '修改成功!';
  47 + }else{
  48 + $result['code'] = 0;
  49 + $result['msg'] = '修改失败!';
  50 + }
  51 + return $result;
  52 +
  53 + }
  54 + /**
  55 + * 插件安装卸载
  56 + */
  57 + public function install(){
  58 + $condition['type'] = input('post.type');
  59 + $condition['code'] = input('post.code');
  60 + $update['status'] = input('post.install');
  61 + $model = db('plugin');
  62 + //卸载插件时 删除配置信息
  63 + if($update['status']==0){
  64 + $row = db('plugin')->where($condition)->delete();
  65 + }else{
  66 + $row = $model->where($condition)->update($update);
  67 + }
  68 + if($row){
  69 + $info['code'] = 1;
  70 + $info['url'] = url($condition['type']);
  71 + $info['msg'] = $update['status'] ? '安装成功!' : '卸载成功!';
  72 + }else{
  73 + $info['code'] = 0;
  74 + $info['msg'] = $update['status'] ? '安装失败' : '卸载失败';
  75 + }
  76 + return $info;
  77 + }
  78 + /**
  79 + * 插件目录扫描
  80 + * @return array 返回目录数组
  81 + */
  82 + private function scanPlugin(){
  83 + $plugin_field = array();
  84 + $field = Env::get('root_path')."/plugins";
  85 + $plugin_field = $this->dirscan($field);
  86 + $plugin_list=array();
  87 + foreach($plugin_field as $k=>$v){
  88 + $plugin_list[$v] = $this->dirscan($field.'/'.$v);
  89 + }
  90 + foreach($plugin_list as $k=>$v){
  91 + foreach($v as $k2=>$v2){
  92 + if(!file_exists(Env::get('root_path').'/plugins/'.$k.'/'.$v2.'/config.php')){
  93 + unset($plugin_list[$k][$k2]);
  94 + }else {
  95 + $plugin_list[$k][$v2] = include(Env::get('root_path').'/plugins/'.$k.'/'.$v2.'/config.php');
  96 + unset($plugin_list[$k][$k2]);
  97 + }
  98 + }
  99 + }
  100 + //dump($plugin_list);
  101 + return $plugin_list;
  102 + }
  103 + /**
  104 + * 获取插件目录列表
  105 + * @param $dir
  106 + * @return array
  107 + */
  108 + private function dirscan($dir){
  109 + $dirArray = array();
  110 + if (false != ($handle = opendir($dir))) {
  111 + $i=0;
  112 + while ( false !== ($file = readdir ( $handle )) ) {
  113 + //去掉"“.”、“..”以及带“.xxx”后缀的文件
  114 + if ($file != "." && $file != ".."&&!strpos($file,".")) {
  115 + $dirArray[$i]=$file;
  116 + $i++;
  117 + }
  118 + }
  119 + //关闭句柄
  120 + closedir ( $handle );
  121 + }
  122 + return $dirArray;
  123 + }
  124 + /**
  125 + * 更新插件到数据库
  126 + * @param $plugin_list 本地插件数组
  127 + */
  128 + private function insertPlugin($plugin_list){
  129 + $d_list = db('plugin')->field('code,type')->select(); // 数据库
  130 +
  131 + $cv = array();
  132 + $new_arr = array(); // 本地
  133 + //插件类型
  134 + foreach($plugin_list as $pt=>$pv){
  135 + // 本地对比数据库
  136 + foreach($pv as $t=>$v){
  137 + foreach ($v['config'] as $key=>$val){
  138 + $cv[$val['name']] = $val['value'];
  139 + }
  140 + $tmp['code'] = $v['code'];
  141 + $tmp['type'] = $pt;
  142 + $new_arr[] = $tmp;
  143 + // 对比数据库 本地有 数据库没有
  144 + $is_exit = db('plugin')->where(array('type'=>$pt,'code'=>$v['code']))->find();
  145 + if(empty($is_exit)){
  146 + $add['code'] = $v['code'];
  147 + $add['name'] = $v['name'];
  148 + $add['version'] = $v['version'];
  149 + $add['icon'] = $v['icon'];
  150 + $add['author'] = $v['author'];
  151 + $add['desc'] = $v['desc'];
  152 + if(isset($v['bank_code'])){
  153 + $add['bank_code'] = serialize($v['bank_code']);
  154 + }
  155 + $add['type'] = $pt;
  156 + $add['scene'] = $v['scene'];
  157 + $add['config'] = empty($v['config']) ? '' : serialize($v['config']);
  158 + $add['config_value'] = empty($cv) ? '' : serialize($cv);
  159 + db('plugin')->insert($add);
  160 + }
  161 + }
  162 + }
  163 + foreach($d_list as $k=>$v){
  164 + if(!in_array($v,$new_arr)){
  165 + db('plugin')->where($v)->delete();
  166 + }
  167 + }
  168 +
  169 + }
  170 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\facade\Request;
  5 +class System extends Common
  6 +{
  7 + /********************************站点管理*******************************/
  8 + //站点设置
  9 + public function system($sys_id=1){
  10 + $table = db('system');
  11 + if(Request::isAjax()) {
  12 + $data = Request::except('file');
  13 + if($table->where('id',1)->update($data)!==false) {
  14 + savecache('System');
  15 + return json(['code' => 1, 'msg' => '站点设置保存成功!', 'url' => url('system/system')]);
  16 + } else {
  17 + return json(array('code' => 0, 'msg' =>'站点设置保存失败!'));
  18 + }
  19 + }else{
  20 + $system = $table->find($sys_id);
  21 + $this->assign('system', json_encode($system,true));
  22 + return $this->fetch();
  23 + }
  24 + }
  25 + public function email(){
  26 + if(Request::isAjax()) {
  27 + $datas = input('post.');
  28 + foreach ($datas as $k=>$v){
  29 + Db::name('config')->where([['name','=',$k],['inc_type','=','smtp']])->update(['value'=>$v]);
  30 + }
  31 + return json(['code' => 1, 'msg' => '邮箱设置成功!', 'url' => url('system/email')]);
  32 + }else{
  33 + $smtp = Db::name('config')->where('inc_type','smtp')->select();
  34 + $info = convert_arr_kv($smtp,'name','value');
  35 + $this->assign('info', json_encode($info,true));
  36 + return $this->fetch();
  37 + }
  38 + }
  39 + public function trySend(){
  40 + $sender = input('email');
  41 + //检查是否邮箱格式
  42 + if (!is_email($sender)) {
  43 + return json(['code' => 0, 'msg' => '测试邮箱码格式有误']);
  44 + }
  45 + $arr = db('config')->where('inc_type','smtp')->select();
  46 + $config = convert_arr_kv($arr,'name','value');
  47 + $content = $config['test_eamil_info'];
  48 + $send = send_email($sender, '测试邮件',$content);
  49 + if ($send) {
  50 + return json(['code' => 1, 'msg' => '邮件发送成功!']);
  51 + } else {
  52 + return json(['code' => 0, 'msg' => '邮件发送失败!']);
  53 + }
  54 + }
  55 +
  56 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\facade\Env;
  4 +class Template extends Common{
  5 + protected $filepath,$publicpath,$viewSuffix;
  6 + function initialize()
  7 + {
  8 + parent::initialize();
  9 + $viewPath = config('template.view_path');
  10 + $this->viewSuffix = config('template.view_suffix');
  11 + $viewPath = $viewPath ? $viewPath : 'view';
  12 + $this->filepath = Env::get('app_path').strtolower(config('default_module')).'/'.$viewPath.'/';
  13 + $this->publicpath = 'static/home/';
  14 + $this->assign ( 'viewSuffix',$this->viewSuffix );
  15 + }
  16 + /*public function index(){
  17 + $type= input('param.type') ? input('param.type') : $this->viewSuffix;
  18 + if($type==$this->viewSuffix){
  19 + $path=$this->filepath;
  20 + }else{
  21 + $path=$this->publicpath.$type.'/';
  22 + }
  23 + $files = dir_list($path,$type);
  24 + $templates = array();
  25 + foreach ($files as $key=>$file){
  26 + $filename = basename($file);
  27 + $templates[$key]['value'] = substr($filename,0,strrpos($filename, '.'));
  28 + $templates[$key]['filename'] = $filename;
  29 + $templates[$key]['filepath'] = $file;
  30 + $templates[$key]['filesize']=byte_format(filesize($file));
  31 + $templates[$key]['filemtime']=filemtime($file);
  32 + $templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)));
  33 + }
  34 + $this->assign ( 'templates',$templates );
  35 +
  36 + return $this->fetch();
  37 + }*/
  38 +
  39 + /*public function add(){
  40 + $this->assign ( 'title','添加模版' );
  41 + return $this->fetch();
  42 + }
  43 + public function insert(){
  44 + $filename = input('post.file');
  45 + $type = input('post.type');
  46 + $path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
  47 + $file = $path.$filename.'.'.$type;
  48 + if(file_exists($file)){
  49 + $result['msg'] = '文件已经存在!';
  50 + $result['status'] = 0;
  51 + return $result;
  52 + }
  53 + file_put_contents($file,stripslashes(input('post.content')));
  54 + $result['msg'] = '添加成功!';
  55 + if($type==$this->viewSuffix){
  56 + $result['url'] = url('index');
  57 + }else{
  58 + $result['url'] = url('index',array('type'=>$type));
  59 + }
  60 + $result['code'] = 1;
  61 + return $result;
  62 + }
  63 +
  64 + public function edit(){
  65 + $filename = input('param.file');
  66 + if(input('param.type')){
  67 + $type = input('param.type');
  68 + }else{
  69 + $type = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
  70 + }
  71 + $path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
  72 + $file = $path.$filename;
  73 + if(file_exists($file)){
  74 + $file=iconv('gb2312','utf-8',$file);
  75 + $content = file_get_contents($file);
  76 + $this->assign ( 'filename',$filename );
  77 + $this->assign ( 'title','修改模版内容' );
  78 + $this->assign ( 'file',$file );
  79 + $this->assign ( 'content',$content );
  80 + }else{
  81 + $this->error('文件不存在!');
  82 + }
  83 + return $this->fetch();
  84 + }
  85 + public function update(){
  86 + $filename = input('post.file');
  87 + $type= input('param.type') ? input('param.type') : $this->viewSuffix;
  88 + $path = $type==$this->viewSuffix ? $this->filepath : $this->publicpath.$type.'/';
  89 + $file = $path.$filename;
  90 + if(file_exists($file)){
  91 + file_put_contents($file,stripslashes(input('content')));
  92 + $result['msg'] = '修改成功!';
  93 + if($type==$this->viewSuffix){
  94 + $result['url'] = url('index');
  95 + }else{
  96 + $result['url'] = url('index',array('type'=>$type));
  97 + }
  98 + $result['code'] = 1;
  99 + return $result;
  100 + }else{
  101 + $result['msg'] = '文件不存在!';
  102 + $result['code'] = 0;
  103 + return $result;
  104 + }
  105 + }
  106 +
  107 + public function delete(){
  108 + $filename = input('param.file');
  109 + $type = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
  110 + $path = $type==$this->viewSuffix ? $path=$this->filepath : $this->publicpath.$type.'/';
  111 + $file = $path.$filename;
  112 + if(file_exists($file)){
  113 + unlink($file);
  114 + if($type==$this->viewSuffix){
  115 + $this->redirect('index');
  116 + }else{
  117 + $this->redirect('index',array('type'=>$type));
  118 + }
  119 + }else{
  120 + if($type==$this->viewSuffix){
  121 + $this->redirect('index');
  122 + }else{
  123 + $this->redirect('index',array('type'=>$type));
  124 + }
  125 + }
  126 + }
  127 +
  128 + public function images(){
  129 + $path = $this->publicpath.'images/'.input('folder').'/';
  130 + $uppath = explode('/',input('folder'));
  131 + $leve = count($uppath)-1;
  132 + unset($uppath[$leve]);
  133 + if($leve>1){
  134 + unset($uppath[$leve-1]);
  135 + $uppath = implode('/',$uppath).'/';
  136 + }else{
  137 + $uppath = '';
  138 + }
  139 + $this->assign ( 'leve',$leve);
  140 + $this->assign ( 'uppath',$uppath);
  141 + $files = glob($path.'*');
  142 + $folders=array();
  143 + foreach($files as $key => $file) {
  144 + $filename = basename($file);
  145 + if(is_dir($file)){
  146 + $folders[$key]['filename'] = $filename;
  147 + $folders[$key]['filepath'] = $file;
  148 + $folders[$key]['ext'] = 'folder';
  149 + }else{
  150 + $templates[$key]['filename'] = $filename;
  151 + $templates[$key]['filepath'] = $file;
  152 + $templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
  153 + if(!in_array($templates[$key]['ext'],array('gif','jpg','png','bmp'))) $templates[$key]['ico'] =1;
  154 + }
  155 + }
  156 + $this->assign ( 'title','媒体文件' );
  157 + $this->assign ( 'path',$path);
  158 + $this->assign ( 'folders',$folders );
  159 + $this->assign ( 'files',$templates );
  160 + return $this->fetch();
  161 + }
  162 + public function imgDel(){
  163 + $path = $this->publicpath.'images/'.input('post.folder');
  164 + $file=$path.input('post.filename');
  165 + if(file_exists($file)){
  166 + is_dir($file) ? dir_delete($file) : unlink($file);
  167 +
  168 + $result['msg'] = '删除成功!';
  169 + $result['code'] = 1;
  170 + return $result;
  171 + }else{
  172 + $result['msg'] = '文件不存在!';
  173 + $result['code'] = 0;
  174 + return $result;
  175 + }
  176 + }*/
  177 +
  178 + public function index(){
  179 + $path = $this->publicpath.'images/'.input('folder').'/';
  180 + $uppath = explode('/',input('folder'));
  181 + $leve = count($uppath)-1;
  182 + unset($uppath[$leve]);
  183 + if($leve>1){
  184 + unset($uppath[$leve-1]);
  185 + $uppath = implode('/',$uppath).'/';
  186 + }else{
  187 + $uppath = '';
  188 + }
  189 + $this->assign ( 'leve',$leve);
  190 + $this->assign ( 'uppath',$uppath);
  191 + $files = glob($path.'*');
  192 + $folders=array();
  193 + foreach($files as $key => $file) {
  194 + $filename = basename($file);
  195 + if(is_dir($file)){
  196 + $folders[$key]['filename'] = $filename;
  197 + $folders[$key]['filepath'] = $file;
  198 + $folders[$key]['ext'] = 'folder';
  199 + }else{
  200 + $templates[$key]['filename'] = $filename;
  201 + $templates[$key]['filepath'] = $file;
  202 + $templates[$key]['ext'] = strtolower(substr($filename,strrpos($filename, '.')-strlen($filename)+1));
  203 + if(!in_array($templates[$key]['ext'],array('zip','gif','jpg','png','bmp'))) $templates[$key]['favicon.ico'] =1;
  204 + }
  205 + }
  206 + $this->assign ( 'title','二维码管理' );
  207 + $this->assign ( 'path',$path);
  208 + $this->assign ( 'folders',$folders );
  209 + $this->assign ( 'files',$templates );
  210 + return $this->fetch();
  211 + }
  212 +
  213 + public function PackzipDownload(){
  214 + $path = $this->publicpath.'images/'.input('post.folder');
  215 + $file=$path.input('post.filename');
  216 + //首先判断是图片还是路径
  217 + if($this->isImage($file)!==false){
  218 + //是图片
  219 + $zip = new \ZipArchive;
  220 + //压缩文件名
  221 + $filename = $path.'download.zip';
  222 + //新建zip压缩包
  223 + $obj = $zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
  224 + //把图片一张一张加进去压缩
  225 + $zip->addFile($file);
  226 + //打包zip
  227 + $zip->close();
  228 +
  229 + //可以直接重定向下载
  230 + //header('Location:'.$filename);
  231 +
  232 + //或者输出下载
  233 + /*header("Cache-Control: public");
  234 + header("Content-Description: File Transfer");
  235 + header('Content-disposition: attachment; filename='.basename($filename)); //文件名
  236 + header("Content-Type: application/force-download");
  237 + header("Content-Transfer-Encoding: binary");
  238 + header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
  239 + return @readfile($filename);*/
  240 + }else{
  241 + //目录
  242 + $zip = new \ZipArchive;
  243 + //压缩文件名
  244 + $filename = $path.'download.zip';
  245 + //新建zip压缩包
  246 + $obj = $zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);
  247 + //把图片一张一张加进去压缩
  248 + $files = glob($file.'/*');
  249 + foreach($files as $key=>$val){
  250 + $zip->addFile($val);
  251 + }
  252 +
  253 + //打包zip
  254 + $zip->close();
  255 +
  256 + //可以直接重定向下载
  257 + header('Location:'.$filename);exit;
  258 +
  259 + //或者输出下载
  260 + header("Cache-Control: public");
  261 + header("Content-Description: File Transfer");
  262 + header('Content-disposition: attachment; filename='.basename($filename)); //文件名
  263 + header("Content-Type: application/force-download");
  264 + header("Content-Transfer-Encoding: binary");
  265 + header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小
  266 + return @readfile($filename);
  267 + }
  268 + }
  269 +
  270 + /**
  271 + * 判断所传文件是否是图片
  272 + */
  273 + public function isImage($filename)
  274 + {
  275 + $types = '.gif|.jpeg|.png|.bmp'; //定义检查的图片类型
  276 + if(file_exists($filename))
  277 + {
  278 + if (($info = @getimagesize($filename)))
  279 + return 0;
  280 + $ext = image_type_to_extension($info['2']);
  281 + return stripos($types,$ext);
  282 + }
  283 + else
  284 + {
  285 + return false;
  286 + }
  287 + }
  288 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use think\Db;
  4 +use think\Request;
  5 +use think\Controller;
  6 +use think\facade\Env;
  7 +class UpFiles extends Common
  8 +{
  9 + public function upload(){
  10 + // 获取上传文件表单字段名
  11 + $fileKey = array_keys(request()->file());
  12 + // 获取表单上传文件
  13 + $file = request()->file($fileKey['0']);
  14 + // 移动到框架应用根目录/public/uploads/ 目录下
  15 +
  16 + $info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move('uploads');
  17 + if($info){
  18 + $result['code'] = 1;
  19 + $result['info'] = '图片上传成功!';
  20 + $path=str_replace('\\','/',$info->getSaveName());
  21 + $result['url'] = '/uploads/'. $path;
  22 + return $result;
  23 + }else{
  24 + // 上传失败获取错误信息
  25 +
  26 + $result['code'] =0;
  27 + $result['info'] = $file->getError();
  28 + $result['url'] = '';
  29 + return $result;
  30 + }
  31 + }
  32 + public function file(){
  33 + $fileKey = array_keys(request()->file());
  34 + // 获取表单上传文件 例如上传了001.jpg
  35 + $file = request()->file($fileKey['0']);
  36 + // 移动到框架应用根目录/public/uploads/ 目录下
  37 + $info = $file->validate(['ext' => 'zip,rar,pdf,swf,ppt,psd,ttf,txt,xls,doc,docx'])->move('uploads');
  38 + if($info){
  39 + $result['code'] = 0;
  40 + $result['info'] = '文件上传成功!';
  41 + $path=str_replace('\\','/',$info->getSaveName());
  42 +
  43 + $result['url'] = '/uploads/'. $path;
  44 + $result['ext'] = $info->getExtension();
  45 + $result['size'] = byte_format($info->getSize(),2);
  46 + return $result;
  47 + }else{
  48 + // 上传失败获取错误信息
  49 + $result['code'] =1;
  50 + $result['info'] = '文件上传失败!';
  51 + $result['url'] = '';
  52 + return $result;
  53 + }
  54 + }
  55 + public function pic(){
  56 + // 获取上传文件表单字段名
  57 + $fileKey = array_keys(request()->file());
  58 + // 获取表单上传文件
  59 + $file = request()->file($fileKey['0']);
  60 + // 移动到框架应用根目录/public/uploads/ 目录下
  61 + $info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
  62 + if($info){
  63 + $result['code'] = 1;
  64 + $result['info'] = '图片上传成功!';
  65 + $path=str_replace('\\','/',$info->getSaveName());
  66 + $result['url'] = '/uploads/'. $path;
  67 + return json_encode($result,true);
  68 + }else{
  69 + // 上传失败获取错误信息
  70 + $result['code'] =0;
  71 + $result['info'] = '图片上传失败!';
  72 + $result['url'] = '';
  73 + return json_encode($result,true);
  74 + }
  75 + }
  76 + //编辑器图片上传
  77 + public function editUpload(){
  78 + // 获取表单上传文件 例如上传了001.jpg
  79 + $file = request()->file('file');
  80 + // 移动到框架应用根目录/public/uploads/ 目录下
  81 + $info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
  82 + if($info){
  83 + $result['code'] = 0;
  84 + $result['msg'] = '图片上传成功!';
  85 + $path=str_replace('\\','/',$info->getSaveName());
  86 + $result['data']['src'] = '/uploads/'. $path;
  87 + $result['data']['title'] = $path;
  88 + return json_encode($result,true);
  89 + }else{
  90 + // 上传失败获取错误信息
  91 + $result['code'] =1;
  92 + $result['msg'] = '图片上传失败!';
  93 + $result['data'] = '';
  94 + return json_encode($result,true);
  95 + }
  96 + }
  97 + //多图上传
  98 + public function upImages(){
  99 + $fileKey = array_keys(request()->file());
  100 + // 获取表单上传文件
  101 + $file = request()->file($fileKey['0']);
  102 + // 移动到框架应用根目录/public/uploads/ 目录下
  103 + $info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move(Env::get('root_path') . 'public/uploads');
  104 + if($info){
  105 + $result['code'] = 0;
  106 + $result['msg'] = '图片上传成功!';
  107 + $path=str_replace('\\','/',$info->getSaveName());
  108 + $result["src"] = '/uploads/'. $path;
  109 + return $result;
  110 + }else{
  111 + // 上传失败获取错误信息
  112 + $result['code'] =1;
  113 + $result['msg'] = '图片上传失败!';
  114 + return $result;
  115 + }
  116 + }
  117 +}
  1 +<?php
  2 +namespace app\admin\controller;
  3 +use app\admin\model\Users as UsersModel;
  4 +class Users extends Common{
  5 + //会员列表
  6 + public function index(){
  7 + if(request()->isPost()){
  8 + $key=input('post.key');
  9 + $page =input('page')?input('page'):1;
  10 + $pageSize =input('limit')?input('limit'):config('pageSize');
  11 + $list=db('users')->alias('u')
  12 + ->join(config('database.prefix').'user_level ul','u.level = ul.level_id','left')
  13 + ->field('u.*,ul.level_name')
  14 + ->where('u.email|u.mobile|u.username','like',"%".$key."%")
  15 + ->order('u.id desc')
  16 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  17 + ->toArray();
  18 + foreach ($list['data'] as $k=>$v){
  19 + $list['data'][$k]['reg_time'] = date('Y-m-d H:s',$v['reg_time']);
  20 + }
  21 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  22 + }
  23 + return $this->fetch();
  24 + }
  25 + //设置会员状态
  26 + public function usersState(){
  27 + $id=input('post.id');
  28 + $is_lock=input('post.is_lock');
  29 + if(db('users')->where('id='.$id)->update(['is_lock'=>$is_lock])!==false){
  30 + return ['status'=>1,'msg'=>'设置成功!'];
  31 + }else{
  32 + return ['status'=>0,'msg'=>'设置失败!'];
  33 + }
  34 + }
  35 + public function edit($id=''){
  36 + if(request()->isPost()){
  37 + $user = db('users');
  38 + $data = input('post.');
  39 + $level =explode(':',$data['level']);
  40 + $data['level'] = $level[1];
  41 + $province =explode(':',$data['province']);
  42 + $data['province'] = isset( $province[1])?$province[1]:'';
  43 + $city =explode(':',$data['city']);
  44 + $data['city'] = isset( $city[1])?$city[1]:'';
  45 + $district =explode(':',$data['district']);
  46 + $data['district'] = isset( $district[1])?$district[1]:'';
  47 + if(empty($data['password'])){
  48 + unset($data['password']);
  49 + }else{
  50 + $data['password'] = md5($data['password']);
  51 + }
  52 + if ($user->update($data)!==false) {
  53 + $result['msg'] = '会员修改成功!';
  54 + $result['url'] = url('index');
  55 + $result['code'] = 1;
  56 + } else {
  57 + $result['msg'] = '会员修改失败!';
  58 + $result['code'] = 0;
  59 + }
  60 + return $result;
  61 + }else{
  62 + $province = db('Region')->where ( array('pid'=>1) )->select ();
  63 + $user_level=db('user_level')->order('sort')->select();
  64 + $info = UsersModel::get($id);
  65 + $this->assign('info',json_encode($info,true));
  66 + $this->assign('title',lang('edit').lang('user'));
  67 + $this->assign('province',json_encode($province,true));
  68 + $this->assign('user_level',json_encode($user_level,true));
  69 +
  70 + $city = db('Region')->where ( array('pid'=>$info['province']) )->select ();
  71 + $this->assign('city',json_encode($city,true));
  72 + $district = db('Region')->where ( array('pid'=>$info['city']) )->select ();
  73 + $this->assign('district',json_encode($district,true));
  74 + return $this->fetch();
  75 + }
  76 + }
  77 +
  78 + public function getRegion(){
  79 + $Region=db("region");
  80 + $pid = input("pid");
  81 + $arr = explode(':',$pid);
  82 + $map['pid']=$arr[1];
  83 + $list=$Region->where($map)->select();
  84 + return $list;
  85 + }
  86 +
  87 + public function usersDel(){
  88 + db('users')->delete(['id'=>input('id')]);
  89 + db('oauth')->delete(['uid'=>input('id')]);
  90 + return $result = ['code'=>1,'msg'=>'删除成功!'];
  91 + }
  92 + public function delall(){
  93 + $map[] =array('id','IN',input('param.ids/a'));
  94 + db('users')->where($map)->delete();
  95 + $result['msg'] = '删除成功!';
  96 + $result['code'] = 1;
  97 + $result['url'] = url('index');
  98 + return $result;
  99 + }
  100 +
  101 + /***********************************会员组***********************************/
  102 + public function userGroup(){
  103 + if(request()->isPost()){
  104 + $userLevel=db('user_level');
  105 + $list=$userLevel->order('sort')->select();
  106 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list,'rel'=>1];
  107 + }
  108 + return $this->fetch();
  109 + }
  110 + public function groupAdd(){
  111 + if(request()->isPost()){
  112 + $data = input('post.');
  113 + db('user_level')->insert($data);
  114 + $result['msg'] = '会员组添加成功!';
  115 + $result['url'] = url('userGroup');
  116 + $result['code'] = 1;
  117 + return $result;
  118 + }else{
  119 + $this->assign('title',lang('add')."会员组");
  120 + $this->assign('info','null');
  121 + return $this->fetch('groupForm');
  122 + }
  123 + }
  124 + public function groupEdit(){
  125 + if(request()->isPost()) {
  126 + $data = input('post.');
  127 + db('user_level')->update($data);
  128 + $result['msg'] = '会员组修改成功!';
  129 + $result['url'] = url('userGroup');
  130 + $result['code'] = 1;
  131 + return $result;
  132 + }else{
  133 + $map['level_id'] = input('param.level_id');
  134 + $info = db('user_level')->where($map)->find();
  135 + $this->assign('title',lang('edit')."会员组");
  136 + $this->assign('info',json_encode($info,true));
  137 + return $this->fetch('groupForm');
  138 + }
  139 + }
  140 + public function groupDel(){
  141 + $level_id=input('level_id');
  142 + if (empty($level_id)){
  143 + return ['code'=>0,'msg'=>'会员组ID不存在!'];
  144 + }
  145 + db('user_level')->where(array('level_id'=>$level_id))->delete();
  146 + return ['code'=>1,'msg'=>'删除成功!'];
  147 + }
  148 + public function groupOrder(){
  149 + $userLevel=db('user_level');
  150 + $data = input('post.');
  151 + $userLevel->update($data);
  152 + $result['msg'] = '排序更新成功!';
  153 + $result['url'] = url('userGroup');
  154 + $result['code'] = 1;
  155 + return $result;
  156 + }
  157 +
  158 +
  159 +
  160 +
  161 +}
  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +use think\Db;
  5 +use clt\WchatOauth;
  6 +use think\facade\Request;
  7 +class Wechat extends Common{
  8 + private $return = array();
  9 + protected $instance_id;
  10 + /**
  11 + * 微信账户设置
  12 + */
  13 + public function config()
  14 + {
  15 + $info = db('wx_config')->where([ 'key' => 'SHOPWCHAT'])->field('value')->find();
  16 + if (empty($info['value'])) {
  17 + $info= array(
  18 + 'value' => array(
  19 + 'appid' => '',
  20 + 'appsecret' => '',
  21 + 'token' => ''
  22 + ),
  23 + 'is_use' => 1
  24 + );
  25 + } else {
  26 + $info['value'] = json_decode($info['value'], true);
  27 + }
  28 + $wchat_config = $info;
  29 + // 获取当前域名
  30 + $domain_name = Request::domain();
  31 + $url = $domain_name.Request::root();
  32 + // 去除链接的http://头部
  33 + $url_top = substr($url, 7);
  34 + // 去除链接的尾部index.php
  35 + $url_top = str_replace('/index.php', '', $url_top);
  36 + $call_back_url = $domain_name.'/wchat/wchat/relateWeixin';
  37 + $this->assign("url", $url_top);
  38 + $this->assign("call_back_url", $call_back_url);
  39 + $this->assign('wchat_config', $wchat_config["value"]);
  40 + $this->assign('title', '微信账户设置');
  41 + return $this->fetch();
  42 + }
  43 + public function setWechatConfig(){
  44 + $data = input('post.');
  45 + $value['value'] = json_encode($data);
  46 + $value['modify_time'] = time();
  47 + $value['is_use'] = 1;
  48 + db('wx_config')->where([ 'key' => 'SHOPWCHAT'])->update($value);
  49 + return json(['code' => 1, 'msg' => '设置成功!', 'url' => url('config')]);
  50 + }
  51 +
  52 + /**
  53 + *微信菜单
  54 + */
  55 + function getInstanceWchatMenu($instance_id)
  56 + {
  57 + $wx_menu = db('wx_menu');
  58 + $foot_menu = $wx_menu->where(['instance_id'=>$instance_id,'pid'=>0])->order('sort asc')->select();
  59 + if (! empty($foot_menu)) {
  60 + foreach ($foot_menu as $k => $v) {
  61 + $foot_menu[$k]['child'] = '';
  62 + $second_menu = $wx_menu->where(['instance_id'=>$instance_id,'pid'=>$v['menu_id']])->order('sort asc')->select();
  63 + if (! empty($second_menu)) {
  64 + $foot_menu[$k]['child'] = $second_menu;
  65 + $foot_menu[$k]['child_count'] = count($second_menu);
  66 + } else {
  67 + $foot_menu[$k]['child_count'] = 0;
  68 + }
  69 + }
  70 + }
  71 + return $foot_menu;
  72 + }
  73 + public function menu(){
  74 + error_reporting(0);
  75 + $menu_list = $this->getInstanceWchatMenu(0);
  76 + $default_menu_info = array(); // 默认显示菜单
  77 + $menu_list_count = count($menu_list);
  78 + $class_index = count($menu_list);
  79 + if ($class_index > 0) {
  80 + if ($class_index == MAX_MENU_LENGTH) {
  81 + $class_index = MAX_MENU_LENGTH - 1;
  82 + }
  83 + }
  84 + if ($menu_list_count > 0) {
  85 + $default_menu_info = $menu_list[$menu_list_count - 1];
  86 + } else {
  87 + $default_menu_info["menu_name"] = "";
  88 + $default_menu_info["menu_id"] = 0;
  89 + $default_menu_info["child_count"] = 0;
  90 + $default_menu_info["media_id"] = 0;
  91 + $default_menu_info["menu_event_url"] = "";
  92 + $default_menu_info["menu_event_type"] = 1;
  93 + }
  94 + $media_detail = array();
  95 + if ($default_menu_info["media_id"]) {
  96 + // 查询图文消息
  97 + $media_detail = $this->gwmd($default_menu_info["media_id"]);
  98 + $media_detail["item_list_count"] = count($media_detail["item_list"]);
  99 + } else {
  100 + $media_detail["create_time"] = "";
  101 + $media_detail["title"] = "";
  102 + $media_detail["item_list_count"] = 0;
  103 + }
  104 + $default_menu_info["media_list"] = $media_detail;
  105 + $this->assign("wx_name",$this->system['name']);
  106 + $this->assign("pagesize",2);
  107 + $this->assign("menu_list", $menu_list);
  108 + $this->assign("MAX_MENU_LENGTH", MAX_MENU_LENGTH); // 一级菜单数量
  109 + $this->assign("MAX_SUB_MENU_LENGTH", MAX_SUB_MENU_LENGTH); // 二级菜单数量
  110 + $this->assign("menu_list_count", $menu_list_count);
  111 + //dump($default_menu_info);
  112 + $this->assign("default_menu_info", $default_menu_info);
  113 + $this->assign("class_index", $class_index);
  114 + return $this->fetch();
  115 + }
  116 + public function getweixinmediadetail()
  117 + {
  118 + $media_id = input('media_id');
  119 + $res = $this->gwmd($media_id);
  120 + return $res;
  121 + }
  122 +
  123 +
  124 + public function gwmd($media_id)
  125 + {
  126 + $wx_media = db('wx_media');
  127 + $weixin_media_info = $wx_media->find($media_id);
  128 + $weixin_media_info['create_time'] = toDate($weixin_media_info['create_time'],'Y-m-d H:i:s');
  129 + if (! empty($weixin_media_info)) {
  130 + $item_list = db('wx_media_item')->where(['media_id' => $media_id])->select();
  131 + $weixin_media_info['item_list'] = $item_list;
  132 + }
  133 + return $weixin_media_info;
  134 + }
  135 + public function addweixinmenu(){
  136 + $menu = input('menu');
  137 + if (! empty($menu)) {
  138 + $menu = json_decode($menu, true);
  139 + $instance_id = 0;
  140 + $menu_name = $menu["menu_name"]; // 菜单名称
  141 + $ico = ""; // 菜图标单
  142 + $pid = $menu["pid"]; // 父级菜单(一级菜单)
  143 + $menu_event_type = $menu["menu_event_type"]; // '1普通url 2 图文素材 3 功能',
  144 + $menu_event_url = $menu["menu_event_url"]; // '菜单url',
  145 + $media_id = $menu["media_id"]; // '图文消息ID',
  146 + $sort = $menu["sort"]; // 排序
  147 + $res = $this->addwm($instance_id, $menu_name, $ico, $pid, $menu_event_type, $menu_event_url, $media_id, $sort);
  148 + return $res;
  149 + }
  150 + return - 1;
  151 + }
  152 + public function addwm($instance_id, $menu_name, $ico, $pid, $menu_event_type, $menu_event_url, $media_id, $sort)
  153 + {
  154 + $data = array(
  155 + 'instance_id' => $instance_id,
  156 + 'menu_name' => $menu_name,
  157 + 'ico' => $ico,
  158 + 'pid' => $pid,
  159 + 'menu_event_type' => $menu_event_type,
  160 + 'menu_event_url' => $menu_event_url,
  161 + 'media_id' => $media_id,
  162 + 'sort' => $sort,
  163 + 'create_date' => time()
  164 + );
  165 + return db('wx_menu')->insertGetId($data);
  166 + }
  167 + public function updateweixinmenuname()
  168 + {
  169 + $wx_menu = db('wx_menu');
  170 + $data = input('post.');
  171 + if(! empty($data['menu_name'])){
  172 + $retval = $wx_menu->update($data);
  173 + return $retval;
  174 + }
  175 + return -1;
  176 + }
  177 + public function deleteWeixinMenu()
  178 + {
  179 + $menu_id = input('menu_id');
  180 + if (! empty($menu_id)) {
  181 + $res = db('wx_menu')->where("menu_id=$menu_id or pid=$menu_id")->delete();
  182 + return $res;
  183 + }
  184 + return - 1;
  185 + }
  186 + public function updateweixinmenueventtype()
  187 + {
  188 + $data = input('post.');
  189 + if (! empty($data['menu_event_type'])) {
  190 + $retval = db('wx_menu')->update($data);
  191 + return $retval;
  192 + }
  193 + return - 1;
  194 + }
  195 + public function updateweixinmenumessage()
  196 + {
  197 + $menu_event_type = request()->post('menu_event_type', '');
  198 + $menu_id = request()->post('menu_id', '');
  199 + $media_id = request()->post('media_id', '');
  200 + if (! empty($menu_event_type)) {
  201 + $retval =db('wx_menu')->where(['menu_id'=>$menu_id])->update(["media_id" => $media_id, "menu_event_type" => $menu_event_type]);
  202 + return $retval;
  203 + }
  204 + return - 1;
  205 + }
  206 + public function updateweixinmenuurl()
  207 + {
  208 + $data = input('post.');
  209 + if (! empty($data['menu_event_url'])) {
  210 + $retval = db('wx_menu')->update($data);
  211 + return $retval;
  212 + }
  213 + return - 1;
  214 + }
  215 + public function updateweixinmenuSort()
  216 + {
  217 + $menu_id_arr = input('menu_id_arr');
  218 + if (! empty($menu_id_arr)) {
  219 + $weixin_menu = db('wx_menu');
  220 + $menu_id_arr = explode(",", $menu_id_arr);
  221 + $retval = 0;
  222 + foreach ($menu_id_arr as $k => $v) {
  223 + $data = array(
  224 + 'sort' => $k + 1,
  225 + 'modify_date' => time(),
  226 + 'menu_id'=>$v
  227 + );
  228 + $retval += $weixin_menu->update($data);
  229 + }
  230 + return $retval;
  231 + }
  232 + return - 1;
  233 + }
  234 + //ajax 加载 选择素材 弹框数据
  235 + public function onloadMaterial()
  236 + {
  237 + $type = request()->post('type', 0);
  238 + $search_text = request()->post('search_text', '');
  239 + $page =input('page')?input('page'):1;
  240 + $pageSize =input('limit')?input('limit'):config('pageSize');
  241 + $condition = array();
  242 + if ($type != 0) {
  243 + $condition[] = ['type','=',$type];
  244 + }
  245 + $condition[] = array('title','like', '%' . $search_text . '%');
  246 + $wx_media = Db::name('wx_media');
  247 + $list = $wx_media->where($condition)->order('sort')->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  248 + ->toArray();
  249 + if (! empty($list)) {
  250 + foreach ($list['data'] as $k => $v) {
  251 + $item_list = Db::name('wx_media_item')->where(['media_id' => $v['media_id']])->select();
  252 + $list['data'][$k]['item_list'] = $item_list;
  253 + $list['data'][$k]['create_time'] = toDate($v['create_time']);
  254 + }
  255 + }
  256 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  257 + }
  258 + /**
  259 + * 添加 消息
  260 + */
  261 + public function addMedia()
  262 + {
  263 + if (request()->isAjax()) {
  264 + $type = request()->post('type', '');
  265 + $title = request()->post('title', '');
  266 + $content = request()->post('content', '');
  267 + $sort = 0;
  268 +
  269 + $res = $this->addWeixinMedia($title, 0, $type, $sort, $content);
  270 + return $res;
  271 + }
  272 + return view('addMedia');
  273 + }
  274 +
  275 + public function addWeixinMedia($title, $instance_id, $type, $sort, $content)
  276 + {
  277 + $wx_media = db('wx_media');
  278 + $wx_media->startTrans();
  279 + try {
  280 + $data_media = array(
  281 + 'title' => $title,
  282 + 'instance_id' => $instance_id,
  283 + 'type' => $type,
  284 + 'sort' => $sort,
  285 + 'create_time' => time()
  286 + );
  287 + $media_id = $wx_media->insertGetId($data_media);
  288 + if ($type == 1) {
  289 + $this->addWeixinMediaItem($media_id, $title, '', '', '', '', '', '', 0);
  290 + } else if ($type == 2) {
  291 + $info = explode('`|`', $content);
  292 + $this->addWeixinMediaItem($media_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6], 0);
  293 + } else if ($type == 3) {
  294 + $list = explode('`$`', $content);
  295 + foreach ($list as $k => $v) {
  296 + $arr = Array();
  297 + $arr = explode('`|`', $v);
  298 + $this->addWeixinMediaItem($media_id, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], 0);
  299 + }
  300 + }
  301 + $wx_media->commit();
  302 + return ['code'=>1,'message'=>'添加成功!','url'=>url('menu')];
  303 + } catch (\Exception $e) {
  304 + $wx_media->rollback();
  305 + return $e->getMessage();
  306 + }
  307 + // TODO Auto-generated method stub
  308 + }
  309 + public function addWeixinMediaItem($media_id, $title, $author, $cover, $show_cover_pic, $summary, $content, $content_source_url, $sort)
  310 + {
  311 + $weixin_media_item = db('wx_media_item');
  312 + $data = array(
  313 + 'media_id' => $media_id,
  314 + 'title' => $title,
  315 + 'author' => $author,
  316 + 'cover' => $cover,
  317 + 'show_cover_pic' => $show_cover_pic,
  318 + 'summary' => $summary,
  319 + 'content' => $content,
  320 + 'content_source_url' => $content_source_url,
  321 + 'sort' => $sort
  322 + );
  323 + $retval = $weixin_media_item->insert($data);
  324 + return $retval;
  325 + }
  326 + public function upload(){
  327 + // 获取上传文件表单字段名
  328 + $fileKey = array_keys(request()->file());
  329 + // 获取表单上传文件
  330 + $file = request()->file($fileKey['0']);
  331 + // 移动到框架应用根目录/public/uploads/ 目录下
  332 + $info = $file->validate(['ext' => 'jpg,png,gif,jpeg'])->move('uploads');
  333 + if($info){
  334 + $this->return['code'] = 1;
  335 + $this->return['message'] = '图片上传成功!';
  336 + $path=str_replace('\\','/',$info->getSaveName());
  337 + $this->return['data'] = '/uploads/'. $path;
  338 + }else{
  339 + // 上传失败获取错误信息
  340 + $this->return['code'] =0;
  341 + $this->return['message'] = '图片上传失败!';
  342 + $this->return['url'] = '';
  343 + }
  344 + $this->ajaxFileReturn();
  345 + }
  346 + /**
  347 + * 上传文件后,ajax返回信息
  348 + *
  349 + * 2017年6月9日 19:54:46 王永杰
  350 + *
  351 + * @param array $return
  352 + */
  353 + private function ajaxFileReturn()
  354 + {
  355 + if (empty($this->return['code']) || null == $this->return['code'] || "" == $this->return['code']) {
  356 + $this->return['code'] = 0; // 错误码
  357 + }
  358 +
  359 + if (empty($this->return['message']) || null == $this->return['message'] || "" == $this->return['message']) {
  360 + $this->return['message'] = ""; // 消息
  361 + }
  362 +
  363 + if (empty($this->return['data']) || null == $this->return['data'] || "" == $this->return['data']) {
  364 + $this->return['data'] = ""; // 数据
  365 + }
  366 + echo json_encode($this->return);
  367 + //return json_encode($this->return);
  368 + }
  369 + public function materialmessage()
  370 + {
  371 + if (request()->isAjax()) {
  372 + $type = request()->post('type', 0);
  373 + $search_text = request()->post('search_text', '');
  374 + $page =input('page',1);
  375 + $pageSize =input('limit',config('pageSize'));
  376 + $condition = array();
  377 + if ($type != 0) {
  378 + $condition[] = ['type','=',$type];
  379 + }
  380 + $condition[] = array('title','like', '%' . $search_text . '%');
  381 +
  382 + $condition = array_filter($condition);
  383 + $list = db('wx_media')->where($condition)->order('create_time desc')
  384 + ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
  385 + ->toArray();
  386 + if (! empty($list)) {
  387 + foreach ($list['data'] as $k => $v) {
  388 + $item_list = db('wx_media_item')->where(['media_id'=>$v['media_id']])->column('title');
  389 + $list['data'][$k]['item_list'] = $item_list;
  390 + $list['data'][$k]['create_time'] = toDate($v['create_time']);
  391 + }
  392 + }
  393 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  394 + }
  395 + $type = input('param.type',0);
  396 + $child_menu_list = array(
  397 + array(
  398 + 'url' => url('materialmessage'),
  399 + 'menu_name' => "全部",
  400 + "active" => $type == 0 ? 1 : 0
  401 + ),
  402 + array(
  403 + 'url' => url('materialmessage',['type'=>1]),
  404 + 'menu_name' => "文本",
  405 + "active" => $type == 1 ? 1 : 0
  406 + ),
  407 + array(
  408 + 'url' => url('materialmessage',['type'=>2]),
  409 + 'menu_name' => "单图文",
  410 + "active" => $type == 2 ? 1 : 0
  411 + ),
  412 + array(
  413 + 'url' => url('materialmessage',['type'=>3]),
  414 + 'menu_name' => "多图文",
  415 + "active" => $type == 3 ? 1 : 0
  416 + )
  417 + );
  418 +
  419 + $this->assign('type', $type);
  420 + $this->assign('child_menu_list', $child_menu_list);
  421 + return view('materialmessage');
  422 + }
  423 + public function updatemedia(){
  424 + if (request()->isAjax()) {
  425 + $media_id = request()->post('media_id', 0);
  426 + $type = request()->post('type', '');
  427 + $title = request()->post('title', '');
  428 + $content = request()->post('content', '');
  429 + $sort = 0;
  430 + $res = $this->updateWeixinMedia($media_id, $title, 0, $type, $sort, $content);
  431 + return json($res);
  432 + }
  433 + $media_id = input('media_id', 0);
  434 + $weixin_media = db('wx_media');
  435 + $weixin_media_info = $weixin_media->where(['media_id'=>$media_id])->find();
  436 + if (! empty($weixin_media_info)) {
  437 + $weixin_media_item = db('wx_media_item');
  438 + $item_list = $weixin_media_item->where(['media_id' => $media_id])->select();
  439 + $weixin_media_info['item_list'] = $item_list;
  440 + }
  441 + $this->assign('info', $weixin_media_info);
  442 + return view();
  443 + }
  444 + public function updateWeixinMedia($media_id, $title, $instance_id, $type, $sort, $content)
  445 + {
  446 + $weixin_media = db('wx_media');
  447 + $weixin_media->startTrans();
  448 + try {
  449 + // 先修改 图文消息表
  450 + $data_media = array(
  451 + 'title' => $title,
  452 + 'instance_id' => $instance_id,
  453 + 'type' => $type,
  454 + 'sort' => $sort,
  455 + 'create_time' => time()
  456 + );
  457 + $weixin_media->where(['media_id' => $media_id])->update($data_media);
  458 + // 修改 图文消息内容的时候 先删除了图文消息内容再添加一次
  459 + $weixin_media_item = db('wx_media_item');
  460 + $weixin_media_item->where(['media_id'=>$media_id])->delete();
  461 + if ($type == 1) {
  462 + $this->addWeixinMediaItem($media_id, $title, '', '', '', '', '', '', 0);
  463 + } else if ($type == 2) {
  464 + $info = explode('`|`', $content);
  465 + $this->addWeixinMediaItem($media_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6], 0);
  466 + } else if ($type == 3) {
  467 + $list = explode('`$`', $content);
  468 + foreach ($list as $k => $v) {
  469 + $arr = Array();
  470 + $arr = explode('`|`', $v);
  471 + $this->addWeixinMediaItem($media_id, $arr[0], $arr[1], $arr[2], $arr[3], $arr[4], $arr[5], $arr[6], 0);
  472 + }
  473 + }
  474 + $weixin_media->commit();
  475 + return ['code'=>1,'message'=>'修改成功!'];
  476 + } catch (\Exception $e) {
  477 + $weixin_media->rollback();
  478 + return $e->getMessage();
  479 + }
  480 + }
  481 + public function deleteweixinmediadetail(){
  482 + $id = input('id', '');
  483 + $res = 0;
  484 + if (! empty($id)) {
  485 + $weixin_media_item = db('wx_media_item');
  486 + $res = $weixin_media_item->where("id=$id")->delete();
  487 + return $res;
  488 + }
  489 + return $res;
  490 + }
  491 + public function updatemenutoweixin(){
  492 + $this->instance_id=0;
  493 + $result = $this->updateInstanceMenuToWeixin($this->instance_id);
  494 + $auth_info = $this->getInstanceWchatConfig($this->instance_id);
  495 + $res='';
  496 + if (! empty($auth_info['value']['appid']) && ! empty($auth_info['value']['appsecret'])) {
  497 + $wchat_auth = new WchatOauth();
  498 + $res = $wchat_auth->menu_create($result);
  499 + if (! empty($res)) {
  500 + $res = json_decode($res, true);
  501 + if ($res['errcode'] == 0) {
  502 + $retval = 1;
  503 + } else {
  504 + $retval = $res['errmsg'];
  505 + }
  506 + } else {
  507 + $retval = 0;
  508 + }
  509 + } else {
  510 + $retval = "当前未配置微信授权";
  511 + }
  512 + return ['code' => $retval,'wxcode'=>$res['errcode'], 'message' => '操作成功'];
  513 + }
  514 +
  515 + public function getInstanceWchatConfig($instance_id)
  516 + {
  517 + $info = db('wx_config')->where(['key' => 'SHOPWCHAT', 'instance_id' => $instance_id])->field('value')->find();
  518 + if (empty($info['value'])) {
  519 + return array(
  520 + 'value' => array(
  521 + 'appid' => '',
  522 + 'appsecret' => ''
  523 + ),
  524 + 'is_use' => 1
  525 + );
  526 + } else {
  527 + $info['value'] = json_decode($info['value'], true);
  528 + return $info;
  529 + }
  530 + }
  531 + public function updateInstanceMenuToWeixin($instance_id)
  532 + {
  533 + $menu = array();
  534 + $menu_list = $this->getInstanceWchatMenu($instance_id);
  535 + if (! empty($menu_list)) {
  536 +
  537 + foreach ($menu_list as $k => $v) {
  538 + if (! empty($v)) {
  539 + $menu_item = array(
  540 + 'name' => ''
  541 + );
  542 + $menu_item['name'] = $v['menu_name'];
  543 + if (! empty($v['child'])) {
  544 +
  545 + foreach ($v['child'] as $k_child => $v_child) {
  546 + if (! empty($v_child)) {
  547 + $sub_menu = array();
  548 + $sub_menu['name'] = $v_child['menu_name'];
  549 + if ($v_child['menu_event_type'] == 1) {
  550 + $sub_menu['type'] = 'view';
  551 + $sub_menu['url'] = $v_child['menu_event_url'];
  552 + } else {
  553 + $sub_menu['type'] = 'click';
  554 + $sub_menu['key'] = $v_child['menu_id'];
  555 + }
  556 +
  557 + $menu_item['sub_button'][] = $sub_menu;
  558 + }
  559 + }
  560 + } else {
  561 + if ($v['menu_event_type'] == 1) {
  562 + $menu_item['type'] = 'view';
  563 + $menu_item['url'] = $v['menu_event_url'];
  564 + } else {
  565 + $menu_item['type'] = 'click';
  566 + $menu_item['key'] = $v['menu_id'];
  567 + }
  568 + }
  569 + $menu[] = $menu_item;
  570 + }
  571 + }
  572 + }
  573 + $menu_array = array();
  574 + $menu_array['button'] = array();
  575 + foreach ($menu as $k => $v) {
  576 + $menu_array['button'][] = $v;
  577 + }
  578 + $menu_array = json_encode($menu_array,JSON_UNESCAPED_UNICODE);
  579 + return $menu_array;
  580 + }
  581 +
  582 + /*******************************回复设置********************************/
  583 + /**
  584 + * 关键字 回复
  585 + */
  586 + public function keyReplayList()
  587 + {
  588 + $page =input('page')?input('page'):1;
  589 + $pageSize =input('limit')?input('limit'):config('pageSize');
  590 + $list = db('wx_key_replay')->order('sort')->paginate(array('list_rows'=>$pageSize,'page'=>$page))->toArray();
  591 + if (! empty($list)) {
  592 + foreach ($list['data'] as $k => $v) {
  593 +
  594 + $list['data'][$k]['match_type'] = $v['match_type']==2?'全部匹配':'模糊匹配';
  595 + $list['data'][$k]['create_time'] = toDate($v['create_time']);
  596 + }
  597 + }
  598 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
  599 + }
  600 +
  601 +
  602 + public function replay(){
  603 + $type = input('type', 1);
  604 + $child_menu_list = array(
  605 + array(
  606 + 'url' => url('replay',['type'=>1]),
  607 + 'menu_name' => "关注时回复",
  608 + "active" => $type == 1 ? 1 : 0
  609 + ),
  610 + array(
  611 + 'url' => url('replay',['type'=>2]),
  612 + 'menu_name' => "关键字回复",
  613 + "active" => $type == 2 ? 1 : 0
  614 + ),
  615 + array(
  616 + 'url' => url('replay',['type'=>3]),
  617 + 'menu_name' => "默认回复",
  618 + "active" => $type == 3 ? 1 : 0
  619 + )
  620 + );
  621 + $this->assign('child_menu_list', $child_menu_list);
  622 + $this->assign('type', $type);
  623 + if ($type == 1) {
  624 + $info = db('wxFollowReplay')->where(['instance_id' => 0])->find();
  625 + if ($info['reply_media_id'] > 0) {
  626 + $weixin_media_info = db('wx_media')->where(['media_id'=>$info['reply_media_id']])->find();
  627 + if (! empty($weixin_media_info)) {
  628 + $item_list = db('wx_media_item')->where(['media_id'=>$info['reply_media_id']])->select();
  629 + $weixin_media_info['item_list'] = $item_list;
  630 + }
  631 + $info['media_info'] = $weixin_media_info;
  632 + }
  633 + $this->assign('info', $info);
  634 + } else if ($type == 2) {
  635 + } else if ($type == 3) {
  636 + $info = db('wx_default_replay')->where(['instance_id' => 0])->find();
  637 + if ($info['reply_media_id'] > 0) {
  638 + $weixin_media_info = db('wx_media')->where(['media_id' => $info['reply_media_id']])->find();
  639 + if (!empty($weixin_media_info)) {
  640 + $item_list = db('wx_media_item')->where(['media_id' => $info['reply_media_id']])->select();
  641 + $weixin_media_info['item_list'] = $item_list;
  642 + }
  643 + $info['media_info'] = $weixin_media_info;
  644 + }
  645 + $this->assign('info', $info);
  646 + }
  647 + return view();
  648 + }
  649 + /**
  650 + * 添加 或 修改 关注时回复
  651 + */
  652 + public function addorupdatefollowreply()
  653 + {
  654 + $id = input('id',0);
  655 + $replay_media_id = input('media_id', 0);
  656 + if($id==0){
  657 + if ($replay_media_id > 0) {
  658 + $res = $this->addFollowReplay(0, $replay_media_id, 0);
  659 + } else {
  660 + return ['code'=>0,'msg'=>'添加失败'];
  661 + }
  662 + }else{
  663 + if ($replay_media_id > 0) {
  664 + $res = $this->updateFollowReplay($id, 0, $replay_media_id, 0);
  665 + } else {
  666 + return ['code'=>0,'msg'=>'修改失败'];
  667 + }
  668 + }
  669 + return $res;
  670 + }
  671 + public function addFollowReplay($instance_id, $replay_media_id, $sort)
  672 + {
  673 + $data = array(
  674 + 'instance_id' => $instance_id,
  675 + 'reply_media_id' => $replay_media_id,
  676 + 'sort' => $sort,
  677 + 'create_time' => time()
  678 + );
  679 + $id = db('wx_follow_replay')->insertGetId($data);
  680 + if($id){
  681 + return ['code'=>$id,'msg'=>'添加成功'];
  682 + }else{
  683 + return ['code'=>0,'msg'=>'添加失败'];
  684 + }
  685 +
  686 + }
  687 + public function updateFollowReplay($id, $instance_id, $replay_media_id, $sort)
  688 + {
  689 + $data = array(
  690 + 'instance_id' => $instance_id,
  691 + 'reply_media_id' => $replay_media_id,
  692 + 'sort' => $sort,
  693 + 'modify_time' => time()
  694 + );
  695 + if(db('wx_follow_replay')->where(['id' => $id])->update($data)!==false){
  696 + return ['code'=>1,'msg'=>'修改成功'];
  697 + }else{
  698 + return ['code'=>0,'msg'=>'修改失败'];
  699 + }
  700 + }
  701 + /**
  702 + * 删除 回复
  703 + * @return unknown[]
  704 + */
  705 + public function delReply()
  706 + {
  707 + $type = request()->post('type', '');
  708 + if ($type == '') {
  709 + return ['code'=>0];
  710 + } else {
  711 + if ($type == 1) {
  712 + db('wx_follow_replay')->where(['instance_id'=>0])->delete();
  713 + return ['code'=>1,'msg'=>'删除成功!','url'=>url('replay',['type'=>1])];
  714 + } else if ($type == 3) {
  715 + // 删除 默认回复
  716 + db('wx_default_replay')->where(['instance_id'=>0])->delete();
  717 + return ['code'=>1,'msg'=>'删除成功!','url'=>url('replay',['type'=>3])];
  718 + }
  719 + }
  720 + }
  721 + /**
  722 + * 添加 或 修改 默认回复
  723 + */
  724 + public function addOrUpdateDefaultReply()
  725 + {
  726 + $id = input('id',0);
  727 + $replay_media_id = input('media_id', 0);
  728 + if ($id == 0) {
  729 + if ($replay_media_id > 0) {
  730 + $res = $this->addDefaultReplay(0, $replay_media_id, 0);
  731 + } else {
  732 + return ['code'=>0,'msg'=>'添加失败'];
  733 + }
  734 + } else{
  735 + if ($replay_media_id > 0) {
  736 + $res = $this->updateDefaultReplay($id, 0, $replay_media_id, 0);
  737 + } else {
  738 + return ['code'=>0,'msg'=>'修改失败'];
  739 + }
  740 + }
  741 + return $res;
  742 + }
  743 + public function updateDefaultReplay($id, $instance_id, $replay_media_id, $sort)
  744 + {
  745 + $data = array(
  746 + 'instance_id' => $instance_id,
  747 + 'reply_media_id' => $replay_media_id,
  748 + 'sort' => $sort,
  749 + 'modify_time' => time()
  750 + );
  751 + if(db('wx_default_replay')->where(['id' => $id])->update($data)!==false){
  752 + return ['code'=>1,'msg'=>'修改成功'];
  753 + }else{
  754 + return ['code'=>0,'msg'=>'修改失败'];
  755 + }
  756 + }
  757 + public function addDefaultReplay($instance_id, $replay_media_id, $sort)
  758 + {
  759 + $data = array(
  760 + 'instance_id' => $instance_id,
  761 + 'reply_media_id' => $replay_media_id,
  762 + 'sort' => $sort,
  763 + 'create_time' => time()
  764 + );
  765 + $id = db('wx_default_replay')->insertGetId($data);
  766 + if($id){
  767 + return ['code'=>$id,'msg'=>'添加成功'];
  768 + }else{
  769 + return ['code'=>0,'msg'=>'添加失败'];
  770 + }
  771 + }
  772 +
  773 + /**
  774 + * 添加 或 修改 关键字 回复
  775 + */
  776 + public function addorupdatekeyreplay()
  777 + {
  778 + if (request()->isAjax()) {
  779 + $id = input('id');
  780 + $key = input('key', '');
  781 + $match_type = input('match_type', 1);
  782 + $replay_media_id = input('media_id', 0);
  783 + $sort = 0;
  784 + if ($id > 0) {
  785 + $res = $this->updateKeyReplay($id, 0, $key, $match_type, $replay_media_id, $sort);
  786 + }else{
  787 + $res = $this->addKeyReplay(0, $key, $match_type, $replay_media_id, $sort);
  788 + }
  789 + return $res;
  790 + }
  791 + $id = input('id',0);
  792 + $this->assign('id', $id);
  793 + $info = array(
  794 + 'key' => '',
  795 + 'match_type' => 1,
  796 + 'reply_media_id' => 0,
  797 + 'madie_info' => array()
  798 + );
  799 + if ($id > 0) {
  800 + $info = Db::name('wx_key_replay')->where('id',$id)->find();
  801 + if ($info['reply_media_id'] > 0) {
  802 + $weixin_media_info = Db::name('wx_media')->where('media_id',$info['reply_media_id'])->find();
  803 + if (! empty($weixin_media_info)) {
  804 + $item_list = Db::name('wx_media_item')->where('media_id' ,$info['reply_media_id'])->select();
  805 + $weixin_media_info['item_list'] = $item_list;
  806 + }
  807 + $info['media_info'] = $weixin_media_info;
  808 + }
  809 + }
  810 + $secend_menu['module_name'] = "编辑回复";
  811 + $this->assign("title", "编辑回复");
  812 + $child_menu_list = array(
  813 + array(
  814 + 'url' => "Wchat/addOrUpdateKeyReplay.html?id=" . $id,
  815 + 'menu_name' => "编辑回复",
  816 + "active" => 1
  817 + )
  818 + );
  819 + if (! empty($id)) {
  820 + $this->assign("secend_menu", $secend_menu);
  821 + $this->assign('child_menu_list', $child_menu_list);
  822 + }
  823 + $this->assign('info', $info);
  824 + return view();
  825 + }
  826 + public function updateKeyReplay($id, $instance_id, $key, $match_type, $replay_media_id, $sort)
  827 + {
  828 + $data = array(
  829 + 'instance_id' => $instance_id,
  830 + 'key' => $key,
  831 + 'match_type' => $match_type,
  832 + 'reply_media_id' => $replay_media_id,
  833 + 'sort' => $sort,
  834 + 'create_time' => time()
  835 + );
  836 + if(db('wx_key_replay')->where('id' , $id)->update($data)!==false){
  837 + return ['code'=>1,'msg'=>'修改成功'];
  838 + }else{
  839 + return ['code'=>0,'msg'=>'修改失败'];
  840 + }
  841 + }
  842 + public function addKeyReplay($instance_id, $key, $match_type, $replay_media_id, $sort)
  843 + {
  844 + $data = array(
  845 + 'instance_id' => $instance_id,
  846 + 'key' => $key,
  847 + 'match_type' => $match_type,
  848 + 'reply_media_id' => $replay_media_id,
  849 + 'sort' => $sort,
  850 + 'create_time' => time()
  851 + );
  852 + $id = db('wx_key_replay')->insertGetId($data);
  853 + if($id){
  854 + return ['code'=>$id,'msg'=>'添加成功'];
  855 + }else{
  856 + return ['code'=>0,'msg'=>'添加失败'];
  857 + }
  858 + }
  859 + /**
  860 + * 删除图文消息
  861 + *
  862 + * @return number
  863 + */
  864 + public function deleteWeixinMedia(){
  865 + $media_id = input('media_id', '');
  866 + db('wx_media')->where(['media_id'=>$media_id])->delete();
  867 + return ['code'=>1,'msg'=>'删除成功'];
  868 + }
  869 + /**
  870 + * 删除 回复
  871 + *
  872 + * @return unknown[]
  873 + */
  874 + public function delKeyReply()
  875 + {
  876 + $id = input('id');
  877 + db('wx_key_replay')->where(['id'=>$id])->delete();
  878 + return ['code'=>1,'msg'=>'删除成功'];
  879 +
  880 + }
  881 +}
  1 +<?php
  2 +return [
  3 + 'hello' => '欢迎使用CLTPHP',
  4 + 'adminInfo' => '个人信息',
  5 + 'logout' =>'注销',
  6 + 'home' =>'浏览网站',
  7 + 'clearCache' =>'清除缓存',
  8 +
  9 + 'pleaseEnter' =>'请输入',
  10 + 'systemInfo' =>'系统信息',
  11 + 'system' =>'系统',
  12 + 'systemSet' =>'系统设置',
  13 + 'websiteName' =>'网站名称',
  14 + 'WebsiteUrl' =>'网站地址',
  15 + 'seoTitle' =>'SEO标题',
  16 + 'seoKeyword' =>'SEO关键字',
  17 + 'description' =>'SEO描述',
  18 + 'recordNum' =>'备案号',
  19 + 'companyAddress' =>'公司地址',
  20 +
  21 + 'admin'=>'管理员',
  22 + 'module'=>'模型',
  23 +
  24 + 'user'=>'会员',
  25 + 'nickname'=>'昵称',
  26 + 'man'=>'男',
  27 + 'woman'=>'女',
  28 +
  29 + 'message'=>'留言',
  30 + 'link'=>'链接',
  31 + 'ad'=>'广告',
  32 +
  33 + 'back'=>'返回',
  34 + 'submit'=>'提交',
  35 + 'reset'=>'重置',
  36 + 'open'=>'开启',
  37 + 'enabled'=>'已开启',
  38 + 'close'=>'关闭',
  39 + 'disabled'=>'已禁用',
  40 + 'yes'=>'是',
  41 + 'no'=>'否',
  42 + 'edit'=>'编辑',
  43 + 'del'=>'删除',
  44 + 'add'=>'添加',
  45 + 'list'=>'列表',
  46 + 'field'=>'字段',
  47 + 'search'=>'搜索',
  48 + 'debris'=>'碎片',
  49 + 'hit'=>'点击',
  50 +
  51 + 'name'=>'名称',
  52 + 'table'=>'表名',
  53 + 'detail'=>'详述',
  54 + 'username'=>'用户名',
  55 + 'userGroup'=>'用户组',
  56 +
  57 + 'pwd'=>'密码',
  58 + 'email'=>'邮箱账号',
  59 + 'tel'=>'联系电话',
  60 + 'sex'=>'性别',
  61 + 'qq'=>'QQ',
  62 + 'status'=>'状态',
  63 + 'ip'=>'IP地址',
  64 + 'action'=>'操作',
  65 + 'icon'=>'图标',
  66 + 'order'=>'排序',
  67 + 'id'=>'编号',
  68 + 'address'=>'地址',
  69 + 'content'=>'内容',
  70 + 'time'=>'时间',
  71 + 'title'=>'标题',
  72 +
  73 +
  74 + 'Super administrator cannot be deleted'=>'超级管理员不可删除!',
  75 + 'Are you sure you want to delete it'=>'你确定要删除吗?'
  76 +
  77 +
  78 +];
  1 +<?php
  2 +namespace app\admin\model;
  3 +use think\Model;
  4 +use think\Db;
  5 +class Admin extends Model
  6 +{
  7 + protected $pk = 'admin_id';
  8 + public function login($data,$code){
  9 + if($code=='open'){
  10 + if(!$this->check($data['vercode'])){
  11 + return ['code' => 0, 'msg' => '验证码错误'];
  12 + }
  13 + }
  14 + $user=Db::name('admin')->where('username',$data['username'])->find();
  15 + if($user) {
  16 + if ($user['is_open']==1 && $user['pwd'] == md5($data['password'])){
  17 + session('username', $user['username']);
  18 + session('aid', $user['admin_id']);
  19 + $avatar = $user['avatar'] == '' ? '/static/admin/images/0.jpg' : $user['avatar'];
  20 + session('avatar', $avatar);
  21 + return ['code' => 1, 'msg' => '登录成功!']; //信息正确
  22 + }else{
  23 + return ['code' => 0, 'msg' => '用户名或者密码错误,重新输入!']; //密码错误
  24 + }
  25 + }else{
  26 + return ['code' => 0, 'msg' => '用户不存在!']; //用户不存在
  27 + }
  28 + }
  29 + public function getInfo($admin_id){
  30 + $info = Db::name('admin')->field('pwd',true)->find($admin_id);
  31 + return $info;
  32 + }
  33 + public function check($code){
  34 + return captcha_check($code);
  35 + }
  36 +
  37 +}
  38 +
  1 +<?php
  2 +namespace app\admin\model;
  3 +use think\Model;
  4 +class AuthGroup extends Model
  5 +{
  6 + protected $type = [
  7 + // 设置addtime为时间戳类型(整型)
  8 + 'addtime' => 'timestamp:Y-m-d H:i:s',
  9 + ];
  10 +}
  1 +<?php
  2 +namespace app\admin\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class System extends Model
  7 +{
  8 + protected $name = 'system';
  9 +
  10 +}
  1 +<?php
  2 +namespace app\admin\model;
  3 +
  4 +use think\Model;
  5 +
  6 +class Users extends Model
  7 +{
  8 + protected $name = 'users';
  9 + protected $type = [
  10 + // 设置addtime为时间戳类型(整型)
  11 + 'reg_time' => 'timestamp:Y-m-d H:i:s',
  12 + ];
  13 + // birthday修改器
  14 + protected function setpwdAttr($value){
  15 + return md5($value);
  16 + }
  17 +
  18 +}
  1 +<?php
  2 +namespace app\admin\model;
  3 +use think\Model;
  4 +class authRule extends Model
  5 +{
  6 +
  7 +}
  1 +<?php
  2 +namespace app\admin\validate;
  3 +
  4 +use think\Validate;
  5 +
  6 +class Admin extends Validate
  7 +{
  8 + protected $rule = [
  9 + 'username' => 'require|length:3,25',
  10 + 'email' =>'email'
  11 + ];
  12 + protected $message = [
  13 + 'username.require' => '用户名不能为空',
  14 + 'username.length' => '用户名在3到25个字符之间',
  15 + 'email.email' => '邮箱格式不正确',
  16 + ];
  17 +}
  1 +<?php
  2 +namespace app\admin\validate;
  3 +
  4 +use think\Validate;
  5 +
  6 +class Member extends Validate
  7 +{
  8 + protected $rule = [
  9 + ['group_id', 'require', '会员所属用户组必须选择'],
  10 + ['username', 'require', '用户名不能为空'],
  11 + ['pwd', 'require|length:6,25', '登录密码不能为空|登录密码位数不能少于6位或者大于15位'],
  12 + ['petname', 'require', '昵称不能为空'],
  13 + ['tel', 'checkName:tel|unique:member', '手机号码格式不正确|该手机已注册'],
  14 + ['email', 'email|unique:member', '邮箱格式不正确|该邮箱已注册'],
  15 + ];
  16 + // 自定义验证规则
  17 + protected function checkName($value,$rule,$data){
  18 + if(is_mobile_phone($value)){
  19 + return true;
  20 + }else{
  21 + return '手机号码格式不正确';
  22 + }
  23 + }
  24 +}
  1 +<?php
  2 +namespace app\admin\validate;
  3 +
  4 +use think\Validate;
  5 +
  6 +class Sys extends Validate
  7 +{
  8 + protected $rule = [
  9 + ['sys_name', 'require', '站点名称不能为空!'],
  10 + ['sys_url', 'require', '站点网址不能为空!']
  11 + ];
  12 +}
  1 +{include file="common/head"/}
  2 +<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
  3 + <fieldset class="layui-elem-field layui-field-title">
  4 + <legend>{$title}</legend>
  5 + </fieldset>
  6 + <form class="layui-form layui-form-pane">
  7 + <div class="layui-form-item">
  8 + <label class="layui-form-label">所属位置</label>
  9 + <div class="layui-input-4">
  10 + <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">
  11 + <option value="">请选择所属广告位</option>
  12 + </select>
  13 + </div>
  14 + </div>
  15 + <div class="layui-form-item">
  16 + <label class="layui-form-label">广告名称</label>
  17 + <div class="layui-input-4">
  18 + <input type="text" name="name" ng-model="field.name" lay-verify="required" placeholder="{:lang('pleaseEnter')}广告名称" class="layui-input">
  19 + </div>
  20 + </div>
  21 + <div class="layui-form-item">
  22 + <label class="layui-form-label">广告图片</label>
  23 + <input type="hidden" name="pic" id="pic" value="{{field.pic}}">
  24 + <div class="layui-input-block">
  25 + <div class="layui-upload">
  26 + <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
  27 + <div class="layui-upload-list">
  28 + <img class="layui-upload-img" id="adPic">
  29 + <p id="demoText"></p>
  30 + </div>
  31 + </div>
  32 + </div>
  33 + </div>
  34 + <div class="layui-form-item">
  35 + <label class="layui-form-label">{:lang('ad')}URL</label>
  36 + <div class="layui-input-4">
  37 + <input type="text" name="url" ng-model="field.url" lay-verify="url" placeholder="{:lang('pleaseEnter')}{:lang('ad')}URL" class="layui-input">
  38 + </div>
  39 + </div>
  40 + <div class="layui-form-item">
  41 + <label class="layui-form-label">是否审核</label>
  42 + <div class="layui-input-block">
  43 + <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==1" ng-value="1" title="{:lang('open')}">
  44 + <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==0" ng-value="0" title="{:lang('close')}">
  45 + </div>
  46 + </div>
  47 + <div class="layui-form-item">
  48 + <label class="layui-form-label">{:lang('order')}</label>
  49 + <div class="layui-input-4">
  50 + <input type="text" name="sort" ng-model="field.sort" value="" placeholder="从小到大排序" class="layui-input">
  51 + </div>
  52 + </div>
  53 + <div class="layui-form-item layui-form-text">
  54 + <label class="layui-form-label">内容</label>
  55 + <div class="layui-input-block">
  56 + <textarea ng-model="field.content" placeholder="请输广告内容" name="content" class="layui-textarea"></textarea>
  57 + </div>
  58 + </div>
  59 + <div class="layui-form-item">
  60 + <div class="layui-input-block">
  61 + <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
  62 + <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
  63 + </div>
  64 + </div>
  65 + </form>
  66 +</div>
  67 +{include file="common/foot"/}
  68 +<script src="/static/common/js/angular.min.js"></script>
  69 +<script>
  70 + var m = angular.module('hd',[]);
  71 + m.controller('ctrl',['$scope',function($scope) {
  72 + $scope.field = '{$info|raw}'!='null'?{$info|raw}:{type_id:'',ad_id:'',name:'',url:'',open:1,sort:50,pic:'',content:''};
  73 + $scope.group = {$adtypeList|raw};
  74 + $scope.selected = {$selected|raw};
  75 + layui.use(['form', 'layer','upload'], function () {
  76 + var form = layui.form, $ = layui.jquery, upload = layui.upload;
  77 + if($scope.field.pic){
  78 + adPic.src = $scope.field.pic;
  79 + }
  80 + form.on('submit(submit)', function (data) {
  81 + // 提交到方法 默认为本身
  82 + data.field.ad_id = $scope.field.ad_id;
  83 + var loading = layer.load(1, {shade: [0.1, '#fff']});
  84 + $.post("", data.field, function (res) {
  85 + layer.close(loading);
  86 + if (res.code > 0) {
  87 + layer.msg(res.msg, {time: 1800, icon: 1}, function () {
  88 + location.href = res.url;
  89 + });
  90 + } else {
  91 + layer.msg(res.msg, {time: 1800, icon: 2});
  92 + }
  93 + });
  94 + });
  95 + //普通图片上传
  96 + var uploadInst = upload.render({
  97 + elem: '#adBtn'
  98 + ,url: '{:url("UpFiles/upload")}'
  99 + ,before: function(obj){
  100 + //预读本地文件示例,不支持ie8
  101 + obj.preview(function(index, file, result){
  102 + $('#adPic').attr('src', result); //图片链接(base64)
  103 + });
  104 + },
  105 + done: function(res){
  106 + if(res.code>0){
  107 + $('#pic').val(res.url);
  108 + }else{
  109 + //如果上传失败
  110 + return layer.msg('上传失败');
  111 + }
  112 + }
  113 + ,error: function(){
  114 + //演示失败状态,并实现重传
  115 + var demoText = $('#demoText');
  116 + demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
  117 + demoText.find('.demo-reload').on('click', function(){
  118 + uploadInst.upload();
  119 + });
  120 + }
  121 + });
  122 + });
  123 + }]);
  124 +</script>
  1 +{include file="common/head"/}
  2 +<div class="admin-main layui-anim layui-anim-upbit">
  3 + <fieldset class="layui-elem-field layui-field-title">
  4 + <legend>{:lang('ad')}管理</legend>
  5 + </fieldset>
  6 + <div class="demoTable">
  7 + <div class="layui-inline">
  8 + <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
  9 + </div>
  10 + <button class="layui-btn" id="search" data-type="reload">{:lang('search')}</button>
  11 + <a href="{:url('index')}" class="layui-btn">显示全部</a>
  12 + <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
  13 + <a href="{:url('add')}" class="layui-btn" style="float:right;"><i class="fa fa-plus" aria-hidden="true"></i>{:lang('add')}{:lang('ad')}</a>
  14 + <div style="clear: both;"></div>
  15 + </div>
  16 + <table class="layui-table" id="list" lay-filter="list"></table>
  17 +</div>
  18 +{include file="common/foot"/}
  19 +<script type="text/html" id="name">
  20 + {{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();">{{# } }}
  21 +</script>
  22 +<script type="text/html" id="order">
  23 + <input name="{{d.ad_id}}" data-id="{{d.ad_id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
  24 +</script>
  25 +<script type="text/html" id="open">
  26 + <input type="checkbox" name="open" value="{{d.ad_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
  27 +</script>
  28 +<script type="text/html" id="action">
  29 + <a href="{:url('edit')}?ad_id={{d.ad_id}}" class="layui-btn layui-btn-xs">编辑</a>
  30 + <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  31 +</script>
  32 +<script>
  33 + layui.use(['table','form'], function() {
  34 + var table = layui.table,form = layui.form,$ = layui.jquery;
  35 + var tableIn = table.render({
  36 + id: 'ad',
  37 + elem: '#list',
  38 + url: '{:url("index")}',
  39 + method: 'post',
  40 + page:true,
  41 + cols: [[
  42 + {checkbox: true, fixed: true},
  43 + {field: 'ad_id', title: '{:lang("id")}', width: 80, fixed: true},
  44 + {field: 'name', title: '广告名称', width: 400,templet: '#name'},
  45 + {field: 'typename', title: '所属位置', width: 160},
  46 + {field: 'addtime', title: '{:lang("add")}{:lang("time")}',width: 150},
  47 + {field: 'sort', align: 'center', title: '{:lang("order")}', width: 120, templet: '#order'},
  48 + {field: 'open', align: 'center', title: '{:lang("status")}', width: 100, toolbar: '#open'},
  49 + {width: 160, align: 'center', toolbar: '#action'}
  50 + ]],
  51 + limit:10
  52 + });
  53 + form.on('switch(open)', function(obj){
  54 + loading =layer.load(1, {shade: [0.1,'#fff']});
  55 + var id = this.value;
  56 + var open = obj.elem.checked===true?1:0;
  57 + $.post('{:url("editState")}',{'id':id,'open':open},function (res) {
  58 + layer.close(loading);
  59 + if (res.status==1) {
  60 + tableIn.reload();
  61 + }else{
  62 + layer.msg(res.msg,{time:1000,icon:2});
  63 + return false;
  64 + }
  65 + })
  66 + });
  67 + //搜索
  68 + $('#search').on('click', function () {
  69 + var key = $('#key').val();
  70 + if ($.trim(key) === '') {
  71 + layer.msg('{:lang("pleaseEnter")}关键字!', {icon: 0});
  72 + return;
  73 + }
  74 + tableIn.reload({ page: {page: 1}, where: {key: key}});
  75 + });
  76 + table.on('tool(list)', function(obj) {
  77 + var data = obj.data;
  78 + if (obj.event === 'del'){
  79 + layer.confirm('您确定要删除该广告吗?', function(index){
  80 + var loading = layer.load(1, {shade: [0.1, '#fff']});
  81 + $.post("{:url('del')}",{ad_id:data.ad_id},function(res){
  82 + layer.close(loading);
  83 + if(res.code===1){
  84 + layer.msg(res.msg,{time:1000,icon:1});
  85 + tableIn.reload();
  86 + }else{
  87 + layer.msg('操作失败!',{time:1000,icon:2});
  88 + }
  89 + });
  90 + layer.close(index);
  91 + });
  92 + }
  93 + });
  94 + $('body').on('blur','.list_order',function() {
  95 + var ad_id = $(this).attr('data-id');
  96 + var sort = $(this).val();
  97 + var loading = layer.load(1, {shade: [0.1, '#fff']});
  98 + $.post('{:url("adOrder")}',{ad_id:ad_id,sort:sort},function(res){
  99 + layer.close(loading);
  100 + if(res.code === 1){
  101 + layer.msg(res.msg, {time: 1000, icon: 1});
  102 + tableIn.reload();
  103 + }else{
  104 + layer.msg(res.msg,{time:1000,icon:2});
  105 + }
  106 + })
  107 + });
  108 + $('#delAll').click(function(){
  109 + layer.confirm('确认要删除选中的广告吗?', {icon: 3}, function(index) {
  110 + layer.close(index);
  111 + var checkStatus = table.checkStatus('ad'); //test即为参数id设定的值
  112 + var ids = [];
  113 + $(checkStatus.data).each(function (i, o) {
  114 + ids.push(o.ad_id);
  115 + });
  116 + if(ids==''){
  117 + layer.msg('请选择要删除的数据!', {time: 1000, icon: 2});
  118 + return false;
  119 + }
  120 + var loading = layer.load(1, {shade: [0.1, '#fff']});
  121 + $.post("{:url('delall')}", {ids: ids}, function (data) {
  122 + layer.close(loading);
  123 + if (data.code === 1) {
  124 + layer.msg(data.msg, {time: 1000, icon: 1});
  125 + tableIn.reload();
  126 + } else {
  127 + layer.msg(data.msg, {time: 1000, icon: 2});
  128 + }
  129 + });
  130 + });
  131 + })
  132 + })
  133 +</script>