AgencyMattersController.class.php 15.2 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
<?php
/**
 * 代办事项
 */

namespace Apicp\Controller\HomePage;

use Common\Common\Answer;
use Common\Common\Cache;
use Common\Common\Contact;
use Common\Common\Exam;
use Common\Common\Integral;
use Common\Common\Train;
use Common\Common\Workmate;
use Common\Service\CommonAgencyRecordService;
use VcySDK\AdminerRole;
use VcySDK\EnterprisePlugin;
use VcySDK\Member;
use VcySDK\Service;

class AgencyMattersController extends AbstractController
{
    protected $_require_login = false;

    /**
     * @var array 当前管理员有权限的目录
     */
    protected $_cp_menu = [];

    /**
     * @var int 当前管理员类型(1=系统管理员;2=用户自定义)
     */
    protected $_ear_type;

    /**
     * @var array 关闭的代办事项(没有app_data_id的待办事项)
     */
    protected $_close_action = [];

    /**
     * 代办事项:完善企业信息
     */
    const ACTIVE_IS_COMPLETE_EP_INFO = 'completeEpInfo';
    /**
     * 代办事项:获取人员未关注数量
     */
    const ACTIVE_IS_NOT_CONCERNED = 'notConcerned';
    /**
     * 代办事项:问答待审核
     */
    const ACTIVE_IS_APPROVAL_ANSWER = 'approvalAnswer';
    /**
     * 代办事项:邀请待审核
     */
    const ACTIVE_IS_APPROVAL_INVITE = 'approvalInvite';
    /**
     * 代办事项:话题待审核
     */
    const ACTIVE_IS_APPROVAL_WORKMATE = 'approvalWorkmate';
    /**
     * 代办事项:积分待审核
     */
    const ACTIVE_IS_APPROVAL_INTEGRAL_CONVERT = 'approvalIntegralConvert';
    /**
     * 代办事项:企业培训报名待审核
     */
    const ACTIVE_IS_APPROVAL_TRAIN_SIGN_UP = 'approvalTrainSignUp';
    /**
     * 代办事项:考试待批阅
     */
    const ACTIVE_IS_NEED_READING_PAPER = 'needReadingPaper';

    public function index()
    {
        // 关闭的代办事项(没有app_data_id的待办事项)
        $agencyRecordServ = new CommonAgencyRecordService();
        $actionList = $agencyRecordServ->list_by_conds([
            'app_data_id' => 0,
            'ea_id' => $this->_login->user['eaId']]);
        $this->_close_action = empty($actionList) ? [] : array_column($actionList, 'agency_action');

        // 考试待批阅
        $this->needReadingPaper();
        // 企业培训报名审核
        $this->approvalTrainSignUp();
        // 积分兑换待审核
        $this->approvalIntegralConvert();
        // 帖子待审核
        $this->approvalWorkmate();
        // 话题待审核
        $this->approvalTopic();
        // 邀请待审核
        $this->approvalInvite();
        // 问答待审核
        $this->approvalAnswer();
        // 企业信息是否完善
        $this->checkCompleteEpInfo();
        // 未加入人员数量
        $this->notConcerned();

        return true;
    }

