| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- import { orderType } from './../../constant/index'
- import { reactive } from 'vue'
- import { state } from '@/state'
- import request from '@/helpers/request'
- import { browser } from '@/helpers/utils'
- import { Dialog } from 'vant'
- import dayjs from 'dayjs'
- type orderType =
- | 'VIDEO'
- | 'LIVE'
- | 'GROUP'
- | 'PRACTICE'
- | 'GOODS'
- | 'VIP'
- | 'SVIP'
- | 'MUSIC'
- | 'PIANO_ROOM'
- | 'ACTI_REGIST'
- | 'VIP_COURSE'
- | 'ALBUM'
- | 'TENANT_ALBUM'
- | ''
- const original = () => {
- return {
- orderType: '' as orderType, // 购买类型
- orderInfo: {
- // 订单信息
- orderNo: '',
- actualPrice: 0,
- payStatus: true
- },
- orderObject: {
- // 订单对象
- orderNo: '',
- actualPrice: 0,
- orderName: '',
- orderDesc: '',
- orderType: '' as orderType,
- recomUserId: null as any, // 推荐人编号
- orderList: [] as Array<any>, // 商品信息
- activityId: '' as any, // 活动编号
- couponId: '' as string, // 优惠券编号
- couponAmount: 0 as number, // 所有的优惠金额 - 继续支付使用
- couponDiscountPrice: 0 as number, // 优惠券扣减金额
- discountCardPrice: 0 as number, // 畅学卡扣减金额
- discountPrice: 0 as number // 优惠
- } as any
- // orderObject: {
- // orderNo: '',
- // actualPrice: 28,
- // orderName: '小酷Ai月度会员',
- // orderDesc: '小酷Ai月度会员',
- // orderType: 'VIP',
- // recomUserId: 0,
- // activityId: null,
- // orderList: [
- // {
- // orderType: 'VIP',
- // goodsName: '小酷Ai月度会员',
- // id: 2,
- // title: '月度会员',
- // price: 28,
- // startTime: '2023-02-28',
- // endTime: '2023-03-28'
- // }
- // ]
- // }
- }
- }
- export const orderStatus = reactive(original())
- // 重置对象
- export const resestState = () => {
- Object.assign(orderStatus, original())
- }
- // 购买会员多少数量满足条件
- export const memberNeedNumber = (item: any) => {
- if (item.vipEndDays > 0) {
- const endTime = dayjs(item.startTime).add(item.vipEndDays, 'day')
- const unit = item.period === 'YEAR' ? 'years' : 'months'
- const months = endTime.diff(dayjs(item.startTime), unit)
- if (item.period === 'MONTH') {
- return months + 1
- } else if (item.period === 'QUARTERLY') {
- return Math.ceil((months + 1) / 3)
- } else if (item.period === 'YEAR_HALF') {
- return Math.ceil((months + 1) / 6)
- } else if (item.period === 'YEAR') {
- return months + 1
- } else {
- return 1
- }
- }
- return 1
- }
- export const orderInfos = () => {
- // 商品列表
- const orderList = orderStatus.orderObject.orderList || []
- return orderList.map((item: any) => {
- const params = {
- goodType: item.orderType,
- goodName: item.goodsName,
- recomUserId: item.recomUserId, // 推荐人id
- bizContent: {}
- } as any
- if (item.orderType === 'VIDEO') {
- params.bizContent = {
- videoLessonGroupId: item.courseGroupId,
- payMoney: item.coursePrice || 0
- }
- } else if (item.orderType === 'LIVE' || item.orderType === 'GROUP') {
- params.bizContent = {
- groupId: item.courseGroupId
- }
- } else if (item.orderType === 'PRACTICE' || item.orderType === "VIP_COURSE") {
- const tempTime = item.classTime || []
- const classCourse: any = []
- tempTime.forEach((time: any) => {
- classCourse.push({
- classDate: time.classDate,
- startTime: time.startTime,
- endTime: time.endTime
- })
- })
- params.bizContent = {
- courseGroupName: item.courseGroupName,
- courseIntroduce: item.courseIntroduce,
- subjectId: item.subjectId,
- singleCourseMinutes: item.singleCourseMinutes,
- courseNum: item.courseNum,
- coursePrice: item.coursePrice,
- teacherId: item.teacherId,
- classTime: classCourse
- }
- } else if (item.orderType === 'VIP') {
- params.bizContent = item.id
- params.goodsNum = item.num
- params.bizPrice = item.salePrice
- } else if (item.orderType === 'SVIP') {
- params.bizContent = item.id
- const needNumber = memberNeedNumber(item)
- params.vipEndDays = item.num > needNumber ? item.vipEndDays : null
- params.goodsNum = item.num
- params.bizPrice = item.salePrice
- } else if (item.orderType === 'MUSIC') {
- params.bizContent = {
- musicSheetId: item.id,
- actualPrice: item.actualPrice || 0,
- clientType: state.platformType
- }
- } else if (item.orderType === 'ALBUM') {
- params.bizContent = {
- musicSheetId: item.id,
- actualPrice: item.actualPrice || 0,
- clientType: state.platformType
- }
- } else if (item.orderType === 'PIANO_ROOM') {
- params.bizContent = item.id
- } else if (item.orderType === 'ACTI_REGIST') {
- params.bizContent = {
- activityId: item.activityId
- }
- } else if (item.orderType === 'TENANT_ALBUM') {
- params.bizContent = {
- musicSheetId: item.id,
- actualPrice: item.actualPrice || 0,
- clientType: state.platformType
- }
- }
- return params
- })
- }
- //
- export const orderTenantInfos = (otherGoods: any[] = []) => {
- // 商品列表
- let orderList: any[] = []
- if(otherGoods && otherGoods.length > 0) {
- orderList = otherGoods || []
- } else {
- orderList = orderStatus.orderObject.orderList || []
- }
-
- const activityList: any[] = [] // 活动赠品
- const infos = orderList.map((item: any) => {
- const params: any = {
- goodType: item.orderType,
- goodName: item.goodsName,
- goodNum: 1,
- bizContent: {}
- } as any
- if (item.orderType === 'VIP') {
- params.bizContent = item.id
- params.bizId = item.id
- params.goodsNum = item.num
- params.goodNum = item.num
- ;(item.activityList || []).map(actItem => {
- activityList.push(actItem)
- })
- } else if (item.orderType === 'SVIP') {
- params.bizContent = item.id
- // params.vipEndDays = item.vipEndDays
- const needNumber = memberNeedNumber(item)
- params.vipEndDays = item.num > needNumber ? item.vipEndDays : null
- params.goodsNum = item.num
- params.goodNum = item.num
- ;(item.activityList || []).map(actItem => {
- activityList.push(actItem)
- })
- } else if (item.orderType === 'MUSIC') {
- params.bizContent = {
- musicSheetId: item.id,
- actualPrice: item.actualPrice || 0,
- clientType: state.platformType
- }
- params.bizId = item.id
- } else if (item.orderType === 'ALBUM') {
- params.bizContent = {
- musicSheetId: item.id,
- actualPrice: item.actualPrice || 0,
- clientType: state.platformType
- }
- params.bizId = item.id
- } else if (item.orderType === 'TENANT_ALBUM') {
- console.log(item, 'item')
- params.bizContent = {
- tenantAlbumId: item.id,
- actualPrice: item.actualPrice || 0,
- buyNumber: 1,
- buyMultiple: 1,
- clientType: state.platformType
- }
- params.tenantGroupAlbumId = item.tenantGroupAlbumId
- params.bizId = item.id
- params.buyNumber = 1
- params.buyMultiple = 1
- } else if (item.orderType === 'LIVE' || item.orderType === 'GROUP') {
- params.bizContent = {
- groupId: item.courseGroupId
- }
- } else if (item.orderType === 'VIDEO') {
- params.bizContent = {
- videoLessonGroupId: item.courseGroupId,
- payMoney: item.coursePrice || 0
- }
- } else if (item.orderType === 'PRACTICE' || item.orderType === 'VIP_COURSE') {
- const tempTime = item.classTime || []
- const classCourse: any = []
- tempTime.forEach((time: any) => {
- classCourse.push({
- classDate: time.classDate,
- startTime: time.startTime,
- endTime: time.endTime
- })
- })
- params.bizContent = {
- courseGroupName: item.courseGroupName,
- courseIntroduce: item.courseIntroduce,
- teacherSubjectPriceId: item.teacherSubjectPriceId,
- subjectId: item.subjectId,
- singleCourseMinutes: item.singleCourseMinutes,
- courseNum: item.courseNum,
- coursePrice: item.coursePrice,
- teacherId: item.teacherId,
- classTime: classCourse
- }
- } else if (item.orderType === 'PIANO_ROOM') {
- params.bizContent = item.id
- } else if (item.orderType === 'ACTI_REGIST') {
- params.bizContent = {
- activityId: item.activityId
- }
- } else if(item.orderType == 'DISCOUNT') {
- params.bizContent = item.id
- params.goodsNum = item.num
- params.goodNum = item.num
- }
- return params
- })
- return [...infos, ...activityList]
- }
- /**
- * @title 0元购买
- * @param {function} callBack 回调函数
- * @returns {Promise<void>}
- */
- export const onSubmitZero = async (callBack?: Function): Promise<void> => {
- // 正常支付
- try {
- const orderObject = orderStatus.orderObject
- const url =
- state.platformType === 'TEACHER'
- ? '/api-teacher/userOrder/executeOrder'
- : '/api-student/userOrder/executeOrder'
- const res = await request.post(url, {
- data: {
- orderName: orderObject.orderName,
- orderDesc: orderObject.orderDesc,
- orderType: orderObject.orderType,
- actualPrice: orderObject.actualPrice || 0,
- recomUserId: orderObject.recomUserId,
- activityId: orderObject.activityId,
- orderInfos: [...orderInfos()]
- }
- })
- const result = res.data || {}
- // 支付成功
- if (result.status == 'PAID') {
- if (callBack) {
- callBack()
- } else {
- Dialog.alert({
- message: '领取成功',
- confirmButtonText: '确定',
- confirmButtonColor: '#2dc7aa'
- })
- }
- } else {
- Dialog.alert({
- message: result.msg,
- confirmButtonText: '确定',
- confirmButtonColor: '#2dc7aa'
- })
- }
- } catch {
- Dialog.alert({
- title: '提示',
- message: '支付失败,请稍后重试!',
- confirmButtonText: '确定',
- confirmButtonColor: '#2dc7aa'
- })
- }
- }
- /**
- * @author wxl
- * @description 处理基础支付功能
- */
- // 判断浏览器与支付类型,返回对应页面名称
- export const beforeSubmit = (pt: string) => {
- // const pt = state.pay_channel
- let payCode = 'qrCode'
- // 判断当前浏览器
- if (browser().weixin) {
- // 微信浏览器
- if (pt == 'alipay_qr' || pt == 'alipay_wap') {
- payCode = 'qrCode'
- } else if (pt == 'wx_pub') {
- payCode = 'pay'
- }
- } else if (browser().alipay) {
- // 支付宝浏览器
- if (pt == 'alipay_wap') {
- // 支付宝 H5 支付
- payCode = 'pay'
- } else {
- payCode = 'qrCode'
- }
- } else {
- payCode = 'qrCode'
- }
- return payCode == 'qrCode' ? 'payDefine' : 'payResult'
- }
|