Parcourir la source

限购数据问题

yuhongqi il y a 4 jours
Parent
commit
c4629c4363

+ 6 - 3
api/product.js

@@ -40,9 +40,12 @@ let request = new Request().http
  export function getTuiProducts(data) {
  	 return request('/app/product/getTuiProducts',data,'GET');
  }
- export function getStoreProductAttrValueList(data) {
- 	 return request('/app/product/getStoreProductAttrValueList',data,'GET');
- }
+export function getStoreProductAttrValueList(data) {
+	 return request('/app/product/getStoreProductAttrValueList',data,'GET');
+}
+export function checkPurchaseLimit(data) {
+	 return request('/app/product/checkPurchaseLimit',data,'GET');
+}
  
  
  

+ 0 - 8
package-lock.json

@@ -16,20 +16,12 @@
     },
     "dayjs": {
       "version": "1.11.19",
-<<<<<<< HEAD
-      "resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.19.tgz",
-=======
       "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.19.tgz",
->>>>>>> 8722d06ebbdea27bb060ba30f05e1e37cf4dcfed
       "integrity": "sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw=="
     },
     "uview-ui": {
       "version": "2.0.38",
-<<<<<<< HEAD
-      "resolved": "https://registry.npmmirror.com/uview-ui/-/uview-ui-2.0.38.tgz",
-=======
       "resolved": "https://registry.npmjs.org/uview-ui/-/uview-ui-2.0.38.tgz",
->>>>>>> 8722d06ebbdea27bb060ba30f05e1e37cf4dcfed
       "integrity": "sha512-6egHDf9lXHKpG3hEjRE0vMx4+VWwKk/ReTf5x18KrIKqdvdPRqO3+B8Unh7vYYwrIxzAWIlmhZ9RJpKI/4UqPQ=="
     },
     "vuex": {

+ 2 - 2
pages/shopping/productDetails.vue

@@ -360,7 +360,7 @@
 					if (this.remainingPurchaseLimit === 0) {
 						uni.showToast({
 							icon: 'none',
-							title: "库存不足",
+							title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
 						});
 						return;
 					}
@@ -376,7 +376,7 @@
 				if (this.specNum == 0) {
 					uni.showToast({
 						icon: 'none',
-						title: "库存不足",
+						title: "购买商品数量必须大于0",
 					});
 					return;
 				}

+ 23 - 1
pages_course/living.vue

@@ -722,6 +722,9 @@
 	import {
 		editUser
 	} from '@/api/user'
+	import {
+		checkPurchaseLimit
+	} from '@/api/product'
 	import {
 		nextTick
 	} from 'vue';
@@ -4638,8 +4641,27 @@
 				}, 20000);
 			},
 			// 去购买,跳商品详情
-			goShop(productId, goodsId) {
+			async goShop(productId, goodsId) {
 				if (!this.liveId) return;
+				// 检查限购
+				try {
+					const res = await checkPurchaseLimit({ productId: productId });
+					if (res.code !== 200) {
+						uni.showToast({
+							icon: 'none',
+							title: res.msg || '该商品限购,目前剩余可购买数量不足'
+						});
+						return;
+					}
+				} catch (error) {
+					console.error('检查限购失败:', error);
+					uni.showToast({
+						icon: 'none',
+						title: '检查限购失败,请稍后重试'
+					});
+					return;
+				}
+				// 限购检查通过,进行跳转
 				uni.navigateTo({
 					url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' +
 						this.liveId +

+ 2 - 2
pages_shopping/live/goods.vue

@@ -197,7 +197,7 @@
 					if (this.remainingPurchaseLimit === 0) {
 						uni.showToast({
 							icon: 'none',
-							title: "库存不足",
+							title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
 						});
 						return;
 					}
@@ -213,7 +213,7 @@
 				if (this.totalNum == 0) {
 					uni.showToast({
 						icon: 'none',
-						title: "库存不足",
+						title: "购买商品数量必须大于0",
 					});
 					return;
 				}

+ 50 - 1
pages_user/user/storeOrder.vue

@@ -173,6 +173,7 @@
 <script>
 	import {getMyStoreOrderList,cancelOrder,canceliveOrder, deleteOrder as deleteOrderApi, cancelLiveOrder} from '@/api/storeOrder'
 	import {getDicts} from '@/api/index'
+	import {checkPurchaseLimit} from '@/api/product'
 	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
 	export default {
 		mixins: [MescrollMixin], 
@@ -352,13 +353,61 @@
 				    }
 				});
 			},
-			pay(item) {
+			async pay(item) {
 				if(item.isPrescribe==1 && item.prescribeId==null){
 					uni.navigateTo({
 						url:"/pages/shopping/prescribe?orderId="+item.id
 					});
 				}
 				else{
+					// 检查限购
+					let productId = null;
+					if(item.orderType==2){
+						// 直播订单,从 item 中获取 productId
+						if(item.productId){
+							productId = item.productId;
+						} else if(item.itemJson){
+							try {
+								const itemJson = JSON.parse(item.itemJson);
+								productId = itemJson.productId;
+							} catch(e) {
+								console.error('解析 itemJson 失败:', e);
+							}
+						}
+					} else {
+						// 普通订单,从 items 中获取第一个商品的 productId
+						if(item.items && item.items.length > 0 && item.items[0].jsonInfo){
+							try {
+								const jsonInfo = JSON.parse(item.items[0].jsonInfo);
+								productId = jsonInfo.productId;
+							} catch(e) {
+								console.error('解析 jsonInfo 失败:', e);
+							}
+						}
+					}
+					
+					// 如果获取到 productId,检查限购
+					if(productId){
+						try {
+							const res = await checkPurchaseLimit({ productId: productId });
+							if (res.code !== 200) {
+								uni.showToast({
+									icon: 'none',
+									title: res.msg || '该商品限购,目前剩余可购买数量不足'
+								});
+								return;
+							}
+						} catch (error) {
+							console.error('检查限购失败:', error);
+							uni.showToast({
+								icon: 'none',
+								title: '检查限购失败,请稍后重试'
+							});
+							return;
+						}
+					}
+					
+					// 限购检查通过,进行支付跳转
 					if(item.orderType==2){
 						// 支付
 						console.log("去支付", item)