新增:余额支付、微信支付、下单确认功能

This commit is contained in:
2025-07-28 11:17:41 +08:00
parent 469e020df5
commit 1fdec4b807
14 changed files with 145 additions and 37 deletions

View File

@@ -6,7 +6,7 @@ import {RichText, View} from '@tarojs/components'
import {ShopGoods} from "@/api/shop/shopGoods/model";
import {getShopGoods} from "@/api/shop/shopGoods";
import {Swiper} from '@nutui/nutui-react-taro'
import {wxParse} from "@/utils/common";
import navTo, {wxParse} from "@/utils/common";
import "./index.scss";
import {useCart} from "@/hooks/useCart";
@@ -23,6 +23,14 @@ const GoodsDetail = () => {
const handleAddToCart = () => {
if (!goods) return;
if(!Taro.getStorageSync('UserId')){
return Taro.showToast({
title: '请先登录',
icon: 'none',
duration: 2000
});
}
addToCart({
goodsId: goods.goodsId!,
name: goods.name || '',
@@ -117,7 +125,7 @@ const GoodsDetail = () => {
top: "50px",
right: "110px",
}}
onClick={() => Taro.navigateTo({url: '/pages/cart/cart'})}>
onClick={() => navTo(`/pages/cart/cart`,true)}>
<Badge value={cartCount} top="-2" right="2">
<div style={{display: 'flex', alignItems: 'center'}}>
<Cart size={16}/>
@@ -201,7 +209,7 @@ const GoodsDetail = () => {
onClick={() => handleAddToCart()}>
</div>
<div className={'cart-buy pl-4 pr-5 text-sm'}
onClick={() => Taro.navigateTo({url: `/shop/orderConfirm/index?goodsId=${goods?.goodsId}`})}>
onClick={() => navTo(`/shop/orderConfirm/index?goodsId=${goods?.goodsId}`,true)}>
</div>
</div>
</View>

View File

@@ -12,6 +12,7 @@ import Gap from "@/components/Gap";
import {TenantId} from "@/config/app";
import {payByBalance, selectPayment} from "@/api/system/payment";
import {Payment} from "@/api/system/payment/model";
import {API_BASE_URL} from "@/config/env";
const OrderConfirm = () => {
const [goods, setGoods] = useState<ShopGoods | null>(null);
@@ -60,9 +61,10 @@ const OrderConfirm = () => {
const onBalancePay = async (goods: ShopGoods) => {
Taro.showLoading({title: '支付中...'})
payByBalance({
payType: goods.type,
payType: 0, // 余额支付
payPrice: goods.price,
totalPrice: goods.price,
addressId: address?.id,
userId: Taro.getStorageSync('UserId'),
tenantId: Number(TenantId)
}).then().finally(() => {
@@ -73,7 +75,7 @@ const OrderConfirm = () => {
})
Taro.hideLoading()
setTimeout(() => {
// Taro.switchTab({url: '/pages/order/order'})
Taro.switchTab({url: '/pages/order/order'})
}, 2000)
}).catch(() => {
Taro.hideLoading()
@@ -83,8 +85,8 @@ const OrderConfirm = () => {
const onWxPay = async (goods: ShopGoods) => {
Taro.showLoading({title: '支付中...'})
Taro.request({
// url: 'https://cms-api.websoft.top/api/shop/shop-order',
url: 'http://127.0.0.1:9200/api/shop/shop-order',
url: API_BASE_URL + '/shop/shop-order',
// url: 'http://127.0.0.1:9200/api/shop/shop-order',
method: 'POST',
header: {
'content-type': 'application/json',
@@ -92,15 +94,26 @@ const OrderConfirm = () => {
TenantId
},
data: {
payType: 1,
totalPrice: goods.price,
payPrice: goods.price,
userId: Taro.getStorageSync('UserId'),
tenantId: TenantId,
payType: goods.type,
comments: goods.name,
name: goods.name
name: goods.name,
addressId: address?.id,
},
success: function (res) {
Taro.hideLoading()
if(res.data.code != 0){
Taro.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
})
return false;
}
// 支付结果
const data = res.data.data
console.log(data, 'payInfo')
// Taro.showToast({
@@ -131,13 +144,8 @@ const OrderConfirm = () => {
})
}
},
fail: function (msg) {
console.log('支付失败')
complete: function () {
Taro.hideLoading()
Taro.showToast({
title: `${msg}`,
icon: 'error'
})
}
})
}