Agentusers.php
18.4 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
<?php
namespace app\admin\controller\agent;
use app\common\controller\Backend;
use think\Db;
use app\api\controller\v1\WxXcxQrcode;
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
/**
* 经纪人管理
*
* @icon fa fa-circle-o
*/
class Agentusers extends Backend
{
/**
* Agentusers模型对象
* @var \app\admin\model\agent\Agentusers
*/
protected $model = null;
protected $dataLimit = 'auth';
protected $dataLimitField = 'admin_id';
protected $relationSearch = true;
protected $searchFields = 'id,jjr_name,agentlist,jjr_mobile';
protected $selectpageFields = "id,jjr_name,agentlist,jjr_mobile";
protected $issupAdm;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\agent\Agentusers;
$this->view->assign("jjrTypeList", $this->model->getJjrTypeList());
$this->view->assign("jjrAgentStuList", $this->model->getJjrAgentStuList());
$this->view->assign("jjrPayStuList", $this->model->getJjrPayStuList());
$this->view->assign("getIndustry", $this->model->getIndustry());
//判断是否是超级管理员
if (in_array($this->auth->id, [1, 2, 26, 32, 37])) {
$isSup = 1;
} else {
$isSup = 0;
}
$this->issupAdm = $isSup;
$this->view->assign("isSup", $isSup);
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparamsAdm();
if ($this->issupAdm == 1) {
$list = $this->model
->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist'])
->where($where)
->order($sort, $order)
->paginate($limit);
} else {
$list = $this->model
->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist'])
->where($where)
->order($sort, $order)
->paginate($limit);
}
foreach ($list as $row) {
$row->visible(['id', 'user_id', 'jjr_sex', 'agent_shop_id', 'agent_list_id', 'jjr_type', 'user_cat_id', 'user_educat_id', 'jjr_name', 'jjr_image', 'createtime', 'updatetime', 'jjr_mobile', 'home_address', 'now_address', 'idcard', 'idcard_images', 'jjr_content', 'jjr_agent_stu', 'jjr_start_pay_time', 'jjr_end_pay_time', 'jjr_pay_stu', 'credit', 'addstep', 'jjr_type_uptime', 'is_stu_ok', 'is_test_ok', 'userno','industry']);
$row->visible(['agentusercat']);
$row->getRelation('agentusercat')->visible(['catname']);
$row->visible(['agentusereducat']);
$row->getRelation('agentusereducat')->visible(['educat_name']);
$row->visible(['agentlist']);
$row->getRelation('agentlist')->visible(['agent_name']);
$row->visible(['agentshoplist']);
$row->getRelation('agentshoplist')->visible(['shop_name']);
$row->visible(['user']);
$row->getRelation('user')->visible(['username', 'nickname']);
}
$rows = $list->items();
$getIndustry = $this->model->getIndustry();
foreach ($rows as $kk => $vv) {
//身份证处理
$rows[$kk]['idcard'] = tyssl_decode($vv['idcard']);
//判断入驻进度
if ($vv['jjr_pay_stu'] == '0' && $vv['is_stu_ok'] == '0' && $vv['is_test_ok'] == '0') {
$rows[$kk]['addstep'] = '未支付年费';
}
if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '0' && $vv['is_test_ok'] == '0') {
$rows[$kk]['addstep'] = '已支付年费';
}
/*
if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '0') {
$rows[$kk]['addstep'] = '培训完成,考试中';
}
if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '1' && $vv['jjr_type_uptime'] == 0) {
$rows[$kk]['addstep'] = '考试完成,未选择身份';
}
if ($vv['jjr_pay_stu'] == '1' && $vv['is_stu_ok'] == '1' && $vv['is_test_ok'] == '1' && $vv['jjr_type_uptime'] > 0) {
$rows[$kk]['addstep'] = '已完成';
}
*/
//判断入驻考试是否完成
$testok = getUserGradOk($vv['user_id']);
if ($testok == 1) {
$rows[$kk]['userno'] = '未经考试合格暂无工号';
}
//从事行业处理
$rows[$kk]['industry'] = !empty($vv['industry'])?$getIndustry[$vv['industry']]:'';
}
$result = array("total" => $list->total(), "rows" => $rows);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['idcard'] = tyssl_encode($params['idcard']);
//经纪人身份
$params['jjr_type_uptime'] = time();
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
//如果选择了企业,添加经纪人归属
$userup['admin_id'] = 2;
if ($params['jjr_type'] == '1') {
$userup['admin_id'] = agent_list_admin_id($params['agent_list_id']);
}
if ($params['jjr_agent_stu'] == "1") {
//审核通过;生成小程序二维码
$qrcode_api = new WxXcxQrcode();
$path = '/pages/home/broker/broker?id=' . $this->model->id;
$qrcode = $qrcode_api->qrcode($this->model->id, $path, true);
if (!empty($qrcode)) {
$userup['qrcode'] = $qrcode;
}
}
$userup['updatetime'] = time();
Db::name("agent_users")
->where("id", $this->model->id)
->update($userup);
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
//处理身份证
$row['idcard'] = tyssl_decode($row['idcard']);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
/*
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}*/
if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) {
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['idcard'] = tyssl_encode($params['idcard']);
//处理选择为自由经纪人,清空选择的企业
if ($params['jjr_type'] == '0') {
$params['agent_list_id'] = 0;
$params['agent_shop_id'] = 0;
}
//如果选择了企业,添加经纪人归属
if ($params['jjr_type'] == '1') {
$params['admin_id'] = agent_list_admin_id($params['agent_list_id']);
}
//流程改动:上传职业证书的用户审核通过就不需要进行考试等等流程;直接成为经纪人 20230804 陈程
if($params['jjr_agent_stu'] == '1' && !empty($params['vocational_certificate'])){
$time = time();
$params['is_test_time'] = $time; // 完成考试时间
$params['is_test_ok'] = '1'; //完成入驻考试,0否,1是
$params['is_stu_ok'] = '1';//完成培训考试,0否,1是
$parms['is_stu_time']= $time;//完成培训时间
$params['jjr_type_uptime'] = $time; // 经济人信息更新 表示绑定为经济人了
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
if ($params['jjr_agent_stu'] == "1") {
//审核通过;生成小程序二维码
$qrcode_api = new WxXcxQrcode();
$path = '/pages/home/broker/broker?id=' . $row->id;
$params['qrcode'] = $qrcode_api->qrcode($row->id, $path, true);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
//公众号消息推送
if ($params['jjr_agent_stu'] == '1' || $params['jjr_agent_stu'] == '2') {
if ($params['jjr_agent_stu'] == '1') {
$desctit = "经纪人入驻已审核通过";
$remark = '审核通过';
}
if ($params['jjr_agent_stu'] == '2') {
$desctit = "经纪人入驻审核不通过";
$remark = '不通过原因:' . $params['remark'];
}
//推送公众号模板信息给经纪人
$this->senWxmsgToAgentUser($desctit, $row->id, $remark);
}
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
/***
* 公众号推送审核信息给经纪人
*/
private function senWxmsgToAgentUser($titdesc, $agent_users_id, $remark)
{
$sendInfo = array(
'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"),
'keyword1' => array('value' => urlencode(date('Y-m-d H:i:s', time())), 'color' => '#173177'),
'keyword2' => array('value' => urlencode('经纪人入驻'), 'color' => '#173177'),
'remark' => array('value' => urlencode($remark), 'color' => '#173177'),
);
$wxopenid = getAgetWxOpenid($agent_users_id);
if ($wxopenid) {
$config = get_addon_config('wechat');
$tourl = 'https://fdc.xp.yn.cn/h5/';
$ywt_appid = 'wx9f73637c6b8f2c47';
$pagepath = 'pages/home/index';
$res = sendAstuWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
//file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
}
}
/***
* 导出测试
*/
public function pclexport()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$search = $this->request->post('search');
$ids = $this->request->post('ids');
//搜索条件
$filter = $this->request->post('filter');
$op = $this->request->post('op');
//导出的字段
$columns = $this->request->post('columns');
//查询条件
$whereIds = $ids == 'all' ? '1=1' : ['agentusers.id' => ['in', explode(',', $ids)]];
$this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
//获得数据列表:全部字段的内容
$list = $this->model
->with(['agentusercat', 'agentusereducat', 'agentlist', 'user', 'agentshoplist'])
->where($where)
->where($whereIds)
->order($sort, $order)
->select();
foreach ($list as $row) {
$row->visible(['id', 'user_id', 'jjr_sex', 'agent_shop_id', 'agent_list_id', 'jjr_type', 'user_cat_id', 'user_educat_id', 'jjr_name', 'jjr_image', 'createtime', 'updatetime', 'jjr_mobile', 'home_address', 'now_address', 'idcard', 'idcard_images', 'jjr_content', 'jjr_agent_stu', 'jjr_start_pay_time', 'jjr_end_pay_time', 'jjr_pay_stu', 'credit', 'addstep', 'jjr_type_uptime', 'is_stu_ok', 'is_test_ok', 'userno']);
$row->visible(['agentusercat']);
$row->getRelation('agentusercat')->visible(['catname']);
$row->visible(['agentusereducat']);
$row->getRelation('agentusereducat')->visible(['educat_name']);
$row->visible(['agentlist']);
$row->getRelation('agentlist')->visible(['agent_name']);
$row->visible(['agentshoplist']);
$row->getRelation('agentshoplist')->visible(['shop_name']);
$row->visible(['user']);
$row->getRelation('user')->visible(['username', 'nickname']);
}
//对象处理成数组
$list = json_encode($list);
$list = json_decode($list, true);
// var_dump($list);
}
}
/**
* 删除
*/
public function del($ids = "")
{
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
/*if (!is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', [1, 2, 26, 32, 37]);
}*/
if (!in_array($this->auth->id, [1, 2, 26, 32, 37])) {
$this->error(__("Invalid parameters"));
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}