| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | <?php/** * Created by PhpStorm. * User: Administrator * Date: 2018/11/7 * Time: 10:06 */namespace App\Services\Content;use App\Repositories\HelpCategoryRepository;use App\Repositories\HelpRepository;class HelpCategoryService{    protected $helpCategoryRepository;    protected $helpRepository;    /**     * HelpCategoryService constructor.     * @param $helpCategoryRepository     */    public function __construct(HelpCategoryRepository $helpCategoryRepository, HelpRepository $helpRepository)    {        $this->helpCategoryRepository = $helpCategoryRepository;        $this->helpRepository = $helpRepository;    }    public function getCategories($where, $limit)    {        $lists = $this->helpCategoryRepository->getCategories($where, $limit);        if ($lists->toArray()) {            //获取大类下的所有help            foreach ($lists as $k => $v) {                $helps = $this->helpRepository->getHelpsByType($v->id);                if ($helps->toArray()) {                    $lists[$k]->helps = $helps;                } else {                    $lists[$k]->helps = array();                }            }        }        if (array_key_exists('id', $lists)) {            return $lists[0];        } else {            return $lists;        }    }    public function noHelpCategories($where, $limit)    {        $lists = $this->helpCategoryRepository->getCategories($where, $limit);        if (array_key_exists('id', $lists)) {            return $lists[0];        } else {            return $lists;        }    }    public function getOneCategory($where)    {        return $this->helpCategoryRepository->getCategory($where);    }}
 |