<?php

namespace app\admin\model;

use app\BaseModel;

class QuestionLanguages extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    
    public static function getQuestion($keyword_ids, $content)
    {
        $content = strip_tags($content);
        //缓存问题列表
        $questionList = cache('questionList');
        //if (!$questionList) {
            $questionList = self::where('status', 1)->field(['id','category_id','question','answer','keyword_id','language_code'])->order('weight','desc')->select()->toArray();
            cache('questionList', $questionList);
        //}
        $list = [];
        foreach ($questionList as $item) {
            //判断content是否包含关键词
            if (in_array($item['keyword_id'], $keyword_ids) || strpos($item['question'], $content) !== false) {
                $list[] = $item;
            }
        }
        return $list;
    }
}