C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

261 行
7.2 KiB

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