Ver código fonte

commit -m 修改购买优惠券

zhengjinyi 3 anos atrás
pai
commit
80685bcc26

+ 26 - 12
components/cm-module/cart-components/index.vue

@@ -1428,17 +1428,6 @@ export default {
 					console.log('获取优惠券列表失败')
 				})
 		},
-		toPayCoupon(coupon){
-			// 点击购买优惠券,友盟埋点收集购买优惠券
-			if (process.env.NODE_ENV != 'development') {
-				this.$uma.trackEvent('Um_Event_cartCouponBuy', {
-					Um_Key_PageName: '机构购物车',
-					Um_Key_EvenName: '购买优惠券',
-					Um_Key_CouponId: `${coupon.couponId}`,
-				})
-			}
-			this.MiniWxPayFor(coupon)
-		},
 		receiveCoupon(coupon) {
 			// 点击优惠券领取按钮,友盟埋点收集领取优惠券
 			if (process.env.NODE_ENV != 'development') {
@@ -1465,12 +1454,37 @@ export default {
 					this.$util.msg(error.msg, 2000)
 				})
 		},
-		async MiniWxPayFor(coupon){
+		toPayCoupon(coupon){
+			// 点击购买优惠券,友盟埋点收集购买优惠券
+			if (process.env.NODE_ENV != 'development') {
+				this.$uma.trackEvent('Um_Event_cartCouponBuy', {
+					Um_Key_PageName: '机构购物车',
+					Um_Key_EvenName: '购买优惠券',
+					Um_Key_CouponId: `${coupon.couponId}`,
+				})
+			}
+			this.createCouponRecord(coupon)
+		},
+		createCouponRecord(coupon){
+			// 生成购买优惠券记录Id
+			this.PayService.WeChatCouponRecord({
+				userId: this.userId,
+				couponId: coupon.couponId
+			})
+			.then(response => {
+				this.MiniWxPayFor(coupon,response.data.couponRecordId)
+			})
+			.catch(error => {
+				console.log(error)
+			})
+		},
+		async MiniWxPayFor(coupon,couponRecordId){
 			const wechatcode = await authorize.getCode('weixin')
 			this.PayService.WeChatCouponMiniWxPay(
 				{
 					userId: this.userId,
 					couponId: coupon.couponId,
+					couponRecordId:couponRecordId,
 					payWay: 'WEIXIN',
 					code: wechatcode,
 					source: 1 //支付来源 1 小程序 2 WWW

+ 2 - 2
main.js

@@ -5,7 +5,7 @@ import './services/index.js'
 import * as Api from '@/common/config/caimeiApi.js'
 import * as Regs from '@/common/config/common.js'
 // 友盟
-import Uma from './plugins/uma'
+// import Uma from './plugins/uma'
 
 // 公共组件 全局组件
 import { msg, modal, prePage, boundingClientRect } from './utils/util'
@@ -42,7 +42,7 @@ Vue.prototype.$Static = 'https://static.caimei365.com/app/img/'
 App.mpType = 'app'
 
 // 使用插件
-Vue.use(Uma)
+// Vue.use(Uma)
 
 const app = new Vue({
     ...App

+ 26 - 12
pages/goods/product.vue

@@ -974,17 +974,6 @@ export default {
 					console.log('获取购物车数量失败')
 				})
 		},
-		toPayCoupon(coupon) {
-			// 点击购买优惠券,友盟埋点收集购买优惠券
-			if (process.env.NODE_ENV != 'development') {
-				this.$uma.trackEvent('Um_Event_productCouponBuy', {
-					Um_Key_PageName: '商品详情',
-					Um_Key_EvenName: '购买优惠券',
-					Um_Key_CouponId: `${coupon.couponId}`,
-				})
-			}
-			this.MiniWxPayFor(coupon)
-		},
 		receiveCoupon(coupon) {
 			// 点击优惠券领取按钮,友盟埋点收集领取优惠券
 			if (process.env.NODE_ENV != 'development') {
@@ -1011,12 +1000,37 @@ export default {
 					this.$util.msg(error.msg, 2000)
 				})
 		},
-		async MiniWxPayFor(coupon){
+		toPayCoupon(coupon) {
+			// 点击购买优惠券,友盟埋点收集购买优惠券
+			if (process.env.NODE_ENV != 'development') {
+				this.$uma.trackEvent('Um_Event_productCouponBuy', {
+					Um_Key_PageName: '商品详情',
+					Um_Key_EvenName: '购买优惠券',
+					Um_Key_CouponId: `${coupon.couponId}`,
+				})
+			}
+			this.createCouponRecord(coupon)
+		},
+		createCouponRecord(coupon){
+			// 生成购买优惠券记录Id
+			this.PayService.WeChatCouponRecord({
+				userId: this.userId,
+				couponId: coupon.couponId
+			})
+			.then(response => {
+				this.MiniWxPayFor(coupon,response.data.couponRecordId)
+			})
+			.catch(error => {
+				console.log(error)
+			})
+		},
+		async MiniWxPayFor(coupon,couponRecordId){
 			const wechatcode = await authorize.getCode('weixin')
 			this.PayService.WeChatCouponMiniWxPay(
 				{
 					userId: this.userId,
 					couponId: coupon.couponId,
+					couponRecordId:couponRecordId,
 					payWay: 'WEIXIN',
 					code: wechatcode,
 					source: 1 //支付来源 1 小程序 2 WWW

+ 17 - 3
pages/seller/cart/coupon-share.vue

@@ -36,7 +36,7 @@
 				</view>
 			</view>
 			<view class="container-button">
-				<view class="button" @click="MiniWxPayFor">¥{{ coupon.moneyCouponPrice }}购买</view>
+				<view class="button" @click="createCouponRecord">¥{{ coupon.moneyCouponPrice }}购买</view>
 			</view>
 		</view>
 	</view>
@@ -101,11 +101,25 @@ export default {
 					console.log('初始化优惠券信息异常~')
 				})
 		},
-		async MiniWxPayFor() {
+		createCouponRecord(){
+			// 生成购买优惠券记录Id
+			this.PayService.WeChatCouponRecord({
+				userId: this.userId,
+				couponId: this.couponId
+			})
+			.then(response => {
+				this.MiniWxPayFor(response.data.couponRecordId)
+			})
+			.catch(error => {
+				console.log(error)
+			})
+		},
+		async MiniWxPayFor(couponRecordId) {
 			const wechatcode = await authorize.getCode('weixin')
 			this.PayService.WeChatCouponMiniWxPay({
 				userId: this.userId,
 				couponId: this.couponId,
+				couponRecordId:couponRecordId,
 				payWay: 'WEIXIN',
 				code: wechatcode,
 				source: 1 //支付来源 1 小程序 2 WWW
@@ -136,7 +150,7 @@ export default {
 				signType: data.signType,
 				paySign: data.paySign,
 				success: function(res) {
-					wx.reLaunch({ url: '/pages/tabBar/user/user' })
+					wx.reLaunch({ url: '/pages/tabBar/home/index' })
 				},
 				fail: function(res) {
 					self.$util.msg('用户取消支付~')

+ 34 - 20
pages/user/coupon/coupon-activity.vue

@@ -222,25 +222,6 @@ export default {
 					this.$util.msg(error.msg, 2000)
 				})
 		},
-		toPayCoupon(coupon) {
-			// 点击购买优惠券,友盟埋点收集购买优惠券
-			if (process.env.NODE_ENV != 'development') {
-				this.$uma.trackEvent('Um_Event_meibohuiCouponBuy', {
-					Um_Key_PageName: '美博会优惠券活动页',
-					Um_Key_EvenName: '购买优惠券',
-					Um_Key_CouponId: `${coupon.couponId}`,
-				})
-			}
-			if (this.hasLogin) {
-				if (this.userIdentity === 1 || this.userIdentity === 3) {
-					this.$util.msg('您的身份暂不支持领取优惠券', 2000)
-					return
-				}
-				this.MiniWxPayFor(coupon)
-			} else {
-				this.$api.navigateTo('/pages/login/login')
-			}
-		},
 		receiveCoupon(coupon) {
 			// 点击优惠券领取按钮,友盟埋点收集领取优惠券
 			if (process.env.NODE_ENV != 'development') {
@@ -311,11 +292,44 @@ export default {
 					break
 			}
 		},
-		async MiniWxPayFor(coupon) {
+		toPayCoupon(coupon) {
+			// 点击购买优惠券,友盟埋点收集购买优惠券
+			if (process.env.NODE_ENV != 'development') {
+				this.$uma.trackEvent('Um_Event_meibohuiCouponBuy', {
+					Um_Key_PageName: '美博会优惠券活动页',
+					Um_Key_EvenName: '购买优惠券',
+					Um_Key_CouponId: `${coupon.couponId}`,
+				})
+			}
+			if (this.hasLogin) {
+				if (this.userIdentity === 1 || this.userIdentity === 3) {
+					this.$util.msg('您的身份暂不支持领取优惠券', 2000)
+					return
+				}
+				this.createCouponRecord(coupon)
+			} else {
+				this.$api.navigateTo('/pages/login/login')
+			}
+		},
+		createCouponRecord(coupon){
+			// 生成购买优惠券记录Id
+			this.PayService.WeChatCouponRecord({
+				userId: this.listQuery.userId,
+				couponId: coupon.couponId
+			})
+			.then(response => {
+				this.MiniWxPayFor(coupon,response.data.couponRecordId)
+			})
+			.catch(error => {
+				console.log(error)
+			})
+		},
+		async MiniWxPayFor(coupon,couponRecordId) {
 			const wechatcode = await authorize.getCode('weixin')
 			this.PayService.WeChatCouponMiniWxPay({
 				userId: this.listQuery.userId,
 				couponId: coupon.couponId,
+				couponRecordId:couponRecordId,
 				payWay: 'WEIXIN',
 				code: wechatcode,
 				source: 1 //支付来源 1 小程序 2 WWW

+ 51 - 36
pages/user/coupon/coupon-collection.vue

@@ -204,25 +204,6 @@ export default {
 					this.$util.msg(error.msg, 2000)
 				})
 		},
-		toPayCoupon(coupon) {
-			// 点击购买优惠券,友盟埋点收集购买优惠券
-			if (process.env.NODE_ENV != 'development') {
-				this.$uma.trackEvent('Um_Event_userCouponCollectionBuy', {
-					Um_Key_PageName: '领券中心',
-					Um_Key_EvenName: '购买优惠券',
-					Um_Key_CouponId: `${coupon.couponId}`,
-				})
-			}
-			if (this.hasLogin) {
-				if (this.userIdentity === 1 || this.userIdentity === 3) {
-					this.$util.msg('您的身份暂不支持领取优惠券', 2000)
-					return
-				}
-				this.MiniWxPayFor(coupon)
-			} else {
-				this.$api.navigateTo('/pages/login/login')
-			}
-		},
 		receiveCoupon(coupon) {
 			// 点击优惠券领取按钮,友盟埋点收集领取优惠券
 			if (process.env.NODE_ENV != 'development') {
@@ -289,31 +270,65 @@ export default {
 					break
 			}
 		},
-		async MiniWxPayFor(coupon) {
+		toPayCoupon(coupon) {
+			// 点击购买优惠券,友盟埋点收集购买优惠券
+			if (process.env.NODE_ENV != 'development') {
+				this.$uma.trackEvent('Um_Event_userCouponCollectionBuy', {
+					Um_Key_PageName: '领券中心',
+					Um_Key_EvenName: '购买优惠券',
+					Um_Key_CouponId: `${coupon.couponId}`,
+				})
+			}
+			if (this.hasLogin) {
+				if (this.userIdentity === 1 || this.userIdentity === 3) {
+					this.$util.msg('您的身份暂不支持领取优惠券', 2000)
+					return
+				}
+				this.createCouponRecord(coupon)
+				
+			} else {
+				this.$api.navigateTo('/pages/login/login')
+			}
+		},
+		createCouponRecord(coupon){
+			// 生成购买优惠券记录Id
+			this.PayService.WeChatCouponRecord({
+				userId: this.listQuery.userId,
+				couponId: coupon.couponId
+			})
+			.then(response => {
+				this.MiniWxPayFor(coupon,response.data.couponRecordId)
+			})
+			.catch(error => {
+				console.log(error)
+			})
+		},
+		async MiniWxPayFor(coupon,couponRecordId) {
 			const wechatcode = await authorize.getCode('weixin')
 			this.PayService.WeChatCouponMiniWxPay({
 				userId: this.listQuery.userId,
 				couponId: coupon.couponId,
+				couponRecordId:couponRecordId,
 				payWay: 'WEIXIN',
 				code: wechatcode,
 				source: 1 //支付来源 1 小程序 2 WWW
 			})
-				.then(response => {
-					// 友盟埋点收集微信支付
-					if (process.env.NODE_ENV != 'development') {
-						this.$uma.trackEvent('Um_Event_userCouponCollectionPay', {
-							Um_Key_PageName: '领券中心',
-							Um_Key_SourcePage: '线上支付优惠券',
-							Um_Key_CouponId: `${coupon.couponId}`,
-							Um_Key_userId: `${this.userId}`
-						})
-					}
-					let PayInfo = JSON.parse(response.data.data.payInfo)
-					this.WxRequestPayment(PayInfo)
-				})
-				.catch(error => {
-					this.$util.msg(error.msg, 2000)
-				})
+			.then(response => {
+				// 友盟埋点收集微信支付
+				if (process.env.NODE_ENV != 'development') {
+					this.$uma.trackEvent('Um_Event_userCouponCollectionPay', {
+						Um_Key_PageName: '领券中心',
+						Um_Key_SourcePage: '线上支付优惠券',
+						Um_Key_CouponId: `${coupon.couponId}`,
+						Um_Key_userId: `${this.userId}`
+					})
+				}
+				let PayInfo = JSON.parse(response.data.data.payInfo)
+				this.WxRequestPayment(PayInfo)
+			})
+			.catch(error => {
+				this.$util.msg(error.msg, 2000)
+			})
 		},
 		WxRequestPayment(data) {
 			let self = this

+ 12 - 0
services/pay.service.js

@@ -56,6 +56,18 @@ export default class PayService {
             loadText:'请求支付中...'  
         })
     }
+    /**
+	 *购买优惠券生成记录Id
+	 *@param  userId  用户Id
+	 *@param  couponId  优惠券Id
+	 */
+    WeChatCouponRecord (data = {}) {
+        return this.AjaxService.post({ 
+            url:'/order/pay/coupon/record', 
+            data, 
+            isLoading: false ,
+        })
+    }
     /**
 	 *生成支付链接
 	 *@param  unpaidAmount 本次待付款金额