提交 6929a85c 编写于 作者: R root

x

上级 ecc1d219
<?php
# 本文件在app/web/index.php 处引入。
#
# fecshop的核心模块
$modules = [];
foreach (glob(__DIR__ . '/modules/*.php') as $filename){
$modules = array_merge($modules,require($filename));
}
return [
'modules'=>$modules,
/* only config in front web */
'bootstrap' => ['store'],
];
<?php
return [
'fecadmin' => [
'class' => '\fecadmin\Module',
//'controllerMap' => [
// 'login' => [
// 'class' => 'appadmin\local\fecadmin\controllers\LoginController',
// ],
//
//],
],
];
<?php
# 本文件在app/web/index.php 处引入。
#
# fecshop - appfront 的核心模块
$modules = [];
foreach (glob(__DIR__ . '/modules/*.php') as $filename){
$modules = array_merge($modules,require($filename));
}
# 此处也可以重写fecshop的组件。供调用。
return [
'modules'=>$modules,
/* only config in front web */
'bootstrap' => ['store'],
];
<?php
return [
'cms' => [
'class' => '\fecshop\app\appfront\modules\Cms\Module',
],
];
<?php
namespace fecshop\app\appfront\modules;
use Yii;
use fec\controllers\FecController;
use yii\base\InvalidValueException;
class AppfrontController extends FecController
{
protected $_currentLayoutFile = 'main.php';
protected $_themeDir = '@fecshop/app/appfront/theme/base/default';
public function beforeAction($action){
if(parent::beforeAction($action)){
Yii::$app->page->theme->fecshopThemeDir = Yii::getAlias($this->_themeDir);
return true;
}
}
public function render($view, $params = []){
$viewFile = '';
$relativeFile = $this->module->id.'/'.$this->id.'/'.$view.'.php';
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.'/'.$relativeFile;
if(file_exists($file)){
$viewFile = $file;
break;
}
}
}
if(!$viewFile){
$notExistFile = [];
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.'/'.$relativeFile;
$notExistFile[] = $file;
}
}
throw new InvalidValueException('view file is not exist in'.implode(',',$notExistFile));
}
$content = $this->getView()->renderFile($viewFile, $params, $this);
return $this->renderContent($content);
}
public function findLayoutFile($view){
$layoutFile = '';
$relativeFile = '/layouts/'.$this->_currentLayoutFile;
$absoluteDir = Yii::$app->page->theme->getThemeDirArr();
foreach($absoluteDir as $dir){
if($dir){
$file = $dir.$relativeFile;
if(file_exists($file)){
$layoutFile = $file;
return $layoutFile;
}
}
}
throw new InvalidValueException('layout file is not exist!');
}
}
<?php
namespace fecshop\app\appfront\modules;
use Yii;
class AppfrontModule extends \yii\base\Module
{
/*
public function init()
{
# 以下代码必须指定
//$this->_currentDir = __DIR__ ;
//$this->_currentNameSpace = __NAMESPACE__;
# 指定默认的man文件
//$this->layout = "main_ajax.php";
parent::init();
}
*/
}
<?php
namespace fecshop\app\appfront\modules\Cms;
use Yii;
use fecshop\app\appfront\modules\AppfrontModule;
class Module extends AppfrontModule
{
public function init()
{
# 以下代码必须指定
# web controller
if (Yii::$app instanceof \yii\web\Application) {
$this->controllerNamespace = __NAMESPACE__ . '\\controllers';
# console controller
} elseif (Yii::$app instanceof \yii\console\Application) {
$this->controllerNamespace = __NAMESPACE__ . '\\console';
}
//$this->_currentDir = __DIR__ ;
//$this->_currentNameSpace = __NAMESPACE__;
# 指定默认的man文件
//$this->layout = "/main_ajax.php";
parent::init();
}
}
<?php
namespace fecshop\app\appfront\modules\Cms\controllers;
use fecshop\app\appfront\modules\AppfrontController;
class HomeController extends AppfrontController
{
protected $_currentLayoutFile = 'home.php';
# վϢ
public function actionIndex()
{
//echo 111;exit;
return $this->render($this->action->id,[]);
}
}
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use fecadmin\myassets\AppAsset;
use common\widgets\Alert;
use fec\helpers\CUrl;
use fecadmin\views\layouts\Head;
use fecadmin\views\layouts\Footer;
use fecadmin\views\layouts\Header;
use fecadmin\views\layouts\Menu;
//AppAsset::register($this);
//$cssAndJs = Head::getJsAndCss();
//var_dump( $cssAndJs['js']);exit;
//$this->assetBundles["fecadmin\myassets\AppAsset"]->js = $cssAndJs['js'];
//$this->assetBundles["fecadmin\myassets\AppAsset"]->css = $cssAndJs['css'];
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
//$publishedPath = $this->assetManager->publish('@fecadmin/myassets/dwz_jui-master/dwz.frag.xml');
?>
</head>
<body>
<?php $this->beginBody() ?>
343243245
<div id="layout">
<div id="header">
</div>
<?= $content ?>
</div>
<footer class="footer">
<div class="container">
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
# 本文件在app/web/index.php 处引入。
# fecshop的核心模块
/*
$modules = [];
foreach (glob(__DIR__ . '/modules/*.php') as $filename){
$modules = array_merge($modules,require($filename));
}
*/
# 服务器组件
$services = [];
foreach (glob(__DIR__ . '/services/*.php') as $filename){
$services = array_merge($services,require($filename));
}
return [
//'modules'=>$modules,
'components' => $services,
/* only config in front web */
//'bootstrap' => ['store'],
];
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
'category' => [
'class' => 'fecshop\services\Category',
//'terry' => 'xxxx',
# ӷ
'childService' => [
'product' => [
'class' => 'fecshop\services\category\Product',
],
'menu' => [
'class' => 'fecshop\services\category\Menu',
//'rootCategoryId' => 0,
],
],
],
];
\ 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 [
'Customer' => [
'class' => 'fecshop\services\Customer',
# ӷ
'childService' => [
'address' => [
'class' => 'fecshop\services\customer\Address',
],
'affiliate' => [
'class' => 'fecshop\services\customer\Affiliate',
],
'coupon' => [
'class' => 'fecshop\services\customer\Coupon',
],
'dropship' => [
'class' => 'fecshop\services\customer\Dropship',
],
'favorite' => [
'class' => 'fecshop\services\customer\Favorite',
],
'message' => [
'class' => 'fecshop\services\customer\Message',
],
'order' => [
'class' => 'fecshop\services\customer\Order',
],
'point' => [
'class' => 'fecshop\services\customer\Point',
],
'review' => [
'class' => 'fecshop\services\customer\Review',
],
'wholesale' => [
'class' => 'fecshop\services\customer\Wholesale',
],
],
],
];
\ 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 [
'page' => [
'class' => 'fecshop\services\Page',
//'terry' => 'xxxx',
# ӷ
'childService' => [
'breadcrumbs' => [
'class' => 'fecshop\services\page\Breadcrumbs',
'homeName' => 'Home', # if homeName => '', Home will not show in breadcrums.
'ifAddHomeUrl' => true, # default true, if set false, home will not add url (a).
//'intervalSymbol'=> ' >> ' # default value:' > '
],
'cms' => [
'class' => 'fecshop\services\page\Cms',
],
'theme' => [
'class' => 'fecshop\services\page\Theme',
],
'currency' => [
'class' => 'fecshop\services\page\Currency',
'currencys' => [
'USD' => [
'rate' => 1,
'symbol' => '$',
],
'RMB' => [
'rate' => 6.3,
'symbol' => '',
],
],
//'defaultCurrency' => 'USD',
],
'footer' => [
'class' => 'fecshop\services\page\Footer',
/*
'textTerms' => [
[
'text' => 'Company Info',
'urlPath' => 'company-info.html',
'child' => [
[
'text' => 'About US',
'urlPath' => 'about-us.html',
],
[
'text' => 'Site Map',
'urlPath' => 'site-map.html',
],
]
],
[
'text' => 'Payment Shipping',
'urlPath' => 'payment-shipping.html',
'child' => [
[
'text' => 'Payment Guide',
'urlPath' => 'payment-guide.html',
],
[
'text' => 'Shipping Guide',
'urlPath' => 'shipping-guide.html',
],
[
'text' => 'Locations We Ship To',
'urlPath' => 'locations-we-ship-to.html',
],
]
],
[
'text' => 'Policies & Service',
'urlPath' => 'policies-service.html',
'child' => [
[
'text' => 'Terms of Use',
'urlPath' => 'terms-of-use.html',
],
[
'text' => 'Help For Order',
'urlPath' => 'help-for-order.html',
],
[
'text' => 'Privacy Policy',
'urlPath' => 'privacy-policy.html',
],
]
],
[
'text' => 'Partner Program',
'urlPath' => 'company-info.html',
'child' => [
[
'text' => 'Affiliate Program',
'urlPath' => 'about-us.html',
],
[
'text' => 'Wholesale',
'urlPath' => 'site-map.html',
],
[
'text' => 'See All',
'urlPath' => 'see-all.html',
],
[
'text' => '',
'urlPath' => '',
],
]
],
],
*/
],
'newsletter' => [
'class' => 'fecshop\services\page\Newsletter',
],
'staticblock' => [
'class' => 'fecshop\services\page\StaticBlock',
],
'menu' => [
'class' => 'fecshop\services\page\Menu',
'displayHome' => [
'enable' => true,
'display'=> 'Home',
],
/**
* custom menu in the front menu section.
*/
'frontCustomMenu' => [
[
'name' => 'my custom menu',
'urlPath' => '/my-custom-menu.html',
'childMenu' => [
[
'name' => 'my custom menu 2',
'urlPath' => '/my-custom-menu-2.html',
],
[
'name' => 'my custom menu 2',
'urlPath' => '/my-custom-menu-2.html',
'childMenu' => [
[
'name' => 'my custom menu 2',
'urlPath' => '/my-custom-menu-2.html',
],
[
'name' => 'my custom menu 2',
'urlPath' => '/my-custom-menu-2.html',
],
],
],
],
],
[
'name' => 'my custom menu 2',
'urlPath' => '/my-custom-menu-2.html',
],
],
/**
* custom menu behind the menu section.
*/
'behindCustomMenu' => [
[
'name' => 'my behind custom menu',
'urlPath' => '/my-behind-custom-menu.html',
],
[
'name' => 'my behindcustom menu 2',
'urlPath' => '/my-behind-custom-menu-2.html',
],
],
],
],
],
];
\ 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 [
'product' => [
'class' => 'fecshop\services\Product',
//'terry' => 'xxxx',
# ӷ
'childService' => [
'image' => [
'class' => 'fecshop\services\product\Image',
'imageFloder' => 'media/catalog/product',
],
'price' => [
'class' => 'fecshop\services\product\Price',
],
'review' => [
'class' => 'fecshop\services\product\Review',
],
'info' => [
'class' => 'fecshop\services\product\Info',
],
'coll' => [
'class' => 'fecshop\services\product\Coll',
//'numPerPage' => 50, # default
//'pageNum' => 1, # default
//'orderBy' => ['_id' => SORT_DESC ], # default
//'allowMaxPageNum' => 200, # default
],
'bestSell' => [
'class' => 'fecshop\services\product\BestSell',
],
'viewLog' => [
'class' => 'fecshop\services\product\ViewLog',
'childService' => [
'session' => [
'class' => 'fecshop\services\product\viewLog\Session',
],
'db' =>[
'class' => 'fecshop\services\product\viewLog\Db',
//'table' => '', # custom table, you must create this mysql table before you use it.
],
'mongodb' =>[
'class' => 'fecshop\services\product\viewLog\Mongodb',
'collection' => '',
],
],
],
],
],
];
\ 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 [
'store' => [
'class' => 'fecshop\services\Store',
'stores' => [
/*
'demo.www.fecshop.com' => [
'language' => 'en',
'themePackage' => 'default',
'theme' => 'default',
'currency' => 'USD',
],
'admin.fancyecommerce.com' => [
'language' => 'cn',
'themePackage' => 'default',
'theme' => 'default',
'currency' => 'RMB',
],
*/
],
'languages' => [
//'en','fr','it','de','es','nl','pt','ru',
],
],
];
\ 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 [
'url' => [
'class' => 'fecshop\services\Url',
],
];
\ No newline at end of file
<?php
use yii\db\Migration;
class m160607_052627_log_product_view extends Migration
{
public function up()
{
$sql1 = "
CREATE TABLE `fecshop`.`log_product_view` (
`id` INT( 25 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date_time` DATETIME NULL ,
`product_id` INT( 20 ) NULL ,
`sku` VARCHAR( 100 ) NULL ,
`image` VARCHAR( 255 ) NULL ,
`name` VARCHAR( 255 ) NULL ,
`user_id` INT NULL
) ENGINE = InnoDB;
";
$this->execute($sql1);
$sql2 = "
ALTER TABLE `log_product_view` ADD INDEX (`user_id` , `date_time` ) ;
";
$this->execute($sql2);
}
public function down()
{
echo "m160607_052627_log_product_view cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
<?php
class m160608_062040_mongodb_log_product_view extends \yii\mongodb\Migration
{
public function up()
{
$columns = ['user_id','date_time'];
$this->createIndex('log_product_view', $columns);
}
public function down()
{
echo "m160608_062040_mongodb_log_product_view cannot be reverted.\n";
return false;
}
}
<?php
class m160608_061933_mongodb_url_write extends \yii\mongodb\Migration
{
public function up()
{
# url_write: _id, type ,custom_url, yii_url
# index: [custom_url] , [type]
$columns = ['custom_url'];
$this->createIndex('url_rewrite', $columns);
$columns = ['type'];
$this->createIndex('url_rewrite', $columns);
}
public function down()
{
echo "m160608_061933_mongodb_url_write cannot be reverted.\n";
return false;
}
}
......@@ -8,7 +8,7 @@
*/
namespace fecshop\models\db\product;
use Yii;
use yii\db\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
......@@ -29,5 +29,4 @@ class ViewLog extends ActiveRecord
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\models\mongodb;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Category extends ActiveRecord
{
public static function collectionName()
{
return '{{%category}}';
}
public function attributes()
{
return [
'_id',
'parent_id',
'name',
'status',
'url_key',
'url_path',
'thumbnail_image',
'image',
'description',
'title',
'meta_description',
'meta_keywords',
'include_in_menu',
'is_feature',
'available_sort_by',
'default_sort_by',
'theme',
'active_from',
'active_to',
//other
/*
category filter
category product
*/
];
}
}
\ 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\models\mongodb;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class CategoryProduct extends ActiveRecord
{
public static function collectionName()
{
return '{{%category_product}}';
}
public function attributes()
{
return [
'_id',
'product_id',
'category_id',
];
}
}
\ 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\models\mongodb;
use Yii;
use yii\mongodb\ActiveRecord;
use yii\helpers\CDate;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Newsletter extends ActiveRecord
{
public static function collectionName()
{
return 'newsletter';
}
public function attributes()
{
return [
'_id',
'email',
'created_at',
'send_mail_count'
];
}
public function rules()
{
$parent_rules = parent::rules();
$current_rules = [
['email', 'filter', 'filter' => 'trim'],
['email', 'email'],
// ['email', 'validateEmail'],
];
return array_merge($parent_rules,$current_rules) ;
}
/*
public function validateEmail($attribute, $params){
//$user = User::findByUsername($this->username)
if($this->_id){
$one = Newsletter::find()->where('<>','_id',$this->_id)
->andWhere('email' => $this->email)
->one();
if($one['id']){
$this->addError($attribute,"the email is exist,you can not change!");
}
}else{
$one = Newsletter::find()->where('email' => $this->email)
->one();
if($one['id']){
$this->addError($attribute,"the email is subscription by other");
}
}
}
*/
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$now_date = CDate::getCurrentDateTime();
if($insert == self::EVENT_BEFORE_INSERT)
$this->created_at = $now_date;
$this->updated_at = $now_date;
return true;
} else {
return false;
}
}
}
\ 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\models\mongodb;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Product extends ActiveRecord
{
public static function collectionName()
{
return '{{%product}}';
}
public function attributes()
{
return [
'_id',
'name',
'sku',
'weight',
'status',
'qty',
'is_in_stock',
'visibility',
'url_key',
'url_path',
'price',
'cost_price',
'special_price',
'special_from',
'special_to',
'tier_price',
'now_price', # 算出来的最终价格。这个通过脚本赋值。
'new_product_from',
'new_product_to',
'freeshipping',
'featured',
'upc',
'meta_title',
'meta_keywords',
'meta_description',
'image',
'sell_7_count',
'sell_30_count',
'sell_90_count',
'description',
'short_description',
'custom_option',
'remark',
//other
/*
related product
buy this product also buy
view this product also view
categories
product views
product template.
*/
];
}
}
\ 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\models\mongodb;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class UrlRewrite extends ActiveRecord
{
public static function collectionName()
{
return 'url_rewrite';
}
public function attributes()
{
return [
'_id', 'type',
'custom_url',
'yii_url', 'status'
];
}
}
\ 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\models\mongodb\product;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class ViewLog extends ActiveRecord
{
public static $_collectionName;
public static function collectionName()
{
return self::$_collectionName;
}
public static function setCurrentCollectionName($name){
self::$_collectionName = $name;
}
public function attributes()
{
return [
'_id', 'date_time',
'product_id',
'sku', 'image' ,
'name', 'user_id'
];
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
/**
* Blog
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Blog extends Service
{
public function getCategoryMenu(){
}
public function getArticleList(){
}
public function getCategoryArticleList(){
}
public function getArticleById(){
}
public function saveArticle(){
}
public function deleteArticle(){
}
public function saveCategory(){
}
public function deleteCategory(){
}
public function getCategoryById(){
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
/**
* Cart services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Cart extends Service
{
public $noLoginUserCartStorage = 'session';
public $cartMergeCurrency = 'current' ;# 当购物车合并的时候,当前的货币和购物车的货币不一致的情况下,以哪个为准?
public $cartMergeLanguage = 'current'; # 当购物车合并的时候,当前的语言和购物车的语言不一致的情况下,以哪个为准?
protected $cartMergeCurrencyArr = ['current','account',]; # 在用户登录账户的时候,当前的货币和语言与购物车的货币和语言不一致的情况下,current代表是当前为准则,account代表以购物车为准则
/**
* @property $item|Array
* add product info to cart,before add to cart,check if product is exist in db,
* check if product info is correct .
* then , if customer is login,use db to save customer cart info, else,
* use session to save custom cart info, also ,you can config varibale $noLoginUserCartStorage ,save cart info to db.
*
*/
public function addProductToCart($item){
}
public function getUserCartInfo(){
}
public function changeItemQty($sku){
}
/**
* merge cart , if current cart currency is not equals to user cart currency when user login account.
*/
public function mergeCartAfterUserLogin(){
}
/**
* change current cart currency
* 1. check if currency is allowed to change.
*/
public function changeCartCurrency(){
}
/**
* @property $language|String
* change current language , cart product language change to current language.
*/
public function changeProductLanguage($language=''){
}
/**
* @property $address|Array
* save cart address.like,, customer name,tel,email,address ,,etc,,.
*/
public function saveCartAddress($address){
}
/**
* @property $shippingId | Int
* 1.check if $shippingId is effective
* 2.add or change shipping to cart.
* 3.change shipping cost after change
*
*/
public function saveCartShipping($shippingId){
}
/**
* @property $payment | Int
* 1.check if $paymentId is effective
* 2.add or change payment to cart.
*/
public function saveCartPayment($paymentId){
}
/**
* $item_ids
* remove cart items by $items_ids
*/
public function removeItems($item_ids){
}
/**
* clear cart product.
*/
public function clearCart(){
}
/**
* generate order by current Cart.
*/
public function generateOrderByCart(){
}
/**
* add cart items by pending order Id
* 1. check if the order is exist ,and belong to current customer.
* 2. get all item sku and custom option.
* 3. add to cart like in product page ,click add to cart button.
*/
public function addItemsByPendingOrder($order_id){
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
/**
* Category Service is the component that you can get category info from it.
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Category extends Service
{
}
\ 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\services;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class ChildService
{
public $childService;
public $_childService;
/**
* 得到services 里面配置的子服务childService的实例
*/
public function getChildService($childServiceName){
if(!$this->_childService[$childServiceName]){
$childService = $this->childService;
if(isset($childService[$childServiceName])){
$service = $childService[$childServiceName];
$this->_childService[$childServiceName] = Yii::createObject($service);
}else{
throw new InvalidConfigException('Child Service ['.$childServiceName.'] is not find in '.get_called_class().', you must config it! ');
}
}
return $this->_childService[$childServiceName];
}
/**
*
*/
public function __get($attr){
return $this->getChildService($attr);
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
/**
* Coupon
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Coupon extends Service
{
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
/**
* Customer service
* @property Image|\fecshop\services\Product\Image $image ,This property is read-only.
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Customer extends Service
{
/**
* @property $data|Array
* like :['email'=>'xxx@xxx.com','password'=>'xxxx']
*/
public function login($data){
}
/**
* @property $data|Array
* register customer account
* ['email','firstname','lastname','password'
* ,'sex','age',
* ]
*/
public function register($data){
}
/**
* @property $customerId|Int
* Get customer info by customerId, if customer id is empty, current customer id will be set,
* if current customer id is empty , false will be return .
*/
public function viewInfo($customerId = ''){
}
/**
* @property $password|String
* @property $customerId|Int
* change customer password.
* if $customer id is empty, it will be equals current customer id.
*/
public function changePassword($password,$customerId=''){
}
/**
* @property $customerId|Array
* ['firstname','lastname','password','customerId']
*/
public function changeNameAndPassword($data){
}
/**
* get current customer identify.
*/
public function getCurrentAccount(){
return Yii::$app->user->identity->username;
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
/**
* Cart services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Order extends Service
{
protected $orderStatus = [
'pending','processing'
];
/**
* get all order collection
*/
public function getOrderList(){
}
/**
* get order list by customer account id.
*/
public function getAccountOrderList(){
}
/**
* get order list by customer account id.
*/
public function changeOrderStatus(){
}
/**
* get order by Id.
*/
public function getOrderById(){
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
/**
* Page services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Page extends Service
{
}
\ No newline at end of file
......@@ -18,57 +18,7 @@ use yii\base\InvalidConfigException;
*/
class Product extends Service
{
public $_productId;
/**
* 1.得到单个产品的详细信息。
* 2.通过当前的语言,名字,描述等都会被转换成当前语言的value
* 3.价格将会被转换成当前货币的价格。
* 4.图片将会被转换成url(根据当前的domain)
* 5.这个功能提供给产品详细页面使用。返回的值比较全面
*/
public function getProductInfo($productId='',$selectAttr=[])
{
if(!$productId)
$productId = $this->getCurrentProductId();
if(!$productId)
throw new InvalidValueException('productId is empty,you must pass a ProductId');
}
/**
* 通过where条件,得到product的数组,
* 您可以在 $selectAttr 中指定返回的字段。
* 如果您选择的属性中有图片,那么图片将会返回url
* 这个功能给分类页面使用
*/
public function getProductCollByWhere($where , $selectAttr){
}
/**
* 得到销量最好的产品,这个给首页等其他地方使用
*/
public function getBestSellProduct(){
}
/**
* 得到某个分类的产品销量最好
*/
public function getCategoryBestSellProduct(){
return Yii::$app->product->bestSell->getCategoryProduct();
}
private $_productId;
public function setCurrentProductId($productId){
$this->_productId = $productId;
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\models\mongodb\UrlRewrite;
/**
* rewrite class \yii\web\Request
* use custom url in our system, example: www.example.com/xxxxx.html, this file is not
* exit in our system, In order to consider SEO, we can use db storage map between custom url and yii url
* when request visit /xxxx.html, select this custom url in mongodb, return the yii url ,ex. /product/index?_id=3
* then , resolve /product/index?_id=3 .
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Request extends \yii\web\Request
{
/**
* rewrite yii\web\Request resolveRequestUri()
*/
protected function resolveRequestUri()
{
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // IIS
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
if ($requestUri !== '' && $requestUri[0] !== '/') {
$requestUri = preg_replace('/^(http|https):\/\/[^\/]+/i', '', $requestUri);
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0 CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
throw new InvalidConfigException('Unable to determine the request URI.');
}
/**
* Replace Code
* //return $requestUri;
* To:
*/
return $this->getRewriteUri($requestUri);
}
/**
* get module request url by db ;
*/
protected function getRewriteUri($requestUri){
$urlPath = '';
$urlParam = '';
$urlParamSuffix = '';
if(strstr($requestUri,"#")){
list($urlNoSuffix,$urlParamSuffix)= explode("#",$requestUri);
if(strstr($urlNoSuffix,"?")){
list($urlPath,$urlParam)= explode("?",$urlNoSuffix);
}
}else if(strstr($requestUri,"?")){
list($urlPath,$urlParam)= explode("?",$requestUri);
}else{
$urlPath = $requestUri;
}
if($urlParamSuffix){
$urlParamSuffix = '#'.$urlParamSuffix;
}
if($yiiUrlPath = $this->getYiiUrl($urlPath)){
if(strstr($yiiUrlPath,'?')){
if($urlParam){
$url = $yiiUrlPath.'&'.$urlParam.$urlParamSuffix;
}else{
$url = $yiiUrlPath.$urlParamSuffix;
}
$this->setRequestParam($yiiUrlPath);
}else{
if($urlParam){
$url = $yiiUrlPath.'?'.$urlParam.$urlParamSuffix;
}else{
$url = $yiiUrlPath.$urlParamSuffix;
}
}
return $url;
}else{
return $requestUri;
}
}
/**
* after get urlPath from db, if urlPath has get param ,
* set the param to $_GET
*/
public function setRequestParam($yiiUrlPath){
$arr = explode("?",$yiiUrlPath);
$yiiUrlParam = $arr[1];
$arr = explode("&",$yiiUrlParam);
foreach($arr as $a){
list($key,$val) = explode("=",$a);
$_GET[$key] = $val;
}
}
/**
* mongodb url_rewrite collection columns: _id, type ,custom_url, yii_url,
* if selete date from UrlRewrite, return the yii url.
*/
protected function getYiiUrl($urlPath){
$UrlData = UrlRewrite::find()->where([
'custom_url' => $urlPath,
])->asArray()->one();
if($UrlData['custom_url']){
return $UrlData['yii_url'];
}
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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
/**
* Search
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Search extends Service
{
public function getProductList($text,$filter){
}
public function getHotSearchText(){
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use yii\base\BootstrapInterface;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Store extends Service implements BootstrapInterface
{
/**
* init by config file.
* all stores config . include : domain,language,theme,themePackage
*/
public $stores;
/**
* init by config file.
* all store Language.
*/
public $languages;
/**
* current store language
*/
public $currentLanguage = 'en';
/**
* current store theme package
*/
public $currentThemePackage = 'default';
/**
* current store theme
*/
public $currentTheme = 'default';
/**
* current store name , this property will init value with domain.
*/
public $currentStore;
/**
* Bootstrap:init website, class property $currentLanguage ,$currentTheme and $currentStore.
* if you not config this ,default class property will be set.
* if current domain is not config , InvalidValueException will be throw.
* class property $currentStore will be set value $domain.
*/
public function bootstrap($app){
$host = explode('://' ,$app->getHomeUrl());
$stores = $this->stores;
$init_compelte = 0;
if(is_array($stores) && !empty($stores)){
foreach($stores as $domain => $lang){
if($host[1] == $domain){
Yii::$app->store->currentStore = $domain;
if(isset($lang['language']) && !empty($lang['language'])){
Yii::$app->store->currentLanguage = $lang['language'];
}
if(isset($lang['theme']) && !empty($lang['theme'])){
Yii::$app->store->currentTheme = $lang['theme'];
}
if(isset($lang['themePackage']) && !empty($lang['themePackage'])){
Yii::$app->store->currentThemePackage = $lang['themePackage'];
}
/**
* init store currency.
*/
if(isset($lang['currency']) && !empty($lang['currency'])){
$currency = $lang['currency'];
}else{
$currency = '';
}
Yii::$app->page->currency->initCurrency($currency);
/**
* current domian is config is store config.
*/
$init_compelte = 1;
}
}
}
if(!$init_compelte){
throw new InvalidValueException('this domain is not config in store component');
}
}
/**
* if a object or array attribute is a store attribute, you can get current
* language value by this function.
*/
public function getLangVal($attr,$attrName){
return $attr[$this->currentLanguage."_".$attrName];
}
public function getAllLanguage(){
}
}
\ 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\services;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use yii\base\BootstrapInterface;
use fecshop\models\mongodb\UrlRewrite;
use fec\helpers\CUrl;
/**
*
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Url extends Service
{
/**
* save custom url to mongodb collection url_rewrite
* @param $urlArr|Array, example:
* $urlArr = [
* 'custom_url' => '/xxxx.html',
* 'yii_url' => '/product/index?_id=32',
* ];
* @param $type|String.
*/
public function saveCustomUrl($urlArr,$type='system'){
$data = UrlRewrite::find()->where([
'custom_url' => $urlArr['custom_url'],
])->asArray()->one();
if(isset($data['custom_url'])){
throw new InvalidValueException('custom_url is exist in mongodb collection url_rewrite,which _id is:'.$data['_id']);
}else{
$arr = [
'type' => $type,
'custom_url'=> $urlArr['custom_url'],
'yii_url' => $urlArr['yii_url'],
];
$UrlRewrite = UrlRewrite::getCollection();
$UrlRewrite->save($arr);
return true;
}
}
public function getUrlByPath($path){
return CUrl::getHomeUrl().'/'.$path;
}
}
\ 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\services\category;
use Yii;
use fec\helpers\CDir;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fecshop\models\mongodb\Category;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Menu extends ChildService
{
public $rootCategoryId = 0;
/**
* @property $parentId|Int
* get category menu as array. array key is: _id ,name ,urlPath,childMenu
*
*/
public function getCategoryMenuArr($parentId=''){
$arr = [];
if(!$parentId)
$parentId = $this->rootCategoryId;
$data = Category::find()->asArray()->select([
'_id','parent_id','name','url_path'
])->where([
'parent_id' => $parentId
])->all();
if(is_array($data) && !empty($data)){
foreach($data as $category){
$categoryOne = [
'_id' => $category['_id'];
'name' => Yii::$app->store->getLangVal($category['name'],'name'),
'urlPath' => $category['url_path'],
]
$childMenu = $this->getCategoryMenuArr($category['parent_id']);
if($childMenu){
$categoryOne['childMenu'] = $childMenu;
}
$arr[] = $categoryOne;
}
return $arr;
}
return '';
}
/**
* @property $categoryId|Array
* check if cateogry has child .
*/
public function hasChild($categoryId){
$one = Category::find()->asArray()->where([
'parent_id' => $categoryId
])->one();
if($one['_id'])
return true;
return false;
}
}
\ 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\services\category;
use Yii;
use fec\helpers\CDir;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fecshop\models\mongodb\Category;
use fecshop\models\mongodb\Product;
use fecshop\models\mongodb\CategoryProduct;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Product extends ChildService
{
public $pageNum = 1;
public $numPerPage = 50;
public $allowedNumPerPage ;
/**
* [
'categoryId' => 1,
'pageNum' => 2,
'numPerPage' => 50,
'orderBy' => 'name',
'where' => [
'price' => [
'?gte' => 11,
'?lt' => 22
],
],
]
*/
public function getFilterProduct($filter){
$where = isset($filter['where']) ? $filter['where'] : '';
$categoryId = isset($filter['categoryId']) ? $filter['categoryId'] : '';
if($categoryId){
$productIds = $this->getProductIdsByCategoryId($categoryId);
$where['_id'] = ['?in' => $productIds];
}
$pageNum = isset($filter['pageNum']) ? $filter['pageNum'] : $this->pageNum;
$numPerPage = isset($filter['numPerPage']) ? $filter['numPerPage'] : $this->numPerPage;
$orderBy = isset($filter['orderBy']) ? $filter['orderBy'] : '';
$offset = ($pageNum - 1)*$numPerPage;
$query = Product::find()->asArray()->offset($offset)->limit($numPerPage);
if($orderBy)
$query->orderBy($orderBy);
return $query->all();
}
/**
* @property $categoryId|Int
* @return $productIds|Array
*/
protected function getProductIdsByCategoryId($categoryId){
$data = CategoryProduct::find()->asArray()->where([
'category_id' => $categoryId
])->all();
$productIds = [];
if(!empty($data)){
foreach($data as $one){
$productIds[] = $one['product_id'];
}
}
return $productIds;
}
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Address child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Address extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Affiliate child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Affiliate extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Coupon child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Coupon extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* DropShip child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class DropShip extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Favorite child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Favorite extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Message child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Message extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Order child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Order extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Point child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Point extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Review child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Review extends ChildService
{
}
\ 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\services\customer;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Wholesale child services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Wholesale extends ChildService
{
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Breadcrumbs extends ChildService
{
public $homeName = 'Home';
public $ifAddHomeUrl = true;
public $intervalSymbol = ' > ';
protected $_items;
/**
* property $items|Array. add $items to $this->_items.
* $items format example.
* $items = ['name'=>'fashion handbag','url'=>'http://www.xxx.com'];
*/
public function addItems($items){
$this->_items[] = $items;
}
public function init(){
if($this->homeName){
$items['name'] = $this->homeName;
if($this->ifAddHomeUrl)
$items['url'] = CUrl::getHomeUrl();
$this->addItems($items);
}
}
/**
* generate Breadcrumbs html ,before generate , you should use addItems function to add breadcrumbs items.
*/
public function generateHtml(){
$arr = [];
if($this->_items){
foreach($this->_items as $item){
$name = isset($item['name']) ? $item['name'] : '';
$url = isset($item['url']) ? $item['url'] : '';
if($name){
if($url){
$arr[] = '<a href="'.$url.'">'.$name.'</a>';
}else{
$arr[] = '<span>'.$name.'</span>';
}
}
}
}
if(!empty($arr))
return implode($this->intervalSymbol,$arr);
}
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Cms extends ChildService
{
public function getById(){
}
public function getCmsList($filter){
}
/**
* @property $date|Array
* save $data to cms model,then,add url rewrite info to system service urlrewrite.
*/
public function save($data){
}
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fecshop\services\ChildService;
/**
* Currency
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Currency extends ChildService
{
const CURRENCY_CURRENT = 'currency_current';
/**
* get all currency ,format:
* [
* 'USD' => [
* 'rate' => 1,
* 'symbol' => '$',
* ],
* 'RMB' => [
* 'rate' => 6.3,
* 'symbol' => 'ԧ',
* ],
* ]
*
*/
public $currencys;
/**
* default currency;
*/
public $defaultCurrency = 'USD';
private $_currentCurrency;
/**
* Get all currencys info.
*/
public function getAllCurrencys(){
$arr = [];
foreach($this->currencys as $code => $info){
$arr[$code] = [
'code' => $code ,
'rate' => $info['rate'] ,
'symbol' => $info['symbol'] ,
];
}
return $arr;
}
/**
* property $price|Float
* Get current currency price. price format is two decimal places,
* if current currency is not find in object variable $currencys(maybe change config in online shop,but current user session is effective),
* current currency will set defaultCurrency, origin price will be return.
*/
public function getCurrentCurrencyPrice($price){
if(isset($this->currencys[$this->getCurrentCurrency()]['rate'])){
$rate = $this->currencys[$this->getCurrentCurrency()]['rate'];
if($rate)
return ceil($price * $rate * 100)/100;
}
/**
* if error current will be set to default currency.
*/
$currency = $this->defaultCurrency ;
$this->setCurrentCurrency($currency);
return $price;
}
/**
* service Store bootstrap(Yii::$app->store->bootstrap()),
* call this function to init currency.
* 1. if current currency is set (get value from session), none will be done.
* 2. if store pass currency to this function, current currency will equals store currency.
* 3. if store not pass currency to this function ,defaultCurrency will be set.
*/
public function initCurrency($currency=''){
if(!$this->getCurrentCurrency()){
if(!$currency)
$currency = $this->defaultCurrency;
$this->setCurrentCurrency($currency);
}
}
public function getCurrentCurrency(){
if(!$this->_currentCurrency)
$this->_currentCurrency = CSession::get(self::CURRENCY_CURRENT);
return $this->_currentCurrency;
}
public function setCurrentCurrency($currency){
if($this->isCorrectCurrency($currency)){
CSession::set(self::CURRENCY_CURRENT,$currency);
}
}
/**
* check param currency if is contained in object variable $currencys.
*/
protected function isCorrectCurrency($currency){
foreach($this->currencys as $code => $info){
if($code == $currency)
return true;
}
return false;
}
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Footer extends ChildService
{
//public $textTerms;
const TEXT_TERMS = 'footer_text_terms';
const COPYRIGHT = 'footer_copyright';
const FOLLOW_USE = 'footer_follow_us';
const PAYMENT_IMG = 'footer_payment_img';
public function getTextTerms(){
Yii::$app->page->staticblock->get(self::TEXT_TERMS);
}
public function getCopyRight(){
Yii::$app->page->staticblock->get(self::COPYRIGHT);
}
public function followUs(){
Yii::$app->page->staticblock->get(self::FOLLOW_USE);
}
public function getPaymentImg(){
Yii::$app->page->staticblock->get(self::PAYMENT_IMG);
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
use fecshop\models\mongodb\Category;
/**
* Menu services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Menu extends ChildService
{
/**
* whether display HOME in the menu.
*/
public $displayHome;
/**
* custom menu that display in the front of product category.
*/
public $frontCustomMenu;
/**
* custom menu that display in the behind of product category.
*/
public $behindCustomMenu;
protected $_homeUrl;
/**
* return menu array data, contains:
* home,frontCustomMenu,productCategory,behindCustomMenu.
* example:
[
[
'name' => 'my custom menu',
'urlPath' => '/my-custom-menu.html',
'childMenu' => [
'name' => 'my custom menu',
'urlPath' => '/my-custom-menu.html',
],
],
[
...,
]
]
*/
public function getMenuData(){
$this->_homeUrl = CUrl::getHomeUrl();
$arr = [];
if($displayHome = $this->displayHome){
$enable = isset($displayHome['enable']) ?$displayHome['enable'] : '',
$display = isset($displayHome['display']) ?$displayHome['display'] : '',
if($enable && $display){
$arr[] = [
'name' => $display,
'urlPath' => '',
];
}
}
if($this->frontCustomMenu){
$arr[] = $this->frontCustomMenu,
}
$arr[] = $this->getProductCategoryMenu();
if($this->behindCustomMenu){
$arr[] = $this->behindCustomMenu,
}
return $arr;
}
/**
* get product category array as menu.
*/
protected function getProductCategoryMenu(){
return Yii::$app->category->menu->getCategoryMenuArr();
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
use fecshop\models\mongodb\Newsletter as MongoNewsletter;
/**
* Page Newsletter services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Newsletter extends ChildService
{
/**
* newsletter subscription
*/
public function subscription($email){
$mongoNewsletter = new MongoNewsletter();
$mongoNewsletter->attributes = [
'email' => $email,
];
if($mongoNewsletter->validate()){
$one = MongoNewsletter::find()->where('email' => $email)
->one();
if($one['id']){
return [
'code' => 300,
'description' => 'subscription email is exist',
];
}else{
$mongoNewsletter->save();
return [
'code' => 200,
'description' => 'subscription email success'
];
}
}else{
return [
'code' => 300,
'description' => 'subscription email format is not correct'
];
}
}
/**
* @property $filter|array
* get subscription email collection
*/
public function getSubscriptionList($filter){
}
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class StaticBlock extends ChildService
{
/**
* @property $key|Array
*
*/
public function getByKey($key,$lang=''){
if(!$lang)
$lang = Yii::$app->store->currentLanguage;
if(!$lang)
throw new InvalidValueException('language is empty');
}
/**
* @property $_id | Int
* get StaticBlock one data by $_id.
*/
public function getById($_id){
}
/**
* @property $filter | Array
* get StaticBlock collections by $filter .
*/
public function getStaticBlockList($filter){
}
}
\ 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\services\page;
use Yii;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fec\helpers\CSession;
use fec\helpers\CUrl;
use fecshop\services\ChildService;
/**
* Breadcrumbs services
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Theme extends ChildService
{
/**
* user current theme dir. Highest priority
*/
public $currentThemeDir;
/**
* $thirdThemeDir | Array
* user current theme dir.Second priority.
* array[0] priority is higher than array[1],
*/
public $thirdThemeDir;
/**
* fecshop theme dir. lower priority
*/
public $fecshopThemeDir ;
protected $_themeDirArr;
public function getThemeDirArr(){
if(!$this->_themeDirArr){
$arr = [];
$arr[] = Yii::getAlias($this->currentThemeDir);
$thirdThemeDirArr = $this->thirdThemeDir;
if(!empty($thirdThemeDirArr) && is_array($thirdThemeDirArr)){
foreach($thirdThemeDirArr as $theme){
$arr[] = Yii::getAlias($theme);
}
}
$arr[] = Yii::getAlias($this->fecshopThemeDir);
$this->_themeDirArr = $arr;
}
return $this->_themeDirArr;
}
}
\ No newline at end of file
......@@ -9,12 +9,12 @@
namespace fecshop\services\product;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
use fecshop\services\ChildService;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class BestSell extends Service
class BestSell extends ChildService
{
/**
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\product;
use Yii;
use fec\helpers\CDir;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fecshop\models\mongodb\Product;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Coll extends ChildService
{
/**
* the number of product info when get products collection in one page.
*/
public $numPerPage = 50;
/**
* the number of page when get products collectionss.
*/
public $pageNum = 1;
/**
* the table column and direction (SORT_ASC OR SORT_DESC) when get products collections.
*/
public $orderBy = ['_id' => SORT_DESC ];
/**
* the max PageNum allowed when get product collections
*/
public $allowMaxPageNum = 200;
/**
* @property $filter|Array.
* Get product collection .
* $filter is a Array Variable that user for filter product collection.
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
* 'where' => [
* 'price' => [
* '?gt' => 1,
* '?lt' => 10,
* ],
* 'sku' => 'uk10001',
* ],
* 'asArray' => true,
* ]
*/
public function getProducts($filter){
$numPerPage = isset($filter['numPerPage']) ? $filter['numPerPage'] : $this->numPerPage;
$pageNum = isset($filter['pageNum']) ? $filter['pageNum'] : $this->pageNum;
$orderBy = isset($filter['orderBy']) ? $filter['orderBy'] : $this->orderBy;
$where = isset($filter['where']) ? $filter['where'] : '';
$asArray = isset($filter['asArray']) ? $filter['asArray'] : true;
if($pageNum > $this->allowMaxPageNum)
throw new InvalidValueException("product pageNum is $pageNum, it can not > $this->allowMaxPageNum , you can change param pageNum , or chage config allowMaxPageNum in services product/coll");
$query = Product::find();
$offset = ($pageNum -1 ) * $numPerPage;
if($asArray)
$query->asArray();
if($where)
$query->where($where);
$query->limit($numPerPage)->offset($offset)->orderBy($orderBy);
return $query->all();
}
}
\ No newline at end of file
......@@ -8,28 +8,202 @@
*/
namespace fecshop\services\product;
use Yii;
use fec\helpers\CDir;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
use fecshop\services\ChildService;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Image extends Service
class Image extends ChildService
{
public $imagePath;
# get Current Product info
public function getProductImage()
{
return 'product Image info';
/**
* absolute image save floder
*/
public $imageFloder;
/**
* upload image max size
*/
public $maxUploadMSize;
/**
* allow image type
*/
public $allowImgType;
/**
* curent max upload size
*/
private $_maxUploadSize;
/**
* image absolute floder that can save product image,
* example:/www/web/fecshop/appadmin/web/media/catalog/product
*/
private $_imageBaseFloder;
/**
* image absolute url that product image saved,
* example:http://www.fecshop.com/media/catalog/product
*/
private $_imageBaseUrl;
/**
* default allowed image type ,if not set allowImgType in config file ,this value will be effective.
*/
private $_defaultAllowImgType = ['image/jpeg','image/gif','image/png'];
/**
* default allow image upload size (MB) ,if not set maxUploadMSize in config file ,this value will be effective.
*/
private $_defaultMaxUploadMSize = 2; #mb
/**
* default relative image save floder ,if not set imageFloder in config file ,this value will be effective.
*/
private $_defaultImageFloder = 'media/catalog/product';
//private $_image
/**
* @property $param_img_file | Array .
* upload image from web page , you can get image from $_FILE['XXX'] ,
* $param_img_file is get from $_FILE['XXX'].
* return , if success ,return image saved relative file path , like '/b/i/big.jpg'
* if fail, reutrn false;
*/
public function saveProductUploadImg($param_img_file){
$this->initUploadImage();
$size = $param_img_file['size'];
$file = $param_img_file['tmp_name'];
$name = $param_img_file['name'];
if($size > $this->_maxUploadSize){
throw new InvalidValueException('upload image is to max than '.($this->maxUploadSize/(1024*1024)));
}else if($img = getimagesize($file)){
$imgType = $img['mime'];
if(in_array($imgType,$this->allowImgType)){
}else{
throw new InvalidValueException('image type is not allow for '.$imgType);
}
}
// process image name.
$imgSavedRelativePath = $this->getImgSavedRelativePath($name);
$isMoved = @move_uploaded_file ( $file, $this->getImageBaseFloder().$imgSavedRelativePath);
if($isMoved){
return $imgSavedRelativePath;
}
return false;
}
protected function resize($imgPath,$width='',$height=''){
}
/**
* init Object property.
*/
protected function initUploadImage(){
if(!$this->allowImgType){
$this->allowImgType = $this->_defaultAllowImgType;
}
if(!$this->_maxUploadSize){
if($this->maxUploadMSize){
$this->_maxUploadSize = $this->maxUploadMSize * 1024 * 1024;
}else{
$this->_maxUploadSize = $this->_defaultMaxUploadMSize * 1024 * 1024;
}
}
$this->getImageFloder();
}
/**
* Get relative Floder that product image saved.
*/
protected function getImageFloder(){
if(!$this->imageFloder){
$this->imageFloder = $this->_defaultImageFloder;
}
}
/**
* Get absolute Floder that product image saved.
*/
protected function getImageBaseFloder(){
if(!$this->_imageBaseFloder){
if(!$this->imageFloder)
$this->getImageFloder();
$this->_imageBaseFloder = Yii::getAlias("@webroot").'/'. $this->imageFloder;
}
return $this->_imageBaseFloder;
}
/**
* Get Image base url string that product image saved floder.
*/
protected function getImageBaseUrl(){
if(!$this->_imageBaseUrl){
if(!$this->imageFloder)
$this->getImageFloder();
$this->_imageBaseUrl = Yii::$app->homeUrl.'/'. $this->imageFloder;
}
return $this->_imageBaseUrl;
}
public function getImageBasePath(){
return Yii::getAlias("@webroot").'/'. $this->imagePath;
/**
* get Image save file path, if floder is not exist, this function will create floder.
* if image file is exsit , image file name will be change to a not existed file name( by add radom string to file name ).
* return image saved relative path , like /a/d/advert.jpg
*/
protected function getImgSavedRelativePath($name){
list($imgName,$imgType) = explode('.',$name);
if(!$imgName || !$imgType){
throw new InvalidValueException('image file name and type is not correct');
}
if(strlen($imgName) < 2){
$imgName .= time(). mt_rand(100, 999);
}
$first_str = substr($imgName,0,1);
$two_str = substr($imgName,1,2);
$imgSaveFloder = CDir::createFloder($this->getImageBaseFloder(),[$first_str,$two_str]);
if($imgSaveFloder){
$imgName = $this->getUniqueImgNameInPath($imgSaveFloder,$imgName,$imgType);
$relative_floder = '/'.$first_str.'/'.$two_str.'/';
return $relative_floder.$imgName;
}
return false;
}
/**
* @property $imgSaveFloder|String image save Floder absolute Path
* @property $name|String , image file name ,not contain image suffix.
* @property $imageType|String , image file suffix. like '.gif','jpg'
* return saved Image Name.
*/
public function getBase(){
return $this->getChildService('base');
protected function getUniqueImgNameInPath($imgSaveFloder,$name,$imageType,$randStr=''){
$imagePath = $imgSaveFloder.'/'.$name.$randStr.'.'.$imageType;
if(!file_exists($imagePath)){
return $name.$randStr.'.'.$imageType;;
}else{
$randStr = time().rand(100,999);
return $this->getUniqueImgNameInPath($imgSaveFloder,$name,$imageType,$randStr);
}
}
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\product;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidValueException;
use fecshop\services\ChildService;
use fec\helpers\CDate;
use fec\helpers\CUser;
use fecshop\models\mongodb\Product;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Info extends ChildService
{
private $_product;
/**
* Get product info by special $productId.
* product language attributes will be set current language value.
* product price will be process to current price.
* image will return full image url
* this function will be use for front product info page.
*/
public function getProduct($productId='',$selectAttr=[])
{
//echo 33;exit;
if(!$this->_product){
if(!$productId){
$productId = Yii::$app->product->getCurrentProductId();
}
if(!$productId){
throw new InvalidValueException('productId is empty,you must pass a ProductId');
}
$product = Product::findOne([
'_id' => (int)$productId
]);
if($product_id){
$product->
$this->_product = $product;
}
}
return $this->_product;
}
/**
* @property $product is object.
* convert product language attribute to current language value.
*/
public function getCurrentLangProduct($product){
$lang_attrs = $this->getLangAttr();
foreach($lang_attrs as $attr){
$product->$attr = Yii::$app->store->getLangVal($product->$attr,$attr);
}
}
/**
* product language attributes array.
*/
public function getLangAttr(){
return [
'name',
'title',
'meta_keywords',
'meta_description',
'short_description',
'description',
];
}
}
\ No newline at end of file
......@@ -9,103 +9,43 @@
namespace fecshop\services\product;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
use fecshop\services\ChildService;
use fecshop\models\db\product\ViewLog as DbViewLog;
use fecshop\models\mongodb\product\ViewLog as MongodbViewLog;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class ViewLog extends Service
class ViewLog extends ChildService
{
public $type;
public $_defaultType = 'session';
public $_defaultViewTable = 'log_product_view';
public $_sessionKey = 'services_product_viewlog_history';
public $_maxProductCount = 10;
public $_currentType;
public $_currentTable;
public $_currentModel;
# 初始化
public function init(){
$configType = $this->type;
if(!$configType){
$configType = $this->_defaultType;
}
$configTypeArr = explode(',',$configType);
$storage = $configTypeArr[0];
if($storage == 'session'){
}else if(($storage == 'mysql') || ($storage == 'mongodb')){
if(isset($configTypeArr[1]) && $configTypeArr[1]){
$this->_currentTable = $configTypeArr[1];
}else{
$this->_currentTable = $this->_defaultViewTable;
}
if($storage == 'mysql'){
DbViewLog::setCurrentTableName($this->_currentTable);
}else if($storage == 'mongodb'){
MongodbViewLog::setCurrentCollectionName($this->_currentTable);
}
}else{
throw new InvalidConfigException('services:product->viewlog,config type is not right, you can
only config type in [session,mysql,mongodb]
,example:(1)session,(2)mysql.'.$this->_defaultViewTable.',(3)mongodb.'.$this->_defaultViewTable.'
if you config mysql or mongodb ,do not config table , default ('.$this->_defaultViewTable.') will use.
current file:'.get_called_class());
}
$this->_currentType = $storage;
}
/**
* 得到产品浏览的历史记录
*/
public function getHistory()
{
return 'category best sell product';
}
/**
* 保存产品的历史记录
*/
public function setHistory($productOb){
$logArr = [
'date_time' => CDate::getCurrentDateTime(),
'product_id'=> $productOb['id'],
'sku' => $productOb['sku'],
'image' => $productOb['image'],
'name' => is_array($productOb['name']) ? serialize($productOb['name']) : $productOb['name'],
* data:
$product = [
'id' => 44,
'sku' => 'ttt',
'image' => '/xx/tt/dfas/dsd.jpg',
'name' => 'xxxxx',
'user_id' => 22, # 如果选填,则通过user组件,选择当前的用户id
];
if($this->_currentType == 'session'){
if(!($session_history = CSession::get($this->_sessionKey))){
$session_history = [];
}else if(($count = count($session_history)) >= $this->_maxProductCount)){
$unsetMaxKey = $count - $this->_maxProductCount ;
for($i=0;$i<=$unsetMaxKey;$i++){
array_shift($session_history);
}
}
$session_history[] = $logArr;
CSession::set($this->_sessionKey,$session_history);
}else if(($this->_currentType == 'mysql'){
$this->_currentModel
$this->_currentTable
$fn_set_exec = $this->_currentModel.'::setCurrentTableName';
\call_user_func_array($fn_set_exec,[$this->_currentTable]);
}else if(($this->_currentType == 'mongodb'){
$this->_currentTable
}
}
#use mongodb save product view log history
Yii::$app->product->viewLog->mongodb->setHistory($product);
#use mongodb get product view log history
$d = Yii::$app->product->viewLog->mongodb->getHistory();
#use mysql save product view log history
Yii::$app->product->viewLog->db->setHistory($product);
#use mysql get product view log history
$d = Yii::$app->product->viewLog->db->getHistory();
#use session save product view log history
Yii::$app->product->viewLog->session->setHistory($product);
#use session get product view log history
$history = Yii::$app->product->viewLog->session->getHistory();
*/
}
\ 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\services\product\viewLog;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fec\helpers\CDate;
use fec\helpers\CUser;
use fecshop\models\db\product\ViewLog as DbViewLog;
use fecshop\models\mongodb\product\ViewLog as MongodbViewLog;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Db extends ChildService
{
public $table;
public $_defaultTable = 'log_product_view';
public $_maxProductCount = 10;
# init function
public function init(){
if(!$this->table)
$this->table = $this->_defaultTable;
DbViewLog::setCurrentTableName($this->table);
}
/**
* get product history log
*/
public function getHistory($user_id='',$count = '')
{
if(!$count)
$count = $this->_maxProductCount;
if(!$user_id)
$user_id = CUser::getCurrentUserId();
if(!$user_id)
return ;
$coll = DbViewLog::find()->where([
'user_id' => $user_id,
])
->asArray()
->orderBy(['date_time' => SORT_DESC])
->limit($count)
->all();
return $coll;
}
/**
* save product visit log
*/
public function setHistory($productOb){
$DbViewLog = new DbViewLog;
if(isset($productOb['user_id']) && $productOb['user_id']){
$DbViewLog->user_id = $productOb['user_id'];
}else if($currentUser = CUser::getCurrentUserId()){
$DbViewLog->user_id = $currentUser;
}else{
// if not give user_id, can not save history
return;
}
$DbViewLog->date_time = CDate::getCurrentDateTime();
$DbViewLog->product_id = $productOb['id'];
$DbViewLog->sku = $productOb['sku'];
$DbViewLog->image = $productOb['image'];
$DbViewLog->name = $productOb['name'];
$DbViewLog->save();
}
}
\ 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\services\product\viewLog;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fec\helpers\CDate;
use fec\helpers\CUser;
use fecshop\models\mongodb\product\ViewLog as MongodbViewLog;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Mongodb extends ChildService
{
public $collection;
public $_defaultCollection = 'log_product_view';
public $_maxProductCount = 10;
# init
public function init(){
if(!$this->collection)
$this->collection = $this->_defaultCollection;
MongodbViewLog::setCurrentCollectionName($this->collection);
}
/**
* get product history log
*/
public function getHistory($user_id='',$count = '')
{
if(!$count)
$count = $this->_maxProductCount;
if(!$user_id)
$user_id = CUser::getCurrentUserId();
if(!$user_id)
return ;
$coll = MongodbViewLog::find()->where([
'user_id' => $user_id,
])
->asArray()
->orderBy(['date_time' => SORT_DESC])
->limit($count)
->all();
return $coll;
}
/**
* save product history log
*/
public function setHistory($productOb){
$arr = [
'date_time' => CDate::getCurrentDateTime(),
'product_id' => $productOb['id'],
'sku' => $productOb['sku'],
'image' => $productOb['image'],
'name' => $productOb['name'],
];
if(isset($productOb['user_id']) && $productOb['user_id']){
$arr['user_id'] = $productOb['user_id'];
}else if($currentUser = CUser::getCurrentUserId()){
$arr['user_id'] = $currentUser;
}else{
// if not give user_id, can not save history
return;
}
$MongodbViewLog = MongodbViewLog::getCollection();
$MongodbViewLog->save($arr);
}
}
\ 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\services\product\viewLog;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\ChildService;
use fec\helpers\CDate;
use fec\helpers\CSession;
use fec\helpers\CUser;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Session extends ChildService
{
public $type;
public $_defaultType = 'session';
public $_sessionKey = 'services_product_viewlog_history';
public $_maxProductCount = 10;
/**
* get product history log.
*/
public function getHistory()
{
$history = CSession::get($this->_sessionKey);
return $history ? $history : '';
}
/**
* save product history log.
*/
public function setHistory($productOb){
$logArr = [
'date_time' => CDate::getCurrentDateTime(),
'product_id'=> $productOb['id'],
'sku' => $productOb['sku'],
'image' => $productOb['image'],
'name' => is_array($productOb['name']) ? serialize($productOb['name']) : $productOb['name'],
];
if(isset($productOb['user_id']) && $productOb['user_id']){
$logArr['user_id'] = $productOb['user_id'];
}else{
$logArr['user_id'] = CUser::getCurrentUserId();
}
if(!($session_history = CSession::get($this->_sessionKey))){
$session_history = [];
}else if(($count = count($session_history)) >= $this->_maxProductCount){
$unsetMaxKey = $count - $this->_maxProductCount ;
for($i=0;$i<=$unsetMaxKey;$i++){
array_shift($session_history);
}
}
$session_history[] = $logArr;
CSession::set($this->_sessionKey,$session_history);
}
}
\ No newline at end of file
#!/bin/sh
#processDate=$1
#Cur_Dir=$(pwd)
Cur_Dir=$(cd `dirname $0`; pwd)
#fec_admin
$Cur_Dir/../../../../yii migrate --migrationPath=@fecadmin/migrations
#db
$Cur_Dir/../../../../yii migrate --migrationPath=@fecshop/migrations/db/product/log
#mongodb
$Cur_Dir/../../../../yii mongodb-migrate --migrationPath=@fecshop/migrations/mongodb/urlwrite
$Cur_Dir/../../../../yii mongodb-migrate --migrationPath=@fecshop/migrations/mongodb/product/log
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册