| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- // +----------------------------------------------------------------------
- // | EasyAdmin
- // +----------------------------------------------------------------------
- // | PHP交流群: 763822524
- // +----------------------------------------------------------------------
- // | 开源协议 https://mit-license.org
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
- // +----------------------------------------------------------------------
- namespace app\admin\controller\system;
- use app\admin\logic\SystemNodeLogic;
- use app\common\model\SystemNode;
- use app\admin\service\TriggerService;
- use app\common\controller\AdminController;
- use EasyAdmin\annotation\ControllerAnnotation;
- use EasyAdmin\annotation\NodeAnotation;
- use app\admin\service\NodeService;
- use think\App;
- /**
- * @ControllerAnnotation(title="系统节点管理")
- * Class Node
- * @package app\admin\controller\system
- */
- class Node extends AdminController
- {
- use \app\admin\traits\Curd;
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new SystemNode();
- }
- /**
- * @NodeAnotation(title="列表")
- */
- public function index()
- {
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($count,$list) = SystemNodeLogic::getList();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="系统节点更新")
- */
- public function refreshNode($force = 0)
- {
- $this->checkPostRequest();
- $nodeList = (new NodeService())->getNodelist();
- empty($nodeList) && $this->error('暂无需要更新的系统节点');
- $model = new SystemNode();
- try {
- if ($force == 1) {
- $updateNodeList = $model->whereIn('node', array_column($nodeList, 'node'))->select();
- $formatNodeList = array_format_key($nodeList, 'node');
- foreach ($updateNodeList as $vo) {
- isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->update([
- 'title' => $formatNodeList[$vo['node']]['title'],
- 'is_auth' => $formatNodeList[$vo['node']]['is_auth'],
- ]);
- }
- }
- $existNodeList = $model->field('node,title,type,is_auth')->select();
- foreach ($nodeList as $key => $vo) {
- foreach ($existNodeList as $v) {
- if ($vo['node'] == $v->node) {
- unset($nodeList[$key]);
- break;
- }
- }
- }
- $model->saveAll($nodeList);
- TriggerService::updateNode();
- } catch (\Exception $e) {
- $this->error('节点更新失败');
- }
- $this->success('节点更新成功');
- }
- /**
- * @NodeAnotation(title="清除失效节点")
- */
- public function clearNode()
- {
- $this->checkPostRequest();
- $nodeList = (new NodeService())->getNodelist();
- $model = new SystemNode();
- try {
- $existNodeList = $model->field('id,node,title,type,is_auth')->select()->toArray();
- $formatNodeList = array_format_key($nodeList, 'node');
- foreach ($existNodeList as $vo) {
- !isset($formatNodeList[$vo['node']]) && $model->where('id', $vo['id'])->delete();
- }
- TriggerService::updateNode();
- } catch (\Exception $e) {
- $this->error('节点更新失败');
- }
- $this->success('节点更新成功');
- }
- }
|