mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 21:40:50 +00:00
fix(评价): 同商品重复购买时按订单号定位评价条目
评价页带订单号时后端按订单号+SKU unique 精确落单(原仅凭 unique 反查会命中旧订单);去评价动作兼容列表行 extra_info.items 取条目
This commit is contained in:
parent
45d3304606
commit
b09d029ef9
@ -2749,6 +2749,38 @@ class CenterOrderController
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按订单号+SKU unique 定位中台订单内的评价商品条目
|
||||
* 评价必须落到用户指定的那笔订单:同商品重复购买时各订单 unique 相同,仅凭 unique 反查会命中旧订单
|
||||
* @param string $orderNo 中台订单号
|
||||
* @param string $unique SKU 唯一码
|
||||
* @param int|null $uid 限定归属用户
|
||||
* @return array|null
|
||||
*/
|
||||
protected function findOrderItemByOrderNo(string $orderNo, string $unique, ?int $uid = null): ?array
|
||||
{
|
||||
if ($orderNo === '' || $unique === '') {
|
||||
return null;
|
||||
}
|
||||
$order = app()->make(OrderCenterDao::class)->get(['order_no' => $orderNo]);
|
||||
if (!$order) {
|
||||
return null;
|
||||
}
|
||||
$order = is_object($order) ? $order->toArray() : (array)$order;
|
||||
if ($uid !== null && (int)($order['uid'] ?? 0) !== $uid) {
|
||||
return null;
|
||||
}
|
||||
$extra = is_string($order['extra_info'] ?? null) ? json_decode($order['extra_info'], true) : ($order['extra_info'] ?? []);
|
||||
foreach ($extra['items'] ?? [] as $item) {
|
||||
if (($item['attr_info']['unique'] ?? '') === $unique) {
|
||||
$item['_order_no'] = (string)$order['order_no'];
|
||||
$item['_center_id'] = (int)$order['id'];
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单评价(中台化)
|
||||
* @param StoreProductReplyServices $replyServices
|
||||
@ -2780,7 +2812,11 @@ class CenterOrderController
|
||||
}
|
||||
|
||||
// ==================== 4. 从中台订单快照定位商品(unique 为 SKU 唯一码,限定本人订单防越权) ====================
|
||||
$item = $this->findOrderItemBySkuUnique((string)$unique, $uid);
|
||||
// 页面带订单号(uni)时按订单精确定位;同商品重复购买时 unique 跨订单重复,仅凭 unique 会命中旧订单
|
||||
$uni = (string)request()->param('uni', '');
|
||||
$item = $uni !== ''
|
||||
? $this->findOrderItemByOrderNo($uni, (string)$unique, $uid)
|
||||
: $this->findOrderItemBySkuUnique((string)$unique, $uid);
|
||||
if (!$item) {
|
||||
return app('json')->fail('商品不存在');
|
||||
}
|
||||
|
||||
@ -157,9 +157,19 @@ export default {
|
||||
/** 去评价(后端 NormalOrderAdapter 等模块下发的 action 名;评价页按 SKU unique 提交) */
|
||||
goComment(order, params) {
|
||||
var orderNo = order.order_no || (params && params.order_no) || '';
|
||||
// 取第一个商品条目的 SKU unique;section 以 key='product' 注册,props.product.items 为商品条目
|
||||
// 详情页:section 以 key='product' 注册,props.product.items 为商品条目;
|
||||
// 列表行:extra_info.items 为商品条目(用户端列表接口已解码 extra_info)
|
||||
var items = (order.product && order.product.product && order.product.product.items) || [];
|
||||
var skuUnique = items.length && items[0].attr_info && items[0].attr_info.unique;
|
||||
if (!items.length && order.extra_info && Array.isArray(order.extra_info.items)) {
|
||||
items = order.extra_info.items;
|
||||
}
|
||||
var skuUnique = '';
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
if (items[i] && items[i].attr_info && items[i].attr_info.unique) {
|
||||
skuUnique = items[i].attr_info.unique;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!orderNo || !skuUnique) {
|
||||
uni.showToast({ title: i18n.t(`订单信息异常`), icon: 'none' });
|
||||
return;
|
||||
|
||||
@ -180,6 +180,8 @@
|
||||
value.service_score = service_score;
|
||||
value.pics = pics.value;
|
||||
value.unique = unique.value;
|
||||
// 评价必须落到用户点进来的这笔订单:同商品重复购买时 unique 不唯一,后端需按订单号定位
|
||||
value.uni = orderId.value;
|
||||
uni.showLoading({
|
||||
title: i18n.t(`正在发布评论`)
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user