C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

273 строки
7.7 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. that.setData({
  59. endtime: util.timechuo(endTime)
  60. });
  61. wx.hideLoading();
  62. that.setData({
  63. data: res.data
  64. });
  65. });
  66. // }
  67. },
  68. /**
  69. * 支付订单更新
  70. */
  71. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  72. // 支付成功
  73. Http.post({
  74. url: config.api.payOrderUpdate,
  75. data: {
  76. payOrderId: payOrderId,
  77. orderId: orderId,
  78. status: status,
  79. reason: reason
  80. }
  81. })
  82. .then(res => {
  83. console.log("payOrderUpdate then", res);
  84. // wx.showToast({
  85. // title: "购买成功",
  86. // duration: 2500
  87. // });
  88. })
  89. .catch(err => {
  90. console.log("payOrderUpdate catch", err);
  91. });
  92. },
  93. /**
  94. * 发起支付
  95. */
  96. orderFunc() {
  97. var that = this;
  98. wx.showLoading({
  99. title: "加载中..."
  100. });
  101. if (that.data.type == 5) {
  102. // 领取 5.停车券
  103. // TODO 选取用户下的车牌
  104. } else {
  105. Http.post({
  106. url: config.api.checkPhoneStatus,
  107. data: {}
  108. })
  109. .then(res => {
  110. console.log(res);
  111. console.log("姐姐在检查手机号是否授权的情况");
  112. var data = {
  113. couponChannelId: "" + that.data.couponChannelId,
  114. couponId: "" + that.data.couponId
  115. };
  116. if (that.data.couponChannelId == null) {
  117. var data = {
  118. couponId: "" + that.data.couponId
  119. };
  120. }
  121. /**
  122. * orderSave 下单
  123. */
  124. return Http.post({
  125. url: config.api.orderSave,
  126. data: data
  127. });
  128. })
  129. .catch(err => {
  130. console.log(err);
  131. console.log(that.data.couponChannelId);
  132. console.log(that.data.couponId);
  133. console.log("我即将要跳转到用户手机号授权的页面");
  134. if (err.code == "3002") {
  135. wx.showToast({
  136. title: "领取达到上限",
  137. image: "./../../../assets/img/fail.png",
  138. duration: 2000,
  139. mask: false
  140. });
  141. }
  142. if (err.code == "4003") {
  143. wx.showToast({
  144. title: "卡券已作废",
  145. image: "./../../../assets/img/fail.png",
  146. duration: 2000,
  147. mask: false
  148. });
  149. }
  150. if (err.code == 11005) {
  151. // 用户手机未授权
  152. /**
  153. * 将值传到用户手机号授权的页面
  154. *
  155. */
  156. wx.redirectTo({
  157. url:
  158. "/pages/getphoneInfo/index?couponChannelId=" +
  159. that.data.couponChannelId +
  160. "&couponId=" +
  161. that.data.couponId
  162. });
  163. }
  164. if (err.code == 11006) {
  165. // 用户手机已加密
  166. wx.redirectTo({
  167. url:
  168. "/pages/phoneinput/phoneinput?couponChannelId=" +
  169. that.data.couponChannelId +
  170. "&couponId=" +
  171. that.data.couponId
  172. });
  173. }
  174. })
  175. .then(res => {
  176. console.log(res);
  177. console.log("点击领取卡券一直在loading");
  178. if (res != "undefined") {
  179. console.log(res);
  180. let orderId = "" + res.data.id;
  181. that.setData({
  182. orderId: orderId
  183. });
  184. if (res.data.payment > 0) {
  185. // 支付金额不为0
  186. /**
  187. * 支付订单创建
  188. */
  189. Http.post({
  190. url: config.api.payOrderCreate,
  191. data: {
  192. orderId: orderId
  193. }
  194. }).then(res => {
  195. console.log(res);
  196. /// Begin payment ----
  197. var payOrderId = "" + res.data.payOrderId;
  198. wx.hideLoading();
  199. wx.requestPayment({
  200. timeStamp: res.data.timeStamp,
  201. nonceStr: res.data.nonceStr,
  202. package: res.data.package,
  203. signType: "MD5",
  204. paySign: res.data.paySign,
  205. success: res => {
  206. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  207. console.log(res);
  208. if (res.errMsg == "requestPayment:ok") {
  209. wx.showToast({
  210. title: "购买成功",
  211. image: "./../../../assets/img/success.png",
  212. duration: 2000,
  213. mask: false,
  214. success:function(){
  215. wx.redirectTo({
  216. url: `/pages/order/detail/index?orderId=${that.data.orderId}`,
  217. })
  218. }
  219. });
  220. /**
  221. * 用户支付成功以后跳转到券包列表
  222. */
  223. }
  224. },
  225. fail: res => {
  226. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  227. console.log(res);
  228. return;
  229. },
  230. complete: res => {
  231. console.log(res);
  232. console.log("支付完成");
  233. if (res.errMsg == "requestPayment:ok") {
  234. } else {
  235. wx.showToast({
  236. title: "支付失败",
  237. image: "./../../../assets/img/fail.png",
  238. duration: 2000,
  239. mask: false
  240. });
  241. }
  242. return;
  243. }
  244. });
  245. /// End payment --------
  246. ///// virtual pay
  247. //var payOrderId = "" + res.data.out_trade_no;
  248. //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  249. ///// end virtual pay
  250. });
  251. } else {
  252. // 免费券
  253. that.payOrderUpdate(orderId, "0", 1);
  254. wx.showToast({
  255. title: "领取成功",
  256. duration: 3000,
  257. image: "./../../../assets/img/success.png"
  258. });
  259. }
  260. }
  261. })
  262. .catch(err => {
  263. console.log(err);
  264. });
  265. }
  266. }
  267. });