UsersController.php
9.3 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
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use Dompdf\Image\Cache;
use think\Db;
class UsersController extends AdminBaseController{
public function get_over(){
$order = Db::name('indent')->whereIn('state',[2,3,5,6])
->whereBetween('pay_time',[1567958400,1568044799])
->sum('money');
echo $order.'--';
$zhichu = Db::name('money_expend')->where('state',1)
->whereBetween('create_time',[1567958400,1568044799])
->sum('money');
echo $zhichu;
$zhichu1 = Db::name('money_expend')->where('state',1)
->whereBetween('create_time',[1567958400,1568044799])
->column('id');
var_dump($zhichu1);
// $list = Db::name('money_income')->alias('mi')
// ->field('mi.*,i.uid as iuid,i.money as imoney,indent_type,salesman_uid')
// ->join('__INDENT__ i','mi.indent_id = i.id')
// ->where('i.state',2)
// ->select(false);
// var_dump($list);
}
public function over_count() {
$income = Db::name('money_income')->where('money','>',0)->select();
$income = collection($income)->toArray();
$ids = $user_ids = [];
$money = 0;
foreach ($income as $k=>$v) {
$indent = Db::name('indent')->where('id',$v['indent_id'])->find();
if(!$indent) {
$ids[] = $v['id'];
$user_ids[] = $v['uid'];
$money += $v['money'];
}
}
echo implode(',',$ids).'<br/>';
echo implode(',',$user_ids).'<br/>';
echo $money;
}
/**
* 显示用户列表
*/
public function user_list(){
$param = $this->request->param();
$where = [
'a.create_time' => ['>=', 0],
];
if(!empty($param['keyword'])){
$keyword = trim($param['keyword']);
$where['b.user_nickname|a.phone'] = ['like',"%$keyword%"];
}
if(!empty($param['id'])){
$where['a.id'] = ['eq',$param['id']];
}
if(!empty($param['identity'])){
if($param['identity'] == -1){
$where['a.status'] = ['eq',0];
}else{
$where['a.status'] = ['eq',$param['identity']];
}
}
$data = Db::name('my_user') -> alias('a')
->field('a.*,b.user_nickname')
->join('user b','a.uid = b.id','LEFT')
->where($where)
->order(['a.balance'=>'DESC','a.create_time'=>'DESC'])
->paginate(12);
$data->appends($param);
$list = $data->items();
foreach ($list as $k=>$v) {
// 获取邀请人昵称
$invite_nickname = '';
if($v['pid']) {
$invite = Db::name('my_user')->alias('m')
->field('u.user_nickname')
->join('user u','m.uid = u.id')
->where('m.id',$v['pid'])
->find();
$invite_nickname = $invite['user_nickname'];
}
$list[$k]['invite_nickname'] = $invite_nickname;
// 获取提现数据
$ti_count = Db::name('money_expend')->where('uid',$v['uid'])->where('state',1)->sum('money');// 已提金额
$list[$k]['ti_count'] = $ti_count;
$list[$k]['all_count'] = Db::name('money_income')->where('uid',$v['uid'])->sum('money');
// 获取邀请人数
$invite_count = 0;
if(in_array($v['status'],[2,3])) {
$invite_count = Db::name('my_user')
->alias('a')
->field('a.*,b.user_nickname')
->join('user b','a.uid = b.id','left')
->where('status',$v['status']+1)
->where('pid',$v['id'])
->count();
}
$list[$k]['invite_count'] = $invite_count;
}
// echo Db::name('my_user')->sum('balance');
// echo Db::name('indent')->where('indent_type',1)->where('state',5)->sum('money');
$this->assign('list',$list);
$this->assign('data',$data);
$this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
$this->assign('status',!empty($param['identity']) ? $param['identity'] : '');
$this->assign('id',!empty($param['id']) ? $param['id'] : '');
return $this->fetch();
}
/**
* 设置为业务员
*/
public function set_salesman(){
$id = $_POST['id'];
$data = Db::name('my_user') -> where('id',$id) -> update(['status'=>1]);
if($data){
return true;
}else{
return false;
}
}
/**
* 下线老师列表
*/
public function teacher_list(){
if($this -> request -> isPost()){
$where = [
'status' => 3,
'pid' => $_POST['salesman_id']
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($_POST['keyword'])){
$keyword = $_POST['keyword'];
$where['user_nickname'] = ['like',"%$keyword%"];
}
$this -> assign('salesman_id',$_POST['salesman_id']);
$data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(1000000);
$data_arr = $data -> toArray();
}else{
$id = $this -> request -> param();
$this -> assign('salesman_id',$id['id']);
$data = Db::name('my_user') -> where("status = 3 and pid =".$id['id']) -> paginate(12);
$data_arr = $data -> toArray();
foreach($data_arr['data'] as $key => $val){
$data_nick = Db::name('user') -> where('id',$data[$key]['uid']) -> find();
$data_arr['data'][$key]['user_nickname'] = $data_nick['user_nickname'];
}
}
foreach ($data_arr['data'] as $key => $val){
$money_income = Db::name('money_income') -> where('uid',$val['uid']) -> select();
$m_money = 0;
foreach ($money_income as $key1 => $val1){
$m_money += $val1['money'];
}
$data_arr['data'][$key]['money'] = $m_money;
}
$this -> assign('data',$data);
$this -> assign('data_arr',$data_arr['data']);
return $this -> fetch();
}
/**
* 下线学生列表
*/
public function student_list(){
if($this -> request -> isPost()){
$teacher_id = $_POST['teacher_id'];
$where = [
'a.status' => 4,
'a.pid' => $teacher_id
];
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($_POST['keyword'])){
$keyword = $_POST['keyword'];
$where['b.user_nickname'] = ['like',"%$keyword%"];
}
$data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(1000000);
}else{
$id = $this -> request -> param();
$teacher_id = $id['teacher_id'];
$data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where("a.status = 4 and a.pid =".$teacher_id) -> paginate(12);
}
$this -> assign('teacher_id',$teacher_id);
$this -> assign('data',$data);
return $this -> fetch();
}
/**
* 显示余额明细页
*/
public function users_money(){
$uid = $this -> request -> param();
$data = Db::name('money_income')->where('uid',$uid['uid'])->order('create_time','DESC')->select()->toArray();
if(!empty($data)){
foreach ($data as $key => $val){
if($val['type'] == 2){
$data[$key]['indent'] = Db::name('indent') -> where('id',$val['indent_id']) -> find();
$indent_good = Db::name('indent_goods') -> where('indent_id',$val['indent_id']) -> select() -> toArray();
$indent_goods = '';
foreach ($indent_good as $key1 => $val1){
$indent_goods .= $val1['book_name'].',';
}
$data[$key]['indent_good'] = $indent_goods;
}else{
$data[$key]['indent'] = Db::name('indent') -> where('id',$val['indent_id']) -> find();
$data[$key]['indent_good'] = $val['book_name'];
}
}
}
$this -> assign('data',$data);
return $this -> fetch();
}
}