Commit 8774b350 by Confettis

出门刷脸扣款 1

parent e3fc2b60
...@@ -30,6 +30,9 @@ class OrderDetailMini extends Component { ...@@ -30,6 +30,9 @@ class OrderDetailMini extends Component {
contact, contact,
storeName, storeName,
}); });
setTimeout(() => {
this.props.onPress();
}, 2000);
} }
// 生成不重复的key // 生成不重复的key
......
...@@ -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);
...@@ -767,7 +771,7 @@ class FacePage extends Component { ...@@ -767,7 +771,7 @@ class FacePage extends Component {
Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true); Speech.speak('刷脸支付启动失败,请重新刷脸或扫码支付', true);
} else { } else {
this.faceRetry = true; this.faceRetry = true;
this.wxFacepay(); // 重试 await this.wxFacepay(); // 重试
} }
return; return;
} }
...@@ -776,6 +780,10 @@ class FacePage extends Component { ...@@ -776,6 +780,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;
} }
}; };
...@@ -796,17 +804,134 @@ class FacePage extends Component { ...@@ -796,17 +804,134 @@ 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,
});
console.log('data', data);
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() {
...@@ -957,7 +1082,10 @@ class FacePage extends Component { ...@@ -957,7 +1082,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={
......
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