Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
1a8cd465
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
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,发现更多精彩内容 >>
提交
1a8cd465
编写于
7月 22, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add storeBaseConfig model and services
上级
90a16f92
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
225 addition
and
0 deletion
+225
-0
models/mysqldb/StoreBaseConfig.php
models/mysqldb/StoreBaseConfig.php
+28
-0
services/StoreBaseConfig.php
services/StoreBaseConfig.php
+197
-0
未找到文件。
models/mysqldb/StoreBaseConfig.php
0 → 100644
浏览文件 @
1a8cd465
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\models\mysqldb
;
use
yii\db\ActiveRecord
;
use
yii\base\InvalidValueException
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
StoreBaseConfig
extends
ActiveRecord
{
public
static
function
tableName
()
{
return
'{{%store_base_config}}'
;
}
}
services/StoreBaseConfig.php
0 → 100644
浏览文件 @
1a8cd465
<?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
;
/**
* Cart services. 购物车service, 执行购物车部分对应的方法。
*
* @property \fecshop\services\cart\Coupon $coupon coupon sub-service of cart
* @property \fecshop\services\cart\Info $info info sub-service of cart
* @property \fecshop\services\cart\Quote $quote quote sub-service of cart
* @property \fecshop\services\cart\QuoteItem $quoteItem quoteItem sub-service of cart
*
* @method getCartInfo($activeProduct, $shippingMethod = '', $country = '', $region = '*') see [[\fecshop\services\Cart::actionGetCartInfo()]]
* @method mergeCartAfterUserLogin() see [[\fecshop\services\Cart::actionmergeCartAfterUserLogin()]]
*
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
StoreBaseConfig
extends
Service
{
public
$numPerPage
=
20
;
protected
$_modelName
=
'\fecshop\models\mysqldb\StoreBaseConfig'
;
protected
$_model
;
//protected $_serilizeAttr = [
// "service_db",
//];
public
function
init
()
{
parent
::
init
();
list
(
$this
->
_modelName
,
$this
->
_model
)
=
Yii
::
mapGet
(
$this
->
_modelName
);
}
public
function
getPrimaryKey
()
{
return
'id'
;
}
public
function
getByPrimaryKey
(
$primaryKey
)
{
if
(
$primaryKey
)
{
$one
=
$this
->
_model
->
findOne
(
$primaryKey
);
return
$one
;
}
else
{
return
new
$this
->
_modelName
();
}
}
public
function
getByKey
(
$key
)
{
if
(
$key
)
{
$one
=
$this
->
_model
->
findOne
([
'key'
=>
$key
]);
return
$one
;
}
return
null
;
}
/*
* 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
->
_model
->
find
();
$query
=
Yii
::
$service
->
helper
->
ar
->
getCollByFilter
(
$query
,
$filter
);
$coll
=
$query
->
all
();
//if (!empty($coll)) {
// foreach ($coll as $k => $one) {
//if (in_array($one['key'], $this->_serilizeAttr)) {
// $one['key'] = unserialize($one)
//}
//foreach ($this->_lang_attr as $attr) {
// $one[$attr] = $one[$attr] ? unserialize($one[$attr]) : '';
//}
$coll
[
$k
]
=
$one
;
//}
//}
//var_dump($one);
return
[
'coll'
=>
$coll
,
'count'
=>
$query
->
limit
(
null
)
->
offset
(
null
)
->
count
(),
];
}
public
function
getAllConfig
()
{
$arr
=
[];
$baseConfigs
=
$this
->
_model
->
find
()
->
select
([
'key'
,
'value'
])
->
asArray
()
->
all
();
foreach
(
$baseConfigs
as
$one
)
{
$arr
[
$one
[
'key'
]]
=
unserialize
(
$one
[
'value'
]);
}
return
$arr
;
}
/**
* @param $one|array
* save $data to cms model,then,add url rewrite info to system service urlrewrite.
*/
public
function
save
(
$one
)
{
$currentDateTime
=
\
fec\helpers\CDate
::
getCurrentDateTime
();
$primaryVal
=
isset
(
$one
[
$this
->
getPrimaryKey
()])
?
$one
[
$this
->
getPrimaryKey
()]
:
''
;
if
(
$primaryVal
)
{
$model
=
$this
->
_model
->
findOne
(
$primaryVal
);
if
(
!
$model
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'config {primaryKey} is not exist'
,
[
'primaryKey'
=>
$this
->
getPrimaryKey
()]);
return
;
}
}
else
{
$model
=
new
$this
->
_modelName
();
$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
saveConfig
(
$one
)
{
if
(
!
$one
[
'key'
]
||
!
$one
[
'value'
])
{
return
false
;
}
$model
=
$this
->
_model
->
findOne
([
'key'
=>
$one
[
'key'
]]);
if
(
!
$model
[
'id'
])
{
$model
=
new
$this
->
_modelName
();
$model
->
created_at
=
time
();
$model
->
key
=
$one
[
'key'
];
}
if
(
is_array
(
$one
[
'value'
]))
{
$model
->
value
=
serialize
(
$one
[
'value'
]);
}
else
{
$model
->
value
=
$one
[
'value'
];
}
$model
->
updated_at
=
time
();
return
$model
->
save
();
}
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
->
_model
->
findOne
(
$id
);
$model
->
delete
();
}
}
else
{
$id
=
$ids
;
foreach
(
$ids
as
$id
)
{
$model
=
$this
->
_model
->
findOne
(
$id
);
$model
->
delete
();
}
}
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录