Parcourir la source

限购数据问题

yuhongqi il y a 3 jours
Parent
commit
de33d520de

+ 6 - 0
api/product.js

@@ -46,6 +46,12 @@ export function getStoreProductAttrValueList(data) {
 export function checkPurchaseLimit(data) {
 	 return request('/app/product/checkPurchaseLimit',data,'GET');
 }
+export function checkCartPurchaseLimit(data) {
+	 return request('/app/product/checkCartPurchaseLimit',data,'POST','application/json;charset=UTF-8');
+}
+export function checkOrderPurchaseLimit(data) {
+	 return request('/app/product/checkOrderPurchaseLimit',data,'GET');
+}
  
  
  

+ 2 - 2
common/request.js

@@ -10,8 +10,8 @@ export default class Request {
 		// let path = 'https://test.userapp.store.cdwjyyh.com';
 		// let path = 'https://user.test.ylrztop.com/api';
 
-		let path = 'https://userapp.klbycp.com/store'; //百域承品
-		let path2 = 'https://userapp.klbycp.com'; //百域承品
+		let path = 'http://localhost:8113/store'; //百域承品
+		let path2 = 'http://localhost:8113'; //百域承品
 
 		//let path = 'http://e895a54d.natappfree.cc/store'; //百域承品 夏伟
 		//let path2 = 'http://e895a54d.natappfree.cc'; //百域承品 夏伟

+ 45 - 0
components/custom-toast.vue

@@ -0,0 +1,45 @@
+<template>
+  <view class="custom-toast" v-if="visible">
+    {{ message }}
+  </view>
+</template>
+
+<script>
+export default {
+  name:'CustomToast',
+  data() {
+    return {
+      visible: false,
+      message: '',
+      duration: 1500,
+      fontSize: '16px' // 可配置字体大小
+    };
+  },
+  methods: {
+    show(options) {
+      this.message = options.title || '';
+      this.duration = options.duration || 1500;
+      this.fontSize = options.fontSize || '16px';
+      this.visible = true;
+      setTimeout(() => {
+        this.visible = false;
+      }, this.duration);
+    }
+  }
+};
+</script>
+
+<style>
+.custom-toast {
+  position: fixed;
+  top: 50%;
+  left: 50%;
+  transform: translate(-50%, -50%);
+  padding: 12px 24px;
+  background-color: rgba(0, 0, 0, 0.7);
+  color: white;
+  border-radius: 4px;
+  font-size: 16px; /* 默认字体大小 */
+  z-index: 9999;
+}
+</style>

+ 47 - 8
pages/shopping/cart.vue

@@ -65,16 +65,18 @@
 				<view class="btn" @click="submit">结算</view>
 			</view>
 		</view>
-		
+		<CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
 <script>
-	import {getCarts,cartNum,delCart} from '@/api/product'
+	import {getCarts,cartNum,delCart,checkCartPurchaseLimit} from '@/api/product'
 	import likeProduct from '@/components/likeProduct.vue'
+  import {CustomToast} from '@/components/custom-toast.vue';
 	export default {
 		components: {
-			likeProduct
+			likeProduct,CustomToast
 		},	
 		data() {
 			return {
@@ -202,10 +204,14 @@
 								delete item._originalCartNum;
 							}
 							this.$forceUpdate(); // 强制更新视图
-							uni.showToast({
-								icon:'none',
-								title: res.msg,
-							});
+              this.$refs.customToast.show({
+                title: res.msg || '该商品限购,目前剩余可购买数量不足',
+                duration: 2000
+              });
+							// uni.showToast({
+							// 	icon:'none',
+							// 	title: ,
+							// });
 						}
 					},
 					rej => {
@@ -328,7 +334,7 @@
 				this.changeCartNum(item, targetNum, originalNum)
 			},
 			// 结算
-			submit() {
+			async submit() {
 				var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
 				  return ele.id
 				});
@@ -339,6 +345,39 @@
 					});
 					return;
 				}
