展示点券/10 正常了
This commit is contained in:
@@ -107,5 +107,35 @@ class XpdExchangeTests(unittest.TestCase):
|
||||
self.assertEqual((second_params['page_begin'], second_params['page_num']), ('10', '2'))
|
||||
|
||||
|
||||
def test_exchange_keeps_raw_price_from_goods_list(self):
|
||||
self.client._request = Mock(side_effect=[
|
||||
SimpleNamespace(
|
||||
text='var recommend={"errcode":0,"data":{"client_data":{"itemsdetail":[{'
|
||||
'"iGoodsId":"goods-1","sGoodsName":"测试商品","iPrice":"6800",'
|
||||
'"iJb2Price":"0","iGoodsLeft":"-1"}]}}};',
|
||||
),
|
||||
SimpleNamespace(text='var buyInfo={"ret":"0","msg":"ok","serial":"order-1","newBalance":88};'),
|
||||
])
|
||||
|
||||
goods = self.client.xpd_list_goods(
|
||||
embed_query={}, act_id='46195', openid='openid', roleid='roleid',
|
||||
)['goods']
|
||||
result = self.client.xpd_exchange_goods(
|
||||
embed_query={'code': 'fresh-code'},
|
||||
act_id='46195',
|
||||
rid='9263298',
|
||||
commodity_id=goods[0]['commodity_id'],
|
||||
price=goods[0]['price'],
|
||||
picture='',
|
||||
pay_type=1,
|
||||
action_id='46195',
|
||||
)
|
||||
|
||||
self.assertEqual(goods[0]['price'], 6800)
|
||||
self.assertEqual(result['serial'], 'order-1')
|
||||
params = self.client._request.call_args.kwargs['params']
|
||||
self.assertEqual(json.loads(params['appext'])['user_price'], 6800)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -231,10 +231,21 @@ function goodsLabel(item: DouyuGoodsItem): string {
|
||||
return `${item.name || item.commodity_id}${item.score ? ` / ${item.score}积分` : ''}${stockText}`;
|
||||
}
|
||||
|
||||
// 道聚城 iPrice 为 10 倍点券单位(如 6800=680 点券),仅展示层换算,兑换请求仍传原值。
|
||||
const XPD_POINT_PRICE_SCALE = 10;
|
||||
|
||||
function xpdPointPrice(item: DouyuGoodsItem): number {
|
||||
const xpd = item as DouyuGoodsItem & { price?: number | null };
|
||||
const raw = item.raw?.raw as Record<string, unknown> | undefined;
|
||||
const rawPrice = Number(xpd.price ?? raw?.iPrice);
|
||||
if (!Number.isFinite(rawPrice) || rawPrice <= 0) return 0;
|
||||
return Math.round(rawPrice / XPD_POINT_PRICE_SCALE);
|
||||
}
|
||||
|
||||
function xpdGoodsLabel(item: DouyuGoodsItem): string {
|
||||
const xpd = item as DouyuGoodsItem & { price?: number | null; goods_left?: number | null };
|
||||
const raw = item.raw?.raw as Record<string, unknown> | undefined;
|
||||
const pointPrice = Number(xpd.price ?? raw?.iPrice);
|
||||
const pointPrice = xpdPointPrice(item);
|
||||
const fragmentPrice = Number(raw?.iJb2Price);
|
||||
const prices = [
|
||||
Number.isFinite(pointPrice) && pointPrice > 0 ? `${pointPrice}点券` : '',
|
||||
@@ -249,9 +260,8 @@ function xpdGoodsLabel(item: DouyuGoodsItem): string {
|
||||
|
||||
function xpdGoodsPaymentOptions(item: DouyuGoodsItem | undefined): Array<{ value: '1' | '5'; label: string }> {
|
||||
if (!item) return [];
|
||||
const xpd = item as DouyuGoodsItem & { price?: number | null };
|
||||
const raw = item.raw?.raw as Record<string, unknown> | undefined;
|
||||
const pointPrice = Number(xpd.price ?? raw?.iPrice);
|
||||
const pointPrice = xpdPointPrice(item);
|
||||
const fragmentPrice = Number(raw?.iJb2Price);
|
||||
return [
|
||||
Number.isFinite(pointPrice) && pointPrice > 0
|
||||
|
||||
Reference in New Issue
Block a user