提交 0bf9d363 编写于 作者: T Terry

appserver的接口部分

上级 da6cc041
......@@ -18,7 +18,7 @@ class ArticleController extends AppapiController
public function actionTest()
{
//echo 11;exit;
echo 11;exit;
//var_dump(get_class(Yii::$service->cms->article->getByPrimaryKey('')));
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
'cms' => [
'class' => '\fecshop\app\appserver\modules\Cms\Module',
'params'=> [
],
]
];
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
'general' => [
'class' => '\fecshop\app\appserver\modules\General\Module',
'params'=> [
],
]
];
\ No newline at end of file
......@@ -9,45 +9,57 @@
namespace fecshop\app\appserver\modules;
use fec\controllers\FecController;
use yii\rest\Controller;
use fec\helpers\CConfig;
use Yii;
use yii\web\Response;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class AppserverController extends FecController
class AppserverController extends Controller
{
public $blockNamespace;
/**
* init theme component property : $fecshopThemeDir and $layoutFile
* $fecshopThemeDir is appfront base theme directory.
* layoutFile is current layout relative path.
*/
public function init()
{
parent::init();
Yii::$app->user->enableSession = false;
//if (!Yii::$service->page->theme->fecshopThemeDir) {
// Yii::$service->page->theme->fecshopThemeDir = Yii::getAlias(CConfig::param('appfrontBaseTheme'));
//}
//if (!Yii::$service->page->theme->layoutFile) {
// Yii::$service->page->theme->layoutFile = CConfig::param('appfrontBaseLayoutName');
//}
//Yii::$service->page->translate->category = 'appfront';
}
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
$behaviors["corsFilter"] = [
'class' => \yii\filters\Cors::className(),
'cors' => [
// restrict access to
'Origin' => ['*'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
// Allow only POST and PUT methods
'Access-Control-Request-Headers' => ['*'],
// Allow only headers 'X-Wsse'
'Access-Control-Allow-Credentials' => null,
// Allow OPTIONS caching
'Access-Control-Max-Age' => 86400,
// Allow the X-Pagination-Current-Page header to be exposed to the browser.
'Access-Control-Expose-Headers' => ['fecshop_uuid'],
],
];
return $behaviors;
}
/**
* get current block
* you can change $this->blockNamespace.
*/
public function getBlock($blockName = '')
{
if (!$blockName) {
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appserver\modules\Cms;
use fecshop\app\appserver\modules\AppserverModule;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Module extends AppserverModule
{
public $blockNamespace;
public function init()
{
// 以下代码必须指定
$nameSpace = __NAMESPACE__;
// web controller
if (Yii::$app instanceof \yii\web\Application) {
$this->controllerNamespace = $nameSpace . '\\controllers';
$this->blockNamespace = $nameSpace . '\\block';
// console controller
//} elseif (Yii::$app instanceof \yii\console\Application) {
// $this->controllerNamespace = $nameSpace . '\\console\\controllers';
// $this->blockNamespace = $nameSpace . '\\console\\block';
}
//$this->_currentDir = __DIR__ ;
//$this->_currentNameSpace = __NAMESPACE__;
// 指定默认的man文件
//$this->layout = "home.php";
//Yii::$service->page->theme->layoutFile = 'main.php';
parent::init();
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appserver\modules\Cms\controllers;
use fecshop\app\appserver\modules\AppserverController;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class HomeController extends AppserverController
{
public function actionAdvertise(){
$bigImg1 = Yii::$service->image->getImgUrl('custom/home_img_1.jpg','apphtml5');
$bigImg2 = Yii::$service->image->getImgUrl('custom/home_img_2.jpg','apphtml5');
$bigImg3 = Yii::$service->image->getImgUrl('custom/home_img_3.jpg','apphtml5');
$smallImg1 = Yii::$service->image->getImgUrl('custom/home_small_1.jpg','apphtml5');
$smallImg2 = Yii::$service->image->getImgUrl('custom/home_small_2.jpg','apphtml5');
return [
'bigImgList' => [
['imgUrl' => $bigImg1],
['imgUrl' => $bigImg2],
['imgUrl' => $bigImg3],
],
'smallImgList' => [
['imgUrl' => $smallImg1],
['imgUrl' => $smallImg2],
],
];
}
public function actionProduct(){
$featured_skus = Yii::$app->controller->module->params['homeFeaturedSku'];
Yii::$service->session->getUUID();
return $this->getProductBySkus($featured_skus);
}
//public function getBestSellerProduct(){
// $best_skus = Yii::$app->controller->module->params['homeBestSellerSku'];
// return $this->getProductBySkus($best_skus);
//}
public function getProductBySkus($skus)
{
if (is_array($skus) && !empty($skus)) {
$filter['select'] = [
'sku', 'spu', 'name', 'image',
'price', 'special_price',
'special_from', 'special_to',
'url_key', 'score',
];
$filter['where'] = ['in', 'sku', $skus];
$products = Yii::$service->product->getProducts($filter);
//var_dump($products);
$products = Yii::$service->category->product->convertToCategoryInfo($products);
$i = 1;
$product_return = [];
if(is_array($products) && !empty($products)){
foreach($products as $k=>$v){
$i++;
$products[$k]['url'] = '/catalog/product/'.$v['product_id'];
$products[$k]['image'] = Yii::$service->product->image->getUrl($v['image'] );
if($i%2 === 0){
$arr = $products[$k];
}else{
$product_return[] = [
'one' => $arr,
'two' => $products[$k],
];
}
}
if($i%2 === 0){
$product_return[] = [
'one' => $arr,
'two' => [],
];
}
}
return $product_return;
}
}
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appserver\modules\General;
use fecshop\app\appserver\modules\AppserverModule;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Module extends AppserverModule
{
public $blockNamespace;
public function init()
{
// 以下代码必须指定
$nameSpace = __NAMESPACE__;
// web controller
if (Yii::$app instanceof \yii\web\Application) {
$this->controllerNamespace = $nameSpace . '\\controllers';
$this->blockNamespace = $nameSpace . '\\block';
// console controller
//} elseif (Yii::$app instanceof \yii\console\Application) {
// $this->controllerNamespace = $nameSpace . '\\console\\controllers';
// $this->blockNamespace = $nameSpace . '\\console\\block';
}
//$this->_currentDir = __DIR__ ;
//$this->_currentNameSpace = __NAMESPACE__;
// 指定默认的man文件
//$this->layout = "home.php";
//Yii::$service->page->theme->layoutFile = 'main.php';
parent::init();
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appserver\modules\General\controllers;
use fecshop\app\appserver\modules\AppserverController;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class BaseController extends AppserverController
{
public function actionMenu(){
$arr = Yii::$service->category->getTreeArr('','',true);
return $arr ;
}
// 语言
public function actionLang(){
$langs = Yii::$service->store->serverLangs;
$currentLangCode = Yii::$service->store->currentLangCode;
foreach($langs as $k => $one){
$code = $one['code'];
if($currentLangCode == $code){
$langs[$k]['selected'] = true;
}else{
$langs[$k]['selected'] = false;
}
}
return $langs ;
}
public function actionCurrency(){
$currencys = Yii::$service->page->currency->getCurrencys();
$currentCurrencyCode = Yii::$service->page->currency->getCurrentCurrency();
foreach($currencys as $k => $one){
$code = $one['code'];
if($currentCurrencyCode == $code){
$currencys[$k]['selected'] = true;
}else{
$currencys[$k]['selected'] = false;
}
}
return $currencys;
}
}
\ No newline at end of file
......@@ -105,9 +105,9 @@ class Category extends Service
* 数组中只有 id name(default language), child(子分类) 等数据。
* 目前此函数仅仅用于后台对分类的编辑使用。 appadmin.
*/
protected function actionGetTreeArr($rootCategoryId = 0)
protected function actionGetTreeArr($rootCategoryId = 0,$lang = '',$appserver=false)
{
return $this->_category->getTreeArr($rootCategoryId);
return $this->_category->getTreeArr($rootCategoryId,$lang,$appserver);
}
/**
......
......@@ -53,7 +53,8 @@ class Store extends Service
public $thirdLogin;
//public $https;
public $serverLangs;
/**
* Bootstrap:init website, class property $currentLang ,$currentTheme and $currentStore.
* if you not config this ,default class property will be set.
......@@ -108,6 +109,33 @@ class Store extends Service
*/
$init_compelte = 1;
$this->thirdLogin = $store['thirdLogin'];
/**
* appserver 部分
*/
if(isset($store['serverLangs']) && !empty($store['serverLangs'])){
$this->serverLangs = $store['serverLangs'];
}
$headers = Yii::$app->request->getHeaders();
if(isset($headers['language']) && $headers['language']){
$h_lang = $headers['language'];
if(is_array($this->serverLangs)){
foreach($this->serverLangs as $one){
if($one['code'] == $h_lang){
Yii::$service->store->currentLangCode = $h_lang;
}
}
}
}
if(isset($headers['currency']) && $headers['currency']){
$currentC = Yii::$service->page->currency->getCurrentCurrency();
if($currentC != $headers['currency']){
Yii::$service->page->currency->setCurrentCurrency($currentC);
}
}
break;
}
}
......
......@@ -196,7 +196,7 @@ class CategoryMongodb implements CategoryInterface
* 数组中只有 id name(default language), child(子分类) 等数据。
* 目前此函数仅仅用于后台对分类的编辑使用。 appadmin.
*/
public function getTreeArr($rootCategoryId = '', $lang = '')
public function getTreeArr($rootCategoryId = '', $lang = '',$appserver=false)
{
$arr = [];
if (!$lang) {
......@@ -217,10 +217,13 @@ class CategoryMongodb implements CategoryInterface
$idKey => $idVal,
'name' => Yii::$service->fecshoplang->getLangAttrVal($cate['name'], 'name', $lang),
];
if($appserver){
$arr[$idVal]['url'] = Yii::$service->url->getUrl('catalog/category/'.$idVal);
}
//echo $arr[$idVal]['name'];
if ($this->hasChildCategory($idVal)) {
$arr[$idVal]['child'] = $this->getTreeArr($idVal, $lang);
$arr[$idVal]['child'] = $this->getTreeArr($idVal, $lang,$appserver);
}
}
}
......
......@@ -106,12 +106,13 @@ class Product extends Service
}
list($price, $special_price) = $this->getPrices($one['price'], $one['special_price'], $one['special_from'], $one['special_to']);
$arr[] = [
'name' => $name,
'sku' => $one['sku'],
'image' => $image,
'price' => $price,
'name' => $name,
'sku' => $one['sku'],
'image' => $image,
'price' => $price,
'special_price' => $special_price,
'url' => Yii::$service->url->getUrl($url_key),
'url' => Yii::$service->url->getUrl($url_key),
'product_id' => (string)$one['_id'],
];
}
}
......
......@@ -29,8 +29,9 @@ class QueryParamAuth extends YiiQueryParamAuth
return $identity;
}else{
$result = ['status' => 'ERROR', 'code' => 401,'message' => 'token is time out'];
echo json_encode($result);
exit;
Yii::$app->response->data=json_encode($result);
Yii::$app->response->send();
Yii::$app->end();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册