/** * @param string $staion 站名 * @param boolean $bl_insert 如果站名不存在,是否添加 * @return int 站名ID */ public function GetTrainCityId($station, $bl_insert = true) { $w = array('cityname' => $station); $one = $this->GetOne($w, 'id', 'rhi_trainstation'); $id = 0; if (!$one && $bl_insert) { $data = array('cityname' => $station); require_once COMMON_PATH . "Xpinyin.php"; $py = new Xpinyin(); $data['pinyin'] = $py->getAllPY($station); $data['szm'] = $py->getFirstPY($station); $data['flag'] = 1; $id = $this->AddOne($data, 'rhi_trainstation'); } else { $id = $one['id']; } return $id; }
public function testupdateDataAction() { $model = new PSys_RegionModel(); $list = $model->GetList('region_type > 0 and region_type < 3', ' region_id ASC', 0, 0, "*"); require_once COMMON_PATH . "Xpinyin.php"; $py = new Xpinyin(); foreach ($list['allrow'] as $lv) { $pinyin = $py->Pinyin($lv['region_name']); //全拼 $logogram = $py->getInitials($lv['region_name']); //简写 $initials = substr($logogram, 0, 1); //首字母 $data = array('initials' => $initials, 'pinyin' => $pinyin, 'logogram' => $logogram); $w = array('region_id' => $lv['region_id']); $model->UpdateOne($data, $w); } echo "更新完毕"; }