pay_view.js
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
//定义全局变量
var order_id = '';
var order_status = 1;
//人民币转换红包券
$('.total').bind('input propertychange', function() {
var total = $(this).val();
if(total == ''){
$('.ticket').hide();
}else{
var ratio = $('.ratio').val();
var number = ratio/0.01*total;
$('.ticket').show().children('span').text(number);
}
});
//点击立即充值
$('.pay').click(function (){
var admin_id = $('.admin_id').val();
var total = $('.total').val();
if(total == ''){
top.window.Layer.open({
title:'温馨提示',
content:'请输入充值金额'
});
return false;
}else if(total<100){
top.window.Layer.open({
title:'温馨提示',
content:'充值金额不得小于100元'
});
return false;
}else if(!(/(^[1-9]\d*$)/.test(total))){
top.window.Layer.open({
title:'温馨提示',
content:'必须为整数'
});
return false;
}
$.ajax({
url:"pay_view/create_order",
type:"POST",
data:{'admin_id':admin_id,'total':total},
success:function(res){
if(res.code == 1){
order_id = res.data.order_id;
$('.qrcode').show().find('img').first().attr('src',window.location.protocol+"//"+window.location.host+"/admin/pay_view/pay/order_id/"+res.data.order_id);
}else{
top.window.Layer.open({
title:'温馨提示',
content:'与服务器连接失败'
});
}
},
error:function(){
top.window.Layer.open({
title:'温馨提示',
content:'与服务器连接失败'
});
}
})
});
setInterval(function(){order_pay()},3000);
function order_pay() {
console.log(order_id);console.log(order_status);
if(order_id != '' && order_status != 2){
$.ajax({
url:"pay_view/order_pay",
type:"POST",
data:{'order_id':order_id},
success:function(res){
console.log(res);
if(res.code == 1){
order_id = '';
order_status = 2;
top.window.Layer.open({
title:'温馨提示',
content:'支付成功',
});
window.location.href='';
}
},
error:function(res){
top.window.Layer.open({
title:'温馨提示',
content:'与服务器连接失败'
});
}
})
}
}
//点击立即提现
$('.withdraw').click(function(){
var admin_id = $('.admin_id').val();
var money = $('.money').val();
if(money == ''){
top.window.Layer.open({
title:'温馨提示',
content:'请输入提现金额'
});
return false;
}else if(money<50){
top.window.Layer.open({
title:'温馨提示',
content:'提现金额不得小于50元'
});
return false;
}else if(!(/(^[1-9]\d*$)/.test(money))){
top.window.Layer.open({
title:'温馨提示',
content:'必须为整数'
});
return false;
}
$.ajax({
url:"pay_view/create_withdraw",
type:"POST",
data:{'admin_id':admin_id,'money':money},
success:function(res){
if(res.code == 1){
top.window.Layer.open({
title:'温馨提示',
content:'提现申请已发送请等待审核',
});
window.location.href='';
}else{
top.window.Layer.open({
title:'温馨提示',
content:res.msg
});
}
},
error:function(){
top.window.Layer.open({
title:'温馨提示',
content:'与服务器连接失败'
});
}
})
});
Controller.api.bindevent();
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});