各位大神好~
小魯又問問題了...
小魯今天被前輩提醒 Code要好維護 資料跟邏輯要拆分 但小魯腦袋卡住轉不過來想說我已經將PDO用Class包裝 這樣不算拆分嗎?
不知道大神們都是怎麼處理這件事的?
底下是被嫌棄的Code一部分 風格大概都是這樣 想請大神給點建議他他乾淨一點
乾霞QQ
private function Chekdata($jsondata){
if($jsondata['username']==''){
$this->SetResult(-1,'帳號為空');
return false;
}
if($jsondata['password']==''){
$this->SetResult(-1,'密碼為空');
return false;
}
if($jsondata['startcode']==''){
$this->SetResult(-1,'啟動碼為空');
return false;
}
if($jsondata['machinecode']==''){
$this->SetResult(-1,'機碼為空');
return false;
}
if(!DBGetter::Get()->Check('member','account',$jsondata['username'])){
$this->SetResult(1,'錯誤的帳號');
return false;
}
$memberdata = DBGetter::Get()->QueryOne('member','id,password,startcode,used_period','account',$jsondata['username']);
$Passworder = new DjangoPassworder();
$this->memberid = $memberdata['id'];
if(!$Passworder->VerifyPassword( $jsondata['password'],$memberdata['password'] )){
$this->SetResult(1,'錯誤的密碼');
return false;
}
if($memberdata['used_period'] < date("Y-m-d")){
$this->SetResult(2,'使用期限過期');
return false;
}
if($jsondata['startcode'] != $memberdata['startcode'] ){
$this->SetResult(3,'啟動碼與登入帳戶不符');
return false;
}
$sql ="SELECT activate FROM machinecode WHERE code = :code And member_id = $this->memberid";
$tmp_db =DBGetter::Get()->DB()->prepare($sql);
$tmp_db->bindParam(":code",$jsondata['machinecode']);
$tmp_db->execute();
$machinecode = $tmp_db->fetch(PDO::FETCH_ASSOC);
if(!$machinecode){
$this->SetResult(4,'機碼與登入帳戶不符');
return false;
}
if($machinecode['activate'] == 0){
$this->SetResult(5,'該機碼已被禁用');
return false;
}
return true;
}