OrderPay.js 10 KB

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