-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
authored and
root
committed
Jun 6, 2016
1 parent
08adf21
commit ecc1d21
Showing
30 changed files
with
377 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* FecShop file. | ||
* | ||
* @link http://www.fecshop.com/ | ||
* @copyright Copyright (c) 2016 FecShop Software LLC | ||
* @license http://www.fecshop.com/license/ | ||
*/ | ||
namespace fecshop\models\db\product; | ||
use Yii; | ||
|
||
/** | ||
* @author Terry Zhao <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
|
||
class ViewLog extends ActiveRecord | ||
{ | ||
public static $_tableName; | ||
|
||
public static function tableName() | ||
{ | ||
return self::$_tableName; | ||
} | ||
|
||
public static function setCurrentTableName($tableName){ | ||
self::$_tableName = $tableName; | ||
} | ||
|
||
|
||
|
||
|
||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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; | ||
/** | ||
* Product Service is the component that you can get product info from it. | ||
* @property Image|\fecshop\services\Product\Image $image ,This property is read-only. | ||
* @author Terry Zhao <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
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(); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
public function setCurrentProductId($productId){ | ||
$this->_productId = $productId; | ||
} | ||
|
||
public function getCurrentProductId(){ | ||
return $this->_productId; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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 <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class Service extends Component | ||
{ | ||
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); | ||
|
||
} | ||
|
||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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 fecshop\services\Service; | ||
/** | ||
* @author Terry Zhao <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class BestSell extends Service | ||
{ | ||
|
||
/** | ||
* 得到全部产品中热销的产品 | ||
*/ | ||
|
||
public function getCategoryProduct() | ||
{ | ||
return 'category best sell product'; | ||
} | ||
|
||
/** | ||
* 得到全部产品中热销的产品 | ||
*/ | ||
public function getProduct(){ | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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 fecshop\services\Service; | ||
/** | ||
* @author Terry Zhao <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class Image extends Service | ||
{ | ||
public $imagePath; | ||
# get Current Product info | ||
public function getProductImage() | ||
{ | ||
return 'product Image info'; | ||
} | ||
|
||
public function getImageBasePath(){ | ||
return Yii::getAlias("@webroot").'/'. $this->imagePath; | ||
} | ||
|
||
|
||
public function getBase(){ | ||
return $this->getChildService('base'); | ||
} | ||
|
||
|
||
|
||
} |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?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 fecshop\services\Service; | ||
use fecshop\models\db\product\ViewLog as DbViewLog; | ||
use fecshop\models\mongodb\product\ViewLog as MongodbViewLog; | ||
/** | ||
* @author Terry Zhao <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class ViewLog extends Service | ||
{ | ||
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'], | ||
]; | ||
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 | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.