提交 ecc1d219 编写于 作者: R root

x

上级 08adf21e
......@@ -6,11 +6,6 @@ fecshop for ecommerce , online shop open source
> 项目已经开始
> Terry
[![Latest Stable Version](https://poser.pugx.org/fancyecommerce/fecshop/v/stable)](https://packagist.org/packages/fancyecommerce/fecshop)
[![Total Downloads](https://poser.pugx.org/fancyecommerce/fecshop/downloads)](https://packagist.org/packages/fancyecommerce/fecshop)
[![License](https://poser.pugx.org/fancyecommerce/fecshop/license)](https://packagist.org/packages/fancyecommerce/fecshop)
1、安装Yii2
------------
......
......@@ -22,8 +22,8 @@
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.6" ,
"fancyecommerce/fec_admin":"~1.3.5.3"
"fancyecommerce/fec_admin":"~1.3.5.3",
"yiisoft/yii2-mongodb": "~2.0.0"
},
"autoload": {
"psr-4": {
......
<?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 <2358269014@qq.com>
* @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;
}
}
<?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 <2358269014@qq.com>
* @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;
}
}
\ 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 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);
}
}
\ 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;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class BestSell extends Service
{
/**
* 得到全部产品中热销的产品
*/
public function getCategoryProduct()
{
return 'category best sell product';
}
/**
* 得到全部产品中热销的产品
*/
public function getProduct(){
}
}
\ 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;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
/**
* @author Terry Zhao <2358269014@qq.com>
* @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');
}
}
\ 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;
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 <2358269014@qq.com>
* @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
}
}
}
\ No newline at end of file
<?php
namespace fecshop\services\product\image;
use Yii;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
class Base extends Service
{
public $imagePath;
# get Current Product info
public function getBaseProductImage()
{
return 'product Image info';
}
public function getImageBasePath(){
return Yii::getAlias("@webroot").'/'. $this->imagePath;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册