Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
d0a168cf
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d0a168cf
编写于
7月 25, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
product attribute groups services
上级
77a6bc0d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
257 addition
and
0 deletion
+257
-0
services/product/AttrGroup.php
services/product/AttrGroup.php
+89
-0
services/product/attrgroup/AttrGroupInterface.php
services/product/attrgroup/AttrGroupInterface.php
+27
-0
services/product/attrgroup/AttrGroupMongodb.php
services/product/attrgroup/AttrGroupMongodb.php
+0
-0
services/product/attrgroup/AttrGroupMysql.php
services/product/attrgroup/AttrGroupMysql.php
+141
-0
未找到文件。
services/product/AttrGroup.php
0 → 100644
浏览文件 @
d0a168cf
<?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\base\InvalidCallException
;
use
yii\base\InvalidConfigException
;
use
fecshop\services\Service
;
use
Yii
;
/**
* Product Service is the component that you can get product info from it.
*
* @property \fecshop\services\Image | \fecshop\services\Product\Image $image image service or product image sub-service
* @property \fecshop\services\product\Info $info product info sub-service
* @property \fecshop\services\product\Stock $stock stock sub-service of product service
*
* @method getByPrimaryKey($primaryKey) get product model by primary key
* @see \fecshop\services\Product::actionGetByPrimaryKey()
* @method getEnableStatus() get enable status
* @see \fecshop\services\Product::actionGetEnableStatus()
*
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
AttrGroup
extends
Service
{
/**
* $storagePrex , $storage , $storagePath 为找到当前的storage而设置的配置参数
* 可以在配置中更改,更改后,就会通过容器注入的方式修改相应的配置值
*/
public
$storage
=
'AttrGroupMysqldb'
;
// AttrGroupMysqldb | AttrGroupMongodb 当前的storage,如果在config中配置,那么在初始化的时候会被注入修改
/**
* 设置storage的path路径,
* 如果不设置,则系统使用默认路径
* 如果设置了路径,则使用自定义的路径
*/
public
$storagePath
=
''
;
/**
* @var \fecshop\services\product\ProductInterface 根据 $storage 及 $storagePath 配置的 Product 的实现
*/
protected
$_attrGroup
;
public
function
init
()
{
parent
::
init
();
// 从数据库配置中得到值, 设置成当前service存储,是Mysqldb 还是 Mongodb
//$config = Yii::$app->store->get('service_db', 'category_and_product');
//$this->storage = 'ProductMysqldb';
//if ($config == Yii::$app->store->serviceMongodbName) {
// $this->storage = 'ProductMongodb';
//}
$currentService
=
$this
->
getStorageService
(
$this
);
$this
->
_attrGroup
=
new
$currentService
();
}
// 动态更改为mongodb model
public
function
changeToMongoStorage
()
{
$this
->
storage
=
'AttrGroupMongodb'
;
$currentService
=
$this
->
getStorageService
(
$this
);
$this
->
_attrGroup
=
new
$currentService
();
}
// 动态更改为mongodb model
public
function
changeToMysqlStorage
()
{
$this
->
storage
=
'AttrGroupMysqldb'
;
$currentService
=
$this
->
getStorageService
(
$this
);
$this
->
_attrGroup
=
new
$currentService
();
}
protected
function
actionGetEnableStatus
()
{
return
$this
->
_attrGroup
->
getEnableStatus
();
}
}
services/product/attrgroup/AttrGroupInterface.php
0 → 100644
浏览文件 @
d0a168cf
<?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\attrgroup
;
/**
* Product services interface.
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
interface
AttrGroupInterface
{
public
function
getByPrimaryKey
(
$primaryKey
);
public
function
coll
(
$filter
);
public
function
save
(
$one
,
$originUrlKey
);
public
function
remove
(
$ids
);
}
services/product/attrgroup/AttrGroupMongodb.php
0 → 100644
浏览文件 @
d0a168cf
services/product/attrgroup/AttrGroupMysql.php
0 → 100644
浏览文件 @
d0a168cf
<?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\attrgroup
;
use
fecshop\services\Service
;
use
yii\db\Query
;
use
Yii
;
/**
* Product ProductMysqldb Service 未开发。
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
AttrGroupMysqldb
extends
Service
implements
AttrInterface
{
public
$numPerPage
=
20
;
protected
$_attrGroupModelName
=
'\fecshop\models\mysqldb\product\AttrGroup'
;
protected
$_attrGroupModel
;
public
function
init
()
{
parent
::
init
();
list
(
$this
->
_attrGroupModelName
,
$this
->
_attrGroupModel
)
=
\
Yii
::
mapGet
(
$this
->
_attrGroupModelName
);
}
public
function
getPrimaryKey
()
{
return
'id'
;
}
/**
* 得到分类激活状态的值
*/
public
function
getEnableStatus
()
{
$model
=
$this
->
_attrGroupModel
;
return
$model
::
STATUS_ENABLE
;
}
public
function
getByPrimaryKey
(
$primaryKey
=
null
)
{
if
(
$primaryKey
)
{
$one
=
$this
->
_attrGroupModel
->
findOne
(
$primaryKey
);
return
$this
->
unserializeData
(
$one
)
;
}
else
{
return
new
$this
->
_attrGroupModel
();
}
}
/*
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
* 'where' => [
['>','price',1],
['<=','price',10]
* ['sku' => 'uk10001'],
* ],
* 'asArray' => true,
* ]
*/
public
function
coll
(
$filter
=
''
)
{
$query
=
$this
->
_attrGroupModel
->
find
();
$query
=
Yii
::
$service
->
helper
->
ar
->
getCollByFilter
(
$query
,
$filter
);
$coll
=
$query
->
all
();
$arr
=
[];
foreach
(
$coll
as
$one
)
{
$arr
[]
=
$this
->
unserializeData
(
$one
)
;
}
return
[
'coll'
=>
$arr
,
'count'
=>
$query
->
limit
(
null
)
->
offset
(
null
)
->
count
(),
];
}
/**
* @param $one|array
* save $data to cms model,then,add url rewrite info to system service urlrewrite.
*/
public
function
save
(
$one
)
{
if
(
$primaryVal
)
{
$model
=
$this
->
_attrGroupModel
->
findOne
(
$primaryVal
);
if
(
!
$model
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'Product attr {primaryKey} is not exist'
,
[
'primaryKey'
=>
$this
->
getPrimaryKey
()]);
return
;
}
}
else
{
$model
=
new
$this
->
_attrGroupModelName
();
$model
->
created_at
=
time
();
}
$model
->
updated_at
=
time
();
$primaryKey
=
$this
->
getPrimaryKey
();
$model
=
Yii
::
$service
->
helper
->
ar
->
save
(
$model
,
$one
);
$primaryVal
=
$model
[
$primaryKey
];
return
true
;
}
public
function
remove
(
$ids
)
{
if
(
!
$ids
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'remove id is empty'
);
return
false
;
}
if
(
is_array
(
$ids
)
&&
!
empty
(
$ids
))
{
foreach
(
$ids
as
$id
)
{
$model
=
$this
->
_attrGroupModel
->
findOne
(
$id
);
$model
->
delete
();
}
}
else
{
$id
=
$ids
;
$model
=
$this
->
_attrGroupModel
->
findOne
(
$id
);
$model
->
delete
();
}
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录