feat:完成前台获取指定子类目代码块列表接口
This commit is contained in:
parent
e37aeee1be
commit
f2d18d0d05
@ -4,6 +4,8 @@ namespace app\api\controller\Code;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Code\CodeModule as ModelCodeModule;
|
||||
use app\api\logic\Code\CodeModule as LogicCodeModule;
|
||||
use app\api\logic\Code\CodeModuleCategory as ModelCodeModuleCategory;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
@ -18,59 +20,41 @@ use think\facade\Env;
|
||||
class CodeModule extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取代码块列表
|
||||
* 获取指定子类目代码块列表接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-06-28
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCodeModuleList(Request $request): array
|
||||
public function getCategoryCodeModuleList(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)
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|子类目' => 'require',
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
foreach ($params['code_module_category_guid'] as $code_module_category_guid) {
|
||||
ModelCodeModuleCategory::isSonCategory($code_module_category_guid);
|
||||
$code_module_list = ModelCodeModule::field([
|
||||
'code_module.code_module_guid',
|
||||
'code_module.code_module_category_guid',
|
||||
'code_module.code_module_name',
|
||||
'code_module.code_module_html',
|
||||
'code_module.code_module_style',
|
||||
'code_module.code_module_script',
|
||||
'code_module.code_module_sort',
|
||||
'code_module.code_module_audit',
|
||||
'code_module_category.code_module_category_name',
|
||||
'code_module_category.code_module_category_guid',
|
||||
])->leftJoin('code_module_category', 'code_module_category.code_module_category_guid = code_module.code_module_category_guid')
|
||||
->where('code_module.code_module_category_guid', $code_module_category_guid)
|
||||
->order('code_module.code_module_sort')->select();
|
||||
$data[] = $code_module_list;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代码块详情
|
||||
*/
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
27
app/api/logic/Code/CodeModuleCategory.php
Normal file
27
app/api/logic/Code/CodeModuleCategory.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic\Code;
|
||||
|
||||
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
|
||||
use app\common\exception\Tool;
|
||||
|
||||
|
||||
class CodeModuleCategory
|
||||
{
|
||||
/**
|
||||
* 验证是否为子类目
|
||||
*
|
||||
* @param string $code_module_category_guid 类目guid
|
||||
* @return void
|
||||
* @date 2023-06-28
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function isSonCategory(string $code_module_category_guid): void
|
||||
{
|
||||
$module_category = ModelCodeModuleCategory::scope('not_master')->find($code_module_category_guid);
|
||||
if (!$module_category) {
|
||||
throwErrorMsg("当前类目不为子类目!");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user