fix(商品评价): 去掉已删 cartInfo 关联,推荐评价失败不拖垮好评统计

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
吴昊天 2026-10-27 13:09:31 +08:00
parent 99e7a70245
commit 066cd52f8c
3 changed files with 12 additions and 9 deletions

View File

@ -54,8 +54,9 @@ class StoreProductReplyDao extends BaseDao
*/
public function getProductReply(int $productId)
{
// cartInfo 关联已随 eb_store_order_cart_info 删除,SKU 由本表 suk 承载,仅预加载 userInfo
return $this->search(['product_id' => $productId, 'is_del' => 0, 'status' => 1])
->with(['cartInfo', 'userInfo'])
->with(['userInfo'])
->order('add_time DESC,product_score DESC,service_score DESC,add_time DESC')
->find();
}

View File

@ -840,11 +840,14 @@ class CenterProductServices extends BaseService
$reply = null;
$replyCount = 0;
$replyChance = 0;
$replyService = app()->make(\app\services\product\product\StoreProductReplyServices::class);
// 统计与推荐评价拆开:推荐评价失败不应拖垮数量/好评率
try {
$replyService = app()->make(\app\services\product\product\StoreProductReplyServices::class);
$reply = get_thumb_water($replyService->getRecProductReply($id), 'big', ['pics']);
[$replyCount, $goodReply, $replyChance] = $replyService->getProductReplyData($id);
} catch (\Throwable $e) {}
try {
$reply = get_thumb_water($replyService->getRecProductReply($id), 'big', ['pics']);
} catch (\Throwable $e) {}
// ========== 9. 优惠券 ==========
$coupons = [];

View File

@ -246,17 +246,16 @@ class StoreProductReplyServices extends BaseService
if ($res) {
$res = $res->toArray();
if ($res['suk'] === '') {
$res['suk'] = isset($res['cart_info']['productInfo']['attrInfo']) ? $res['cart_info']['productInfo']['attrInfo']['suk'] : '';
}
// SKU 以评价表 suk 为准(旧 cartInfo 关联已删除)
$res['suk'] = (string)($res['suk'] ?? '');
$res['nickname'] = anonymity($res['nickname']);
$res['merchant_reply_time'] = date('Y-m-d H:i', $res['merchant_reply_time']);
$replyTime = (int)($res['merchant_reply_time'] ?? 0);
$res['merchant_reply_time'] = $replyTime > 0 ? date('Y-m-d H:i', $replyTime) : '';
$res['add_time'] = time_tran($res['add_time']);
$res['star'] = bcadd($res['product_score'], $res['service_score'], 2);
$res['star'] = bcadd((string)$res['product_score'], (string)$res['service_score'], 2);
$res['star'] = bcdiv($res['star'], '2', 0);
$res['comment'] = $res['comment'] ?: '此用户没有填写评价';
$res['pics'] = is_string($res['pics']) ? json_decode($res['pics'], true) : $res['pics'];
unset($res['cartInfo']);
}
return $res;
}