+				
+				// 获取选中的商品信息,用于限购校验
+				var selectedProducts = this.carts.filter(ele => ele.checked==true).map(ele => {
+					return {
+						productId: ele.productId,
+						num: ele.cartNum
+					}
+				});
+				
+				// 结算前先校验限购
+				try {
+					const res = await checkCartPurchaseLimit({ products: selectedProducts });
+					if (res.code !== 200) {
+            this.$refs.customToast.show({
+              title: res.msg || '商品限购校验失败',
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: res.msg || '商品限购校验失败'
+						// });
+						return;
+					}
+				} catch (error) {
+					console.error('检查限购失败:', error);
+					uni.showToast({
+						icon: 'none',
+						title: '检查限购失败,请稍后重试'
+					});
+					return;
+				}
+				
+				// 限购检查通过,进行跳转
 				uni.navigateTo({
 					url: './confirmOrder?type=cart&cartIds='+selectCarts.toString()
 				})

+ 47 - 22
pages/shopping/productDetails.vue

@@ -189,11 +189,15 @@
 			<image src="../../static/logo.png"></image>
 			<text class="text">加载中...</text>
 		</view>
+    <CustomToast ref="customToast">
+    </CustomToast>
 		<!-- <u-modal :show="showModal" title="温馨提示" content="处方药须凭处方在药师指导下购买和使用" @confirm="hideModal()"></u-modal> -->
 	</view>
 </template>
 
 <script>
+import {CustomToast} from '@/components/custom-toast.vue';
+
 	import {
 		getDicts
 	} from '@/api/index'
@@ -209,7 +213,8 @@
 	export default {
 		components: {
 			item: {},
-			popupBottom
+			popupBottom,
+      CustomToast
 		},
 		data() {
 			return {
@@ -358,18 +363,26 @@
 				if (this.remainingPurchaseLimit !== null && typeof this.remainingPurchaseLimit === 'number') {
 					// 如果限购数量为0,提示库存不足
 					if (this.remainingPurchaseLimit === 0) {
-						uni.showToast({
-							icon: 'none',
-							title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
-						});
+            this.$refs.customToast.show({
+              title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
+						// });
 						return;
 					}
 					// 如果购买数量超过限购数量,提示
 					if (this.specNum > this.remainingPurchaseLimit) {
-						uni.showToast({
-							icon: 'none',
-							title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
-						});
+            this.$refs.customToast.show({
+              title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
+						// });
 						return;
 					}
 				}
@@ -582,10 +595,14 @@
 				// 检查限购数量
 				if (this.remainingPurchaseLimit !== null && typeof this.remainingPurchaseLimit === 'number' && this.specNum > this.remainingPurchaseLimit) {
 					this.specNum = this.remainingPurchaseLimit;
-					uni.showToast({
-						icon: 'none',
-						title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
-					});
+          this.$refs.customToast.show({
+            title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+            duration: 2000
+          });
+					// uni.showToast({
+					// 	icon: 'none',
+					// 	title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+					// });
 				}
 			},
 			// 数量减法
@@ -600,10 +617,14 @@
 				// 检查限购数量
 				if (this.remainingPurchaseLimit !== null && typeof this.remainingPurchaseLimit === 'number' && this.specNum > this.remainingPurchaseLimit) {
 					this.specNum = this.remainingPurchaseLimit;
-					uni.showToast({
-						icon: 'none',
-						title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
-					});
+          this.$refs.customToast.show({
+            title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+            duration: 2000
+          });
+					// uni.showToast({
+					// 	icon: 'none',
+					// 	title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+					// });
 				}
 			},
 			// 数量加法
@@ -615,10 +636,14 @@
 				// 检查限购数量
 				if (this.remainingPurchaseLimit !== null && typeof this.remainingPurchaseLimit === 'number' && this.specNum > this.remainingPurchaseLimit) {
 					this.specNum = this.remainingPurchaseLimit;
-					uni.showToast({
-						icon: 'none',
-						title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
-					});
+          this.$refs.customToast.show({
+            title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+            duration: 2000
+          });
+					// uni.showToast({
+					// 	icon: 'none',
+					// 	title: "该商品限购:" + this.remainingPurchaseLimit + "次,已达购买上限",
+					// });
 				}
 			},
 			// 确定选择该规格
@@ -930,7 +955,7 @@
 				}
 				
 				.limit-text {
-					font-size: 24upx;
+					font-size: 32rpx;
 					font-family: PingFang SC;
 					font-weight: 500;
 					color: #FF6633;

+ 13 - 5
pages_course/living.vue

@@ -685,10 +685,13 @@
 							</view>
 						</view>
 		</view>
+    <CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
 <script>
+import {CustomToast} from '@/components/custom-toast.vue';
 	import LikeButton from '@/pages_course/components/like.vue';
 	import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue';
 	import CryptoJS from 'crypto-js';
@@ -754,7 +757,8 @@
 	export default {
 		components: {
 			ThreeItemSwiper,
-			LikeButton
+			LikeButton,
+      CustomToast
 		},
 		data() {
 			return {
@@ -4647,10 +4651,14 @@
 				try {
 					const res = await checkPurchaseLimit({ productId: productId });
 					if (res.code !== 200) {
-						uni.showToast({
-							icon: 'none',
-							title: res.msg || '该商品限购,目前剩余可购买数量不足'
-						});
+            this.$refs.customToast.show({
+              title: res.msg || '该商品限购,目前剩余可购买数量不足',
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: res.msg || '该商品限购,目前剩余可购买数量不足'
+						// });
 						return;
 					}
 				} catch (error) {

+ 38 - 18
pages_shopping/live/goods.vue

@@ -127,6 +127,8 @@
 				<view class="sub-btn" @click="submit">确定</view>
 			</view>
 		</popupBottom>
+    <CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
@@ -139,9 +141,11 @@
 	} from "@/api/order.js"
 	import popupBottom from '@/components/px-popup-bottom/px-popup-bottom.vue'
 
+  import {CustomToast} from '@/components/custom-toast.vue';
+
 	export default {
 		components: {
-			popupBottom
+			popupBottom,CustomToast
 		},
 		data() {
 			return {
@@ -195,18 +199,26 @@
 				if (this.remainingPurchaseLimit !== null && typeof this.remainingPurchaseLimit === 'number') {
 					// 如果限购数量为0,提示库存不足
 					if (this.remainingPurchaseLimit === 0) {
-						uni.showToast({
-							icon: 'none',
-							title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
-						});
+            this.$refs.customToast.show({
+              title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: "该商品限购:" + this.purchaseLimit +",已达到购买上限",
+						// });
 						return;
 					}
 					// 如果购买数量超过限购数量,提示
 					if (this.totalNum > this.remainingPurchaseLimit) {
-						uni.showToast({
-							icon: 'none',
-							title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
-						});
+            this.$refs.customToast.show({
+              title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
+              duration: 2000
+            });
+						// uni.showToast({
+						// 	icon: 'none',
+						// 	title: "购买数量不能超过限购数量:" + this.remainingPurchaseLimit,
+						// });
 						return;
 					}
 				}
@@ -374,10 +386,14 @@
 				}
 				if(this.totalNum > this.remainingPurchaseLimit && this.remainingPurchaseLimit!==null){
 					this.totalNum = this.remainingPurchaseLimit;
-					uni.showToast({
-						icon: 'none',
-						title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
-					});
+          this.$refs.customToast.show({
+            title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
+            duration: 2000
+          });
+					// uni.showToast({
+					// 	icon: 'none',
+					// 	title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
+					// });
 				}
 			},
 			// 数量减法
@@ -398,10 +414,14 @@
 				}
 				if(this.totalNum > this.remainingPurchaseLimit && this.remainingPurchaseLimit!==null){
 					this.totalNum = this.remainingPurchaseLimit;
-					uni.showToast({
-						icon: 'none',
-						title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
-					});
+          this.$refs.customToast.show({
+            title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
+            duration: 2000
+          });
+					// uni.showToast({
+					// 	icon: 'none',
+					// 	title: "该商品限购:"+this.remainingPurchaseLimit+"次"+",已达购买上限",
+					// });
 				}
 			}
 		}
@@ -583,7 +603,7 @@
 				margin-top: 7rpx;
 			}
 			.limit-info {
-				font-size: 24rpx;
+				font-size: 32rpx;
 				font-weight: 500;
 				color: #FF6633;
 				margin-top: 16rpx;

+ 50 - 2
pages_shopping/live/storeOrderDetail.vue

@@ -253,17 +253,24 @@
 				@click="payRemain()">支付尾款</view>
 			<view class="btn pay" v-if="order.status==2" @click="finish()">确认收货</view>
 		</view>
+    <CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
 <script>
+import {CustomToast} from '@/components/custom-toast.vue';
 	import {
 		getMyStoreOrderById,
 		cancelOrder,
 		finishOrder
 	} from '@/api/order.js'
+	import {checkPurchaseLimit} from '@/api/product'
 	export default {
-		data() {
+    components: {
+      CustomToast
+    },
+    data() {
 			return {
 				liveId:null,
 				product: {},
@@ -412,7 +419,48 @@
 					}
 				});
 			},
-			pay() {
+			async pay() {
+				// 直播订单,使用productId校验限购
+				let productId = null;
+				if(this.order.productId){
+					productId = this.order.productId;
+				} else if(this.product && this.product.productId){
+					productId = this.product.productId;
+				} else if(this.order.itemJson){
+					try {
+						const itemJson = JSON.parse(this.order.itemJson);
+						productId = itemJson.productId;
+					} catch(e) {
+						console.error('解析 itemJson 失败:', e);
+					}
+				}
+				
+				// 如果获取到 productId,检查限购
+				if(productId){
+					try {
+						const res = await checkPurchaseLimit({ productId: productId });
+						if (res.code !== 200) {
+              this.$refs.customToast.show({
+                title: res.msg || '该商品限购,目前剩余可购买数量不足',
+                duration: 2000
+              });
+							// uni.showToast({
+							// 	icon: 'none',
+							// 	title: res.msg || '该商品限购,目前剩余可购买数量不足'
+							// });
+							return;
+						}
+					} catch (error) {
+						console.error('检查限购失败:', error);
+						uni.showToast({
+							icon: 'none',
+							title: '检查限购失败,请稍后重试'
+						});
+						return;
+					}
+				}
+				
+				// 限购检查通过,进行支付跳转
 				uni.navigateTo({
 					url: `./paymentOrder?orderList=${encodeURIComponent(JSON.stringify(this.order))}`
 					// url: './paymentOrder?orderId=' + this.order.orderId

+ 57 - 35
pages_user/user/storeOrder.vue

@@ -167,17 +167,23 @@
 				</view>
 			</view>
 		</mescroll-body>
+    <CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
 <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";
+	import {checkPurchaseLimit,checkOrderPurchaseLimit} from '@/api/product';
+  import {CustomToast} from '@/components/custom-toast.vue';
+  import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
 	export default {
-		mixins: [MescrollMixin], 
-		data() {
+		mixins: [MescrollMixin],
+    components: {
+      CustomToast
+    },
+    data() {
 			return {
 				searchKey:"",
 				status:0,
@@ -360,10 +366,9 @@
 					});
 				}
 				else{
-					// 检查限购
-					let productId = null;
 					if(item.orderType==2){
-						// 直播订单,从 item 中获取 productId
+						// 直播订单,限购逻辑不变,使用原有逻辑
+						let productId = null;
 						if(item.productId){
 							productId = item.productId;
 						} else if(item.itemJson){
@@ -374,47 +379,64 @@
 								console.error('解析 itemJson 失败:', e);
 							}
 						}
-					} else {
-						// 普通订单,从 items 中获取第一个商品的 productId
-						if(item.items && item.items.length > 0 && item.items[0].jsonInfo){
+						
+						// 如果获取到 productId,检查限购
+						if(productId){
 							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) {
+								const res = await checkPurchaseLimit({ productId: productId });
+								if (res.code !== 200) {
+                  this.$refs.customToast.show({
+                    title: res.msg || '该商品限购,目前剩余可购买数量不足',
+                    duration: 2000
+                  });
+									// uni.showToast({
+									// 	icon: 'none',
+									// 	title: res.msg || '该商品限购,目前剩余可购买数量不足'
+									// });
+									return;
+								}
+							} catch (error) {
+								console.error('检查限购失败:', error);
 								uni.showToast({
 									icon: 'none',
-									title: res.msg || '该商品限购,目前剩余可购买数量不足'
+									title: '检查限购失败,请稍后重试'
 								});
 								return;
 							}
-						} catch (error) {
-							console.error('检查限购失败:', error);
-							uni.showToast({
-								icon: 'none',
-								title: '检查限购失败,请稍后重试'
-							});
-							return;
 						}
-					}
-					
-					// 限购检查通过,进行支付跳转
-					if(item.orderType==2){
+						
 						// 支付
 						console.log("去支付", item)
 						uni.navigateTo({
 							url: `/pages_shopping/live/paymentOrder?orderList=${encodeURIComponent(JSON.stringify(item))}`
 						})
 					}else{
+						// 商城订单,使用新接口根据orderCode校验
+						if(item.orderCode){
+							try {
+								const res = await checkOrderPurchaseLimit({ orderCode: item.orderCode });
+								if (res.code !== 200) {
+                  this.$refs.customToast.show({
+                    title: res.msg || '订单商品限购校验失败',
+                    duration: 2000
+                  });
+									// uni.showToast({
+									// 	icon: 'none',
+									// 	title: res.msg || '订单商品限购校验失败'
+									// });
+									return;
+								}
+							} catch (error) {
+								console.error('检查限购失败:', error);
+								uni.showToast({
+									icon: 'none',
+									title: '检查限购失败,请稍后重试'
+								});
+								return;
+							}
+						}
+						
+						// 限购检查通过,进行支付跳转
 						uni.navigateTo({
 							url: '/pages/shopping/paymentOrder?orderId='+item.id
 						})

+ 34 - 1
pages_user/user/storeOrderDetail.vue

@@ -255,12 +255,19 @@
 			<view class="btn pay" v-if="order.status==2&&order.payType!=1&&order.isPayRemain==0&&order.deliverySn=='SF'" @click="payRemain()">支付尾款</view>
 			<view class="btn pay" v-if="order.status==2" @click="finish()">确认收货</view>
 		</view>
+    <CustomToast ref="customToast">
+    </CustomToast>
 	</view>
 </template>
 
 <script>
 	import {getMyStoreOrderById,cancelOrder,express,finishOrder,orderBindUser} from '@/api/storeOrder'
+	import {checkOrderPurchaseLimit} from '@/api/product'
+  import {CustomToast} from '@/components/custom-toast.vue';
 	export default {
+    components: {
+      CustomToast
+    },
 		data() {
 			return {
 				isAfterSales:0,
@@ -425,13 +432,39 @@
 				    }
 				});
 			},
-			pay() {
+			async pay() {
 				if(this.order.isPrescribe==1 && this.order.prescribeId==null){
 					uni.navigateTo({
 						url:"/pages/shopping/prescribe?orderId="+this.order.id
 					});
 				}
 				else{
+					// 商城订单,使用orderCode校验限购
+					if(this.order.orderCode){
+						try {
+							const res = await checkOrderPurchaseLimit({ orderCode: this.order.orderCode });
+							if (res.code !== 200) {
+                this.$refs.customToast.show({
+                  title: res.msg || '订单商品限购校验失败',
+                  duration: 2000
+                });
+								// uni.showToast({
+								// 	icon: 'none',
+								// 	title: res.msg || '订单商品限购校验失败'
+								// });
+								return;
+							}
+						} catch (error) {
+							console.error('检查限购失败:', error);
+							uni.showToast({
+								icon: 'none',
+								title: '检查限购失败,请稍后重试'
+							});
+							return;
+						}
+					}
+					
+					// 限购检查通过,进行支付跳转
 					uni.navigateTo({
 						url: '/pages/shopping/paymentOrder?orderId='+this.order.id
 					})