Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
40a42edf
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 搜索 >>
提交
40a42edf
编写于
7月 30, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spu产品,相同spu,不同sku,spu属性的值不能全部相同
上级
bbc088ec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
108 addition
and
0 deletion
+108
-0
services/product/ProductMongodb.php
services/product/ProductMongodb.php
+49
-0
services/product/ProductMysqldb.php
services/product/ProductMysqldb.php
+59
-0
未找到文件。
services/product/ProductMongodb.php
浏览文件 @
40a42edf
...
...
@@ -315,6 +315,17 @@ class ProductMongodb extends Service implements ProductInterface
$one
[
'min_sales_qty'
]
=
(
int
)
$one
[
'min_sales_qty'
];
$currentDateTime
=
\
fec\helpers\CDate
::
getCurrentDateTime
();
$primaryVal
=
isset
(
$one
[
$this
->
getPrimaryKey
()])
?
$one
[
$this
->
getPrimaryKey
()]
:
''
;
// 得到group spu attr
$attr_group
=
$one
[
'attr_group'
];
$groupSpuAttrs
=
Yii
::
$service
->
product
->
getGroupSpuAttr
(
$attr_group
);
$spuAttrArr
=
[];
if
(
is_array
(
$groupSpuAttrs
))
{
foreach
(
$groupSpuAttrs
as
$groupSpuOne
)
{
$spuAttrArr
[]
=
$groupSpuOne
[
'name'
];
}
}
if
(
$primaryVal
)
{
$model
=
$this
->
_productModel
->
findOne
(
$primaryVal
);
if
(
!
$model
)
{
...
...
@@ -334,6 +345,25 @@ class ProductMongodb extends Service implements ProductInterface
return
false
;
}
// spu 下面的各个sku的spu属性不能相同
if
(
!
empty
(
$spuAttrArr
))
{
$product_mode
=
$this
->
_productModel
->
find
()
->
asArray
()
->
where
([
'<>'
,
$this
->
getPrimaryKey
(),
(
new
\
MongoDB\BSON\ObjectId
(
$primaryVal
)),
])
->
andWhere
([
'spu'
=>
$one
[
'spu'
],
]);
foreach
(
$spuAttrArr
as
$sar
)
{
$product_mode
->
andWhere
([
$sar
=>
$one
[
$sar
]]);
}
$product_one
=
$product_mode
->
one
();
if
(
$product_one
[
'sku'
])
{
Yii
::
$service
->
helper
->
errors
->
add
(
'product Spu of the same, Spu attributes cannot be the same'
);
return
false
;
}
}
}
else
{
$model
=
new
$this
->
_productModelName
();
$model
->
created_at
=
time
();
...
...
@@ -349,6 +379,23 @@ class ProductMongodb extends Service implements ProductInterface
return
false
;
}
if
(
!
empty
(
$spuAttrArr
))
{
$product_mode
=
$this
->
_productModel
->
find
()
->
asArray
()
->
where
([
'spu'
=>
$one
[
'spu'
],
]);
foreach
(
$spuAttrArr
as
$sar
)
{
$product_mode
->
andWhere
([
$sar
=>
$one
[
$sar
]]);
}
$product_one
=
$product_mode
->
one
();
if
(
$product_one
[
'sku'
])
{
Yii
::
$service
->
helper
->
errors
->
add
(
'product Spu of the same, Spu attributes cannot be the same'
);
return
false
;
}
}
}
$model
->
updated_at
=
time
();
// 计算出来产品的最终价格。
...
...
@@ -369,6 +416,7 @@ class ProductMongodb extends Service implements ProductInterface
/**
* 保存产品
*/
//var_dump($one);exit;
$saveStatus
=
Yii
::
$service
->
helper
->
ar
->
save
(
$model
,
$one
);
// 自定义url部分
...
...
@@ -380,6 +428,7 @@ class ProductMongodb extends Service implements ProductInterface
$model
->
url_key
=
$urlKey
;
$model
->
save
();
}
$product_id
=
$model
->
{
$this
->
getPrimaryKey
()};
/**
* 更新产品库存。
...
...
services/product/ProductMysqldb.php
浏览文件 @
40a42edf
...
...
@@ -363,6 +363,33 @@ class ProductMysqldb extends Service implements ProductInterface
$this
->
_productModel
->
addCustomProductAttrs
(
$attrs
);
}
}
// 进行spu对应的属性进行检查,相同spu的产品,他们的sku属性不能全部相同,否则返回false
public
function
checkSpuAttrUnique
(
$spuAttrArr
,
$product_colls
)
{
if
(
is_array
(
$product_colls
))
{
foreach
(
$product_colls
as
$sar
)
{
$sar_attr_group_info
=
unserialize
(
$sar
[
'attr_group_info'
]);
$si
=
0
;
if
(
is_array
(
$sar_attr_group_info
))
{
foreach
(
$spuAttrArr
as
$sar_key
=>
$sar_val
)
{
if
(
!
isset
(
$sar_attr_group_info
[
$sar_key
]))
{
$si
=
1
;
}
else
if
(
isset
(
$sar_attr_group_info
[
$sar_key
])
&&
$sar_attr_group_info
[
$sar_key
]
!=
$sar_val
)
{
$si
=
1
;
}
}
}
if
(
$si
==
0
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'product Spu of the same, Spu attributes cannot be the same'
);
return
false
;
}
}
}
return
true
;
}
/**
* @param $one|array , 产品数据数组
...
...
@@ -379,6 +406,15 @@ class ProductMysqldb extends Service implements ProductInterface
$one
[
'min_sales_qty'
]
=
$one
[
'min_sales_qty'
];
$currentDateTime
=
\
fec\helpers\CDate
::
getCurrentDateTime
();
$primaryVal
=
isset
(
$one
[
$this
->
getPrimaryKey
()])
?
$one
[
$this
->
getPrimaryKey
()]
:
''
;
// 得到group spu attr
$attr_group
=
$one
[
'attr_group'
];
$groupSpuAttrs
=
Yii
::
$service
->
product
->
getGroupSpuAttr
(
$attr_group
);
$spuAttrArr
=
[];
if
(
is_array
(
$groupSpuAttrs
))
{
foreach
(
$groupSpuAttrs
as
$groupSpuOne
)
{
$spuAttrArr
[
$groupSpuOne
[
'name'
]]
=
$one
[
$groupSpuOne
[
'name'
]];
}
}
if
(
$primaryVal
)
{
$model
=
$this
->
_productModel
->
findOne
(
$primaryVal
);
...
...
@@ -399,6 +435,18 @@ class ProductMysqldb extends Service implements ProductInterface
return
false
;
}
// spu 下面的各个sku的spu属性不能相同
if
(
!
empty
(
$spuAttrArr
))
{
$product_colls
=
$this
->
_productModel
->
find
()
->
asArray
()
->
where
([
'<>'
,
$this
->
getPrimaryKey
(),
$primaryVal
,
])
->
andWhere
([
'spu'
=>
$one
[
'spu'
],
])
->
all
();
/////////////////
if
(
!
$this
->
checkSpuAttrUnique
(
$spuAttrArr
,
$product_colls
))
{
return
false
;
}
}
}
else
{
$model
=
new
$this
->
_productModelName
();
...
...
@@ -419,6 +467,17 @@ class ProductMysqldb extends Service implements ProductInterface
return
false
;
}
// spu 下面的各个sku的spu属性不能相同
if
(
!
empty
(
$spuAttrArr
))
{
$product_colls
=
$this
->
_productModel
->
find
()
->
asArray
()
->
where
([
'spu'
=>
$one
[
'spu'
],
])
->
all
();
/////////////////
if
(
!
$this
->
checkSpuAttrUnique
(
$spuAttrArr
,
$product_colls
))
{
return
false
;
}
}
}
$model
->
updated_at
=
time
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录