OrderPay.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import {
  11. svipOrderCreateApi
  12. } from '@/api/activity.js';
  13. import {
  14. orderPayApi,
  15. orderExpressPayApi,
  16. orderSecondHandPayApi
  17. } from '@/api/order.js';
  18. import {
  19. ProductTypeEnum,
  20. } from "@/enums/productEnums";
  21. export default {
  22. data() {
  23. return {
  24. ProductTypeEnum: ProductTypeEnum,
  25. isBuy: false //是否可以点击购买
  26. };
  27. },
  28. methods: {
  29. /**
  30. * 调支付订单接口后的操作
  31. * @param {Object} res 接口返回的值
  32. * @param {Object} orderNo 订单号
  33. * @param {Object} productType 商品类型
  34. * @param {Object} fromType 页面来源
  35. * @param {Object} payType 支付方式
  36. * @param {Object} payPrice 支付金额
  37. */
  38. handleOrderPay(res,orderNo,productType,fromType,payType,payPrice){
  39. let jsConfig = res.data.jsConfig;
  40. let goPages = ''
  41. if(fromType==='svip'){
  42. goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
  43. }else{
  44. if (fromType) {
  45. goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&apiType=${fromType}`;
  46. } else {
  47. goPages = '/pages/goods/order_pay_status/index?order_id=' + orderNo;
  48. }
  49. }
  50. switch (res.data.payType) {
  51. case 'weixin':
  52. uni.hideLoading();
  53. this.weixinPay(jsConfig, orderNo, goPages,productType,fromType);
  54. break;
  55. case 'yue':
  56. uni.hideLoading();
  57. uni.reLaunch({
  58. url: goPages + '&status=1'
  59. });
  60. break;
  61. case 'h5':
  62. uni.hideLoading();
  63. setTimeout(() => {
  64. location.href = jsConfig.mwebUrl + '&redirect_url=' + window
  65. .location
  66. .protocol + '//' + window.location.host + goPages +
  67. '&status=1';
  68. }, 500)
  69. break;
  70. case 'alipay':
  71. //#ifdef H5
  72. //h5支付
  73. uni.hideLoading();
  74. this.formContent = res.data.alipayRequest;
  75. this.$nextTick(() => {
  76. document.forms['punchout_form'].submit();
  77. })
  78. uni.setStorage({
  79. key: 'orderNo',
  80. data: orderNo
  81. });
  82. uni.setStorage({
  83. key: 'payResultfromType',
  84. data: fromType
  85. });
  86. //#endif
  87. // #ifdef APP-PLUS
  88. let alipayRequest = res.data.alipayRequest;
  89. uni.requestPayment({
  90. provider: 'alipay',
  91. orderInfo: alipayRequest,
  92. success: (e) => {
  93. setTimeout(res => {
  94. uni.hideLoading();
  95. uni.navigateTo({
  96. url: `/pages/goods/alipay_return/alipay_return?out_trade_no=${orderNo}&payChannel=appAlipay&payPrice=${payPrice}&fromType=${fromType}`
  97. })
  98. }, 500)
  99. },
  100. fail: (e) => {
  101. uni.hideLoading();
  102. uni.showModal({
  103. content: "支付失败",
  104. showCancel: false,
  105. success: function(res) {
  106. if (res.confirm) {
  107. //点击确认的操作
  108. uni.navigateTo({
  109. url: '/pages/goods/alipay_return/alipay_return?out_trade_no=' +
  110. orderNo +
  111. '&payChannel=' +
  112. 'appAlipay'
  113. })
  114. }
  115. }
  116. })
  117. },
  118. complete: () => {
  119. uni.hideLoading();
  120. },
  121. });
  122. // #endif
  123. break;
  124. }
  125. },
  126. //微信支付
  127. weixinPay(jsConfig, orderNo, goPages,productType,fromType) {
  128. // #ifdef MP
  129. if (productType === 'video') {
  130. uni.requestOrderPayment({
  131. timeStamp: jsConfig.timeStamp,
  132. nonceStr: jsConfig.nonceStr,
  133. package: jsConfig.packages,
  134. signType: jsConfig.signType,
  135. paySign: jsConfig.paySign,
  136. ticket: productType === 'normal' ? null : jsConfig.ticket,
  137. success: function(ress) {
  138. setTimeout(res => {
  139. uni.hideLoading();
  140. uni.reLaunch({
  141. url: goPages
  142. })
  143. }, 500);
  144. },
  145. fail: function(e) {
  146. uni.hideLoading();
  147. return this.$util.Tips({
  148. title: '取消支付'
  149. }, {
  150. tab: 5,
  151. url: goPages + '&status=2'
  152. });
  153. },
  154. complete: function(e) {
  155. uni.hideLoading();
  156. //关闭当前页面跳转至订单状态
  157. if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
  158. title: '取消支付'
  159. }, {
  160. tab: 5,
  161. url: goPages + '&status=2'
  162. });
  163. },
  164. })
  165. } else {
  166. uni.requestPayment({
  167. timeStamp: jsConfig.timeStamp,
  168. nonceStr: jsConfig.nonceStr,
  169. package: jsConfig.packages,
  170. signType: jsConfig.signType,
  171. paySign: jsConfig.paySign,
  172. ticket: productType === 'normal' ? null : jsConfig.ticket,
  173. success: function(ress) {
  174. setTimeout(res => {
  175. uni.hideLoading();
  176. uni.reLaunch({
  177. url: goPages
  178. })
  179. }, 500);
  180. },
  181. fail: function(e) {
  182. uni.hideLoading();
  183. return this.$util.Tips({
  184. title: '取消支付'
  185. }, {
  186. tab: 5,
  187. url: goPages + '&status=2'
  188. });
  189. },
  190. complete: function(e) {
  191. uni.hideLoading();
  192. //关闭当前页面跳转至订单状态
  193. if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
  194. title: '取消支付'
  195. }, {
  196. tab: 5,
  197. url: goPages + '&status=2'
  198. });
  199. },
  200. })
  201. }
  202. // #endif
  203. // #ifdef H5
  204. let data = {
  205. timestamp: jsConfig.timeStamp,
  206. nonceStr: jsConfig.nonceStr,
  207. package: jsConfig.packages,
  208. signType: jsConfig.signType,
  209. paySign: jsConfig.paySign
  210. };
  211. if (this.$wechat.isWeixin()) {
  212. this.$wechat.pay(data).then(res => {
  213. setTimeout(res => {
  214. uni.hideLoading();
  215. uni.redirectTo({
  216. url: goPages
  217. })
  218. }, 500);
  219. }).catch(res => {
  220. uni.hideLoading();
  221. return this.$util.Tips({
  222. title: '取消支付'
  223. }, {
  224. tab: 5,
  225. url: goPages + '&status=2'
  226. });
  227. });
  228. } else {
  229. setTimeout(() => {
  230. location.href = jsConfig.mwebUrl + '&redirect_url=' + window.location.protocol + '//' + window.location.host + goPages;
  231. }, 100)
  232. uni.hideLoading();
  233. }
  234. // #endif
  235. // #ifdef APP-PLUS
  236. let mp_pay_name = ''
  237. if (uni.requestOrderPayment) {
  238. mp_pay_name = 'requestOrderPayment'
  239. } else {
  240. mp_pay_name = 'requestPayment'
  241. }
  242. uni[mp_pay_name]({
  243. provider: 'wxpay',
  244. orderInfo: {
  245. "appid": jsConfig.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  246. "noncestr": jsConfig.nonceStr, // 随机字符串
  247. "package": "Sign=WXPay", // 固定值
  248. "partnerid": jsConfig.partnerid, // 微信支付商户号
  249. "prepayid": jsConfig.packages, // 统一下单订单号
  250. "timestamp": Number(jsConfig.timeStamp), // 时间戳(单位:秒)
  251. "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig.paySign // 签名,这里用的 MD5 签名
  252. }, //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  253. success: function(res) {
  254. uni.hideLoading();
  255. setTimeout(res => {
  256. uni.redirectTo({
  257. url: goPages
  258. })
  259. }, 500)
  260. },
  261. fail: function(err) {
  262. uni.hideLoading();
  263. uni.showModal({
  264. content: "支付失败",
  265. showCancel: false,
  266. success: function(res) {
  267. if (res.confirm) {
  268. uni.redirectTo({
  269. url: goPages + '&status=2'
  270. })
  271. }
  272. }
  273. })
  274. },
  275. complete: (err) => {
  276. uni.hideLoading();
  277. }
  278. });
  279. // #endif
  280. },
  281. //购买svip
  282. svipOnCreateOrder(data, orderNo,payType,payPrice,fromType) {
  283. svipOrderCreateApi(data).then(res => {
  284. let jsConfig = res.data.jsConfig;
  285. let goPages = `/pages/goods/order_pay_status/index?order_id=${res.data.orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
  286. this.weixinPay(jsConfig, res.data.orderNo, goPages,'normal',fromType)
  287. }).catch(err => {
  288. uni.hideLoading();
  289. return this.$util.Tips({
  290. title: err
  291. });
  292. });
  293. },
  294. /**
  295. * 跳入支付收银台页面
  296. * @param {Object} secondType 二级订单类型
  297. * @param {data} res 订单对象
  298. */
  299. getToPayment(secondType,data,fromType) {
  300. let url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}&fromType=${fromType}`
  301. // let url = ''
  302. // if(secondType === this.ProductTypeEnum.Integral){
  303. // url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}&fromType=integral`
  304. // }else{
  305. // url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}`
  306. // }
  307. uni.redirectTo({
  308. url: url
  309. });
  310. },
  311. /**
  312. * 订单支付
  313. * @param {Object} orderNo 订单号
  314. * @param {Object} payChannel 支付渠道
  315. * @param {Object} payType 支付方式
  316. * @param {Object} productType 商品类型
  317. * @param {Object} fromType 页面来源
  318. * @param {Object} payPrice 支付金额
  319. */
  320. changeOrderPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
  321. let api = fromType == 'fast' ? orderExpressPayApi : fromType == 'secondHand' ? orderSecondHandPayApi : orderPayApi;
  322. api({
  323. orderNo: orderNo,
  324. payChannel: payChannel,
  325. payType: payType,
  326. scene: productType === 'normal' ? 0 : 1177
  327. }).then(res => {
  328. this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
  329. }).catch(err => {
  330. uni.hideLoading();
  331. this.isBuy = false;
  332. return this.$util.Tips({
  333. title: err
  334. });
  335. });
  336. },
  337. /**
  338. * 订单支付
  339. * @param {Object} orderNo 订单号
  340. * @param {Object} payChannel 支付渠道
  341. * @param {Object} payType 支付方式
  342. * @param {Object} productType 商品类型
  343. * @param {Object} fromType 页面来源
  344. * @param {Object} payPrice 支付金额
  345. */
  346. changeOrderExpressPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
  347. orderExpressPayApi({
  348. orderNo: orderNo,
  349. payChannel: payChannel,
  350. payType: payType,
  351. scene: productType === 'normal' ? 0 : 1177
  352. }).then(res => {
  353. this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
  354. }).catch(err => {
  355. uni.hideLoading();
  356. this.isBuy = false;
  357. return this.$util.Tips({
  358. title: err
  359. });
  360. });
  361. }
  362. }
  363. };