    /**
     * 企业信息是否完善
     */
    private function checkCompleteEpInfo()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_COMPLETE_EP_INFO, $this->_close_action)) {
            return true;
        }

        // 需要完善企业信息
        $needCompleteEpInfo = false;

        $epDetail = Cache::instance()->get('Common.EnterpriseDetail', '', ['expire' => 300]);
        // 看那个字段没有填写
        foreach (
            array_intersect_key($epDetail, array_fill_keys([
                'corpName',
                'epIndustry',
                'epCompanysize',
                'epContacter',
                'epContactmobile',
                'epContactemail',
                'epPostalCode',
                'epAddress',
            ], '')) as $item
        ) {
            if (empty($item)) {
                $needCompleteEpInfo = true;
            }
        };
        // 另外判断地区
        if (empty($epDetail['epArea']) && empty($epDetail['epCity']) && empty($epDetail['epProvince'])) {
            $needCompleteEpInfo = true;
        }

        if ($needCompleteEpInfo) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_COMPLETE_EP_INFO,
                'message' => '【企业信息】尚未完善企业账户信息,立即前往设置',
                'url' => admincpUrl('/admincp/#/c/system-settings/account-info'),
            ];
        }

        return true;
    }

    /**
     * 获取人员未关注数量
     * @return bool
     */
    private function notConcerned()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_NOT_CONCERNED, $this->_close_action)) {
            return true;
        }

        // 企业应用
        $enterprisePluginSdk = new EnterprisePlugin(Service::instance());
        $pluginList = $enterprisePluginSdk->listAll();
        $pluginList = array_combine_by_key($pluginList, 'plIdentifier');
        // 人员状态
        $memberSdk = new Member(Service::instance());
        $memberDetail = $memberSdk->memberStatusCount([]);

        // 有人没关注
        if ($memberDetail['notConcerned'] > 0 &&
            // 通讯录开启的
            ($pluginList['contact']['available'] == EnterprisePlugin::AVAILABLE_OPEN) &&
            // 有邀请人员权限 或者 超级管理员
            $this->checkRight('member-invite')
        ) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_NOT_CONCERNED,
                'message' => "【员工管理】有{$memberDetail['notConcerned']}名员工尚未加入,立即前往邀请",
                'url' => admincpUrl('/admincp/#/c/contacts/employee-contract')
            ];
        }

        return true;
    }

    /**
     * 待审核问答
     * @author tangxingguo
     * @return bool
     */
    public function approvalAnswer()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_APPROVAL_ANSWER, $this->_close_action)) {
            return true;
        }

        // 管理员是否有权限
        if (!$this->checkRight('answer-list')) {
            return true;
        }

        // 待审核的提问数量
        $answer = &Answer::instance();
        $count = $answer->getAnswerCount(['check_status' => Answer::QUESTION_CHECK_STATUS_WAIT]);

        if ($count > 0) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_APPROVAL_ANSWER,
                'message' => "【问答审核】有{$count}条问答待审核,点击立即前往",
                'url' => admincpUrl('/admincp/#/c/my-app/answer-center')
            ];
        }

        return true;
    }

    /**
     * 待审核邀请人员
     * @author tangxingguo
     * @return bool
     */
    public function approvalInvite()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_APPROVAL_INVITE, $this->_close_action)) {
            return true;
        }

        // 管理员是否有权限
        if (!$this->checkRight('member-invite')) {
            return false;
        }

        // 待审核的邀请数量
        $contact = &Contact::instance();
        $count = $contact->getNeedInviteCount([
            'check_status' => Contact::CHECK_STATUS_WAIT,
            'type' => Contact::INVITE_TYPE_APPROVAL
        ]);

        if ($count > 0) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_APPROVAL_INVITE,
                'message' => "【用户审核】有{$count}名员工邀请待审核,点击立即前往",
                'url' => admincpUrl('/admincp/#/c/contacts/invite')
            ];
        }

        return true;
    }

    /**
     * 待审核帖子
     * @author tangxingguo
     * @return bool
     */
    public function approvalWorkmate()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_APPROVAL_WORKMATE, $this->_close_action)) {
            return true;
        }

        // 管理员是否有权限
        if (!$this->checkRight('workmate-list')) {
            return false;
        }

        $workmateServ = &Workmate::instance();
        $count = $workmateServ->getWorkmateCount(['audit_state' => Workmate::CHECK_STATUS_WAIT, 'type' =>Workmate::CIRCLE_NOTE_TYPE, 'pid' => Workmate::CIRCLE_PID_TYPE]);

        if ($count > 0) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_APPROVAL_WORKMATE,
                'message' => "【同事圈帖子审核】有{$count}条同事圈帖子待审核,点击立即前往",
                'url' => admincpUrl('/admincp/#/c/my-app/workmate')
            ];
        }

        return true;
    }

    /**
     * 待审核话题
     * @author tangxingguo
     * @return bool
     */
    public function approvalTopic()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_APPROVAL_WORKMATE, $this->_close_action)) {
            return true;
        }

        // 管理员是否有权限
        if (!$this->checkRight('workmate-list')) {
            return false;
        }

        $workmateServ = &Workmate::instance();
        $count = $workmateServ->getWorkmateCount(['audit_state' => Workmate::CHECK_STATUS_WAIT, 'type' =>Workmate::CIRCLE_TOPIC_TYPE, 'pid' => Workmate::CIRCLE_PID_TYPE]);

        if ($count > 0) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_APPROVAL_WORKMATE,
                'message' => "【同事圈话题审核】有{$count}条同事圈话题待审核,点击立即前往",
                'url' => admincpUrl('/admincp/#/c/my-app/workmate/workmate-topic')
            ];
        }

        return true;
    }

    /**
     * 待审核积分兑换
     * @author tangxingguo
     * @return bool
     */
    public function approvalIntegralConvert()
    {
        // 代办事项是否被关闭
        if (in_array(self::ACTIVE_IS_APPROVAL_INTEGRAL_CONVERT, $this->_close_action)) {
            return true;
        }

        // 管理员是否有权限
        if (!$this->checkRight('integral')) {
            return false;
        }

        $integral = &Integral::instance();
        $count = $integral->getIntegralConvertCount(['convert_status' => Integral::CONVERT_STATUS_IS_WAIT]);

        if ($count > 0) {
            $this->_result[] = [
                'id' => self::ACTIVE_IS_APPROVAL_INTEGRAL_CONVERT,
                'message' => "【积分商城审核】有{$count}个兑换商品待审核,点击立即前往",
                'url' => admincpUrl('/admincp/#/c/my-app/integral/integral-mall/exchange-manage')
            ];
        }
        return true;
    }


    /**
     * 待审核企业培训报名
     * @author tangxingguo
     */
    public function approvalTrainSignUp()
    {
        // 管理员是否有权限
        if (!$this->checkRight('train')) {
            return false;
        }

        // 需要审核的未过期的企业培训
        $train = &Train::instance();
        $trainList = $train->getEducationList([
            // 培训截止时间
            'ed_end_time > ?' => MILLI_TIME,
            // 开启了报名
            'ed_is_sign_up' => Train::SIGN_OPEN,
            // 开启了审核
            'ed_is_check' => Train::CHECK
        ]);
        if (empty($trainList)) {
            return false;
        }
        $trainIds = array_column($trainList, 'ed_id');

        // 已经关闭的待办事项
        $agencyRecordServ = new CommonAgencyRecordService();
        $closeList = $agencyRecordServ->list_by_conds([
            'agency_action' => self::ACTIVE_IS_APPROVAL_TRAIN_SIGN_UP,
            'ea_id' => $this->_login->user['eaId'],
            'app_data_id' => $trainIds
        ]);
        $closeIds = empty($closeList) ? [] : array_column($closeList, 'app_data_id');

        // 需要待办的事项(需要审核 与 关闭 差集)
        $ids = array_diff($trainIds, $closeIds);

        // 待审核的报名
        $countUids = $train->countRightUserList($ids);
        if (!empty($countUids)) {
            foreach ($countUids as $v) {
                $params = [
                    'ed_id' => $v['ed_id'],
                ];
                $this->_result[] = [
                    'id' => self::ACTIVE_IS_APPROVAL_TRAIN_SIGN_UP,
                    'app_data_id' => $v['ed_id'],
                    'message' => "【企业培训审核】有{$v['count']}个报名待审核,点击立即前往",
                    'url' => admincpUrl("/admincp/#/c/my-app/train/train-detail", $params)
                ];
            }
        }

        return true;
    }

    /**
     * 考试待批阅
     * @author tangxingguo
     * @return bool
     */
    public function needReadingPaper()
    {
        // 管理员是否有权限
        if (!$this->checkRight('exam')) {
            return false;
        }

        // 需要阅卷的考试
        $exam = &Exam::instance();
        $readingList = $exam->getNeedReadingList();
        if (empty($readingList)) {
            return false;
        }

        // 试卷ID
        $epIds = array_column($readingList, 'ep_id');

        // 已关闭的待办
        $agencyRecordServ = new CommonAgencyRecordService();
        $closeList = $agencyRecordServ->list_by_conds([
            'agency_action' => self::ACTIVE_IS_NEED_READING_PAPER,
            'ea_id' => $this->_login->user['eaId'],
            'app_data_id' => $epIds
        ]);
        $closeIds = empty($closeList) ? [] : array_column($closeList, 'app_data_id');

        // 需要待办的事项(需要审核 与 关闭 差集)
        $ids = array_diff($epIds, $closeIds);

        // 考试信息
        $paperList = $exam->getPaperList(['ep_id' => $ids]);
        if (!empty($paperList)) {
            $paperList = array_combine_by_key($paperList, 'ep_id');
        }

        if (!empty($ids)) {
            foreach ($readingList as $v) {
                // 事项没有被关闭 & 考试没有被删除
                if (in_array($v['ep_id'], $ids) && isset($paperList[$v['ep_id']])) {
                    $params = [
                        'ep_id' => $v['ep_id']
                    ];
                    $this->_result[] = [
                        'id' => self::ACTIVE_IS_NEED_READING_PAPER,
                        'app_data_id' => $v['ep_id'],
                        'message' => "{$paperList[$v['ep_id']]['ep_name']}】有{$v['count']}名员工试卷待批阅,点击立即前往",
                        'url' => admincpUrl("/admincp/#/c/my-app/exam/exam-paper-detail", $params)
                    ];
                }
            }
        }
        return true;
    }

    /**
     * 检查权限
     * @author tangxingguo
     * @param string $appItem 应用目录
     * @return bool
     */
    public function checkRight($appItem)
    {
        // 当前管理员有权限的目录以及管理员类型
        $this->getCpMenu();

        // 有权限 或者 超级管理员
        if (array_key_exists($appItem, $this->_cp_menu) || $this->_ear_type == AdminerRole::ROLE_TYPE_SYS) {
            return true;
        }
        return false;
    }

    /**
     * 获取当前管理员有权限的目录以及管理员类型
     * @author tangxingguo
     */
    protected function getCpMenu()
    {
        if (empty($this->_cp_menu) || empty($this->_ear_type)) {
            $sdkRole = new AdminerRole(Service::instance());
            $role = $sdkRole->detail([
                'earId' => $this->_login->user['earId'],
                'eaId' => $this->_login->user['eaId']
            ]);
            $this->_cp_menu = !is_null($role['earCpmenu']) ? json_decode($role['earCpmenu'], true) : [];
            $this->_ear_type = $role['earType'];
        }
    }
}