<?php /** * Created by PhpStorm. * User: liyifei2012it * Date: 16/9/17 * Time: 22:51 */ namespace Api\Controller\User; use Common\Common\User; use Common\Model\AttrModel; use Common\Service\AttrService; class EditInfoController extends AbstractController { /** * 【通讯录】人员编辑查询 * @author tangxingguo * @param string uid:true 课程ID * @return array array( 'is_custom' => 1, // 是否存在自定义属性(0=无;1=有) 'dp_name' => array( // 部门信息 array( "dpId"=>"3E31D5997F00000120C5EBDB96A02CEE", "epId"=>"3E31CD177F00000137AEDDF6F6B0C809", "dpName"=>"小花专用部门", ) ), 'list' => array( // 列表数据 array ( "attr_name"=>"组织", // 属性名称 "field_name"=>"dpName", // 架构接口字段标识 "type"=>"999", // 属性字段类型 "option"=>"", // 该属性选项值 "is_required_cp"=>"1", // 是否必填(0=非必填;1=必填) "is_system"=>"1", // 是否为系统字段(0=自定义字段;1=系统字段) "postion"=>"3", // 前端显示区域(1=基本信息;2=验证信息;3=身份信息;4=自定义信息 "order"=>"6", // 排序 "attr_value"=> array( // 属性值 ) ) ) ); */ 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, 'dp_name' => $userInfo['dpName'], 'list' => array_values($list) ]; } }