代码功能更新
This commit is contained in:
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
use think\facade\Db;
|
||||
use laytp\BaseController;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
return redirect("/admin/index.html");
|
||||
}
|
||||
public function getnumber()
|
||||
{
|
||||
$uplist=Cache::get("getnumber");
|
||||
if(empty($uplist)){
|
||||
$url="http://git.zf789.life/kaifa/premium/graph";
|
||||
$html= file_get_contents($url);
|
||||
preg_match_all('/<span class="message tw-inline-block gt-ellipsis tw-mr-2">\s*<span>(.*?)<\/span>\s*<\/span>/', $html, $matches);
|
||||
$uplist=array();
|
||||
if ($matches[1]) {
|
||||
$messages = $matches[1]; // Array of all matched messages
|
||||
foreach ($messages as $message) {
|
||||
$uplist[]=$message;
|
||||
// var_dump($message);
|
||||
// Process each message
|
||||
}
|
||||
}
|
||||
|
||||
Cache::set("getnumber",$uplist,1024);
|
||||
}
|
||||
|
||||
//平台总用户
|
||||
$ptzuser=Db::name("member")->count();
|
||||
//平台托管机器人
|
||||
$ptzbot=Db::name("admin_bot")->count();
|
||||
//平台机器人总余额
|
||||
$ptzbotmoney=Db::name("admin_bot")->sum('money');
|
||||
//平台总利润
|
||||
$ptlirun=Db::name("order")->sum('lirun');
|
||||
|
||||
return $this->success('返回成功', ['uplist'=>$uplist,'ptzuser'=>$ptzuser,'ptzbot'=>$ptzbot,'ptzbotmoney'=>$ptzbotmoney,'ptlirun'=>$ptlirun]);
|
||||
}
|
||||
}
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use laytp\library\Tree;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 地区管理
|
||||
*/
|
||||
class Area extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* area模型对象
|
||||
* @var \app\model\Area
|
||||
*/
|
||||
protected $model;
|
||||
public $hasSoftDel = 1;//是否拥有软删除功能
|
||||
public $orderRule = ['sort' => 'DESC', 'id' => 'ASC'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\Area();
|
||||
}
|
||||
|
||||
//查看
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$sourceData = $this->model->where($where)->order($order)->with(['parent']);
|
||||
$isTree = $this->request->param('is_tree');
|
||||
if ($isTree) {
|
||||
$menuTreeObj = Tree::instance();
|
||||
$menuTreeObj->init($sourceData->select()->toArray());
|
||||
$data = $menuTreeObj->getRootTrees();
|
||||
} else {
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $sourceData->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $sourceData->select()->toArray();
|
||||
}
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
|
||||
$sourceData = $this->model->select()->toArray();
|
||||
$treeLib = Tree::instance();
|
||||
$treeLib->init($sourceData);
|
||||
$childIds = $treeLib->getChildIds($ids);
|
||||
|
||||
if ($this->model->destroy($childIds)) {
|
||||
return $this->success('数据删除成功');
|
||||
} else {
|
||||
return $this->error('数据删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
//回收站
|
||||
public function recycle()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $this->model->onlyTrashed()
|
||||
->with(['parent'])
|
||||
->order($order)->where($where)->paginate($limit)->toArray();
|
||||
return $this->success('回收站数据获取成功', $data);
|
||||
}
|
||||
|
||||
//设置排序
|
||||
public function setSort()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['sort'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+10
File diff suppressed because one or more lines are too long
Executable
+235
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\service\admin\UserServiceFacade;
|
||||
use app\service\ConfServiceFacade;
|
||||
use laytp\library\UploadDomain;
|
||||
use plugin\ali_oss\service\Oss;
|
||||
use plugin\qiniu_kodo\service\Kodo;
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Env;
|
||||
use think\facade\Filesystem;
|
||||
use think\File;
|
||||
|
||||
class Common extends Backend
|
||||
{
|
||||
protected $noNeedAuth = ['*'];
|
||||
protected $noNeedLogin = ['getLoginNeedCaptchaConf'];
|
||||
|
||||
/**
|
||||
* 获取登录后台是否需要验证码的配置
|
||||
* 这个接口是后台登录界面使用的,给这个接口独立的访问权限,无需登录,无需鉴权
|
||||
*/
|
||||
public function getLoginNeedCaptchaConf()
|
||||
{
|
||||
return $this->success('获取成功', ConfServiceFacade::get('system.basic.loginNeedCaptcha', 0));
|
||||
}
|
||||
|
||||
//上传接口
|
||||
public function upload()
|
||||
{
|
||||
try {
|
||||
$defaultType = ConfServiceFacade::get('system.upload.defaultType', 'local');
|
||||
$uploadType = $this->request->param('upload_type', 'default');
|
||||
if ($uploadType == 'default') $uploadType = $defaultType;
|
||||
if (!in_array($uploadType, ['local', 'ali-oss', 'qiniu-kodo'])) {
|
||||
return $this->error($uploadType . '上传方式未定义');
|
||||
}
|
||||
$file = $this->request->file('laytpUploadFile'); // 获取上传的文件
|
||||
if (!$file) {
|
||||
return $this->error('上传失败,请选择需要上传的文件');
|
||||
}
|
||||
$fileExt = strtolower($file->getOriginalExtension());
|
||||
$uploadDomain = new UploadDomain();
|
||||
if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt, $file->getMime())) {
|
||||
return $this->error($uploadDomain->getError());
|
||||
}
|
||||
$saveName = date("Ymd") . "/" . md5(uniqid(mt_rand())) . ".{$fileExt}";
|
||||
/**
|
||||
* 不能以斜杆开头
|
||||
* - 因为OSS存储时,不允许以/开头
|
||||
*/
|
||||
$uploadDir = $this->request->param('dir');
|
||||
$object = $uploadDir ? $uploadDir . '/' . $saveName : $saveName;//设置了上传目录的上传文件名
|
||||
$filePath = $object; //保存到lt_files中的path
|
||||
|
||||
//如果上传的是图片,验证图片的宽和高
|
||||
$accept = $this->request->param('accept');
|
||||
if ($accept == "image") {
|
||||
$width = $this->request->param('width');
|
||||
$height = $this->request->param('height');
|
||||
if ($width || $height) {
|
||||
$imageInfo = getimagesize($file->getFileInfo());
|
||||
if (($width && $imageInfo[0] > $width) || ($height && $imageInfo[1] > $height)) {
|
||||
return $this->error('上传失败,图片尺寸要求宽:' . $width . 'px,高:' . $height . 'px,实际上传文件[ ' . $file->getOriginalName() . ' ]的尺寸为宽' . $imageInfo[0] . 'px,高:' . $imageInfo[1] . 'px');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$inputValue = "";
|
||||
//上传至七牛云
|
||||
if ($uploadType == 'qiniu-kodo') {
|
||||
if (ConfServiceFacade::get('plugin.qiniu_kodo.switch') != 1) {
|
||||
return $this->error('未开启七牛云KODO存储,请到七牛云KODO配置中开启,如果未安装七牛云KODO存储插件,请先到插件市场进行安装');
|
||||
}
|
||||
$kodoConf = [
|
||||
'accessKey' => ConfServiceFacade::get('plugin.qiniu_kodo.accessKey'),
|
||||
'secretKey' => ConfServiceFacade::get('plugin.qiniu_kodo.secretKey'),
|
||||
'bucket' => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
|
||||
'domain' => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
|
||||
];
|
||||
$kodo = Kodo::instance();
|
||||
$kodoRes = $kodo->upload($file->getPathname(), $object, $kodoConf);
|
||||
if ($kodoRes) {
|
||||
$inputValue = $kodoRes;
|
||||
} else {
|
||||
return $this->error($kodo->getError());
|
||||
}
|
||||
}
|
||||
|
||||
//上传至阿里云
|
||||
if ($uploadType == 'ali-oss') {
|
||||
if (ConfServiceFacade::get('plugin.ali_oss.switch') != 1) {
|
||||
return $this->error('未开启阿里云OSS存储,请到阿里云OSS配置中开启');
|
||||
}
|
||||
$ossConf = [
|
||||
'accessKeyID' => ConfServiceFacade::get('plugin.ali_oss.accessKeyID'),
|
||||
'accessKeySecret' => ConfServiceFacade::get('plugin.ali_oss.accessKeySecret'),
|
||||
'bucket' => ConfServiceFacade::get('plugin.ali_oss.bucket'),
|
||||
'endpoint' => ConfServiceFacade::get('plugin.ali_oss.endpoint'),
|
||||
'domain' => ConfServiceFacade::get('plugin.ali_oss.domain'),
|
||||
];
|
||||
$oss = Oss::instance();
|
||||
$ossUploadRes = $oss->upload($file->getPathname(), $object, $ossConf);
|
||||
if ($ossUploadRes) {
|
||||
$inputValue = $ossUploadRes;
|
||||
} else {
|
||||
return $this->error($oss->getError());
|
||||
}
|
||||
}
|
||||
|
||||
//本地上传
|
||||
if ($uploadType == 'local') {
|
||||
$uploadDir = ltrim('/', $uploadDir);
|
||||
$saveName = Filesystem::putFileAs('/' . $uploadDir, $file, '/' . $object);
|
||||
$filePath = $saveName;
|
||||
$staticDomain = Env::get('domain.static');
|
||||
if ($staticDomain) {
|
||||
$inputValue = $staticDomain . '/storage/' . $saveName;
|
||||
} else {
|
||||
$inputValue = request()->domain() . '/static/storage/' . $saveName;
|
||||
}
|
||||
}
|
||||
|
||||
//将inputValue存入lt_files表中
|
||||
$filesModel = new \app\model\Files();
|
||||
$fileId = $filesModel->insertGetId([
|
||||
'category_id' => 0,
|
||||
'name' => $file->getOriginalName(),
|
||||
'file_type' => $this->request->param('accept'),
|
||||
'path' => $filePath,
|
||||
'upload_type' => $uploadType,
|
||||
'size' => $file->getSize(),
|
||||
'ext' => $file->getExtension(),
|
||||
'create_admin_user_id' => UserServiceFacade::getUser()->id,
|
||||
'update_admin_user_id' => UserServiceFacade::getUser()->id,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
return $this->success('上传成功', [
|
||||
'id' => $fileId,
|
||||
'path' => $inputValue,
|
||||
'name' => $file->getOriginalName(),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取阿里云sts的临时凭证,目前仅用于客户端直接上传到oss前获取到临时凭证进行上传
|
||||
public function aliSts()
|
||||
{
|
||||
if (ConfServiceFacade::get('plugin.ali_oss_sts.switch') != 1) {
|
||||
return $this->error('阿里云OSS存储的STS方式,请到阿里云STS配置中开启');
|
||||
}
|
||||
$uploadDomain = new UploadDomain();
|
||||
$fileName = $this->request->param('name');
|
||||
$fileSize = $this->request->param('size');
|
||||
$fileExt = $this->request->param('ext');
|
||||
if (!$uploadDomain->check($fileName, $fileSize, $fileExt, '')) {
|
||||
return $this->error($uploadDomain->getError());
|
||||
}
|
||||
$stsConf = [
|
||||
'accessKeyID' => ConfServiceFacade::get('plugin.ali_oss_sts.accessKeyID'),
|
||||
'accessKeySecret' => ConfServiceFacade::get('plugin.ali_oss_sts.accessKeySecret'),
|
||||
'ARN' => ConfServiceFacade::get('plugin.ali_oss_sts.ARN'),
|
||||
'endpoint' => ConfServiceFacade::get('plugin.ali_oss_sts.endpoint'),
|
||||
'domain' => ConfServiceFacade::get('plugin.ali_oss_sts.domain'),
|
||||
'bucket' => ConfServiceFacade::get('plugin.ali_oss_sts.bucket'),
|
||||
];
|
||||
$oss = Oss::instance();
|
||||
$sts = $oss->sts($stsConf);
|
||||
$file = new File('', false);
|
||||
|
||||
if ($sts) {
|
||||
return $this->success('sts获取成功', [
|
||||
'sts' => $sts,
|
||||
'path' => str_replace('\\', '/', $file->hashName()) . $fileExt,
|
||||
'index' => $this->request->param('index'),
|
||||
]);
|
||||
} else {
|
||||
return $this->error('sts获取失败,' . $oss->getError());
|
||||
}
|
||||
}
|
||||
|
||||
// 获取kodo上传凭证token
|
||||
public function kodoToken()
|
||||
{
|
||||
if (ConfServiceFacade::get('plugin.qiniu_kodo.switch') != 1) {
|
||||
return $this->error('未开启七牛云KODO存储,请到七牛云KODO配置中开启');
|
||||
}
|
||||
$uploadDomain = new UploadDomain();
|
||||
$fileName = $this->request->param('name');
|
||||
$fileSize = $this->request->param('size');
|
||||
$fileExt = $this->request->param('ext');
|
||||
if (!$uploadDomain->check($fileName, $fileSize, $fileExt, '')) {
|
||||
return $this->error($uploadDomain->getError());
|
||||
}
|
||||
$kodoConf = [
|
||||
'accessKey' => ConfServiceFacade::get('plugin.qiniu_kodo.accessKey'),
|
||||
'secretKey' => ConfServiceFacade::get('plugin.qiniu_kodo.secretKey'),
|
||||
'domain' => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
|
||||
'bucket' => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
|
||||
];
|
||||
$kodo = Kodo::instance();
|
||||
$token = $kodo->token($kodoConf);
|
||||
$file = new File('', false);
|
||||
|
||||
if ($token) {
|
||||
return $this->success('KodoToken获取成功', [
|
||||
'token' => $token,
|
||||
'domain' => ConfServiceFacade::get('plugin.qiniu_kodo.domain'),
|
||||
'bucket' => ConfServiceFacade::get('plugin.qiniu_kodo.bucket'),
|
||||
'path' => str_replace('\\', '/', $file->hashName()) . $fileExt,
|
||||
'index' => $this->request->param('index'),
|
||||
]);
|
||||
} else {
|
||||
return $this->error('KodoToken获取失败,' . $kodo->getError());
|
||||
}
|
||||
}
|
||||
|
||||
//解锁屏幕
|
||||
function unLockScreen()
|
||||
{
|
||||
$password = $this->request->post('password');
|
||||
$userId = UserServiceFacade::getUser()->id;
|
||||
$passwordHash = User::where('id', '=', $userId)->value('password');
|
||||
if (!password_verify(md5($password), $passwordHash)) {
|
||||
return $this->error('解锁失败,密码错误');
|
||||
} else {
|
||||
return $this->success('解锁成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\service\ConfServiceFacade;
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use laytp\library\UploadDomain;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 系统配置控制器
|
||||
* Class Conf
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Conf extends Backend
|
||||
{
|
||||
protected $model;
|
||||
protected $noNeedAuth = ['getGroupConf', 'saveGroupConf'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\Conf();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个分组下所有的配置项
|
||||
*/
|
||||
public function getGroupConf()
|
||||
{
|
||||
$group = $this->request->param('group');
|
||||
$return = ConfServiceFacade::groupGet($group, true);
|
||||
return $this->success('获取成功', $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
public function saveGroupConf()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if (isset($post['laytpUploadFile'])) {
|
||||
unset($post['laytpUploadFile']);
|
||||
}
|
||||
$group = $post['group'];
|
||||
unset($post['group']);
|
||||
$formType = $post['form_type'];
|
||||
unset($post['form_type']);
|
||||
$allConf = [];
|
||||
foreach ($post as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$temp = [];
|
||||
foreach ($value['key'] as $arrK => $arrV) {
|
||||
if ($arrV) {
|
||||
$temp[$arrV] = $value['value'][$arrK];
|
||||
}
|
||||
}
|
||||
$value = $temp;
|
||||
}
|
||||
$conf['group'] = $group;
|
||||
$conf['key'] = $key;
|
||||
$conf['value'] = $value;
|
||||
$conf['form_type'] = $formType[$key];
|
||||
$allConf[] = $conf;
|
||||
}
|
||||
ConfServiceFacade::groupSet($allConf);
|
||||
return $this->success('保存成功', $allConf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除某个分组下某个key的配置信息
|
||||
* 这个不在配置页面进行调用,后续要做生成工具的时候统一管理所有的key
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
$group = $this->request->param('group');
|
||||
$key = $this->request->param('key');
|
||||
ConfServiceFacade::del($group, $key);
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use app\service\admin\UserServiceFacade;
|
||||
use laytp\library\CommonFun;
|
||||
use laytp\library\UploadDomain;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 附件管理
|
||||
*/
|
||||
class Files extends Backend
|
||||
{
|
||||
/**
|
||||
* files模型对象
|
||||
* @var \app\model\Files
|
||||
*/
|
||||
protected $model;
|
||||
public $hasSoftDel = 1;//是否拥有软删除功能
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new \app\model\Files();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order)->with(['category', 'createAdminUser'=>['avatarFile']]);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
return $this->error('当前版本暂时不支持在附件管理中添加附件');
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$post['create_admin_user_id'] = UserServiceFacade::getUser()->id;
|
||||
$post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
|
||||
$post['path'] = UploadDomain::singleDelUploadDomain($post['path']);
|
||||
if ($this->model->create($post)) {
|
||||
return $this->success('添加成功', $post);
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//不经过服务器方式上传成功后,回调的ajax请求地址,将上传成功的文件信息存入表中
|
||||
public function unViaSave()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$post['create_admin_user_id'] = UserServiceFacade::getUser()->id;
|
||||
$post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
|
||||
$post['create_time'] = date('Y-m-d H:i:s');
|
||||
$post['update_time'] = date('Y-m-d H:i:s');
|
||||
$post['id'] = $this->model->insertGetId($post);
|
||||
if ($post['id']) {
|
||||
return $this->success('添加成功', $post);
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit()
|
||||
{
|
||||
return $this->error('当前版本暂时不支持在附件管理中编辑附件');
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$post['update_admin_user_id'] = UserServiceFacade::getUser()->id;
|
||||
$post['path'] = UploadDomain::singleDelUploadDomain($post['path']);
|
||||
foreach ($post as $k => $v) {
|
||||
$info->$k = $v;
|
||||
}
|
||||
try {
|
||||
$updateRes = $info->save();
|
||||
if ($updateRes) {
|
||||
return $this->success('编辑成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未做修改');
|
||||
} else if ($updateRes === null) {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
$ids = array_filter($this->request->post('ids'));
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
try {
|
||||
if ($this->model->destroy($ids)) {
|
||||
return $this->success('数据删除成功');
|
||||
} else {
|
||||
return $this->error('数据删除失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//回收站
|
||||
public function recycle()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $this->model->onlyTrashed()
|
||||
->with(['category', 'createAdminUser', 'updateAdminUser'])
|
||||
->order($order)->where($where)->paginate($limit)->toArray();
|
||||
return $this->success('回收站数据获取成功', $data);
|
||||
}
|
||||
}
|
||||
Executable
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
use laytp\library\CommonFun;
|
||||
use app\validate\admin\member\Add;
|
||||
use app\validate\admin\member\Edit;
|
||||
use laytp\library\Str;
|
||||
use laytp\library\UploadDomain;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
*/
|
||||
class Member extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* member模型对象
|
||||
* @var \app\model\Member
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel=1;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\Member();
|
||||
}
|
||||
|
||||
|
||||
//查看和搜索列表
|
||||
public function index(){
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order)->with(['avatar_pic_file']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new Add();
|
||||
if(!$validate->check($post)){
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
if(isset($post['password']) && $post['password']) $post['password'] = Str::createPassword($post['password']);
|
||||
try {
|
||||
if ($this->model->create($post)) {
|
||||
return $this->success('添加成功', $post);
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->with(['avatar_pic_file'])->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
|
||||
//编辑
|
||||
public function edit(){
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new Edit();
|
||||
if(!$validate->check($post)){
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
if(!$post['password']){
|
||||
unset($post['password']);
|
||||
}else{
|
||||
$post['password'] = Str::createPassword($post['password']);
|
||||
}
|
||||
foreach ($post as $k => $v) {
|
||||
$info->$k = $v;
|
||||
}
|
||||
try {
|
||||
$updateRes = $info->save();
|
||||
if ($updateRes) {
|
||||
return $this->success('编辑成功');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//设置账号状态
|
||||
public function setStatus()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['status'] = $fieldVal;
|
||||
try {
|
||||
if($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+267
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\service\admin\UserServiceFacade;
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use laytp\library\Tree;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 菜单控制器
|
||||
*/
|
||||
class Menu extends Backend
|
||||
{
|
||||
public $noNeedAuth = ['getMenuTree', 'getTree'];
|
||||
public $model;
|
||||
public $orderRule = ['sort' => 'desc', 'id' => 'asc'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\Menu();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$sourceData = $this->model->where($where)->order($order);
|
||||
$isTree = $this->request->param('is_tree');
|
||||
if ($isTree) {
|
||||
$menuTreeObj = Tree::instance();
|
||||
$menuTreeObj->init($sourceData->select()->toArray());
|
||||
$data = $menuTreeObj->getRootTrees();
|
||||
} else {
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $sourceData->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $sourceData->select()->toArray();
|
||||
}
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
//获取当前登录者的权限列表,返回树形数据,角色管理赋予权限时用到
|
||||
public function getTree()
|
||||
{
|
||||
$user = UserServiceFacade::getUser();
|
||||
if ($user->is_super_manager === 1) {
|
||||
$sourceData = $this->model->order($this->orderRule)->select()->toArray();
|
||||
} else {
|
||||
$roleIds = \app\model\admin\role\User::where('admin_user_id', '=', $user->id)
|
||||
->column('admin_role_id');
|
||||
$menuIds = \app\model\admin\menu\Role::where('admin_role_id', 'in', $roleIds)
|
||||
->column('admin_menu_id');
|
||||
$where[] = ['id', 'in', $menuIds];
|
||||
$sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
|
||||
}
|
||||
$menuTreeObj = Tree::instance();
|
||||
$menuTreeObj->init($sourceData);
|
||||
//由列表数据转化成树形结构数据
|
||||
$data = $menuTreeObj->getRootTrees();
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
//获取当前登录者的菜单列表,返回树形数据,仅返回is_menu=1的列表,后台菜单列表展示使用
|
||||
public function getMenuTree()
|
||||
{
|
||||
$user = UserServiceFacade::getUser();
|
||||
$where[] = ['is_show', '=', 1];
|
||||
$where[] = ['is_menu', '=', 1];
|
||||
if ($user->is_super_manager === 1) {
|
||||
$sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
|
||||
} else {
|
||||
$roleIds = \app\model\admin\role\User::where('admin_user_id', '=', $user->id)
|
||||
->column('admin_role_id');
|
||||
$menuIds = \app\model\admin\menu\Role::where('admin_role_id', 'in', $roleIds)
|
||||
->column('admin_menu_id');
|
||||
$where[] = ['id', 'in', $menuIds];
|
||||
$sourceData = $this->model->order($this->orderRule)->where($where)->select()->toArray();
|
||||
}
|
||||
$menuTreeObj = Tree::instance();
|
||||
$menuTreeObj->init($sourceData);
|
||||
//由列表数据转化成树形结构数据
|
||||
$data = $menuTreeObj->getRootTrees();
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
if ($post['rule'] && substr($post['rule'], 0, 1) != '/') {
|
||||
$post['rule'] = '/' . $post['rule'];
|
||||
}
|
||||
if ($this->model->create($post)) {
|
||||
return $this->success('添加成功', $post);
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
if ($post['rule'] && substr($post['rule'], 0, 1) != '/') {
|
||||
$post['rule'] = '/' . $post['rule'];
|
||||
}
|
||||
if ($id == $post['pid']) {
|
||||
return $this->error('不能将上级改成自己');
|
||||
}
|
||||
foreach ($post as $k => $v) {
|
||||
$info->$k = $v;
|
||||
}
|
||||
$update_res = $info->save();
|
||||
if ($update_res) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($update_res === 0) {
|
||||
return $this->success('未做修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
|
||||
$sourceData = $this->model->select()->toArray();
|
||||
$treeLib = Tree::instance();
|
||||
$treeLib->init($sourceData);
|
||||
$childIds = $treeLib->getChildIds($ids);
|
||||
|
||||
if ($this->model->destroy($childIds)) {
|
||||
return $this->success('数据删除成功', $childIds);
|
||||
} else {
|
||||
return $this->error('数据删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
//设置排序
|
||||
public function setSort()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['sort'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//设置是否为菜单
|
||||
public function setIsMenu()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['is_menu'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//设置是否显示
|
||||
public function setIsShow()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['is_show'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
// 复制菜单
|
||||
public function copy()
|
||||
{
|
||||
$pid = (int)$this->request->post('pid');
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
|
||||
$data = \app\model\admin\Menu::where('id', 'in', $ids)
|
||||
->withoutField('id')->select()
|
||||
->each(function ($item) use ($pid) {
|
||||
$item->pid = $pid;
|
||||
})->toArray();
|
||||
|
||||
$insert = $this->model->insertAll($data);
|
||||
if ($insert) {
|
||||
return $this->success('复制成功');
|
||||
} else {
|
||||
return $this->error('复制失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 移动菜单
|
||||
public function move()
|
||||
{
|
||||
$pid = (int)$this->request->post('pid');
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
|
||||
$save = \app\model\admin\Menu::where('id', 'in', $ids)
|
||||
->save(['pid' => $pid]);
|
||||
|
||||
if ($save) {
|
||||
return $this->success('移动成功');
|
||||
} else {
|
||||
return $this->error('移动失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+158
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
use laytp\library\CommonFun;
|
||||
use app\validate\admin\bot\Add;
|
||||
use app\validate\admin\bot\Edit;
|
||||
use laytp\library\Str;
|
||||
use laytp\library\UploadDomain;
|
||||
use app\service\Telegram as Telegrambot;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
*/
|
||||
class Order extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* member模型对象
|
||||
* @var \app\model\Bot
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel=1;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\Order();
|
||||
}
|
||||
|
||||
|
||||
//查看和搜索列表
|
||||
public function index(){
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
//var_dump($where,$order);
|
||||
$data = $this->model->where($where)->order($order)->with(['avatar_pic_file']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new Add();
|
||||
if(!$validate->check($post)){
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
try {
|
||||
if ($this->model->create($post)) {
|
||||
return $this->success('添加成功', $post);
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
//webhook
|
||||
public function webhook(){
|
||||
$botkey = $this->request->param('botkey');
|
||||
$id = $this->request->param('id');
|
||||
$botid = explode(":", $botkey)[0];
|
||||
$webhookdm = Request::domain() . '/api.Telegram/callback?botid='.$botid;
|
||||
$Telegrambot=new Telegrambot($botkey);
|
||||
$Telegrambot->setWebhook($webhookdm);
|
||||
$me=$Telegrambot->getme();
|
||||
$first_name=isset($me["result"]['first_name'])?$me["result"]['first_name']:"";
|
||||
$username=isset($me["result"]['username'])?$me["result"]['username']:"";
|
||||
|
||||
|
||||
$updateRes = $this->model->where('id', '=', $id)->update(['botid'=>$botid,'botuser'=>$username,'first_name'=>$first_name]);
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
//编辑
|
||||
public function edit(){
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
//var_dump($info);
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new Edit();
|
||||
if(!$validate->check($post)){
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
|
||||
foreach ($post as $k => $v) {
|
||||
$info->$k = $v;
|
||||
}
|
||||
try {
|
||||
$updateRes = $info->save();
|
||||
if ($updateRes) {
|
||||
return $this->success('编辑成功');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//设置账号状态
|
||||
public function setStatus()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['status'] = $fieldVal;
|
||||
try {
|
||||
if($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+151
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\service\admin\PluginsServiceFacade;
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\Http;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 插件管理
|
||||
*/
|
||||
class Plugins extends Backend
|
||||
{
|
||||
/**
|
||||
* files模型对象
|
||||
* @var \app\model\Files
|
||||
*/
|
||||
protected $model;
|
||||
public $hasSoftDel = 1;//是否拥有软删除功能
|
||||
|
||||
// 获取laytp官网定义的插件分类列表
|
||||
public function category()
|
||||
{
|
||||
$url = Config::get('plugin.apiUrl') . '/plugins/category';
|
||||
$data = json_decode(Http::get($url), true)['data'];
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
// 查看
|
||||
public function index()
|
||||
{
|
||||
$params['page'] = $this->request->param('page', 1);
|
||||
$params['limit'] = $this->request->param('limit', 10);
|
||||
$params['category_id'] = $this->request->param('category_id', 0);
|
||||
$url = Config::get('plugin.apiUrl') . '/plugins/index';
|
||||
$data = json_decode(Http::get($url, $params), true)['data'];
|
||||
$installed = Config::get('plugin.installed');
|
||||
foreach ($data['data'] as $k => $datum) {
|
||||
if ($installed && in_array($datum['alias'], $installed)) {
|
||||
$data['data'][$k]['installed'] = 1;
|
||||
$pluginInfo = PluginsServiceFacade::getPluginInfo($datum['alias']);
|
||||
if (isset($pluginInfo['version'])) {
|
||||
$version = $pluginInfo['version'];
|
||||
} else {
|
||||
$version = '1.0.0';
|
||||
}
|
||||
$data['data'][$k]['version'] = $version;
|
||||
} else {
|
||||
$data['data'][$k]['installed'] = 2;
|
||||
}
|
||||
}
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
// 离线安装 - 所有的离线安装都是覆盖安装
|
||||
public function offLineInstall()
|
||||
{
|
||||
if (PluginsServiceFacade::offLineInstall()) {
|
||||
sleep(1);
|
||||
$file = request()->file('laytpUploadFile'); // 获取上传的文件
|
||||
$pluginConf = Config::get('plugin');
|
||||
$fileName = $file->getOriginalName();
|
||||
$pathinfo = pathinfo($fileName);
|
||||
$plugin = $pathinfo['filename'];
|
||||
$pluginConf['installed'][] = $plugin;
|
||||
$pluginConf['installed'] = array_unique($pluginConf['installed']);
|
||||
sort($pluginConf['installed']);
|
||||
|
||||
$info = PluginsServiceFacade::getPluginInfo($plugin);
|
||||
if(isset($info['is_editor']) && $info['is_editor']){
|
||||
$pluginConf['installedEditor'][] = $plugin;
|
||||
$pluginConf['installedEditor'] = array_unique($pluginConf['installedEditor']);
|
||||
sort($pluginConf['installedEditor']);
|
||||
}
|
||||
|
||||
return $this->success('安装成功', [
|
||||
'pluginConf' => $pluginConf
|
||||
]);
|
||||
} else {
|
||||
return $this->error(PluginsServiceFacade::getError());
|
||||
}
|
||||
}
|
||||
|
||||
// 卸载
|
||||
public function uninstall()
|
||||
{
|
||||
$plugin = $this->request->param('plugin');
|
||||
$info = PluginsServiceFacade::getPluginInfo($plugin);
|
||||
|
||||
if (PluginsServiceFacade::unInstall($plugin)) {
|
||||
$pluginConf = Config::get('plugin');
|
||||
foreach($pluginConf['installed'] as $k=>$installed){
|
||||
if($installed === $plugin) unset($pluginConf['installed'][$k]);
|
||||
}
|
||||
$pluginConf['installed'] = array_unique($pluginConf['installed']);
|
||||
sort($pluginConf['installed']);
|
||||
|
||||
if(isset($info['is_editor']) && $info['is_editor']){
|
||||
foreach($pluginConf['installedEditor'] as $k=>$installedEditor){
|
||||
if($installedEditor === $plugin) unset($pluginConf['installedEditor'][$k]);
|
||||
}
|
||||
$pluginConf['installedEditor'] = array_unique($pluginConf['installedEditor']);
|
||||
sort($pluginConf['installedEditor']);
|
||||
// 如果根目录下有相应的html文件,将文件内容进行替换
|
||||
$htmlFile = root_path() . 'public/admin/' . $plugin . '.html';
|
||||
if(is_file($htmlFile)){
|
||||
file_put_contents($htmlFile, '<p style="color:blue">请先到插件市场安装' . $plugin . '编辑器。</p>
|
||||
<p style="color:red">注意:安装或卸载编辑器后,需要清空浏览器缓存才能生效</p>');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($plugin . '插件卸载成功', [
|
||||
'pluginConf' => $pluginConf,
|
||||
'info' => $info
|
||||
]);
|
||||
} else {
|
||||
return $this->error(PluginsServiceFacade::getError());
|
||||
}
|
||||
}
|
||||
|
||||
// 安装
|
||||
public function install()
|
||||
{
|
||||
$plugin = $this->request->param('plugin');
|
||||
$laytpGwToken = $this->request->param('laytpGwToken');
|
||||
|
||||
if (PluginsServiceFacade::install($plugin, $laytpGwToken)) {
|
||||
// 如果是文件存储,插件安装信息,刚安装完成马上要取出来,取出来的不会是最新的文件内容
|
||||
sleep(1);
|
||||
$pluginConf = Config::get('plugin');
|
||||
$pluginConf['installed'][] = $plugin;
|
||||
$pluginConf['installed'] = array_unique($pluginConf['installed']);
|
||||
sort($pluginConf['installed']);
|
||||
|
||||
$info = PluginsServiceFacade::getPluginInfo($plugin);
|
||||
if(isset($info['is_editor']) && $info['is_editor']){
|
||||
$pluginConf['installedEditor'][] = $plugin;
|
||||
$pluginConf['installedEditor'] = array_unique($pluginConf['installedEditor']);
|
||||
sort($pluginConf['installedEditor']);
|
||||
}
|
||||
|
||||
return $this->success($plugin . '插件安装成功', [
|
||||
'pluginConf' => $pluginConf
|
||||
]);
|
||||
} else {
|
||||
$error = PluginsServiceFacade::getError();
|
||||
return $this->error($error['msg'], $error['code']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+177
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*/
|
||||
class Role extends Backend
|
||||
{
|
||||
protected $noNeedAuth = ['getMenuIds'];
|
||||
|
||||
public $model;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\Role();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* all_data参数的值为true时,表示查询表中所有数据集,否则进行分页查询
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加,同时添加lt_plugin_core_role和lt_plugin_core_role_menu两个表的数据
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$roleInfo = $this->model->getByName($post['name']);
|
||||
if ($roleInfo) throw new \Exception('角色名已存在');
|
||||
|
||||
$menuIds = explode(',', $post['menu_ids']);
|
||||
unset($post['menu_ids']);
|
||||
$saveMenu = $this->model->save($post);
|
||||
if (!$saveMenu) throw new \Exception('保存角色基本信息失败');
|
||||
|
||||
$saveAllData = [];
|
||||
foreach ($menuIds as $menu_id) {
|
||||
$saveAllData[] = [
|
||||
'admin_role_id' => $this->model->id,
|
||||
'admin_menu_id' => $menu_id,
|
||||
];
|
||||
}
|
||||
$menu = new \app\model\admin\menu\Role();
|
||||
$saveAllMenu = $menu->saveAll($saveAllData);
|
||||
if (!$saveAllMenu) throw new \Exception('保存角色权限失败');
|
||||
|
||||
Db::commit();
|
||||
return $this->success('操作成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑,同时编辑lt_plugin_core_role和lt_plugin_core_role_menu两个表的数据
|
||||
* @return bool|\think\response\Json
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
|
||||
$postData = Request::only(['id', 'name', 'menu_ids']);
|
||||
$post = CommonFun::filterPostData($postData);
|
||||
|
||||
$roleInfo = $this->model->getByName($post['name']);
|
||||
if ($roleInfo && ($roleInfo['id'] != $id)) {
|
||||
return $this->error('角色名已存在');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$menuIds = explode(',', $post['menu_ids']);
|
||||
unset($post['menu_ids']);
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($post);
|
||||
if (!is_numeric($updateRes)) throw new \Exception('保存角色基本信息失败');
|
||||
|
||||
$delRes = \app\model\admin\menu\Role::where('admin_role_id', '=', $id)->delete();
|
||||
if (!is_numeric($delRes)) throw new \Exception('删除角色权限失败');
|
||||
|
||||
$saveAllData = [];
|
||||
foreach ($menuIds as $menu_id) {
|
||||
$saveAllData[] = [
|
||||
'admin_role_id' => $id,
|
||||
'admin_menu_id' => $menu_id,
|
||||
];
|
||||
}
|
||||
$menu = new \app\model\admin\menu\Role();
|
||||
$menu->saveAll($saveAllData);
|
||||
|
||||
Db::commit();
|
||||
return $this->success('操作成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 真实删除
|
||||
* lt_admin_role、lt_admin_menu_role、lt_admin_role_user三表数据都要真实删除
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function trueDel()
|
||||
{
|
||||
$ids = $this->request->param('ids');
|
||||
Db::startTrans();
|
||||
try {
|
||||
$roles = $this->model->onlyTrashed()->where('id', 'in', $ids)->select();
|
||||
foreach ($roles as $key => $item) {
|
||||
$delRes = $item->force()->delete();
|
||||
if (!$delRes) throw new \Exception('角色删除失败');
|
||||
}
|
||||
$delRes = \app\model\admin\menu\Role::where('admin_role_id', 'in', $ids)->delete();
|
||||
if (!is_numeric($delRes)) throw new \Exception('角色权限删除失败');
|
||||
|
||||
$delRes = \app\model\admin\role\User::where('admin_role_id', 'in', $ids)->delete();
|
||||
if (!is_numeric($delRes)) throw new \Exception('角色用户删除失败');
|
||||
|
||||
Db::commit();
|
||||
return $this->success('操作成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取编辑页面权限设置应该选中的菜单id
|
||||
* 只能获取最低级别的菜单id,有子菜单的菜单id不能返回
|
||||
* 原因:比如tree.setChecked('auth_node',1);会选中整棵树,因为layui的树组件,模拟点击了树的首节点
|
||||
* @return false|string|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getMenuIds()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$menuIds = \app\model\admin\menu\Role::where('admin_role_id', '=', $id)->column('admin_menu_id');
|
||||
$auth = [];
|
||||
foreach ($menuIds as $menuId) {
|
||||
$hasChild = \app\model\admin\Menu::where('pid', '=', $menuId)->find() ? true : false;
|
||||
if (!$hasChild) {
|
||||
$auth[] = $menuId;
|
||||
}
|
||||
}
|
||||
return $this->success('获取成功', $auth);
|
||||
}
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
use laytp\library\CommonFun;
|
||||
use app\validate\admin\bot\Add;
|
||||
use app\validate\admin\bot\Edit;
|
||||
use laytp\library\Str;
|
||||
use think\facade\App;
|
||||
use laytp\library\UploadDomain;
|
||||
use app\service\Telegram as Telegrambot;
|
||||
use think\facade\Request;
|
||||
use GitWrapper\GitWrapper;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
*/
|
||||
class Updata extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* member模型对象
|
||||
* @var \app\model\Bot
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel=1;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//查看和搜索列表
|
||||
//查看和搜索列表
|
||||
public function index(){
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
//var_dump($where,$order);
|
||||
$data = $this->model->where($where)->order($order)->with(['avatar_pic_file']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
//添加
|
||||
public function updata()
|
||||
{
|
||||
|
||||
$repoPath = App::getRootPath();
|
||||
$output = shell_exec("cd {$repoPath} && git pull 2>&1");
|
||||
|
||||
// 输出结果
|
||||
echo "Git Pull Output:\n";
|
||||
echo $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Executable
+306
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\admin\login\Log;
|
||||
use app\service\admin\AuthServiceFacade;
|
||||
use app\service\admin\UserServiceFacade;
|
||||
use app\validate\admin\user\Add;
|
||||
use app\validate\admin\user\Edit;
|
||||
use app\validate\admin\user\Login;
|
||||
use app\validate\admin\user\singleEdit;
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use laytp\library\Random;
|
||||
use laytp\library\Str;
|
||||
use laytp\library\Token;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 后台管理员控制器
|
||||
*/
|
||||
class User extends Backend
|
||||
{
|
||||
protected $model;
|
||||
//当前模型对象
|
||||
protected $noNeedLogin = ['login', 'logout'];
|
||||
protected $noNeedAuth = ['loginInfo', 'singleEdit'];
|
||||
|
||||
protected function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\User();
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
//获取表单提交数据
|
||||
$param = $this->request->post();
|
||||
//防止密码爆破
|
||||
$fail = Cache::get('laytp-admin-login-num-' . $param['username'], 1);
|
||||
if ($fail >= 5) return $this->error('失败次数过多,请三分钟后再试');
|
||||
//验证表单提交
|
||||
$validate = new Login();
|
||||
if (!$validate->check($param)) {
|
||||
$param['password'] = '******';
|
||||
//登录失败也不记录用户密码
|
||||
Log::create([
|
||||
'login_status' => 2,
|
||||
'admin_id' => 0,
|
||||
'request_body' => json_encode($param),
|
||||
'request_header' => json_encode($this->request->header()),
|
||||
'ip' => $this->request->ip(),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
Cache::set('laytp-admin-login-num-' . $param['username'], $fail + 1, 180);
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
//设置登录信息
|
||||
$loginUserInfo = \app\model\admin\User::where('username', '=', $param['username'])
|
||||
->with(['avatar_file'])->field(UserServiceFacade::getAllowFields())->findOrEmpty();
|
||||
$loginUserInfo->login_time = date('Y-m-d H:i:s');
|
||||
$loginUserInfo->login_ip = $this->request->ip();
|
||||
$loginUserInfo->save();
|
||||
$userId = $loginUserInfo['id'];
|
||||
$token = Random::uuid();
|
||||
$loginUserInfo['token'] = $token;
|
||||
Token::set($token, $userId, 24 * 60 * 60 * 3);
|
||||
|
||||
$param['password'] = '******';
|
||||
//登录成功不记录用户密码
|
||||
Log::create([
|
||||
'login_status' => 1,
|
||||
'admin_id' => $userId,
|
||||
'request_body' => json_encode($param),
|
||||
'request_header' => json_encode($this->request->header()),
|
||||
'ip' => $this->request->ip(),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$authList = AuthServiceFacade::getAuthList($userId);
|
||||
return $this->success('登录成功', [
|
||||
'user' => $loginUserInfo,
|
||||
'authList' => $authList,
|
||||
'pluginConf' => Config::get('plugin'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function loginInfo()
|
||||
{
|
||||
$loginUserInfo = UserServiceFacade::getUserInfo();
|
||||
$authList = AuthServiceFacade::getAuthList($loginUserInfo['id']);
|
||||
|
||||
return $this->success('获取成功', [
|
||||
'user' => $loginUserInfo,
|
||||
'authList' => $authList,
|
||||
'pluginConf' => Config::get('plugin'),
|
||||
'ltVersion' => LT_VERSION,
|
||||
]);
|
||||
}
|
||||
|
||||
//退出登录
|
||||
public function logout()
|
||||
{
|
||||
$token = $this->request->header('laytp-admin-token', $this->request->cookie('laytpAdminToken'));
|
||||
Token::delete($token);
|
||||
return $this->success('退出成功');
|
||||
}
|
||||
|
||||
//查看
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order)->with(['avatar_file']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new Add();
|
||||
if (!$validate->check($post)) throw new \Exception($validate->getError());
|
||||
|
||||
$post['password'] = Str::createPassword($post['password']);
|
||||
$saveRes = $this->model->save($post);
|
||||
if (!$saveRes) throw new \Exception('保存基础信息失败');
|
||||
|
||||
if ($post['role_ids']) {
|
||||
$roleIds = explode(',', $post['role_ids']);
|
||||
$data = [];
|
||||
foreach ($roleIds as $k => $v) {
|
||||
$data[] = ['admin_role_id' => $v, 'admin_user_id' => $this->model->id];
|
||||
}
|
||||
$roleUser = new \app\model\admin\role\User();
|
||||
$saveAllRes = $roleUser->saveAll($data);
|
||||
if (!$saveAllRes) throw new \Exception('保存角色信息失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $this->success('操作成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->with(['role_ids', 'avatar_file'])->findOrEmpty($id)->toArray();
|
||||
$data = \app\resource\admin\User::info($info);
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
//编辑
|
||||
public function edit()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$user = $this->model->findOrEmpty($post['id']);
|
||||
if (!$user) throw new \Exception('id参数错误');
|
||||
|
||||
$validate = new Edit();
|
||||
if (!$validate->check($post)) throw new \Exception($validate->getError());
|
||||
if ($post['password']) {
|
||||
$post['password'] = Str::createPassword($post['password']);
|
||||
} else {
|
||||
unset($post['password']);
|
||||
unset($post['re_password']);
|
||||
}
|
||||
$updateRes = $user->update($post);
|
||||
if (!$updateRes) throw new \Exception('保存基本信息失败');
|
||||
|
||||
$userRole = new \app\model\admin\role\User();
|
||||
$deleteRes = $userRole->where('admin_user_id', '=', $post['id'])->delete();
|
||||
if (!is_numeric($deleteRes)) throw new \Exception('删除用户角色失败');
|
||||
|
||||
if ($post['role_ids']) {
|
||||
$roleIds = explode(',', $post['role_ids']);
|
||||
$data = [];
|
||||
foreach ($roleIds as $k => $v) {
|
||||
$data[] = ['admin_role_id' => $v, 'admin_user_id' => $user->id];
|
||||
}
|
||||
|
||||
$saveAllRes = $userRole->saveAll($data);
|
||||
if (!$saveAllRes) throw new \Exception('保存用户角色失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $this->success('操作成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//修改个人资料
|
||||
public function singleEdit()
|
||||
{
|
||||
$post = CommonFun::filterPostData($this->request->post());
|
||||
$validate = new singleEdit();
|
||||
if (!$validate->check($post)) {
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
if (!$post['password']) {
|
||||
unset($post['password']);
|
||||
} else {
|
||||
$post['password'] = Str::createPassword($post['password']);
|
||||
}
|
||||
$user = $this->model->with(['avatar_file'])->find($post['id']);
|
||||
if (!$user) {
|
||||
return $this->error('ID参数错误');
|
||||
}
|
||||
$res = $user->update($post);
|
||||
if ($res) {
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
$ids = array_filter($this->request->param('ids'));
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
if (in_array(1, $ids)) {
|
||||
return $this->error('不允许删除初始化用户');
|
||||
}
|
||||
try {
|
||||
if ($this->model->destroy($ids)) {
|
||||
return $this->success('数据删除成功');
|
||||
} else {
|
||||
return $this->error('数据删除失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->exceptionError($e);
|
||||
}
|
||||
}
|
||||
|
||||
//设置状态
|
||||
public function setStatus()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['status'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
//设置是否为超管
|
||||
public function setIsSuperManager()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['is_super_manager'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin\action;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 后台操作日志
|
||||
*/
|
||||
class Log extends Backend
|
||||
{
|
||||
/**
|
||||
* admin_action_log模型对象
|
||||
* @var \app\model\admin\action\Log
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel = 0;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\action\Log();
|
||||
}
|
||||
|
||||
//查看和搜索列表
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order)->with(['adminUser']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
//回收站
|
||||
public function recycle()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $this->model->onlyTrashed()
|
||||
->with(['adminUser'])
|
||||
->order($order)->where($where)->paginate($limit)->toArray();
|
||||
return $this->success('回收站数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin\api;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* Api请求日志
|
||||
*/
|
||||
class Log extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* api_log模型对象
|
||||
* @var \app\model\api\Log
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel = 0;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\api\Log();
|
||||
}
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin\balance;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* Api请求日志
|
||||
*/
|
||||
class Log extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* api_log模型对象app\model\admin\balance
|
||||
* @var \app\model\admin\balance\Log
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel = 0;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\balance\Log();
|
||||
|
||||
}
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin\files;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\Tree;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 附件分类管理
|
||||
*/
|
||||
class Category extends Backend
|
||||
{
|
||||
/**
|
||||
* files_category模型对象
|
||||
* @var \app\model\files\Category
|
||||
*/
|
||||
protected $model;
|
||||
public $hasSoftDel = 1;//是否拥有软删除功能
|
||||
public $orderRule = ['sort' => 'DESC', 'id' => 'ASC'];
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new \app\model\files\Category();
|
||||
}
|
||||
|
||||
//查看
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$sourceData = $this->model->order($order)->where($where);
|
||||
$isTree = $this->request->param('is_tree');
|
||||
if ($isTree) {
|
||||
$menuTreeObj = Tree::instance();
|
||||
$menuTreeObj->init($sourceData->select()->toArray());
|
||||
$data = $menuTreeObj->getRootTrees();
|
||||
} else {
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $sourceData->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $sourceData->select()->toArray();
|
||||
}
|
||||
}
|
||||
return $this->success('获取成功', $data);
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
return $this->error('参数ids不能为空');
|
||||
}
|
||||
|
||||
$sourceData = $this->model->select()->toArray();
|
||||
$treeLib = Tree::instance();
|
||||
$treeLib->init($sourceData);
|
||||
$childIds = $treeLib->getChildIds($ids);
|
||||
|
||||
if ($this->model->destroy($childIds)) {
|
||||
return $this->success('数据删除成功');
|
||||
} else {
|
||||
return $this->error('数据删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
//回收站
|
||||
public function recycle()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $this->model->onlyTrashed()
|
||||
->with(['parent'])
|
||||
->order($order)->where($where)->paginate($limit)->toArray();
|
||||
return $this->success('回收站数据获取成功', $data);
|
||||
}
|
||||
|
||||
//设置排序
|
||||
public function setSort()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$fieldVal = $this->request->post('field_val');
|
||||
$isRecycle = $this->request->post('is_recycle');
|
||||
$update['sort'] = $fieldVal;
|
||||
try {
|
||||
if ($isRecycle) {
|
||||
$updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
|
||||
} else {
|
||||
$updateRes = $this->model->where('id', '=', $id)->update($update);
|
||||
}
|
||||
if ($updateRes) {
|
||||
return $this->success('操作成功');
|
||||
} else if ($updateRes === 0) {
|
||||
return $this->success('未作修改');
|
||||
} else {
|
||||
return $this->error('操作失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('数据库异常,操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin\login;
|
||||
|
||||
use laytp\controller\Backend;
|
||||
use laytp\library\CommonFun;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 后台登录日志
|
||||
*/
|
||||
class Log extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* admin_login_log模型对象
|
||||
* @var \app\model\admin\login\Log
|
||||
*/
|
||||
protected $model;
|
||||
protected $hasSoftDel = 0;//是否拥有软删除功能
|
||||
|
||||
protected $noNeedLogin = []; // 无需登录即可请求的方法
|
||||
protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
$this->model = new \app\model\admin\login\Log();
|
||||
}
|
||||
|
||||
|
||||
//查看和搜索列表
|
||||
|
||||
/**
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$data = $this->model->where($where)->order($order)->with(['adminUser']);
|
||||
$paging = $this->request->param('paging', false);
|
||||
if ($paging) {
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $data->paginate($limit)->toArray();
|
||||
$data['data'] = $this->getSelectedData($data['data']);
|
||||
} else {
|
||||
$data = $data->select()->toArray();
|
||||
}
|
||||
return $this->success('数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
//查看详情
|
||||
public function info()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
$info = $this->model->find($id);
|
||||
return $this->success('获取成功', $info);
|
||||
}
|
||||
|
||||
|
||||
//回收站
|
||||
public function recycle()
|
||||
{
|
||||
$where = $this->buildSearchParams();
|
||||
$order = $this->buildOrder();
|
||||
$limit = $this->request->param('limit', Config::get('paginate.limit'));
|
||||
$data = $this->model->onlyTrashed()
|
||||
->where($where)
|
||||
->with(['adminUser'])
|
||||
->order($order)->paginate($limit)->toArray();
|
||||
return $this->success('回收站数据获取成功', $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
use think\facade\Db;
|
||||
use laytp\controller\Api;
|
||||
use dh2y\qrcode\QRcode;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* @ApiInternal ()
|
||||
*/
|
||||
class Demo extends Api
|
||||
{
|
||||
|
||||
public $noNeedLogin = ['test'];
|
||||
|
||||
/*@formatter:on*/
|
||||
/**
|
||||
*
|
||||
* @ApiTitle (需要登录的接口需要登录的接口需要登录的接口需要登录的接口)
|
||||
* @ApiSummary (需要登录的接口详细描述)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api.demo/test)
|
||||
* @ApiHeaders (name="token", type="string", required="true", description="请求的Token")
|
||||
* @ApiParams (name="id", type="integer", required="true", description="会员ID")
|
||||
* @ApiParams (name="name", type="string", required="true", description="用户名")
|
||||
* @ApiReturnParams (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
|
||||
* @ApiReturnParams (name="msg", type="string", description="返回描述")
|
||||
* @ApiReturnParams (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
|
||||
* @ApiReturnParams (name="data", type="object", description="返回的数据对象")
|
||||
* @ApiReturnParams (name="data.id", type="string", description="参数id的值")
|
||||
* @ApiReturnParams (name="data.name", type="string", description="参数name的值")
|
||||
* @ApiReturn
|
||||
({
|
||||
"code": 0,
|
||||
"msg": "返回成功",
|
||||
"time": 1591168410,
|
||||
"data": {
|
||||
"id": "",
|
||||
"name": ""
|
||||
}
|
||||
})
|
||||
*/
|
||||
/*@formatter:on*/
|
||||
public function test()
|
||||
{ $req = ChangeMoney('7891454089', 'member', "-", 5, 8032909529, "消费" . "测试");
|
||||
var_dump($req);
|
||||
return $this->success('返回成功', $this->request->param());
|
||||
}
|
||||
|
||||
/*@formatter:off*/
|
||||
/**
|
||||
* @ApiTitle (无需登录的接口)
|
||||
* @ApiSummary (无需登录的接口详细描述)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api.demo/test1)
|
||||
* @ApiReturnParams (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
|
||||
* @ApiReturnParams (name="msg", type="string", description="返回描述")
|
||||
* @ApiReturnParams (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
|
||||
* @ApiReturnParams (name="data", type="object", description="返回的数据对象")
|
||||
* @ApiReturnParams (name="data.action", type="string", description="固定返回test1")
|
||||
* @ApiReturn
|
||||
({
|
||||
"code": 0,
|
||||
"msg": "返回成功",
|
||||
"time": 1591168410,
|
||||
"data": {
|
||||
"action": "test1"
|
||||
}
|
||||
})
|
||||
*/
|
||||
/*@formatter:on*/
|
||||
public function createqrcoe()
|
||||
{
|
||||
|
||||
|
||||
|
||||
return $this->success('返回成功', ['action' => 'test1']);
|
||||
}
|
||||
/*@formatter:on*/
|
||||
public function test1()
|
||||
{
|
||||
$public_path= public_path();
|
||||
$code = new QRcode();
|
||||
var_dump($public_path.'img/mode.png');
|
||||
$code_path = $code->png('二维码携带的参数',$public_path.'uploads/qrcode/11122.png',10)->background(105,100,$public_path.'img/mode.jpg')->text("10.000",20,[250,480],'#000000')->text("TSCBYxKnLbLGPkcjZddWB4b64ymTdpcyY3",15,[140,550],'#000000')->getPath(true);
|
||||
|
||||
var_dump($code_path);
|
||||
|
||||
|
||||
|
||||
return $this->success('返回成功', ['action' => 'test1']);
|
||||
}
|
||||
|
||||
/*@formatter:off*/
|
||||
/**
|
||||
* @ApiTitle (参数传递array的接口)
|
||||
* @ApiSummary (参数传递array的接口详细描述)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api.demo/arrayParam)
|
||||
* @ApiParams (name="id", type="string", required="true", description="ID")
|
||||
* @ApiParams (name="name", type="array", required="true", description="数组中的值")
|
||||
* @ApiParams (name="array[key]", type="array", required="true", description="数组中的值")
|
||||
* @ApiReturnParams (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
|
||||
* @ApiReturnParams (name="msg", type="string", description="返回描述")
|
||||
* @ApiReturnParams (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
|
||||
* @ApiReturnParams (name="data", type="object", description="返回的数据对象")
|
||||
* @ApiReturnParams (name="data.action", type="string", description="固定返回test1")
|
||||
* @ApiReturn
|
||||
({
|
||||
"code": 0,
|
||||
"msg": "返回成功",
|
||||
"time": 1591168410,
|
||||
"data": {
|
||||
"action": "test1"
|
||||
}
|
||||
})
|
||||
*/
|
||||
/*@formatter:on*/
|
||||
public function arrayParam()
|
||||
{
|
||||
return $this->success('返回成功', $this->request->param());
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use laytp\BaseController;
|
||||
|
||||
/**
|
||||
* @ApiInternal ()
|
||||
*/
|
||||
class Index extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return redirect('/api.html');
|
||||
}
|
||||
}
|
||||
Executable
+11
File diff suppressed because one or more lines are too long
Executable
+11
File diff suppressed because one or more lines are too long
Executable
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use laytp\controller\Api;
|
||||
use laytp\library\Random;
|
||||
|
||||
/**
|
||||
* @ApiInternal ()
|
||||
*/
|
||||
class Token extends Api
|
||||
{
|
||||
public $no_need_login = [];
|
||||
|
||||
/*@formatter:off*/
|
||||
/**
|
||||
* @ApiTitle (检测Token是否过期)
|
||||
* @ApiSummary (检测Token是否过期)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api.token/check)
|
||||
* @ApiHeaders (name="token", type="string", required="true", description="用户登录后得到的Token")
|
||||
* @ApiReturnParams (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
|
||||
* @ApiReturnParams (name="msg", type="string", description="返回描述")
|
||||
* @ApiReturnParams (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
|
||||
* @ApiReturnParams (name="data", type="object", description="返回的数据对象")
|
||||
* @ApiReturnParams (name="data.token", type="string", description="用户登录凭证,token")
|
||||
* @ApiReturnParams (name="data.expires_in", type="integer", description="token有效时间,单位秒")
|
||||
* @ApiReturn
|
||||
({
|
||||
"code": 0,
|
||||
"msg": "Token有效",
|
||||
"time": 1591167181,
|
||||
"data": {
|
||||
"token": "827fb87e-2064-45c8-839a-128e195a7411",
|
||||
"expires_in": 1789
|
||||
}
|
||||
})
|
||||
*/
|
||||
/*@formatter:on*/
|
||||
public function check()
|
||||
{
|
||||
$token = $this->service_user->getToken();
|
||||
$tokenInfo = \library\Token::get($token);
|
||||
$this->success('Token有效', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
}
|
||||
|
||||
/*@formatter:off*/
|
||||
/**
|
||||
* @ApiTitle (刷新Token)
|
||||
* @ApiSummary (刷新Token)
|
||||
* @ApiMethod (POST)
|
||||
* @ApiRoute (/api.token/refresh)
|
||||
* @ApiHeaders (name="token", type="string", required="true", description="用户登录后得到的Token")
|
||||
* @ApiReturnParams (name="code", type="integer", description="接口返回码.0=常规正确码,表示常规操作成功;1=常规错误码,客户端仅需提示msg;其他返回码与具体业务相关。框架实现了的唯一其他返回码:10401,前端需要跳转至登录界面。在一个复杂的交互过程中,你可能需要自行定义其他返回码")
|
||||
* @ApiReturnParams (name="msg", type="string", description="返回描述")
|
||||
* @ApiReturnParams (name="time", type="integer", description="请求时间,Unix时间戳,单位秒")
|
||||
* @ApiReturnParams (name="data", type="object", description="返回的数据对象")
|
||||
* @ApiReturnParams (name="data.token", type="string", description="用户登录凭证,token")
|
||||
* @ApiReturnParams (name="data.expires_in", type="integer", description="token有效时间,单位秒")
|
||||
* @ApiReturn
|
||||
({
|
||||
"code": 0,
|
||||
"msg": "成功刷新Token",
|
||||
"time": 1591167423,
|
||||
"data": {
|
||||
"token": "e356df60-ff03-4f15-bb66-c0e3ef37f335",
|
||||
"expires_in": 1800
|
||||
}
|
||||
})
|
||||
*/
|
||||
/*@formatter:on*/
|
||||
public function refresh()
|
||||
{
|
||||
//删除源Token
|
||||
$token = $this->service_user->getToken();
|
||||
\library\Token::delete($token);
|
||||
//创建新Token
|
||||
$token = Random::uuid();
|
||||
\library\Token::set($token, $this->service_user->id, $this->service_user->token_keep_time);
|
||||
$this->success('成功刷新Token', ['token' => $token, 'expires_in' => $this->service_user->token_keep_time]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user