Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
38a48221
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 搜索 >>
提交
38a48221
编写于
9月 12, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
产品url_key部分bug处理
上级
58a13893
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
122 addition
and
11 deletion
+122
-11
migrations/mysqldb/m190912_052057_fecshop_tables.php
migrations/mysqldb/m190912_052057_fecshop_tables.php
+56
-0
services/Url.php
services/Url.php
+54
-6
services/product/ProductMysqldb.php
services/product/ProductMysqldb.php
+12
-5
未找到文件。
migrations/mysqldb/m190912_052057_fecshop_tables.php
0 → 100644
浏览文件 @
38a48221
<?php
use
yii\db\Migration
;
/**
* Class m190912_052057_fecshop_tables
*/
class
m190912_052057_fecshop_tables
extends
Migration
{
/**
* {@inheritdoc}
*/
public
function
safeUp
()
{
$arr
=
[
"
ALTER TABLE product_flat DROP INDEX sku;
"
,
"
ALTER TABLE `product_flat` ADD UNIQUE (`sku`);
"
,
"
ALTER TABLE `product_flat` ADD UNIQUE (`url_key`);
"
,
];
foreach
(
$arr
as
$sql
)
{
$this
->
execute
(
$sql
);
}
}
/**
* {@inheritdoc}
*/
public
function
safeDown
()
{
echo
"m190912_052057_fecshop_tables cannot be reverted.
\n
"
;
return
false
;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m190912_052057_fecshop_tables cannot be reverted.\n";
return false;
}
*/
}
services/Url.php
浏览文件 @
38a48221
...
...
@@ -24,7 +24,7 @@ use Yii;
*/
class
Url
extends
Service
{
public
$randomCount
=
8
;
public
$randomCount
=
9
;
public
$showScriptName
;
...
...
@@ -62,14 +62,24 @@ class Url extends Service
$str
=
trim
(
$str
);
$originUrl
=
$originUrl
?
'/'
.
trim
(
$originUrl
,
'/'
)
:
''
;
$originUrlKey
=
$originUrlKey
?
'/'
.
trim
(
$originUrlKey
,
'/'
)
:
''
;
if
(
$originUrlKey
)
{
if
(
$originUrlKey
&&
$originUrl
)
{
/**
* if originUrlKey and originUrl is exist in url rewrite collectons.
*/
$model
=
$this
->
find
();
// 如果已经存在,那么直接返回
$data_one
=
$model
->
where
([
'custom_url_key'
=>
$originUrlKey
,
'origin_url'
=>
$originUrl
,
])
->
one
();
if
(
isset
(
$data_one
[
'custom_url_key'
]))
{
return
$originUrlKey
;
}
/*
$data_one = $model->where([
'custom_url_key' => $originUrlKey,
//
'origin_url' => $originUrl,
'origin_url' => $originUrl,
])->one();
if (isset($data_one['custom_url_key'])) {
// 只要进行了查询,就要更新一下rewrite url表的updated_at.
...
...
@@ -79,6 +89,7 @@ class Url extends Service
return $originUrlKey;
}
*/
}
if
(
$originUrlKey
)
{
$urlKey
=
$this
->
generateUrlByName
(
$originUrlKey
);
...
...
@@ -348,6 +359,23 @@ class Url extends Service
return
$str
;
}
protected
function
isRandomStr
(
$randomStr
)
{
$f
=
substr
(
$randomStr
,
0
,
1
);
if
(
$f
!==
'-'
)
{
return
false
;
}
$s
=
substr
(
$randomStr
,
1
);
if
(
strlen
(
$s
)
!=
$this
->
randomCount
)
{
return
false
;
}
if
(
!
is_numeric
(
$s
)){
return
false
;
}
return
true
;
}
/**
* if url key is exist in url_rewrite table ,Behind url add some random string.
...
...
@@ -359,13 +387,33 @@ class Url extends Service
$o_url
=
$this
->
_origin_url
;
if
(
strstr
(
$this
->
_origin_url
,
'.'
))
{
list
(
$o_url
,
$suffix
)
=
explode
(
'.'
,
$this
->
_origin_url
);
$l
=
$this
->
randomCount
+
1
;
if
(
strlen
(
$o_url
)
>
$l
)
{
$randomStrSub
=
substr
(
$o_url
,
strlen
(
$o_url
)
-
$l
,
$l
);
$orignUrlK
=
substr
(
$o_url
,
0
,
strlen
(
$o_url
)
-
$l
);
if
(
$this
->
isRandomStr
(
$randomStrSub
))
{
$o_url
=
$orignUrlK
;
}
}
$randomStr
=
$this
->
getRandom
();
return
$o_url
.
'-'
.
$randomStr
.
'.'
.
$suffix
;
}
$randomStr
=
$this
->
getRandom
();
}
else
{
$l
=
$this
->
randomCount
+
1
;
if
(
strlen
(
$o_url
)
>
$l
)
{
$randomStr
=
substr
(
$o_url
,
strlen
(
$o_url
)
-
$l
,
$l
);
$orignUrlK
=
substr
(
$o_url
,
0
,
strlen
(
$o_url
)
-
$l
);
if
(
$this
->
isRandomStr
(
$randomStr
))
{
$o_url
=
$orignUrlK
;
}
}
$randomStr
=
$this
->
getRandom
();
return
$this
->
_origin_url
.
'-'
.
$randomStr
;
return
$o_url
.
'-'
.
$randomStr
;
}
}
}
...
...
services/product/ProductMysqldb.php
浏览文件 @
38a48221
...
...
@@ -406,6 +406,9 @@ class ProductMysqldb extends Service implements ProductInterface
if
(
!
$this
->
initSave
(
$one
))
{
return
false
;
}
$url_key
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
unset
(
$one
[
'url_key'
]);
$currentDateTime
=
\
fec\helpers\CDate
::
getCurrentDateTime
();
$primaryVal
=
isset
(
$one
[
$this
->
getPrimaryKey
()])
?
$one
[
$this
->
getPrimaryKey
()]
:
''
;
// 得到group spu attr
...
...
@@ -513,7 +516,7 @@ class ProductMysqldb extends Service implements ProductInterface
// 自定义url部分
if
(
$originUrlKey
)
{
$originUrl
=
$originUrlKey
.
'?'
.
$this
->
getPrimaryKey
()
.
'='
.
$product_id
;
$originUrlKey
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
$originUrlKey
=
$url_key
;
$defaultLangTitle
=
Yii
::
$service
->
fecshoplang
->
getDefaultLangAttrVal
(
$one
[
'name'
],
'name'
);
$urlKey
=
Yii
::
$service
->
url
->
saveRewriteUrlKeyByStr
(
$defaultLangTitle
,
$originUrl
,
$originUrlKey
);
$model
->
url_key
=
$urlKey
;
...
...
@@ -546,6 +549,8 @@ class ProductMysqldb extends Service implements ProductInterface
if
(
!
$this
->
initSave
(
$one
))
{
return
false
;
}
$url_key
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
unset
(
$one
[
'url_key'
]);
$defaultLangTitle
=
Yii
::
$service
->
fecshoplang
->
getDefaultLangAttrVal
(
$one
[
'name'
],
'name'
);
$product_one
=
$this
->
_productModel
->
find
()
->
where
([
'sku'
=>
$one
[
'sku'
],
...
...
@@ -585,9 +590,8 @@ class ProductMysqldb extends Service implements ProductInterface
$this
->
syncProductCategory
(
$one
[
'category'
],
$product_id
);
// 自定义url部分
$originUrlKey
=
'catalog/product/index'
;
$originUrl
=
$originUrlKey
.
'?'
.
$this
->
getPrimaryKey
()
.
'='
.
$product_id
;
$originUrlKey
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
$originUrl
=
'catalog/product/index'
.
'?'
.
$this
->
getPrimaryKey
()
.
'='
.
$product_id
;
$originUrlKey
=
$url_key
;
//var_dump([$defaultLangTitle, $originUrl, $originUrlKey]);
//echo $defaultLangTitle;
$urlKey
=
Yii
::
$service
->
url
->
saveRewriteUrlKeyByStr
(
$defaultLangTitle
,
$originUrl
,
$originUrlKey
);
...
...
@@ -1191,6 +1195,9 @@ class ProductMysqldb extends Service implements ProductInterface
{
$sku
=
$one
[
'sku'
];
// 查询出来主键。
$url_key
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
unset
(
$one
[
'url_key'
]);
$primaryKey
=
$this
->
getPrimaryKey
();
$productModel
=
$this
->
getBySku
(
$sku
);
if
(
isset
(
$productModel
[
'sku'
])
&&
$productModel
[
'sku'
])
{
...
...
@@ -1311,7 +1318,7 @@ class ProductMysqldb extends Service implements ProductInterface
// 自定义url部分
if
(
$originUrlKey
)
{
$originUrl
=
$originUrlKey
.
'?'
.
$this
->
getPrimaryKey
()
.
'='
.
$product_id
;
$originUrlKey
=
isset
(
$one
[
'url_key'
])
?
$one
[
'url_key'
]
:
''
;
$originUrlKey
=
$url_key
;
$defaultLangTitle
=
Yii
::
$service
->
fecshoplang
->
getDefaultLangAttrVal
(
$one
[
'name'
],
'name'
);
$urlKey
=
Yii
::
$service
->
url
->
saveRewriteUrlKeyByStr
(
$defaultLangTitle
,
$originUrl
,
$originUrlKey
);
$model
->
url_key
=
$urlKey
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录