<?php /** * Created by PhpStorm. * User: liyifei2012it * Date: 18/6/5 * Time: 11:43 */ namespace Apicp\Controller\Invite; use Common\Common\Constant; use Common\Common\Department; use Common\Service\AttrService; use Common\Service\InviteUserService; class UserEditInfoController extends AbstractController { /** * UserEditInfo * @author liyifei * @desc 被邀请人员详情(编辑用) * @param Int invite_id 邀请id * @return Array array( 'invite_id' => 1, // 邀请id 'is_custom' => 1, // 是否有自定义布局(0=无;1=有) 'form' => array( // 人员属性及数据 array( 'type' => '7', // 属性类型(1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门选人组件) 'field_name' => 'memGender', // 对应UC字段名 'attr_name' => '性别', // 属性名称 'attr_value' => '1', // 属性值 'option' => array( // 属性选项 array( 'name' => '男', // 选项名称 'value' => '1', // 选项值 ) ), 'postion' => '1', // 前端显示区域(1=基本信息;2=验证信息;3=身份信息) ) ) ) */ 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'); } // 属性信息 $attrServ = new AttrService(); $attrs = $attrServ->getAttrList(true, array(), true, false); $attrs = array_combine_by_key($attrs, 'field_name'); // 格式化用户提交的表单数据 $form = !empty($invite['form']) ? unserialize($invite['form']) : []; $isCustom = AttrService::ATTR_CUSTOM_IS_FALSE; if (!empty($form)) { foreach ($form as $k => $v) { $field_name = $v['field_name']; // 过滤多余返回值(管理后台已删除的属性) if ($field_name === '_mobile_code' || (!isset($attrs[$field_name]) && $field_name !== 'dpIdList')) { unset($form[$k]); continue; } // 补全返回值 if (!isset($form[$k]['attr_value'])) { $form[$k]['attr_value'] = ''; } if (!is_array($v['option'])) { $form[$k]['option'] = ''; } $form[$k]['postion'] = isset($attrs[$field_name]['postion']) ? $attrs[$field_name]['postion'] : Constant::AREA_IDENTITY; // 特殊处理的属性 switch ($field_name) { // 属性为"组织"时,需增加返回"组织名称",便于前端编辑时显示 case 'dpIdList': $dp_path = &Department::instance()->getById($invite['dp_id']); $form[$k]['dp_name'] = $dp_path['dpName']; break; // 属性为"岗位"时,更新option、type case 'memJob': $form[$k]['type'] = $attrs[$field_name]['type']; $form[$k]['option'] = $attrs[$field_name]['option']; break; // 属性为"角色"时,更新option、type case 'memRole': $form[$k]['type'] = $attrs[$field_name]['type']; $form[$k]['option'] = $attrs[$field_name]['option']; break; } // 特殊处理"多选"类型属性的值 if ($v['type'] == Constant::ATTR_TYPE_CHECKBOX) { $form[$k]['attr_value'] = []; $form[$k]['option'] = $attrs[$field_name]['option']; $attr_value = array_combine_by_key($v['attr_value'], 'value'); foreach ($form[$k]['option'] as $val) { $name = $val['name']; $value = $val['value']; if (isset($attr_value[$value]) && $attr_value[$value]['name'] == $name && $attr_value[$value]['value'] == $value ) { $val['checked'] = true; } $form[$k]['attr_value'][] = $val; } } // 是否存在自定义属性(方便前端布局) if ($form[$k]['postion'] == Constant::AREA_CUSTOM) { $isCustom = AttrService::ATTR_CUSTOM_IS_TRUE; } } $form = array_values($form); } $this->_result = [ 'invite_id' => $invite_id, 'is_custom' => $isCustom, 'form' => $form, ]; } }