Skip to content

Commit ecc1d21

Browse files
rootroot
root
authored and
root
committed
x
1 parent 08adf21 commit ecc1d21

30 files changed

+377
-7
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ fecshop for ecommerce , online shop open source
66
> 项目已经开始
77
> Terry
88
9-
[![Latest Stable Version](https://poser.pugx.org/fancyecommerce/fecshop/v/stable)](https://packagist.org/packages/fancyecommerce/fecshop)
10-
[![Total Downloads](https://poser.pugx.org/fancyecommerce/fecshop/downloads)](https://packagist.org/packages/fancyecommerce/fecshop)
11-
[![License](https://poser.pugx.org/fancyecommerce/fecshop/license)](https://packagist.org/packages/fancyecommerce/fecshop)
12-
13-
149
1、安装Yii2
1510
------------
1611

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"require": {
2323
"php": ">=5.4.0",
2424
"yiisoft/yii2": ">=2.0.6" ,
25-
"fancyecommerce/fec_admin":"~1.3.5.3"
26-
25+
"fancyecommerce/fec_admin":"~1.3.5.3",
26+
"yiisoft/yii2-mongodb": "~2.0.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

models/db/product/ViewLog.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\models\db\product;
10+
use Yii;
11+
12+
/**
13+
* @author Terry Zhao <2358269014@qq.com>
14+
* @since 1.0
15+
*/
16+
17+
class ViewLog extends ActiveRecord
18+
{
19+
public static $_tableName;
20+
21+
public static function tableName()
22+
{
23+
return self::$_tableName;
24+
}
25+
26+
public static function setCurrentTableName($tableName){
27+
self::$_tableName = $tableName;
28+
}
29+
30+
31+
32+
33+
}

models/mongodb/product/ViewLog.php

Whitespace-only changes.

services/Breadcrumbs.php

Whitespace-only changes.

services/Cart.php

Whitespace-only changes.

services/Category.php

Whitespace-only changes.

services/Cms.php

Whitespace-only changes.

services/Coupon.php

Whitespace-only changes.

services/Currency.php

Whitespace-only changes.

services/Customer.php

Whitespace-only changes.

services/Email.php

Whitespace-only changes.

services/Order.php

Whitespace-only changes.

services/Payment.php

Whitespace-only changes.

services/Product.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\services;
10+
use Yii;
11+
use yii\base\InvalidValueException;
12+
use yii\base\InvalidConfigException;
13+
/**
14+
* Product Service is the component that you can get product info from it.
15+
* @property Image|\fecshop\services\Product\Image $image ,This property is read-only.
16+
* @author Terry Zhao <2358269014@qq.com>
17+
* @since 1.0
18+
*/
19+
class Product extends Service
20+
{
21+
public $_productId;
22+
/**
23+
* 1.得到单个产品的详细信息。
24+
* 2.通过当前的语言,名字,描述等都会被转换成当前语言的value
25+
* 3.价格将会被转换成当前货币的价格。
26+
* 4.图片将会被转换成url(根据当前的domain)
27+
* 5.这个功能提供给产品详细页面使用。返回的值比较全面
28+
*/
29+
public function getProductInfo($productId='',$selectAttr=[])
30+
{
31+
if(!$productId)
32+
$productId = $this->getCurrentProductId();
33+
if(!$productId)
34+
throw new InvalidValueException('productId is empty,you must pass a ProductId');
35+
36+
37+
}
38+
39+
40+
41+
42+
/**
43+
* 通过where条件,得到product的数组,
44+
* 您可以在 $selectAttr 中指定返回的字段。
45+
* 如果您选择的属性中有图片,那么图片将会返回url
46+
* 这个功能给分类页面使用
47+
*/
48+
public function getProductCollByWhere($where , $selectAttr){
49+
50+
51+
}
52+
53+
/**
54+
* 得到销量最好的产品,这个给首页等其他地方使用
55+
*/
56+
public function getBestSellProduct(){
57+
58+
59+
}
60+
61+
62+
/**
63+
* 得到某个分类的产品销量最好
64+
*/
65+
public function getCategoryBestSellProduct(){
66+
return Yii::$app->product->bestSell->getCategoryProduct();
67+
68+
}
69+
70+
71+
72+
73+
public function setCurrentProductId($productId){
74+
$this->_productId = $productId;
75+
}
76+
77+
public function getCurrentProductId(){
78+
return $this->_productId;
79+
}
80+
81+
82+
83+
84+
85+
86+
}

services/Search.php

Whitespace-only changes.

services/Service.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\services;
10+
use Yii;
11+
use yii\base\Component;
12+
use yii\base\InvalidConfigException;
13+
/**
14+
* @author Terry Zhao <2358269014@qq.com>
15+
* @since 1.0
16+
*/
17+
class Service extends Component
18+
{
19+
public $childService;
20+
public $_childService;
21+
22+
/**
23+
* 得到services 里面配置的子服务childService的实例
24+
*/
25+
public function getChildService($childServiceName){
26+
if(!$this->_childService[$childServiceName]){
27+
$childService = $this->childService;
28+
if(isset($childService[$childServiceName])){
29+
$service = $childService[$childServiceName];
30+
$this->_childService[$childServiceName] = Yii::createObject($service);
31+
}else{
32+
throw new InvalidConfigException('Child Service ['.$childServiceName.'] is not find in '.get_called_class().', you must config it! ');
33+
}
34+
}
35+
return $this->_childService[$childServiceName];
36+
}
37+
38+
/**
39+
*
40+
*/
41+
public function __get($attr){
42+
return $this->getChildService($attr);
43+
44+
}
45+
46+
}

services/Shipping.php

Whitespace-only changes.

services/Sitemap.php

Whitespace-only changes.

services/Staticblock.php

Whitespace-only changes.

services/Store.php

Whitespace-only changes.

services/Url.php

Whitespace-only changes.

services/product/BestSell.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\services\product;
10+
use Yii;
11+
use yii\base\InvalidConfigException;
12+
use fecshop\services\Service;
13+
/**
14+
* @author Terry Zhao <2358269014@qq.com>
15+
* @since 1.0
16+
*/
17+
class BestSell extends Service
18+
{
19+
20+
/**
21+
* 得到全部产品中热销的产品
22+
*/
23+
24+
public function getCategoryProduct()
25+
{
26+
return 'category best sell product';
27+
}
28+
29+
/**
30+
* 得到全部产品中热销的产品
31+
*/
32+
public function getProduct(){
33+
34+
35+
}
36+
37+
38+
39+
40+
}

services/product/Coll.php

Whitespace-only changes.

services/product/Image.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\services\product;
10+
use Yii;
11+
use yii\base\InvalidConfigException;
12+
use fecshop\services\Service;
13+
/**
14+
* @author Terry Zhao <2358269014@qq.com>
15+
* @since 1.0
16+
*/
17+
class Image extends Service
18+
{
19+
public $imagePath;
20+
# get Current Product info
21+
public function getProductImage()
22+
{
23+
return 'product Image info';
24+
}
25+
26+
public function getImageBasePath(){
27+
return Yii::getAlias("@webroot").'/'. $this->imagePath;
28+
}
29+
30+
31+
public function getBase(){
32+
return $this->getChildService('base');
33+
}
34+
35+
36+
37+
}

services/product/Info.php

Whitespace-only changes.

services/product/Price.php

Whitespace-only changes.

services/product/Review.php

Whitespace-only changes.

services/product/ViewLog.php

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* FecShop file.
4+
*
5+
* @link http://www.fecshop.com/
6+
* @copyright Copyright (c) 2016 FecShop Software LLC
7+
* @license http://www.fecshop.com/license/
8+
*/
9+
namespace fecshop\services\product;
10+
use Yii;
11+
use yii\base\InvalidConfigException;
12+
use fecshop\services\Service;
13+
use fecshop\models\db\product\ViewLog as DbViewLog;
14+
use fecshop\models\mongodb\product\ViewLog as MongodbViewLog;
15+
/**
16+
* @author Terry Zhao <2358269014@qq.com>
17+
* @since 1.0
18+
*/
19+
class ViewLog extends Service
20+
{
21+
public $type;
22+
public $_defaultType = 'session';
23+
public $_defaultViewTable = 'log_product_view';
24+
public $_sessionKey = 'services_product_viewlog_history';
25+
public $_maxProductCount = 10;
26+
public $_currentType;
27+
public $_currentTable;
28+
29+
public $_currentModel;
30+
31+
32+
# 初始化
33+
public function init(){
34+
$configType = $this->type;
35+
if(!$configType){
36+
$configType = $this->_defaultType;
37+
}
38+
$configTypeArr = explode(',',$configType);
39+
$storage = $configTypeArr[0];
40+
41+
if($storage == 'session'){
42+
43+
}else if(($storage == 'mysql') || ($storage == 'mongodb')){
44+
if(isset($configTypeArr[1]) && $configTypeArr[1]){
45+
$this->_currentTable = $configTypeArr[1];
46+
}else{
47+
$this->_currentTable = $this->_defaultViewTable;
48+
}
49+
if($storage == 'mysql'){
50+
DbViewLog::setCurrentTableName($this->_currentTable);
51+
}else if($storage == 'mongodb'){
52+
MongodbViewLog::setCurrentCollectionName($this->_currentTable);
53+
}
54+
}else{
55+
56+
throw new InvalidConfigException('services:product->viewlog,config type is not right, you can
57+
only config type in [session,mysql,mongodb]
58+
,example:(1)session,(2)mysql.'.$this->_defaultViewTable.',(3)mongodb.'.$this->_defaultViewTable.'
59+
if you config mysql or mongodb ,do not config table , default ('.$this->_defaultViewTable.') will use.
60+
current file:'.get_called_class());
61+
}
62+
$this->_currentType = $storage;
63+
}
64+
65+
66+
/**
67+
* 得到产品浏览的历史记录
68+
*/
69+
public function getHistory()
70+
{
71+
return 'category best sell product';
72+
}
73+
74+
/**
75+
* 保存产品的历史记录
76+
*/
77+
public function setHistory($productOb){
78+
79+
$logArr = [
80+
'date_time' => CDate::getCurrentDateTime(),
81+
'product_id'=> $productOb['id'],
82+
'sku' => $productOb['sku'],
83+
'image' => $productOb['image'],
84+
'name' => is_array($productOb['name']) ? serialize($productOb['name']) : $productOb['name'],
85+
];
86+
if($this->_currentType == 'session'){
87+
if(!($session_history = CSession::get($this->_sessionKey))){
88+
$session_history = [];
89+
}else if(($count = count($session_history)) >= $this->_maxProductCount)){
90+
$unsetMaxKey = $count - $this->_maxProductCount ;
91+
for($i=0;$i<=$unsetMaxKey;$i++){
92+
array_shift($session_history);
93+
}
94+
}
95+
$session_history[] = $logArr;
96+
CSession::set($this->_sessionKey,$session_history);
97+
}else if(($this->_currentType == 'mysql'){
98+
$this->_currentModel
99+
$this->_currentTable
100+
$fn_set_exec = $this->_currentModel.'::setCurrentTableName';
101+
\call_user_func_array($fn_set_exec,[$this->_currentTable]);
102+
103+
}else if(($this->_currentType == 'mongodb'){
104+
$this->_currentTable
105+
}
106+
}
107+
108+
109+
110+
111+
}

0 commit comments

Comments
 (0)