forked from fecshop/yii2_fecshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1031877
commit 3875d34
Showing
5 changed files
with
373 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
use Yii; | ||
use yii\base\Exception; | ||
use yii\web\Controller; | ||
use fecshop\models\mysqldb\StoreDomain; | ||
use fecshop\models\mysqldb\StoreBaseConfig; | ||
|
||
|
||
/** | ||
* @author Terry Zhao <[email protected]> | ||
|
@@ -62,6 +65,12 @@ public function init() | |
// 安装默认第一步页面 | ||
public function actionIndex() | ||
{ | ||
$database = Yii::$app->request->get('database'); | ||
if (!$database) { | ||
return $this->render('readme', []); | ||
} | ||
|
||
|
||
$editForm = Yii::$app->request->post('editForm'); | ||
if ($editForm && $this->checkDatabaseData($editForm) | ||
&& $this->updateDatabaseConfig($editForm)) { | ||
|
@@ -72,34 +81,15 @@ public function actionIndex() | |
} | ||
$errorInfo = Yii::$app->session->getFlash('database-errors'); | ||
$errorInfo = $this->getErrorHtml($errorInfo); | ||
|
||
|
||
return $this->render($this->action->id, [ | ||
'errorInfo' => $errorInfo, | ||
'editForm' => $editForm, | ||
]); | ||
} | ||
|
||
// 安装默认第一步页面 | ||
public function actionInitadminuser() | ||
{ | ||
$editForm = Yii::$app->request->post('editForm'); | ||
if (is_array($editForm) && !empty($editForm)) { | ||
$param = [ | ||
'username' => $editForm['username'], | ||
'password' => $editForm['password'], | ||
]; | ||
if ($this->installUpdateUser($param)) { | ||
$homeUrl = Yii::$app->homeUrl; | ||
return $this->redirect($homeUrl . '/database/config/complete'); | ||
|
||
} | ||
} | ||
$errorInfo = $this->getErrorHtml($this->_install_errors); | ||
return $this->render($this->action->id, [ | ||
'errorInfo' => $errorInfo, | ||
'editForm' => $editForm, | ||
]); | ||
|
||
} | ||
|
||
|
||
// 数据库migrate页面 | ||
public function actionMigrate() | ||
|
@@ -228,11 +218,211 @@ public function actionAddtestdata() | |
'errorInfo' => $errorInfo, | ||
'successInfo' => $successInfo, | ||
'initUrl' => Yii::$app->homeUrl . '/database/config/addtestdatainit', | ||
'nextUrl' => Yii::$app->homeUrl . '/database/config/initadminuser', | ||
'nextUrl' => Yii::$app->homeUrl . '/database/config/initdomain', | ||
//'migrateLog' => $this->_migrateLog | ||
]); | ||
|
||
} | ||
|
||
// 域名部分 | ||
public function actionInitdomain() | ||
{ | ||
$editForm = Yii::$app->request->post('editForm'); | ||
if (is_array($editForm) && !empty($editForm)) { | ||
$appfront_domain = $editForm['appfront_domain']; | ||
$img_domain = $editForm['img_domain']; | ||
$mall_type = $editForm['mall_type']; | ||
if ($appfront_domain && $img_domain && $mall_type) { | ||
$this->updateDomainConfig($editForm); | ||
|
||
return $this->redirect(Yii::$app->homeUrl . '/database/config/initadminuser'); | ||
} else { | ||
$this->_install_errors .= 'pc域名,图片域名, 商城类型 不能为空'; | ||
} | ||
} | ||
$errorInfo = $this->getErrorHtml($this->_install_errors); | ||
return $this->render($this->action->id, [ | ||
'errorInfo' => $errorInfo, | ||
'editForm' => $editForm, | ||
'demoDomainList' => $this->getDemoDomainList(), | ||
]); | ||
|
||
} | ||
|
||
// 将提交的信息更新到数据库 | ||
public function updateDomainConfig($editForm) | ||
{ | ||
$appfront_domain = $editForm['appfront_domain']; | ||
$img_domain = $editForm['img_domain']; | ||
$apphtml5_domain = $editForm['apphtml5_domain']; | ||
$appserver_domain = $editForm['appserver_domain']; | ||
$mall_type = $editForm['mall_type']; // 商城类型 | ||
$baseCurrencyCode = ''; | ||
$storeLanguageCode = ''; | ||
$storeLanguageName = ''; | ||
|
||
if ($mall_type == 'china') { | ||
$baseCurrencyCode = 'CNY'; | ||
$storeLanguageCode = 'zh-CN'; | ||
$storeLanguageName = '中文'; | ||
} else { | ||
$baseCurrencyCode = 'USD'; | ||
$storeLanguageCode = 'en-US'; | ||
$storeLanguageName = 'English'; | ||
} | ||
// pc | ||
if ($appfront_domain) { | ||
// appfront 更新 | ||
$appfrontOne = StoreDomain::findOne([ | ||
'app_name' => 'appfront', | ||
'status' => 1, | ||
]); | ||
if ($appfrontOne['id']) { | ||
$appfrontOne['key'] = $appfront_domain; | ||
$appfrontOne['lang'] = $storeLanguageCode; | ||
$appfrontOne['lang_name'] = $storeLanguageName; | ||
$appfrontOne['currency'] = $baseCurrencyCode; | ||
$appfrontOne['mobile_type'] = 'apphtml5'; | ||
if ($apphtml5_domain) { | ||
$appfrontOne['mobile_redirect_domain'] = $apphtml5_domain; | ||
} else { | ||
$appfrontOne['mobile_enable'] = 2; | ||
} | ||
$appfrontOne['updated_at'] = time(); | ||
|
||
$appfrontOne->save(); | ||
} | ||
} | ||
if ($apphtml5_domain) { | ||
// apphtml5 更新 | ||
$apphtml5One = StoreDomain::findOne([ | ||
'app_name' => 'apphtml5', | ||
'status' => 1, | ||
]); | ||
if ($apphtml5One['id']) { | ||
$apphtml5One['key'] = $apphtml5_domain; | ||
$apphtml5One['lang'] = $storeLanguageCode; | ||
$apphtml5One['lang_name'] = $storeLanguageName; | ||
$apphtml5One['currency'] = $baseCurrencyCode; | ||
|
||
$apphtml5One['updated_at'] = time(); | ||
$apphtml5One->save(); | ||
} | ||
} | ||
// base_info | ||
if ($img_domain) { | ||
$baseConfig = StoreBaseConfig::findOne([ | ||
'key' => 'base_info', | ||
]); | ||
if ($baseConfig['id']) { | ||
$configArr = unserialize($baseConfig['value']); | ||
$configArr['image_domain'] = 'http://'.$img_domain; | ||
$configArr['base_currency'] = $baseCurrencyCode; | ||
|
||
$baseConfig['value'] = serialize($configArr); | ||
$baseConfig['updated_at'] = time(); | ||
$baseConfig->save(); | ||
} | ||
} | ||
// 设置汇率 // {s:13:"currency_code";s:3:"CNY";s:15:"currency_symbol";s:3:"¥";s:13:"currency_rate";s:3:"6.3";}} | ||
if ($mall_type == 'china') { | ||
$baseConfig = StoreBaseConfig::findOne([ | ||
'key' => 'currency', | ||
]); | ||
if ($baseConfig['id']) { | ||
$configArr = [ | ||
[ | ||
'currency_code' => $baseCurrencyCode, | ||
'currency_symbol' => '¥', | ||
'currency_rate' => 1, | ||
] | ||
]; | ||
|
||
$baseConfig['value'] = serialize($configArr); | ||
$baseConfig['updated_at'] = time(); | ||
$baseConfig->save(); | ||
} | ||
} | ||
|
||
|
||
if ($appserver_domain) { | ||
$baseConfig = StoreBaseConfig::findOne([ | ||
'key' => 'appserver_store', | ||
]); | ||
if ($baseConfig['id']) { | ||
$configArr = unserialize($baseConfig['value']); | ||
$configArr['key'] = $appserver_domain; | ||
$configArr['lang'] = $storeLanguageCode; | ||
$configArr['lang_name'] = $storeLanguageName; | ||
$configArr['currency'] = $baseCurrencyCode; | ||
|
||
$baseConfig['value'] = serialize($configArr); | ||
$baseConfig['updated_at'] = time(); | ||
$baseConfig->save(); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
public function getDemoDomainList() | ||
{ | ||
$domainStr = $_SERVER['SERVER_NAME']; | ||
$domainArr = explode('.', $domainStr); | ||
$subDomainStr = ''; | ||
if (count($domainArr) == 2) { | ||
$subDomainStr = $domainStr; | ||
} else if (count($domainArr) == 3) { | ||
$subDomainStr = $domainArr[1].'.'.$domainArr[2]; | ||
} else { | ||
|
||
return [ | ||
'demo_pc_domain' => '', | ||
'demo_admin_domain' => '', | ||
'demo_img_domain' => '', | ||
'demo_h5_domain' => '', | ||
'demo_appserver_domain' => '', | ||
'demo_appapi_domain' => '', | ||
'demo_appbdmin_domain' => '', | ||
]; | ||
} | ||
|
||
return [ | ||
'demo_pc_domain' => 'www.' . $subDomainStr, | ||
'demo_admin_domain' => 'appadmin.' . $subDomainStr, | ||
'demo_img_domain' => 'img.' . $subDomainStr, | ||
'demo_h5_domain' => 'm.' . $subDomainStr, | ||
'demo_appserver_domain' => 'appserver.' . $subDomainStr, | ||
'demo_appapi_domain' => 'appapi.' . $subDomainStr, | ||
'demo_appbdmin_domain' => 'appbdmin.' . $subDomainStr, | ||
]; | ||
} | ||
|
||
|
||
|
||
|
||
// 安装默认第一步页面 | ||
public function actionInitadminuser() | ||
{ | ||
$editForm = Yii::$app->request->post('editForm'); | ||
if (is_array($editForm) && !empty($editForm)) { | ||
$param = [ | ||
'username' => $editForm['username'], | ||
'password' => $editForm['password'], | ||
]; | ||
if ($this->installUpdateUser($param)) { | ||
$homeUrl = Yii::$app->homeUrl; | ||
return $this->redirect($homeUrl . '/database/config/complete'); | ||
|
||
} | ||
} | ||
$errorInfo = $this->getErrorHtml($this->_install_errors); | ||
return $this->render($this->action->id, [ | ||
'errorInfo' => $errorInfo, | ||
'editForm' => $editForm, | ||
]); | ||
|
||
} | ||
|
||
// 进行sql migrate ,产品图片的复制 | ||
public function addProductData() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/appinstall/modules/Database/views/config/initdomain.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
use fec\helpers\CRequest; | ||
|
||
?> | ||
<h1>Fecmall域名配置</h1> | ||
<br/><br/> | ||
|
||
<?= $errorInfo ?> | ||
|
||
|
||
<form action="<?= Yii::$app->homeUrl . '/database/config/initdomain?database=1' ?>" method="post"> | ||
<?php echo CRequest::getCsrfInputHtml(); ?> | ||
注意:下面填写的域名,必须和nginx/apache中配置的一致, 如果您使用的是宝塔控制面板,保持和宝塔安装填写的域名一致即可。 | ||
<br/><br/> | ||
<div class="form-group"> | ||
<label for="name">Pc站域名【必须<code>*</code>】譬如:<code> www.fecmall.com</code>, 电脑pc浏览器访问的商城入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['appfront_domain'] ? $editForm['appfront_domain'] : $demoDomainList['demo_pc_domain'] ?>" | ||
name="editForm[appfront_domain]" placeholder="这是电脑pc浏览器访问的商城入口域名"> | ||
</div> | ||
<!-- | ||
<div class="form-group"> | ||
<label for="name">后台域名【必须<code>*</code>】譬如:<code> appadmin.fecmall.com</code>, 管理后台访问的入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['appadmin_domain'] ? $editForm['appadmin_domain'] : $demoDomainList['demo_admin_domain'] ?>" | ||
name="editForm[appadmin_domain]" placeholder="这是管理后台访问的入口域名"> | ||
</div> | ||
--> | ||
<div class="form-group"> | ||
<label for="name">图片域名【必须<code>*</code>】譬如:<code> img.fecmall.com</code>, 图片入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['img_domain'] ? $editForm['img_domain'] : $demoDomainList['demo_img_domain'] ?>" | ||
name="editForm[img_domain]" placeholder="图片入口域名, 将图片使用单独的子域名,可以提高更高的安全性,以及浏览器加载图片速度"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name">手机H5域名【选填】譬如:<code> m.fecmall.com</code>,手机浏览器html5入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['apphtml5_domain'] ? $editForm['apphtml5_domain'] : $demoDomainList['demo_h5_domain'] ?>" | ||
name="editForm[apphtml5_domain]" placeholder="这是手机浏览器html5入口域名"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name">Appserver域名【选填】譬如:<code> appserver.fecmall.com</code>, 微信小程序,vue等前后端分析应用,fecmall提供api数据的入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['appserver_domain'] ? $editForm['appserver_domain'] : $demoDomainList['demo_appserver_domain'] ?>" | ||
name="editForm[appserver_domain]" placeholder="微信小程序,vue等前后端分析应用,fecmall提供api数据的入口域名"> | ||
</div> | ||
|
||
|
||
<div class="form-group"> | ||
<label for="name">电商类型【必须<code>*</code>】</label> | ||
<select class="form-control" name="editForm[mall_type]"> | ||
<option value="china">国内中文电商类型【基础货币:CNY(人民币),Store默认语言:zh-CN】</option> | ||
<option value="global">跨境出口电商【基础货币:USD(美元),Store默认语言:en-US】</option> | ||
</select> | ||
</div> | ||
<!-- | ||
|
||
<div class="form-group"> | ||
<label for="name">AppApi域名【选填】譬如::<code> appapi.fecmall.com</code>, fecmall和第三方erp等系统,进行数据对接的入口域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['appapi_domain'] ? $editForm['appapi_domain'] : $demoDomainList['demo_appapi_domain'] ?>" | ||
name="editForm[appapi_domain]" placeholder="fecmall和第三方erp等系统,进行数据对接的入口域名"> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="name">AppBdmin域名【选填】譬如::<code> appbdmin.fecmall.com</code>, 多商户扩展经销商后台域名</label> | ||
<input type="text" class="form-control" value="<?= $editForm['appbdmin_domain'] ? $editForm['appbdmin_domain'] : $demoDomainList['demo_appbdmin_domain'] ?>" | ||
name="editForm[appbdmin_domain]" placeholder="多商户扩展经销商后台域名"> | ||
</div> | ||
--> | ||
|
||
<button type="submit" class="btn btn-default">提交</button> | ||
</form> |
Oops, something went wrong.