InfoController.class.php 4.21 KB
<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 16/9/18
 * Time: 11:22
 */

namespace Api\Controller\User;

use Common\Common\Cache;
use Common\Common\Constant;
use Common\Common\Department;
use Common\Model\AttrModel;
use Common\Service\UserService;
use Common\Common\User;
use Common\Common\Integral;
use Common\Common\Teacher;

class InfoController extends AbstractController
{

    /**
     * 【通讯录】个人详情
     * @author liyifei
     * @time   2016-09-18 11:32:34
     */
    public function Index_post()
    {

        $uid = I('post.uid', '', 'trim');
        if (empty($uid)) {
            E('_ERR_UID_IS_NULL');
        }

        // 是否是"我的"页面顶部展示的个人信息(2017-10-23修改:因"我的"页面顶部用户信息加载过慢,故加该参数判断,省去不必要的信息查询)
        $index_show = I('post.index_show', '', 'trim');

        // 属性列表
        $userService = new UserService();
        $attrs = $userService->getAttrList(false, array(), false, false);
        $list = $userService->getUserInfoByUid($uid, $attrs);
        $list = array_combine_by_key($list, 'field_name');

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

        // 组织路径 (有部门 并且 员工属性开启了手机端显示)
        $departmentPath = '';
        if (!empty($userInfo['dpName']) && $list['dpName']['is_show'] == AttrModel::ATTR_IS_SHOW_TRUE) {

            $departmentPath = Department::instance()->getCdNames($userInfo['dpName'][0]['dpId']);

            // 非"我的"页面顶部展示信息
            if (!$index_show) {
                // 企业信息
                $enterprise = Cache::instance()->get(
                    'Common.EnterpriseDetail',
                    '',
                    ['expire' => cfg('ENTERPRISE_DETAIL_CACHE_EXPIRE')]
                );
                // 写入属性列表数据内
                $list['dpName']['attr_value'] = $departmentPath;
            }
        }

        // "我的"页面顶部展示信息
        if ($index_show) {
            // 初始化返回值
            $result = [
                // 是否本人
                'oneself' => $this->uid == $uid,
                'name' => $userInfo['memUsername'],
                'title' => $userInfo['memJob'],
                'face' => $userInfo['memFace'],
                'departmentPath' => $departmentPath
            ];
        } else {
            // 初始化返回值
            $list = array_values($list);
            $result = [
                // 是否本人
                'oneself' => $this->uid == $uid,
                'qy_name' => $enterprise['epName'],
                'name' => $userInfo['memUsername'],
                'sex' => $userInfo['memGender'],
                'title' => $userInfo['memJob'],
                'face' => $userInfo['memFace'],
                'qr_code' => oaUrl('Frontend/Index/ContactQrcode/index', ['uid' => $uid]),
                'departmentPath' => $departmentPath,
                'is_custom' => in_array(Constant::AREA_CUSTOM, array_column($list, 'postion')) ?
                    Constant::CUSTOM_ATTR_YES : Constant::CUSTOM_ATTR_NO,
                'list' => $list,
            ];
        }

        // 学分
        $integralServ = &Integral::instance();
        $integralList = $integralServ->listByUid([$uid], 'mi_type1');
        $result['credit'] = isset($integralList[$uid]['available']) ? $integralList[$uid]['available'] : 0;

        // 积分
        $integralList = $integralServ->listByUid([$uid]);
        $result['integral'] = isset($integralList[$uid]['available']) ? $integralList[$uid]['available'] : 0;

        // 勋章
        $result['medal'] = 0;
        $medalList = $integralServ->listMedalTotalByUid(['mem_uid' => $uid]);
        foreach ($medalList as $medal) {
            $result['medal'] += $medal['im_total'];
        }

        // 是否为讲师
        $teacherServ = &Teacher::instance();
        $teacher = $teacherServ->getTeacherByConds(['uid' => $uid, 'teacher_status' => 1]);
        $result['is_teacher'] = !empty($teacher);

        $this->_result = $result;
    }
}