Просмотр исходного кода

运费计算启用新接口(从微信同城配送获取),弃用原有实现

shizhongqi 11 месяцев назад
Родитель
Сommit
b42a7c969f

+ 4 - 0
mallApp/src/api/order/index.js

@@ -1,5 +1,9 @@
 import https from '@/plugins/luch-request_0.0.7/request'
 
+export const newFreight = data => {
+	return https.post("/order/new-freight", data);
+};
+
 export const freight = data => {
 	return https.get("/order/freight", data);
 };

+ 0 - 1
mallApp/src/components/RichMediaViewer/index.vue

@@ -229,7 +229,6 @@ export default {
 
     // 初始化内容列表,添加懒加载状态
     initializeContentList(content) {
-      console.log('initializeContentList -- content: ', content)
       return content.map(item => {
         const newItem = { ...item }
 

+ 41 - 13
mallApp/src/pages/billing/affirmGhs.vue

@@ -135,7 +135,7 @@
 <script>
 import TuiListCell from "@/components/plugin/list-cell";
 import productMins from "@/mixins/cgProduct";
-import { buyItem,freight } from "@/api/order"
+import { buyItem,freight,newFreight } from "@/api/order"
 import { currentInfo } from "@/api/user"
 // import { mapActions, mapGetters } from "vuex";
 export default {
@@ -164,12 +164,7 @@ export default {
 				showAddress:'',
 				hasMap:0
 			},
-			userInfo:{
-				lat:'',
-				long:'',
-				fullAddress:'',
-				showAddress:''
-			},
+			userInfo:{},
       		timeOptions: [
 				['00', '01', '02','03','04','05','06','07','08','09','10','11','12','13', '14','15','16','17','18','19','20','21','22','23'],
 				['00', '05', '10','15','20','25','30','35','40','45','50','55']
@@ -239,8 +234,9 @@ export default {
 					that.userInfo = res.data.info
 					that.form.province = that.userInfo.province
 					that.form.city = that.userInfo.city
-					that.form.floor = that.userInfo.floor
+					that.form.dist = that.userInfo.dist
 					that.form.address = that.userInfo.address
+					that.form.floor = that.userInfo.floor
 					that.form.long = that.userInfo.long
 					that.form.lat = that.userInfo.lat
 					that.form.showAddress = that.userInfo.showAddress
@@ -280,9 +276,29 @@ export default {
 				that.form.sendCost = 0
 				return
 			}
-			freight({weight:weight,lat:that.userInfo.lat,long:that.userInfo.long}).then(res => {
+			// freight({weight:weight,lat:that.userInfo.lat,long:that.userInfo.long}).then(res => {
+			// 	if(res.code == 1){
+			// 		that.form.sendCost = res.data.fee?parseFloat(Number(res.data.fee)):0
+			// 	}
+			// }).catch(()=>{});
+			// newFreight
+			let packageNum = that.allCountFun && that.allCountFun.bigLength ? Number(that.allCountFun.bigLength) : 1
+			let cargoName = '花材'
+			let newFreightParams = {
+				cargo_name: cargoName,
+				price: that.allPriceFun,
+				weight: weight,
+				package_num: packageNum,
+				user_lng: that.userInfo.long,
+				user_lat: that.userInfo.lat,
+				user_name: that.userInfo.name || that.userInfo.realName || '',
+				user_phone: that.userInfo.mobile || that.userInfo.phone || '',
+				user_address: that.userInfo.province + that.userInfo.city + that.userInfo.dist + that.userInfo.address + that.userInfo.floor
+			}
+			newFreight(newFreightParams).then(res => {
+				console.log('newFreight',res)
 				if(res.code == 1){
-					that.form.sendCost = res.data.fee?parseFloat(Number(res.data.fee)):0
+					that.form.sendCost = res.data.est_fee?parseFloat(Number(res.data.est_fee/100)):0
 				}
 			}).catch(()=>{});
 		},
@@ -307,12 +323,24 @@ export default {
 			uni.showLoading({mask:true})
 			buyItem(params).then(res => {
 				uni.hideLoading()
-				this.removeMemory()
 				if(res.code && res.code == 1){
 					let account = this.option.account ? this.option.account : 0
-					this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
+					let totalPrice = Number(res.data.totalPrice) + Number(this.form.sendCost)
+					
+					if (Math.abs(totalPrice - this.modifyPrice) < 0.001) {
+						res.data.totalPrice = totalPrice
+					}else{
+						this.$msg('运费计算错误')
+						return
+					}
+					this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data, hdId: hdId, account: account } })
 				}
-			});
+				this.removeMemory()
+			}).catch((e)=>{
+				console.log('buyItem error: ', e)
+				uni.hideLoading()
+				this.removeMemory()
+			})
 		},
 		modifyItem() {
 			let account = this.option.account ? this.option.account : 0

+ 57 - 8
mallApp/src/pages/order/buy.vue

@@ -55,7 +55,7 @@ import AppDeliveryModule from "@/components/app-delivery";
 import AppListModule from "@/components/module/app-order-list2";
 import { getShopUser } from "@/utils/auth";
 import { getOrderShop } from "@/utils/config";
-import { createOrder } from "@/api/order";
+import { createOrder,newFreight } from "@/api/order";
 import { getUserDistance, getHasMap } from "@/api/express";
 export default {
   name: "buy",
@@ -70,6 +70,7 @@ export default {
       goodsInfo: {},
       form: {
         sendDistance:"",
+        sendCost: 0,
         goodsId: "",
         goodsStyleId: "",
         goodsNum: "",
@@ -133,12 +134,56 @@ export default {
       let long = ref.region.longitude;
       this.form.lat = lat
       this.form.long = long
-      getUserDistance({ lat: lat, lng: long }).then(res => {
-        const data = res.data || {}
-        this.freightPrice = data.fee?parseFloat(data.fee):0;
-        this.showDistance = data.showDistance || 0;
-        this.form.sendDistance = this.showDistance
-      });
+      // getUserDistance({ lat: lat, lng: long }).then(res => {
+      //   const data = res.data || {}
+      //   this.freightPrice = data.fee?parseFloat(data.fee):0;
+      //   this.showDistance = data.showDistance || 0;
+      //   this.form.sendDistance = this.showDistance
+      // });
+      // 当需要的数据都具备时,调用 newFreight 计算运费
+      try {
+        const deliveryForm = (ref && ref.form) ? ref.form : {};
+        const goodsInfo = this.goodsInfo || {};
+        const cargoName = goodsInfo.goodsName || goodsInfo.name || '商品';
+        const packageNum = Number(goodsInfo.buyNum || this.form.goodsNum || 0);
+        // 商品总重量 = 单件重量(kg,缺省视为 1) * 数量
+        const unitWeight = goodsInfo.weight ? Number(goodsInfo.weight) : 1; // 单件重量,缺省视为 1 公斤
+        const totalWeight = Number((unitWeight * packageNum).toFixed(2));
+        const userName = deliveryForm.receiveUserName || '';
+        const userPhone = deliveryForm.receiveMobile || '';
+
+        // 仅当必要数据都具备时才调用 newFreight
+        const hasLocation = lat && long;
+        const hasValidNum = packageNum > 0;
+        const hasValidWeight = totalWeight > 0;
+        const hasContact = !!userName && !!userPhone;
+        if (!(hasLocation && hasValidNum && hasValidWeight && hasContact)) {
+          return;
+        }
+
+        const params = {
+          cargo_name: cargoName,
+          price: this.goodsTotalPrice,
+          weight: totalWeight,
+          package_num: packageNum,
+          user_lng: long,
+          user_lat: lat,
+          user_name: userName,
+          user_phone: userPhone,
+          user_address: ref.region.province + ref.region.city + ref.region.dist + ref.region.address + ref.region.floor
+        };
+
+        newFreight(params).then(res => {
+          console.log('newFreight',res)
+          if (res && res.code == 1) {
+            const data = res.data || {};
+            this.freightPrice = data.est_fee ? parseFloat(Number(data.est_fee/100)) : 0;
+            this.showDistance = (data.distance/1000 || 0).toFixed(2);
+            this.form.sendDistance = (data.distance/1000 || 0).toFixed(2);
+            this.form.sendCost = this.freightPrice
+          }
+        }).catch(() => {});
+      } catch (e) {}
     },
     formSubmit() {
       this.createOrderFn()
@@ -174,7 +219,11 @@ export default {
       createOrder({...form, ...this.form,hdId:hdId}).then(res => {
         uni.hideLoading()
         uni.removeStorageSync("buyGoodsDetil")
-        this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
+        this.$util.pageTo({ 
+          url: "/pages/callback/pay",
+          type: 2,
+          query: { pageStatus: 1, ...res.data, hdId:hdId, account:account, freightPrice: this.freightPrice } 
+        })
       }).catch(()=>{
         uni.hideLoading()
       })