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.

190 rindas
5.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. 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. Common.payOrderCreate(res.data.data.id)
  30. .then(res =>{
  31. wx.requestPayment({
  32. timeStamp: res.data.data.timeStamp,
  33. nonceStr: res.data.data.nonceStr,
  34. package: res.data.data.package,
  35. signType: 'MD5',
  36. paySign: res.data.data.paySign,
  37. 'success': function (res) {
  38. console.log('支付成功');
  39. wx.showToast({
  40. title: '购买成功',
  41. duration: 2500
  42. })
  43. wx.navigateBack({
  44. delta: 2
  45. })
  46. },
  47. 'fail': function (res) {
  48. console.log('支付失败');
  49. console.log(res)
  50. return;
  51. },
  52. 'complete': function (res) {
  53. console.log('支付完成');
  54. var url = that.data.url;
  55. console.log('get url', url)
  56. if (res.errMsg == 'requestPayment:ok') {
  57. wx.showModal({
  58. title: '提示',
  59. content: '支付成功'
  60. });
  61. if (url) {
  62. setTimeout(function () {
  63. wx.redirectTo({
  64. url: '/pages' + url
  65. });
  66. }, 2000)
  67. } else {
  68. setTimeout(() => {
  69. wx.navigateBack()
  70. }, 2000)
  71. }
  72. }
  73. return;
  74. }
  75. })
  76. })
  77. } else {
  78. wx.showToast({
  79. title: res.data.message,
  80. duration: 3000
  81. })
  82. }
  83. })
  84. }
  85. let Common = require('../../../common/common.js')
  86. var app = getApp()
  87. Page({
  88. data: {
  89. list:{},
  90. couponId:null
  91. },
  92. onLoad(e) {
  93. console.log(e.id)
  94. Common.getCouponDetail(e.id)
  95. .then(res =>{
  96. console.log(res)
  97. this.setData({
  98. list: res.data.data,
  99. couponId: e.id
  100. })
  101. })
  102. },
  103. orderfunc(){
  104. var orderId = '';
  105. var payOrderId = '';
  106. wx.showLoading({
  107. title: '加载中...',
  108. })
  109. console.log(this.data.couponId)
  110. Common.orderSave(''+this.data.couponId)
  111. .then(res => {
  112. wx.hideLoading();
  113. console.log(res)
  114. if (res.data.code == 200) {
  115. return res;
  116. } else {
  117. wx.showToast({
  118. title: res.data.message,
  119. duration: 3000
  120. })
  121. }
  122. })
  123. .then(res => {
  124. orderId = '' + res.data.data.id;
  125. return Common.payOrderCreate(orderId)
  126. })
  127. .then(res => {
  128. console.log(res)
  129. payOrderId = res.data.data.payOrderId;
  130. if (res.data.code == 200) {
  131. wx.requestPayment({
  132. timeStamp: res.data.data.timeStamp,
  133. nonceStr: res.data.data.nonceStr,
  134. package: res.data.data.package,
  135. signType: 'MD5',
  136. paySign: res.data.data.paySign,
  137. 'success': function (res) {
  138. Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功
  139. console.log(res);
  140. console.log('支付成功');
  141. wx.showToast({
  142. title: '购买成功',
  143. duration: 2500
  144. })
  145. wx.navigateBack({
  146. delta: 2
  147. })
  148. },
  149. 'fail': function (res) {
  150. Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
  151. console.log(res)
  152. console.log('支付失败');
  153. return;
  154. },
  155. 'complete': function (res) {
  156. console.log(res);
  157. console.log('支付完成');
  158. var url = that.data.url;
  159. console.log('get url', url)
  160. if (res.errMsg == 'requestPayment:ok') {
  161. wx.showModal({
  162. title: '提示',
  163. content: '支付成功'
  164. });
  165. if (url) {
  166. setTimeout(function () {
  167. wx.redirectTo({
  168. url: '/pages' + url
  169. });
  170. }, 2000)
  171. } else {
  172. setTimeout(() => {
  173. wx.navigateBack()
  174. }, 2000)
  175. }
  176. } else {
  177. wx.showModal({
  178. title: '错误提示',
  179. content: res.errMsg
  180. });
  181. }
  182. return;
  183. }
  184. })
  185. }
  186. })
  187. }
  188. })