Commit ace69fb7 authored by gaodapeng's avatar gaodapeng

增加退款的逻辑

parent 1b0a4998
......@@ -35,4 +35,14 @@ export const ACTION_GET_ACCOUNT = "ACTION_GET_ACCOUNT";
export const ACTION_DIRECT_PAYMENT = "ACTION_DIRECT_PAYMENT";
//兑换券
export const ACTION_CONVERT_COUPON = "ACTION_CONVERT_COUPON";
\ No newline at end of file
export const ACTION_CONVERT_COUPON = "ACTION_CONVERT_COUPON";
//退款操作
export const ACTION_REFUND = "ACTION_REFUND";
//退款成功
export const ACTION_REFUND_SUCCESS = "ACTION_REFUND_SUCCESS";
//退款失败
export const ACTION_REFUND_FAILED = "ACTION_REFUND_FAILED";
......@@ -9,4 +9,6 @@ export const API_CREATE_ORDER = "order/create";
//支付接口
export const API_PAY = "pay/micropay";
//查询支付结果
export const API_QUERY = "order/query";
\ No newline at end of file
export const API_QUERY = "order/query";
export const API_REFUND = "order/refund";
\ No newline at end of file
<view class="page" >
<view class="bg" onTap="homeTap"/>
<!-- 弹窗 -->
<scandialog displayDialog="{{scanDialogDisplay}}"
remindText="请扫描兑换码"
loadingText="识别中"
resultSuccessRemind="兑换码已识别"
resultSuccessText="恭喜您!兑换成功 "
resultFailureRemind="兑换码未识别"
resultFailureText="兑换失败,请稍后重试!"
remindText="{{dialogRemindText}}"
loadingText="{{dialogLoadingText}}"
resultSuccessRemind="{{dialogResultSuccessRemind}}"
resultSuccessText="{{dialogResultSuccessText}}"
resultFailureRemind="{{dialogResultFailureRemind}}"
resultFailureText="{{dialogResultFailureText}}"
/>
</view>
\ No newline at end of file
......@@ -5,22 +5,33 @@ import { ACTION_GO_SCAN } from '../../const/actioncmd'
import { ACTION_GET_ACCOUNT } from '../../const/actioncmd'
import { ACTION_DIRECT_PAYMENT } from '../../const/actioncmd'
import { ACTION_CONVERT_COUPON } from '../../const/actioncmd'
import { ACTION_GO_HOME } from '../../const/actioncmd'
import { ACTION_REFUND } from '../../const/actioncmd'
import { ACTION_REFUND_FAILED } from '../../const/actioncmd'
import { ACTION_REFUND_SUCCESS } from '../../const/actioncmd'
Page({
data: {
//显示弹窗,>1为显示,2loading 3 result success 4 result failed
scanDialogDisplay: 0
scanDialogDisplay: 0,
dialogRemindText: "请扫描兑换码",
dialogLoadingText: "识别中",
dialogResultSuccessRemind: "兑换码已识别",
dialogResultSuccessText: "恭喜您!兑换成功",
dialogResultFailureRemind: "兑换码未识别",
dialogResultFailureText: "兑换失败,请稍后重试!",
},
onLoad() {
},
onShow(){
onShow() {
let context = this;
my.ix.onBuddyMessage({
success: (res) => {
console.info(`onBuddyMessage success: ${JSON.stringify(res)}`);
if(res.action == ACTION_GO_SCAN){
if (res.action == ACTION_GO_SCAN) {
my.ix.sendBuddyMessage({
// 填入目标小程序的 AppID
target: getApp().globalData.backScreenAppId,
......@@ -39,10 +50,10 @@ Page({
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
}
});
} else if(res.action == ACTION_GET_ACCOUNT){
} else if (res.action == ACTION_GET_ACCOUNT) {
var message = {
data:getApp().globalData.localAccountInfo,
action:ACTION_GET_ACCOUNT
data: getApp().globalData.localAccountInfo,
action: ACTION_GET_ACCOUNT
}
my.ix.sendBuddyMessage({
// 填入目标小程序的 AppID
......@@ -81,6 +92,22 @@ Page({
}else if(res.action == ACTION_CONVERT_COUPON){
//兑换券
this.setData({scanDialogDisplay:res.data})
} else if (res.action == ACTION_REFUND) {
//显示弹窗
context.setData({
scanDialogDisplay: 1,
dialogRemindText: "请扫描订单编码",
dialogLoadingText: "识别中",
dialogResultSuccessRemind: "退款成功",
dialogResultSuccessText: "退款完成!会在1~2个工作日 返还到您的付款账户",
dialogResultFailureRemind: "退款失败",
dialogResultFailureText: "退款失败!无效的订单码",
});
} else if (res.action == ACTION_GO_HOME) {
//home界面收到,则返回界面上
context.setData({
scanDialogDisplay: 0
})
}
}
});
......@@ -156,6 +183,62 @@ Page({
});
},
//增加扫码内容,以及退款等操作的内容
onKeyPress(r) {
//只有在弹窗出现时才扫码
if (this.data.scanDialogDisplay > 0) {
refund(r);
}
},
refund(barcode) {
this.setData({ scanDialogDisplay: 2 })
var request = api.createCommonRequest();
request.tradeNo = barcode;
my.request({
url: getApp().globalData.BASE_URL + API_REFUND,
method: 'POST',
dataType: 'json',
timeout: 30000,
data: request,
success: (res) => {
if (res.data.success != true||res.data.data == null) {
this.setData({ scanDialogDisplay: 4 })
console.log("退款失败 ==>" + JSON.stringify(res.data));
this.refundCallback(ACTION_REFUND_FAILED,null);
} else {
this.setData({ scanDialogDisplay: 3 })
console.log("退款成功 ==>" + JSON.stringify(res.data));
this.refundCallback(ACTION_REFUND_SUCCESS, res.data.data);
}
},
fail: (res) => {
this.setData({ scanDialogDisplay: 4 })
console.log("退款失败 ==>" + JSON.stringify(res.data));
this.refundCallback(ACTION_REFUND_FAILED,null);
}
});
},
refundCallback(action,data){
my.ix.sendBuddyMessage({
// 填入目标小程序的 AppID
target: getApp().globalData.backScreenAppId,
data: {
action: action,
data: data
},
success: (res) => {
console.info(`sendBuddyMessage success: ${JSON.stringify(res)}`);
//跳转到扫码页面
},
fail: (res) => {
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
}
});
},
//同步兑换券到后台
sendConvertCouponToBack(e){
......
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