Online.php 2.63 KB
<?php

namespace Home;

use LibModels\Wap\Home\OnlineData;
use Plugin\Helpers;

/**
 * 在线客服相关数据处理
 */
class OnlineModel
{

    //获取在线帮助分类
    public static function getOnlineServiceInfo($clientType = 'iphone')
    {
        //调用接口获取数据
        $res = OnlineData::getOnlineServiceInfo($clientType);
        $cateInfo = $res['data'];
        $question = array();
        $tab = array();
        if ($cateInfo) {
            foreach ($cateInfo as $key => $value) {
                //强制截成3个tab
                if ($key > 2) {
                    break;
                }
                $tab[$key]['tabid'] = 'tab' . $value['id'];
                $tab[$key]['tabname'] = $value['category_name'];
                $tab[$key]['iscut'] = true;
                $tab[$key]['current'] = (!$key) ? TRUE : FALSE;
                $question[$key]['name'] = 'tab' . $value['id'];
                $question[$key]['current'] = (!$key) ? TRUE : FALSE;
                $sub = $value['sub'];
                $qTmp = array();
                if ($sub) {
                    foreach ($sub as $sk => $sv) {
                        $qTmp[$sk]['title'] = $sv['category_name'];
                        $qTmp[$sk]['link'] = '/home/onlineservicedetail?cateId=' . $sv['id'] . '&cateName=' . $sv['category_name'];
                    }
                }
                $question[$key]['list'] = $qTmp;
            }
            $question[0]['current'] = true;
            $tab[count($tab) - 1]['iscut'] = false;
        }
        //处理返回信息
        $result = array(
            'header' => array('title' => '在线客服'),
            'tab' => $tab,
            'question' => $question
        );

        return $result;
    }

    //加载分类下的问题和解决方法
    public static function getOnlineServiceDetail($cateId, $clinetType = 'iphone')
    {
        $result = array();
        if (!$cateId) {
            return $result;
        }
        $res = OnlineData::getOnlineServiceDetail($cateId, $clinetType);
        $questionInfo = $res['data'];
        if ($questionInfo) {
            $list = array();
            if ($questionInfo) {
                foreach ($questionInfo as $qk => $qv) {
                    $list[$qk]['q'] = $qv['title'];
                    $list[$qk]['a'] = $qv['content'];
                }
            }
            //处理返回信息
            $result = array(
                'header' => array('title' => '在线客服'),
                'list' => $list
            );
        }
        return $result;
    }

}