清空
This commit is contained in:
@@ -1,679 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin;
|
||||
|
||||
use think\App;
|
||||
use think\facade\View;
|
||||
|
||||
use app\model\Admin as AdminModel;
|
||||
use app\model\Access as AccessModel;
|
||||
use app\model\Auth as AuthModel;
|
||||
use app\model\Node as NodeModel;
|
||||
use app\model\Group as GroupModel;
|
||||
use app\model\Conf as ConfModel;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class QfShop
|
||||
{
|
||||
protected $model = null;
|
||||
//搜索字段
|
||||
protected $selectList = '*';
|
||||
protected $selectDetail = '*';
|
||||
//筛选字段
|
||||
protected $searchFilter = [];
|
||||
//更新字段
|
||||
protected $updateFields = [];
|
||||
//更新时的必须字段
|
||||
protected $updateRequire = [];
|
||||
//添加字段
|
||||
protected $insertFields = [];
|
||||
//添加时的必须字段
|
||||
protected $insertRequire = [];
|
||||
//excel查询字段 用来查询
|
||||
protected $excelField = [
|
||||
"join_id" => "编号",
|
||||
];
|
||||
//excel 表头
|
||||
protected $excelTitle = "数据导出表";
|
||||
//EXCEL 单元格字母
|
||||
protected $excelCells = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD'];
|
||||
|
||||
//主键key
|
||||
protected $pk = '';
|
||||
//表名称
|
||||
protected $table = '';
|
||||
//主键value
|
||||
protected $pk_value = 0;
|
||||
|
||||
|
||||
//模型
|
||||
protected $adminModel;
|
||||
protected $accessModel;
|
||||
protected $authModel;
|
||||
protected $nodeModel;
|
||||
protected $groupModel;
|
||||
protected $confModel;
|
||||
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
protected $plat = 'all';
|
||||
protected $version = 0;
|
||||
|
||||
|
||||
protected $module;
|
||||
protected $controller;
|
||||
protected $action;
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
//TODO !!!如有特殊需求请重写下面的方法到子类,请勿修改此处!!! BEGIN.........//
|
||||
/**
|
||||
* 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//校验Insert字段是否填写
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Insert数据
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
//添加这行数据
|
||||
$this->insertRow($data);
|
||||
return jok('添加成功');
|
||||
}
|
||||
/**
|
||||
* 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//校验Update字段是否填写
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Update数据
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
//根据主键更新这条数据
|
||||
$this->updateByPk($data);
|
||||
return jok('修改成功');
|
||||
}
|
||||
/**
|
||||
* 禁用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$this->disableBySingle();
|
||||
} else {
|
||||
//批量操作
|
||||
$this->disableByMultiple();
|
||||
}
|
||||
return jok("禁用成功");
|
||||
}
|
||||
/**
|
||||
* 启用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$this->enableBySingle();
|
||||
} else {
|
||||
//批量操作
|
||||
$this->enableByMultiple();
|
||||
}
|
||||
return jok("启用成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$this->deleteBySingle();
|
||||
} else {
|
||||
//批量操作
|
||||
$this->deleteByMultiple();
|
||||
}
|
||||
return jok('删除成功');
|
||||
}
|
||||
/**
|
||||
* 获取列表接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
//从请求中获取排序方式
|
||||
$order = $this->getorderfromRequest();
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
/**
|
||||
* 获取详情基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("没有查询到数据", 404);
|
||||
}
|
||||
return jok('数据加载成功', $item);
|
||||
}
|
||||
/**
|
||||
* 导出Excel基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function excel()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$this->exportExcelData();
|
||||
}
|
||||
// !!!如有特殊需求请重写下面的方法到子类,请勿修改此处!!! END.........//
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
$this->module = "api";
|
||||
$this->controller = $this->request->controller() ? $this->request->controller() : "Index";
|
||||
$this->action = strtolower($this->request->action()) ? strtolower($this->request->action()) : "index";
|
||||
View::assign('controller', strtolower($this->controller));
|
||||
View::assign('action', strtolower($this->action));
|
||||
|
||||
$this->table = strtolower($this->controller);
|
||||
$this->pk = $this->table . "_id";
|
||||
$this->pk_value = input($this->pk);
|
||||
|
||||
$this->adminModel = new AdminModel();
|
||||
$this->accessModel = new AccessModel();
|
||||
$this->authModel = new AuthModel();
|
||||
$this->nodeModel = new NodeModel();
|
||||
$this->groupModel = new GroupModel();
|
||||
$this->confModel = new ConfModel();
|
||||
|
||||
$configs = $this->confModel->select()->toArray();
|
||||
$c = [];
|
||||
foreach ($configs as $config) {
|
||||
$c[$config['conf_key']] = $config['conf_value'];
|
||||
}
|
||||
config($c, 'qfshop');
|
||||
}
|
||||
/**
|
||||
* 检测授权
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function access()
|
||||
{
|
||||
if (!input("plat")) {
|
||||
return jerr("plat参数为必须", 400);
|
||||
}
|
||||
$this->plat = input('plat');
|
||||
if (!input("version")) {
|
||||
return jerr("version参数为必须", 400);
|
||||
}
|
||||
$this->version = input('version');
|
||||
|
||||
if (!input("access_token")) {
|
||||
return jerr("AccessToken为必要参数", 400);
|
||||
}
|
||||
$access_token = input("access_token");
|
||||
$this->admin = $this->adminModel->getAdminByAccessToken($access_token);
|
||||
if (!$this->admin) {
|
||||
return jerr("登录过期,请重新登录", 401);
|
||||
}
|
||||
if ($this->admin['admin_status'] == 1) {
|
||||
return jerr("你的账户被禁用,登录失败", 401);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 从请求中获取Request数据
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getInsertDataFromRequest()
|
||||
{
|
||||
$data = [];
|
||||
foreach (input('post.') as $k => $v) {
|
||||
if (in_array($k, $this->insertFields)) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* 校验Insert的字段
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function validateInsertFields()
|
||||
{
|
||||
foreach ($this->insertRequire as $k => $v) {
|
||||
if (!input($k)) {
|
||||
return jerr($v, 400);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 从请求中获取Update数据
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getUpdateDataFromRequest()
|
||||
{
|
||||
$data = [];
|
||||
foreach (input('post.') as $k => $v) {
|
||||
if (in_array($k, $this->updateFields)) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* 校验Update的字段
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function validateUpdateFields()
|
||||
{
|
||||
foreach ($this->updateRequire as $k => $v) {
|
||||
if (!input($k)) {
|
||||
return jerr($v, 400);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 按主键集合批量禁用 1,2,3,4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function disableByMultiple()
|
||||
{
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 单个禁用 可传入自定义$map
|
||||
* 默认按主键ID禁用
|
||||
*
|
||||
* @param array $map
|
||||
* @return void
|
||||
*/
|
||||
protected function disableBySingle($map = null)
|
||||
{
|
||||
if ($map == null) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 按主键集合批量启用 1,2,3,4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function enableByMultiple()
|
||||
{
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->update([
|
||||
$this->table . "_status" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 单个启用 可传入自定义$map
|
||||
* 默认按主键ID启用
|
||||
*
|
||||
* @param array $map
|
||||
* @return void
|
||||
*/
|
||||
protected function enableBySingle($map = null)
|
||||
{
|
||||
if ($map == null) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 按主键集合批量删除1,2,3,4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteByMultiple()
|
||||
{
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->delete();
|
||||
}
|
||||
/**
|
||||
* 单个删除 默认主键ID
|
||||
*
|
||||
* @param array $map
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteBySingle($map = null)
|
||||
{
|
||||
if ($map == null) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
}
|
||||
$this->model->where($map)->delete();
|
||||
}
|
||||
/**
|
||||
* 根据主键ID获取一行数据
|
||||
*
|
||||
* @param int|null 主键ID
|
||||
* @return array|null
|
||||
*/
|
||||
protected function getRowByPk($pk_value = null)
|
||||
{
|
||||
if (!$pk_value) {
|
||||
$pk_value = $this->pk_value;
|
||||
}
|
||||
$item = $this->model->where($this->pk, $pk_value)->field($this->selectDetail)->find();
|
||||
return $item ? $item->toArray() : null;
|
||||
}
|
||||
/**
|
||||
* 根据主键ID更新数据
|
||||
*
|
||||
* @param array 需要更新的KV数组
|
||||
* @param int|null 主键ID 默认$this->pk_value
|
||||
* @param bool 是否更新_updatetime字段 默认TRUE
|
||||
* @return void
|
||||
*/
|
||||
protected function updateByPk($data, $pk_value = null, $auto_updatetime = true)
|
||||
{
|
||||
if (!$pk_value) {
|
||||
$pk_value = $this->pk_value;
|
||||
}
|
||||
if ($auto_updatetime) {
|
||||
$data[$this->table . "_updatetime"] = time();
|
||||
}
|
||||
$this->model->where($this->pk, $this->pk_value)->update($data);
|
||||
}
|
||||
/**
|
||||
* 添加一行数据
|
||||
*
|
||||
* @param array 需要添加的KV数组
|
||||
* @param bool 是否自动记录_createtime和_updatetime字段 默认true
|
||||
* @return int 添加返回的主键ID
|
||||
*/
|
||||
protected function insertRow($data, $auto_inserttime = true)
|
||||
{
|
||||
if ($auto_inserttime) {
|
||||
$data[$this->table . "_updatetime"] = time();
|
||||
$data[$this->table . "_createtime"] = time();
|
||||
} else {
|
||||
$data[$this->table . "_updatetime"] = 0;
|
||||
$data[$this->table . "_createtime"] = 0;
|
||||
}
|
||||
$id = $this->model->insertGetId($data);
|
||||
return $id;
|
||||
}
|
||||
/**
|
||||
* 从请求中获取查询排序(默认主键DESC)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getOrderFromRequest()
|
||||
{
|
||||
if (input('order')) {
|
||||
$order = urldecode(input('order'));
|
||||
} else {
|
||||
$order = strtolower($this->controller) . "_id desc";
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
/**
|
||||
* 设置分页查询每页数量
|
||||
*
|
||||
* @param int|null 每页数量
|
||||
* @return void
|
||||
*/
|
||||
protected function setGetListPerPage($per_page = null)
|
||||
{
|
||||
if ($per_page) {
|
||||
$this->model->per_page = intval($per_page);
|
||||
} else if (input('per_page')) {
|
||||
$this->model->per_page = input('per_page');
|
||||
} else {
|
||||
$this->model->per_page = 10;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取查询列表的Where参数
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDataFilterFromRequest()
|
||||
{
|
||||
$map = [];
|
||||
$filter = input('post.');
|
||||
foreach ($filter as $k => $v) {
|
||||
if ($k == 'filter') {
|
||||
$k = input('filter');
|
||||
$v = input('keyword');
|
||||
}
|
||||
if ($v === '' || $v === null) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($k, $this->searchFilter)) {
|
||||
switch ($this->searchFilter[$k]) {
|
||||
case "like":
|
||||
array_push($map, [$k, 'like', "%" . $v . "%"]);
|
||||
break;
|
||||
case "=":
|
||||
array_push($map, [$k, '=', $v]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
protected function getExcelFields()
|
||||
{
|
||||
$excelField = [];
|
||||
foreach ($this->excelField as $k => $v) {
|
||||
if ($k == "*") {
|
||||
continue;
|
||||
} else {
|
||||
array_push($excelField, [
|
||||
$k, $v
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $excelField;
|
||||
}
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @return string 下载文件名
|
||||
*/
|
||||
protected function exportExcelData($data)
|
||||
{
|
||||
$datalist = $data ? $data->toArray() : [];
|
||||
$excelField = $this->getExcelFields();
|
||||
$PHPExcel = new \PHPExcel(); //实例化
|
||||
$PHPExcel
|
||||
->getProperties() //获得文件属性对象,给下文提供设置资源
|
||||
->setCreator("qfshop") //设置文件的创建者
|
||||
->setLastModifiedBy("qfshop") //设置最后修改者
|
||||
->setDescription("Export by qfshop"); //设置备注
|
||||
|
||||
$PHPSheet = $PHPExcel->getActiveSheet();
|
||||
|
||||
|
||||
if (count($excelField) > count($this->excelCells)) {
|
||||
echo 'Error and you need check Excel Cells Keys...';
|
||||
die;
|
||||
}
|
||||
$PHPSheet->getRowDimension(1)->setRowHeight(30);
|
||||
for ($column = 0; $column < count($excelField); $column++) {
|
||||
$PHPSheet->setCellValue($this->excelCells[$column] . "1", $excelField[$column][1]);
|
||||
$PHPSheet->getStyle($this->excelCells[$column])->getNumberFormat()
|
||||
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
|
||||
for ($line = 0; $line < count($datalist); $line++) {
|
||||
$string = $datalist[$line][$excelField[$column][0]];
|
||||
$PHPSheet->getColumnDimension($this->excelCells[$column])->setWidth(20);
|
||||
$PHPSheet->setCellValueExplicit($this->excelCells[$column] . ($line + 2), $string, \PHPExcel_Cell_DataType::TYPE_STRING);
|
||||
}
|
||||
}
|
||||
//***********************画出单元格边框*****************************
|
||||
$styleArray = array(
|
||||
|
||||
);
|
||||
$PHPSheet->getStyle('A2:' . $this->excelCells[count($excelField) - 1] . (count(
|
||||
$datalist
|
||||
) + 2))->applyFromArray($styleArray);
|
||||
//***********************画出单元格边框结束*****************************
|
||||
|
||||
//设置全部居中对齐
|
||||
$PHPSheet->getStyle('A1:' . $this->excelCells[count($excelField) - 1] . (count(
|
||||
$datalist
|
||||
) + 2))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
//设置全部字体
|
||||
$PHPSheet->getStyle('A1:' . $this->excelCells[count($excelField) - 1] . (count(
|
||||
$datalist
|
||||
) + 2))->getFont()->setName('微软雅黑');
|
||||
$PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel, "Excel2007"); //创建生成的格式
|
||||
header('Content-Disposition: attachment;filename="' . $this->excelTitle . "_" . date('Y-m-d_H:i:s') . '.xlsx"'); //下载下来的表格名
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
$PHPWriter->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
|
||||
exit;
|
||||
return $this->excelTitle . "_" . date('Y-m-d_H:i:s') . '.xlsx"';
|
||||
}
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return jerr("访问异常", 404);
|
||||
}
|
||||
}
|
||||
@@ -1,480 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Admin as model;
|
||||
use app\model\Sms as SmsModel;
|
||||
use app\model\Validate as ValidateModel;
|
||||
|
||||
class Admin extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//查询字段
|
||||
$this->selectList = "*";
|
||||
$this->selectDetail = "*";
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"admin_id" => "=",
|
||||
"admin_account" => "like",
|
||||
"admin_name" => "like",
|
||||
"admin_truename" => "like",
|
||||
"admin_status" => "=",
|
||||
];
|
||||
$this->insertFields = [
|
||||
"admin_account", "admin_password", "admin_name", "admin_idcard", "admin_email", "admin_group", "admin_truename"
|
||||
];
|
||||
$this->updateFields = [
|
||||
"admin_account", "admin_password", "admin_name", "admin_idcard", "admin_email", "admin_group", "admin_truename"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
'admin_name' => "用户昵称必须填写",
|
||||
'admin_account' => "用户帐号必须填写",
|
||||
'admin_password' => "密码必须填写",
|
||||
'admin_group' => "用户组必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
'admin_name' => "用户昵称必须填写",
|
||||
'admin_account' => "用户帐号必须填写",
|
||||
'admin_group' => "用户组必须填写",
|
||||
];
|
||||
$this->excelField = [
|
||||
"id" => "编号",
|
||||
"account" => "帐号",
|
||||
"name" => "昵称",
|
||||
"idcard" => "身份证",
|
||||
"email" => "邮箱",
|
||||
"createtime" => "创建时间",
|
||||
"updatetime" => "修改时间"
|
||||
];
|
||||
$this->model = new model();
|
||||
}
|
||||
public function add()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
$data['admin_ipreg'] = "127.0.0.1";
|
||||
$admin = $this->model->getAdminByAccount($data["admin_account"]);
|
||||
if ($admin) {
|
||||
return jerr("帐号已存在,请重新输入");
|
||||
}
|
||||
$salt = getRandString(4);
|
||||
$password = $data["admin_password"];
|
||||
$password = encodePassword($password, $salt);
|
||||
$data["admin_salt"] = $salt;
|
||||
$data["admin_password"] = $password;
|
||||
$this->insertRow($data);
|
||||
return jok('用户添加成功');
|
||||
}
|
||||
public function update()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (!isInteger($this->pk_value)) {
|
||||
return jerr("修改失败,参数错误", 400);
|
||||
}
|
||||
$item = $this->model->where($this->pk, $this->pk_value)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if (intval($this->pk_value) == 1) {
|
||||
return jerr("无法修改超管用户信息");
|
||||
}
|
||||
foreach ($this->updateRequire as $k => $v) {
|
||||
if (!input($k)) {
|
||||
return jerr($v);
|
||||
}
|
||||
}
|
||||
$data = [];
|
||||
foreach (input('post.') as $k => $v) {
|
||||
if (in_array($k, $this->updateFields)) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
$admin = $this->model->getAdminByAccount($data["admin_account"]);
|
||||
if ($admin && $admin[$this->pk] != $item[$this->pk]) {
|
||||
return jerr("帐号已存在,请重新输入");
|
||||
}
|
||||
if (input('new_password')) {
|
||||
//设置密码
|
||||
$salt = getRandString(4);
|
||||
$password = input('new_password');
|
||||
$password = encodePassword($password, $salt);
|
||||
$data["admin_salt"] = $salt;
|
||||
$data["admin_password"] = $password;
|
||||
}
|
||||
if ($this->admin['admin_group'] != 1) {
|
||||
//除超级管理员组外 其他任何组不允许修改用户组
|
||||
unset($data['admin_group']);
|
||||
}
|
||||
$data[$this->table . "_updatetime"] = time();
|
||||
$this->model->where($this->pk, $this->pk_value)->update($data);
|
||||
return jok('用户信息更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用用户
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item["admin_group"] == 1) {
|
||||
return jerr("超级管理员不允许操作!");
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->where("admin_group > 1")->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("禁用用户成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用用户
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item["admin_group"] == 1) {
|
||||
return jerr("超级管理员不允许操作!");
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->where("admin_group > 1")->update([
|
||||
$this->table . "_status" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("启用用户成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//
|
||||
if ($item["admin_group"] == 1) {
|
||||
return jerr("超级管理员不允许操作!");
|
||||
}
|
||||
$this->model->where($map)->delete();
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
//批量删除只允许删除用户组不为1的用户
|
||||
$this->model->where($this->pk, 'in', $list)->where("admin_group > 1")->delete();
|
||||
}
|
||||
return jok('删除用户成功');
|
||||
}
|
||||
public function detail()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
$item = $this->model->field($this->selectDetail)->where($this->pk, $this->pk_value)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("没有查询到数据", 404);
|
||||
}
|
||||
return jok('数据加载成功', $item);
|
||||
}
|
||||
public function getList()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$map = [];
|
||||
$filter = input('post.');
|
||||
foreach ($filter as $k => $v) {
|
||||
if ($k == 'filter') {
|
||||
$k = input('filter');
|
||||
$v = input('keyword');
|
||||
}
|
||||
if ($v === '' || $v === null) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($k, $this->searchFilter)) {
|
||||
switch ($this->searchFilter[$k]) {
|
||||
case "like":
|
||||
array_push($map, [$k, 'like', "%" . $v . "%"]);
|
||||
break;
|
||||
case "=":
|
||||
array_push($map, [$k, '=', $v]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
$order = strtolower($this->controller) . "_id desc";
|
||||
if (input('order')) {
|
||||
$order = urldecode(input('order'));
|
||||
}
|
||||
if (input('per_page')) {
|
||||
$this->model->per_page = intval(input('per_page'));
|
||||
}
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('用户列表获取成功', $dataList);
|
||||
}
|
||||
public function login()
|
||||
{
|
||||
if (!input("admin_account")) {
|
||||
return jerr('请确认帐号是否正确填写', 400);
|
||||
}
|
||||
if (!input("admin_password")) {
|
||||
return jerr('请确认密码是否正确填写', 400);
|
||||
}
|
||||
if (!input("admin_code")) {
|
||||
return jerr('请确认图形验证码是否填写', 400);
|
||||
}
|
||||
$plat = input("plat");
|
||||
$admin_account = input("admin_account");
|
||||
$admin_password = input("admin_password");
|
||||
|
||||
//验证图形验证码
|
||||
$validateModel = new ValidateModel();
|
||||
$error = $validateModel->validateImgCode(input('token'), input('admin_code'));
|
||||
if ($error) {
|
||||
return jerr('验证码错误', 400);
|
||||
}
|
||||
//登录获取用户信息
|
||||
$admin = $this->model->login($admin_account, $admin_password);
|
||||
if ($admin) {
|
||||
//创建一个新的授权
|
||||
$access = $this->accessModel->createAccess($admin['admin_id'], $plat);
|
||||
if ($access) {
|
||||
setCookie('access_token', $access['access_token'], time() + 3600, '/');
|
||||
return jok('登录成功', ['access_token' => $access['access_token']]);
|
||||
} else {
|
||||
return jerr('登录系统异常');
|
||||
}
|
||||
} else {
|
||||
return jerr('帐号或密码错误');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 退出登录
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
$access_token = input("access_token");
|
||||
cookie('access_token', null);
|
||||
$this->accessModel->where('access_token', $access_token)->update(["access_status" => 1]);
|
||||
return jok('已退出登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reg()
|
||||
{
|
||||
if (!input("phone")) {
|
||||
return jerr("手机号不能为空!", 400);
|
||||
}
|
||||
$phone = input("phone");
|
||||
if (!input("code")) {
|
||||
return jerr("短信验证码不能为空!", 400);
|
||||
}
|
||||
$code = input("code");
|
||||
if (!input("password")) {
|
||||
return jerr("密码不能为空!", 400);
|
||||
}
|
||||
$password = input("password");
|
||||
$name = $phone;
|
||||
if (input("name")) {
|
||||
$name = input("name");
|
||||
}
|
||||
$smsModel = new SmsModel();
|
||||
if ($smsModel->validSmsCode($phone, $code)) {
|
||||
$admin = $this->model->where([
|
||||
"admin_account" => $phone
|
||||
])->find();
|
||||
if ($admin) {
|
||||
return jerr("该手机号已经注册!");
|
||||
}
|
||||
$result = $this->model->reg($phone, $password, $name);
|
||||
if ($result) {
|
||||
return jok("用户注册成功");
|
||||
} else {
|
||||
return jerr("注册失败,请重试!");
|
||||
}
|
||||
} else {
|
||||
return jerr("短信验证码已过期,请重新获取");
|
||||
}
|
||||
}
|
||||
public function motifyPassword()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!input("oldPassword")) {
|
||||
return jerr("你必须要输入你的原密码!", 400);
|
||||
}
|
||||
if (!input("newPassword")) {
|
||||
return jerr("你必须输入一个新的密码!", 400);
|
||||
}
|
||||
$old_password = input("oldPassword");
|
||||
$new_password = input("newPassword");
|
||||
if (strlen($new_password) < 6 || strlen($new_password) > 16) {
|
||||
return jerr("新密码因为6-16位!");
|
||||
}
|
||||
if ($this->admin['admin_password'] != encodePassword($old_password, $this->admin['admin_salt'])) {
|
||||
return jerr("原密码输入不正确,请重试!");
|
||||
}
|
||||
$result = $this->model->motifyPassword($this->admin['admin_id'], $new_password);
|
||||
if ($result) {
|
||||
return jok("密码已重置,请使用新密码登录");
|
||||
} else {
|
||||
return jerr("注册失败,请重试!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetPassword()
|
||||
{
|
||||
if (!input("phone")) {
|
||||
return jerr("手机号不能为空!", 400);
|
||||
}
|
||||
if (!input("code")) {
|
||||
return jerr("短信验证码不能为空!", 400);
|
||||
}
|
||||
if (!input("password")) {
|
||||
return jerr("密码不能为空!", 400);
|
||||
}
|
||||
$phone = input("phone");
|
||||
$code = input("code");
|
||||
$password = input("password");
|
||||
$smsModel = new SmsModel();
|
||||
if ($smsModel->validSmsCode($phone, $code)) {
|
||||
$admin = $this->model->where([
|
||||
"admin_account" => $phone
|
||||
])->find();
|
||||
if (!$admin) {
|
||||
return jerr("该手机号尚未注册!", 404);
|
||||
}
|
||||
$result = $this->model->motifyPassword($admin['admin_id'], $password);
|
||||
if ($result) {
|
||||
return jok("密码已重置,请使用新密码登录");
|
||||
} else {
|
||||
return jerr("注册失败,请重试!");
|
||||
}
|
||||
} else {
|
||||
return jerr("短信验证码已过期,请重新获取");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getMyInfo()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$myInfo = $this->admin;
|
||||
foreach (['admin_password', 'admin_salt', 'admin_accesstoken', 'admin_tokentime', 'admin_status'] as $key) {
|
||||
unset($myInfo[$key]);
|
||||
}
|
||||
return jok('数据获取成功', $myInfo);
|
||||
}
|
||||
public function updateMyInfo()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!input("admin_name")) {
|
||||
return jerr("你确定飘到连名字都可以不要了吗?", 400);
|
||||
}
|
||||
$data = [
|
||||
"admin_name" => input("admin_name"),
|
||||
"admin_truename" => input("admin_truename"),
|
||||
"admin_email" => input("admin_email"),
|
||||
"admin_idcard" => input("admin_idcard"),
|
||||
];
|
||||
$this->model->where("admin_id", $this->admin['admin_id'])->update($data);
|
||||
return jok("资料更新成功");
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Filesystem;
|
||||
use think\exception\ValidateException;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Attach as AttachModel;
|
||||
|
||||
class Attach extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"attach_id" => "=", //相同筛选
|
||||
"attach_key" => "like", //相似筛选
|
||||
"attach_value" => "like", //相似筛选
|
||||
"attach_desc" => "like", //相似筛选
|
||||
"attach_readonly" => "=", //相似筛选
|
||||
];
|
||||
$this->model = new AttachModel();
|
||||
}
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uploadImage()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
try {
|
||||
$file = request()->file('file');
|
||||
try {
|
||||
validate(['file' => 'filesize:' . config("qfshop.upload_max_image") . '|fileExt:' . config("qfshop.upload_image_type")])
|
||||
->check(['file' => $file]);
|
||||
$saveName = Filesystem::putFile('image', $file);
|
||||
$attach_data = array(
|
||||
'attach_path' => "/uploads/".$saveName,
|
||||
'attach_name' => $file->getOriginalName(),
|
||||
'attach_type' => $file->extension(),
|
||||
'attach_size' => $file->getSize(),
|
||||
'attach_admin' => $this->admin['admin_id']
|
||||
);
|
||||
$attach_id = $this->insertRow($attach_data);
|
||||
$attach_data = $this->getRowByPk($attach_id);
|
||||
if (input("?extend")) {
|
||||
$attach_data['extend'] = input("extend");
|
||||
}
|
||||
return jok('上传成功!', $attach_data);
|
||||
} catch (ValidateException $e) {
|
||||
return jerr($e->getMessage());
|
||||
}
|
||||
} catch (\Exception $error) {
|
||||
return jerr('上传文件失败,请检查你的文件!');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除图片
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$res = $this->model->where($map)->delete();
|
||||
if($res){
|
||||
try {
|
||||
unlink("./uploads/".$item['attach_path']);
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $this->pk_value);
|
||||
foreach ($list as $key => $value) {
|
||||
$item = $this->model->where("attach_id",$value)->find();
|
||||
if($item){
|
||||
try {
|
||||
unlink("./uploads/".$item['attach_path']);
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->model->where($this->pk, 'in', $list)->delete();
|
||||
}
|
||||
return jok('删除成功');
|
||||
}
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uploadFile()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
try {
|
||||
$file = request()->file('file');
|
||||
try {
|
||||
validate(['file' => 'filesize:' . config("qfshop.upload_max_file") . '|fileExt:' . config("qfshop.upload_file_type")])
|
||||
->check(['file' => $file]);
|
||||
$saveName = Filesystem::putFile('normal', $file);
|
||||
$attach_data = array(
|
||||
'attach_path' => $saveName,
|
||||
'attach_type' => $file->extension(),
|
||||
'attach_size' => $file->getSize(),
|
||||
'attach_admin' => $this->admin['admin_id']
|
||||
);
|
||||
$attach_id = $this->insertRow($attach_data);
|
||||
$attach_data = $this->getRowByPk($attach_id);
|
||||
if (input("?extend")) {
|
||||
$attach_data['extend'] = input("extend");
|
||||
}
|
||||
return jok('上传成功!', $attach_data);
|
||||
} catch (ValidateException $e) {
|
||||
return jerr($e);
|
||||
}
|
||||
} catch (\Exception $error) {
|
||||
return jerr('上传文件失败,请检查你的文件!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 富文本上传图片
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uploads()
|
||||
{
|
||||
header("Content-Type: text/html; charset=utf-8");
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("./static/admin/UEditor/config.json")), true);
|
||||
$action = $_GET['action'];
|
||||
|
||||
switch ($action) {
|
||||
case 'config':
|
||||
$result = json_encode($CONFIG);
|
||||
break;
|
||||
|
||||
/* 上传图片 */
|
||||
case 'uploadimage':
|
||||
/* 上传涂鸦 */
|
||||
case 'uploadscrawl':
|
||||
/* 上传视频 */
|
||||
case 'uploadvideo':
|
||||
/* 上传文件 */
|
||||
case 'uploadfile':
|
||||
try {
|
||||
$file = request()->file('upfile');
|
||||
try {
|
||||
validate(['file' => 'filesize:' . config("qfshop.upload_max_image") . '|fileExt:' . config("qfshop.upload_image_type")])
|
||||
->check(['file' => $file]);
|
||||
$saveName = Filesystem::putFile('normal', $file);
|
||||
$result = json_encode(array(
|
||||
'original'=> $file->getOriginalName(),
|
||||
'state'=> "SUCCESS",
|
||||
'title'=> $file->getOriginalName(),
|
||||
'url'=> "/uploads/".$saveName,
|
||||
'type'=> $file->extension(),
|
||||
));
|
||||
} catch (ValidateException $e) {
|
||||
$result = json_encode(array(
|
||||
'state'=> $e->getMessage()
|
||||
));
|
||||
}
|
||||
} catch (\Exception $error) {
|
||||
$result = json_encode(array(
|
||||
'state'=> '上传文件失败,请检查你的文件!'
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$result = json_encode(array(
|
||||
'state'=> '请求地址出错'
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
/* 输出结果 */
|
||||
if (isset($_GET["callback"])) {
|
||||
if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
|
||||
echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
|
||||
} else {
|
||||
echo json_encode(array(
|
||||
'state'=> 'callback参数不合法'
|
||||
));
|
||||
}
|
||||
} else {
|
||||
echo $result;
|
||||
}
|
||||
die;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Auth as AuthModel;
|
||||
|
||||
class Auth extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"auth_id" => "=", //相同筛选
|
||||
];
|
||||
$this->model = new AuthModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除访问日志
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$this->model->cleanAuth();
|
||||
return jok('授权信息清理成功');
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Conf as ConfModel;
|
||||
|
||||
class Conf extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"conf_id" => "=", //相同筛选
|
||||
"conf_key" => "like", //相似筛选
|
||||
"conf_value" => "like", //相似筛选
|
||||
"conf_title" => "like", //相似筛选
|
||||
"conf_status" => "=", //相同筛选
|
||||
"conf_type" => "=", //相同筛选
|
||||
];
|
||||
$this->insertFields = [
|
||||
"conf_key", "conf_value", "conf_title", "conf_desc", "conf_status", "conf_type", "conf_spec", "conf_content", "conf_sort", "conf_system"
|
||||
];
|
||||
$this->updateFields = [
|
||||
"conf_key", "conf_value", "conf_title", "conf_desc", "conf_status", "conf_type", "conf_spec", "conf_content", "conf_sort", "conf_system"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
'conf_title' => "参数名称必须填写",
|
||||
'conf_key' => "参数字段必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
'conf_title' => "参数名称必须填写",
|
||||
'conf_key' => "参数字段必须填写",
|
||||
];
|
||||
$this->model = new ConfModel();
|
||||
}
|
||||
/**
|
||||
* 获取列表接口基类
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
//从请求中获取排序方式
|
||||
$order = "conf_sort desc, conf_id asc";
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
/**
|
||||
* 读取基本配置
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getBaseConfig()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$datalist = $this->model->where('conf_status', 1)->order("conf_sort desc ".$this->pk . " asc")->select();
|
||||
foreach ($datalist as $key => $value) {
|
||||
if($value['conf_content']){
|
||||
$value['conf_content'] = explode("\n",$value['conf_content']);
|
||||
}
|
||||
}
|
||||
return jok('', $datalist);
|
||||
}
|
||||
/**
|
||||
* 更新基础配置
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateBaseConfig()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
foreach (input("post.") as $k => $v) {
|
||||
$map["conf_key"] = $k;
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
continue;
|
||||
}
|
||||
if(is_array($v)){
|
||||
$v = implode(",",$v);
|
||||
}
|
||||
$this->model->where("conf_key", $k)->update(["conf_value" => $v]);
|
||||
}
|
||||
return jok("配置修改成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//校验Insert字段是否填写
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Insert数据
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
|
||||
$res = $this->model->where('conf_key',$data['conf_key'])->find();
|
||||
if ($res) {
|
||||
return jerr("参数字段已存在");
|
||||
}
|
||||
|
||||
//添加这行数据
|
||||
$data['conf_value'] = '';
|
||||
$this->insertRow($data);
|
||||
return jok('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//校验Update字段是否填写
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Update数据
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
|
||||
$res = $this->model->where('conf_key',$data['conf_key'])->find();
|
||||
if ($res['conf_id']!= input("conf_id") && $res) {
|
||||
return jerr("参数字段已存在");
|
||||
}
|
||||
//根据主键更新这条数据
|
||||
$this->updateByPk($data);
|
||||
return jok('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口基类
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if($item['conf_system']==1){
|
||||
return jerr("系统参数,禁止删除", 404);
|
||||
}
|
||||
//单个操作
|
||||
$this->deleteBySingle();
|
||||
} else {
|
||||
//批量操作
|
||||
return jerr("暂不支持批量删除", 400);
|
||||
}
|
||||
return jok('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\QfShop;
|
||||
|
||||
class Error extends QfShop
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return jerr("admin not found", 404);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Filesystem;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Feedback as FeedbackModel;
|
||||
|
||||
class Feedback extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//查询列表时允许的字段
|
||||
$this->selectList = "*";
|
||||
//查询详情时允许的字段
|
||||
$this->selectDetail = "*";
|
||||
$this->model = new FeedbackModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
//从请求中获取排序方式
|
||||
$order = $this->getorderfromRequest();
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Group as GroupModel;
|
||||
|
||||
class Group extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"group_id" => "=", //相同筛选
|
||||
"group_name" => "like", //相似筛选
|
||||
];
|
||||
$this->insertFields = [
|
||||
"group_name", "group_desc"
|
||||
];
|
||||
$this->updateFields = [
|
||||
"group_name", "group_desc"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
'group_name' => "组名称必须填写"
|
||||
];
|
||||
$this->updateRequire = [
|
||||
'group_name' => "组名称必须填写"
|
||||
];
|
||||
$this->model = new GroupModel();
|
||||
}
|
||||
/**
|
||||
* 修改用户组
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (!isInteger($this->pk_value)) {
|
||||
return jerr("修改失败,参数错误", 400);
|
||||
}
|
||||
$item = $this->model->where($this->pk, $this->pk_value)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item[$this->pk] == 1) {
|
||||
return jerr("无法操作超级管理员组信息");
|
||||
}
|
||||
foreach ($this->updateRequire as $k => $v) {
|
||||
if (!input($k)) {
|
||||
return jerr($v);
|
||||
}
|
||||
}
|
||||
$data = [];
|
||||
foreach (input('post.') as $k => $v) {
|
||||
if (in_array($k, $this->updateFields)) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
}
|
||||
if (!input($this->table . "_name")) {
|
||||
return jerr("组名称必须填写", 400);
|
||||
}
|
||||
$data[$this->table . "_updatetime"] = time();
|
||||
$this->model->where($this->pk, $this->pk_value)->update($data);
|
||||
return jok('用户组信息更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用用户组
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item[$this->pk] == 1) {
|
||||
return jerr("无法操作超级管理员组信息");
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->where("group_id > 1")->update([
|
||||
$this->table . "_status" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("禁用用户组成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用用户组
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item[$this->pk] == 1) {
|
||||
return jerr("无法操作超级管理员组信息");
|
||||
}
|
||||
$this->model->where($map)->update([
|
||||
$this->table . "_status" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->where("group_id > 1")->update([
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("启用用户组成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户组
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
if ($item[$this->pk] == 1) {
|
||||
return jerr("无法删除超级管理员组");
|
||||
}
|
||||
$this->deleteBySingle();
|
||||
//删除对应ID的授权记录
|
||||
$this->authModel->where([
|
||||
"auth_group" => $this->pk_value
|
||||
])->delete();
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->where("group_id > 1")->delete();
|
||||
//删除对应ID的授权记录
|
||||
$this->authModel->where("auth_group", "in", $list)->delete();
|
||||
}
|
||||
return jok('删除用户组成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 为用户组授权节点
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (!isInteger($this->pk_value)) {
|
||||
return jerr("修改失败,参数错误", 400);
|
||||
}
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("用户组信息查询失败,授权失败", 404);
|
||||
}
|
||||
$this->authModel->where([
|
||||
"auth_group" => $this->pk_value
|
||||
])->delete();
|
||||
if ($item[$this->pk] == 1) {
|
||||
return jerr("超级管理组无需授权!");
|
||||
}
|
||||
$node_ids = explode(",", input("node_ids"));
|
||||
foreach ($node_ids as $node_id) {
|
||||
if (intval($node_id) == 0) {
|
||||
continue;
|
||||
}
|
||||
$this->authModel->insert([
|
||||
"auth_group" => $this->pk_value,
|
||||
"auth_node" => $node_id,
|
||||
"auth_createtime" => time(),
|
||||
"auth_updatetime" => time()
|
||||
]);
|
||||
}
|
||||
return jok('用户组授权成功');
|
||||
}
|
||||
/**
|
||||
* 获取用户组拥有的权限
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAuthorize()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (!isInteger($this->pk_value)) {
|
||||
return jerr("修改失败,参数错误", 400);
|
||||
}
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("用户组信息查询失败,授权失败", 404);
|
||||
}
|
||||
$myAuthorizeList = $this->authModel->where("auth_group", $this->pk_value)->select();
|
||||
return jok('ok', $myAuthorizeList);
|
||||
}
|
||||
/**
|
||||
* 获取所有用户组
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$dataList = $this->model->select();
|
||||
return jok('用户组列表获取成功', $dataList);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\QfShop;
|
||||
use think\facade\Config;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use util\Time;
|
||||
|
||||
class Index extends QfShop
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Node as NodeModel;
|
||||
|
||||
class Node extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"node_id" => "=", //相同筛选
|
||||
"node_show" => "=", //相同筛选
|
||||
"node_title" => "like", //相似筛选
|
||||
"node_desc" => "like", //相似筛选
|
||||
"node_module" => "like", //相似筛选
|
||||
"node_controller" => "like", //相似筛选
|
||||
"node_action" => "like", //相似筛选
|
||||
];
|
||||
$this->insertFields = [
|
||||
"node_title", "node_desc", "node_module", "node_action", "node_controller", "node_icon", "node_show", "node_pid", "node_order", "node_login", "node_access"
|
||||
];
|
||||
$this->updateFields = [
|
||||
"node_title", "node_desc", "node_module", "node_action", "node_controller", "node_icon", "node_show", "node_pid", "node_order", "node_login", "node_access"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
'node_title' => "节点名称必须填写",
|
||||
'node_module' => "节点模块必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
'node_title' => "节点名称必须填写",
|
||||
'node_module' => "节点模块必须填写",
|
||||
];
|
||||
$this->model = new NodeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加节点
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
$data['node_module'] = strtolower($data['node_module']);
|
||||
$data['node_controller'] = input("node_controller") ? strtolower($data['node_controller']) : "";
|
||||
$data['node_action'] = input("node_action") ? strtolower($data['node_action']) : "";
|
||||
$this->insertRow($data);
|
||||
return jok('用户添加成功');
|
||||
}
|
||||
/**
|
||||
* 更新节点
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
if (!isInteger($this->pk_value)) {
|
||||
return jerr("修改失败,参数错误", 400);
|
||||
}
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
if($item['node_id'] == $data['node_pid']){
|
||||
return jerr("不能选择自己为上级菜单", 404);
|
||||
}
|
||||
$data['node_module'] = strtolower($data['node_module']);
|
||||
$data['node_controller'] = input("node_controller") ? strtolower($data['node_controller']) : "";
|
||||
$data['node_action'] = input("node_action") ? strtolower($data['node_action']) : "";
|
||||
$this->updateByPk($data);
|
||||
return jok('节点信息更新成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除节点
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写");
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$map = [$this->pk => $this->pk_value];
|
||||
$item = $this->model->where($map)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败");
|
||||
}
|
||||
$this->deleteBySingle();
|
||||
//删除对应ID的授权记录
|
||||
$this->authModel->where("auth_node", $this->pk_value)->delete();
|
||||
} else {
|
||||
$this->deleteByMultiple();
|
||||
//删除对应ID的授权记录
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->authModel->where("auth_node", 'in', $list)->delete();
|
||||
}
|
||||
return jok('删除节点成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有节点
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$order = $this->table . "_order desc," . $this->pk . " asc";
|
||||
$map = [
|
||||
"node_pid" => 0
|
||||
];
|
||||
$datalist = $this->model->where($map)->order($order)->select();
|
||||
$subMap = $this->getDataFilterFromRequest();
|
||||
for ($i = 0; $i < count($datalist); $i++) {
|
||||
$subDatalist = $this->model->field($this->selectList)->where($subMap)->where($this->table . "_pid", $datalist[$i][$this->pk])->order($order)->select();
|
||||
$datalist[$i]['sub'] = $subDatalist;
|
||||
for ($j = 0; $j < count($datalist[$i]['sub']); $j++) {
|
||||
$subDatalist2 = $this->model->field($this->selectList)->where($subMap)->where($this->table . "_pid", $datalist[$i]['sub'][$j][$this->pk])->order($order)->select();
|
||||
$datalist[$i]['sub'][$j]['sub'] = $subDatalist2;
|
||||
}
|
||||
}
|
||||
return jok('success', [
|
||||
'data' => $datalist,
|
||||
'map' => $map
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 显示到菜单中
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_menu()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$this->model->where($this->pk, $this->pk_value)->update([
|
||||
$this->table . "_show" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->update([
|
||||
$this->table . "_show" => 1,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("显示成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从菜单中隐藏
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function hide_menu()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (isInteger($this->pk_value)) {
|
||||
$this->model->where($this->pk, $this->pk_value)->update([
|
||||
$this->table . "_show" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
} else {
|
||||
$list = explode(',', $this->pk_value);
|
||||
$this->model->where($this->pk, 'in', $list)->update([
|
||||
$this->table . "_show" => 0,
|
||||
$this->table . "_updatetime" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("隐藏成功");
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Sms as SmsModel;
|
||||
use app\model\Validate as ValidateModel;
|
||||
|
||||
class Sms extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->model = new SmsModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
//验证图形验证码
|
||||
$validateModel = new ValidateModel();
|
||||
$error = $validateModel->validateImgCode(input('token'), input('code'));
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (input("phone")) {
|
||||
$phone = input('phone');
|
||||
$code = cache("SMS_" . $phone);
|
||||
if ($code) {
|
||||
return jerr('发送短信太频繁,请稍候再试');
|
||||
}
|
||||
|
||||
$code = rand(100000, 999999);
|
||||
$error = $this->model->sendSms($phone, $code);
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
cache('SMS_' . $phone, $code, 300);
|
||||
return jok('短信验证码已经发送至你的手机');
|
||||
} else {
|
||||
return jerr("手机号为必填信息,请填写后提交");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,486 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Filesystem;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Source as SourceModel;
|
||||
use app\model\SourceLog as SourceLogModel;
|
||||
|
||||
class Source extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//第三方转存接口地址
|
||||
$this->url = "https://pan.xinyuedh.com";
|
||||
//查询列表时允许的字段
|
||||
$this->selectList = "*";
|
||||
//查询详情时允许的字段
|
||||
$this->selectDetail = "*";
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"source_id" => "=",
|
||||
"title"=>"like",
|
||||
];
|
||||
$this->insertFields = [
|
||||
//允许添加的字段列表
|
||||
"source_category_id","title","url","status","is_delete","sort","is_top"
|
||||
];
|
||||
$this->updateFields = [
|
||||
//允许更新的字段列表
|
||||
"source_category_id","title","url","status","is_delete","sort","is_top"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
//添加时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"title"=>"资源名称必须填写",
|
||||
"url"=>"资源地址必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
//修改时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"source_id"=>"资源ID必须填写",
|
||||
"title"=>"资源名称必须填写",
|
||||
"url"=>"资源地址必须填写",
|
||||
];
|
||||
$this->model = new SourceModel();
|
||||
$this->SourceLogModel = new SourceLogModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
$map[] = ['is_delete','=',0];
|
||||
if(!empty(input('source_category_id'))){
|
||||
$map[] = ['source_category_id','=',input('source_category_id')];
|
||||
}
|
||||
//从请求中获取排序方式
|
||||
$order = ['is_top' => 'desc','sort' => 'desc','source_id' => 'desc'];
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//校验Insert字段是否填写
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Insert数据
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
//添加这行数据
|
||||
$data["update_time"] = time();
|
||||
$data["create_time"] = time();
|
||||
$this->model->insertGetId($data);
|
||||
return jok('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//校验Update字段是否填写
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Update数据
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
//根据主键更新这条数据
|
||||
$data["update_time"] = time();
|
||||
$this->model->where($this->pk, $this->pk_value)->update($data);
|
||||
return jok('修改成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (!$this->pk_value) {
|
||||
return jerr($this->pk . "必须填写", 400);
|
||||
}
|
||||
|
||||
//根据主键获取一行数据
|
||||
$item = $this->getRowByPk();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
$this->model->where($this->pk, $this->pk_value)->delete();
|
||||
|
||||
return jok('删除成功');
|
||||
}
|
||||
|
||||
// 判断文件编码
|
||||
function detectFileEncoding($filename) {
|
||||
$handle = fopen($filename, 'r');
|
||||
$firstLine = fread($handle, 1024); // 读取文件的开头一部分内容
|
||||
fclose($handle);
|
||||
// 尝试使用不同的编码进行解码,并检查是否成功
|
||||
if (mb_check_encoding($firstLine, 'UTF-8')) {
|
||||
return 'UTF-8';
|
||||
} elseif (mb_check_encoding($firstLine, 'GBK')) {
|
||||
return 'GBK';
|
||||
} else {
|
||||
// 如果无法确定编码,则返回默认编码
|
||||
return 'UTF-8'; // 或者根据需要返回其他默认编码
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Excel导入
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function imports()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
// try {
|
||||
$file = request()->file('file');
|
||||
try {
|
||||
validate(['file' => 'filesize:' . config("qfshop.upload_max_file") . '|fileExt:' . config("qfshop.upload_file_type")])
|
||||
->check(['file' => $file]);
|
||||
$saveName = Filesystem::putFile('excel', $file, 'excel.csv');
|
||||
|
||||
ini_set("memory_limit",-1);
|
||||
|
||||
$file_name = app()->getRootPath()."public/uploads/".$saveName;
|
||||
|
||||
$extension = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
if ($extension == 'csv') {
|
||||
$PHPReader = new \PHPExcel_Reader_CSV();
|
||||
$encoding = $this->detectFileEncoding($file_name);
|
||||
$PHPReader->setInputEncoding($encoding);
|
||||
$PHPReader->setDelimiter(',');
|
||||
} elseif ($extension == 'xlsx') {
|
||||
$PHPReader = new \PHPExcel_Reader_Excel2007();
|
||||
} elseif ($extension == 'xls') {
|
||||
$PHPReader = new \PHPExcel_Reader_Excel5();
|
||||
} else {
|
||||
return jerr('不支持的文件类型');
|
||||
}
|
||||
|
||||
//载入文件
|
||||
$objExcel = $PHPReader->load($file_name);
|
||||
$excel_array = $objExcel ->getSheet(0)->toArray();
|
||||
array_shift($excel_array); //删除第一个数组(标题);
|
||||
$data = [];
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
//删除这个文件
|
||||
unlink("./uploads/".$saveName);
|
||||
|
||||
// 生成二维码
|
||||
foreach ($excel_array as $k => $v) {
|
||||
$patterns = '/^\d+\.|\d+\-/';
|
||||
$title = '';
|
||||
if (!empty($v[2]) && preg_match('/http[^ ]+/', $v[2], $matches)) {
|
||||
$title = preg_replace($patterns, '', $v[1]);
|
||||
$url = $matches[0];
|
||||
} else {
|
||||
if (!empty($v[3]) && preg_match('/http[^ ]+/', $v[3], $matches)) {
|
||||
$title = preg_replace($patterns, '', $v[2]);
|
||||
$url = $matches[0];
|
||||
} else {
|
||||
$url = '';
|
||||
}
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['title', '=',$title];
|
||||
$res = $this->model->where($map)->find();
|
||||
if (empty($res) && $url) {
|
||||
$data[$k]['title'] = $title;
|
||||
$data[$k]['url'] = $url;
|
||||
$data[$k]['source_category_id'] = input('source_category_id')??0;
|
||||
$data[$k]['update_time'] = time();
|
||||
$data[$k]['create_time'] = time();
|
||||
$i++;
|
||||
}else if($url){
|
||||
$this->model->where($map)->update(['url' => $url, 'update_time' => time()]);
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->model->insertAll($data);
|
||||
if($i == 0 && $j == 0){
|
||||
return jok('无可导入的资源,请检查表格格式');
|
||||
}
|
||||
return jok('导入成功'.$i.'个资源,更新成功'.$j.'个资源');
|
||||
|
||||
} catch (ValidateException $e) {
|
||||
return jerr($e->getMessage());
|
||||
}
|
||||
// } catch (\Exception $error) {
|
||||
// return jerr('上传文件失败,请检查你的文件!');
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键转存并分享夸克资源
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function transfer()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$url = input("url");
|
||||
$substring = strstr($url, 's/');
|
||||
if ($substring !== false) {
|
||||
$pwd_id = substr($substring, 2); // 去除 's/' 部分
|
||||
} else {
|
||||
return jerr("资源地址格式有误");
|
||||
}
|
||||
|
||||
|
||||
$logId = $this->SourceLogModel->addLog('一键转存他人链接',1);
|
||||
|
||||
$urlData = array(
|
||||
'cookie' => Config('qfshop.quark_cookie'),
|
||||
'url' => $url,
|
||||
);
|
||||
$res = curlHelper($this->url."/api/open/transfer", "POST", $urlData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
$this->SourceLogModel->editLog($logId,1,'fail_num',$res['message'],1);
|
||||
return jerr($res['message']);
|
||||
}
|
||||
$patterns = '/^\d+\./';
|
||||
$title = preg_replace($patterns, '', $res['data']['title']);
|
||||
//添加资源到系统中
|
||||
$data["title"] = $title;
|
||||
$data["url"] = $res['data']['share_url'];
|
||||
$data["update_time"] = time();
|
||||
$data["create_time"] = time();
|
||||
$this->model->insertGetId($data);
|
||||
$this->SourceLogModel->editLog($logId,1,'new_num','',1);
|
||||
|
||||
return jok('已提交任务,稍后查看结果',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部转存
|
||||
* 转存心悦搜剧资源
|
||||
* @return void
|
||||
*/
|
||||
public function transferAll()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
@set_time_limit(999999);
|
||||
//分页转存
|
||||
$page_no = 1;
|
||||
$dataList = '';
|
||||
$logId = '';
|
||||
while ($dataList=='' || !empty($dataList['items'])) {
|
||||
$searchData = array(
|
||||
'page_no' => $page_no,
|
||||
'page_size' => 100,
|
||||
'type' => 2,
|
||||
);
|
||||
$res = curlHelper($this->url."/api/search", "POST", $searchData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
return jerr($res['message']);
|
||||
}
|
||||
$dataList = $res['data'];
|
||||
$page_no++;
|
||||
|
||||
if($logId == ''){
|
||||
$logId = $this->SourceLogModel->addLog('全部转存',$dataList['total_result']);
|
||||
}
|
||||
|
||||
foreach ($dataList['items'] as $key => $value) {
|
||||
//如已有此资源 跳过
|
||||
$detail = $this->model->where('title', $value['title'])->find();
|
||||
if(!empty($detail)){
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'skip_num','重复跳过转存');
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $value['url'];
|
||||
$substring = strstr($url, 's/');
|
||||
|
||||
if ($substring !== false) {
|
||||
$pwd_id = substr($substring, 2); // 去除 's/' 部分
|
||||
} else {
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num','资源地址格式有误');
|
||||
continue;
|
||||
}
|
||||
|
||||
$urlData = array(
|
||||
'cookie' => Config('qfshop.quark_cookie'),
|
||||
'url' => $url,
|
||||
);
|
||||
$res = curlHelper($this->url."/api/open/transfer", "POST", $urlData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
if($res['message'] == 'capacity limit[{0}]'){
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num',$res['message']);
|
||||
break;
|
||||
}else{
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'fail_num',$res['message']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//添加资源到系统中
|
||||
$data["title"] = $value['title'];
|
||||
$data["url"] = $res['data']['share_url'];
|
||||
$data["update_time"] = time();
|
||||
$data["create_time"] = time();
|
||||
$this->model->insertGetId($data);
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'new_num','');
|
||||
}
|
||||
// 可以添加一个最大重试次数的限制,防止无限循环
|
||||
if ($page_no > 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->SourceLogModel->editLog($logId,$dataList['total_result'],'','',3);
|
||||
return jok('已提交任务,稍后查看结果',$dataList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取夸克网盘文件夹
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getFiles()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$urlData = array(
|
||||
'cookie' => Config('qfshop.quark_cookie'),
|
||||
);
|
||||
$res = curlHelper($this->url."/api/open/getFiles", "POST", $urlData)['body'];
|
||||
$res = json_decode($res, true);
|
||||
|
||||
if($res['code'] !== 200){
|
||||
return jerr($res['message']);
|
||||
}
|
||||
return jok('获取成功',$res['data']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function excel()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
//查询数据
|
||||
$map = [];
|
||||
$filter = input('');
|
||||
foreach ($filter as $k => $v) {
|
||||
if ($k == 'filter') {
|
||||
$k = input('filter');
|
||||
$v = input('keyword');
|
||||
}
|
||||
if ($v === '' || $v === null) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($k, $this->searchFilter)) {
|
||||
switch ($this->searchFilter[$k]) {
|
||||
case "like":
|
||||
array_push($map, [$k, 'like', "%" . $v . "%"]);
|
||||
break;
|
||||
case "=":
|
||||
array_push($map, [$k, '=', $v]);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$field = 'title,url';
|
||||
$dataList = $this->model->field($field)->where($map)->select();
|
||||
$excelField = [
|
||||
"title" => "资源名称",
|
||||
"url" => "资源地址",
|
||||
];
|
||||
$data = $dataList->toArray();
|
||||
|
||||
$this->excelField = $excelField;
|
||||
$this->exportExcelData($dataList);
|
||||
print_r(12);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,258 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use app\admin\QfShop;
|
||||
use app\model\SourceCategory as SourceCategoryModel;
|
||||
|
||||
class SourceCategory extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//查询列表时允许的字段
|
||||
$this->selectList = "*";
|
||||
//查询详情时允许的字段
|
||||
$this->selectDetail = "*";
|
||||
//筛选字段
|
||||
$this->searchFilter = [
|
||||
"source_category_id" => "=",
|
||||
"name"=>"like"
|
||||
];
|
||||
$this->insertFields = [
|
||||
//允许添加的字段列表
|
||||
"name","sort","status"
|
||||
];
|
||||
$this->updateFields = [
|
||||
//允许更新的字段列表
|
||||
"name","sort","status"
|
||||
];
|
||||
$this->insertRequire = [
|
||||
//添加时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"name"=>"分类名称必须填写",
|
||||
];
|
||||
$this->updateRequire = [
|
||||
//修改时必须填写的字段
|
||||
// "字段名称"=>"该字段不能为空"
|
||||
"name"=>"分类名称必须填写",
|
||||
];
|
||||
$this->model = new SourceCategoryModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表接口
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//查询数据
|
||||
$dataList = $this->model->order('sort', 'desc')->select();
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("没有查询到数据", 404);
|
||||
}
|
||||
return jok('数据加载成功', $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//校验Insert字段是否填写
|
||||
$error = $this->validateInsertFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Insert数据
|
||||
$data = $this->getInsertDataFromRequest();
|
||||
//添加这行数据
|
||||
$data['create_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$this->model->insertGetId($data);
|
||||
return jok('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//校验Update字段是否填写
|
||||
$error = $this->validateUpdateFields();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取Update数据
|
||||
$data = $this->getUpdateDataFromRequest();
|
||||
//根据主键更新这条数据
|
||||
$data['update_time'] = time();
|
||||
$this->model->where("source_category_id", $source_category_id)->update($data);
|
||||
return jok('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->delete();
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->delete();
|
||||
}
|
||||
return jok('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->update([
|
||||
"status" => 1,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->update([
|
||||
"status" => 1,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("禁用成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
$source_category_id = input("source_category_id");
|
||||
if (!$source_category_id) {
|
||||
return jerr("ID参数必须填写", 400);
|
||||
}
|
||||
if (isInteger($source_category_id)) {
|
||||
//根据主键获取一行数据
|
||||
$item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find();
|
||||
if (empty($item)) {
|
||||
return jerr("数据查询失败", 404);
|
||||
}
|
||||
//单个操作
|
||||
$map = ["source_category_id" => $source_category_id];
|
||||
$this->model->where($map)->update([
|
||||
"status" => 0,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
} else {
|
||||
//批量操作
|
||||
$list = explode(',', $source_category_id);
|
||||
$this->model->where("source_category_id", 'in', $list)->update([
|
||||
"status" => 0,
|
||||
"update_time" => time(),
|
||||
]);
|
||||
}
|
||||
return jok("启用成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Filesystem;
|
||||
use app\admin\QfShop;
|
||||
use app\model\SourceLog as SourceLogModel;
|
||||
|
||||
class SourceLog extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
//查询列表时允许的字段
|
||||
$this->selectList = "*";
|
||||
//查询详情时允许的字段
|
||||
$this->selectDetail = "*";
|
||||
$this->model = new SourceLogModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取列表接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
//校验Access与RBAC
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
//从请求中获取筛选数据的数组
|
||||
$map = $this->getDataFilterFromRequest();
|
||||
//从请求中获取排序方式
|
||||
$order = $this->getorderfromRequest();
|
||||
//设置Model中的 per_page
|
||||
$this->setGetListPerPage();
|
||||
//查询数据
|
||||
$dataList = $this->model->getListByPage($map, $order, $this->selectList);
|
||||
return jok('数据获取成功', $dataList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cache;
|
||||
use app\admin\QfShop;
|
||||
use app\model\Validate as ValidateModel;
|
||||
|
||||
class System extends QfShop
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
}
|
||||
/**
|
||||
* 获取图形验证码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getCaptcha()
|
||||
{
|
||||
// $error = $this->access();
|
||||
// if ($error) {
|
||||
// return $error;
|
||||
// }
|
||||
$validateModel = new ValidateModel();
|
||||
$imgData = $validateModel->getImg();
|
||||
$code = strtoupper($validateModel->getCode());
|
||||
$token = sha1($code . time()) . rand(100000, 999999);
|
||||
cache($token, $code, 60);
|
||||
return jok('验证码生成成功', [
|
||||
'img' => $imgData,
|
||||
'token' => $token
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 清除缓存
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
$error = $this->access();
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
Cache::clear();
|
||||
|
||||
if($this->del_dir("../runtime/")){
|
||||
return jok('缓存已清空');
|
||||
}else{
|
||||
return jerr('缓存清除失败');
|
||||
}
|
||||
}
|
||||
|
||||
function del_dir($dir) {
|
||||
$dh=opendir($dir);
|
||||
while ($file=readdir($dh)) {
|
||||
if($file!="." && $file!="..") {
|
||||
$fullpath=$dir."/".$file;
|
||||
if(!is_dir($fullpath)) {
|
||||
@unlink($fullpath);
|
||||
} else {
|
||||
$this->del_dir($fullpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
if(rmdir($dir)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user