Commit 8774b350 by Confettis

出门刷脸扣款 1

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