C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.0 KiB

  1. let Common = require('../../../common/common.js')
  2. var app = getApp()
  3. Page({
  4. data: {
  5. list:{},
  6. couponId:null
  7. },
  8. onLoad(e) {
  9. console.log(e.id)
  10. Common.getCouponDetail(e.id)
  11. .then(res =>{
  12. console.log(res)
  13. this.setData({
  14. list: res.data.data,
  15. couponId: e.id
  16. })
  17. })
  18. },
  19. orderfunc() {
  20. /*
  21. var couponOrderId = '189631451703017472';
  22. var orderId = '189631451640102912';
  23. var payOrderId = '189631462532710400';
  24. var status = 1;
  25. var reason = '';
  26. Common.refundCouponOrder(couponOrderId)
  27. .then(res => {
  28. console.log(res);
  29. if (res.data.code == 200) {
  30. Common.refundOrderCreate(orderId, payOrderId)
  31. .then(res => {
  32. console.log(res);
  33. })
  34. } else {
  35. wx.showToast({
  36. title: res.data.message,
  37. duration: 3000
  38. })
  39. }
  40. })
  41. */
  42. /*
  43. Common.payOrderUpdate(orderId, payOrderId, status, reason)
  44. .then(res =>{
  45. console.log(res);
  46. })
  47. */
  48. wx.showLoading({
  49. title: '加载中...',
  50. })
  51. var couponId = '' + this.data.couponId;
  52. console.log("order coupon: " + couponId)
  53. Common.orderSave(couponId)
  54. .then(res => {
  55. console.log(res)
  56. if (res.data.code == 200) {
  57. var orderId = '' + res.data.data.id;
  58. if (res.data.data.payment > 0) {
  59. return Common.payOrderCreate(orderId)
  60. } else {
  61. Common.payOrderUpdate(orderId, "0", 1) // 支付成功
  62. .then(res =>{
  63. wx.showToast({
  64. title: res.data.message,
  65. duration: 3000
  66. })
  67. })
  68. }
  69. } else {
  70. wx.hideLoading();
  71. wx.showToast({
  72. title: res.data.message,
  73. duration: 3000
  74. })
  75. }
  76. })
  77. .then(res => {
  78. console.log(res)
  79. var payOrderId = '' + res.data.data.payOrderId;
  80. if (res.data.code == 200) {
  81. wx.requestPayment({
  82. timeStamp: res.data.data.timeStamp,
  83. nonceStr: res.data.data.nonceStr,
  84. package: res.data.data.package,
  85. signType: 'MD5',
  86. paySign: res.data.data.paySign,
  87. 'success': function(res) {
  88. Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功
  89. console.log(res);
  90. console.log('支付成功');
  91. wx.showToast({
  92. title: '购买成功',
  93. duration: 2500
  94. })
  95. wx.navigateBack({
  96. delta: 2
  97. })
  98. },
  99. 'fail': function(res) {
  100. Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
  101. console.log(res)
  102. console.log('支付失败');
  103. return;
  104. },
  105. 'complete': function(res) {
  106. console.log(res);
  107. console.log('支付完成');
  108. var url = that.data.url;
  109. console.log('get url', url)
  110. if (res.errMsg == 'requestPayment:ok') {
  111. wx.showModal({
  112. title: '提示',
  113. content: '支付成功'
  114. });
  115. if (url) {
  116. setTimeout(function () {
  117. wx.redirectTo({
  118. url: '/pages' + url
  119. });
  120. }, 2000)
  121. } else {
  122. setTimeout(() => {
  123. wx.navigateBack()
  124. }, 2000)
  125. }
  126. } else {
  127. wx.showModal({
  128. title: '错误提示',
  129. content: res.errMsg
  130. });
  131. }
  132. return;
  133. }
  134. })
  135. } else {
  136. wx.showModal({
  137. title: '错误提示',
  138. content: res.data.message
  139. });
  140. }
  141. })
  142. wx.hideLoading();
  143. }
  144. })