Skip to content

Commit

Permalink
admin add fa config
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Dec 20, 2020
1 parent 2e7fa41 commit c73ddbb
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 0 deletions.
195 changes: 195 additions & 0 deletions app/appadmin/modules/Config/block/fa/Manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/

namespace fecshop\app\appadmin\modules\Config\block\fa;

use fec\helpers\CUrl;
use fec\helpers\CRequest;
use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockEditInterface;
use fecshop\app\appadmin\modules\AppadminbaseBlockEdit;
use Yii;

/**
* block cms\staticblock.
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class Manager extends AppadminbaseBlockEdit implements AppadminbaseBlockEditInterface
{
public $_saveUrl;
// 需要配置
public $_key = 'fa_info';
public $_type;
protected $_attrArr = [
'status',
'fa_domain',
'website_id',
'access_token',
'api_time_out',
];

public function init()
{
// 需要配置
$this->_saveUrl = CUrl::getUrl('config/fa/managersave');
$this->_editFormData = 'editFormData';
$this->setService();
$this->_param = CRequest::param();
$this->_one = $this->_service->getByKey([
'key' => $this->_key,
]);
if ($this->_one['value']) {
$this->_one['value'] = unserialize($this->_one['value']);
}
}


// 传递给前端的数据 显示编辑form
public function getLastData()
{
$id = '';
if (isset($this->_one['id'])) {
$id = $this->_one['id'];
}
return [
'id' => $id,
'editBar' => $this->getEditBar(),
'textareas' => $this->_textareas,
'lang_attr' => $this->_lang_attr,
'saveUrl' => $this->_saveUrl,
];
}

public function setService()
{
$this->_service = Yii::$service->storeBaseConfig;
}

public function getEditArr()
{

return [
// 需要配置
[
'label' => Yii::$service->page->translate->__('Status'),
'name' => 'status',
'display' => [
'type' => 'select',
'data' => [
Yii::$app->store->enable => Yii::$service->page->translate->__('Enable'),
Yii::$app->store->disable => Yii::$service->page->translate->__('Disable'),
],
],
'remark' => '是否开启FA数据分析系统,开启后,您的Fecmall商城的用户行为数据,将会被收集,并进行统计分析。'
],

[
'label' => Yii::$service->page->translate->__('FA Domain'),
'name' => 'fa_domain',
'display' => [
'type' => 'inputString',
],
'require' => 0,
'remark' => Yii::$service->page->translate->__('FA 系统的域名,格式为:fatrace.fecshop.com , 请严格按照该格式填写'),
],

[
'label' => Yii::$service->page->translate->__('FA Website Id'),
'name' => 'website_id',
'display' => [
'type' => 'inputString',
],
'require' => 0,
'remark' => Yii::$service->page->translate->__('网站的id,在FA trace系统中获取'),
],
[
'label' => Yii::$service->page->translate->__('FA Access Token'),
'name' => 'access_token',
'display' => [
'type' => 'inputString',
],
'require' => 0,
'remark' => Yii::$service->page->translate->__('通过trace系统得到的token'),
],
[
'label' => Yii::$service->page->translate->__('FA Api Time Out'),
'name' => 'api_time_out',
'display' => [
'type' => 'inputString',
],
'require' => 0,
'remark' => Yii::$service->page->translate->__(' api发送数据给trace系统的最大等待时间,超过这个时间将不继续等待'),
],


];
}

public function getArrParam()
{
$request_param = CRequest::param();
$this->_param = $request_param[$this->_editFormData];
$param = [];
$attrVals = [];
foreach ($this->_param as $attr => $val) {
if (in_array($attr, $this->_attrArr)) {
$attrVals[$attr] = $val;
} else {
$param[$attr] = $val;
}
}
$param['value'] = $attrVals;
$param['key'] = $this->_key;

return $param;
}

/**
* save article data, get rewrite url and save to article url key.
*/
public function save()
{
/*
* if attribute is date or date time , db storage format is int ,by frontend pass param is int ,
* you must convert string datetime to time , use strtotime function.
*/
// 设置 bdmin_user_id 为 当前的user_id
$this->_service->saveConfig($this->getArrParam());
$errors = Yii::$service->helper->errors->get();
if (!$errors) {
echo json_encode([
'statusCode' => '200',
'message' => Yii::$service->page->translate->__('Save Success'),
]);
exit;
} else {
echo json_encode([
'statusCode' => '300',
'message' => $errors,
]);
exit;
}
}


public function getVal($name, $column)
{
if (is_object($this->_one) && property_exists($this->_one, $name) && $this->_one[$name]) {

return $this->_one[$name];
}
$content = $this->_one['value'];
if (is_array($content) && !empty($content) && isset($content[$name])) {

return $content[$name];
}

return '';
}
}
38 changes: 38 additions & 0 deletions app/appadmin/modules/Config/controllers/FaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/

namespace fecshop\app\appadmin\modules\Config\controllers;

use fecshop\app\appadmin\modules\Config\ConfigController;
use Yii;
/**
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
class FaController extends ConfigController
{
public $enableCsrfValidation = true;
//public $blockNamespace = 'fecshop\app\appadmin\modules\Config\block';

public function actionManager()
{
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id, $data);
}


public function actionManagersave()
{

$primaryKey = Yii::$service->customer->getPrimaryKey();

$data = $this->getBlock('manager')->save();
}

}
80 changes: 80 additions & 0 deletions app/appadmin/theme/base/default/config/fa/manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* FecMall file.
*
* @link http://www.fecmall.com/
* @copyright Copyright (c) 2016 FecMall Software LLC
* @license http://www.fecmall.com/license
*/
use yii\helpers\Html;
use fec\helpers\CRequest;
use fecadmin\models\AdminRole;
/**
* @author Terry Zhao <[email protected]>
* @since 1.0
*/
?>
<style>
.checker{float:left;}
.dialog .pageContent {background:none;}
.dialog .pageContent .pageFormContent{background:none;}
</style>

<div class="pageContent systemConfig">
<form method="post" action="<?= $saveUrl ?>" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
<?php echo CRequest::getCsrfInputHtml(); ?>
<div layouth="56" class="pageFormContent" style="height: 240px; overflow: auto;">

<input type="hidden" value="<?= $_id; ?>" size="30" name="editFormData[_id]" class="textInput ">

<fieldset id="fieldset_table_qbe">
<legend style="color:#888"><?= Yii::$service->page->translate->__('Base Config') ?></legend>
<div>
<?= $editBar; ?>
</div>
</fieldset>
<?= $lang_attr ?>
<?= $textareas ?>
</div>

<div class="formBar">
<ul>
<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
<li>
<div class="buttonActive"><div class="buttonContent"><button onclick="func('accept')" value="accept" name="accept" type="submit"><?= Yii::$service->page->translate->__('Save') ?></button></div></div>
</li>
<li>
<div class="button"><div class="buttonContent"><button type="button" class="close"><?= Yii::$service->page->translate->__('Cancel') ?></button></div></div>
</li>
</ul>
</div>
</form>
</div>

<style>
.pageForm .pageFormContent .edit_p{
width:100%;
line-height:35px;
}
.pageForm .pageFormContent .edit_p .remark-text{
font-size: 11px;
color: #777;
margin-left: 20px;
}
.pageForm .pageFormContent p.edit_p label{
width: 240px;
line-height: 30px;
font-size: 13px;
font-weight: 500;
}

.pageContent .combox {
margin-left:5px;

}
</style>





0 comments on commit c73ddbb

Please sign in to comment.