Commit 39ae6702 by wangshuo

播放页单集购买

parent 32d23447
...@@ -536,7 +536,6 @@ class Detail extends Component { ...@@ -536,7 +536,6 @@ class Detail extends Component {
videoId={this.state.singMess.video_id} videoId={this.state.singMess.video_id}
nowPrice={this.state.nowPrice} nowPrice={this.state.nowPrice}
laterPrice={this.state.laterPrice} laterPrice={this.state.laterPrice}
payCallBack={this.payCallBack}
/> />
} }
{/*payCallback={this.payCallback}*/} {/*payCallback={this.payCallback}*/}
......
...@@ -2,7 +2,7 @@ import React, {Component} from 'react' ...@@ -2,7 +2,7 @@ import React, {Component} from 'react'
import HeaderBar from '@/common/HeaderBar' import HeaderBar from '@/common/HeaderBar'
import './video.scss' import './video.scss'
import {NavLink, Route, Redirect, Switch, Link} from 'react-router-dom' import {NavLink, Route, Redirect, Switch, Link} from 'react-router-dom'
import {http, getParam} from '@/utils' import {http, getParam, browser} from '@/utils'
import Recommendation from './recommendation' import Recommendation from './recommendation'
import VideoCatalog from './video-catalog' import VideoCatalog from './video-catalog'
import DatumCatalog from './datum-catalog' import DatumCatalog from './datum-catalog'
...@@ -15,6 +15,7 @@ import {connect} from "react-redux" ...@@ -15,6 +15,7 @@ import {connect} from "react-redux"
import jsCookie from 'js-cookie' import jsCookie from 'js-cookie'
import io from 'socket.io-client' import io from 'socket.io-client'
import Single from "@/components/detail/single"; import Single from "@/components/detail/single";
import SingleSuccess from "../detail/single/singleSuccess";
let alert = Modal.alert let alert = Modal.alert
...@@ -95,6 +96,9 @@ class Video extends Component { ...@@ -95,6 +96,9 @@ class Video extends Component {
shareData: {}, shareData: {},
singleBox: false, singleBox: false,
singMess: '', singMess: '',
singleType: 1,// 单集购买需要
nowPrice: 0,// 单集购买需要
laterPrice: 0,// 单集购买需要
} }
...@@ -113,6 +117,16 @@ class Video extends Component { ...@@ -113,6 +117,16 @@ class Video extends Component {
this.setState({ this.setState({
courseId: this.courseID courseId: this.courseID
}) })
const { location: { state = {} } } = this.props;
if(state.oid) {
this.check(state.oid);
}
if (getParam('is_class') === 1 || getParam('weixinpay')) {
this.payCallback()
}
if (browser.isWeixin) {
this.isweixinPay()
}
this.token = jsCookie.get('token') this.token = jsCookie.get('token')
this.getVideoList() this.getVideoList()
this.getDatumCatalog() this.getDatumCatalog()
...@@ -142,6 +156,168 @@ class Video extends Component { ...@@ -142,6 +156,168 @@ class Video extends Component {
this.setState({singleBox: val}) this.setState({singleBox: val})
} }
// 单集购买 H5支付成功后回调
payCallback =() => {
const _this = this;
if(!getParam('oid')) {
return;
}else{
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
// 获取课程类型
http.get(`${API['base-api']}/class_order_status/${getParam('oid')}`).then((res) => {
if (Number(res.data.data.errno) === 200) {
// 正常购买单集成功
_this.setState({
singleType: 6,
})
} else if (Number(res.data.data.errno) === 201) {
// 0元参团
_this.setState({
singleType: 4,
})
} else if (Number(res.data.data.errno) === 202) {
// 0元购
_this.setState({
singleType: 3,
})
} else if (Number(res.data.data.errno) === 203) {
// 三天内特价
_this.setState({
nowPrice: res.data.data.data.now_price,
laterPrice: res.data.data.data.three_day_later_price,
singleType: 2,
})
} else {
Toast.info(res.data.data.msg, 2)
}
})
}
})
}, 1000)
}
};
// 单集购买 微信内支付成功后回调
isweixinPay =()=> {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (!getParam('oid')) {
return
} else {
// this.props.weixinPay(weixin_code)
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
const data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": data.appId, //公众号名称,由商户传入
"timeStamp": data.timeStamp, //时间戳,自1970年以来的秒数
"nonceStr": data.nonceStr, //随机串
"package": data.package,
"signType": data.signType, //微信签名方式:
"paySign": data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
// 获取课程类型
http.get(`${API['base-api']}/class_order_status/${getParam('oid')}`).then((res) => {
if (Number(res.data.data.errno) === 200) {
// 正常购买单集成功
_this.setState({
singleType: 6,
})
} else if (Number(res.data.data.errno) === 201) {
// 0元参团
_this.setState({
singleType: 4,
})
} else if (Number(res.data.data.errno) === 202) {
// 0元购
_this.setState({
singleType: 3,
})
} else if (Number(res.data.data.errno) === 203) {
// 三天内特价
_this.setState({
nowPrice: res.data.data.data.now_price,
laterPrice: res.data.data.data.three_day_later_price,
singleType: 2,
})
} else {
Toast.info(res.data.data.msg, 2)
}
})
}
})
}, 1000)
} else {
alert('支付失败')
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady()
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
};
// 判断支付是否成功
check = (oid) => {
http.get(`${API['base-api']}/class_order_status/${oid}`).then((res) => {
if (Number(res.data.data.errno) === 200) {
// 正常购买单集成功
this.setState({
singleType: 6,
})
} else if (Number(res.data.data.errno) === 201) {
// 0元参团
this.setState({
singleType: 4,
})
} else if (Number(res.data.data.errno) === 202) {
// 0元购
this.setState({
singleType: 3,
})
} else if (Number(res.data.data.errno) === 203) {
// 三天内特价
this.setState({
nowPrice: res.data.data.data.now_price,
laterPrice: res.data.data.data.three_day_later_price,
singleType: 2,
})
} else {
Toast.info(res.data.data.msg, 2)
}
})
}
setupRecord = () => { setupRecord = () => {
this.recordSocket = io(API.record, { this.recordSocket = io(API.record, {
...@@ -472,7 +648,7 @@ class Video extends Component { ...@@ -472,7 +648,7 @@ class Video extends Component {
render() { render() {
let {match, location} = this.props let {match, location} = this.props
const {videoList, activeIndex, isAuth, salePrice, course} = this.state const {videoList, activeIndex, isAuth, salePrice, course, singleBox, singleType} = this.state
return ( return (
<div className='play'> <div className='play'>
<HeaderBar title={this.state.title} arrow={true}/> <HeaderBar title={this.state.title} arrow={true}/>
...@@ -524,9 +700,28 @@ class Video extends Component { ...@@ -524,9 +700,28 @@ class Video extends Component {
</div> </div>
{/*单集购买*/} {/*单集购买*/}
<Single singleBox={this.state.singleBox} boxHide={this.boxHide} data={this.state.singMess} {
videoId={this.state.singMess.id} singleBox &&
title={this.state.singMess.course_tile}/> <Single singleBox={this.state.singleBox} boxHide={this.boxHide} data={this.state.singMess}
singleType={this.state.singleType}
vcourseId={course.course_info.v_course_id}
videoId={this.state.singMess.video_id}
check={this.check}
title={this.state.singMess.course_tile}/>
}
{/* 单集购买成功 */}
{
singleType !== 1 &&
<SingleSuccess
boxHide={this.boxHide}
data={this.state.singMess}
singleType={singleType}
videoId={this.state.singMess.video_id}
nowPrice={this.state.nowPrice}
laterPrice={this.state.laterPrice}
/>
}
</Loading> </Loading>
<Switch> <Switch>
<Redirect exact from={'/play'} to={{ <Redirect exact from={'/play'} to={{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment