fixed 添加基础前端接口

This commit is contained in:
lwh 2023-06-30 11:25:11 +08:00
parent 4079ff8f38
commit 61395af1f6
2 changed files with 198 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<?php
namespace app\api\controller\Code;
use app\BaseController;
use app\common\model\Code\CodeModule as ModelCodeModule;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use think\facade\Db;
use app\common\exception\Tool;
use think\facade\Env;
class CodeModule extends BaseController
{
/**
* 获取代码块列表
*/
public function getCodeModuleList(Request $request): array
{
$params = $request->param();
$con = [];
$con[] = ['code_module_audit', '=', '2'];
$con = Tool::getOptionalQuery(['code_module_category_guid', '='], ['code_module_name', 'LIKE']);
$query = ModelCodeModule::where($con)
->field([
'code_module_id',
'code_module_guid',
'code_module_category_guid',
'code_module_name',
'code_module_html',
'code_module_style',
'code_module_script',
'code_module_sort',
])
->order('code_module_sort', 'asc')
->select();
return msg(0, "获取代码块列表成功!", [
'data' => $query,
'count' => count($query)
]);
}
/**
* 获取代码块详情
*/
public function getCodeModuleInfo(Request $request): array
{
$params = $request->param();
$this->validate($params, ['code_module_guid' => 'require']);
$find = ModelCodeModule::field([
'code_module_id',
'code_module_guid',
'code_module_catetory_guid',
'code_module_name',
'code_module_html',
'code_module_style',
'code_module_script',
'code_module_sort',
'code_module_audit'
])
->where('code_module_guid', $params['code_module_guid'])
->find();
return msg(0, '获取代码块详情成功!', ['data' => $find]);
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace app\api\controller\Code;
use app\BaseController;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\arw\adjfut\src\Traverse;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use think\facade\Db;
use app\common\exception\Tool;
use think\facade\Env;
class CodeModuleCategory extends BaseController
{
/**
* 获取代码块类目列表
*/
public function getCodeModuleCategoryList(Request $request)
{
$params = $request->param();
$con = Tool::getOptionalQuery(
['cmc.code_module_category_name', 'LIKE'],
['cmc.code_module_category_ps', 'LIKE'],
['cmc.code_module_category_library_type', '='],
['cust.customer_name|cust.customer_account', 'LIKE', 'customer'],
['cmc.code_module_category_audit', '='],
);
// 筛选已审核
$con[] = ['cmc.code_module_category_audit','=','2'];
if (isset($params['code_module_category_global_mode']) && $params['code_module_category_global_mode']) {
$con[] = ['cmc.code_module_category_global_mode', 'REGEXP', implode('|', $params['code_module_category_global_mode'])];
}
$tree_data = [];
//只针对主级类目进行的分页处理
$query = ModelCodeModuleCategory::alias('cmc')->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')
->scope('master')->where($con);
$module_category_guids = self::pageWrapper($query)->column('code_module_category_guid');
if ($module_category_guids) {
//分页后的主级类目开始构建树形结构(此时才会获取到各个父级类目所包含的子级类目)
$data = ModelCodeModuleCategory::alias('cmc')
->whereOr([
['cmc.code_module_category_guid', 'in', $module_category_guids],
['cmc.code_module_category_parent_guid', 'in', $module_category_guids],
])->field([
'cmc.code_module_category_id',
'cmc.code_module_category_guid',
'cmc.customer_guid',
'cmc.code_module_category_audit',
'cmc.code_module_category_sort',
'cmc.code_module_category_parent_guid',
'cmc.code_module_category_name',
'cmc.code_module_category_audit',
'cmc.code_module_category_global_mode',
'cmc.code_module_category_library_type',
'cmc.code_module_category_ps',
'cmcp.code_module_category_name' => "code_module_category_parent_name",
'cust.customer_name',
])
->leftjoin('code_module_category cmcp', 'cmc.code_module_category_parent_guid = cmcp.code_module_category_guid')
->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')
->order('code_module_category_sort')
->select()
->toArray();
$Traverse = new Traverse('code_module_category_guid', 'code_module_category_parent_guid');
$tree_data = $Traverse->tree($data, ModelCodeModuleCategory::MASTER_DEFAULT, function ($v) {
return [
'guid' => $v['code_module_category_guid'],
'name' => $v['code_module_category_name'],
'parent_name' => $v['code_module_category_parent_name'],
'parent_guid' => $v['code_module_category_parent_guid'],
'tips' => $v['code_module_category_ps'],
'sort' => $v['code_module_category_sort'],
'langHit' => $v['code_module_category_global_mode'],
'code_module_category_library_type' => $v['code_module_category_library_type'],
'customer_guid' => $v['customer_guid'],
'customer_name' => $v['customer_name'],
];
});
}
return msg(0, "获取代码块类目列表成功!", [
'count' => $query->count(),
'data' => $tree_data,
]);
}
/**
* 获取代码块类目详情
*/
public function getCodeModuleCategoryInfo(Request $request): array
{
$params = $request->param();
$this->validate($params, ['code_module_category_guid' => 'require']);
$find = ModelCodeModuleCategory::field([
'code_module_category_id',
'code_module_category_guid',
'code_module_category_name',
'code_module_category_ps',
'code_module_category_parent_guid',
'code_module_category_sort',
'code_module_category_global_mode',
'code_module_category_library_type',
'customer_guid',
'code_module_category_audit'
])
->where('code_module_category_guid', $params['code_module_category_guid'])
->find();
return msg(0, '获取代码块类目详情成功!', ['data' => $find]);
}
}