作者 SHW\戥岁。。

下单bug

... ... @@ -278,203 +278,147 @@ class Litestoregoods extends Backend
/**
* 导出
*/
public function export()
{
//1.从数据库中导出需要进行要导出的数据
$goods = new Goods();
$list = Db::name('litestore_goods_spec')->alias('c')
->join('fa_litestore_goods g', 'g.goods_id = c.goods_id', 'LEFT')
->select();
// ->each(function (&$item) {
// $item['goods'] = Db::name('litestore_goods')
// ->where('goods_id', $item['goods_id'])->find();
// });
if (empty($list)) {
$this->error('没有可导出的数据');
}
//重要补助
//2.加载PHPExcle类库
vendor('PHPExcel.PHPExcel');
//3.实例化PHPExcel类
$objPHPExcel = new \PHPExcel();
//4.激活当前的sheet表
$objPHPExcel->setActiveSheetIndex(0);
//5.设置表格头(即excel表格的第一行)
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '商品ID')
->setCellValue('B1', '商品名称')
->setCellValue('C1', '商品原价')
->setCellValue('D1', '折扣')
->setCellValue('E1', '商品现价')
->setCellValue('F1', '已销数量')
->setCellValue('G1', '导出时间');
// ->setCellValue('G1', '院系')
// ->setCellValue('H1', '专业');
//设置A列水平居中
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//设置单元格宽度
//6.循环刚取出来的数组,将数据逐一添加到excel表格。
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(10);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
$objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
for ($i = 0; $i < count($list); $i++) {
$objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['goods_id']);//ID
$objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['goods_name']);//商品名称
$objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['line_price']);//原价
$objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['discount']);//ID
$objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $list[$i]['goods_price']);//标签码
$objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $list[$i]['goods_sales']);//ID
$objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), datetime(time()));//标签码
}
//7.设置保存的Excel表格名称
// $filename = '商品信息' . date('ymd', time()) . '.xls';
// //8.设置当前激活的sheet表格名称;
// $objPHPExcel->getActiveSheet()->setTitle('商品信息');
// //9.设置浏览器窗口下载表格
ob_end_clean();
ob_start();
// header("Content-Type: application/force-download");
// header("Content-Type: application/octet-stream");
// header("Content-Type: application/download");
// header('Content-Disposition:inline;filename="' . $filename . '"');
//// header("Pragma: public");
//// header("Expires: 0");
////// header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
////// header("Content-Type:application/force-download");
////// header("Content-Type:application/vnd.ms-execl");
////// header("Content-Type:application/octet-stream");
////// header("Content-Type:application/download");;
////// header('Content-Disposition:attachment;filename='.$filename.'');
////// header("Content-Transfer-Encoding:binary");
////// //生成excel文件
////// $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
////// ini_set('display_errors', TRUE);
////// ini_set('display_startup_errors', TRUE);
//// header('pragma:public');
//// header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $filename . '.xls"');
//// header("Content-Disposition:inline;filename=$filename.xls"); //attachment新窗口打印inline本窗口打印
// $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
// $objWriter->save('php://output');
$title = 'ahhah';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output'); //文件通过浏览器下载
exit();
}
// public function export()
// {
// if ($this->request->isPost()) {
// set_time_limit(0);
// $search = $this->request->post('search');
// $ids = $this->request->post('ids');
// $filter = $this->request->post('filter');
// $op = $this->request->post('op');
// $columns = $this->request->post('columns');
//
// $excel = new PHPExcel();
//
// $excel->getProperties()
// ->setCreator("FastAdmin")
// ->setLastModifiedBy("FastAdmin")
// ->setTitle("标题")
// ->setSubject("Subject");
// $excel->getDefaultStyle()->getFont()->setName('Microsoft Yahei');
// $excel->getDefaultStyle()->getFont()->setSize(12);
//
// $this->sharedStyle = new PHPExcel_Style();
// $this->sharedStyle->applyFromArray(
// array(
// 'fill' => array(
// 'type' => PHPExcel_Style_Fill::FILL_SOLID,
// 'color' => array('rgb' => '000000'),
// ),
// 'font' => array(
// 'color' => array('rgb' => "000000"),
// ),
// 'alignment' => array(
// 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
// 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
// 'indent' => 1,
// ),
// 'borders' => array(
// 'allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
// ),
// ));
//
// $worksheet = $excel->setActiveSheetIndex(0);
// $worksheet->setTitle('标题');
//
// $whereIds = $ids == 'all' ? '1=1' : ['id' => ['in', explode(',', $ids)]];
// $this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]);
// list($where, $sort, $order, $offset, $limit) = $this->buildparams();
//
// $line = 1;
// $list = [];
// $this->model
// ->field($columns)
// ->where($where)
// ->where($whereIds)
// ->chunk(100, function ($items) use (&$list, &$line, &$worksheet) {
// $styleArray = array(
// 'font' => array(
// 'bold' => true,
// 'color' => array('rgb' => 'FF0000'),
// 'size' => 15,
// 'name' => 'Verdana',
// ));
// $list = $items = collection($items)->toArray();
// foreach ($items as $index => $item) {
// $line++;
// $col = 0;
// foreach ($item as $field => $value) {
//
// $worksheet->setCellValueByColumnAndRow($col, $line, $value);
// $worksheet->getStyleByColumnAndRow($col, $line)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
// $worksheet->getCellByColumnAndRow($col, $line)->getStyle()->applyFromArray($styleArray);
// $col++;
// }
// }
// });
// $first = array_keys($list[0]);
// foreach ($first as $index => $item) {
// $worksheet->setCellValueByColumnAndRow($index, 1, __($item));
// }
//
// $excel->createSheet();
// // Redirect output to a client’s web browser (Excel2007)
// $title = date("YmdHis");
// header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
// header('Cache-Control: max-age=0');
// // If you're serving to IE 9, then the following may be needed
// header('Cache-Control: max-age=1');
//
// // If you're serving to IE over SSL, then the following may be needed
// header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
// header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
// header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
// header('Pragma: public'); // HTTP/1.0
// //1.从数据库中导出需要进行要导出的数据
// $list = Db::name('litestore_goods_spec')->alias('c')
// ->join('fa_litestore_goods g', 'g.goods_id = c.goods_id', 'LEFT')
// ->select();
// if (empty($list)) {
// $this->error('没有可导出的数据');
// }
// //重要补助
// //2.加载PHPExcle类库
// vendor('PHPExcel.PHPExcel');
// //3.实例化PHPExcel类
// $objPHPExcel = new \PHPExcel();
// //4.激活当前的sheet表
// $objPHPExcel->setActiveSheetIndex(0);
// //5.设置表格头(即excel表格的第一行)
// $objPHPExcel->setActiveSheetIndex(0)
// ->setCellValue('A1', '商品ID')
// ->setCellValue('B1', '商品名称')
// ->setCellValue('C1', '商品原价')
// ->setCellValue('D1', '折扣')
// ->setCellValue('E1', '商品现价')
// ->setCellValue('F1', '已销数量')
// ->setCellValue('G1', '导出时间');
// //设置A列水平居中
// $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
// ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// //设置单元格宽度
// //6.循环刚取出来的数组,将数据逐一添加到excel表格。
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(10);
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
// $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
//
// $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
// $objWriter->save('php://output');
// return;
// for ($i = 0; $i < count($list); $i++) {
// $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['goods_id']);//ID
// $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['goods_name']);//商品名称
// $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['line_price']);//原价
// $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['discount']);//ID
// $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $list[$i]['goods_price']);//标签码
// $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $list[$i]['goods_sales']);//ID
// $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), datetime(time()));//标签码
// }
// ob_end_clean();
// ob_start();
// $title = 'ahhah';
// header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// header('Content-Disposition:attachment;filename="' . $title . '.xlsx"');
// header('Cache-Control: max-age=0');
// header('Cache-Control: max-age=1');
// header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
// header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
// header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
// header('Pragma: public'); // HTTP/1.0
// $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
// $objWriter->save('php://output'); //文件通过浏览器下载
// exit();
// }
public function export()
{
if ($this->request->isPost()) {
set_time_limit(0);
$search = $this->request->post('search');
$ids = $this->request->post('ids');
$filter = $this->request->post('filter');
$op = $this->request->post('op');
$columns = $this->request->post('columns');
//$excel = new PHPExcel();
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()
->setCreator("FastAdmin")
->setLastModifiedBy("FastAdmin")
->setTitle("标题")
->setSubject("Subject");
$spreadsheet->getDefaultStyle()->getFont()->setName('Microsoft Yahei');
$spreadsheet->getDefaultStyle()->getFont()->setSize(12);
$worksheet = $spreadsheet->setActiveSheetIndex(0);
$whereIds = $ids == 'all' ? '1=1' : ['id' => ['in', explode(',', $ids)]];
$this->request->get(['search' => $search, 'ids' => $ids, 'filter' => $filter, 'op' => $op]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$line = 1;
//设置过滤方法
$this->request->filter(['strip_tags']);
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($whereIds)
->order($sort, $order)
->count();
$list = $this->model
->where($whereIds)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
$first = array_keys($list[0]);
foreach ($first as $index => $item) {
$worksheet->setCellValueByColumnAndRow($index, 1, __($item));
}
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(__DIR__ . '/muban/test.xls'); //读取模板
$worksheet = $spreadsheet->getActiveSheet(); //指向激活的工作表
$worksheet->setTitle('模板测试标题');
for($i=0;$i<$total;++$i){
//向模板表中写入数据
$worksheet->setCellValue('A1', '模板测试内容'); //送入A1的内容
$worksheet->getCell('B2')->setValue($result['rows'][$i]['week']); //星期
$worksheet->getCell('d2')->setValue($result['rows'][$i]['genderdata']); //性别
$worksheet->getCell('f2')->setValue($result['rows'][$i]['hobbydata']); //爱好
$worksheet->getCell('b3')->setValue($result['rows'][$i]['title']); //标题
$worksheet->getCell('b4')->setValue($result['rows'][$i]['content']); //内容
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
//下载文档
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. date('Y-m-d') . $result['rows'][$i]['admin_id'] .'_test'.'.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
}
return;
}
}
}
... ...
... ... @@ -22,11 +22,13 @@
title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload"
data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i>
{:__('Import')}</a>
<!-- <a href="javascript:;"-->
<!-- class="btn btn-info btn-change btn-export btn-disable" data-params="action=export"-->
<!-- data-url="litestore/litestoregoods/export"-->
<!-- title="{:__('批量导出')}"><i class="fa fa-download"></i>{:__('批量导出')}</a>-->
<a href="javascript:;"
class="btn btn-info btn-change btn-export btn-disable" data-params="action=export"
data-url="litestore/litestoregoods/export"
title="{:__('批量导出')}"><i class="fa fa-download"></i>{:__('批量导出')}</a>
<!-- <a href="javascript:;" class="btn btn-info btn-export {:$auth->check('litestore/litestoregoods/export')?'':'hide'}" title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> {:__('Export')}</a>-->
class="btn btn-info btn-export {:$auth->check('litestore/litestoregoods/export')?'':'hide'}"
title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> 批量导出</a>
<!-- <div class="dropdown btn-group {:$auth->check('litestore/litestoregoods/multi')?'':'hide'}">-->
<!-- <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
... ...
... ... @@ -199,12 +199,13 @@ class Order extends Api
}
$goods = $goodsmodel->where('goods_id',$value['goods_id'])->field('goods_id,goods_name,image,spec_type')->find();
if (!$goods) $this->error('商品不存在');
$goods->visibleAppend(['image_text']);
// $goods->visibleAppend(['image_text']);
$goods->append(['image_text']);
$goods->hidden(['image']);
$sku = $skumodel->where('goods_spec_id',$value['goods_sku_id'])
->field('goods_spec_id,spec_sku_id,goods_price')->find();
if (!$sku) $this->error('商品规格不存在');
$sku->unsetAppend();
// $sku->unsetAppend();
$goods['sku_id'] = $sku['goods_spec_id'];
$goods['sku_price'] = $sku['goods_price'];
... ...
... ... @@ -90,16 +90,59 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'litestor
]
]
});
//*************************** 自定义export开始
var submitForm = function (ids, layero) {
var options = table.bootstrapTable('getOptions');
console.log(options);
var columns = [];
$.each(options.columns[0], function (i, j) {
if (j.field && !j.checkbox && j.visible && j.field != 'operate') {
columns.push(j.field);
}
});
var search = options.queryParams({});
$("input[name=search]", layero).val(options.searchText);
$("input[name=ids]", layero).val(ids);
$("input[name=filter]", layero).val(search.filter);
$("input[name=op]", layero).val(search.op);
$("input[name=columns]", layero).val(columns.join(','));
$("form", layero).submit();
};
$(document).on("click", ".btn-export", function () {
var ids = Table.api.selectedids(table);
var page = table.bootstrapTable('getData');
var all = table.bootstrapTable('getOptions').totalRows;
console.log(ids, page, all);
Layer.confirm("请选择导出的选项<form action='" + Fast.api.fixurl("test/export") + "' method='post' target='_blank'><input type='hidden' name='ids' value='' /><input type='hidden' name='filter' ><input type='hidden' name='op'><input type='hidden' name='search'><input type='hidden' name='columns'></form>", {
title: '导出数据',
btn: ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
// btn: ["选中项(" + ids.length + "条)"],
success: function (layero, index) {
$(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
}
, yes: function (index, layero) {
submitForm(ids.join(","), layero);
return false;
}
,
btn2: function (index, layero) {
var ids = [];
$.each(page, function (i, j) {
ids.push(j.id);
});
submitForm(ids.join(","), layero);
return false;
}
,
btn3: function (index, layero) {
submitForm("all", layero);
return false;
}
})
});
//*************************** 自定义export结束
// 为表格绑定事件
Table.api.bindevent(table);
$(document).on("click", ".btn-export", function () {
var all = table.bootstrapTable('getOptions').totalRows;
// Fast.api.fixurl("litestore/litestoregoods/export")
Table.api.multi("changestatus", all.join(","), table, this);
}
);
table.on('load-success.bs.table', function (data) {
$(".btn-editone").data("area", ["1000px", "800px"]);
});
... ... @@ -194,8 +237,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'litestor
});
}
,
},
edit: function () {
//Controller.api.bindevent();
... ... @@ -284,8 +326,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'litestor
$goodsSpecMany.show() && $goodsSpecSingle.hide();
}
});
}
,
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ... @@ -293,5 +334,4 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'litestor
}
};
return Controller;
})
;
\ No newline at end of file
});
\ No newline at end of file
... ...