C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

102 lignes
2.9 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. wx.showLoading({
  21. title: '加载中...',
  22. })
  23. console.log(this.data.couponId)
  24. Common.orderSave(''+this.data.couponId)
  25. .then(res => {
  26. wx.hideLoading();
  27. console.log(res)
  28. if (res.data.code == 200) {
  29. return res;
  30. } else {
  31. wx.showToast({
  32. title: res.data.message,
  33. duration: 3000
  34. })
  35. }
  36. })
  37. .then(res => {
  38. orderId = '' + res.data.data.id;
  39. return Common.payOrderCreate(orderId)
  40. })
  41. .then(res =>{
  42. console.log(res)
  43. payOrderId = res.data.data.payOrderId;
  44. if (res.data.code == 200) {
  45. wx.requestPayment({
  46. timeStamp: res.data.data.timeStamp,
  47. nonceStr: res.data.data.nonceStr,
  48. package: res.data.data.package,
  49. signType: 'MD5',
  50. paySign: res.data.data.paySign,
  51. 'success': function (res) {
  52. Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功
  53. console.log(res);
  54. console.log('支付成功');
  55. wx.showToast({
  56. title: '购买成功',
  57. duration: 2500
  58. })
  59. wx.navigateBack({
  60. delta: 2
  61. })
  62. },
  63. 'fail': function (res) {
  64. Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
  65. console.log(res)
  66. console.log('支付失败');
  67. return;
  68. },
  69. 'complete': function (res) {
  70. console.log(res);
  71. console.log('支付完成');
  72. var url = that.data.url;
  73. console.log('get url', url)
  74. if (res.errMsg == 'requestPayment:ok') {
  75. wx.showModal({
  76. title: '提示',
  77. content: '支付成功'
  78. });
  79. if (url) {
  80. setTimeout(function () {
  81. wx.redirectTo({
  82. url: '/pages' + url
  83. });
  84. }, 2000)
  85. } else {
  86. setTimeout(() => {
  87. wx.navigateBack()
  88. }, 2000)
  89. }
  90. } else {
  91. wx.showModal({
  92. title: '错误提示',
  93. content: res.errMsg
  94. });
  95. }
  96. return;
  97. }
  98. })
  99. }
  100. })
  101. }
  102. })