business add import and undisplay price_coplus
This commit is contained in:
@@ -274,6 +274,181 @@ class Business extends HD_Controller{
|
||||
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
||||
}
|
||||
|
||||
function add_excel()
|
||||
{
|
||||
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
|
||||
$res = $this->upload();
|
||||
if (!$res['code']) {
|
||||
return $this->show_json(0, $res['message']);
|
||||
}
|
||||
$file = $res['path'];
|
||||
if ($res['file_ext'] == '.xls') {
|
||||
$reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档
|
||||
} elseif ($res['file_ext'] == '.xlsx') {
|
||||
$reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
|
||||
} else {
|
||||
return $this->show_json(SYS_CODE_FAIL, '文件无法识别');
|
||||
}
|
||||
$PHPExcel = $reader->load($file); // 文档名称
|
||||
$objWorksheet = $PHPExcel->getActiveSheet();
|
||||
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
|
||||
if ($rowCnt > 800) {
|
||||
@unlink($file);
|
||||
return $this->show_json(0, '数据大于800请拆分多个表格导入');
|
||||
}
|
||||
$data = array();
|
||||
$yearary = $this->auto_business_model->year();
|
||||
$monthary = $this->auto_business_model->month();
|
||||
$c_time = time();
|
||||
$count = $rowCnt - 1;
|
||||
$count_ignore = 0;
|
||||
$msg_debug = "file: {$file};count: {$count};";
|
||||
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
|
||||
$brand_name = $objWorksheet->getCell('A' . $_row)->getValue();
|
||||
$res = $this->auto_brand_model->get(array('status'=>1, 'name'=>$brand_name), 'id');
|
||||
if (!$res){
|
||||
$count_ignore += 1;
|
||||
$msg_debug .= 'no brand_id;';
|
||||
continue;
|
||||
}
|
||||
$brand_id = $res['id'];
|
||||
|
||||
$s_name = $objWorksheet->getCell('B' . $_row)->getValue();
|
||||
$res = $this->auto_series_model->get(array('status'=>1, 'brand_id'=> $brand_id, 'name'=>$s_name), 'id');
|
||||
if (!$res){
|
||||
$count_ignore += 1;
|
||||
$msg_debug .= 'no s_id;';
|
||||
continue;
|
||||
}
|
||||
$s_id = $res['id'];
|
||||
|
||||
$v_name = $objWorksheet->getCell('C' . $_row)->getValue();
|
||||
$res = $this->auto_attr_model->get(array('status'=>1, 's_id'=> $s_id, 'title'=>$v_name), 'id');
|
||||
if (!$res){
|
||||
$count_ignore += 1;
|
||||
$msg_debug .= 'no v_id;';
|
||||
continue;
|
||||
}
|
||||
$v_id = $res['id'];
|
||||
|
||||
$city_name = $objWorksheet->getCell('D' . $_row)->getValue();
|
||||
if (!$city_name){
|
||||
$count_ignore += 1;
|
||||
$msg_debug .= 'no city_name;';
|
||||
continue;
|
||||
}
|
||||
$res = $this->sys_city_model->get(array('status'=>1, "name like '%{$city_name}%'"=>null), 'city_id');
|
||||
if (!$res){
|
||||
$count_ignore += 1;
|
||||
$sql = $this->sys_city_model->db->last_query();
|
||||
$msg_debug .= "no city_id: {$sql};";
|
||||
continue;
|
||||
}
|
||||
$city_id = $res['city_id'];
|
||||
|
||||
$s_effect_date = $objWorksheet->getCell('E' . $_row)->getValue(); # 此处得到是距离1900-01-01天数
|
||||
$s_effect_date && $s_effect_date = gmdate("Y-m-d", \PHPExcel_Shared_Date::ExcelToPHP($s_effect_date));
|
||||
$s_effect_time = 0;
|
||||
$if_effect = 0;
|
||||
if ($s_effect_date) {
|
||||
$s_effect_time = strtotime($s_effect_date);
|
||||
if($c_time>$s_effect_time){
|
||||
$if_effect = 1;
|
||||
}
|
||||
}
|
||||
$msg_debug .= "s_effect_date:{$s_effect_date};s_effect_time:{$s_effect_time};if_effect:{$if_effect};";
|
||||
|
||||
$year = $objWorksheet->getCell('F' . $_row)->getValue();
|
||||
$month = $objWorksheet->getCell('G' . $_row)->getValue();
|
||||
$year = intval($year);
|
||||
$month = intval($month);
|
||||
if (!in_array($year, $yearary) || !in_array($month, $monthary)){
|
||||
$count_ignore += 1;
|
||||
$msg_debug .= 'year or month exception;';
|
||||
continue;
|
||||
}
|
||||
|
||||
$where = [
|
||||
'brand_id' => $brand_id,
|
||||
's_id' => $s_id,
|
||||
'v_id' => $v_id,
|
||||
'city_id' => $city_id,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'status' => 1,
|
||||
];
|
||||
if($this->auto_business_model->get($where)){
|
||||
$count_ignore += 1;
|
||||
$sql = $this->auto_business_model->db->last_query();
|
||||
$msg_debug .= "exists business: {$sql};";
|
||||
continue;
|
||||
}
|
||||
|
||||
$price_car = $objWorksheet->getCell('H' . $_row)->getValue();
|
||||
$price_floor = $objWorksheet->getCell('I' . $_row)->getValue();
|
||||
$delivery_day = $objWorksheet->getCell('J' . $_row)->getValue();
|
||||
$delivery_day = intval($delivery_day);
|
||||
$delivery_day = $delivery_day < 0 ? 0 : $delivery_day;
|
||||
$price_color = $objWorksheet->getCell('K' . $_row)->getValue();
|
||||
$proxy_name = $objWorksheet->getCell('L' . $_row)->getValue();
|
||||
$proxy_type = $proxy_name == '票折' ? 1 : 0;
|
||||
|
||||
$proxy_profix_car = $objWorksheet->getCell('M' . $_row)->getValue();
|
||||
$profix_car = $objWorksheet->getCell('N' . $_row)->getValue();
|
||||
$profix_cardno = $objWorksheet->getCell('O' . $_row)->getValue();
|
||||
$profix_insure = $objWorksheet->getCell('P' . $_row)->getValue();
|
||||
$profix_loan = $objWorksheet->getCell('Q' . $_row)->getValue();
|
||||
|
||||
$info = [
|
||||
'brand_id' => $brand_id,
|
||||
's_id' => $s_id,
|
||||
'v_id' => $v_id,
|
||||
'city_id' => $city_id,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'status' => 1,
|
||||
'c_time' => $c_time,
|
||||
];
|
||||
|
||||
$info['price_car'] = $price_car;
|
||||
$info['price_floor'] = $price_floor;
|
||||
$info['price_color'] = $price_color;
|
||||
$info['proxy_type'] = $proxy_type;
|
||||
$info['proxy_profix_car'] = $proxy_profix_car;
|
||||
$info['profix_car'] = $profix_car;
|
||||
$info['profix_carno'] = $profix_cardno;
|
||||
$info['profix_insure'] = $profix_insure;
|
||||
$info['profix_loan'] = $profix_loan;
|
||||
$info['s_effect_time'] = $s_effect_time;
|
||||
$info['if_effect'] = $if_effect;
|
||||
$info['delivery_day'] = $delivery_day;
|
||||
$data[] = $info;
|
||||
}
|
||||
$msg_debug .= "count_ignore:{$count_ignore}";
|
||||
$done = 0;
|
||||
$data && $done = $this->auto_business_model->add_batch($data);
|
||||
@unlink($file);
|
||||
$this->data['load_num'] = count($data);
|
||||
$this->data['done'] = $done;
|
||||
#$this->data['msg_debug'] = $msg_debug;
|
||||
return $this->show_json(SYS_CODE_SUCCESS, "共{$count}条,成功导入{$done}条");
|
||||
}
|
||||
|
||||
private function upload()
|
||||
{
|
||||
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
|
||||
$config['allowed_types'] = 'xls|xlsx';
|
||||
$config['max_size'] = 5120;
|
||||
$config['file_name'] = 'receiver_clues' . time() . rand(1, 99999);
|
||||
$this->load->library('upload', $config);
|
||||
if (!$this->upload->do_upload('file')) {
|
||||
return array('code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', ''));
|
||||
} else {
|
||||
$data = $this->upload->data();
|
||||
return array('code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$info = $this->input->post('info');
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="am-form-group wp50">
|
||||
<div class="am-form-group wp50" style="display: none">
|
||||
<label class="am-para-label">公司加价:</label>
|
||||
<div class="am-para-input">
|
||||
<input type="text" placeholder="请输入公司加价" name="price_fine" v-model="info.price_coplus" style="display: inline;width: 60%"/>
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
<div class="am-form-group fl ml20">
|
||||
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
|
||||
<a class="am-btn am-btn-sm am-btn-success w100" data-modal="/auto/business/get" data-title="新增">新增</a>
|
||||
<button type="button" id="import" class="am-btn am-btn-success am-btn-sm w100">导入</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -168,6 +169,26 @@
|
||||
<?php page_view($pager) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="cule-modal" style="display: none;padding: 10px">
|
||||
<div class="modal-body">
|
||||
<div class="text-center">
|
||||
<h2><i class="fa fa-info-circle"></i> 请上传Excel文件</h2>
|
||||
<p>Excel文件格式必须与模板保持一致,否则无法导入</p>
|
||||
<div class="form-group-action">
|
||||
<a href="/temp/business.xlsx" target="_blank" class="btn btn-default">查看模板</a>
|
||||
<label href="javascript:" class="btn btn-primary" style="margin-left: 10px;">
|
||||
<form id="import-form">
|
||||
<input type="file" id="business-file" name="file" accept=".xls,.xlsx"
|
||||
style="left:-9999px;position:absolute;" onchange="load_business()">
|
||||
</form>
|
||||
<span>上传Excel文件</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
require(['laydate'], function (laydate) {
|
||||
@@ -321,7 +342,55 @@
|
||||
}
|
||||
});
|
||||
|
||||
$("#import").click(function () {
|
||||
$("#business-file").val('');
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['40%'], //宽高
|
||||
content: $('#cule-modal'),
|
||||
title: '导入线索',
|
||||
shade: false,
|
||||
btn: ['完成'],
|
||||
yes: function (index) {
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
<?php page_script($pager) ?>
|
||||
});
|
||||
|
||||
function load_business() {
|
||||
var file = $("#business-file");
|
||||
if (file.val() == '') {
|
||||
layer.msg('文件是空的');
|
||||
return 0;
|
||||
}
|
||||
var loading = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
|
||||
var options = {
|
||||
url: "/auto/business/add_excel",
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: {},
|
||||
success: function (res) {
|
||||
if (1 == res.code) {
|
||||
layer.msg(res.msg, {
|
||||
icon: 1,
|
||||
time: 2000
|
||||
}, function () {
|
||||
$.form.reload();
|
||||
});
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
file.val('');
|
||||
layer.close(loading);
|
||||
}
|
||||
};
|
||||
$("#import-form").ajaxSubmit(options);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user