初始版本
This commit is contained in:
108
server/app/shopapi/logic/GoodsCommentLogic.php
Executable file
108
server/app/shopapi/logic/GoodsCommentLogic.php
Executable file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\shopapi\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\order\Order;
|
||||
|
||||
/**
|
||||
* 评论控制器类
|
||||
* Class GoodsCommentLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class GoodsCommentLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 评论分类
|
||||
* @param $shopId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/11/1 17:49
|
||||
*/
|
||||
public function commentCategory($shopId)
|
||||
{
|
||||
$orderGoodsIds = Order::alias('O')
|
||||
->join('order_goods OG', 'O.id = OG.order_id')
|
||||
->where(['shop_id' => $shopId, 'is_comment' => 1])
|
||||
->field('OG.id')
|
||||
->select()
|
||||
->toArray();
|
||||
$orderGoodsIds = array_column($orderGoodsIds, 'id');
|
||||
$all_count = GoodsComment::where('order_goods_id', 'in', $orderGoodsIds)->count();
|
||||
$image_count = GoodsComment::alias('gc')->where('order_goods_id', 'in', $orderGoodsIds)->join('goods_comment_image gci', 'gc.id = gci.comment_id')->group('gci.comment_id')->count();
|
||||
$good_count = GoodsComment::where('order_goods_id', 'in', $orderGoodsIds)->where('service_comment', '>', 3)->count();
|
||||
$medium_bad_count = GoodsComment::where('order_goods_id', 'in', $orderGoodsIds)->where('service_comment', '<=', 3)->count();
|
||||
|
||||
if ($all_count == 0) {
|
||||
$percentStr = '100%';
|
||||
$star = 5;
|
||||
} else {
|
||||
$percent = round((($good_count / $all_count) * 100));
|
||||
$percentStr = round((($good_count / $all_count) * 100)) . '%';
|
||||
if ($percent >= 100) {
|
||||
$star = 5;
|
||||
} else if ($percent >= 80) {
|
||||
$star = 4;
|
||||
} else if ($percent >= 60) {
|
||||
$star = 3;
|
||||
} else if ($percent >= 40) {
|
||||
$star = 2;
|
||||
} else if ($percent >= 20) {
|
||||
$star = 1;
|
||||
} else {
|
||||
$star = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ['comment' =>
|
||||
[
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => '全部',
|
||||
'count' => $all_count
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => '有图',
|
||||
'count' => $image_count
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => '好评',
|
||||
'count' => $good_count
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => '中差评',
|
||||
'count' => $medium_bad_count
|
||||
]
|
||||
],
|
||||
'percent' => $percentStr,
|
||||
'star' => $star,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user