UserInfoController.class.php
4.66 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/6/4
* Time: 16:33
*/
namespace Apicp\Controller\Invite;
use Common\Common\Constant;
use Common\Common\Department;
use Common\Service\InviteUserService;
class UserInfoController extends AbstractController
{
/**
* UserInfo
* @author liyifei
* @desc 被邀请人员详情(查询用)
* @param Int invite_id 邀请id
* @return Array
array(
'invite_id' => 1, // 邀请id
'username' => '李四', // 员工姓名
'dp_name' => '测试部', // 部门
'job_name' => '测试岗', // 岗位
'check_uid' => '111', // 审核人uid
'check_status' => 1, // 审批结果(1=待审批;2=通过审批;3=驳回审批)
'reason' => 111, // 驳回理由
'check_type' => 1, // 审批人类型( 1=员工 2=管理员)
'check_time' => 18877533201, // 审批时间,
'is_notice' => 1, // 是否已通知邀请人(0=未通知;1=已通知)
'form' => array( // 人员属性及数据
array(
'field_name' => 'memGender', // 对应UC字段名
'attr_name' => '性别', // 属性名称
'attr_value' => '1', // 属性值
'option' => array( // 属性选项
array(
'name' => '男', // 选项名称
'value' => '1', // 选项值
)
)
)
)
)
*/
public function Index_post()
{
$invite_id = I('post.invite_id', 0, 'intval');
if ($invite_id == 0) {
E('_ERR_PARAM_IS_NULL');
}
$inviteUserServ = new InviteUserService();
$invite = $inviteUserServ->get($invite_id);
if (empty($invite)) {
E('_ERR_DATA_IS_NULL');
}
// 处理部门返回值
if (!empty($invite['dp_id'])) {
$dp_path = &Department::instance()->getById($invite['dp_id']);
$invite['dp_name'] = $dp_path['departmentPath'];
}
// 保留返回值
$keys = ['invite_id', 'username', 'dp_name', 'job_name', 'check_uid', 'form',
'check_status', 'reason', 'check_type', 'check_time', 'is_notice'];
$invite = array_intersect_key_reserved($invite, $keys, true);
// 格式化表单信息
$invite['form'] = !empty($invite['form']) ? unserialize($invite['form']) : [];
if (!empty($invite['form'])) {
// 待移除表单数据
$move_field_names = ['memUsername', 'dpIdList', 'memJob', '_mobile_code'];
foreach ($invite['form'] as $k => $form) {
// 在返回值form外已展示的form中的数据,从form中移除
$field_name = $form['field_name'];
if (in_array($field_name, $move_field_names)) {
unset($invite['form'][$k]);
continue;
}
// 补全返回字段
if (!isset($form['attr_value'])) {
$invite['form'][$k]['attr_value'] = '';
}
if (!is_array($form['option'])) {
$invite['form'][$k]['option'] = '';
}
// 格式化单选类型、多选类型属性
$attr_value = $form['attr_value'];
if ((!empty($attr_value) && is_array($attr_value)) || mb_strlen($attr_value) > 0) {
$options = is_array($form['option']) ? array_combine_by_key($form['option'], 'value') : [];
switch ($form['type']) {
case Constant::ATTR_TYPE_RADIO:
$attr_value = (string)$attr_value;
$invite['form'][$k]['attr_value'] = $options[$attr_value]['name'];
break;
case Constant::ATTR_TYPE_CHECKBOX:
// 多选类型属性的attr_value为二维数组
$values = [];
foreach ($attr_value as $v) {
if (isset($v['checked']) && $v['checked'] == true) {
$values[] = $v['name'];
}
}
$invite['form'][$k]['attr_value'] = !empty($values) ? implode(';', $values) : '';
break;
}
}
}
$invite['form'] = array_values($invite['form']);
}
$this->_result = $invite;
}
}