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 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 {font} from '../utils/common';
import NP from '../utils/np'; import NP from '../utils/np';
import {setSpText, scaleSize} from '../utils/screen'; import {scaleSize, setSpText} from '../utils/screen';
import ModalStyles from './Modal/styles';
const mStyles = { const mStyles = {
...ModalStyles, ...ModalStyles,
......
...@@ -25,6 +25,8 @@ import Speech from '../utils/Speech'; ...@@ -25,6 +25,8 @@ import Speech from '../utils/Speech';
import validity from '../utils/validity'; import validity from '../utils/validity';
import WxFacepay from '../utils/WxFacepay'; import WxFacepay from '../utils/WxFacepay';
const wait = t => new Promise(resolve => setTimeout(resolve, t));
@connect(({admin}) => ({admin})) @connect(({admin}) => ({admin}))
class FacePage extends Component { class FacePage extends Component {
state = { state = {
...@@ -187,7 +189,6 @@ class FacePage extends Component { ...@@ -187,7 +189,6 @@ class FacePage extends Component {
}, timeout); }, timeout);
}; };
/** /**
* TODO: 疑似没有同步
* 拉取数据,同步至state * 拉取数据,同步至state
*/ */
getOrderDetailMiniCounter = async () => { getOrderDetailMiniCounter = async () => {
...@@ -255,9 +256,12 @@ class FacePage extends Component { ...@@ -255,9 +256,12 @@ class FacePage extends Component {
else if (this.action === 'leave') { else if (this.action === 'leave') {
// 出门身份识别提示 // 出门身份识别提示
Speech.speak('正在进行安全检查'); Speech.speak('正在进行安全检查');
this.state.faceType === 'wxpay' if (this.state.goodsArr.length === 0) {
? await this.wxFacepay() return;
: await this.smilepay(); }
const facepay =
this.state.faceType === 'wxpay' ? this.wxFacepay : this.smilepay;
await facepay();
// this.getOrderDetailMiniCounter(); // this.getOrderDetailMiniCounter();
// this.orderDetailMiniPop(30000); // this.orderDetailMiniPop(30000);
// this.loading(true, 30000); // this.loading(true, 30000);
...@@ -439,6 +443,7 @@ class FacePage extends Component { ...@@ -439,6 +443,7 @@ class FacePage extends Component {
type: 'goods/faceinfo', type: 'goods/faceinfo',
rawdata, rawdata,
}); });
if (data.code !== 1) return null;
return data; return data;
}; };
...@@ -727,7 +732,8 @@ class FacePage extends Component { ...@@ -727,7 +732,8 @@ class FacePage extends Component {
}; };
wxFacepay = async () => { wxFacepay = async () => {
const auth = (await this.payscoreAuthinfo()) || {}; const {data} = (await this.authinfo()) || {};
const auth = data;
let params = null; let params = null;
if (auth.bizCode === '0000') { if (auth.bizCode === '0000') {
// 随行付支付 // 随行付支付
...@@ -758,10 +764,10 @@ class FacePage extends Component { ...@@ -758,10 +764,10 @@ class FacePage extends Component {
if (!params) { if (!params) {
if (this.faceRetry) { if (this.faceRetry) {
this.faceRetry = false; this.faceRetry = false;
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true); Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付');
} else { } else {
this.faceRetry = true; this.faceRetry = true;
this.wxFacepay(); // 重试 await this.wxFacepay(); // 重试
} }
return; return;
} }
...@@ -770,6 +776,10 @@ class FacePage extends Component { ...@@ -770,6 +776,10 @@ class FacePage extends Component {
res = await WxFacepay.facepay(params); res = await WxFacepay.facepay(params);
} }
if (res.face_code) { 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; this.faceRetry = false;
} }
}; };
...@@ -777,7 +787,7 @@ class FacePage extends Component { ...@@ -777,7 +787,7 @@ class FacePage extends Component {
smilepay = async () => { smilepay = async () => {
await this.alipayinfo(); await this.alipayinfo();
if (!this.alipayInfo || !this.alipayInfo.metaInfo) { if (!this.alipayInfo || !this.alipayInfo.metaInfo) {
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true); Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付');
return; return;
} }
const {data} = await this.props.dispatch({ const {data} = await this.props.dispatch({
...@@ -790,17 +800,133 @@ class FacePage extends Component { ...@@ -790,17 +800,133 @@ class FacePage extends Component {
Toast.show(res.msg); Toast.show(res.msg);
return; return;
} }
// const balanceData = await this.props.balancePay(res.uid); // TODO: 编写 balancePay 和 barcodepay
// if (balanceData.code !== 1) { const balanceData = await this.balancePay(res.uid);
// await this.props.barcodepay( if (balanceData.code !== 1) {
// res.fToken, await this.barcodePay(res.fToken, true, null, res.fToken, res.uid);
// 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() { render() {
...@@ -951,7 +1077,10 @@ class FacePage extends Component { ...@@ -951,7 +1077,10 @@ class FacePage extends Component {
/> />
</Touch> </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}> <View style={styles.click}>
<Image <Image
source={ source={
......
...@@ -2,7 +2,7 @@ const app = ''; // eg: .25h/.eg ...@@ -2,7 +2,7 @@ const app = ''; // eg: .25h/.eg
export const isProd = process.env.NODE_ENV === 'production'; export const isProd = process.env.NODE_ENV === 'production';
export const host = isProd export const host = isProd
? `https://api${app}.vs-u.com` ? `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 login = `https://m${app}.vs-u.com`;
export const qrHost = login; export const qrHost = login;
export const imgUrl = 'http://barcod.oss-cn-shenzhen.aliyuncs.com/images/'; 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