InviteDetailController.class.php
4.83 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 16/9/18
* Time: 11:52
*/
namespace Api\Controller\Invite;
use Common\Common\Cache;
use Common\Common\Constant;
use Common\Common\Department;
use Common\Common\User;
use Common\Model\AttrModel;
use Common\Service\AttrService;
use Common\Service\InviteUserService;
use Common\Service\InviteSettingService;
class InviteDetailController extends AbstractController
{
/**
* 邀请详情
* @author zhonglei
*/
public function Index_post()
{
$inviteId = I('post.invite_id', '', 'trim');
if (empty($inviteId)) {
E('_ERR_INVITE_ID_IS_NULL');
}
$inviteUserService = new InviteUserService();
$invite = $inviteUserService->get($inviteId);
if (!$invite) {
E('_ERR_INVITE_DATA_IS_NULL');
}
// 读取字段信息
$attrServ = new AttrService();
$attrs = $attrServ->getAttrList(true);
// 将form表单格式化为前端可显示格式
$inviteForm = [];
$departments = Department::instance()->listAll();
$form = unserialize($invite['form']);
$form = array_combine_by_key($form, 'field_name');
// 是否有自定义属性(0=无;1=有)
$isCustom = Constant::CUSTOM_ATTR_NO;
//foreach ($form as $v) {
foreach ($attrs as $_attr) {
$field_name = $_attr['field_name'];
if ('dpName' == $_attr['field_name']) {
$field_name = 'dpIdList';
}
if (empty($form[$field_name])) {
continue;
}
$v = $form[$field_name];
$v['attr_value'] = isset($v['attr_value']) ? $v['attr_value'] : '';
$v['postion'] = $_attr['postion'];
// 有自定义属性
if ($_attr['postion'] == Constant::AREA_CUSTOM) {
$isCustom = Constant::CUSTOM_ATTR_YES;
}
if (!empty($v['attr_value']) || $v['attr_value'] !== '') {
// 属性类型为"图片"时,将属性值转为图片详情数组
if ($v['type'] == AttrModel::ATTR_TYPE_PICTURE) {
$v['attr_value'] = $inviteUserService->formatValueByType($v['type'], $v['attr_value']);
}
// 属性类型为"单选、下拉框单选"时,将属性值由单选value转为单选name显示
if ($v['type'] == AttrModel::ATTR_TYPE_RADIO || $v['type'] == AttrModel::ATTR_TYPE_DROPBOX) {
foreach ($v['option'] as $option) {
if ($option['value'] == $v['attr_value']) {
$v['attr_value'] = $option['name'];
break;
}
}
}
// 属性类型为"多选"时,将属性值数组组成字符串
if ($v['type'] == AttrModel::ATTR_TYPE_CHECKBOX) {
$tmp = '';
foreach ($v['attr_value'] as $val) {
$tmp .= $val['name'] . ';';
}
$v['attr_value'] = substr($tmp, 0, -1);
}
// 如果是部门ID
if ('dpIdList' == $v['field_name']) {
if (empty($departments[$v['attr_value']])) {
$v['attr_value'] = '';
} else {
$v['attr_value'] = $departments[$v['attr_value']]['dpName'];
}
}
}
$inviteForm[] = $v;
}
// 当前登录人员是否有审核权限
if ($this->_hasCheckPower($invite)) {
$isChecker = InviteSettingService::IS_CHECK_YES;
} else {
$isChecker = InviteSettingService::IS_CHECK_NO;
}
$data = [
'is_checker' => $isChecker,
'invite_id' => $invite['invite_id'],
'type' => $invite['type'],
'is_custom' => $isCustom,
'fields' => $inviteForm,
'time' => $invite['created'],
'check_status' => $invite['check_status'],
'is_follow' => InviteUserService::USER_IS_FOLLOW_FALSE,
];
if ($invite['check_status'] == InviteUserService::CHECK_STATUS_PASS) {
$userServ = new User();
$user = $userServ->getByUid($invite['uid']);
if ($user) {
$data['face'] = $user['memFace'];
// 已关注
if ($user['memSubscribeStatus'] == InviteUserService::USER_IS_FOLLOW_TRUE) {
$data['is_follow'] = InviteUserService::USER_IS_FOLLOW_TRUE;
}
}
}
// 企业名称
$epData = (new Cache())->get('Common.EnterpriseConfig');
$data['sitename'] = $epData['sitename'];
$this->_result = $data;
}
}