Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jcy2004x
ShopXO
提交
c8c48800
ShopXO
项目概览
jcy2004x
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
GitCode(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c8c48800
编写于
6月 02, 2019
作者:
G
gongfuxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
搜索优化
上级
7955273c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
114 addition
and
25 deletion
+114
-25
application/common.php
application/common.php
+47
-0
application/index/controller/Search.php
application/index/controller/Search.php
+50
-24
application/index/view/default/public/nav_search.html
application/index/view/default/public/nav_search.html
+1
-1
application/service/GoodsService.php
application/service/GoodsService.php
+16
-0
未找到文件。
application/common.php
浏览文件 @
c8c48800
...
...
@@ -11,6 +11,53 @@
// 应用公共文件
/**
* 字符串转ascii
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-02T01:13:47+0800
* @param [string] $str [字符串]
* @return [string] [转换后的ascii]
*/
function
StrToAscii
(
$str
)
{
$change_after
=
''
;
if
(
!
empty
(
$str
))
{
$str
=
mb_convert_encoding
(
$str
,
'GB2312'
);
for
(
$i
=
0
;
$i
<
strlen
(
$str
);
$i
++
){
$temp_str
=
dechex
(
ord
(
$str
[
$i
]));
$change_after
.
=
$temp_str
[
1
]
.
$temp_str
[
0
];
}
}
return
strtoupper
(
$change_after
);
}
/**
* ascii转字符串
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-02T01:14:04+0800
* @param [string] $ascii [ascii]
* @return [string] [转换后的字符串]
*/
function
AsciiToStr
(
$ascii
)
{
$str
=
''
;
if
(
!
empty
(
$ascii
))
{
$asc_arr
=
str_split
(
strtolower
(
$ascii
),
2
);
for
(
$i
=
0
;
$i
<
count
(
$asc_arr
);
$i
++
)
{
$str
.
=
chr
(
hexdec
(
$asc_arr
[
$i
][
1
]
.
$asc_arr
[
$i
][
0
]));
}
}
return
mb_convert_encoding
(
$str
,
'UTF-8'
,
'GB2312'
);
}
/**
* 获取当前系统所在根路径
* @author Devil
...
...
application/index/controller/Search.php
浏览文件 @
c8c48800
...
...
@@ -13,6 +13,7 @@ namespace app\index\controller;
use
app\service\SearchService
;
use
app\service\BrandService
;
use
app\service\SeoService
;
use
app\service\GoodsService
;
/**
* 搜索
...
...
@@ -36,27 +37,8 @@ class Search extends Common
public
function
__construct
()
{
parent
::
__construct
();
// 品牌id
$this
->
params
[
'brand_id'
]
=
intval
(
input
(
'brand_id'
,
0
));
// 分类id
$this
->
params
[
'category_id'
]
=
intval
(
input
(
'category_id'
,
0
));
// 筛选价格id
$this
->
params
[
'screening_price_id'
]
=
intval
(
input
(
'screening_price_id'
,
0
));
// 搜索关键字
$this
->
params
[
'wd'
]
=
str_replace
([
'?'
,
' '
,
'+'
,
'-'
],
''
,
trim
(
input
(
'wd'
)));
// 排序方式
$this
->
params
[
'order_by_field'
]
=
input
(
'order_by_field'
,
'default'
);
$this
->
params
[
'order_by_type'
]
=
input
(
'order_by_type'
,
'desc'
);
// 用户信息
$this
->
params
[
'user_id'
]
=
isset
(
$this
->
user
[
'id'
])
?
$this
->
user
[
'id'
]
:
0
;
}
/**
* 首页
* @author Devil
...
...
@@ -66,11 +48,14 @@ class Search extends Common
*/
public
function
Index
()
{
if
(
input
(
'post.'
))
$keywords
=
input
(
'post.wd'
);
if
(
!
empty
(
$keywords
))
{
$p
=
empty
(
$this
->
params
[
'wd'
])
?
[]
:
[
'wd'
=>
$this
->
params
[
'wd'
]];
return
redirect
(
MyUrl
(
'index/search/index'
,
$p
));
return
redirect
(
MyUrl
(
'index/search/index'
,
[
'wd'
=>
StrToAscii
(
$keywords
)]));
}
else
{
// 参数初始化
$this
->
ParamsInit
();
// 品牌列表
$this
->
assign
(
'brand_list'
,
BrandService
::
CategoryBrandList
([
'category_id'
=>
$this
->
params
[
'category_id'
],
'keywords'
=>
$this
->
params
[
'wd'
]]));
...
...
@@ -84,12 +69,50 @@ class Search extends Common
$this
->
assign
(
'params'
,
$this
->
params
);
// 浏览器名称
$this
->
assign
(
'home_seo_site_title'
,
SeoService
::
BrowserSeoTitle
(
'商品搜索'
,
1
));
if
(
!
empty
(
$this
->
params
[
'category_id'
]))
{
$seo_name
=
GoodsService
::
GoodsCategoryValue
(
$this
->
params
[
'category_id'
],
'name'
,
'商品搜索'
);
}
else
{
$seo_name
=
empty
(
$this
->
params
[
'wd'
])
?
'商品搜索'
:
$this
->
params
[
'wd'
];
}
$this
->
assign
(
'home_seo_site_title'
,
SeoService
::
BrowserSeoTitle
(
$seo_name
,
1
));
return
$this
->
fetch
();
}
}
/**
* 参数初始化
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-02T01:38:27+0800
*/
private
function
ParamsInit
()
{
// 参数
$params
=
input
();
// 品牌id
$this
->
params
[
'brand_id'
]
=
isset
(
$params
[
'brand_id'
])
?
intval
(
$params
[
'brand_id'
])
:
0
;
// 分类id
$this
->
params
[
'category_id'
]
=
isset
(
$params
[
'category_id'
])
?
intval
(
$params
[
'category_id'
])
:
0
;
// 筛选价格id
$this
->
params
[
'screening_price_id'
]
=
isset
(
$params
[
'screening_price_id'
])
?
intval
(
$params
[
'screening_price_id'
])
:
0
;
// 搜索关键字
$this
->
params
[
'wd'
]
=
empty
(
$params
[
'wd'
])
?
''
:
(
IS_AJAX
?
trim
(
$params
[
'wd'
])
:
AsciiToStr
(
$params
[
'wd'
]));
// 排序方式
$this
->
params
[
'order_by_field'
]
=
empty
(
$params
[
'order_by_field'
])
?
'default'
:
$params
[
'order_by_field'
];
$this
->
params
[
'order_by_type'
]
=
empty
(
$params
[
'order_by_type'
])
?
'desc'
:
$params
[
'order_by_type'
];
// 用户信息
$this
->
params
[
'user_id'
]
=
isset
(
$this
->
user
[
'id'
])
?
$this
->
user
[
'id'
]
:
0
;
}
/**
* 获取商品列表
* @author Devil
...
...
@@ -100,6 +123,9 @@ class Search extends Common
*/
public
function
GoodsList
()
{
// 参数初始化
$this
->
ParamsInit
();
// 获取商品列表
$this
->
params
[
'keywords'
]
=
$this
->
params
[
'wd'
];
$ret
=
SearchService
::
GoodsList
(
$this
->
params
);
...
...
application/index/view/default/public/nav_search.html
浏览文件 @
c8c48800
...
...
@@ -20,7 +20,7 @@
{{if !empty($home_search_keywords)}}
<ul
class=
"search-hot-keywords"
>
{{foreach $home_search_keywords as $v}}
<li><a
href=
"{{:MyUrl('index/search/index', ['wd'=>
$v
])}}"
target=
"_blank"
>
{{$v}}
</a></li>
<li><a
href=
"{{:MyUrl('index/search/index', ['wd'=>
StrToAscii($v)
])}}"
target=
"_blank"
>
{{$v}}
</a></li>
{{/foreach}}
</ul>
{{/if}}
...
...
application/service/GoodsService.php
浏览文件 @
c8c48800
...
...
@@ -2163,5 +2163,21 @@ class GoodsService
}
return
DataReturn
(
'删除失败'
,
-
100
);
}
/**
* 获取商品分类字段字段数据
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-06-02T01:51:31+0800
* @param [int] $category_id [商品分类id]
* @param [string] $field [指定字段值]
* @param [string] $default [默认值]
*/
public
static
function
GoodsCategoryValue
(
$category_id
,
$field
,
$default
=
null
)
{
$value
=
Db
::
name
(
'GoodsCategory'
)
->
where
([
'id'
=>
intval
(
$category_id
)])
->
value
(
$field
);
return
(
$value
===
null
)
?
$default
:
$value
;
}
}
?>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录