Help.php 2.64 KB
<?php

namespace Index;

use LibModels\Web\Home\HelpData;

/**
 * 帮助中心
 */
class HelpModel
{

    /**
     * 获取帮助列表
     */
    public static function getHelpList($cateId)
    {
        $list = array();
        $res = HelpData::getHelpCategory();
        if (isset($res['data']) && $res['data']) {
            foreach ($res['data'] as $key => $value) {
                $list[$key]['id'] = $value['id'];
                $list[$key]['name'] = $value['caption'];
                if ($value['id'] == $cateId) {
                    $list[$key]['active'] = true;
                }
            }
        }
        return $list;
    }

    /**
     * 获取具体的帮助信息(非常见问题)
     * @param type $cateId
     */
    public static function getHelpDetail($cateId)
    {
        $detail = '';
        $res = HelpData::getHelpDetail($cateId);
        if (isset($res['data']['helpdetail_list']) && $res['data']['helpdetail_list']) {
            $detail = $res['data']['helpdetail_list'][0]['content'];
        }
        return $detail;
    }

    /**
     * 常见问题相关数据
     * @param type $cateId
     * @param type $page
     * @param type $limit
     * @param type $key
     * @return type
     */
    public static function getSearchDetail($cateId = 37, $page = 1, $limit = 10, $key = '')
    {
        $question = array();
        $qRes = HelpData::getCommonFaqLimit($cateId, $key);
        if (isset($qRes['data']) && $qRes['data']) {
            foreach ($qRes['data'] as $qk => $qv) {
                $question['common'][$qk]['ask'] = $qv['problem'];
                $question['common'][$qk]['answer'] = $qv['answer'];
            }
        }
        $res = HelpData::getHelpDetail($cateId, $page, $limit, $key);
        if (isset($res['data']['helpdetail_list']) && $res['data']['helpdetail_list']) {
            foreach ($res['data']['helpdetail_list'] as $fqk => $fqv) {
                $question['all'][$fqk]['ask'] = $fqv['problem'];
                $question['all'][$fqk]['answer'] = $fqv['answer'];
                if ($fqk % 2) {
                    $question['all'][$fqk]['class'] = 'even';
                }
            }
            $question['pager']['page'] = $res['data']['page'];
            $question['pager']['total'] = $res['data']['total'];
            $question['pager']['pageTotal'] = $res['data']['page_total'];
        }
        else {
            $question['common'] = array();
            $question['all'] = array('empty' => '对不起,没有找到和“<span>' . $key . '</span>”相关的问题!');
        }
        return $question;
    }

}