EditQueryController.class.php
2.38 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 16/9/17
* Time: 22:51
*/
namespace Apicp\Controller\User;
use Common\Common\User;
use Common\Model\AttrModel;
use Common\Service\AttrService;
class EditQueryController extends AbstractController
{
/**
* 【通讯录】人员编辑查询
* @author liyifei
* @time 2016-09-17 22:38:54
*/
public function Index_post()
{
$uid = I('post.uid', '', 'trim');
if (empty($uid)) {
E('_ERR_UID_IS_NULL');
}
// 属性信息
$attrServ = new AttrService();
$attrs = $attrServ->getAttrList(true, array(), true);
// 用户信息
$newUser = new User();
$userInfo = $newUser->getByUid($uid);
$list = [];
$isCustom = AttrService::ATTR_CUSTOM_IS_FALSE;
foreach ($attrs as $k => $attr) {
// 是否存在自定义属性(方便前端布局)
if ($attr['postion'] == AttrModel::AREA_CUSTOM) {
$isCustom = AttrService::ATTR_CUSTOM_IS_TRUE;
}
$list[$k] = [
'attr_name' => $attr['attr_name'],
'field_name' => $attr['field_name'],
'type' => $attr['type'],
'option' => $attr['option'],
'is_required' => $attr['is_required'],
'is_required_cp' => $attr['is_required_cp'],
'is_system' => $attr['is_system'],
'postion' => $attr['postion'],
'order' => $attr['order'],
];
// 根据属性类型不同,将属性值转为与前端约定好的格式
$list[$k]['attr_value'] = $attrServ->formatValueByType($attr['type'], $userInfo[$attr['field_name']]);
// 特殊处理"多选"类型属性,格式化为前端需要格式
if ($attr['type'] == AttrModel::ATTR_TYPE_CHECKBOX) {
foreach ($attr['option'] as $key => $val) {
if (in_array($val['name'], $list[$k]['attr_value'])) {
$attr['option'][$key]['checked'] = true;
}
}
$list[$k]['attr_value'] = $attr['option'];
}
}
$this->_result = [
'is_custom' => $isCustom,
'memSubscribeStatus' => $userInfo['memSubscribeStatus'],
'list' => array_values($list)
];
}
}