OrderPay.js 9.3 KB

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