C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
7.2 KiB

  1. var config = require("../../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../../utils/HttpBasics");
  4. const util = require("../../../utils/util");
  5. Page({
  6. data: {
  7. data: {},
  8. couponChannelId: null,
  9. couponId: null,
  10. orderId: "",
  11. day: "",
  12. hour: "",
  13. minute: ""
  14. },
  15. phone: function() {
  16. let that = this;
  17. console.log(that.data);
  18. if (that.data.data.merchantLinkPhone) {
  19. wx.makePhoneCall({
  20. phoneNumber: that.data.data.merchantLinkPhone //仅为示例,并非真实的电话号码
  21. });
  22. }
  23. },
  24. onLoad(options) {
  25. let that = this;
  26. console.log(options);
  27. console.log("couponChannelId" + options.couponChannelId);
  28. console.log("couponId" + options.couponId);
  29. console.log("传的变量的名字叫couponId");
  30. wx.showLoading({
  31. title: "加载中..."
  32. });
  33. /**
  34. * 暂时注销
  35. * this.orderFunc()
  36. */
  37. // if (options.flag) {
  38. // // this.orderFunc();
  39. // }
  40. // else {
  41. // }
  42. that.setData({
  43. couponChannelId: options.couponChannelId,
  44. couponId: options.couponId
  45. });
  46. var parmer = {
  47. url: config.api.couponDetail,
  48. data: {
  49. couponChannelId: options.couponChannelId
  50. }
  51. };
  52. Http.get(parmer).then(res => {
  53. console.log(res);
  54. console.log("details");
  55. //当前时间与优惠券下架时间做计算
  56. var endTime = util.fmtDate(res.data.endTime);
  57. util.timechuo(endTime)
  58. console.log(util.timechuo(endTime));
  59. that.setData({
  60. endtime:util.timechuo(endTime)
  61. })
  62. wx.hideLoading();
  63. that.setData({
  64. data: res.data
  65. });
  66. });
  67. // }
  68. },
  69. /**
  70. * 支付订单更新
  71. */
  72. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  73. // 支付成功
  74. Http.post({
  75. url: config.api.payOrderUpdate,
  76. data: {
  77. payOrderId: payOrderId,
  78. orderId: orderId,
  79. status: status,
  80. reason: reason
  81. }
  82. })
  83. .then(res => {
  84. console.log("payOrderUpdate then", res);
  85. // wx.showToast({
  86. // title: "购买成功",
  87. // duration: 2500
  88. // });
  89. })
  90. .catch(err => {
  91. console.log("payOrderUpdate catch", err);
  92. });
  93. },
  94. /**
  95. * 发起支付
  96. */
  97. orderFunc() {
  98. var that = this;
  99. wx.showLoading({
  100. title: "加载中..."
  101. });
  102. if (that.data.type == 5) {
  103. // 领取 5.停车券
  104. // TODO 选取用户下的车牌
  105. } else {
  106. Http.post({
  107. url: config.api.checkPhoneStatus,
  108. data: {}
  109. })
  110. .then(res => {
  111. console.log(res);
  112. console.log("姐姐在检查手机号是否授权的情况");
  113. var data = {
  114. couponChannelId: "" + that.data.couponChannelId,
  115. couponId: "" + that.data.couponId
  116. };
  117. if (that.data.couponChannelId == null) {
  118. var data = {
  119. couponId: "" + that.data.couponId
  120. };
  121. }
  122. /**
  123. * orderSave 下单
  124. */
  125. return Http.post({
  126. url: config.api.orderSave,
  127. data: data
  128. });
  129. })
  130. .catch(err => {
  131. console.log(err);
  132. console.log(that.data.couponChannelId);
  133. console.log(that.data.couponId);
  134. console.log("我即将要跳转到用户手机号授权的页面");
  135. if (err.code == 11005) {
  136. // 用户手机未授权
  137. /**
  138. * 将值传到用户手机号授权的页面
  139. *
  140. */
  141. wx.redirectTo({
  142. url:
  143. "/pages/getphoneInfo/index?couponChannelId=" +
  144. that.data.couponChannelId +
  145. "&couponId=" +
  146. that.data.couponId
  147. });
  148. }
  149. if (err.code == 11006) {
  150. // 用户手机已加密
  151. wx.redirectTo({
  152. url:
  153. "/pages/phoneinput/phoneinput?couponChannelId=" +
  154. that.data.couponChannelId +
  155. "&couponId=" +
  156. that.data.couponId
  157. });
  158. }
  159. })
  160. .then(res => {
  161. console.log(res);
  162. console.log("点击领取卡券一直在loading");
  163. if (res != "undefined") {
  164. console.log(res);
  165. let orderId = "" + res.data.id;
  166. that.setData({
  167. orderId: orderId
  168. });
  169. if (res.data.payment > 0) {
  170. // 支付金额不为0
  171. /**
  172. * 支付订单创建
  173. */
  174. Http.post({
  175. url: config.api.payOrderCreate,
  176. data: {
  177. orderId: orderId
  178. }
  179. }).then(res => {
  180. console.log(res);
  181. /// Begin payment ----
  182. var payOrderId = "" + res.data.payOrderId;
  183. wx.hideLoading();
  184. wx.requestPayment({
  185. timeStamp: res.data.timeStamp,
  186. nonceStr: res.data.nonceStr,
  187. package: res.data.package,
  188. signType: "MD5",
  189. paySign: res.data.paySign,
  190. success: res => {
  191. console.log(res);
  192. console.log("姐在检查付款异常");
  193. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  194. console.log(res);
  195. if (res.errMsg == "requestPayment:ok") {
  196. wx.showToast({
  197. title: "购买成功",
  198. image: "./../../../assets/img/success.png",
  199. duration: 2000,
  200. mask: false
  201. });
  202. /**
  203. * 用户支付成功以后跳转到券包列表
  204. */
  205. }
  206. },
  207. fail: res => {
  208. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  209. console.log(res);
  210. return;
  211. },
  212. complete: res => {
  213. console.log(res);
  214. console.log("支付完成");
  215. if (res.errMsg == "requestPayment:ok") {
  216. } else {
  217. wx.showToast({
  218. title: "支付失败",
  219. image: "./../../../assets/img/fail.png",
  220. duration: 2000,
  221. mask: false
  222. });
  223. }
  224. return;
  225. }
  226. });
  227. /// End payment --------
  228. ///// virtual pay
  229. //var payOrderId = "" + res.data.out_trade_no;
  230. //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  231. ///// end virtual pay
  232. });
  233. } else {
  234. // 免费券
  235. that.payOrderUpdate(orderId, "0", 1);
  236. wx.showToast({
  237. title: "领取成功",
  238. duration: 3000,
  239. image: "./../../../assets/img/success.png",
  240. });
  241. }
  242. }
  243. })
  244. .catch(err => {
  245. console.log(err);
  246. });
  247. }
  248. }
  249. });