AbstractController.class.php 1.46 KB
<?php
/**
 * Created by PhpStorm.
 */

namespace Api\Controller;

use Common\Controller\Api;
use Common\Service\EducationService;

abstract class AbstractController extends Api\AbstractController
{

    // 默认页码
    const DEFAULT_PAGE = 1;
    // 默认每页条数
    const DEFAULT_LIMIT = 15;

    // 点赞类型:点赞量加1
    const LIKES_INC = 0;
    // 点赞类型:点赞量减1
    const LIKES_DEC = 1;

    // 已参加人数加1
    const JOINED_INC = 0;

    /**
     * 根据培训id获取培训详情
     *
     * @param int $ed_id 培训id
     *
     * @return mixed
     */
    public function get_education($ed_id = 0)
    {
        $edu_s = new EducationService();
        // 培训详情
        $education = $edu_s->get($ed_id);
        if (!$education) {

            E('_ERR_ED_EXIST');
        }

        return $education;
    }

    /**
     * 格式化用户微信头像为小头像
     *
     * @param string $memFace 原始头像
     *
     * @return string 小头像
     */
    public function format_avatar($memFace = '')
    {

        // 头像为空,直接返回
        if (empty($memFace)) {

            return '';
        }

        // 头像根据"/"分隔为数组,取数组最后一个
        $end = end(explode('/', $memFace));
        // 最后一个元素为空,追加0
        if ($end != '0') {

            $memFace = $memFace . '0';
        }

        // 返回用户小头像
        return $memFace . '/100';
    }
}