User.php
22.1 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* Date: 2015-09-09
*/
namespace app\manager\controller;
use think\AjaxPage;
use think\Page;
use think\Verify;
use think\Db;
use app\manager\logic\UsersLogic;
class User extends Base {
public function index(){
return $this->fetch();
}
/**
* 会员列表
*/
public function ajaxindex(){
// 搜索条件
$condition = array();
I('mobile') ? $condition['mobile'] = I('mobile') : false;
I('email') ? $condition['email'] = I('email') : false;
$sort_order = I('order_by','user_id').' '.I('sort','desc');
$model = M('users');
$count = $model->where($condition)->count();
$Page = new AjaxPage($count,10);
// 搜索条件下 分页赋值
foreach($condition as $key=>$val) {
$Page->parameter[$key] = urlencode($val);
}
$userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow.','.$Page->listRows)->select();
$user_id_arr = get_arr_column($userList, 'user_id');
if(!empty($user_id_arr))
{
$first_leader = DB::query("select first_leader,count(1) as count from __PREFIX__users where first_leader in(". implode(',', $user_id_arr).") group by first_leader");
$first_leader = convert_arr_key($first_leader,'first_leader');
$second_leader = DB::query("select second_leader,count(1) as count from __PREFIX__users where second_leader in(". implode(',', $user_id_arr).") group by second_leader");
$second_leader = convert_arr_key($second_leader,'second_leader');
$third_leader = DB::query("select third_leader,count(1) as count from __PREFIX__users where third_leader in(". implode(',', $user_id_arr).") group by third_leader");
$third_leader = convert_arr_key($third_leader,'third_leader');
}
$this->assign('first_leader',$first_leader);
$this->assign('second_leader',$second_leader);
$this->assign('third_leader',$third_leader);
$show = $Page->show();
$this->assign('userList',$userList);
$this->assign('level',M('user_level')->getField('level_id,level_name'));
$this->assign('page',$show);// 赋值分页输出
$this->assign('pager',$Page);
return $this->fetch();
}
/**
* 会员详细信息查看
*/
public function detail(){
$uid = I('get.id');
$user = D('users')->where(array('user_id'=>$uid))->find();
if(!$user)
exit($this->error('会员不存在'));
if(IS_POST){
// 会员信息编辑
$password = I('post.password');
$password2 = I('post.password2');
if($password != '' && $password != $password2){
exit($this->error('两次输入密码不同'));
}
if($password == '' && $password2 == ''){
unset($_POST['password']);
}else{
$_POST['password'] = encrypt($_POST['password']);
}
$row = M('users')->where(array('user_id'=>$uid))->save($_POST);
if($row)
exit($this->success('修改成功'));
exit($this->error('未作内容修改或修改失败'));
}
$user['first_lower'] = M('users')->where("first_leader = {$user['user_id']}")->count();
$user['second_lower'] = M('users')->where("second_leader = {$user['user_id']}")->count();
$user['third_lower'] = M('users')->where("third_leader = {$user['user_id']}")->count();
$this->assign('user',$user);
return $this->fetch();
}
public function add_user(){
if(IS_POST){
$data = I('post.');
$user_obj = new UsersLogic();
$res = $user_obj->addUser($data);
if($res['status'] == 1){
$this->success('添加成功',U('User/index'));exit;
}else{
$this->error('添加失败,'.$res['msg']);
}
}
return $this->fetch();
}
/**
* 用户收货地址查看
*/
public function address(){
$uid = I('get.id');
$lists = D('user_address')->where(array('user_id'=>$uid))->select();
$regionList = M('Region')->getField('id,name');
$this->assign('regionList',$regionList);
$this->assign('lists',$lists);
return $this->fetch();
}
/**
* 删除会员
*/
public function delete(){
$uid = I('get.id');
$row = M('users')->where(array('user_id'=>$uid))->delete();
if($row){
$this->success('成功删除会员');
}else{
$this->error('操作失败');
}
}
/**
* 账户资金记录
*/
public function account_log(){
$user_id = I('get.id');
//获取类型
$type = I('get.type');
//获取记录总数
$count = M('account_log')->where(array('user_id'=>$user_id))->count();
$page = new Page($count);
$lists = M('account_log')->where(array('user_id'=>$user_id))->order('change_time desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('user_id',$user_id);
$this->assign('page',$page->show());
$this->assign('lists',$lists);
return $this->fetch();
}
/**
* 账户资金调节
*/
public function account_edit(){
$user_id = I('get.id');
if(!$user_id > 0)
$this->error("参数有误");
if(IS_POST){
//获取操作类型
$m_op_type = I('post.money_act_type');
$user_money = I('post.user_money');
$user_money = $m_op_type ? $user_money : 0-$user_money;
$p_op_type = I('post.point_act_type');
$pay_points = I('post.pay_points');
$pay_points = $p_op_type ? $pay_points : 0-$pay_points;
$f_op_type = I('post.frozen_act_type');
$frozen_money = I('post.frozen_money');
$frozen_money = $f_op_type ? $frozen_money : 0-$frozen_money;
$desc = I('post.desc');
if(!$desc)
$this->error("请填写操作说明");
if(accountLog($user_id,$user_money,$pay_points,$desc)){
$this->success("操作成功",U("Admin/User/account_log",array('id'=>$user_id)));
}else{
$this->error("操作失败");
}
exit;
}
$this->assign('user_id',$user_id);
return $this->fetch();
}
public function recharge(){
$timegap = I('timegap');
$nickname = I('nickname');
$map = array();
if($timegap){
$gap = explode(' - ', $timegap);
$begin = $gap[0];
$end = $gap[1];
$map['ctime'] = array('between',array(strtotime($begin),strtotime($end)));
}
if($nickname){
$map['nickname'] = array('like',"%$nickname%");
}
$count = M('recharge')->where($map)->count();
$page = new Page($count);
$lists = M('recharge')->where($map)->order('ctime desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('page',$page->show());
$this->assign('pager',$page);
$this->assign('lists',$lists);
return $this->fetch();
}
public function level(){
$act = I('GET.act','add');
$this->assign('act',$act);
$level_id = I('GET.level_id');
$level_info = array();
if($level_id){
$level_info = D('user_level')->where('level_id='.$level_id)->find();
$this->assign('info',$level_info);
}
return $this->fetch();
}
public function levelList(){
$Ad = M('user_level');
$p = $this->request->param('p');
$res = $Ad->where('1=1')->order('level_id')->page($p.',10')->select();
if($res){
foreach ($res as $val){
$list[] = $val;
}
}
$this->assign('list',$list);
$count = $Ad->where('1=1')->count();
$Page = new Page($count,10);
$show = $Page->show();
$this->assign('page',$show);
return $this->fetch();
}
public function levelHandle(){
$data = I('post.');
if($data['act'] == 'add'){
$r = D('user_level')->add($data);
}
if($data['act'] == 'edit'){
$r = D('user_level')->where('level_id='.$data['level_id'])->save($data);
}
if($data['act'] == 'del'){
$r = D('user_level')->where('level_id='.$data['level_id'])->delete();
if($r) exit(json_encode(1));
}
if($r){
$this->success("操作成功",U('Admin/User/levelList'));
}else{
$this->error("操作失败",U('Admin/User/levelList'));
}
}
/**
* 搜索用户名
*/
public function search_user()
{
$search_key = trim(I('search_key'));
if(strstr($search_key,'@'))
{
$list = M('users')->where(" email like '%$search_key%' ")->select();
foreach($list as $key => $val)
{
echo "<option value='{$val['user_id']}'>{$val['email']}</option>";
}
}
else
{
$list = M('users')->where(" mobile like '%$search_key%' ")->select();
foreach($list as $key => $val)
{
echo "<option value='{$val['user_id']}'>{$val['mobile']}</option>";
}
}
exit;
}
/**
* 分销树状关系
*/
public function ajax_distribut_tree()
{
$list = M('users')->where("first_leader = 1")->select();
return $this->fetch();
}
/**
*
* @time 2016/08/31
* @author dyr
* 发送站内信
*/
public function sendMessage()
{
$user_id_array = I('get.user_id_array');
$users = array();
if (!empty($user_id_array)) {
$users = M('users')->field('user_id,nickname')->where(array('user_id' => array('IN', $user_id_array)))->select();
}
$this->assign('users',$users);
return $this->fetch();
}
/**
* 发送系统消息
* @author dyr
* @time 2016/09/01
*/
public function doSendMessage()
{
$call_back = I('call_back');//回调方法
$text= I('post.text');//内容
$type = I('post.type', 0);//个体or全体
$admin_id = session('admin_id');
$users = I('post.user/a');//个体id
$message = array(
'admin_id' => $admin_id,
'message' => $text,
'category' => 0,
'send_time' => time()
);
if ($type == 1) {
//全体用户系统消息
$message['type'] = 1;
M('Message')->add($message);
} else {
//个体消息
$message['type'] = 0;
if (!empty($users)) {
$create_message_id = M('Message')->add($message);
foreach ($users as $key) {
M('user_message')->add(array('user_id' => $key, 'message_id' => $create_message_id, 'status' => 0, 'category' => 0));
}
}
}
echo "<script>parent.{$call_back}(1);</script>";
exit();
}
/**
*
* @time 2016/09/03
* @author dyr
* 发送邮件
*/
public function sendMail()
{
$user_id_array = I('get.user_id_array');
$users = array();
if (!empty($user_id_array)) {
$user_where = array(
'user_id' => array('IN', $user_id_array),
'email' => array('neq', '')
);
$users = M('users')->field('user_id,nickname,email')->where($user_where)->select();
}
$this->assign('smtp', tpCache('smtp'));
$this->assign('users', $users);
return $this->fetch();
}
/**
* 发送邮箱
* @author dyr
* @time 2016/09/03
*/
public function doSendMail()
{
$call_back = I('call_back');//回调方法
$message = I('post.text');//内容
$title = I('post.title');//标题
$users = I('post.user/a');
if (!empty($users)) {
$user_id_array = implode(',', $users);
$users = M('users')->field('email')->where(array('user_id' => array('IN', $user_id_array)))->select();
$to = array();
foreach ($users as $user) {
if (check_email($user['email'])) {
$to[] = $user['email'];
}
}
$res = send_email($to, $title, $message);
echo "<script>parent.{$call_back}({$res});</script>";
exit();
}
}
/**
* 提现申请记录
*/
public function withdrawals()
{
$model = M("withdrawals");
$_GET = array_merge($_GET,$_POST);
unset($_GET['create_time']);
$status = I('status');
$user_id = I('user_id');
$account_bank = I('account_bank');
$account_name = I('account_name');
$create_time = I('create_time');
$create_time = $create_time ? $create_time : date('Y/m/d',strtotime('-1 year')).'-'.date('Y/m/d',strtotime('+1 day'));
$create_time2 = explode('-',$create_time);
$where = " create_time >= '".strtotime($create_time2[0])."' and create_time <= '".strtotime($create_time2[1])."' ";
if($status === '0' || $status > 0)
$where .= " and status = $status ";
$user_id && $where .= " and user_id = $user_id ";
$account_bank && $where .= " and account_bank like '%$account_bank%' ";
$account_name && $where .= " and account_name like '%$account_name%' ";
$count = $model->where($where)->count();
$Page = new Page($count,16);
$list = $model->where($where)->order("`id` desc")->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('create_time',$create_time);
$show = $Page->show();
$this->assign('show',$show);
$this->assign('pager',$Page);
$this->assign('list',$list);
C('TOKEN_ON',false);
return $this->fetch();
}
/**
* 删除申请记录
*/
public function delWithdrawals()
{
$model = M("withdrawals");
$model->where('id ='.$_GET['id'])->delete();
$return_arr = array('status' => 1,'msg' => '操作成功','data' =>'',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',);
$this->ajaxReturn($return_arr);
}
/**
* 修改编辑 申请提现
*/
public function editWithdrawals()
{
$id = I('id');
$withdrawals = DB::name('withdrawals')->where('id',$id)->find();
$user = M('users')->where("user_id = {$withdrawals[user_id]}")->find();
if (IS_POST) {
$data = I('post.');
// 如果是已经给用户转账 则生成转账流水记录
if ($data['status'] == 1 && $withdrawals['status'] != 1) {
if ($user['user_money'] < $withdrawals['money']) {
$this->error("用户余额不足{$withdrawals['money']},不够提现");
exit;
}
accountLog($withdrawals['user_id'], ($withdrawals['money'] * -1), 0, "平台提现");
$remittance = array(
'user_id' => $withdrawals['user_id'],
'bank_name' => $withdrawals['bank_name'],
'account_bank' => $withdrawals['account_bank'],
'account_name' => $withdrawals['account_name'],
'money' => $withdrawals['money'],
'status' => 1,
'create_time' => time(),
'admin_id' => session('admin_id'),
'withdrawals_id' => $withdrawals['id'],
'remark' => $data['remark'],
);
M('remittance')->add($remittance);
}
DB::name('withdrawals')->update($data);
$this->success("操作成功!", U('Admin/User/remittance'), 3);
exit;
}
if ($user['nickname'])
$withdrawals['user_name'] = $user['nickname'];
elseif ($user['email'])
$withdrawals['user_name'] = $user['email'];
elseif ($user['mobile'])
$withdrawals['user_name'] = $user['mobile'];
$this->assign('user', $user);
$this->assign('data', $withdrawals);
return $this->fetch();
}
public function withdrawals_update(){
$id = I('id/a');
$status = I('status');
$withdrawals = M('withdrawals')->where('id','in', $id)->select();
if($status == 1){
$r = M('withdrawals')->where('id','in', $id)->save(array('status'=>$status,'check_time'=>time()));
}else if($status == -1){
$r = M('withdrawals')->where('id','in', $id)->save(array('status'=>$status,'refuse_time'=>time()));
}else if($status == 2){
foreach($withdrawals as $val){
$user = M('users')->where(array('user_id'=>$val['user_id']))->find();
if($user['user_money'] < $val['money'])
{
$data['status'] = -2;
$data['remark'] = '账户余额不足';
M('withdrawals')->where(array('id'=>$val['id']))->save($data);
}else{
if($val['bank_name'] == '支付宝 '){
//流水号1^收款方账号1^收款账号姓名1^付款金额1^备注说明1|流水号2^收款方账号2^收款账号姓名2^付款金额2^备注说明2
$alipay['batch_no'] = time();
$alipay['batch_fee'] += $val['money'];
$alipay['batch_num'] += 1;
$str = isset($alipay['detail_data']) ? '|' : '';
$alipay['detail_data'] .= $str.$val['pay_code'].'^'.$val['account_bank'].'^'.$val['realname'].'^'.$val['money'].'^'.$val['remark'];
}
if($val['bank_name'] == '微信'){
$wxpay = array(
'userid' => $val['user_id'],//用户ID做更新状态使用
'openid' => $val['account_bank'],//收钱的人微信 OPENID
'pay_code'=>$val['pay_code'],//提现申请ID
'money' => $val['money'],//金额
'desc' => '恭喜您提现申请成功!'
);
$res = $this->transfer('weixin',$wxpay);//微信在线付款转账
if($res['partner_trade_no']){
accountLog($val['user_id'], ($val['money'] * -1), 0,"平台处理用户提现申请");
$r = M('withdrawals')->where(array('id'=>$val['id']))->save(array('status'=>$status,'pay_time'=>time()));
}else{
$this->ajaxReturn(array('status'=>0,'msg'=>$res['msg']),'JSON');
}
}
}
}
if(!empty($alipay)){
$this->transfer('alipay',$alipay);
}
$this->ajaxReturn(array('status'=>1,'msg'=>"操作成功"),'JSON');
}else if($status == 3){
$r = M('withdrawals')->where('id in ('.implode(',', $id).')')->delete();
}else{
accountLog($val['user_id'], ($val['money'] * -1), 0,"管理员处理用户提现申请");//手动转账,默认视为已通过线下转方式处理了该笔提现申请
$r = M('withdrawals')->where('id in ('.implode(',', $id).')')->save(array('status'=>2,'pay_time'=>time()));
}
if($r){
$this->ajaxReturn(array('status'=>1,'msg'=>"操作成功"),'JSON');
}else{
$this->ajaxReturn(array('status'=>0,'msg'=>"操作失败"),'JSON');
}
}
public function transfer($atype,$data){
if($atype == 'weixin'){
include_once PLUGIN_PATH."payment/weixin/weixin.class.php";
$wxpay_obj = new \weixin();
return $wxpay_obj->transfer($data);
}else{
//支付宝在线批量付款
include_once PLUGIN_PATH."payment/alipay/alipay.class.php";
$alipay_obj = new \alipay();
return $alipay_obj->transfer($data);
}
}
/**
* 转账汇款记录
*/
public function remittance(){
$model = M("remittance");
$_GET = array_merge($_GET,$_POST);
unset($_GET['create_time']);
$user_id = I('user_id');
$account_bank = I('account_bank');
$account_name = I('account_name');
$create_time = I('create_time');
$create_time = $create_time ? $create_time : date('Y-m-d',strtotime('-1 year')).' - '.date('Y-m-d',strtotime('+1 day'));
$create_time2 = explode(' - ',$create_time);
$this->assign('start_time',$create_time2[0]);
$this->assign('end_time',$create_time2[1]);
$where = " create_time >= '".strtotime($create_time2[0])."' and create_time <= '".strtotime($create_time2[1])."' ";
$user_id && $where .= " and user_id = $user_id ";
$account_bank && $where .= " and account_bank like '%$account_bank%' ";
$account_name && $where .= " and account_name like '%$account_name%' ";
$count = $model->where($where)->count();
$Page = new Page($count,16);
$list = $model->where($where)->order("`id` desc")->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('pager',$Page);
$this->assign('create_time',$create_time);
$show = $Page->show();
$this->assign('show',$show);
$this->assign('list',$list);
C('TOKEN_ON',false);
return $this->fetch();
}
}