Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞鱼0526
ShopXO
提交
20116a57
ShopXO
项目概览
飞鱼0526
/
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,发现更多精彩内容 >>
提交
20116a57
编写于
9月 30, 2021
作者:
X
xindan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
商品接口优化
上级
001f9bd6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
173 addition
and
74 deletion
+173
-74
app/admin/controller/Goodscomments.php
app/admin/controller/Goodscomments.php
+3
-0
app/api/controller/Goods.php
app/api/controller/Goods.php
+6
-1
app/index/controller/Goods.php
app/index/controller/Goods.php
+1
-1
app/service/GoodsCommentsService.php
app/service/GoodsCommentsService.php
+120
-45
app/service/GoodsService.php
app/service/GoodsService.php
+43
-27
未找到文件。
app/admin/controller/Goodscomments.php
浏览文件 @
20116a57
...
...
@@ -69,6 +69,7 @@ class Goodscomments extends Common
'n'
=>
$this
->
page_size
,
'order_by'
=>
$this
->
form_order_by
[
'data'
],
'is_public'
=>
0
,
'is_goods'
=>
1
,
];
$ret
=
GoodsCommentsService
::
GoodsCommentsList
(
$data_params
);
...
...
@@ -100,6 +101,7 @@ class Goodscomments extends Common
'm'
=>
0
,
'n'
=>
1
,
'where'
=>
$where
,
'is_goods'
=>
1
,
];
$ret
=
GoodsCommentsService
::
GoodsCommentsList
(
$data_params
);
$data
=
(
empty
(
$ret
[
'data'
])
||
empty
(
$ret
[
'data'
][
0
]))
?
[]
:
$ret
[
'data'
][
0
];
...
...
@@ -132,6 +134,7 @@ class Goodscomments extends Common
'n'
=>
1
,
'where'
=>
[
'id'
=>
intval
(
$params
[
'id'
])],
'is_public'
=>
0
,
'is_goods'
=>
1
,
);
$ret
=
GoodsCommentsService
::
GoodsCommentsList
(
$data_params
);
$data
=
empty
(
$ret
[
'data'
][
0
])
?
[]
:
$ret
[
'data'
][
0
];
...
...
app/api/controller/Goods.php
浏览文件 @
20116a57
...
...
@@ -94,6 +94,10 @@ class Goods extends Common
// 商品评价总数
$goods
[
'comments_count'
]
=
GoodsCommentsService
::
GoodsCommentsTotal
([
'goods_id'
=>
$goods_id
,
'is_show'
=>
1
]);
// 评分
$goods
[
'comments_score'
]
=
GoodsCommentsService
::
GoodsCommentsScore
(
$goods_id
);
// 最新3条评价
$goods
[
'comments_data'
]
=
GoodsCommentsService
::
GoodsFirstSeveralComments
(
$goods_id
);
// 商品访问统计
GoodsService
::
GoodsAccessCountInc
([
'goods_id'
=>
$goods_id
]);
...
...
@@ -214,7 +218,8 @@ class Goods extends Common
$ret
=
DataReturn
(
'参数有误'
,
-
1
);
}
else
{
// 获取商品评分
$ret
=
GoodsCommentsService
::
GoodsCommentsScore
(
$this
->
data_post
[
'goods_id'
]);
$data
=
GoodsCommentsService
::
GoodsCommentsScore
(
$this
->
data_post
[
'goods_id'
]);
$ret
=
DataReturn
(
'success'
,
0
,
$data
);
}
return
ApiService
::
ApiDataReturn
(
$ret
);
}
...
...
app/index/controller/Goods.php
浏览文件 @
20116a57
...
...
@@ -117,7 +117,7 @@ class Goods extends Common
if
(
!
empty
(
$middle_tabs_nav
)
&&
in_array
(
'comments'
,
$middle_tabs_nav
[
'type'
]))
{
$goods_score
=
GoodsCommentsService
::
GoodsCommentsScore
(
$goods_id
);
MyViewAssign
(
'goods_score'
,
$goods_score
[
'data'
]
);
MyViewAssign
(
'goods_score'
,
$goods_score
);
}
// 详情tab商品 猜你喜欢
...
...
app/service/GoodsCommentsService.php
浏览文件 @
20116a57
...
...
@@ -201,23 +201,42 @@ class GoodsCommentsService
// 获取数据列表
$data
=
Db
::
name
(
'GoodsComments'
)
->
where
(
$where
)
->
field
(
$field
)
->
limit
(
$m
,
$n
)
->
order
(
$order_by
)
->
select
()
->
toArray
();
return
DataReturn
(
'处理成功'
,
0
,
self
::
DataHandle
(
$data
,
$params
));
}
/**
* 数据处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-14
* @desc description
* @param [array] $data [数据]
* @param [array] $params [输入参数]
*/
public
static
function
DataHandle
(
$data
,
$params
=
[])
{
if
(
!
empty
(
$data
))
{
// 获取商品信息
$goods_params
=
[
'where'
=>
[
'id'
=>
array_unique
(
array_column
(
$data
,
'goods_id'
)),
'is_delete_time'
=>
0
,
],
'field'
=>
'id,title,images,price,min_price'
,
];
$ret
=
GoodsService
::
GoodsList
(
$goods_params
);
$is_goods
=
(
isset
(
$params
[
'is_goods'
])
&&
$params
[
'is_goods'
]
==
1
)
?
1
:
0
;
$goods
=
[];
if
(
!
empty
(
$ret
[
'data'
])
)
if
(
$is_goods
==
1
)
{
foreach
(
$ret
[
'data'
]
as
$g
)
$goods_params
=
[
'where'
=>
[
'id'
=>
array_unique
(
array_column
(
$data
,
'goods_id'
)),
'is_delete_time'
=>
0
,
],
'field'
=>
'id,title,images,price,min_price'
,
];
$ret
=
GoodsService
::
GoodsList
(
$goods_params
);
if
(
!
empty
(
$ret
[
'data'
]))
{
$goods
[
$g
[
'id'
]]
=
$g
;
foreach
(
$ret
[
'data'
]
as
$g
)
{
$goods
[
$g
[
'id'
]]
=
$g
;
}
}
}
...
...
@@ -230,19 +249,22 @@ class GoodsCommentsService
foreach
(
$data
as
&
$v
)
{
// 用户信息
$user
=
UserService
::
GetUserViewInfo
(
$v
[
'user_id'
]);
if
(
!
isset
(
$params
[
'is_public'
])
||
$params
[
'is_public'
]
==
1
)
if
(
array_key_exists
(
'user_id'
,
$v
))
{
$v
[
'user'
]
=
[
'avatar'
=>
$user
[
'avatar'
],
'user_name_view'
=>
(
$v
[
'is_anonymous'
]
==
1
)
?
'匿名'
:
mb_substr
(
$user
[
'user_name_view'
],
0
,
1
,
'utf-8'
)
.
'***'
.
mb_substr
(
$user
[
'user_name_view'
],
-
1
,
null
,
'utf-8'
),
];
}
else
{
$v
[
'user'
]
=
$user
;
$user
=
UserService
::
GetUserViewInfo
(
$v
[
'user_id'
]);
if
(
!
isset
(
$params
[
'is_public'
])
||
$params
[
'is_public'
]
==
1
)
{
$v
[
'user'
]
=
[
'avatar'
=>
$user
[
'avatar'
],
'user_name_view'
=>
(
!
isset
(
$v
[
'is_anonymous'
])
||
$v
[
'is_anonymous'
]
==
1
)
?
'匿名'
:
mb_substr
(
$user
[
'user_name_view'
],
0
,
1
,
'utf-8'
)
.
'***'
.
mb_substr
(
$user
[
'user_name_view'
],
-
1
,
null
,
'utf-8'
),
];
}
else
{
$v
[
'user'
]
=
$user
;
}
}
// 图片
if
(
isset
(
$v
[
'images'
]
))
if
(
array_key_exists
(
'images'
,
$v
))
{
if
(
!
empty
(
$v
[
'images'
]))
{
...
...
@@ -256,43 +278,75 @@ class GoodsCommentsService
}
// 商品信息
$v
[
'goods'
]
=
isset
(
$goods
[
$v
[
'goods_id'
]])
?
$goods
[
$v
[
'goods_id'
]]
:
[];
if
(
array_key_exists
(
'goods_id'
,
$v
)
&&
$is_goods
==
1
)
{
$v
[
'goods'
]
=
isset
(
$goods
[
$v
[
'goods_id'
]])
?
$goods
[
$v
[
'goods_id'
]]
:
[];
}
// 业务类型
$v
[
'business_type_text'
]
=
array_key_exists
(
$v
[
'business_type'
],
$comments_business_type_list
)
?
$comments_business_type_list
[
$v
[
'business_type'
]][
'name'
]
:
null
;
$msg
=
null
;
switch
(
$v
[
'business_type'
])
if
(
array_key_exists
(
'business_type'
,
$v
))
{
// 订单
case
'order'
:
$msg
=
self
::
BusinessTypeOrderSpec
(
$v
[
'order_id'
],
$v
[
'goods_id'
],
$v
[
'user_id'
]);
$v
[
'business_type_text'
]
=
array_key_exists
(
$v
[
'business_type'
],
$comments_business_type_list
)
?
$comments_business_type_list
[
$v
[
'business_type'
]][
'name'
]
:
null
;
$msg
=
null
;
switch
(
$v
[
'business_type'
])
{
// 订单
case
'order'
:
if
(
!
empty
(
$v
[
'order_id'
])
&&
!
empty
(
$v
[
'goods_id'
])
&&
!
empty
(
$v
[
'user_id'
]))
{
$msg
=
self
::
BusinessTypeOrderSpec
(
$v
[
'order_id'
],
$v
[
'goods_id'
],
$v
[
'user_id'
]);
}
}
$v
[
'msg'
]
=
empty
(
$msg
)
?
null
:
$msg
;
}
$v
[
'msg'
]
=
empty
(
$msg
)
?
null
:
$msg
;
// 评分
$v
[
'rating_text'
]
=
$comments_rating_list
[
$v
[
'rating'
]][
'name'
];
$v
[
'rating_badge'
]
=
$comments_rating_list
[
$v
[
'rating'
]][
'badge'
];
if
(
array_key_exists
(
'rating'
,
$v
))
{
$v
[
'rating_text'
]
=
$comments_rating_list
[
$v
[
'rating'
]][
'name'
];
$v
[
'rating_badge'
]
=
$comments_rating_list
[
$v
[
'rating'
]][
'badge'
];
}
// 是否
$v
[
'is_reply_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_reply'
]])
?
$common_is_text_list
[
$v
[
'is_reply'
]][
'name'
]
:
''
;
$v
[
'is_anonymous_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_anonymous'
]])
?
$common_is_text_list
[
$v
[
'is_anonymous'
]][
'name'
]
:
''
;
$v
[
'is_show_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_show'
]])
?
$common_is_text_list
[
$v
[
'is_show'
]][
'name'
]
:
''
;
if
(
array_key_exists
(
'is_reply'
,
$v
))
{
$v
[
'is_reply_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_reply'
]])
?
$common_is_text_list
[
$v
[
'is_reply'
]][
'name'
]
:
''
;
}
if
(
array_key_exists
(
'is_anonymous'
,
$v
))
{
$v
[
'is_anonymous_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_anonymous'
]])
?
$common_is_text_list
[
$v
[
'is_anonymous'
]][
'name'
]
:
''
;
}
if
(
array_key_exists
(
'is_show'
,
$v
))
{
$v
[
'is_show_text'
]
=
isset
(
$common_is_text_list
[
$v
[
'is_show'
]])
?
$common_is_text_list
[
$v
[
'is_show'
]][
'name'
]
:
''
;
}
// 回复时间
$v
[
'reply_time_time'
]
=
empty
(
$v
[
'reply_time'
])
?
null
:
date
(
'Y-m-d H:i:s'
,
$v
[
'reply_time'
]);
$v
[
'reply_time_date'
]
=
empty
(
$v
[
'reply_time'
])
?
null
:
date
(
'Y-m-d'
,
$v
[
'reply_time'
]);
if
(
array_key_exists
(
'reply_time'
,
$v
))
{
$v
[
'reply_time_time'
]
=
empty
(
$v
[
'reply_time'
])
?
null
:
date
(
'Y-m-d H:i:s'
,
$v
[
'reply_time'
]);
$v
[
'reply_time_date'
]
=
empty
(
$v
[
'reply_time'
])
?
null
:
date
(
'm-d H:i'
,
$v
[
'reply_time'
]);
}
// 评论时间
$v
[
'add_time_hour'
]
=
date
(
'H:i:s'
,
$v
[
'add_time'
]);
$v
[
'add_time_time'
]
=
date
(
'Y-m-d H:i:s'
,
$v
[
'add_time'
]);
$v
[
'add_time_date'
]
=
date
(
'Y-m-d'
,
$v
[
'add_time'
]);
if
(
array_key_exists
(
'add_time'
,
$v
))
{
$v
[
'add_time_hour'
]
=
date
(
'H:i:s'
,
$v
[
'add_time'
]);
$v
[
'add_time_time'
]
=
date
(
'Y-m-d H:i:s'
,
$v
[
'add_time'
]);
$v
[
'add_time_date'
]
=
date
(
'm-d H:i'
,
$v
[
'add_time'
]);
}
// 更新时间
$v
[
'upd_time_time'
]
=
empty
(
$v
[
'upd_time'
])
?
null
:
date
(
'Y-m-d H:i:s'
,
$v
[
'upd_time'
]);
$v
[
'upd_time_date'
]
=
empty
(
$v
[
'upd_time'
])
?
null
:
date
(
'Y-m-d'
,
$v
[
'upd_time'
]);
if
(
array_key_exists
(
'upd_time'
,
$v
))
{
$v
[
'upd_time_time'
]
=
empty
(
$v
[
'upd_time'
])
?
null
:
date
(
'Y-m-d H:i:s'
,
$v
[
'upd_time'
]);
$v
[
'upd_time_date'
]
=
empty
(
$v
[
'upd_time'
])
?
null
:
date
(
'm-d H:I'
,
$v
[
'upd_time'
]);
}
}
}
else
{
$data
=
[];
}
return
DataReturn
(
'处理成功'
,
0
,
$data
)
;
return
$data
;
}
/**
...
...
@@ -583,13 +637,34 @@ class GoodsCommentsService
}
}
}
sort
(
$rating_list
);
$result
=
[
'avg'
=>
PriceNumberFormat
(
Db
::
name
(
'GoodsComments'
)
->
where
(
$where
)
->
avg
(
'rating'
),
1
),
$avg
=
PriceNumberFormat
(
Db
::
name
(
'GoodsComments'
)
->
where
(
$where
)
->
avg
(
'rating'
),
1
);
$rate
=
(
$avg
<=
0
)
?
100
:
intval
((
$avg
/
5
)
*
100
);
return
[
'avg'
=>
$avg
,
'rate'
=>
$rate
,
'rating'
=>
$rating_list
,
];
return
DataReturn
(
'操作成功'
,
0
,
$result
);
}
/**
* 商品最新几条评论
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-15
* @desc description
* @param [int] $goods_id [商品id]
* @param [int] $number [获取数量、默认3条]
*/
public
static
function
GoodsFirstSeveralComments
(
$goods_id
,
$number
=
3
)
{
$where
=
[
[
'goods_id'
,
'='
,
$goods_id
],
[
'is_show'
,
'='
,
1
],
];
$field
=
'id,user_id,order_id,business_type,content,reply,is_reply,rating,images,is_anonymous,reply_time,add_time'
;
return
self
::
DataHandle
(
Db
::
name
(
'GoodsComments'
)
->
where
(
$where
)
->
field
(
$field
)
->
limit
(
0
,
$number
)
->
order
(
'id desc'
)
->
select
()
->
toArray
());
}
}
?>
\ No newline at end of file
app/service/GoodsService.php
浏览文件 @
20116a57
...
...
@@ -2742,29 +2742,40 @@ class GoodsService
*/
public
static
function
GoodsDetailMiddleTabsNavList
(
$goods
)
{
// 评论总数
$comments_count
=
isset
(
$goods
[
'comments_count'
])
?
$goods
[
'comments_count'
]
:
GoodsCommentsService
::
GoodsCommentsTotal
([
'goods_id'
=>
$goods
[
'id'
],
'is_show'
=>
1
]);
// 列表
// type 类型
// name 名称
// active 选中(可选)
// value 数据值(可选)
$data
=
[
[
'type'
=>
'detail'
,
'name'
=>
'详情'
,
'active'
=>
1
,
],
[
'type'
=>
'comments'
,
'name'
=>
'评论('
.
$comments_count
.
')'
,
],
[
'type'
=>
'guess_you_like'
,
'name'
=>
'猜你喜欢'
,
]
];
// app与web端不一致
if
(
APPLICATION
==
'app'
)
{
// 这里的 ent 值必须和系统中区域块定义的一致
$data
=
[
[
'name'
=>
'商品'
,
'ent'
=>
'.page'
],
[
'name'
=>
'评价'
,
'ent'
=>
'.goods-comment'
],
[
'name'
=>
'详情'
,
'ent'
=>
'.goods-detail'
],
];
}
else
{
// 评论总数
$comments_count
=
isset
(
$goods
[
'comments_count'
])
?
$goods
[
'comments_count'
]
:
GoodsCommentsService
::
GoodsCommentsTotal
([
'goods_id'
=>
$goods
[
'id'
],
'is_show'
=>
1
]);
// 列表
// type 类型
// name 名称
// active 选中(可选)
// value 数据值(可选)
$data
=
[
[
'type'
=>
'detail'
,
'name'
=>
'详情'
,
'active'
=>
1
,
],
[
'type'
=>
'comments'
,
'name'
=>
'评价('
.
$comments_count
.
')'
,
],
[
'type'
=>
'guess_you_like'
,
'name'
=>
'猜你喜欢'
,
]
];
}
// 商品详情中间导航钩子
$hook_name
=
'plugins_service_goods_detail_middle_tabs_nav_handle'
;
...
...
@@ -2776,10 +2787,15 @@ class GoodsService
]);
// 返回数据
return
[
'nav'
=>
$data
,
'type'
=>
array_column
(
$data
,
'type'
),
];
if
(
APPLICATION
==
'app'
)
{
return
$data
;
}
else
{
return
[
'nav'
=>
$data
,
'type'
=>
array_column
(
$data
,
'type'
),
];
}
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录