Commit 449ebdc9 by zeven

Merge remote-tracking branch 'origin/hzp'

parents 97130656 9285059c
import React, {Component} from 'react';
import {Modal, View, Text, Image, FlatList, ScrollView} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import ModalStyles from './Modal/styles';
import React, {Component} from 'react';
import {FlatList, Image, Modal, ScrollView, Text, View} from 'react-native';
import {font} from '../utils/common';
import NP from '../utils/np';
import {setSpText, scaleSize} from '../utils/screen';
import {scaleSize, setSpText} from '../utils/screen';
import ModalStyles from './Modal/styles';
const mStyles = {
...ModalStyles,
......
......@@ -25,6 +25,8 @@ import Speech from '../utils/Speech';
import validity from '../utils/validity';
import WxFacepay from '../utils/WxFacepay';
const wait = t => new Promise(resolve => setTimeout(resolve, t));
@connect(({admin}) => ({admin}))
class FacePage extends Component {
state = {
......@@ -187,7 +189,6 @@ class FacePage extends Component {
}, timeout);
};
/**
* TODO: 疑似没有同步
* 拉取数据,同步至state
*/
getOrderDetailMiniCounter = async () => {
......@@ -255,9 +256,12 @@ class FacePage extends Component {
else if (this.action === 'leave') {
// 出门身份识别提示
Speech.speak('正在进行安全检查');
this.state.faceType === 'wxpay'
? await this.wxFacepay()
: await this.smilepay();
if (this.state.goodsArr.length === 0) {
return;
}
const facepay =
this.state.faceType === 'wxpay' ? this.wxFacepay : this.smilepay;
await facepay();
// this.getOrderDetailMiniCounter();
// this.orderDetailMiniPop(30000);
// this.loading(true, 30000);
......@@ -439,6 +443,7 @@ class FacePage extends Component {
type: 'goods/faceinfo',
rawdata,
});
if (data.code !== 1) return null;
return data;
};
......@@ -727,7 +732,8 @@ class FacePage extends Component {
};
wxFacepay = async () => {
const auth = (await this.payscoreAuthinfo()) || {};
const {data} = (await this.authinfo()) || {};
const auth = data;
let params = null;
if (auth.bizCode === '0000') {
// 随行付支付
......@@ -758,10 +764,10 @@ class FacePage extends Component {
if (!params) {
if (this.faceRetry) {
this.faceRetry = false;
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true);
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付');
} else {
this.faceRetry = true;
this.wxFacepay(); // 重试
await this.wxFacepay(); // 重试
}
return;
}
......@@ -770,6 +776,10 @@ class FacePage extends Component {
res = await WxFacepay.facepay(params);
}
if (res.face_code) {
const data = await this.balancePay(res.sub_openid);
if (data.code !== 1) {
await this.barcodePay(res.face_code, true, res.sub_openid);
}
this.faceRetry = false;
}
};
......@@ -777,7 +787,7 @@ class FacePage extends Component {
smilepay = async () => {
await this.alipayinfo();
if (!this.alipayInfo || !this.alipayInfo.metaInfo) {
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true);
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付');
return;
}
const {data} = await this.props.dispatch({
......@@ -790,17 +800,133 @@ class FacePage extends Component {
Toast.show(res.msg);
return;
}
// const balanceData = await this.props.balancePay(res.uid);
// if (balanceData.code !== 1) {
// await this.props.barcodepay(
// res.fToken,
// true,
// null,
// res.fToken,
// res.uid,
// );
// }
// TODO: 编写 balancePay 和 barcodepay
const balanceData = await this.balancePay(res.uid);
if (balanceData.code !== 1) {
await this.barcodePay(res.fToken, true, null, res.fToken, res.uid);
}
}
};
getGoods = () => {
const {goodsArr} = this.state;
const ids = {};
const noBarcode = [];
goodsArr.map(({barcode, num, prePrice, name}) => {
if (barcode !== '000000') {
// 非无码商品
if (!ids[barcode]) {
ids[barcode] = num;
} else {
ids[barcode] += num;
}
} else {
noBarcode.push({
name,
barcode,
price: 0,
purPrice: 0,
prePrice,
num,
weight: 0,
});
}
});
return {ids, noBarcode};
};
successPay = async balance => {
Toast.hide();
const msg = balance
? '余额付款成功,祝您生活愉快~'
: '付款成功,祝您生活愉快~';
this.props.dispatch({
// 购物完成步骤
type: 'app/step',
step: 3,
});
Speech.speak(msg);
};
balancePay = async openid => {
Toast.loading('正在付款,请稍后~');
const {ids, noBarcode} = this.getGoods();
const {data} = await this.props.dispatch({
type: 'goods/balancePay',
ids,
noBarcode,
openid,
});
if (data.code === 1) {
this.orderId = data.data.orderId;
this.successPay(true);
await AutoClick.clickBackKey();
await wait(1200);
// await this.setState({orderDetailMini: false});
return data;
}
return data;
};
barcodePay = async (code, facepay, openid, fToken, uid) => {
Toast.loading('正在付款,请稍后');
const isWxpay = code.toString().match(/1[0-5]\d{16}/);
const isAlipay = fToken || code.toString().match(/^(2[5-9]|30)\d{14,22}$/);
if (!isWxpay && !isAlipay) return false;
let successPay = false;
const {ids, noBarcode} = this.getGoods();
const res = await this.props.dispatch({
type: 'goods/barcodepay',
ids,
code,
facepay,
noBarcode,
openid,
fToken,
uid,
});
if (res.code !== 1) {
Toast.info(`${res.msg}`);
Speech.speak(res.msg);
}
if (res.code === 1) {
this.orderId = res.data.orderId;
if (res.data.alipayUserId) {
// 没有匹配到支付宝用户
const voiceTitle =
'为了正常出店,首次使用支付宝付款码,请用进店微信扫描屏幕二维码';
// this.orderId = res.data.orderId;
this.alipayUserId = res.data.alipayUserId;
Speech.speak(voiceTitle);
} else {
this.successPay();
successPay = true;
await wait(1200);
}
} else if (res.code === 2) {
// 等待付款
for (let i = 0; i < 20; ++i) {
await wait(3000);
const status = await this.props.dispatch({
type: 'goods/status',
orderId: this.faceinfo.orderId,
});
if (status.code === 1 && status.data === 1) {
this.successPay();
successPay = true;
await wait(1200);
break;
}
}
} else if (res.code === 3) {
await wait(res.data.timeout);
} else {
await wait(1200);
}
if (successPay) {
return 'SUCCESS';
}
return true;
};
render() {
......@@ -951,7 +1077,10 @@ class FacePage extends Component {
/>
</Touch>
)}
<Touch onPress={this.face} style={styles.btnCome} feedback={false}>
<Touch
onPress={() => this.setState({orderDetailMini: true})}
style={styles.btnCome}
feedback={false}>
<View style={styles.click}>
<Image
source={
......
......@@ -2,7 +2,7 @@ const app = ''; // eg: .25h/.eg
export const isProd = process.env.NODE_ENV === 'production';
export const host = isProd
? `https://api${app}.vs-u.com`
: 'http://192.168.88.43:7001';
: 'http://192.168.88.88:7001';
export const login = `https://m${app}.vs-u.com`;
export const qrHost = login;
export const imgUrl = 'http://barcod.oss-cn-shenzhen.aliyuncs.com/images/';
......
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