PersonalcenterController.php
13.9 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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\WeChatBaseController;
use think\Db;
class sendAPI {
public $data; //发送数据
public $timeout = 30; //超时
private $apiUrl; //发送地址
private $username; //用户名
private $password; //密码
function __construct($url, $username, $password) {
$this->apiUrl = $url;
$this->username = $username;
$this->password = $password;
}
private function httpGet() {
$url = $this->apiUrl . '?' . http_build_query($this->data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error GET '.curl_error($curl);
}
curl_close($curl);
return $res;
}
private function httpPost(){ // 模拟提交数据函数
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $this->apiUrl); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->data)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Error POST'.curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $result; // 返回数据
}
/**
* @param $type|提交类型 POST/GET
* @param $isTranscoding|是否需要转 $isTranscoding 是否需要转utf-8 默认 false
* @return mixed
*/
public function sendSMS($type, $isTranscoding = false) {
$this->data['content'] = $isTranscoding === true ? mb_convert_encoding($this->data['content'], "UTF-8") : $this->data['content'];
$this->data['username'] = $this->username;
$this->data['tkey'] = date('YmdHis');
$this->data['password'] = md5(md5($this->password) . $this->data['tkey']);
return $type == "POST" ? $this->httpPost() : $this->httpGet();
}
}
class PersonalcenterController extends WeChatBaseController{
/**
* 显示个人中心页
*/
public function personal_center(){
$uid = cmf_get_current_user_id();
$my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
$weixin = Db::name('user') -> where('id',$uid) -> find();
$this -> assign('weixin',$weixin);
if($my_user_status['status'] == 0 || $my_user_status['status'] == 1 || $my_user_status['status'] == 3 || $my_user_status['status'] == 4 || $my_user_status['status'] == 5 || $my_user_status['status'] == 6){
if($my_user_status['status'] == 0){
$this -> assign('status',0);
}
if($my_user_status['status'] == 1 || $my_user_status['status'] == 5 || $my_user_status['status'] == 6){
$this -> assign('status',1);
}
if($my_user_status['status'] == 3){
$this -> assign('status',3);
}
if($my_user_status['status'] == 4){
$this -> assign('status',4);
}
return $this -> fetch();
}
//业务员个人中心页
if($my_user_status['status'] == 2){
$this -> assign('weixin',$weixin);
return $this -> fetch('personalcenter/salesman_center');
}
}
/**
* 完善个人信息页
*/
public function perfect_information(){
$uid = cmf_get_current_user_id();
$my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
if($my_user_status['status'] == 2){
$this -> redirect('Personalcenter/personal_center');
}else{
if($my_user_status['status'] == 1){
$this -> assign('status',1);
}
if($my_user_status['status'] == 5){
$this -> assign('status',5);
}
if($my_user_status['status'] == 6){
$this -> assign('status',6);
}
$weixin = Db::name('user') -> where('id',$uid) -> find();
$this -> assign('weixin',$weixin);
return $this -> fetch();
}
}
/**
* 我的收藏页
*/
public function personal_collect(){
$uid = cmf_get_current_user_id();
$data = Db::name('collect') -> where("uid =".$uid) -> select();
$data_count = count($data);
if(!empty($data)){
foreach($data as $key => $val){
$data_goods[] = Db::name('goods') -> where("id =".$val['goods_id']) -> find();
}
foreach ($data_goods as $key => $val){
$price = explode('.',$val['price']);
$pricing = explode('.',$val['pricing']);
$data_goods[$key]['price0'] = $price[0];
$data_goods[$key]['price1'] = $price[1];
$data_goods[$key]['pricing0'] = $pricing[0];
$data_goods[$key]['pricing1'] = $pricing[1];
}
}else{
$data_goods = '';
}
$this -> assign('data_count',$data_count);
$this -> assign('data_goods',$data_goods);
return $this -> fetch();
}
/**
* 填写个人信息页
*/
public function add_information(){
return $this -> fetch();
}
/**
* 浏览记录
*/
public function browsing_history(){
$uid = cmf_get_current_user_id();
$data = Db::name('browsing_history') -> where("uid =".$uid) -> select();
foreach($data as $key => $val){
$data_goods[] = Db::name('goods') -> where('id',$val['goods_id']) -> find();
}
if(!empty($data_goods)){
foreach($data_goods as $key => $val){
$price = explode('.',$val['price']);
$classification_name = Db::name('classification') -> where('id',$val['classify_id']) -> find();
$data_goods[$key]['classification_name'] = $classification_name['name'];
$data_goods[$key]['price0'] = $price[0];
$data_goods[$key]['price1'] = $price[1];
}
}else{
$data_goods = '';
}
$this -> assign('data_goods',$data_goods);
return $this -> fetch();
}
/**
* 收货地址页
*/
public function shop_address(){
$data = Db::name('address') -> where("delete_time = 0") -> select() -> toArray();
if(!empty($data)){
foreach($data as $key => $val){
$detailed = explode(',',$val['detailed']);
$data[$key]['detailed'] = $detailed[0].$detailed[1];
}
}
$this -> assign('data',$data);
return $this -> fetch();
}
/**
* 新增地址页
*/
public function add_shop_address(){
if($this -> request -> isPost()){
$uid = cmf_get_current_user_id();
$_POST['uid'] = $uid;
$add = Db::name('address') -> insert($_POST);
if($add){
return true;
}else{
return false;
}
}else{
return $this -> fetch();
}
}
/**
* 设置默认地址
*/
public function set_default_address(){
$uid = cmf_get_current_user_id();
Db::name('address') -> where('uid',$uid) -> update(['default_address'=>0]);
$data = Db::name('address') -> where('id',$_POST['id']) -> update(['default_address'=>1]);
if($data){
return true;
}else{
return false;
}
}
/**
* 删除地址
*/
public function address_del(){
$delete_time = time();
$data = Db::name('address') -> where('id',$_POST['id']) -> update(['delete_time'=>$delete_time]);
if($data){
return true;
}else{
return false;
}
}
/**
* 编辑地址
*/
public function address_edit(){
if($this -> request -> isPost()){
$data_update = Db::name('address') -> update($_POST);
if($data_update){
return true;
}else{
return false;
}
}else{
$id = $this -> request -> param();
$data = Db::name('address') -> where('id',$id['id']) -> find();
$detailed = explode(',',$data['detailed']);
$data['detailed0'] = $detailed[0];
$data['detailed1'] = $detailed[1];
$this -> assign('data',$data);
return $this -> fetch();
}
}
/**
* 发送短信
*/
public function send_message(){
$url = "http://www.ztsms.cn/sendNSms.do";//提交地址
$username = 'xuekaowuyou';//用户名
$password = 'Cxz307312';//原密码
$sendAPI = new sendAPI($url, $username, $password);
$key = '';
$pattern='1234567890';
for( $i=0; $i<6; $i++ ) {
$key .= $pattern[mt_rand(0, 9)];
}
session('code',$key);
$rand_name = "验证码:".$key."【学考无忧】";
$phone = $_POST['phone'];
$data = array(
'content' => $rand_name,//短信内容
'mobile' => $phone,//手机号码
'productid' => '676767',//产品id
'xh' => ''//小号
);
$sendAPI->data = $data;//初始化数据包
$return = $sendAPI->sendSMS('POST');//GET or POST
if($return){
return true;
}else{
return false;
}
}
/**
* 添加审核信息
*/
public function add_audit(){
$code = session('code');
if($code == $_POST['code']){
$data['name'] = $_POST['name'];
$data['phone'] = $_POST['phone'];
$data['id_number'] = $_POST['id_num'];
$data['img_front'] = $_POST['img0'];
$data['img_back'] = $_POST['img1'];
$data['create_time'] = time();
$data['uid'] = cmf_get_current_user_id();
$inser = Db::name('sale_audit') -> insert($data);
if($inser){
Db::name('my_user') -> where('uid',$data['uid']) -> update(['status'=>5]);
return 1;
}else{
return 2;
}
}else{
return 3;
}
}
/**
* 我的钱包页
*/
public function my_wallet(){
$uid = cmf_get_current_user_id();
$balance = Db::name('my_user') -> where("uid",$uid) -> find();
$balance['balance'] = $balance['balance'] - $balance['balance']*0.006;
$money_income = Db::name("money_income") -> where('uid',$uid) -> select();
$cumulative_money = 0;
foreach ($money_income as $key => $val){
$cumulative_money += $val['money'];
}
$cumulative_money = $cumulative_money-$cumulative_money*0.006;
$money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
$this -> assign('money_ratio',$money_ratio);
$this -> assign('balance',$balance['balance']);
$this -> assign('cumulative_money',$cumulative_money);
$money_expend = Db::name('money_expend') -> where('uid='.$uid." and state=0") -> select();
$money = 0;
foreach ($money_expend as $key => $val){
$money += $val['money'];
}
$this -> assign('status',$balance['status']);
$this -> assign('money',$money);
return $this -> fetch();
}
/**
* 将提现金额存入支出明细表
*/
public function add_money_expend(){
$_POST['uid'] = cmf_get_current_user_id();
$_POST['create_time'] = time();
$_POST['state'] = 0;
$data = Db::name('money_expend') -> insert($_POST);
$money_expend = Db::name('money_expend') -> where('uid='.$_POST['uid']." and state=0") -> select();
$money = 0;
foreach ($money_expend as $key => $val){
$money += $val['money'];
}
if($data){
return $money;
}else{
return false;
}
}
/**
* 邀请名单
*/
public function invitation_list(){
$uid = cmf_get_current_user_id();
$my_user = Db::name('my_user') -> where('uid',$uid) -> find();
if($my_user['status'] == 3){
$student_user = Db::name('my_user') -> where('pid',$my_user['id']) -> select();
foreach ($student_user as $key => $val){
$indent[] = Db::name('indent') -> where('uid',$val['uid']) -> select();
foreach ($indent as $key => $val){
/*$indent[$key]['indent_goods'] = Db::name() -> where() -> */
}
}
}elseif ($my_user['status'] == 2){
}
return $this -> fetch();
}
}