123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- import {
- svipOrderCreateApi
- } from '@/api/activity.js';
- import {
- orderPayApi,
- orderExpressPayApi,
- orderSecondHandPayApi
- } from '@/api/order.js';
- import {
- ProductTypeEnum,
- } from "@/enums/productEnums";
- export default {
- data() {
- return {
- ProductTypeEnum: ProductTypeEnum,
- isBuy: false //是否可以点击购买
- };
- },
- methods: {
- /**
- * 调支付订单接口后的操作
- * @param {Object} res 接口返回的值
- * @param {Object} orderNo 订单号
- * @param {Object} productType 商品类型
- * @param {Object} fromType 页面来源
- * @param {Object} payType 支付方式
- * @param {Object} payPrice 支付金额
- */
- handleOrderPay(res,orderNo,productType,fromType,payType,payPrice){
- let jsConfig = res.data.jsConfig;
- let goPages = ''
- if(fromType==='svip'){
- goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
- }else{
- if (fromType) {
- goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&apiType=${fromType}`;
- } else {
- goPages = '/pages/goods/order_pay_status/index?order_id=' + orderNo;
- }
- }
- switch (res.data.payType) {
-
- case 'weixin':
- uni.hideLoading();
- this.weixinPay(jsConfig, orderNo, goPages,productType,fromType);
- break;
- case 'yue':
- uni.hideLoading();
- uni.reLaunch({
- url: goPages + '&status=1'
- });
- break;
- case 'h5':
- uni.hideLoading();
- setTimeout(() => {
- location.href = jsConfig.mwebUrl + '&redirect_url=' + window
- .location
- .protocol + '//' + window.location.host + goPages +
- '&status=1';
- }, 500)
- break;
- case 'alipay':
- //#ifdef H5
- //h5支付
- uni.hideLoading();
- this.formContent = res.data.alipayRequest;
- this.$nextTick(() => {
- document.forms['punchout_form'].submit();
- })
- uni.setStorage({
- key: 'orderNo',
- data: orderNo
- });
- uni.setStorage({
- key: 'payResultfromType',
- data: fromType
- });
- //#endif
- // #ifdef APP-PLUS
- let alipayRequest = res.data.alipayRequest;
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: alipayRequest,
- success: (e) => {
- setTimeout(res => {
- uni.hideLoading();
- uni.navigateTo({
- url: `/pages/goods/alipay_return/alipay_return?out_trade_no=${orderNo}&payChannel=appAlipay&payPrice=${payPrice}&fromType=${fromType}`
- })
- }, 500)
- },
- fail: (e) => {
- uni.hideLoading();
- uni.showModal({
- content: "支付失败",
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- //点击确认的操作
- uni.navigateTo({
- url: '/pages/goods/alipay_return/alipay_return?out_trade_no=' +
- orderNo +
- '&payChannel=' +
- 'appAlipay'
- })
- }
- }
- })
- },
- complete: () => {
- uni.hideLoading();
- },
- });
- // #endif
- break;
- }
- },
- //微信支付
- weixinPay(jsConfig, orderNo, goPages,productType,fromType) {
- // #ifdef MP
- if (productType === 'video') {
- uni.requestOrderPayment({
- timeStamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign,
- ticket: productType === 'normal' ? null : jsConfig.ticket,
- success: function(ress) {
- setTimeout(res => {
- uni.hideLoading();
- uni.reLaunch({
- url: goPages
- })
- }, 500);
- },
- fail: function(e) {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- complete: function(e) {
- uni.hideLoading();
- //关闭当前页面跳转至订单状态
- if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- })
- } else {
- uni.requestPayment({
- timeStamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign,
- ticket: productType === 'normal' ? null : jsConfig.ticket,
- success: function(ress) {
- setTimeout(res => {
- uni.hideLoading();
- uni.reLaunch({
- url: goPages
- })
- }, 500);
- },
- fail: function(e) {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- complete: function(e) {
- uni.hideLoading();
- //关闭当前页面跳转至订单状态
- if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- })
- }
- // #endif
- // #ifdef H5
- let data = {
- timestamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign
- };
- if (this.$wechat.isWeixin()) {
- this.$wechat.pay(data).then(res => {
- setTimeout(res => {
- uni.hideLoading();
- uni.redirectTo({
- url: goPages
- })
- }, 500);
- }).catch(res => {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- });
- } else {
- setTimeout(() => {
- location.href = jsConfig.mwebUrl + '&redirect_url=' + window.location.protocol + '//' + window.location.host + goPages;
- }, 100)
- uni.hideLoading();
- }
- // #endif
- // #ifdef APP-PLUS
- let mp_pay_name = ''
- if (uni.requestOrderPayment) {
- mp_pay_name = 'requestOrderPayment'
- } else {
- mp_pay_name = 'requestPayment'
- }
- uni[mp_pay_name]({
- provider: 'wxpay',
- orderInfo: {
- "appid": jsConfig.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
- "noncestr": jsConfig.nonceStr, // 随机字符串
- "package": "Sign=WXPay", // 固定值
- "partnerid": jsConfig.partnerid, // 微信支付商户号
- "prepayid": jsConfig.packages, // 统一下单订单号
- "timestamp": Number(jsConfig.timeStamp), // 时间戳(单位:秒)
- "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig.paySign // 签名,这里用的 MD5 签名
- }, //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
- success: function(res) {
- uni.hideLoading();
- setTimeout(res => {
- uni.redirectTo({
- url: goPages
- })
- }, 500)
- },
- fail: function(err) {
- uni.hideLoading();
- uni.showModal({
- content: "支付失败",
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- uni.redirectTo({
- url: goPages + '&status=2'
- })
- }
- }
- })
- },
- complete: (err) => {
- uni.hideLoading();
- }
- });
- // #endif
- },
- //购买svip
- svipOnCreateOrder(data, orderNo,payType,payPrice,fromType) {
- svipOrderCreateApi(data).then(res => {
- let jsConfig = res.data.jsConfig;
- let goPages = `/pages/goods/order_pay_status/index?order_id=${res.data.orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
- this.weixinPay(jsConfig, res.data.orderNo, goPages,'normal',fromType)
- }).catch(err => {
- uni.hideLoading();
- return this.$util.Tips({
- title: err
- });
- });
- },
-
- /**
- * 跳入支付收银台页面
- * @param {Object} secondType 二级订单类型
- * @param {data} res 订单对象
- */
- getToPayment(secondType,data,fromType) {
- let url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}&fromType=${fromType}`
- // let url = ''
- // if(secondType === this.ProductTypeEnum.Integral){
- // url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}&fromType=integral`
- // }else{
- // url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}`
- // }
- uni.redirectTo({
- url: url
- });
- },
-
- /**
- * 订单支付
- * @param {Object} orderNo 订单号
- * @param {Object} payChannel 支付渠道
- * @param {Object} payType 支付方式
- * @param {Object} productType 商品类型
- * @param {Object} fromType 页面来源
- * @param {Object} payPrice 支付金额
- */
- changeOrderPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
- let api = fromType == 'fast' ? orderExpressPayApi : fromType == 'secondHand' ? orderSecondHandPayApi : orderPayApi;
- api({
- orderNo: orderNo,
- payChannel: payChannel,
- payType: payType,
- scene: productType === 'normal' ? 0 : 1177
-
- }).then(res => {
- this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
- }).catch(err => {
- uni.hideLoading();
- this.isBuy = false;
- return this.$util.Tips({
- title: err
- });
- });
- },
-
- /**
- * 订单支付
- * @param {Object} orderNo 订单号
- * @param {Object} payChannel 支付渠道
- * @param {Object} payType 支付方式
- * @param {Object} productType 商品类型
- * @param {Object} fromType 页面来源
- * @param {Object} payPrice 支付金额
- */
- changeOrderExpressPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
- orderExpressPayApi({
- orderNo: orderNo,
- payChannel: payChannel,
- payType: payType,
- scene: productType === 'normal' ? 0 : 1177
-
- }).then(res => {
- this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
- }).catch(err => {
- uni.hideLoading();
- this.isBuy = false;
- return this.$util.Tips({
- title: err
- });
- });
- }
- }
- };
|