public function insertData() { $taskPath = DATA_DIR . 'excel/task.k'; if (!file_exists($taskPath)) { $this->errorOutput('任务文件不存在'); } $task = file_get_contents($taskPath); $task = unserialize($task); if (!$task) { $this->errorOutput('没有任务要执行'); } //执行任务 foreach ($task as $_k => $_v) { $market_id = $_v['market_id']; if (!file_exists($_v['filename'])) { continue; //文件不存在就直接执行下一个 } $userdata = file_get_contents($_v['filename']); $arr = json_decode($userdata, 1); foreach ($arr as $k => $v) { //验证卡号 if (!$v[0]) { continue; } else { if ($this->mode->isExistsMember(" card_number = '" . $v[0] . "' AND market_id = '" . $market_id . "' ")) { continue; } } //名称 if (!$v[1]) { continue; } //验证生日 if (!$v[2]) { continue; } //验证手机号 if (!$v[3]) { continue; } //根据身份证号得到出生日期以及年龄并且保存起来 $idCardInfo = new IdCard(); $birthday = date('Y-m-d', strtotime($v[2])); $age = $idCardInfo->getAge($birthday); $month = intval(date('m', strtotime($birthday))); $day = intval(date('d', strtotime($birthday))); $constellation_id = $idCardInfo->getConstellation($birthday); $data = array('card_number' => $v[0], 'name' => $v[1], 'phone_number' => $v[3], 'age' => $age, 'month' => $month, 'day' => $day, 'birthday' => $birthday, 'constellation_id' => $constellation_id, 'market_id' => $market_id, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'update_user_id' => $this->user['user_id'], 'update_user_name' => $this->user['user_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip()); $this->mode->create($data); } //每导完一条任务就删掉这条数据 unlink($_v['filename']); } //全部导完之后,删除锁文件 unlink($taskPath); $this->addItem('success'); $this->output(); }
/** * 根据身份证的前17位算出完整的18位身份证号 * * @param string $idCard 身份证号 * * @return string */ private static function _createIdCard($idCard) { if (!isset($idCard[16])) { self::$_error = '身份证号不合法[错误代码003]'; return false; } $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); $verifyCodeList = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); $checksum = 0; for ($i = 0; $i < 17; $i++) { $checksum += $idCard[$i] * $factor[$i]; } $mod = $checksum % 11; $idCard = substr($idCard, 0, 17) . $verifyCodeList[$mod]; return strtoupper($idCard); }
} public function verify_id_card() { if (empty($this->id_card)) { return "id_car is empty"; } if (strlen($this->id_card) != 18) { return "id_card length is wrong"; } $id_card = $this->id_card; $check_indexs = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //0-1-2-3-4-5-6-7-8-9-10 对应1-0-X -9-8-7-6-5-4-3-2 $remainder = array(1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2); $tmp_total = 0; foreach ($check_indexs as $i => $check_index) { $tmp_total += $check_index * $id_card[$i]; } $remaind_index = $tmp_total % 11; $real_id_card = substr($id_card, 0, -1) . "{$remainder[$remaind_index]}"; if ($id_card[17] != $remainder[$remaind_index]) { return "{$this->id_card} last check_code is wrong,real_idcard is {$real_id_card}"; } return $this->id_card . " is ok!!!"; } public function get_idcard_info() { } } $test_id_card = "120113198105113214"; $id_card_obj = new IdCard($test_id_card); echo $id_card_obj->verify_id_card();
/** * @brief 提交二维码诊后报到申请 * @author zjj * @exampleUrl http://dev.mobile-api.haodf.com/patientapi/patientsignin_patientSignin4QRCode?name=TestDay&sex=0&relation=0&birthday=2014-01-18&city=北京&province=北京&xdebug=1 * * @param $name * @param $sex * @param $birthday * @param $province * @param $city * @param $diseaseName * @param $hospitalCaseNO * @param $idcard * @param $spaceId * @param $diseaseId * * @return array('msg') */ public function patientSignin4QRCode($name, $sex, $birthday, $province, $city, $diseaseName, $hospitalCaseNO, $idcard, $spaceId, $diseaseId, $patientId) {/*{{{*/ if ($diseaseName == '') { $this->setErrorCode(802); return 0; } if ($hospitalCaseNO == '') { $this->setErrorCode(803); return 0; } $disease = DAL::get()->find('Disease', $diseaseId); if ($disease->isNull()) { $this->setErrorCode(804); return 0; } $user = DAL::get()->find('user', $this->currentUserId); if ($user->isNull()) { $this->setErrorCode(178); return 0; } if($idcard != '') { if(15 == strlen($idcard)) { $idcard = IdCard::idcard_15to18($idcard); } if(false == IdCard::idcard_checksum18($idcard)) { $this->setErrorCode(312); return 0; } } if ($patientId != '') { $patient = DAL::get()->find('Patient', $patientId); if ($patient->isNull()) { $this->setErrorCode(309); return 0; } }else{ $params = array(); $params['name'] = $name; $params['sex'] = $sex; $params['relation'] = Patient::RELATION_SELF; $params['province'] = $province; $params['city'] = $city; $params['birthday'] = $birthday; $params['mobile'] = $user->mobile; $params['idcard'] = $idcard; $patient = PatientClient::getInstance()->add($user, $params); } $spaceId = $this->filterHttpUrlString($spaceId); $space = DAL::get()->find('Space', $spaceId); if ($space->isNull()) { $this->setErrorCode(144); return 0; } $QRcodePatientSignin = DAL::get()->find_by_QRpatientSign('patientsignin', $space->id, $patient->id); $res = array(); if(false == $QRcodePatientSignin->isNull()) { if($QRcodePatientSignin->isUnaudited()) { $res['msg'] = self::PATIENT_SIGNIN_RES_AUDIT; } } if (empty($res)) { $signinId = PatientSigninClient::getInstance()->addQRCODEPatientSignin($space, $patient, $hospitalCaseNO, $diseaseName, $diseaseId); $newQRCodePatientSignin = DAL::get()->find('patientsignin', $signinId); if ($newQRCodePatientSignin->isNull()) { $this->setErrorCode(801); return 0; } $disease = DAL::get()->find('disease', $diseaseId); PatientFileClient::getInstance()->createPatientHealthApply4QRCode($patient->id, $diseaseId, $disease->name); $res['msg'] = self::PATIENT_SIGNIN_RES_SUC; } $this->content = $res; }/*}}}*/
public function importMemberData() { $market_id = $this->input['market_id']; if (!$market_id) { $this->errorOutput(NOID); } //首先将上传上来的excel文件放到data目录 if (!$_FILES['excelfile']['tmp_name']) { $this->errorOutput(NO_FILE); } $original = urldecode($_FILES['excelfile']['name']); $filetype = strtolower(strrchr($original, '.')); if (!in_array($filetype, array('.xlsx', '.xls'))) { $this->errorOutput('此文件格式不支持'); } $name = date('Y-m-d', TIMENOW) . '-' . TIMENOW . hg_rand_num(6); $filename = $name . $filetype; $filepath = DATA_DIR . 'excel/'; if (!hg_mkdir($filepath) || !is_writeable($filepath)) { $this->errorOutput(NOWRITE); } if (!@move_uploaded_file($_FILES['excelfile']['tmp_name'], $filepath . $filename)) { $this->errorOutput(FAIL_MOVE); } //上传成功之后就初始化数据,将excel数据读入缓存文件中 $PHPExcelInfo = new PHPExcelInfo($filepath . $filename); $memberInfo = $PHPExcelInfo->getData(); if ($memberInfo) { foreach ($memberInfo as $k => $v) { //验证卡号 if (!$v[0]) { continue; } else { if ($this->mode->isExistsMember(" card_number = '" . $v[0] . "' AND market_id = '" . $market_id . "' ")) { continue; } } //名称 if (!$v[1]) { continue; } //验证生日 if (!$v[2]) { continue; } //验证手机号 if (!$v[3]) { continue; } //根据身份证号得到出生日期以及年龄并且保存起来 $idCardInfo = new IdCard(); $birthday = date('Y-m-d', strtotime($v[2])); $age = $idCardInfo->getAge($birthday); $month = intval(date('m', strtotime($birthday))); $day = intval(date('d', strtotime($birthday))); $constellation_id = $idCardInfo->getConstellation($birthday); $data = array('card_number' => $v[0], 'name' => $v[1], 'phone_number' => $v[3], 'age' => $age, 'month' => $month, 'day' => $day, 'birthday' => $birthday, 'constellation_id' => $constellation_id, 'market_id' => $market_id, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'update_user_id' => $this->user['user_id'], 'update_user_name' => $this->user['user_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip()); $this->mode->create($data); } } $this->addItem('success'); $this->output(); }
public function newSetPatient($userId, $patientId, $name, $sex, $province, $city, $idcard, $paperstype, $birthday, $mobile, $relation) {/*{{{*/ $user = DAL::get()->find('user', $userId); error_log('birthday:'.$birthday."\n",3,'/tmp/wap123.log'); $request = new Request(); if($request->os == 'ios' && $request->v == '2.1.0' && $paperstype == '0') { $birthday = substr($birthday, 0, 4)."-".substr($birthday, 4, 2)."-".substr($birthday, 6, 2); } else { $birthday = date('Y-m-d',$birthday); } if ($user->isNull()) { $this->setErrorCode(107); return 0; } if(0 == $paperstype) { if(15 == strlen($idcard)) { $idcard = IdCard::idcard_15to18($idcard); } if(false == IdCard::idcard_checksum18($idcard)) { $this->setErrorCode(312); return 0; } } $patientNew = DAL::get()->find('patient', $patientId); if("" == trim($name)) { $this->setErrorCode(176); return 0; } if("" == trim($birthday)) { $this->setErrorCode(171); return 0; } if("" == trim($sex)) { $this->setErrorCode(172); return 0; } if("" == trim($province)) { $this->setErrorCode(173); return 0; } if("" == trim($city)) { $this->setErrorCode(174); return 0; } if("" == trim($relation)) { $this->setErrorCode(175); return 0; } if(false == XString::isMobile($mobile)) { $this->setErrorCode(110); return 0; } /** 患者不存在,写入一条患者信息 */ if ($patientNew->isNull()) { $birthday = $birthday; $params = array( 'name' => trim($name), 'sex' => trim($sex), 'province' => trim($province), 'city' => trim($city), 'idcard' => trim($idcard), 'paperstype'=> trim($paperstype), 'birthday' => trim($birthday), 'mobile' => trim($mobile), 'relation' => trim($relation), ); $theSame = PatientClient::getInstance()->theSame($user, $params, 'jiahao'); if(false == $theSame) { $patientInfo = PatientClient::getInstance()->add($user, $params, 0, '', '', 'jiahao'); } else { $patientInfo = DAL::get()->find('patient', $theSame); } } else { $info = array(); $info['paperstype'] = trim($paperstype); $info['idcard'] = trim($idcard); $info['name'] = trim($name); $info['mobile'] = trim($mobile); //svc方法中会对info中有的字段会被重新赋值。我们不会更改省和市的字段(客户端获取信息时省市拼接一个字段返回,所以无法区别省市回传) // $info['province'] = trim($province); // $info['city'] = trim($city); $info['birthday'] = trim($birthday); if (false == empty($info)) { PatientClient::getInstance()->modifyInfo($patientNew->id , $info); } $patientInfo = $patientNew; } $patient = array(); $patient['patientId'] = $patientInfo->id; $this->content = $patient; }/*}}}*/