KunWeb/web/admin/develop/code_create.php
2025-05-16 01:00:48 +08:00

191 lines
7.9 KiB
PHP

<?php
namespace web\admin\develop;
class code_create {
public static function json_init() {
global $db;
$rsuser = verifyfast();
$post = new \ciy\post();
$query = $post->get('query');
$schema = objstr($query, 'schema');
$tabname = objstr($query, 'table');
$csql = new \ciy\sql('INFORMATION_SCHEMA.COLUMNS');
$csql->where('TABLE_SCHEMA', $schema);
$csql->where('TABLE_NAME', $tabname);
$rows = $db->get($csql);
for ($i = 0; $i < count($rows); $i++)
$rows[$i]['id'] = $i;
$ret = array('list' => $rows);
$field = array();
$field['_btn'] = array('c' => '操作');
$field['TABLE_COMMENT'] = array('c' => '表名');
$field['TABLE_NAME'] = array('c' => '英文名');
$field['TABLE_COLLATION'] = array('c' => '编码');
$field['ENGINE'] = array('c' => '引擎');
$ret['field'] = $field;
$csql = new \ciy\sql('zc_dev_dbcode');
$csql->where('schem', $schema);
$csql->where('tabl', $tabname);
$csql->column('pcjson');
$jnstr = $db->get1($csql);
if (empty($jnstr)) {
$csql = new \ciy\sql('INFORMATION_SCHEMA.TABLES');
$csql->where('TABLE_SCHEMA', $schema);
$csql->where('TABLE_NAME', $tabname);
$tabrow = $db->getone($csql);
$chk_audit = false;
foreach ($rows as $row) {
if ($row['COLUMN_NAME'] == 'auditstatus')
$chk_audit = true;
}
$ret['code_create'] = array('bcod' => array(), 'col' => array());
$ret['code_create']['bcod']['tabname'] = $tabname;
$ret['code_create']['bcod']['titname'] = str_replace('表', '', $tabrow['TABLE_COMMENT']);
$ret['code_create']['bcod']['uploadpat'] = substr($tabname, strpos($tabname, '_') + 1);
if ($chk_audit) {
$ret['code_create']['bcod']['newline'] = '导出';
$ret['code_create']['bcod']['multibtn'] = '批量删除,审核通过,驳回';
$ret['code_create']['bcod']['btnlist_line'] = '审核';
} else {
$ret['code_create']['bcod']['newline'] = '添加,导入,导出';
$ret['code_create']['bcod']['multibtn'] = '批量删除';
$ret['code_create']['bcod']['btnlist_line'] = '查看,修改';
}
} else {
$ret['code_create'] = json_decode($db->get1($csql), true);
}
return succjson($ret);
}
public static function json_save() {
$post = new \ciy\post();
$ret = self::save($post);
if (is_string($ret))
return errjson($ret);
return succjson();
}
public static function save($post) {
global $db;
$schema = get('schema');
$tabname = get('table');
$json = array();
$json['bcod'] = array();
//$json['bcod']['maindb'] = $post->get('_bcod_maindb', '', 'all');
$json['bcod']['verifyfunc'] = $post->get('_bcod_verifyfunc', '', 'all');
$json['bcod']['titname'] = $post->get('_bcod_titname', '', 'all');
//$json['bcod']['logtype'] = $post->get('_bcod_logtype', '', 'all');
$json['bcod']['uploadpat'] = $post->get('_bcod_uploadpat', '', 'all');
$json['bcod']['liiddict'] = $post->get('_bcod_liiddict', '', 'all');
$json['bcod']['uptabcard'] = $post->get('_bcod_uptabcard', '', 'all');
$json['bcod']['tabdict'] = $post->get('_bcod_tabdict', '', 'all');
$json['bcod']['saascode'] = $post->get('_bcod_saascode', '', 'all');
//$json['bcod']['uniquedata'] = $post->get('_bcod_uniquedata', '', 'all');
//$json['bcod']['bcod_chk'] = $post->get('bcod_chk');
$json['bcod']['selectorder'] = $post->get('_bcod_select_order', '', 'all');
$json['bcod']['newline'] = $post->get('_bcod_btntop_newline', '', 'all');
$json['bcod']['multibtn'] = $post->get('_bcod_btntop_multibtn', '', 'all');
$json['bcod']['btnlist_line'] = $post->get('_bcod_btnlist_line', '', 'all');
$json['bcod']['savepc'] = $post->get('_bcod_savepc', '', 'all');
$json['bcod']['htmllang'] = $post->get('_bcod_htmllang', '', 'all');
$json['bcod']['proglang'] = $post->get('_bcod_proglang', '', 'all');
$json['bcod']['pctemplate'] = $post->get('_bcod_pctemplate', '', 'all');
$json['bcod']['mbtemplate'] = $post->get('_bcod_mbtemplate', '', 'all');
$total = $post->getint('total');
$json['col'] = array();
for ($i = 0; $i < $total; $i++) {
$col = $post->get('col_' . $i);
if (empty($col))
continue;
$json['col'][$col] = array();
$json['col'][$col]['bchk'] = $post->get('bchk_' . $i);
$json['col'][$col]['set'] = $post->get('set_' . $i, '', 'all');
}
try {
$db->begin();
$updata = array();
$updata['schem'] = $schema;
$updata['tabl'] = $tabname;
$updata['pcjson'] = json_encode($json, JSON_PARTIAL_OUTPUT_ON_ERROR);
$csql = new \ciy\sql('zc_dev_dbcode');
$csql->where('schem', $schema);
$csql->where('tabl', $tabname);
$row = $db->getone($csql);
$csql = new \ciy\sql('zc_dev_dbcode');
if (is_array($row)) {
$csql->where('id', $row['id']);
if ($db->update($csql, $updata) === false)
throw new \Exception('更新失败:' . $db->error);
} else {
if ($db->insert($csql, $updata) === false)
throw new \Exception('新增失败:' . $db->error);
$id = $db->insert_id();
$updata['id'] = $id;
}
$db->commit();
} catch (\Exception $ex) {
$db->rollback();
return errjson($ex->getMessage());
}
return succjson();
}
public static function json_createhtml() {
$post = new \ciy\post();
require_once 'code_common.php';
require_once 'code_pc_html.php';
$codex = code_pc_html($post);
return succjson(array('source' => $codex));
}
public static function json_createphp() {
$post = new \ciy\post();
require_once 'code_common.php';
require_once 'code_pc_php.php';
$codex = code_pc_php($post);
return succjson(array('source' => $codex));
}
public static function json_creatembvue3() {
$post = new \ciy\post();
require_once 'code_common.php';
require_once 'code_mb_vue3.php';
$codex = code_mbvue3($post);
return succjson(array('source' => $codex));
}
public static function json_savepc() {
$post = new \ciy\post();
require_once 'code_common.php';
require_once 'code_pc_html.php';
require_once 'code_pc_php.php';
$savepc = $post->get('_bcod_savepc', '', 'all');
if (empty($savepc))
return errjson('请填写PC保存路径');
if (strpos($savepc, ':') === false)
$savepc = PATH_ROOT . $savepc;
$tpath = dirname($savepc);
if (!is_dir($tpath))
return errjson('目录不存在' . $tpath);
$ow = $post->getbool('owpc');
if (!$ow) {
if (file_exists($savepc . '.html'))
return errjson($savepc . '.html文件已存在');
if (file_exists($savepc . '.php'))
return errjson($savepc . '.php文件已存在');
}
$ret = self::save($post);
if (is_string($ret))
return errjson($ret);
$codex = code_pc_html($post);
$ret = file_put_contents($savepc . '.html', $codex);
if ($ret === false)
return errjson('写入html失败');
$codex = code_pc_php($post);
$ret = file_put_contents($savepc . '.php', $codex);
if ($ret === false)
return errjson('写入php失败');
return succjson();
}
}