zhangxiaoli 5 years ago
parent 87eaf981e0
commit 37b2d8ecde
  1. 2
      common/models/CarT.php
  2. 251
      frontend/controllers/FinanceController.php
  3. 87
      frontend/views/finance/car-update-frame.php

@ -68,7 +68,7 @@ class CarT extends \common\models\Base
[['user_id', 'car_type_id', 'car_use_id'], 'required'],
[['user_id', 'car_type_id', 'car_use_id','seats','brand_id','series_id','displacement_id','location','invalid_id','invalid_flag','is_track','times','biaozhu','hiddenes'], 'integer'],
[['register_date', 'insurer1_date', 'insurer2_date','id_man','id_number','print_date','car_man_number', 'created_at', 'updated_at'], 'safe'],
[['car_no', 'factory_model', 'car_model', 'engine_no', 'car_frame_no','old_user','phone1'], 'string', 'max' => 50],
[['car_no', 'factory_model', 'car_model', 'engine_no', 'car_frame_no','old_user','phone1','id_phone'], 'string', 'max' => 50],
[['car_year'], 'string', 'max' => 10],
[['car_man','phone','remark','company','op_user1','op_user2','op_user3','weixin','from_src'], 'string', 'max' => 200],
];

@ -3070,6 +3070,7 @@ class FinanceController extends \frontend\controllers\UserBaseController
$result['files'][] = $row;
return json_encode($result);
}
// dd($result);
$result['files'][0]['error'] = '上传文件失败';
return json_encode($result);
@ -6812,5 +6813,255 @@ class FinanceController extends \frontend\controllers\UserBaseController
}
public function actionCarUpdateFrame()
{
return $this->render('car-update-frame', []);
}
public function actionCarUpdateFrameInfo()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '操作失败';
// $company = $request->post('company', '');
$web_path = Yii::$app->getBasePath() . '/../frontend/web';
$filename = $web_path . $request->post('urlfile');
$base_filename=$request->post('urlfile');
//
// $file_path = \Yii::getAlias('@console').'/controllers/';
// $yearname='wash12.xlsx';
// $filename = $file_path.$yearname;
// $basename=$yearname;
// $company = $request->post('company', '');
//
// $web_path = Yii::$app->getBasePath() . '/../frontend/web';
//
// $urlfile = $web_path . $request->post('urlfile');
// if(file_exists($filename)) {
// echo 'OK'."\r\n";
// }
//读取Excel 2007
$PHPReader = new \PHPExcel_Reader_Excel2007();
if (!$PHPReader->canRead($filename)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filename)) {
$errorMessage = "Can not read file.";
echo $errorMessage;
return;
}
}
$PHPExcel = $PHPReader->load($filename);
$currentSheet = $PHPExcel->getSheet(0);
$rowCount = $currentSheet->getHighestRow();
//$data = $currentSheet->toArray('', true, true);
//创建新的xlsx表
// $objectPHPExcel = new \PHPExcel();
// $index = 1;
$insert_total = 0;
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$index,'车牌号');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$index,'车架号');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$index,'发动机号');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$index,'品牌车型');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('E'.$index,'车主');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$index,'证件号');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('G'.$index,'联系方式');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$index,'保险到期日');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('I'.$index,'初登日期');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('J'.$index,'标准初登日期');
// $objectPHPExcel->setActiveSheetIndex(0)->setCellValue('K'.$index,'车牌号不匹配');
for ($i = 2; $i <= $rowCount; $i++) {
// echo $i.'/'.$rowCount."...";
$cell = $currentSheet->getCellByColumnAndRow(0, $i);
$car_no = $cell->getValue();
// $cell = $currentSheet->getCellByColumnAndRow(1, $i);
// $car_man = $cell->getValue();
$cell = $currentSheet->getCellByColumnAndRow(1, $i);
$factory_model = $cell->getValue();//$data[$i][3];
$cell = $currentSheet->getCellByColumnAndRow(2, $i);
$engine_no = $cell->getValue();//$data[$i][2];
// var_dump($cars);
$cell = $currentSheet->getCellByColumnAndRow(3, $i);
$car_frame_no = $cell->getValue();//$data[$i][1];
// var_dump($car_frame_no);
$cell = $currentSheet->getCellByColumnAndRow(4, $i);
$register_date = $cell->getValue();//$data[$i][8];
$cell = $currentSheet->getCellByColumnAndRow(5, $i);
$company = $cell->getValue();//$data[$i][8];
$cell = $currentSheet->getCellByColumnAndRow(6, $i);
$insurer1_date = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(7, $i);
$insurer2_date = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(8, $i);
$seats = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(9, $i);
$car_man = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(10, $i);
$car_man_number = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(11, $i);
$car_man_phone = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(12, $i);
$id_man = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(13, $i);
$id_number = $cell->getFormattedValue();
$cell = $currentSheet->getCellByColumnAndRow(14, $i);
$id_phone = $cell->getFormattedValue();
$car_info = CarT::findOne(['car_frame_no' => $car_frame_no]);
if ($car_info) {
//
// $car_c_info = CarCT::findOne(['id' => $car_info->id]);
// $car_d_info = CarDT::findOne(['id' => $car_info->id]);
// $car_e_info = CarET::findOne(['id' => $car_info->id]);
//
// if ($car_c_info || $car_d_info || $car_e_info) {
// continue;
// }
if($car_no != ''){
$car_info->car_no = $car_no;
}
if($car_man != ''){
$car_info->car_man = $car_man;
}
if($factory_model != ''){
$car_info->factory_model = $factory_model;
}
if($engine_no != ''){
$car_info->engine_no = $engine_no;
}
// if($car_frame_no != ''){
// $car_info->car_frame_no = $car_frame_no;
// }
if($register_date != ''){
$car_info->register_date = $register_date;
}
if($company != ''){
$car_info->company = $company;
}
if($insurer1_date != ''){
$car_info->insurer1_date = $insurer1_date;
}
if($insurer2_date != ''){
$car_info->insurer2_date = $insurer2_date;
}
if($id_man != ''){
$car_info->id_man = $id_man;
}
if($id_number != ''){
$car_info->id_number = $id_number;
}
if($id_phone != ''){
$car_info->id_phone = $id_phone;
}
if($seats != ''){
$car_info->seats = $seats;
}
if($car_man_number != ''){
$car_info->car_man_number = $car_man_number;
}
if($car_man_phone != ''){
$car_info->phone = $car_man_phone;
}
// $car_info->save();
if(!$car_info->save(false)) {
var_dump($car_info->errors);
exit;
}
$insert_total++;
}
if (!$car_info) {
$car_info = new CarT();
if($car_no != ''){
$car_info->car_no = $car_no;
}
if($car_man != ''){
$car_info->car_man = $car_man;
}
if($factory_model != ''){
$car_info->factory_model = $factory_model;
}
if($engine_no != ''){
$car_info->engine_no = $engine_no;
}
if($car_frame_no != ''){
$car_info->car_frame_no = $car_frame_no;
}
if($register_date != ''){
$car_info->register_date = $register_date;
}
if($company != ''){
$car_info->company = $company;
}
if($insurer1_date != ''){
$car_info->insurer1_date = $insurer1_date;
}
if($insurer2_date != ''){
$car_info->insurer2_date = $insurer2_date;
}
if($id_man != ''){
$car_info->id_man = $id_man;
}
if($id_number != ''){
$car_info->id_number = $id_number;
}
if($id_phone != ''){
$car_info->id_phone = $id_phone;
}
if($seats != ''){
$car_info->seats = $seats;
}
if($car_man_number != ''){
$car_info->car_man_number = $car_man_number;
}
if($car_man_phone != ''){
$car_info->phone = $car_man_phone;
}
// $car_info->save();
if(!$car_info->save(false)) {
var_dump($car_info->errors);
exit;
}
$insert_total++;
}
}
// $log = new ImportLogT();
// $datacount=$rowCount;
// $log->filename = $base_filename;
// $log->total = $datacount;
// $log->success = $insert_total;
// $log->success_rate = ($insert_total/$datacount) * 100;
// $log->save();
$result['success'] = true;
$result['msg'] = '操作成功';
return $result;
}
}

