C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

150 rindas
4.2 KiB

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