* complete importMiniProgram.
This commit is contained in:
+31
-1
@@ -493,6 +493,7 @@ class ai extends control
|
||||
* Export a mini program as zip file.
|
||||
*
|
||||
* @param string $appID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function exportMiniProgram($appID)
|
||||
@@ -509,9 +510,38 @@ class ai extends control
|
||||
exit;
|
||||
}
|
||||
|
||||
public function importMiniProgram($appID)
|
||||
/**
|
||||
* Import mini program from zip file.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function importMiniProgram()
|
||||
{
|
||||
if(!empty($_POST) && !empty($_FILES))
|
||||
{
|
||||
$file = $_FILES['file'];
|
||||
$filePath = $file['tmp_name'];
|
||||
$result = $this->ai->extractZtAppZip($filePath);
|
||||
if(is_array($result))
|
||||
{
|
||||
$info = $result[0];
|
||||
$fileName = $info['filename'];
|
||||
include_once($fileName);
|
||||
if(isset($ztApp))
|
||||
{
|
||||
$ztApp = json_decode($ztApp);
|
||||
$ztApp->name = $this->ai->getUniqueAppName($ztApp->name);
|
||||
$ztApp->published = $_POST['published'];
|
||||
$ztApp->category = $_POST['category'];
|
||||
$this->ai->createMiniProgram($ztApp);
|
||||
unlink($fileName);
|
||||
return $this->sendSuccess(array('message' => $this->lang->saveSuccess, 'locate' => $this->createLink('ai', 'miniprograms')));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->send(array('result' => 'fail', 'message' => this->lang->ai->saveFail, 'locate' => $this->createLink('ai', 'miniprograms')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
.main-table td {padding-left: 16px;}
|
||||
#import-miniprogram .modal-dialog {padding: 10px 20px 10px 20px; position: relative;}
|
||||
#import-miniprogram .modal-dialog .modal-header {border: none!important; padding-bottom: 0;}
|
||||
.close-import-dialog {position: absolute; right: 20px; top: 20px;}
|
||||
|
||||
@@ -68,6 +68,9 @@ $lang->ai->exportMiniProgram = 'Export AI Mini Program';
|
||||
$lang->ai->importMiniProgram = 'Import AI Mini Program';
|
||||
$lang->ai->export = 'Export';
|
||||
$lang->ai->import = 'Import';
|
||||
$lang->ai->saveFail = 'Save failed';
|
||||
$lang->ai->installPackage = 'Installation package';
|
||||
$lang->ai->toPublish = 'Publish after installation';
|
||||
|
||||
$lang->ai->chatPlaceholderMessage = 'Hi, I\'m Adao, your AI assistant at ZenTao!';
|
||||
$lang->ai->chatPlaceholderInput = 'type here...';
|
||||
|
||||
@@ -68,6 +68,9 @@ $lang->ai->exportMiniProgram = 'Export AI Mini Program';
|
||||
$lang->ai->importMiniProgram = 'Import AI Mini Program';
|
||||
$lang->ai->export = 'Export';
|
||||
$lang->ai->import = 'Import';
|
||||
$lang->ai->saveFail = 'Save failed';
|
||||
$lang->ai->installPackage = 'Installation package';
|
||||
$lang->ai->toPublish = 'Publish after installation';
|
||||
|
||||
$lang->ai->chatPlaceholderMessage = 'Hi, I\'m Adao, your AI assistant at ZenTao!';
|
||||
$lang->ai->chatPlaceholderInput = 'type here...';
|
||||
|
||||
@@ -68,6 +68,9 @@ $lang->ai->exportMiniProgram = 'Export AI Mini Program';
|
||||
$lang->ai->importMiniProgram = 'Import AI Mini Program';
|
||||
$lang->ai->export = 'Export';
|
||||
$lang->ai->import = 'Import';
|
||||
$lang->ai->saveFail = 'Save failed';
|
||||
$lang->ai->installPackage = 'Installation package';
|
||||
$lang->ai->toPublish = 'Publish after installation';
|
||||
|
||||
$lang->ai->chatPlaceholderMessage = 'Hi, I\'m Adao, your AI assistant at ZenTao!';
|
||||
$lang->ai->chatPlaceholderInput = 'type here...';
|
||||
|
||||
@@ -68,6 +68,9 @@ $lang->ai->exportMiniProgram = '导出AI小程序';
|
||||
$lang->ai->importMiniProgram = '导入AI小程序';
|
||||
$lang->ai->export = '导出';
|
||||
$lang->ai->import = '导入';
|
||||
$lang->ai->saveFail = '保存失败';
|
||||
$lang->ai->installPackage = '安装包';
|
||||
$lang->ai->toPublish = '安装后发布';
|
||||
|
||||
$lang->ai->chatPlaceholderMessage = 'Hi,我是 AI 助手阿道,您可以问我任何问题。';
|
||||
$lang->ai->chatPlaceholderInput = '问问阿道…';
|
||||
|
||||
+77
-34
@@ -622,6 +622,7 @@ class aiModel extends model
|
||||
* Update custom categories.
|
||||
*
|
||||
* @access public
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateCustomCategories()
|
||||
@@ -737,6 +738,7 @@ class aiModel extends model
|
||||
|
||||
/**
|
||||
* @param string $appID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function createNewVersionNotification($appID)
|
||||
@@ -821,15 +823,16 @@ class aiModel extends model
|
||||
* @access public
|
||||
* @return int|false
|
||||
*/
|
||||
public function createMiniProgram()
|
||||
public function createMiniProgram($data = null)
|
||||
{
|
||||
$data = fixer::input('post')->get();
|
||||
$data->editedBy = $this->app->user->account;
|
||||
$data->editedDate = helper::now();
|
||||
$data->published = '0';
|
||||
$data->createdBy = $this->app->user->account;
|
||||
$data->createdDate = helper::now();
|
||||
$data->prompt = $this->lang->ai->miniPrograms->field->default[3];
|
||||
if(empty($data)) $data = fixer::input('post')->get();
|
||||
if(!isset($data->editedBy)) $data->editedBy = $this->app->user->account;
|
||||
if(!isset($data->editedDate)) $data->editedDate = helper::now();
|
||||
if(!isset($data->published)) $data->published = '0';
|
||||
if(!isset($data->createdBy)) $data->createdBy = $this->app->user->account;
|
||||
if(!isset($data->createdDate)) $data->createdDate = helper::now();
|
||||
if(!isset($data->prompt)) $data->prompt = $this->lang->ai->miniPrograms->field->default[3];
|
||||
if($data->published === '1') $data->publishedDate = helper::now();
|
||||
|
||||
if(!empty($data->iconName) && !empty($data->iconTheme))
|
||||
{
|
||||
@@ -838,24 +841,44 @@ class aiModel extends model
|
||||
unset($data->iconTheme);
|
||||
}
|
||||
|
||||
if(isset($data->fields))
|
||||
{
|
||||
$fields = $data->fields;
|
||||
unset($data->fields);
|
||||
}
|
||||
|
||||
$this->dao->insert(TABLE_MINIPROGRAM)
|
||||
->data($data)
|
||||
->exec();
|
||||
$appID = $this->dao->lastInsertID();
|
||||
|
||||
$defaultFields = $this->lang->ai->miniPrograms->field->default;
|
||||
for($i = 0; $i < 3; $i++)
|
||||
if(!isset($fields))
|
||||
{
|
||||
$field = new stdClass();
|
||||
$field->appID = $appID;
|
||||
$field->name = $defaultFields[$i];
|
||||
$field->type = 'text';
|
||||
$field->placeholder = $this->lang->ai->miniPrograms->placeholder->input;
|
||||
$field->options = null;
|
||||
$field->required = '0';
|
||||
$this->dao->insert(TABLE_MINIPROGRAMFIELD)
|
||||
->data($field)
|
||||
->exec();
|
||||
$defaultFields = $this->lang->ai->miniPrograms->field->default;
|
||||
$fieldData = new stdClass();
|
||||
$fieldData->fields = array();
|
||||
for($i = 0; $i < 3; $i++)
|
||||
{
|
||||
$field = new stdClass();
|
||||
$field->appID = $appID;
|
||||
$field->name = $defaultFields[$i];
|
||||
$field->type = 'text';
|
||||
$field->placeholder = $this->lang->ai->miniPrograms->placeholder->input;
|
||||
$field->options = null;
|
||||
$field->required = '0';
|
||||
$fieldData->fields[] = $field;
|
||||
}
|
||||
$this->saveMiniProgramFields($appID, $fieldData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fieldData = new stdClass();
|
||||
$fieldData->fields = $fields;
|
||||
foreach($fields as $field)
|
||||
{
|
||||
if(!isset($field->appID)) $field->appID = $appID;
|
||||
}
|
||||
$this->saveMiniProgramFields($appID, $fieldData);
|
||||
}
|
||||
|
||||
if(dao::isError()) return false;
|
||||
@@ -952,6 +975,13 @@ APP;
|
||||
return $zipPath;
|
||||
}
|
||||
|
||||
public function extractZtAppZip($file)
|
||||
{
|
||||
$this->app->loadClass('pclzip', true);
|
||||
$zip = new pclzip($file);
|
||||
return $zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'tmp/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save mini program fields.
|
||||
*
|
||||
@@ -959,35 +989,33 @@ APP;
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveMiniProgramFields($appID)
|
||||
public function saveMiniProgramFields($appID, $data = null)
|
||||
{
|
||||
$data = fixer::input('post')->get();
|
||||
$this->dao->update(TABLE_MINIPROGRAM)
|
||||
->set('prompt')->eq($data->prompt)
|
||||
->set('published')->eq($data->toPublish)
|
||||
->where('id')->eq($appID)
|
||||
->exec();
|
||||
if(empty($data)) $data = fixer::input('post')->get();
|
||||
|
||||
if(isset($data->prompt) && isset($data->toPublish))
|
||||
{
|
||||
$this->dao->update(TABLE_MINIPROGRAM)
|
||||
->set('prompt')->eq($data->prompt)
|
||||
->set('published')->eq($data->toPublish)
|
||||
->where('id')->eq($appID)
|
||||
->exec();
|
||||
}
|
||||
|
||||
$this->dao->delete()
|
||||
->from(TABLE_MINIPROGRAMFIELD)
|
||||
->where('appID')->eq($appID)
|
||||
->exec();
|
||||
|
||||
$oldFields = $this->getMiniProgramFields($appID);
|
||||
$newFields = array();
|
||||
$fields = $data->fields;
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$field = (array)$field;
|
||||
if(is_array($field['options'])) $field['options'] = implode(',', $field['options']);
|
||||
$newFields[] = $field;
|
||||
$this->dao->insert(TABLE_MINIPROGRAMFIELD)
|
||||
->data($field)
|
||||
->exec();
|
||||
}
|
||||
|
||||
$changes = common::createChanges($oldFields, $newFields);
|
||||
$actionID = $this->loadModel('action')->create('miniProgram', $appID, 'edited');
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1009,6 +1037,21 @@ APP;
|
||||
return !empty($miniProgram);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique app name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function getUniqueAppName($name)
|
||||
{
|
||||
while($this->checkDuplicatedAppName($name))
|
||||
{
|
||||
$name = $name . '_1';
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that any required fields are empty.
|
||||
*
|
||||
|
||||
@@ -31,7 +31,7 @@ $finalList = array_merge($categoryList, $lang->ai->miniPrograms->allCategories);
|
||||
</div>
|
||||
<div class="btn-toolbar pull-right">
|
||||
<?php if(common::hasPriv('ai', 'importMiniProgram')): ?>
|
||||
<button class="btn btn-primary">
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#import-miniprogram">
|
||||
<?= $lang->ai->import; ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
@@ -91,6 +91,52 @@ $finalList = array_merge($categoryList, $lang->ai->miniPrograms->allCategories);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="import-miniprogram">
|
||||
<div class="modal-dialog" style="width: 600px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<strong style="font-size: 20px; color: #0B0F18;"><?= $lang->ai->import; ?></strong>
|
||||
<a data-dismiss="modal" class="close-import-dialog">
|
||||
<i class="icon-close"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-ajax" method="post" action="<?= $this->createLink('ai', 'importMiniProgram'); ?>" id="import-miniprogram-form">
|
||||
<table class="table table-form">
|
||||
<tr>
|
||||
<th><?= $lang->ai->installPackage; ?></th>
|
||||
<td>
|
||||
<input type="file" name="file" required class="form-control">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= $lang->ai->miniPrograms->category; ?></th>
|
||||
<td>
|
||||
<?= html::select('category', array_merge($lang->ai->miniPrograms->categoryList, $categoryList), $category, "class='form-control chosen' required"); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= $lang->ai->toPublish; ?></th>
|
||||
<td class="required">
|
||||
<div class="radio" style="display: flex; align-items: center; gap: 4px;">
|
||||
<label>
|
||||
<input type="radio" name="published" value="1"><?= $lang->ai->miniPrograms->field->requiredOptions[1]; ?>
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="published" value="0" checked><?= $lang->ai->miniPrograms->field->requiredOptions[0]; ?>
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="display: flex; justify-content: center; border-top: none; padding-top: 10px;">
|
||||
<button type="submit" class="btn btn-primary btn-wide"><?= $lang->save; ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mainContent" class="main-row fade">
|
||||
<div class="side-col" id="sidebar">
|
||||
<div class="cell">
|
||||
|
||||
Reference in New Issue
Block a user