Files
liche/admin/controllers/items/goods/Goods.php
T
2021-08-24 21:02:59 +08:00

596 lines
26 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:商品
* Created on: 2021/7/14 15:03
* Created by: dengbw
*/
class Goods extends HD_Controller
{
private $statusAry = array(0 => '下架', 1 => '未售', 2 => '已售');
public function __construct()
{
parent::__construct();
$this->load->model('items/items_model', 'mdItems');
$this->load->model('auto/auto_brand_model', 'mdAutoBrand');
$this->load->model('auto/auto_series_model', 'mdAutoSeries');
$this->load->model('auto/auto_attr_model', 'mdAutoAttr');
$this->load->model("sys/sys_addr_model", 'addr_model');
}
public function index()
{
$this->lists();
}
public function lists()
{
$params = $this->input->get();
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
$where = $autoList = array();
if ($params['brand_id']) {
$where['brand_id'] = $params['brand_id'];
$autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name');
}
if ($params['s_id']) {
$where['s_id'] = $params['s_id'];
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name');
}
if ($params['v_id']) {
$where['v_id'] = $params['v_id'];
}
if($params['addr_id']){
$where['addr_id'] = $params['addr_id'];
} else if($params['city_id']){
$where_addr = array('status>0' => null, 'city_id' => $params['city_id']);
if($params['county_id']){
$where_addr['county_id'] = $params['county_id'];
}
$orderby = 'id desc';
$select = 'id';
$rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select);
if($rows_addr){
$str_ids = implode(',', array_column($rows_addr, 'id'));
$where["addr_id in ({$str_ids})"] = null;
} else {
$where['addr_id'] = -1;
}
} else {
$params['city_id'] = '';
$params['county_id'] = '';
$params['addr_id'] = '';
}
if(strlen($params['status'])>0){
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
if($params['vin']){
$where["vin like '%{$params['vin']}%'"] = null;
}
$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
$count = $this->mdItems->count($where);
$lists = array();
if ($count) {
$fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,p_time,addr_id';
$rows = $this->mdItems->select($where, 'id desc', $page, $size, $fileds);
$brand_id_arr = array();
$addr_ids = array();
foreach($rows as $v){
!in_array($v['brand_id'], $brand_id_arr) && $brand_id_arr[] = $v['brand_id'];
$v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id'];
}
$brands_rows = $this->mdAutoBrand->get_map_by_ids($brand_id_arr, 'id,name');
$series_id_arr = array_unique(array_column($rows, 's_id'));
$series_rows = $this->mdAutoSeries->get_map_by_ids($series_id_arr, 'id,name');
$attr_vid_arr = array_unique(array_column($rows, 'v_id'));
$attr_vid_rows = $this->mdAutoAttr->get_map_by_ids($attr_vid_arr, 'id,title');
$attr_corid_arr = array_unique(array_column($rows, 'cor_id'));
$attr_corid_rows = $this->mdAutoAttr->get_map_by_ids($attr_corid_arr, 'id,title');
$attr_incorid_arr = array_unique(array_column($rows, 'incor_id'));
$attr_incorid_rows = $this->mdAutoAttr->get_map_by_ids($attr_incorid_arr, 'id,title');
$map_addr = array();
if($addr_ids){
$str_ids = implode(',', $addr_ids);
$where = array("id in ({$str_ids})" => null);
$orderby = 'id desc';
$select = 'id, title';
$map_addr = $this->addr_model->map('id', 'title', $where, $orderby, 0, 0, $select);
}
foreach ($rows as $key => $val) {
$p_days = '';
if('0000-00-00 00:00:00' != $val['p_time']){
$p_days = intval((time() - strtotime($val['p_time']))/3600/24);
}
$setVal = array();
$setVal['id'] = $val['id'];
$setVal['brand_name'] = isset($brands_rows[$val['brand_id']]) ? $brands_rows[$val['brand_id']][0]['name'] : '';
$setVal['s_name'] = isset($series_rows[$val['s_id']]) ? $series_rows[$val['s_id']][0]['name'] : '';
$setVal['v_name'] = isset($attr_vid_rows[$val['v_id']]) ? $attr_vid_rows[$val['v_id']][0]['title'] : '';
$setVal['cor_name'] = isset($attr_corid_rows[$val['cor_id']]) ? $attr_corid_rows[$val['cor_id']][0]['title'] : '';
$setVal['incor_name'] = isset($attr_incorid_rows[$val['incor_id']]) ? $attr_incorid_rows[$val['incor_id']][0]['title'] : '';
$setVal['vin'] = $val['vin'];
$setVal['address'] = $val['addr_id'] ? $map_addr[$val['addr_id']] : '';
$setVal['p_time'] = '0000-00-00 00:00:00' == $val['p_time'] ? '' : $val['p_time'];
$setVal['p_days'] = $p_days;
$lists[] = $setVal;
}
}
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['params'] = $params;
$this->data['autoList'] = $autoList;
$this->data['statusAry'] = $this->statusAry;
$this->data['_title'] = '商品管理';
return $this->show_view('/items/goods/lists', true);
}
public function get()
{
$autoList = array();
$id = intval($this->input->get('id'));
$info['brand_id'] = $info['s_id'] = $info['v_id'] = $info['cor_id'] = $info['incor_id'] = 0;
$info['if_pack'] = '';
$info['status'] = 1;
$autoList[2] = $autoList[3] = $autoList[4] = $autoList[5] = array();
if ($id > 0) {
$re = $this->mdItems->get(array('id' => $id));
if (!$re || empty($re)) {
return $this->show_json(SYS_CODE_FAIL, '商品不存在!');
}
$info = $re;
$info['pro_time'] = $re['pro_time'] != '0000-00-00 00:00:00' ? $re['pro_time'] : '';
$info['p_time'] = $re['p_time'] != '0000-00-00 00:00:00' ? $re['p_time'] : '';
$info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : '';
$info['bill_time'] = $re['bill_time'] != '0000-00-00 00:00:00' ? $re['bill_time'] : '';
if ($re['brand_id']) {
$autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $re['brand_id']), 'id desc', 0, 0, 'id,name');
}
if ($re['s_id']) {
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name');
$autoList[4] = $this->mdAutoAttr->select(array('type' => 0, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name');
$autoList[5] = $this->mdAutoAttr->select(array('type' => 2, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name');
}
if($info['addr_id']){
$row_addr = $this->addr_model->get(array('id' => $info['addr_id']));
$info['city_id'] = $row_addr['city_id'];
$info['county_id'] = $row_addr['county_id'];
} else {
$info['city_id'] = '';
$info['county_id'] = '';
$info['addr_id'] = '';
}
$_title = '编辑商品';
$edit_url = '/items/goods/goods/edit';
} else {
$info['city_id'] = '';
$info['county_id'] = '';
$info['addr_id'] = '';
$_title = '新增商品';
$edit_url = '/items/goods/goods/add';
}
$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
$showInfo['autoList'] = $autoList;
$showInfo['statusAry'] = $this->statusAry;
$this->data['info'] = $info;
$this->data['showInfo'] = $showInfo;
$this->data['edit_url'] = $edit_url;
$this->data['_title'] = $_title;
return $this->show_view('/items/goods/edit', true);
}
public function get_info()
{
$id = intval($this->input->get('id'));
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
}
$re = $this->mdItems->get(array('id' => $id));
if (!$re || empty($re)) {
return $this->show_json(SYS_CODE_FAIL, '商品不存在!');
}
$info = $re;
$re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name');
$re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name');
$re_v = $this->mdAutoAttr->get(array('id' => $re['v_id']), 'title');
$re_cor = $this->mdAutoAttr->get(array('id' => $re['cor_id']), 'title');
$re_incor = $this->mdAutoAttr->get(array('id' => $re['incor_id']), 'title');
$info['brand_name'] = $re_b ? $re_b['name'] : '';
$info['s_name'] = $re_s ? $re_s['name'] : '';
$info['v_name'] = $re_v ? $re_v['title'] : '';
$info['cor_name'] = $re_cor ? $re_cor['title'] : '';
$info['incor_name'] = $re_incor ? $re_incor['title'] : '';
$info['if_pack_name'] = $re['if_pack'];
$info['status_name'] = $this->statusAry[$re['status']];
$info['ori_price'] = $re['ori_price'] . '元';
$info['dis_price'] = $re['dis_price'] . '元';
$info['bill_price'] = $re['bill_price'] . '元';
$info['buy_price'] = $re['buy_price'] . '元';
$info['discount'] = $re['discount'] ? $re['discount'] . '%' : '100%';
$info['pro_time'] = $re['pro_time'] != '0000-00-00 00:00:00' ? $re['pro_time'] : '';
$info['p_time'] = $re['p_time'] != '0000-00-00 00:00:00' ? $re['p_time'] : '';
$info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : '';
$info['bill_time'] = $re['bill_time'] != '0000-00-00 00:00:00' ? $re['bill_time'] : '';
if($info['addr_id']){
$row_addr = $this->addr_model->get(array('id' => $info['addr_id']));
$info['address'] = $row_addr['city_name'].$row_addr['county_name'].$row_addr['title'];
} else {
$info['address'] = '';
}
$this->data['info'] = $info;
return $this->show_view('/items/goods/get_info');
}
private function checkInfo($info)
{
$msg = '';
$code = SYS_CODE_FAIL;
if (!$info) {
$msg = '非法参数';
} else if (!$info['brand_id']) {
$msg = '请选择品牌';
} else if (!$info['s_id']) {
$msg = '请选择车系';
} else {
$code = SYS_CODE_SUCCESS;
}
return array('code' => $code, 'msg' => $msg);
}
//添加单条数据
public function add()
{
$info = $this->input->post('info');
$checkInfo = $this->checkInfo($info);
if (!$checkInfo['code']) {
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
}
$addData['brand_id'] = $info['brand_id'];
$addData['s_id'] = $info['s_id'];
$addData['v_id'] = $info['v_id'];
$addData['cor_id'] = $info['cor_id'];
$addData['incor_id'] = $info['incor_id'];
$addData['if_pack'] = $info['if_pack'];
$addData['status'] = $info['status'];
$addData['address'] = $info['address'] ? $info['address'] : '';
$addData['vin'] = $info['vin'] ? $info['vin'] : '';
$addData['stdard_num'] = $info['stdard_num'] ? $info['stdard_num'] : '';
$addData['engine_num'] = $info['engine_num'] ? $info['engine_num'] : '';
$addData['ori_price'] = $info['ori_price'] ? $info['ori_price'] : 0.00;
$addData['discount'] = $info['discount'] ? $info['discount'] : 0;
$addData['dis_price'] = $info['dis_price'] ? $info['dis_price'] : 0.00;
$addData['bill_num'] = $info['bill_num'] ? $info['bill_num'] : '';
$addData['bill_price'] = $info['bill_price'] ? $info['bill_price'] : 0.00;
$addData['buy_price'] = $info['buy_price'] ? $info['buy_price'] : 0.00;
$addData['pro_time'] = $info['pro_time'] ? $info['pro_time'] : '0000-00-00 00:00:00';
$addData['p_time'] = $info['p_time'] ? $info['p_time'] : '0000-00-00 00:00:00';
$addData['out_time'] = $info['out_time'] ? $info['out_time'] : '0000-00-00 00:00:00';
$addData['bill_time'] = $info['bill_time'] ? $info['bill_time'] : '0000-00-00 00:00:00';
$addData['c_time'] = time();
//存货地址
$addData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0;
$id = $this->mdItems->add($addData);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '添加失败!');
}
$this->data['status'] = 1;
return $this->show_json(SYS_CODE_SUCCESS, '添加成功!');
}
/**
* 导入
* @return bool
*/
public 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 文档
}
$PHPExcel = $reader->load($file); // 文档名称
$objWorksheet = $PHPExcel->getActiveSheet();
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
if ($rowCnt > 10000) {
@unlink($file);
return $this->show_json(0, '数据大于一万请拆分多个表格导入');
}
$j = 0;
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
$vin = $objWorksheet->getCell('F' . $_row)->getValue(); //vin码
if ($vin) {//有vin时验证
$re_i = $this->mdItems->get(array('vin' => $vin));
} else {
$re_i = '';
}
if (!$re_i) {
$brand_id = $objWorksheet->getCell('A' . $_row)->getValue(); //品牌id
$s_id = $objWorksheet->getCell('B' . $_row)->getValue(); //车系id
$v_id = $objWorksheet->getCell('C' . $_row)->getValue(); //车型id
$cor_id = $objWorksheet->getCell('D' . $_row)->getValue(); //车身颜色id
$incor_id = $objWorksheet->getCell('E' . $_row)->getValue(); //内饰颜色id
$re_b = $this->mdAutoBrand->get(array('name' => $brand_id));
$brand_id = $re_b ? $re_b['id'] : 0;
$re_s = $this->mdAutoSeries->get(array('brand_id' => $brand_id, 'name' => $s_id));
$s_id = $re_s ? $re_s['id'] : 0;
$re_a1 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 1, 'title' => $v_id));
$v_id = $re_a1 ? $re_a1['id'] : 0;
$re_a0 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 0, 'title' => $cor_id));
$cor_id = $re_a0 ? $re_a0['id'] : 0;
$re_a2 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 2, 'title' => $incor_id));
$incor_id = $re_a2 ? $re_a2['id'] : 0;
$addData = array(
'brand_id' => $brand_id,
's_id' => $s_id,
'v_id' => $v_id,
'cor_id' => $cor_id,
'incor_id' => $incor_id,
'vin' => $vin ? $vin : '',
'c_time' => time()
);
$id = $this->mdItems->add($addData);
if ($id) {
$j++;
}
}
}
@unlink($file);
return $this->show_json(SYS_CODE_SUCCESS, '导入完成,导入总条数为:' . $j);
}
//编辑单条数据
public function edit()
{
$info = $this->input->post('info');
$checkInfo = $this->checkInfo($info);
if (!$checkInfo['code']) {
return $this->show_json($checkInfo['code'], $checkInfo['msg']);
}
$editData['brand_id'] = $info['brand_id'];
$editData['s_id'] = $info['s_id'];
$editData['v_id'] = $info['v_id'];
$editData['cor_id'] = $info['cor_id'];
$editData['incor_id'] = $info['incor_id'];
$editData['if_pack'] = $info['if_pack'];
$editData['status'] = $info['status'];
$editData['address'] = $info['address'];
$editData['vin'] = $info['vin'];
$editData['stdard_num'] = $info['stdard_num'];
$editData['engine_num'] = $info['engine_num'];
$editData['ori_price'] = $info['ori_price'];
$editData['discount'] = $info['discount'];
$editData['dis_price'] = $info['dis_price'];
$editData['bill_num'] = $info['bill_num'];
$editData['bill_price'] = $info['bill_price'];
$editData['buy_price'] = $info['buy_price'];
$editData['pro_time'] = $info['pro_time'];
$editData['p_time'] = $info['p_time'];
$editData['out_time'] = $info['out_time'];
$editData['bill_time'] = $info['bill_time'];
//存货地址
$editData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0;
$ret = $this->mdItems->update($editData, array('id' => $info['id']));
if (!$ret) {
return $this->show_json(SYS_CODE_FAIL, '修改失败!');
}
$this->data['status'] = 2;
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
$params = $this->input->get();
$where = array();
if ($params['brand_id']) {
$where['brand_id'] = $params['brand_id'];
$autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name');
}
if ($params['s_id']) {
$where['s_id'] = $params['s_id'];
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name');
}
if ($params['v_id']) {
$where['v_id'] = $params['v_id'];
}
if($params['addr_id']){
$where['addr_id'] = $params['addr_id'];
} else if($params['city_id']){
$where_addr = array('status>0' => null, 'city_id' => $params['city_id']);
if($params['county_id']){
$where_addr['county_id'] = $params['county_id'];
}
$orderby = 'id desc';
$select = 'id';
$rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select);
if($rows_addr){
$str_ids = implode(',', array_column($rows_addr, 'id'));
$where["addr_id in ({$str_ids})"] = null;
} else {
$where['addr_id'] = -1;
}
} else {
$params['city_id'] = '';
$params['county_id'] = '';
$params['addr_id'] = '';
}
if(strlen($params['status'])>0){
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
if($params['vin']){
$where["vin like '%{$params['vin']}%'"] = null;
}
$total = $this->mdItems->count($where);
if($total > 10000){
return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了');
} else if(0 == $total) {
return $this->show_json(SYS_CODE_SUCCESS, '当前没有数据');
}
$fileName = "车辆明细";
$indexs = array(
'id' => 'ID',
'brand_name' =>'品牌',
's_name' =>'车系',
'v_name' =>'车型',
'cor_name' =>'车身颜色',
'incor_name' =>'内饰颜色',
'ori_price' =>'指导价',
'sale_price' =>'售价',
'bill_price' =>'开票金额',
'buy_price' =>'采购成本',
'dis_price' =>'折扣价',
'discount' =>'折扣百分比',
'city_name' => '城市名',
'county_name' => '行政区',
'address' =>'存放地址',
'vin' =>'车架号',
'engine_num' =>'发动机号',
'stdard_num' =>'合格证号',
'bill_num' =>'开票号',
'if_pack' =>'精品加装',
'status' =>'状态',
'pro_time' =>'生产时间',
'p_time' =>'分配时间',
'out_time' =>'出库时间',
'bill_time' =>'开票时间',
);
$rows = $this->mdItems->select($where, 'id desc', 0, 0, '*');
$lists[] = $indexs;
$brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array();
foreach($rows as $v){
$v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id'];
$v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id'];
$v['s_id'] && !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id'];
$v['v_id'] && !in_array($v['v_id'], $attr_vids) && $attr_vids[] = $v['v_id'];
$v['cor_id'] && !in_array($v['cor_id'], $attr_corids) && $attr_corids[] = $v['cor_id'];
$v['incor_id'] && !in_array($v['incor_id'], $attr_incorids) && $attr_incorids[] = $v['incor_id'];
}
$map_brand = $map_sery = $map_vid = $map_corid = $map_incorid = $map_addr = array();
if($brand_ids){
$str_ids = implode(',', $brand_ids);
$where = array("id in ({$str_ids})" => null);
$map_brand = $this->mdAutoBrand->map('id', 'name', $where);
}
if($s_ids){
$str_ids = implode(',', $s_ids);
$where = array("id in ({$str_ids})" => null);
$map_sery = $this->mdAutoSeries->map('id', 'name', $where);
}
if($attr_vids){
$str_ids = implode(',', $attr_vids);
$where = array("id in ({$str_ids})" => null);
$map_vid = $this->mdAutoAttr->map('id', 'title', $where);
}
if($attr_corids){
$str_ids = implode(',', $attr_corids);
$where = array("id in ({$str_ids})" => null);
$map_corid = $this->mdAutoAttr->map('id', 'title', $where);
}
if($attr_incorids){
$str_ids = implode(',', $attr_incorids);
$where = array("id in ({$str_ids})" => null);
$map_incorid = $this->mdAutoAttr->map('id', 'title', $where);
}
if($addr_ids){
$str_ids = implode(',', $addr_ids);
$where = array("id in ({$str_ids})" => null);
$orderby = 'id desc';
$select = 'id, title, city_name, county_name';
$map_addr = $this->addr_model->map('id', '*', $where, $orderby, 0, 0, $select);
}
foreach($rows as $v){
$addr = $map_addr[$v['addr_id']];
$lists[] = array(
'id' => $v['id'],
'brand_name' => $map_brand[$v['brand_id']],
's_name' => $map_sery[$v['s_id']],
'v_name' => $map_vid[$v['v_id']],
'cor_name' => $map_corid[$v['cor_id']],
'incor_name' => $map_incorid[$v['incor_id']],
'ori_price' =>$v['ori_price'],
'sale_price' => $v['sale_price'],
'bill_price' => $v['bill_price'],
'buy_price' => $v['buy_price'],
'dis_price' => $v['dis_price'],
'discount' => $v['discount'],
'city_name' => $addr ? $addr['city_name'] : '',
'county_name' => $addr ? $addr['county_name'] : '',
'address' => $addr ? $addr['title'] : '',
'vin' => $v['vin'],
'engine_num' => $v['engine_num'],
'stdard_num' =>$v['stdard_num'],
'bill_num' => $v['bill_num'],
'if_pack' => $v['if_pack'],
'status' => $this->statusAry[$v['status']],
'pro_time' => '0000-00-00 00:00:00' == $v['pro_time'] ? '' : $v['pro_time'],
'p_time' => '0000-00-00 00:00:00' == $v['p_time'] ? '' : $v['p_time'],
'out_time' => '0000-00-00 00:00:00' == $v['out_time'] ? '' : $v['out_time'],
'bill_time' => '0000-00-00 00:00:00' == $v['bill_time'] ? '' : $v['bill_time'],
);
}
$this->load->library('excel');
$this->excel->out_csv($lists, $indexs, $fileName . "_" . date('YmdHis'));
return 1;
}
/**
* Notes:上传excel
* Created on: 2021/7/14 15:06
* Created by: dengbw
* @return array
*/
private function upload()
{
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
$config['allowed_types'] = '*';//xls|xlsx
$config['max_size'] = 5 * 1024;
$config['file_name'] = 'items_' . 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']);
}
}
}