site.php
8.81 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* [WeEngine System] Copyright (c) 2014 WE7.CC
* WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
*/
defined('IN_IA') or exit('Access Denied');
class PaycenterModuleSite extends WeModuleSite {
public function __construct() {
global $_W, $_GPC;
load()->model('paycenter');
if($_GPC['do'] != 'pay' && $_GPC['do'] != 'consume') {
$session = json_decode(base64_decode($_GPC['_pc_session']), true);
if(is_array($session)) {
load()->model('user');
$user = user_single(array('uid'=>$session['uid']));
if(is_array($user) && $session['hash'] == md5($user['password'] . $user['salt'])) {
$clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'uid' => $user['uid']));
if(empty($clerk)) {
message('您没有管理该店铺的权限', referer(), 'error');
}
$_W['uid'] = $user['uid'];
$_W['username'] = $user['username'];
$_W['user'] = $user;
} else {
isetcookie('_pc_session', false, -100);
}
unset($user);
}
if(empty($_W['user']) && $_W['openid'] && $_GPC['_wechat_logout'] != '1') {
$clerk = pdo_get('activity_clerks', array('openid' => $_W['openid'], 'uniacid' => $_W['uniacid']));
if(!empty($clerk)) {
$user = pdo_get('users', array('uid' => $clerk['uid']));
if(!empty($user)) {
$cookie = array();
$cookie['uid'] = $user['uid'];
$cookie['username'] = $user['username'];
$cookie['hash'] = md5($user['password'] . $user['salt']);
$session = base64_encode(json_encode($cookie));
isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
$_W['uid'] = $user['uid'];
$_W['username'] = $user['username'];
$_W['user'] = $user;
}
}
}
}
}
public function doMobileLogin() {
global $_W, $_GPC;
if(!empty($_W['user'])) {
header('Location:' . $this->createMobileUrl('home'));
die;
}
if($_W['isajax']) {
load()->model('user');
$user['username'] = trim($_GPC['username']);
$user['password'] = trim($_GPC['password']);
$user = user_single($user);
if(empty($user)) {
message(error(-1, '账号或密码错误'), '', 'ajax');
}
if($user['status'] == 1) {
message(error(-1, '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决'), '', 'ajax');
}
$clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'uid' => $user['uid']));
if(empty($clerk)) {
message(error(-1, '您没有管理该店铺的权限'), '', 'ajax');
}
$cookie = array();
$cookie['uid'] = $user['uid'];
$cookie['hash'] = md5($user['password'] . $user['salt']);
$session = base64_encode(json_encode($cookie));
isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
message(error(0, ''), '', 'ajax');
}
include $this->template('login');
}
public function doMobileLogout() {
isetcookie('_pc_session', '', -10000);
isetcookie('_wechat_logout', '1', 180);
$forward = $_GPC['forward'];
if(empty($forward)) {
$forward = './?refersh';
}
header('Location:' . $this->createMobileUrl('login'));
die;
}
public function doMobileHome() {
global $_W, $_GPC;
paycenter_check_login();
$user_permission = permission_account_user('system');
$today_revenue = $this->revenue(0);
$yesterday_revenue = $this->revenue(-1);
$seven_revenue = $this->revenue(-7);
include $this->template('home');
}
public function revenue($period) {
global $_W;
if($period == '0') {
$starttime = strtotime(date('Y-m-d'));
$endtime = $starttime + 86400;
} else {
$starttime = strtotime(date('Y-m-d',strtotime($period . 'day')));
$endtime = strtotime(date('Y-m-d'));
}
$condition = "WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime AND clerk_id = :clerk_id";
$params = array(':starttime' => $starttime, ':endtime' => $endtime, ':uniacid' => $_W['uniacid'], ':clerk_id' => intval($_W['user']['clerk_id']));
$revenue = pdo_fetchcolumn("SELECT SUM(final_fee) FROM" . tablename('paycenter_order') . $condition, $params);
return floatval($revenue);
}
public function doMobilePay() {
global $_W, $_GPC;
$id = intval($_GPC['id']);
$order = pdo_get('paycenter_order', array('uniacid' => $_W['uniacid'], 'id' => $id));
if(empty($order)) {
message('订单不存在或已删除', '', 'error');
}
if($order['status'] == 1) {
message('该订单已付款', '', 'error');
}
if(!empty($_W['member']['uid']) || !empty($_W['fans'])) {
$update = array(
'uid' => $_W['member']['uid'],
'openid' => $_W['openid'],
'nickname' => $_W['fans']['nickname']
);
pdo_update('paycenter_order', $update, array('uniacid' => $_W['uniacid'], 'id' => $id));
$order['uid'] = $_W['member']['uid'];
}
$params['module'] = "paycenter_order";
$params['tid'] = $order['id'];
$params['ordersn'] = $order['id'];
$params['user'] = $order['uid'];
$params['fee'] = $order['final_fee'];
$params['title'] = $_W['account']['name'] . $order['body'] ? $order['body'] : '收银台收款';
$this->pay($params);
}
public function payResult($params) {
global $_W;
if($params['result'] == 'success' && $params['from'] == 'notify') {
$order = pdo_get('paycenter_order', array('id' => $params['tid'], 'uniacid' => $_W['uniacid']));
if(!empty($order)) {
if(!empty($params['tag'])) {
$params['tag'] = iunserializer($params['tag']);
}
$data = array(
'type' => $params['type'],
'trade_type' => strtolower($params['trade_type']),
'status' => 1,
'paytime' => TIMESTAMP,
'uniontid' => $params['tag']['uniontid'],
'transaction_id' => $params['tag']['transaction_id'],
'follow' => intval($params['follow']),
'final_fee' => $params['card_fee'],
);
if($params['type'] == 'credit') {
$data['credit2'] = $params['card_fee'];
} else {
$data['cash'] = $params['card_fee'];
}
if($params['is_usecard'] == 1) {
$discount_fee = $order['fee'] - $params['card_fee'];
$data['remark'] = "使用优惠券减免{$discount_fee}元";
}
pdo_update('paycenter_order', $data, array('id' => $params['tid'], 'uniacid' => $_W['uniacid']));
$cash_data = array(
'uniacid' => $_W['uniacid'],
'uid' => $order['uid'],
'fee' => $order['fee'],
'final_fee' => $order['final_fee'],
'credit1' => $order['credit1'],
'credit1_fee' => $order['credit1_fee'],
'credit2' => $order['credit2'],
'cash' => $params['card_fee'],
'final_cash' => $params['card_fee'],
'return_cash' => 0,
'remark' => $order['remark'],
'clerk_id' => $order['clerk_id'],
'store_id' => $order['store_id'],
'clerk_type' => $order['clerk_type'],
'createtime' => TIMESTAMP,
);
pdo_insert('mc_cash_record', $cash_data);
}
}
if($params['result'] == 'success' && $params['from'] == 'return') {
message('支付成功!', $this->createMobileUrl('paydetail', array('id' => $params['tid'])), 'success');
}
}
public function doMobilePayDetail() {
global $_W, $_GPC;
$id = intval($_GPC['id']);
$order = pdo_get('paycenter_order', array('id' => $id, 'uniacid' => $_W['uniacid']));
if(empty($order)) {
message('订单不存在或已删除', '', 'error');
}
if($order['store_id'] > 0) {
$store = pdo_get('activity_stores', array('id' => $order['store_id']), array('business_name'));
}
include $this->template('paydetail');
}
public function doMobileSelfpay() {
global $_W, $_GPC;
if(checksubmit()) {
$fee = trim($_GPC['fee']) ? trim($_GPC['fee']) : message('收款金额有误', '', 'error');
$body = trim($_GPC['body']) ? trim($_GPC['body']) : '收银台收款' . trim($_GPC['fee']);
$openid = trim($_GPC['openid']) ? trim($_GPC['openid']) : message('用户信息错误', '', 'error');
$clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'id' => intval($_GPC['clerk_id'])));
$data = array(
'uniacid' => $_W['uniacid'],
'openid' => $openid,
'nickname' => trim($_GPC['nickname']),
'uid' => $_W['member']['uid'],
'clerk_id' => $clerk['id'],
'clerk_type' => 3,
'store_id' => $clerk['storeid'],
'body' => $body,
'fee' => $fee,
'final_fee' => $fee,
'credit_status' => 1,
'createtime' => TIMESTAMP,
);
pdo_insert('paycenter_order', $data);
$id = pdo_insertid();
header('location:' . $this->createMobileUrl('pay', array('id' => $id)));
die;
}
$fans = mc_oauth_userinfo();
if(is_error($fans) || empty($fans)) {
message('获取粉丝信息失败', '', 'error');
}
include $this->template('selfpay');
}
public function doMobileConsume() {
global $_GPC, $_W;
$url = murl('entry', array('m' => 'we7_coupon', 'do' => 'consume', 'card_id' => trim($_GPC['card_id']), 'encrypt_code' => trim($_GPC['encrypt_code']), 'openid' => trim($_GPC['openid'])));
header("Location: $url");
exit;
}
}