diff --git a/app/appapi/modules/V1/controllers/ArticleController.php b/app/appapi/modules/V1/controllers/ArticleController.php index d7d6e1ae23c085f6ab678500da3263d422d5e8b2..e301c76aedb5276f1d9b42af2f5ca0d10cc09046 100644 --- a/app/appapi/modules/V1/controllers/ArticleController.php +++ b/app/appapi/modules/V1/controllers/ArticleController.php @@ -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(''))); } } diff --git a/app/appserver/config/modules/Cms.php b/app/appserver/config/modules/Cms.php new file mode 100644 index 0000000000000000000000000000000000000000..71e5fcb08b521e47846c3d5ea78611f3785ade75 --- /dev/null +++ b/app/appserver/config/modules/Cms.php @@ -0,0 +1,15 @@ + [ + 'class' => '\fecshop\app\appserver\modules\Cms\Module', + 'params'=> [ + ], + ] +]; \ No newline at end of file diff --git a/app/appserver/config/modules/General.php b/app/appserver/config/modules/General.php new file mode 100644 index 0000000000000000000000000000000000000000..324153aa7447f99cf8ed7e447b71055c3c413176 --- /dev/null +++ b/app/appserver/config/modules/General.php @@ -0,0 +1,15 @@ + [ + 'class' => '\fecshop\app\appserver\modules\General\Module', + 'params'=> [ + ], + ] +]; \ No newline at end of file diff --git a/app/appserver/modules/AppserverController.php b/app/appserver/modules/AppserverController.php index 959bb29bbfab0ae2e9051d971828c677b892c5f9..f26edc2e9beb4d637845dc3bbe6e76b17732fd87 100644 --- a/app/appserver/modules/AppserverController.php +++ b/app/appserver/modules/AppserverController.php @@ -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) { diff --git a/app/appserver/modules/Cms/Module.php b/app/appserver/modules/Cms/Module.php new file mode 100644 index 0000000000000000000000000000000000000000..f9a9973430544d875d37178ce043a106ffb0c9c5 --- /dev/null +++ b/app/appserver/modules/Cms/Module.php @@ -0,0 +1,44 @@ + + * @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(); + } +} diff --git a/app/appserver/modules/Cms/controllers/HomeController.php b/app/appserver/modules/Cms/controllers/HomeController.php new file mode 100644 index 0000000000000000000000000000000000000000..958fccb12d308ebd9be9b0451c82afe6469a65b9 --- /dev/null +++ b/app/appserver/modules/Cms/controllers/HomeController.php @@ -0,0 +1,98 @@ + + * @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 diff --git a/app/appserver/modules/General/Module.php b/app/appserver/modules/General/Module.php new file mode 100644 index 0000000000000000000000000000000000000000..4ae9a83d5e5fa94b8fae518e9a47fa77c86d69c0 --- /dev/null +++ b/app/appserver/modules/General/Module.php @@ -0,0 +1,44 @@ + + * @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(); + } +} diff --git a/app/appserver/modules/General/controllers/BaseController.php b/app/appserver/modules/General/controllers/BaseController.php new file mode 100644 index 0000000000000000000000000000000000000000..e2a9c29624323b53a19e205e248dd296bff821ac --- /dev/null +++ b/app/appserver/modules/General/controllers/BaseController.php @@ -0,0 +1,56 @@ + + * @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 diff --git a/services/Category.php b/services/Category.php index 334e2080d3ce8e67b8ddcb7de952c0f6e90e7e1f..cd5b1e0afbae18d3a88ee539e00261e796338976 100644 --- a/services/Category.php +++ b/services/Category.php @@ -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); } /** diff --git a/services/Store.php b/services/Store.php index 7c5521173664ec64863f2793b9285c2acb96ef1f..62fc8def15a756abcead571101c9a95b586fdb16 100644 --- a/services/Store.php +++ b/services/Store.php @@ -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; } } diff --git a/services/category/CategoryMongodb.php b/services/category/CategoryMongodb.php index d26ee026b8a875718004951eda285c06e88d3bf2..5a68034dd13b83e850b5fe7f4431962f0a7853d9 100644 --- a/services/category/CategoryMongodb.php +++ b/services/category/CategoryMongodb.php @@ -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); } } } diff --git a/services/category/Product.php b/services/category/Product.php index 558bba4d18a6f9b7b2c401a379ca36df4a910e79..376ced44bd37facb3091a7ff567c9481afe6c132 100644 --- a/services/category/Product.php +++ b/services/category/Product.php @@ -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'], ]; } } diff --git a/yii/filters/auth/QueryParamAuth.php b/yii/filters/auth/QueryParamAuth.php index ee4020feb7fa78f56f042f198d99be6d93afd991..42656fb5bb21a1c9911878e3393d4dad4f5e5464 100644 --- a/yii/filters/auth/QueryParamAuth.php +++ b/yii/filters/auth/QueryParamAuth.php @@ -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(); } }