C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

256 řádky
7.1 KiB

  1. let Common = require('../../../common/common.js')
  2. var app = getApp()
  3. const Http = require("../../../utils/HttpBasics")
  4. Page({
  5. data: {
  6. list: {},
  7. couponId: null,
  8. orderId: ''
  9. },
  10. onLoad(e) {
  11. console.log(e.id)
  12. Http.get({
  13. url: Http.config.api.couponDetail,
  14. data: {
  15. id: e.id
  16. }
  17. }).then(res => {
  18. this.setData({
  19. list: res,
  20. couponId: e.id
  21. })
  22. })
  23. },
  24. /**
  25. * 支付订单更新
  26. */
  27. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  28. // 支付成功
  29. return Http.post({
  30. url: Http.config.api.payOrderUpdate, data: {
  31. payOrderId: payOrderId,
  32. orderId: orderId,
  33. status: status,
  34. reason: reason
  35. }
  36. })
  37. },
  38. newOrderfunc() {
  39. wx.showLoading({
  40. title: '加载中...',
  41. })
  42. Http.post({
  43. url: Http.config.api.orderSave,
  44. data: {
  45. couponId: this.data.couponId
  46. }
  47. }).then(res => {
  48. const orderId = '' + res.id;
  49. this.setData({
  50. orderId: orderId
  51. })
  52. if (res.payment > 0) {
  53. return Http.post({ url: Http.config.api.payOrderCreate, data: { orderId: orderId } })
  54. } else {
  55. this.payOrderUpdate(orderId, "0", 1) // 支付成功
  56. .then(res => {
  57. wx.showToast({
  58. title: "支付状态更新成功",
  59. duration: 3000
  60. })
  61. })
  62. }
  63. }).then(res => {
  64. console.log(res)
  65. if (res) {
  66. var payOrderId = '' + res.payOrderId;
  67. wx.hideLoading();
  68. wx.requestPayment({
  69. timeStamp: res.timeStamp,
  70. nonceStr: res.nonceStr,
  71. package: res.package,
  72. signType: 'MD5',
  73. paySign: res.paySign,
  74. 'success': (res) => {
  75. this.payOrderUpdate(this.data.orderId, payOrderId, 1)// 支付成功
  76. console.log(res);
  77. console.log('支付成功');
  78. wx.showToast({
  79. title: '购买成功',
  80. duration: 2500
  81. })
  82. wx.navigateBack({
  83. delta: 2
  84. })
  85. },
  86. 'fail': (res) => {
  87. this.payOrderUpdate(this.data.orderId, payOrderId, 2)// 支付失败
  88. console.log(res)
  89. console.log('支付失败');
  90. return;
  91. },
  92. 'complete': (res) => {
  93. console.log(res);
  94. console.log('支付完成');
  95. var url = this.data.url;
  96. console.log('get url', url)
  97. if (res.errMsg == 'requestPayment:ok') {
  98. wx.showModal({
  99. title: '提示',
  100. content: '支付成功'
  101. });
  102. if (url) {
  103. setTimeout(function () {
  104. wx.redirectTo({
  105. url: '/pages' + url
  106. });
  107. }, 2000)
  108. } else {
  109. setTimeout(() => {
  110. wx.navigateBack()
  111. }, 2000)
  112. }
  113. } else {
  114. wx.showModal({
  115. title: '错误提示',
  116. content: res.errMsg
  117. });
  118. }
  119. return;
  120. }
  121. })
  122. }
  123. })
  124. },
  125. orderfunc() {
  126. var that = this
  127. /*
  128. var couponOrderId = '189631451703017472';
  129. var orderId = '189631451640102912';
  130. var payOrderId = '189631462532710400';
  131. var status = 1;
  132. var reason = '';
  133. Common.refundCouponOrder(couponOrderId)
  134. .then(res => {
  135. console.log(res);
  136. if (res.data.code == 200) {
  137. Common.refundOrderCreate(orderId, payOrderId)
  138. .then(res => {
  139. console.log(res);
  140. })
  141. } else {
  142. wx.showToast({
  143. title: res.data.message,
  144. duration: 3000
  145. })
  146. }
  147. })
  148. */
  149. /*
  150. Common.payOrderUpdate(orderId, payOrderId, status, reason)
  151. .then(res =>{
  152. console.log(res);
  153. })
  154. */
  155. wx.showLoading({
  156. title: '加载中...',
  157. })
  158. var couponId = '' + this.data.couponId;
  159. console.log("order coupon: " + couponId)
  160. Common.orderSave(couponId)
  161. .then(res => {
  162. console.log(res)
  163. if (res.data.code == 200) {
  164. var orderId = '' + res.data.data.id;
  165. this.setData({
  166. orderId: '' + res.data.data.id
  167. })
  168. if (res.data.data.payment > 0) {
  169. return Common.payOrderCreate(orderId)
  170. } else {
  171. Common.payOrderUpdate(orderId, "0", 1) // 支付成功
  172. .then(res => {
  173. wx.showToast({
  174. title: res.data.message,
  175. duration: 3000
  176. })
  177. })
  178. }
  179. } else {
  180. wx.hideLoading();
  181. wx.showToast({
  182. title: res.data.message,
  183. duration: 3000
  184. })
  185. }
  186. })
  187. .then(res => {
  188. console.log(res)
  189. var payOrderId = '' + res.data.data.payOrderId;
  190. if (res.data.code == 200) {
  191. wx.requestPayment({
  192. timeStamp: res.data.data.timeStamp,
  193. nonceStr: res.data.data.nonceStr,
  194. package: res.data.data.package,
  195. signType: 'MD5',
  196. paySign: res.data.data.paySign,
  197. 'success': function (res) {
  198. Common.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  199. console.log(res);
  200. console.log('支付成功');
  201. wx.showToast({
  202. title: '购买成功',
  203. duration: 2500
  204. })
  205. wx.navigateBack({
  206. delta: 2
  207. })
  208. },
  209. 'fail': function (res) {
  210. Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败
  211. console.log(res)
  212. console.log('支付失败');
  213. return;
  214. },
  215. 'complete': function (res) {
  216. console.log(res);
  217. console.log('支付完成');
  218. var url = that.data.url;
  219. console.log('get url', url)
  220. if (res.errMsg == 'requestPayment:ok') {
  221. wx.showModal({
  222. title: '提示',
  223. content: '支付成功'
  224. });
  225. if (url) {
  226. setTimeout(function () {
  227. wx.redirectTo({
  228. url: '/pages' + url
  229. });
  230. }, 2000)
  231. } else {
  232. setTimeout(() => {
  233. wx.navigateBack()
  234. }, 2000)
  235. }
  236. } else {
  237. wx.showModal({
  238. title: '错误提示',
  239. content: res.errMsg
  240. });
  241. }
  242. return;
  243. }
  244. })
  245. } else {
  246. wx.showModal({
  247. title: '错误提示',
  248. content: res.data.message
  249. });
  250. }
  251. })
  252. wx.hideLoading();
  253. }
  254. })