TestController.php
19.0 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/8/21
* Time: 19:08
*/
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
class TestController extends HomeBaseController
{
protected $uid = 150; //83-serenity、267-杨恩兵、309-一生缘、295-孔亚芹、34316-菲博珂、330-121、39427-善通宝~培佑教育
protected $complete = [83];
public function prob()
{
ini_set('max_execution_time', 3600);//秒为单位,自己根据需要定义
ini_set('memory_limit','-1');
$uid = $this->uid;
$user = Db::name('user')->where('id',$uid)->find();
$user['my_user_id'] = Db::name('my_user')->where('uid',$uid)->value('id');
$data = [];
$state_arr = [
4 => '待付款',
2 => '待发货',
3 => '已完成',
5 => '已发货',
6 => '待取货'
];
$else_ids = [];
$indent_ids = Db::name('money_income')->where('uid',$uid)->group('indent_id')->column('indent_id');
foreach ($indent_ids as &$id) {
$v = Db::name('indent')->where('id',$id)->find();
// if(!$v) $else_ids[] = $id;
if($v['state'] == 2 || $v['state'] == 3 || $v['state'] == 5) {
$money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->value('money');
$fact_money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->sum('money');
// $income = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->select();
// $v['income'] = collection($income)->toArray();
$data[] = [
$v['id'],
$money,
$v['book_num'],
$v['name'],
$v['phone'],
$v['school'].'-'.$v['grade'].$v['class'],
$state_arr[$v['state']],
date('Y-m-d H:i:s',$v['create_time']),
date('Y-m-d H:i:s',$v['pay_time']),
$v['region'],
$v['beiyong_address'],
$money,
$fact_money,
$fact_money != $money ? '是' : '否'
];
}
}
// print_r($else_ids);exit;
// $indent = Db::name('indent')->where('salesman_uid',$uid)->order('create_time','desc')->select();
// $arr = collection($indent)->toArray();
// foreach ($arr as &$v) {
// if($v['state'] == 3 || $v['state'] == 5) {
// $money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->value('money');
// $fact_money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->sum('money');
//// $income = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->select();
//// $v['income'] = collection($income)->toArray();
// $data[] = [
// $v['id'],
// $money,
// $v['book_num'],
// $v['name'],
// $v['phone'],
// $v['school'].'-'.$v['grade'].$v['class'],
// $state_arr[$v['state']],
// date('Y-m-d H:i:s',$v['create_time']),
// date('Y-m-d H:i:s',$v['pay_time']),
// $v['region'],
// $v['beiyong_address'],
// $money,
// $fact_money,
// $fact_money != $money ? '是' : '否'
// ];
// }
// }
// 查询平台书籍收入金额
$this->excel($user,$data);
// print_r($arr);exit;
}
public function income()
{
$uid = $this->uid;
$user = Db::name('user')->where('id',$uid)->find();
$indent = Db::name('money_income')->where('uid',$uid)->order('create_time','desc')->select();
$arr = collection($indent)->toArray();
$data = [];
$tableheader = array('收入id', '收入金额', '订单id');
foreach ($arr as &$v) {
$data[] = [
$v['id'],
$v['money'],
$v['indent_id']
];
}
$this->excel2($data);
print_r($arr);exit;
}
public function withdraw_log()
{
$uid = $this->uid;
$money_expend = Db::name('money_expend')->where('uid',$uid)->where('state',1)->order('create_time','desc')->select();
$money_expend = collection($money_expend)->toArray();
$data = [];
foreach ($money_expend as $v) {
$data[] = [
date('Y-m-d H:i:s',$v['create_time']),
$v['money']
];
}
$this->excel3($data);
}
/**
*
* 导出Excel
*/
public function excel($user,$data2)
{
//引入PHPExcel库文件
// Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G','H','I','J','k','L','M');
$excel->getActiveSheet()->setCellValue("A1", "用户id");
$excel->getActiveSheet()->setCellValue("B1", $user['id']);
$excel->getActiveSheet()->setCellValue("C1", "业务员id");
$excel->getActiveSheet()->setCellValue("D1", $user['my_user_id']);
$excel->getActiveSheet()->setCellValue("E1", "业务员名称");
$excel->getActiveSheet()->setCellValue("F1", $user['user_nickname']);
//表头数组
$tableheader = array('订单号', '价钱', '数量', '姓名', '电话', '学校-班级', '订单状态', '创建时间', '支付时间', '配送时间', '地区',
'应得收益', '实际收益', '是否异常');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]2", "$tableheader[$i]");
}
//表格数组
$data = array(
array('1', 'B', 'C', 'D', 'E', 'F', 'G'),
array('2', 'B', 'C', 'D', 'E', 'F', 'G'),
array('3', 'B', 'C', 'D', 'E', 'F', 'G'),
array('4', 'B', 'C', 'D', 'E', 'F', 'G'),
array('5', 'B', 'C', 'D', 'E', 'F', 'G'),
array('6', 'B', 'C', 'D', 'E', 'F', 'G'),
array('7', 'B', 'C', 'D', 'E', 'F', 'G'),
);
// $tz = Db::name('taizhang');
// $data2 = $tz->field('type',true)->select();
//print_r($data2);exit();
//填充表格信息
for ($i = 3; $i <= count($data2) + 2; $i++) {
$j = 0;
foreach ($data2[$i - 3] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel2007($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="订单表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
/**
*
* 导出Excel
*/
public function excel2($data2)
{
//引入PHPExcel库文件
// Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B', 'C');
//表头数组
$tableheader = array('收入id', '收入金额', '订单id');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//填充表格信息
for ($i = 2; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 2] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel2007($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="收入表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
/**
*
* 导出Excel
*/
public function excel3($data2)
{
//引入PHPExcel库文件
// Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B');
//表头数组
$tableheader = array('提现时间', '提现金额');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//填充表格信息
for ($i = 2; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 2] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel2007($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="提现表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}
/**
* 恢复父级id
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function test(){
ini_set('max_execution_time', 3600);//秒为单位,自己根据需要定义
ini_set('memory_limit','-1');
// $b = Db::name('indent_pro')->where('salesman_uid',309)->update(['is_out'=>0]);
$page = $this->request->param('page',1);
$uid = Db::name('indent_pro')->where('is_out',0)->group('salesman_uid')->order('salesman_uid','desc')->value('salesman_uid');
if(!$uid) {
echo 123;exit;
}
// print_r($uid);exit;
$list = Db::name('indent_pro')->where('salesman_uid',$uid)->paginate(50,true,['page'=>$page]);
$list = $list->items();
$state_arr = ['2'=>'待发货','3'=>'已完成','5'=>'已发货','6'=>'待收货'];
$i = [];
foreach ($list as $v) {
$order = Db::name('indent')->where('salesman_uid',$v['salesman_uid'])->where('order_number',$v['order_number'])
->whereIn('state',['2','3','5','6'])->find();
if(!$order) continue;
$school_class = $v['school'].'-'.$v['grade'].$v['class'];
$salesman_name = Db::name('user')->where('id',$v['salesman_uid'])->value('user_nickname');
$award = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->value('money');
if($award) {
$award_fac = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->sum('money');
$i[] = [
'state_text' => $state_arr[$order['state']],
'order_number' => $order['order_number'],
'money' => $order['money'],
'create_time' => date('Y-m-d H:i:s',$order['create_time']),
'book_num' => $order['book_num'],
'leave_word' => $order['leave_word'],
'name' => $order['name'],
'phone' => $order['phone'],
'school_class' => $school_class,
'salesman_name' => $salesman_name,
'pay_time' => date('Y-m-d H:i:s',$order['pay_time']),
'start_time' => $order['start_time'],
'end_time' => $order['end_time'],
'region' => $order['region'],
'beiyong_address' => $order['beiyong_address'],
'award' => $award,
'award_fac' => $award_fac,
'is_pro' => $award_fac > $award ? '是' : '否'
];
}
}
$b = true;
Db::startTrans();
if(count($i) == 0) {
Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]);
$page = 0;
} else {
$a = Db::name('indent_orders')->insertAll($i);
if(count($i) < 50) {
$b = Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]);
$page = 0;
}
if(!$a || !$b) Db::rollback();
}
Db::commit();
$page = $page + 1;
sleep(1);
$this->redirect(url('portal/test/test',['page'=>$page],true,true));
// $sql = Db::name('indent_pro')->getLastSql();
// print_r($sql);
// print_r($uid);exit;
// $page = $this->request->param('page',1,'intval');
// $num = 2000;
//// $arr = [267,295,309];
// $uid = Db::name('indent_over')->where('status',0)
//// ->whereNotIn('uid',$arr)
// ->group('uid')->value('uid');
//// print_r($uid);exit;
// $list = Db::name('indent')->whereIn('salesman_uid',$uid)->paginate($num,true,['page'=>$page]);
// $indent = $list->items();
// $insert = [];
// foreach ($indent as $v) {
// unset($v['id']);
// $insert[] = $v;
// }
// $res = $res2 = true;
// Db::startTrans();
// if(count($indent) == 0) {
// $res2 = Db::name('indent_over')->where('uid',$uid)->update(['status'=>1]);
// } else {
// $res = Db::name('indent_pro')->insertAll($insert);
// }
// if(!$res || !$res2) Db::rollback();
// Db::commit();
// $all = Db::name('indent_over')->select();
// foreach ($all as $v) {
// $indent = Db::name('indent')->where('id',$v['indent_id'])->where('book_num',2)->count();
// if($indent) Db::name('indent_over')->where('id',$v['id'])->delete();
// $income = Db::name('money_income')->where('uid',$v['uid'])->where('indent_id',$v['indent_id'])->select();
// if(count($income) == 2) {
// $a = [];
// foreach ($income as $vv) {
// $a[] = $v['money'];
// }
// if($a[0] != $a[1]) {
// Db::name('indent_over')->where('id',$v['id'])->delete();
// }
// } else {
// Db::name('indent_over')->where('id',$v['id'])->delete();
// }
// }
// $indent_data = Db::query("select id,uid,money,indent_id,count(indent_id) count from `cmf_money_income` group by indent_id having count(indent_id) >= 4 order by indent_id desc");
// $a = [];
// foreach ($indent_data as $v) {
// if($v['count'] == 4) {
// $data = Db::name('money_income')->where('money','>',0)->where('indent_id',$v['indent_id'])->find();
// if($data) {
// $data['nickname'] = Db::name('user')->where('id',$data['uid'])->value('user_nickname');
// unset($data['id']);
// $a[] = $data;
// }
// }
// }
// Db::name('indent_over')->insertAll($a);
// print_r($a);exit;
// $data = Db::name('my_user')->where(['status'=>3,'inviter_phone'=>['neq','']])->select()->toArray();
// foreach($data as $key => $vo){
// $result = Db::name('my_user')->where(['phone'=>$vo['inviter_phone']])->value('id');
// if(!empty($result)){
// Db::name('my_user')->where(['id'=>$vo['id']])->update(['pid'=>$result]);
// }
// }
}
public function index(){
//生成带参二维码
$savePath=ROOT_PATH.'public/upload/code_img/';
if (!file_exists($savePath)){
mkdir($savePath, 0777,true);
}
$code_img = $this->code_img(28,3);
$code = file_get_contents($code_img);
file_put_contents(ROOT_PATH."public/upload/code_img/code_img28.png",$code);
echo cmf_get_image_url('code_img/code_img28.png');
}
/**
* 生成带参二维码
*/
public function code_img($admin_id,$status)
{
$options=config('wechat_config');
$app = new Application($options);
$accessToken = $app->access_token; // EasyWeChat\Core\AccessToken 实例
$token = $accessToken->getToken(false);
$url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $token;
$param = [
'expire_seconds' => '',
'action_name' => 'QR_LIMIT_STR_SCENE',
'action_info' => ['scene' => ['scene_str' => "$admin_id"."-"."$status"]]
];
$result = $this->api_notice_increment($url, json_encode($param));
$data = json_decode($result, true);
$ticket = urlencode($data['ticket']);
$qr_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
return $qr_url;
}
/**
* 获取二维码提交
*/
public function api_notice_increment($url, $data)
{
// $data=json_encode($data);
$ch = curl_init();
$header = array("Accept-Charset: utf-8");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
return $ch;
} else {
curl_close($ch);
return $tmpInfo;
}
}
}