drag-create-api/app/api/controller/Tdk/Tdk.php
2023-06-25 08:51:24 +08:00

108 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller\Tdk;
use app\BaseController;
use app\common\model\Tdk\Tdk as ModelTdk;
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 Tdk extends BaseController
{
public function createXmd()
{
$table_all = Db::query('SHOW TABLES');
$arr = [];
$match = ['_copy', '_copy1', 'demo', '_lpf', '_20'];
$res_str = '';
foreach ($table_all as $key => $it) {
$item = $it['Tables_in_shop_uniapp'];
$currentMatch = '';
foreach ($match as $matchKey => $matchItem) {
if (stripos($item, $matchItem) === false) {
$currentMatch = '';
} else {
$currentMatch = $item;
break;
}
}
if ($item != $currentMatch) {
$arr[$item] = [
'comment' => $table_info = Db::query('SHOW TABLE STATUS LIKE ' . "'" . $item . "'")[0]['Comment'],
'children' => Db::query('SHOW FULL COLUMNS FROM `' . $item . '`')
];
}
}
function createXmdStr(&$res_str, $arr)
{
foreach ($arr as $key => &$item) {
if ($item['comment'] != '') {
$res_str .= "\n{$key}\n\t" . $item['comment'];
if ($item['children']) {
foreach ($item['children'] as $childKey => &$childItem) {
if ($childItem['Comment'] == '') {
$res_str .= "\n\t\t{$childItem['Field']}";
} else {
$childItem['Comment'] = str_replace(",", '', $childItem['Comment']);
$childItem['Comment'] = str_replace("]", ')', $childItem['Comment']);
$childItem['Comment'] = str_replace("[", '(', $childItem['Comment']);
$res_str .= "\n\t\t{$childItem['Field']}\n\t\t\t{$childItem['Comment']}";
}
}
}
} else {
$res_str .= "\n{$key}";
if ($item['children']) {
foreach ($item['children'] as $childKey => &$childItem) {
if ($childItem['Comment'] == '') {
$res_str .= "\n\t{$childItem['Field']}";
} else {
$childItem['Comment'] = str_replace(",", '', $childItem['Comment']);
$childItem['Comment'] = str_replace("]", ')', $childItem['Comment']);
$childItem['Comment'] = str_replace("[", '(', $childItem['Comment']);
$res_str .= "\n\t{$childItem['Field']}\n\t\t{$childItem['Comment']}";
}
}
}
}
}
}
createXmdStr($res_str, $arr);
echo $res_str;
return '';
}
/**
* 获取网站tdk详情
*/
public function getTdkInfo(Request $request): array
{
$params = $request->param();
$this->validate($params, ['tdk_type' => 'require']);
$find = ModelTdk::field([
'tdk_id',
'tdk_type',
'tdk_title',
'tdk_description',
'tdk_keyword'
])
->where('tdk_type', $params['tdk_type'])
->find();
return msg(0, '获取网站tdk详情成功!', ['data' => $find]);
}
}