作者 jinglong

修改导入时间

... ... @@ -58,4 +58,34 @@ class AdminCommon extends Backend
$writer->save('php://output');
exit;
}
//转换fastadmin 时间
public static function getDateByFloatValue($dateValue = 0,$calendar_type = 1900){
// Excel中的日期存储的是数值类型,计算的是从1900年1月1日到现在的数值
if (1900 == $calendar_type) { // WINDOWS中EXCEL 日期是从1900年1月1日的基本日期
$myBaseDate = 25569;// php是从 1970-01-01 25569是到1900-01-01所相差的天数
if ($dateValue < 60) {
--$myBaseDate;
}
} else {// MAC中EXCEL日期是从1904年1月1日的基本日期(25569-24107 = 4*365 + 2) 其中2天是润年的时间差?
$myBaseDate = 24107;
}
// 执行转换
if ($dateValue >= 1) {
$utcDays = $dateValue - $myBaseDate;
$returnValue = round($utcDays * 86400);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer)$returnValue;
}
} else {
// 函数对浮点数进行四舍五入
$hours = round($dateValue * 24);
$mins = round($dateValue * 1440) - round($hours * 60);
$secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
$returnValue = (integer)gmmktime($hours, $mins, $secs);
}
return $returnValue;// 返回时间戳
}
}
... ...
... ... @@ -179,6 +179,15 @@ class Free extends Backend
$values = [];
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$cell = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow);
if($cell->getDataType() == DataType::TYPE_NUMERIC){
$cellstyleformat = $cell->getStyle($cell->getCoordinate())->getNumberFormat();
$formatcode = $cellstyleformat->getFormatCode();
if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $formatcode)) {
// $val = strtotime(gmdate("Y-m-d H:i:s", $currentSheet->ExcelToPHP($val)));
$val = AdminCommon::getDateByFloatValue($val);
}
}
$values[] = is_null($val) ? '' : $val;
}
$row = [];
... ...
... ... @@ -12,6 +12,7 @@ use PhpOffice\PhpSpreadsheet\Reader\Csv;
use think\exception\PDOException;
use app\admin\library\Auth;
use think\Db;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
/**
* 会员注册管理
*
... ... @@ -198,6 +199,15 @@ class Registers extends Backend
$values = [];
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$cell = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow);
if($cell->getDataType() == DataType::TYPE_NUMERIC){
$cellstyleformat = $cell->getStyle($cell->getCoordinate())->getNumberFormat();
$formatcode = $cellstyleformat->getFormatCode();
if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $formatcode)) {
// $val = strtotime(gmdate("Y-m-d H:i:s", $currentSheet->ExcelToPHP($val)));
$val = AdminCommon::getDateByFloatValue($val);
}
}
$values[] = is_null($val) ? '' : $val;
}
$row = [];
... ... @@ -235,7 +245,7 @@ class Registers extends Backend
$row['id'] = $res1['id'];
}
//根据手机号查询会员注册id
$res = Db::name('registers')->where('mobile',$values[7])->field('id')->find();
$res = Db::name('registers')->where('mobile',$values[5])->field('id')->find();
if($res){
$row['r_id'] = $res['id'];
}else{
... ... @@ -244,7 +254,7 @@ class Registers extends Backend
}
if ($row) {
if($row['r_id'] != 0){
//如果订单金额为空,则视为该条数据为空
//如果订单编号为空,则视为该条数据为空
if(isset($row['order_sn']) && !empty($row['order_sn'])){
$insert[] = $row;
}
... ... @@ -326,4 +336,40 @@ class Registers extends Backend
$fileName = "套餐订单列表";//文件名
AdminCommon::exportExcel($expTitle,$expCellName,$expTableData,$fileName);
}
//导出服务列表excel
public function export1(){//导出Excel
$ids = $this->request->param('s_ids');
if(!$ids){
return;
}
$ids = explode(',',$ids);
$expTableData = Common::selectWhereData('service_order',['r_id'=>['in',$ids]],'r_id,order_sn,customer_name,service_time,service_content,service_name,assess,mark','id asc');
//查询手机号
$r_ids = array_unique(array_column($expTableData,'r_id'));
$res_mobile = Common::selectWhereData('registers',['id'=>['in',$r_ids]],'id,mobile');
$expCellName = [
['order_sn','服务订单编号',20],
['customer_name','客户姓名',10],
['service_time','服务时间',20],
['service_content','服务项目',30],
['service_name','服务员',10],
['mobile','VIP手机号',20],
['assess','评价',30],
['mark','备注',40],
];
foreach ($expTableData as &$v) {
$v['mobile'] = '';
foreach ($res_mobile as $value){
if($v['r_id'] == $value['id']){
$v['mobile'] = $value['mobile'];
}
}
$v['service_time'] = date('Y-m-d H:i:s',$v['service_time']);
}
$expTitle = "服务订单列表";
$fileName = "服务订单列表";//文件名
AdminCommon::exportExcel($expTitle,$expCellName,$expTableData,$fileName);
}
}
... ...
... ... @@ -38,6 +38,29 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
}
});
});
//导出服务订单列表
var submitForm1 = function (ids, layero) {
if(!ids){
return false;
}
$("input[name=s_ids]", layero).val(ids);
$("#form1", layero).submit();
Layer.closeAll();
};
$(document).on("click", ".btn-export1", function () {
var ids = Table.api.selectedids(table);
Layer.confirm("选择导出的选项<form action='" + Fast.api.fixurl("registers/export1") + "' method='post' id='form1'><input type='hidden' name='s_ids' value=''/></form>", {
title: '导出数据',
btn: ["选中项(" + ids.length + "条)"],
success: function (layero, index) {
$(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
}, yes: function (index, layero) {
submitForm1(ids.join(","), layero);
return false;
}
});
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
... ...