Commit bf3dc9ac by wangshuo

单集购买

parent ea0c5de6
...@@ -83,122 +83,26 @@ class Detail extends Component { ...@@ -83,122 +83,26 @@ class Detail extends Component {
} }
}) })
} }
payCallback = () => { // payCallback = () => {
//
// };
// weixinPay = (weixin_code) => {
//
// }
payCallBack = (singleType, nowPrice, laterPrice) => {
const _this = this; const _this = this;
if(getParam('oid')) { if(singleType === 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({ _this.setState({
singleType: 6 singleType,
nowPrice,
laterPrice
}) })
} else if (Number(res.data.data.errno) === 201) { }else{
// 0元参团
_this.setState({
singleType: 4
})
} else if (Number(res.data.data.errno) === 202) {
// 0元购
_this.setState({ _this.setState({
singleType: 3 singleType,
}) })
} 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)
} }
}; };
weixinPay = (weixin_code) => {
const _this = this;
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)
}
})
}
fetchCourseInfo = () => { fetchCourseInfo = () => {
const id = getParam('id'); const id = getParam('id');
http.get(`${API.home}/m/course/detail/${id}`).then((res) => { http.get(`${API.home}/m/course/detail/${id}`).then((res) => {
...@@ -494,10 +398,12 @@ class Detail extends Component { ...@@ -494,10 +398,12 @@ class Detail extends Component {
data={this.state.singMess} data={this.state.singMess}
singleType={singleType} singleType={singleType}
videoId={this.state.singMess.video_id} videoId={this.state.singMess.video_id}
payCallback={this.payCallback} payCallBack={this.payCallBack}
weixinPay = {this.weixinPay}
/> />
} }
{/*payCallback={this.payCallback}*/}
{/*weixinPay = {this.weixinPay}*/}
{/*分享赚钱*/} {/*分享赚钱*/}
{ {
course_info.is_dist && course_info.is_dist &&
......
...@@ -29,8 +29,8 @@ class Single extends Component { ...@@ -29,8 +29,8 @@ class Single extends Component {
componentDidMount() { componentDidMount() {
if (getParam('is_class') === 1 || getParam('weixinpay')) { if (getParam('is_class') === 1 || getParam('weixinpay')) {
console.log(0); console.log(0);
// this.payCallback() this.payCallback()
this.props.payCallback(); // this.props.payCallback();
} }
if (browser.isWeixin) { if (browser.isWeixin) {
this.isweixinPay() this.isweixinPay()
...@@ -101,7 +101,88 @@ class Single extends Component { ...@@ -101,7 +101,88 @@ class Single extends Component {
if (!getParam('oid')) { if (!getParam('oid')) {
return return
} else { } else {
this.props.weixinPay(weixin_code) // 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) => {
let singleType, nowPrice, laterPrice;
if (Number(res.data.data.errno) === 200) {
// 正常购买单集成功
// _this.setState({
// singleType: 6
// })
singleType = 6;
} else if (Number(res.data.data.errno) === 201) {
// 0元参团
// _this.setState({
// singleType: 4,
// })
singleType = 4;
} else if (Number(res.data.data.errno) === 202) {
// 0元购
// _this.setState({
// singleType: 3,
// })
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,
// })
singleType = 2;
nowPrice = res.data.data.data.now_price;
laterPrice = res.data.data.data.three_day_later_price;
} else {
Toast.info(res.data.data.msg, 2)
return;
}
this.props.payCallBack(singleType, nowPrice, laterPrice);
})
}
})
}, 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)
}
})
} }
} }
} }
...@@ -117,35 +198,40 @@ class Single extends Component { ...@@ -117,35 +198,40 @@ class Single extends Component {
_this.intervalPayStatus = null; _this.intervalPayStatus = null;
// 获取课程类型 // 获取课程类型
http.get(`${API['base-api']}/class_order_status/${getParam('oid')}`).then((res) => { http.get(`${API['base-api']}/class_order_status/${getParam('oid')}`).then((res) => {
let singleType, nowPrice, laterPrice;
if (Number(res.data.data.errno) === 200) { if (Number(res.data.data.errno) === 200) {
// 正常购买单集成功 // 正常购买单集成功
this.setState({ // _this.setState({
status: 6, // singleType: 6
showSingleBox: true, // })
}) singleType = 6;
} else if (Number(res.data.data.errno) === 201) { } else if (Number(res.data.data.errno) === 201) {
// 0元参团 // 0元参团
this.setState({ // _this.setState({
status: 4, // singleType: 4,
showSingleBox: true, // })
}) singleType = 4;
} else if (Number(res.data.data.errno) === 202) { } else if (Number(res.data.data.errno) === 202) {
// 0元购 // 0元购
this.setState({ // _this.setState({
status: 3, // singleType: 3,
showSingleBox: true, // })
}) singleType = 3;
} else if (Number(res.data.data.errno) === 203) { } else if (Number(res.data.data.errno) === 203) {
// 三天内特价 // 三天内特价
this.setState({ // _this.setState({
nowPrice: res.data.data.data.now_price, // nowPrice: res.data.data.data.now_price,
laterPrice: res.data.data.data.three_day_later_price, // laterPrice: res.data.data.data.three_day_later_price,
status: 2, // singleType: 2,
showSingleBox: true, // })
}) singleType = 2;
nowPrice = res.data.data.data.now_price;
laterPrice = res.data.data.data.three_day_later_price;
} else { } else {
Toast.info(res.data.data.msg, 2) Toast.info(res.data.data.msg, 2)
return;
} }
this.props.payCallBack(singleType, nowPrice, laterPrice);
}) })
} }
}) })
......
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