order-pay.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. var app = getApp();
  2. function setOnShowScene(e) {
  3. app.onShowData || (app.onShowData = {}), app.onShowData.scene = e
  4. }
  5. var pay = {
  6. init: function (l, e) {
  7. var _ = this,
  8. A = getApp().api;
  9. _.page = l, app = e;
  10. var y = getApp().core.getStorageSync(getApp().const.PARENT_ID);
  11. y || (y = 0), _.page.orderPay = function (e) {
  12. var t = e.currentTarget.dataset.index,
  13. o = _.page.data.order_list[t],
  14. a = new Array;
  15. if (void 0 !== _.page.data.pay_type_list) a = _.page.data.pay_type_list;
  16. else if (void 0 !== o.pay_type_list) a = o.pay_type_list;
  17. else if (void 0 !== o.goods_list[0].pay_type_list) a = o.goods_list[0].pay_type_list;
  18. else {
  19. var r = {
  20. payment: 0
  21. };
  22. a.push(r)
  23. }
  24. var p = getCurrentPages(),
  25. s = p[p.length - 1].route,
  26. c = {};
  27. if (-1 != s.indexOf("pt")) n = A.group.pay_data, c.order_id = o.order_id;
  28. else if (-1 != s.indexOf("miaosha")) n = A.miaosha.pay_data, c.order_id = o.order_id;
  29. else if (-1 != s.indexOf("book")) n = A.book.order_pay, c.id = o.id;
  30. else {
  31. var n = A.order.pay_data;
  32. c.order_id = o.order_id
  33. }
  34. function i(e, t, o) {
  35. e.pay_type = "WECHAT_PAY", app.request({
  36. url: t,
  37. data: e,
  38. complete: function () {
  39. getApp().core.hideLoading()
  40. },
  41. success: function (e) {
  42. 0 == e.code && (setOnShowScene("pay"), getApp().core.requestPayment({
  43. _res: e,
  44. timeStamp: e.data.timeStamp,
  45. nonceStr: e.data.nonceStr,
  46. package: e.data.package,
  47. signType: e.data.signType,
  48. paySign: e.data.paySign,
  49. success: function (e) {},
  50. fail: function (e) {},
  51. complete: function (e) {
  52. "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? getApp().core.redirectTo({
  53. url: "/" + o + "?status=1"
  54. }) : getApp().core.showModal({
  55. title: "提示",
  56. content: "订单尚未支付",
  57. showCancel: !1,
  58. confirmText: "确认",
  59. success: function (e) {
  60. e.confirm && getApp().core.redirectTo({
  61. url: "/" + o + "?status=0"
  62. })
  63. }
  64. })
  65. }
  66. })), 1 == e.code && getApp().core.showModal({
  67. title: "提示",
  68. content: e.msg,
  69. showCancel: !1
  70. })
  71. }
  72. })
  73. }
  74. function d(t, o, a) {
  75. t.pay_type = "BALANCE_PAY";
  76. var e = getApp().getUser();
  77. getApp().core.showModal({
  78. title: "当前账户余额:" + e.money,
  79. content: "是否使用余额",
  80. success: function (e) {
  81. e.confirm && (getApp().core.showLoading({
  82. title: "正在提交",
  83. mask: !0
  84. }), app.request({
  85. url: o,
  86. data: t,
  87. complete: function () {
  88. getApp().core.hideLoading()
  89. },
  90. success: function (e) {
  91. 0 == e.code && getApp().core.redirectTo({
  92. url: "/" + a + "?status=1"
  93. }), 1 == e.code && getApp().core.showModal({
  94. title: "提示",
  95. content: e.msg,
  96. showCancel: !1
  97. })
  98. }
  99. }))
  100. }
  101. })
  102. }
  103. c.parent_id = y, c.condition = 2, 1 == a.length ? (getApp().core.showLoading({
  104. title: "正在提交",
  105. mask: !0
  106. }), 0 == a[0].payment && i(c, n, s), 3 == a[0].payment && d(c, n, s)) : getApp().core.showModal({
  107. title: "提示",
  108. content: "选择支付方式",
  109. cancelText: "余额支付",
  110. confirmText: "线上支付",
  111. success: function (e) {
  112. e.confirm ? (getApp().core.showLoading({
  113. title: "正在提交",
  114. mask: !0
  115. }), i(c, n, s)) : e.cancel && d(c, n, s)
  116. }
  117. })
  118. },
  119. _.page.order_submit = function (r, g) {
  120. var e = A.order.submit,
  121. p = A.order.pay_data,
  122. u = "/pages/order/order";
  123. if ("pt" == g ? (e = A.group.submit, p = A.group.pay_data, u = "/pages/pt/order/order") : "ms" == g ? (e = A.miaosha.submit, p = A.miaosha.pay_data, u = "/pages/miaosha/order/order") : "pond" == g ? (e = A.pond.submit, p = A.order.pay_data, u = "/pages/order/order") : "scratch" == g ? (e = A.scratch.submit, p = A.order.pay_data, u = "/pages/order/order") : "lottery" == g ? (e = A.lottery.submit, p = A.order.pay_data, u = "/pages/order/order") : "step" == g ? (e = A.step.submit, p = A.order.pay_data, u = "/pages/order/order") : "s" == g && (e = A.order.new_submit, p = A.order.pay_data, u = "/pages/order/order"), 3 == r.payment) {
  124. var t = getApp().getUser();
  125. getApp().core.showModal({
  126. title: "当前账户余额:" + t.money,
  127. content: "是否确定使用余额支付",
  128. success: function (e) {
  129. e.confirm && o()
  130. }
  131. })
  132. } else o();
  133. function o() {
  134. getApp().core.showLoading({
  135. title: "正在提交",
  136. mask: !0
  137. }), app.request({
  138. url: e,
  139. method: "post",
  140. data: r,
  141. success: function (e) {
  142. if (0 == e.code) {
  143. var t = function () {
  144. app.request({
  145. url: p,
  146. data: {
  147. order_id: d,
  148. order_id_list: o,
  149. pay_type: a,
  150. form_id: r.formId,
  151. parent_user_id: y,
  152. condition: 2
  153. },
  154. success: function (e) {
  155. if (0 != e.code) return getApp().core.hideLoading(), void getApp().core.showModal({
  156. title: "提示",
  157. content: e.msg,
  158. showCancel: !1,
  159. confirmText: "确认",
  160. success: function (e) {
  161. e.confirm && getApp().core.redirectTo({
  162. url: u + "?status=0"
  163. })
  164. }
  165. });
  166. setTimeout(function () {
  167. getApp().core.hideLoading()
  168. }, 1e3), "pt" == g ? "ONLY_BUY" == _.page.data.type ? getApp().core.redirectTo({
  169. url: u + "?status=2"
  170. }) : getApp().core.redirectTo({
  171. url: "/pages/pt/group/details?oid=" + d
  172. }) : void 0 !== _.page.data.goods_card_list && 0 < _.page.data.goods_card_list.length && 2 != r.payment ? _.page.setData({
  173. show_card: !0
  174. }) : getApp().core.redirectTo({
  175. url: u + "?status=-1"
  176. })
  177. }
  178. })
  179. };
  180. if (getApp().page.bindParent({
  181. parent_id: y,
  182. condition: 1
  183. }), null != e.data.p_price && 0 === e.data.p_price) return "step" == g ? getApp().core.showToast({
  184. title: "兑换成功"
  185. }) : getApp().core.showToast({
  186. title: "提交成功"
  187. }), void setTimeout(function () {
  188. getApp().core.redirectTo({
  189. url: "/pages/order/order?status=1"
  190. })
  191. }, 2e3);
  192. setTimeout(function () {
  193. _.page.setData({
  194. options: {}
  195. })
  196. }, 1);
  197. var d = e.data.order_id || "",
  198. o = e.data.order_id_list ? JSON.stringify(e.data.order_id_list) : "",
  199. a = "";
  200. 0 == r.payment ? app.request({
  201. url: p,
  202. data: {
  203. order_id: d,
  204. order_id_list: o,
  205. pay_type: "WECHAT_PAY",
  206. parent_user_id: y,
  207. condition: 2
  208. },
  209. success: function (e) {
  210. if (0 != e.code) {
  211. if (1 == e.code) return getApp().core.hideLoading(), void getApp().core.showModal({
  212. title: "提示",
  213. content: e.msg,
  214. showCancel: !1
  215. })
  216. } else {
  217. setTimeout(function () {
  218. getApp().core.hideLoading()
  219. }, 1e3), setOnShowScene("pay"), e.data && 0 == e.data.price ? void 0 !== _.page.data.goods_card_list && 0 < _.page.data.goods_card_list.length ? _.page.setData({
  220. show_card: !0
  221. }) : getApp().core.redirectTo({
  222. url: u + "?status=1"
  223. }) : getApp().core.requestPayment({
  224. _res: e,
  225. timeStamp: e.data.timeStamp,
  226. nonceStr: e.data.nonceStr,
  227. package: e.data.package,
  228. signType: e.data.signType,
  229. paySign: e.data.paySign,
  230. success: function (e) {},
  231. fail: function (e) {},
  232. complete: function (e) {
  233. "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? "requestPayment:ok" != e.errMsg || (void 0 !== _.page.data.goods_card_list && 0 < _.page.data.goods_card_list.length ? _.page.setData({
  234. show_card: !0
  235. }) : "pt" == g ? "ONLY_BUY" == _.page.data.type ? getApp().core.redirectTo({
  236. url: u + "?status=2"
  237. }) : getApp().core.redirectTo({
  238. url: "/pages/pt/group/details?oid=" + d
  239. }) : getApp().core.redirectTo({
  240. url: u + "?status=1"
  241. })) : getApp().core.showModal({
  242. title: "提示",
  243. content: "订单尚未支付",
  244. showCancel: !1,
  245. confirmText: "确认",
  246. success: function (e) {
  247. e.confirm && getApp().core.redirectTo({
  248. url: u + "?status=0"
  249. })
  250. }
  251. })
  252. }
  253. });
  254. var t = getApp().core.getStorageSync(getApp().const.QUICK_LIST);
  255. if (t) {
  256. for (var o = t.length, a = 0; a < o; a++)
  257. for (var r = t[a].goods, p = r.length, s = 0; s < p; s++) r[s].num = 0;
  258. getApp().core.setStorageSync(getApp().const.QUICK_LISTS, t);
  259. var c = getApp().core.getStorageSync(getApp().const.CARGOODS);
  260. for (o = c.length, a = 0; a < o; a++) c[a].num = 0, c[a].goods_price = 0, l.setData({
  261. carGoods: c
  262. });
  263. getApp().core.setStorageSync(getApp().const.CARGOODS, c);
  264. var n = getApp().core.getStorageSync(getApp().const.TOTAL);
  265. n && (n.total_num = 0, n.total_price = 0, getApp().core.setStorageSync(getApp().const.TOTAL, n));
  266. getApp().core.getStorageSync(getApp().const.CHECK_NUM);
  267. 0, getApp().core.setStorageSync(getApp().const.CHECK_NUM, 0);
  268. var i = getApp().core.getStorageSync(getApp().const.QUICK_HOT_GOODS_LISTS);
  269. for (o = i.length, a = 0; a < o; a++) i[a].num = 0, l.setData({
  270. quick_hot_goods_lists: i
  271. });
  272. getApp().core.setStorageSync(getApp().const.QUICK_HOT_GOODS_LISTS, i)
  273. }
  274. }
  275. }
  276. }) : 2 == r.payment ? (a = "HUODAO_PAY", t()) : 3 == r.payment && (a = "BALANCE_PAY", t())
  277. }
  278. 1 == e.code && (getApp().core.hideLoading(), "活力币不足" == e.msg && _.page.data.store.option.step.currency_name ? getApp().core.showModal({
  279. title: "提示",
  280. content: _.page.data.store.option.step.currency_name + "不足",
  281. showCancel: !1
  282. }) : getApp().core.showModal({
  283. title: "提示",
  284. content: e.msg,
  285. showCancel: !1
  286. }))
  287. }
  288. })
  289. }
  290. }
  291. }
  292. };
  293. module.exports = pay;