|
Server : Apache System : Linux iZ6xhqomji47p1Z 5.10.134-15.al8.x86_64 #1 SMP Thu Jul 20 00:44:04 CST 2023 x86_64 User : www ( 1000) PHP Version : 8.1.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/fsjlkj.cn/data/weapp/Sample/weapp/Sample/controller/ |
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-06-28
*/
namespace weapp\Sample\controller;
use think\Page;
use think\Db;
use app\common\controller\Weapp;
use weapp\Sample\model\SampleModel;
/**
* 插件的控制器
*/
class Sample extends Weapp
{
/**
* 实例化模型
*/
private $model;
/**
* 实例化对象
*/
private $db;
/**
* 插件基本信息
*/
private $weappInfo;
/**
* 构造方法
*/
public function __construct(){
parent::__construct();
$this->model = new SampleModel;
$this->db = Db::name('WeappSample');
/*插件基本信息*/
$this->weappInfo = $this->getWeappInfo();
$this->assign('weappInfo', $this->weappInfo);
/*--end*/
}
/**
* 插件使用指南
*/
public function doc(){
return $this->fetch('doc');
}
/**
* 系统内置钩子show方法(没用到这个方法,建议删掉)
* 用于在前台模板显示片段的html代码,比如:QQ客服、对联广告等
*
* @param mixed $params 传入的参数
*/
public function show($params = null){
$list = $this->db->select();
$this->assign('list', $list);
echo $this->fetch('show');
}
/**
* 插件后台管理 - 列表
*/
public function index()
{
$list = array();
$keywords = input('keywords/s');
$map = array();
if (!empty($keywords)) {
$map['title'] = array('LIKE', "%{$keywords}%");
}
$count = $this->db->where($map)->count('id');// 查询满足要求的总记录数
$pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
$list = $this->db->where($map)->order('id desc')->limit($pageObj->firstRow.','.$pageObj->listRows)->select();
$pageStr = $pageObj->show(); // 分页显示输出
$this->assign('list', $list); // 赋值数据集
$this->assign('pageStr', $pageStr); // 赋值分页输出
$this->assign('pager', $pageObj); // 赋值分页对象
return $this->fetch('index');
}
/**
* 插件后台管理 - 新增
*/
public function add()
{
if (IS_POST) {
$post = input('post.');
/*------------这里可以实现存储数据之前的额外逻辑 start-------------*/
/*处理LOGO的本地上传与远程*/
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
$logo = '';
if ($is_remote == 1) {
$logo = $post['logo_remote']; // 远程链接
} else {
$logo = $post['logo_local']; // 本地上传链接
}
$post['logo'] = $logo;
/*--end*/
/*--------------------------------end------------------------------*/
/*组装存储数据*/
$nowData = array(
'add_time' => getTime(),
'update_time' => getTime(),
);
$saveData = array_merge($post, $nowData);
/*--end*/
$insertId = $this->db->insert($saveData);
if (false !== $insertId) {
adminLog('新增'.$this->weappInfo['name'].':'.$post['title']); // 写入操作日志
$this->success("操作成功", weapp_url('Sample/Sample/index'));
}else{
$this->error("操作失败");
}
exit;
}
return $this->fetch('add');
}
/**
* 插件后台管理 - 编辑
*/
public function edit()
{
if (IS_POST) {
$post = input('post.');
$post['id'] = eyIntval($post['id']);
if(!empty($post['id'])){
/*------------这里可以实现存储数据之前的额外逻辑 start-------------*/
/*处理LOGO的本地上传与远程*/
$is_remote = !empty($post['is_remote']) ? $post['is_remote'] : 0;
$logo = '';
if ($is_remote == 1) {
$logo = $post['logo_remote']; // 远程链接
} else {
$logo = $post['logo_local']; // 本地上传链接
}
$post['logo'] = $logo;
/*--end*/
/*--------------------------------end------------------------------*/
/*组装存储数据*/
$nowData = array(
'typeid' => empty($post['typeid']) ? 1 : $post['typeid'],
'url' => trim($post['url']),
'update_time' => getTime(),
);
$saveData = array_merge($post, $nowData);
/*--end*/
$r = $this->db->where(array('id'=>$post['id']))->update($saveData);
if ($r) {
adminLog('编辑'.$this->weappInfo['name'].':'.$post['title']); // 写入操作日志
$this->success("操作成功!", weapp_url('Sample/Sample/index'));
}
}
$this->error("操作失败!");
}
$id = input('id/d', 0);
$row = $this->db->find($id);
if (empty($row)) {
$this->error('数据不存在,请联系管理员!');
exit;
}
/*同时拥有本地上传与远程URL的逻辑处理*/
if (is_http_url($row['logo'])) {
$row['is_remote'] = 1;
$row['logo_remote'] = $row['logo'];
} else {
$row['is_remote'] = 0;
$row['logo_local'] = $row['logo'];
}
/*--end*/
$this->assign('row',$row);
return $this->fetch('edit');
}
/**
* 删除文档
*/
public function del()
{
$id_arr = input('del_id/a');
$id_arr = eyIntval($id_arr);
if(!empty($id_arr) && IS_POST){
$result = $this->db->where("id",'IN',$id_arr)->select();
$title_list = get_arr_column($result, 'title');
$r = $this->db->where("id",'IN',$id_arr)->delete();
if($r !== false){
adminLog('删除'.$this->weappInfo['name'].':'.implode(',', $title_list));
$this->success("操作成功!");
}
}
$this->error("操作失败!");
}
/**
* 插件配置
*/
public function conf()
{
if (IS_POST) {
$post = input('post.');
if(!empty($post['code'])){
$data = array(
'tag_weapp' => $post['tag_weapp'],
'update_time' => getTime(),
);
$r = M('weapp')->where('code','eq',$post['code'])->update($data);
if ($r) {
\think\Cache::clear('hooks');
adminLog('编辑'.$this->weappInfo['name'].':插件配置'); // 写入操作日志
$this->success("操作成功!", weapp_url('Sample/Sample/conf'));
}
}
$this->error("操作失败!");
}
$row = M('weapp')->where('code','eq','Sample')->find();
$this->assign('row', $row);
return $this->fetch('conf');
}
}