InfoController.class.php 5.87 KB
<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 17/9/26
 * Time: 14:34
 */
namespace Api\Controller\HomePage;

use Common\Common\User;
use Common\Common\HomePage;

class InfoController extends AbstractController
{
    /**
     * Info
     * @author liyifei
     * @desc 获取个人主页设置
     * @param String uid:true 人员UID
     * @return array
                array(
                    'memUsername' => '张三',
                    'memFace' => 'http://p.qlogo.cn/bizmail/0IUNiaicjyroLPJ2Etmrb4RgQ8JLmbLZWBJSONSCKQjeJXfiapIuic6g2Q/0',
                    'list' => array(
                        array(
                            'field_name' => 'memUsername',
                            'attr_name' => '姓名',
                            'attr_value' => '李以飞',
                            'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
                            'option' => []; // 属性选项
                        ),
                        array(
                            'field_name' => 'memGender',
                            'attr_name' => '性别',
                            'attr_value' => 1,
                            'type' => 7, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
                            'option' => array( // 属性选项
                                {
                                    "name": "男",
                                    "value": 1
                                },
                                {
                                    "name": "女",
                                    "value": 2
                                }
                            ),
                        ),
                        array(
                            'field_name' => 'dpName',
                            'attr_name' => '组织',
                            'attr_value' => array(
                                '一飞冲天',
                            ),
                            'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
                            'option' => []; // 属性选项
                        ),
                        array(
                            'field_name' => 'custom1',
                            'attr_name' => '多选属性',
                            'attr_value' => array(
                                '属性1',
                                '属性2'
                            ),
                            'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
                            'option' => array(); // 属性选项
                        )
                    )
                )
     */
    public function Index()
    {
        $uid = I('post.uid', '', 'trim');
        if (empty($uid)) {
            E('_ERR_UID_IS_NULL');
        }

        // 获取个人主页设置缓存
        $homepageServ = &HomePage::instance();
        $setting = $homepageServ->getSetting();

        // 是否开启个人主页设置
        if ($setting['homepage'] == HomePage::CLOSE) {
            E('_ERR_HOMEPAGE_CLOSED');
        }

        // 用户信息(从缓存架构用户信息表中的数据获取用户信息,参数设为true越过缓存)
        $commUser = new User();
        $userInfo = $commUser->getByUid($uid);
        if (empty($userInfo)) {
            E('_ERR_HOMEPAGE_GET_USER_FAIL');
        }

        // 可显示的个人信息
        $attrs = $setting['attrs'];
        $isSecret = $homepageServ->checkUserInSecret($userInfo);
        if ($isSecret) {
            $attrs = $setting['secret_attrs'];
        }

        // 没有可显示的个人信息
        if (empty($attrs)) {
            E('_ERR_HOMEPAGE_ATTRS_LOSE');
        }

        // 员工管理中设置可用人员属性
        $homepageServ = &HomePage::instance();
        $attrList = $homepageServ->getAttrs();

        // 可显示的个人信息详情
        $list = [];
        foreach ($attrs as $fieldName) {
            // 跳过员工管理中设置不显示的属性
            if (!isset($attrList[$fieldName])) {
                continue;
            }
            $attrValue = $userInfo[$fieldName];
            switch ($attrList[$fieldName]['type']) {
                // 多选类型属性,反序列化属性值
                case 8:
                    if (!empty($attrValue)) {
                        $attrValue = array_column(unserialize($attrValue), 'name');
                    }
                    break;
                // 部门、组织属性,仅取第一个部门名称
                case 999:
                    if (is_array($attrValue) && !empty($attrValue)) {
                        $attrValue = $userInfo[$fieldName][0]['dpName'];
                    }
                    break;
            }

            $list[] = [
                'field_name' => $fieldName,
                'attr_value' => $attrValue,
                'attr_name' => $attrList[$fieldName]['attr_name'],
                'type' => $attrList[$fieldName]['type'],
                'option' => $attrList[$fieldName]['option'],
            ];
        }

        $this->_result = [
            'memUsername' => $userInfo['memUsername'],
            'memFace' => $userInfo['memFace'],
            'list' => $list,
        ];
    }
}