function get_disease_symptom() { $console = Yii::getAlias("@console"); $file = $console . '/shell/disease_symptom.php'; $disease_symptom_arr = []; if (file_exists($file)) { $disease_symptom_str = file_get_contents($file); $disease_symptom_arr = unserialize($disease_symptom_str); } else { $diseases = \common\models\Disease::find()->asArray()->all(); foreach ($diseases as $disease) { $name = $disease['name']; $row = array('id' => $disease['id'], 'source_flag' => 1); $disease_symptom_arr[$name] = $row; } $symptoms = \common\models\Symptom::find()->asArray()->all(); foreach ($symptoms as $symptom) { $name = $symptom['name']; if (!isset($disease_symptom_arr[$name])) { $row = array('id' => $symptom['id'], 'source_flag' => 2); $disease_symptom_arr[$name] = $row; } } $disease_symptom_str = serialize($disease_symptom_arr); file_put_contents($file, $disease_symptom_str); } return $disease_symptom_arr; }
/** * 根据疾病的拼音简写,得到疾病的信息 * @author gaoqing * @date 2016-03-23 * @param String $pyInitial 疾病的拼音简写 * @return array 疾病的信息集 */ public function getDiseasesByPinyin($pyInitial) { $disease = []; if ($this->isNotNull($pyInitial)) { //疾病基本信息 $diseaseBasic = Disease::find()->where(['pinyin_initial' => $pyInitial])->asArray(true)->one(); //疾病详细信息 $diseaseContent = []; if ($this->isNotNull($diseaseBasic)) { $diseaseContent = DiseaseContent::find()->where(['id' => $diseaseBasic['id']])->asArray(true)->one(); } if ($this->isNotNull($diseaseBasic) && $this->isNotNull($diseaseContent)) { $diseaseContentApp = $diseaseContent; foreach ($diseaseContentApp as $key => $content) { $diseaseContentApp[$key] = String::cutString($content, 35); } $disease = array_merge($diseaseBasic, $diseaseContent); $disease['content_app'] = $diseaseContentApp; } } if (!isset($disease) || empty($disease)) { throw new NotFoundHttpException("当前访问的页面不存在!"); } return $disease; }
/** * 根据疾病id, 获取当前疾病相关疾病的图集 * @author gaoqing * @date 2016-05-05 * @param int $diseaseid 疾病id * @param int $size 所需的个数 * @return array 相关疾病的图集 */ public static function getRelDiseaseImages($diseaseid, $size) { $relDiseaseImages = []; //1、得到所有的相关疾病 $disease = new Disease(); $relDiseases = $disease->getDiseaseDisByDisid($diseaseid); //2、得到相关疾病的图集 if (isset($relDiseases) && !empty($relDiseases)) { $notHasImages = []; $inner = []; $relDiseaseImagesIndex = 0; foreach ($relDiseases as $relDisease) { $images = []; $inner['disease'] = $relDisease; $inner['images'] = $images; //2.1、如果当前图集,已经够 $size 了,就停止查询 if ($relDiseaseImagesIndex == 6) { break; } //2.2、得到疾病图集 $icondition = ['flag' => 1, 'relid' => $relDisease['id']]; $imagesTemp = Image::search($icondition); if (isset($imagesTemp['list']) && !empty($imagesTemp['list'])) { $images = $imagesTemp['list']; $inner['images'] = $images; $relDiseaseImages[] = $inner; $relDiseaseImagesIndex++; } else { $notHasImages[] = $inner; } } $relDiseaseImagesCount = count($relDiseaseImages); /* * 3.1、当前 $relDiseaseImages 中不到指定的个数 $size时: * 3.2、计算出,距离 $size 所需的个数 $needCount * 3.3、从 $notHasImages 中,提前 $needCount 个数据 */ if ($relDiseaseImagesCount < $size) { $needCount = $size - $relDiseaseImagesCount; $needArr = array_slice($notHasImages, 0, $needCount); $relDiseaseImages = array_merge($relDiseaseImages, $needArr); } } return $relDiseaseImages; }
/** * 查询科室下的对应疾病集 * @author gaoqing * @date 2016-04-08 * @param int $columns 在页面中,显示的列数 * @return array 科室下的对应疾病集 */ private static function getDepartmentDis($columns) { $departmentDis = array(); $department = new Department(); $disease = new Disease(); //get the first level departments $firstLevel = $department->getDepartmentLevel1(1); if (self::isNotNull($firstLevel)) { foreach ($firstLevel as $level1) { //select diseases that all belong current first level department $inner = array(); $inner['department'] = $level1; $size = count($firstLevel) * $columns; $inner['disease'] = $disease->getDiseaseByDepartment($level1['id'], 'class_level1', 0, $size); $departmentDis[] = $inner; } return $departmentDis; } return $departmentDis; }
public static function createAllDiseaseSymptomCache4Redis() { $redis = \Yii::$app->redis; $redis_expired = 24 * 60 * 60; //秒 $cache_all_disease_symptom_link_key = APP_CACHE_PREFIX . 'CACHE_ALL_DISEASE_SYMPTOM_LINK'; $cache_all_disease_symptom_link_data = array(); $all_disease = Disease::find()->select(['name', 'pinyin_initial'])->asArray()->all(); foreach ($all_disease as $k => $v) { $cache_all_disease_symptom_link_data[$v['name']] = \Yii::getAlias('@jb_domain') . '/' . $v['pinyin_initial'] . '/'; } $all_symptom = Symptom::find()->select(['name', 'pinyin_initial'])->asArray()->all(); foreach ($all_symptom as $k => $v) { $cache_all_disease_symptom_link_data[$v['name']] = \Yii::getAlias('@jb_domain') . '/zhengzhuang/' . $v['pinyin_initial'] . '/'; } $redis->hMset($cache_all_disease_symptom_link_key, $cache_all_disease_symptom_link_data, $redis_expired); return $cache_all_disease_symptom_link_data; }
public function actionRedirect() { $diseaseid = $this->helpGquery('disid', 0); if ($diseaseid > 0) { $oldDisease = new oldDisease(); $disInfo = $oldDisease->getDiseaseByContentid($diseaseid); $url = \Yii::getAlias("@jb_domain"); // var_dump($url);exit; if ($disInfo) { $disname = $disInfo['title']; $newDisInfo = Disease::find()->where('name=:name', [':name' => $disname])->one(); $pinyin_initial = $newDisInfo ? $newDisInfo->pinyin_initial : ''; $url .= '/' . $pinyin_initial . '/'; header("Location:{$url}", true, 301); exit; } else { $this->actionDispatch(); } } }
/** * * @param type $sphinx_data sphinx查询结果 * @return type */ public static function search_disease_data($sphinx_data) { $total = 0; $ret_list = array(); if (!empty($sphinx_data['matches'])) { $arr_ids = array(); foreach ($sphinx_data['matches'] as $k => $v) { $arr_ids[] = $k; } $disease_list = Disease::List_ByIds($arr_ids); if ($disease_list) { foreach ($disease_list as $k => $v) { $v['tmp_source_id'] = 1; $v['source_flag'] = 1; $v['url'] = sprintf('%s/%s/', Yii::getAlias('@jb_domain'), $v['pinyin_initial']); $v['wap_url'] = sprintf('%s/%s/', Yii::getAlias('@mjb_domain'), $v['pinyin_initial']); $ret_list[] = $v; } } $total = $sphinx_data['total']; } $explain_words = $sphinx_data['explain_words']; return array('list' => $ret_list, 'total' => $total, 'explain_words' => $explain_words); }
/** * 根据疾病的拼音简写,得到疾病的信息 * @author gaoqing * @date 2016-03-23 * @param String $pyInitial 疾病的拼音简写 * @param boolean $isRelDis 是否获取其 相关疾病 * @param boolean $isRelSym 是否获取其 典型症状 * @param boolean $isRelPart 是否获取其相关 部位 * @param boolean $isRelDep 是否获取其 就诊科室 * @return array 疾病的信息集 */ public function getDiseasesByPinyin($pyInitial, $isRelDis = false, $isRelSym = false, $isRelPart = false, $isRelDep = false) { $disease = []; //1、得到疾病的疾病信息 $disease = $this->disease->getDiseasesByPinyin($pyInitial); if ($this->isNotNull($disease)) { $disease['chuanranxing'] = '无'; if ($disease['chuanranflag'] == 1) { $disease['chuanranxing'] = '有'; } //2、获取科室信息 if ($isRelDep) { $treatDepNames = $this->explodeStr($disease['treat_department']); $disease['department'] = $this->department->getDepsByName($treatDepNames); $disease['medicine'] = $this->explodeStr($disease['medicine']); } //3、获取典型症状信息 if ($isRelSym) { $typicalSymptomNames = $this->explodeStr($disease['typical_symptom']); $disease['tsymptom'] = $this->symptom->getSymptomsByName($typicalSymptomNames); } //4、得到疾病对应的所有部位 if ($isRelPart) { $disease['part'] = Relate::getPartsByDisid($disease['id']); } //5、得到相关疾病 if ($isRelDis) { $relDiseaseNames = $this->explodeStr($disease['rel_disease']); $values = Disease::search(['name' => $relDiseaseNames]); if ($this->isNotNull($values)) { $disease['reldis'] = $values['list']; } } } return $disease; }
/** * 找医院 * @return type */ public function actionHospital() { $this->setLayout('disease_without_bottom'); $data = []; $obj_disease = new Disease(); $temp = $this->params; $disease = $obj_disease->getDiseasesByPinyin($temp['dname']); $data['disease'] = $disease; return $this->render('hospital', $data); }
/** * 疾病缓存 */ public function diseaseCache($param = [], $offset) { // $disease = new Disease(); // $res = $disease->getAllDisease(); $disease = new Disease(); $length = self::$length; $offset = ($offset - 1) * $length; // $res = $symptom->getAllSymptom(); $res = $disease->getDiseaseLimit([], $offset, $length); $i = 0; foreach ($res as $k => $v) { if (CacheHelper::$param['function']($param['key_prefix'], $v, true)) { $i++; } } return $i; }
/** * 文章页 * @author gaoqing * @date 2016-03-25 * @return string 视图 */ public function actionDetail() { $view = "detail"; $aid = $this->helpGparam("aid", "-1"); //获取文章的信息 $condition = ['id' => $aid]; $article = Article::search($condition, 0, 1); $article = $article['list']; if (!isset($article) || empty($article)) { throw new NotFoundHttpException('当前访问的页面不存在!'); } if ($this->isNotNull($article)) { $article = $article[0]; $article['inputtime'] = date('Y-m-d H:i:s', $article['inputtime']); $article['keywords_init'] = $article['keywords']; $article['keywords'] = explode(' ', $article['keywords']); } //文章内容添加疾病、症状词的链接 //lc@2016-5-24 $cache_all = Article::getAllDiseaseSymptom2Redis(); $content = $article['content']; $link_num = 5; //每页内链个数 $single_link_num = 1; //单个词链接个数 $i = 1; $str = ''; $count = 0; foreach ($cache_all as $k => $v) { $searchArr = '(' . $k . ')'; $replaceArr = '<a href="' . $v . '" title="' . $k . '" target="_blank">' . $k . '</a>'; if ($i > $link_num) { break; } if (stripos($str, $k) === false) { $content = preg_replace($searchArr, $replaceArr, $content, $single_link_num, $count); if ($count > 0) { $str .= $k; $i++; } } } $article['content'] = $content; //获取当前文章对应的疾病信息 $isSymptom = 0; if ($article['diseaseid'] > 0) { $disease_obj = new Disease(); $res = $disease_obj->getDiseaseById($article['diseaseid']); $disease = $res['disease']; $disease['inspect'] = $res['diseaseContent']['inspect']; } elseif ($article['symptomid'] > 0) { $symptom = Symptom::getSymptomByid($article['symptomid'], true); $disease = $symptom; $disease['inspect'] = $symptom['examine']; $isSymptom = 1; } //上一篇 $preCondition = ['<', 'id', $aid]; $preArticle = Article::search($preCondition, 0, 1, 'id DESC'); $preArticle = $preArticle['list']; if ($this->isNotNull($preArticle)) { $preArticle = $preArticle[0]; } //下一篇 $nextCondition = ['>', 'id', $aid]; $nextArticle = Article::search($nextCondition, 0, 1, 'id ASC'); $nextArticle = $nextArticle['list']; if ($this->isNotNull($nextArticle)) { $nextArticle = $nextArticle[0]; } $relArtsAndAsks = CacheHelper::getCache('frontend_article_detail_xgwz', ['title' => $article['title'], 'id' => $aid, 'diseaseid' => $article['diseaseid'], 'symptomid' => $article['symptomid']]); $relArticles = $relArtsAndAsks['relArticles']; //相关问答 $asks = $relArtsAndAsks['relAsks']; //hot words part $letter_list = range('A', 'Z'); $randwords = $this->rand_words(); $hotWords = ['letter' => $letter_list, 'words' => $randwords]; //common diseases and hot departments part $commonDisDep = CacheHelper::getCache('frontend_article_detail_rmksbw', []); //大家还在找部分 $stillFind = $this->getStillFindDatas($disease['name']); //右侧:最新文章 $lastestArticles = $this->getLatestArticles(); $params = ['article' => $article, 'preArticle' => $preArticle, 'nextArticle' => $nextArticle, 'relArticles' => $relArticles, 'asks' => $asks, 'isSymptom' => $isSymptom, 'disease' => $disease, 'hotWords' => $hotWords, 'commonDisDep' => $commonDisDep, 'stillFind' => $stillFind, 'lastestArticles' => $lastestArticles]; return $this->render($view, $params); }
private function disSymColSitemap() { /** * <urlset> * <url> * <loc>http://jb.9939.com/gm/jianjie/</loc> * <lastmod>2009-03-27</lastmod> * <changefreq>always</changefreq> * <priority>0.6</priority> * </url> * </urlset> */ $this->_changefreq = 'always'; $this->_priority = '0.6'; $where = $this->_ownership; $flag = 1; //目录 if ($where == 'pc') { $frontend = \Yii::getAlias("@frontend"); $frontDomain = \Yii::getAlias("@frontdomain"); } elseif ($where == 'wap') { $frontend = \Yii::getAlias("@wapjb"); $frontDomain = \Yii::getAlias("@mjb_domain"); } $sitemapFolder = $this->_baidu ? 'sitemap/sitemapbaidudissymcolindex' : 'sitemap/sitemapdissymcolindex'; $fileFolder = $frontend . '/web/' . $sitemapFolder; if (!file_exists($fileFolder) || !is_dir($fileFolder)) { mkdir($fileFolder, 0755, true); } $type = ''; // 疾病 | 症状 $sitemap_site = $this->getSitemapCount($fileFolder, ['dis_offset' => 0, 'sym_offset' => 0, 'max_file_tail' => 0]); $dis_offset = $sitemap_site['dis_offset']; $dis_obj = new Disease(); $dis_count = $dis_obj->getCount(); if ($dis_offset < $dis_count) { $type = 'disease'; $data = $dis_obj->getDiseaseLimit(['status' => 2], $dis_offset, 1000); $sitemap_site['dis_offset'] = (int) $dis_offset + count($data); } else { $type = 'symptom'; $sym_offset = $sitemap_site['sym_offset']; $dis_obj = new Symptom(); $sym_count = $dis_obj->getCount(); if ($sym_offset < $sym_count) { $data = $dis_obj->getSymptomLimit(['status' => 3], $sym_offset, 2000); $sitemap_site['sym_offset'] = (int) $sym_offset + count($data); $flag = $sitemap_site['sym_offset'] == $sym_count ? 2 : 1; } else { //无需生成新的数据,返回索引的url $res = $this->generateSitemapIndex($fileFolder, $sitemapFolder, 'dissym'); return ['flag' => 2, 'siteindex' => $res['url']]; } } //xml $sitemap = '<?xml version="1.0" encoding="UTF-8"?>'; $sitemap .= $this->_baidu ? '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">' : '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; $sitemap .= $this->setDiseaseSymptomSubURL($data, $type); $sitemap .= '</urlset>'; $sitemap_site['max_file_tail']++; $name_tail = $sitemap_site['max_file_tail']; //写入计数文件 $this->setSitemapCount($sitemap_site, $fileFolder); $fileName = 'sitemap' . $name_tail . '.xml'; if (file_put_contents($fileFolder . '/' . $fileName, $sitemap)) { $res = $this->generateSitemapIndex($fileFolder, $sitemapFolder, 'dissym'); return ['flag' => $flag, 'url' => $frontDomain . '/' . $sitemapFolder . '/' . $fileName, 'name' => $fileName, 'siteindex' => $res['url']]; } return []; }
/** * 根据分类id获取该分类下的疾病内容 * lc 2016-4-11 * @param type $optionMap 分类id数组 * @param type $contain_article 是否包含文章 * @return type */ public function getCategoryData($optionMap, $disease_length = 10, $contain_article = false, $article_length = 4) { $data = []; foreach ($optionMap as $k => $v) { $catId[] = $k; } $obj_disease = new Disease(); $tmp = $obj_disease->batGetDiseaseByCategoryId($catId); $obj_article = new Article(); // $disid = []; foreach ($tmp as $k => $v) { $data[$v['categoryid']]['disease'][] = $v; $disid[$v['categoryid']][] = $v['id']; } $new_data = []; foreach ($disid as $kk => $vv) { $new_data[$kk]['disease'] = array_slice($data[$kk]['disease'], 0, $disease_length); if ($contain_article) { $dis_str = implode(',', $vv); $res = $obj_article->getListByGroup($dis_str); $new_data[$kk]['article'] = array_slice($res, 0, $article_length); } } ksort($new_data); return $new_data; }
/** * 症状首页可能疾病缓存数据 * lc 2016-4-15 * @param type $cacheKey 缓存的唯一标识 * @param type $parms 单条症状所有字段内容数组 * @param type $forceCache 是否强制缓存,默认不强制缓存 * @return type */ public static function cacheSymptomRelateDisease($cacheKey, $parms, $forceCache = false) { $symptomid = $parms['id']; $cache = \Yii::$app->cache_data_file; $key = $cacheKey . '_' . $symptomid; $data = $cache->get($key); if ($forceCache) { $data = false; } if (!isset($data) || empty($data)) { $relate = new Relate(); $disease = new Disease(); $department = new Department(); $diseaseList = $relate->getRelateDiseases($symptomid); //根据关联表查询出疾病id,该症状对应的疾病下的所有疾病信息 // print_r($diseaseList);exit; if (!empty($diseaseList)) { $diseaseId = []; foreach ($diseaseList as $k => $v) { $diseaseId[] = $v['diseaseid']; } $diseaseMap = $disease->batchGetDiseaseById($diseaseId); //该症状对应的疾病下的所有疾病信息 $symptomMap = $relate->batchGetSymptomsByDisid($diseaseId); //该症状对应的疾病下对应的所有相关症状 $diseaseIdStr = implode(',', $diseaseId); $departmentMap = $department->batchGetDepartmentsByDisid($diseaseIdStr); //该症状对应的疾病对应的所有科室 // print_r($departmentMap);exit; foreach ($symptomMap as $k => $v) { $disId = $v['diseaseid']; $symId = $v['symptomid']; foreach ($diseaseMap as $kk => $vv) { $pinyin = $vv['pinyin_initial']; if ($vv['id'] == $disId) { $tmp[$pinyin][] = $v; } } } $diseaseTmp['relDisease'] = $diseaseMap; $diseaseTmp['relSymptom'] = $tmp; $disTmp = ['diseaseMap' => $diseaseMap, 'symptomMap' => $symptomMap, 'departmentMap' => $departmentMap, 'diseaseTmp' => $diseaseTmp, 'diseaseId' => $diseaseId]; $cache->set($key, $disTmp); return $disTmp; } return array(); } else { return $data; } }
<?php use yii\helpers\Url; use common\models\Disease; $obj_disease = new Disease(); $catId = [25]; $res = $obj_disease->batGetDiseaseByCategoryId($catId); $tmp = array_slice($res, 0, 8); ?> <h2>健康助手</h2> <nav class="asdc"> <a href="http://wapask.9939.com/ask/goAskDoctor"><span></span><p>问医生</p></a><a href="http://m.jb.9939.com/"><span></span><p>查疾病</p></a><a href="javascript:;"><span></span><p>找医院</p></a><a href="http://m.9939.com/drug/"><span></span><p>找药品</p></a> </nav> <article class="prot"> <?php if (!empty($tmp)) { foreach ($tmp as $k => $v) { $url = Url::to('/' . $v['pinyin_initial'] . '/'); if ($k % 4 == 0) { echo '<p>'; } echo '<a href="' . $url . '">' . $v['name'] . '</a>'; if ($k % 4 == 3) { echo '</p>'; } } } ?> </article>
public function init() { parent::init(); }
public function getDiseaseLimit($where = [], $offset = 0, $length = 10, $orderBy = 'id DESC') { return Disease::find()->where($where)->orderBy($orderBy)->offset($offset)->limit($length)->asArray()->all(); }