155 lines
4.3 KiB
PHP
155 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\common\model\Resource;
|
|
use app\common\service\SysDictService;
|
|
use app\common\service\UploadService;
|
|
use app\common\utils\scaffold\Generate;
|
|
use support\Request;
|
|
use support\Db;
|
|
use support\Cache;
|
|
|
|
class IndexController
|
|
{
|
|
|
|
protected $noNeedLogin = ['index', 'view', 'perm', 'createResource', 'test'];
|
|
|
|
protected $noNeedHeaderData = ['index', 'view', 'perm', 'createResource', 'test'];
|
|
|
|
public function index(Request $request)
|
|
{
|
|
return htmlpage();
|
|
}
|
|
|
|
/**
|
|
* 调试飞书
|
|
*/
|
|
public function view(Request $request)
|
|
{
|
|
return view('index/qrcode', ['name' => 'webman']);
|
|
}
|
|
|
|
/**
|
|
* 临时增加用户权限
|
|
*/
|
|
public function perm(Request $request)
|
|
{
|
|
try {
|
|
$data = $request->get();
|
|
|
|
if (Db::table('user_roles')->where('user_id', $data['user_id'])->first()) {
|
|
Db::table('user_roles')->where('user_id', $data['user_id'])->update([
|
|
'role_id' => $data['role_id']
|
|
]);
|
|
} else {
|
|
Db::table('user_roles')->insert([
|
|
'user_id' => $data['user_id'],
|
|
'role_id' => $data['role_id']
|
|
]);
|
|
}
|
|
|
|
if (!Db::table('user_systems')->where('user_id', $data['user_id'])->where('system_id', $data['system_id'])->first()) {
|
|
Db::table('user_systems')->where('user_id', $data['user_id'])->insert([
|
|
'user_id' => $data['user_id'],
|
|
'system_id' => $data['system_id'],
|
|
'created_at' => time()
|
|
]);
|
|
}
|
|
|
|
Cache::delete("user_resources_{$data['user_id']}");
|
|
return json(['code' => 0, 'msg' => 'success']);
|
|
} catch (\Throwable $e) {
|
|
return json(['code' => 1, 'msg' => $e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成资源
|
|
*/
|
|
public function createResource()
|
|
{
|
|
$options = [
|
|
'controller' => [
|
|
'module' => 'crm',
|
|
'name' => 'approval_flows'
|
|
],
|
|
'model' => [
|
|
'module' => 'crm',
|
|
'name' => 'approval_flows'
|
|
],
|
|
'service' => [
|
|
'module' => 'crm',
|
|
'name' => 'approval_flows'
|
|
],
|
|
'logic' => [
|
|
'module' => 'crm',
|
|
'name' => 'approval_flows'
|
|
],
|
|
'validate' => [
|
|
'module' => 'crm',
|
|
'name' => 'approval_flows'
|
|
],
|
|
'table' => 'approval_flows'
|
|
];
|
|
|
|
$result = (new Generate($options))->doGenerate();
|
|
return $result;
|
|
}
|
|
|
|
|
|
public function test2(Request $request)
|
|
{
|
|
$where[] = ['id', '>', 141];
|
|
$list = (new \app\common\utils\MigrationResources())->getFullResourceTreeOptimized('resources', $where);
|
|
|
|
|
|
$keys = ['system_id','name','desc','type','code','parent_id','url','icon','open_type','link',
|
|
'is_hide','is_hide_tab','no_auth','is_home','instance','keep_alive','sort','status'];
|
|
foreach ($list as $key=>$item) {
|
|
|
|
|
|
$temp = [];
|
|
|
|
foreach ($item as $k=>$v) {
|
|
|
|
if (isset($item['children']) && count($item['children']) > 0) {
|
|
$temp = $item['children'];
|
|
}
|
|
|
|
if (!in_array($k, $keys)) {
|
|
unset($item[$k]);
|
|
}
|
|
|
|
$id = Db::table('resources')->insertGetId($item);
|
|
|
|
if ($temp) {
|
|
foreach ($temp as $kc=>$vc) {
|
|
|
|
foreach ($vc as $kk => $vv) {
|
|
if (!in_array($kk, $keys)) {
|
|
unset($vc[$kk]);
|
|
}
|
|
}
|
|
|
|
$vc['parent_id'] = $id;
|
|
|
|
Db::table('resources')->insert($vc);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function test(Request $request)
|
|
{
|
|
// 菜单迁移
|
|
$where[] = ['id', '>', 141];
|
|
$list = (new \app\common\utils\MigrationResources())->do('resources_20250916_bak', 'resources_yuanshi', $where);
|
|
|
|
}
|
|
} |