TestController.php
5.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
<?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
{
/**
* 恢复父级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(){
$uids = Db::name('indent_over')->group('uid')->column('uid');
$indent = Db::name('indent')->whereIn('salesman_uid',$uids)->select();
$insert = [];
foreach ($indent as $v) {
unset($v['id']);
$insert[] = $v;
}
Db::name('indent_pro')->insertAll($insert);
// $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;
}
}
}