芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/xmintal-back/controllers/CustomerlicenseController.php
'yii\data\ActiveDataFilter', 'searchModel'=>(new DynamicModel(['mac_address']))->addRule(['mac_address'],'string') ]; return $actions; } public function actionCreatelicense(){ $data=Yii::$app->request->getBodyParams(); $customer_data=$data['customer']; $license_data=$data['customerlicense']; $payment_data=$data['payment']; $license_id=$license_data['license_id']; if($license_id){ $license_type=License::findOne((int)$license_id); } $response_code=422; $message='Corrije los siguientes errores con los datos de '; $errors=[]; if(isset($customer_data['id'])){ $customer=Customer::find()->where(['id'=>(int)$customer_data['id'],'active'=>1,'trash'=>0])->one(); }else{ $customer=new Customer; } $customer->attributes=$customer_data; if($customer->validate()){ $license=new CustomerLicense; $license->attributes=$license_data; $license->month_duration=$license_type->month_duration; $license->mac_address=trim($license->mac_address); if($license->validate()){ $payment=new Payment; $payment->attributes=$payment_data; $now=date('Y-m-d H:i:s'); $payment->payment_date=$now; $payment->validity_start_date=date('Y-m-d H:i:s',strtotime($payment->validity_start_date)); $payment->validity_end_date=date('Y-m-d H:i:s',strtotime($payment->validity_end_date)); if($payment->validate()){ if(isset($customer_data['id'])){ $customer->update(); }else{ $customer->save(); } $license->customer_id=$customer->id; $license->license_key=StringHelper::randomString(30); $license->save(); $payment->customerlicense_id=$license->id; $payment->save(); $response_code=200; $message='El registro fue dado de alta correctamente'; }else{ $message.='pago'; $errors=$payment->getErrors(); } }else{ $message.='licencia'; $errors=$license->getErrors(); } }else{ $message.='cliente'; $errors=$customer->getErrors(); } if(!empty($errors)){ foreach($errors as $key=>$value){ $message.=' '.$value[0].' '; } } Yii::$app->response->statusCode=$response_code; return ['message'=>$message,'errors'=>$errors,'item'=>$customer]; } public function actionValidate(){ $mac_address=Yii::$app->request->post('mac_address'); $username=Yii::$app->request->post('username'); $password=Yii::$app->request->post('password'); if($username){ $username=trim($username); } if($password){ $password=trim($password); }else{ $password=''; } $customer=Customer::find()->where(['username'=>$username])->one(); $valid=false; $validity='expired'; if($customer){ if($customer->active){ if(password_verify($password,$customer->password)){ if(!empty($mac_address)){ $mac_address=trim($mac_address); } $license=CustomerLicense::find()->where(['mac_address'=>$mac_address,'customer_id'=>$customer->id])->one(); if($license){ if($license->currentpayment){ $validity=date('d/m/Y',strtotime($license->currentpayment->validity_end_date)); $message='La licencia está activa'; $valid=true; }else{ $message='Licencia expirada'; } }else{ $message='No se encontró una licencia para este cuenta'; } }else{ $message='Contraseña incorrecta'; } }else{ $message='Usuario inactivo'; } }else{ $message='Usuario no encontrado'; } return ['valid'=>$valid,'expiry_date'=>$validity,'message'=>$message]; } } ?>