@ -0,0 +1,87 @@
<?php
use \common\libs\MyLib;
?>
<link rel="stylesheet" href="/js/fileupload/css/jquery.fileupload.css">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
<form id="theFrm">
<tr>
<td align="center" width="100" height="25" class="td_bg">导入类型</td>
<td height="25" class="td_bg">数据导入</td>
</tr>
<tr>
<td align="center" width="100" height="25" class="td_bg">批对日期</td>
<td height="25" class="td_bg">
<input type="text" name="urlfile" id="urlfile" style="width: 300px;">
<input id="fileupload" type="file" name="file">
</td>
</tr>
</form>
<tr>
<td height="22" colspan="2" align="center" class="td_bg">
<input id="submit-btn" type=button class="ACT_btn" name=Submit1 value=" 提交 "/>
&nbsp;&nbsp;
<input type="button" class="ACT_btn" name="Submit3" value=" 刷新 " onclick="window.location.reload();">
</td>
</tr>
</table>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/jquery.fileupload.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js?v=2019"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript">
//编辑
$(function () {
//上传按钮
$('#upload-btn').click(function(){
$('#fileupload').click();
});
//提交按钮
$("#submit-btn").click(function(){
if(confirm('是否确认提交?')) {
var urlfile = $("#urlfile").val();
var import_type = $(".import_type").val();
if(urlfile == ''){
alert('请先选择文件!');
return false;
}
var last_url = '/finance/car-update-frame-info';
var params = $("#theFrm").serialize();
$.post(last_url,params,function(obj){
alert(obj.msg);
if(obj.success){
$('#theFrm')[0].reset();
window.location.reload();
}
},'json');
}
});
//上传
$('#fileupload').fileupload({
url: '/finance/receipt-upload',
dataType: 'json',
done: function (e, data) {
var file_info = data.result.files[0];
$('#urlfile').val(file_info.url);
$('#submit-btn').removeAttr('disabled');
}
});
})
</script>
<style>
input[type="text"] {
width: 134px;
}
</style>
Loading…
Cancel
Save