get($where); if(!$val){ echo 'getKqRules failed,Rules is empty!'.PHP_EOL; return false; } $info = json_decode($val,true); if($field) return $info[$field]; else return $info; } public static function getKqRuleDetail( $ruleId ){ if(!$ruleId){ echo 'getKqRuleDetail failed,ruleId empty!'.PHP_EOL; return false; } $p = Redis("xskq_rule_detail","hash"); $where = strtoupper($ruleId); $val = $p->get($where); if(!$val){ echo 'getKqRuleDetail failed,RuleDetail is empty!'.PHP_EOL; return false; } $info = json_decode($val,true); return $info; } public static function setSessionRules( $loginmark, $token ){ if(!$loginmark){ echo 'setKqRules failed,loginmark empty!'.PHP_EOL; return false; } if(!$token){ echo 'setKqRules failed,token empty!'.PHP_EOL; return false; } //保存token到redis $p = Redis("czapp_client_login_session","hash"); $key = $loginmark; $session_info = array( "token"=>$token, "login_time" => date('Y-m-d H:i:s'), "expire"=> 1200 ); $val = json_encode($session_info,JSON_UNESCAPED_UNICODE); $hash = array($key => $val ); return $p->add($hash); } public static function setKqRuleDetail( $ruleId, $info ){ if(!$ruleId){ echo 'setKqRuleDetail failed,ruleId empty!'.PHP_EOL; return false; } if(!$info){ echo 'setKqRuleDetail failed,info empty!'.PHP_EOL; return false; } //更新缓存信息 $p = Redis("xskq_rule_detail","hash"); $key = strtoupper($ruleId); $val = json_encode($info,JSON_UNESCAPED_UNICODE); $hash = array($key => $val ); return $p->add($hash); } public static function deleteKqRules( $gradeId ){ if(!$gradeId){ echo 'deleteKqRules failed,gradeId empty!'.PHP_EOL; return false; } $p = Redis("xskq_rules","hash"); $where = strtoupper($gradeId); $p->where($where)->delete(); return true; } public static function deleteKqRuleDetail( $ruleId ){ if(!$ruleId){ echo 'deleteKqRuleDetail failed,ruleId empty!'.PHP_EOL; return false; } $p = Redis("xskq_rule_detail","hash"); $where = strtoupper($ruleId); $p->where($where)->delete(); return true; } public static function setUserPunchRecord( $rfid, $date, $info ){ if(!$rfid){ echo 'setUserPunchRecord failed,rfid empty!'.PHP_EOL; return false; } if(!$info){ echo 'setUserPunchRecord failed,info empty!'.PHP_EOL; return false; } if(!$date){ echo 'setUserPunchRecord failed,date empty!'.PHP_EOL; return false; } //更新缓存信息 $p = Redis("xskq_user_punch_record_".substr($date,0,6),"hash"); $key = strtoupper($rfid.'_'.$date); $val = json_encode($info,JSON_UNESCAPED_UNICODE); $hash = array($key => $val ); return $p->add($hash); } public static function getUserPunchRecord( $rfid, $date, $field ){ if(!$rfid){ echo 'getUserPunchRecord failed,rfid empty!'.PHP_EOL; return false; } if(!$date){ echo 'getUserPunchRecord failed,date empty!'.PHP_EOL; return false; } $p = Redis("xskq_user_punch_record_".substr($date,0,6),"hash"); $where = strtoupper($rfid.'_'.$date); $val = $p->get($where); if(!$val){ //如果没有打卡记录,就初始化一条 $init_status = array( 'in'=>C('KQ_RECORDS_STATUS_NO_RECORD'), 'out'=>C('KQ_RECORDS_STATUS_NO_RECORD'), ); $init_data = array( C('KQ_RULE_DETAIL_ALL_TYPE_TEXT')[C('KQ_RULE_DETAIL_TYPE_EARLY')] => $init_status, C('KQ_RULE_DETAIL_ALL_TYPE_TEXT')[C('KQ_RULE_DETAIL_TYPE_AM')] => $init_status, C('KQ_RULE_DETAIL_ALL_TYPE_TEXT')[C('KQ_RULE_DETAIL_TYPE_PM')] => $init_status, C('KQ_RULE_DETAIL_ALL_TYPE_TEXT')[C('KQ_RULE_DETAIL_TYPE_NIGHT')] => $init_status, C('KQ_RULE_DETAIL_ALL_TYPE_TEXT')[C('KQ_RULE_DETAIL_TYPE_AM_PM')] => $init_status, ); $result = self::setUserPunchRecord($rfid,$date,$init_data); if(!$result){ echo 'init user punch record failed, ActiveRfid: '.$rfid.PHP_EOL; return false; } echo 'init user punch record success, ActiveRfid: '.$rfid.PHP_EOL; return $init_data; } $info = json_decode($val,true); if($field) return $info[$field]; else return $info; } public static function setStudentKqRules( $studentId, $info ){ if(!$studentId){ echo 'setKqRules failed,studentId empty!'.PHP_EOL; return false; } $p = Redis("xskq_student_rules","hash"); $key = strtoupper($studentId); $val = json_encode($info,JSON_UNESCAPED_UNICODE); $hash = array($studentId => $val ); return $p->add($hash); } public static function deleteKqStudentRules( $studentId ){ if(!$studentId){ echo 'deleteKqRules failed,studentId empty!'.PHP_EOL; return false; } $p = Redis("xskq_student_rules","hash"); $where = strtoupper($studentId); $p->where($where)->delete(); return true; } }