123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace app\admin\controller;
- use app\common\util\ExcelUtil;
- use think\Db;
- use think\Exception;
- use tools\Phptree;
- class ImportDataFile extends Auth
- {
- public function importexcel(){
- return $this->fetch();
- }
- public function kq(){
- set_time_limit(0);
- ini_set("memory_limit", -1);
- ob_flush();//清空缓存
- flush();//刷新缓存
- if(request()->file()) {
- $file = request()->file('file');
- // 移动到框架应用根目录/uploads/ 目录下
- $info = $file->validate([ 'size'=>500*1024*1024,'ext'=>'xls,xlsx' ])
- ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'temp');
- if(!$info){
- exit('文件上传失败');
- }
- $img = './uploads/temp/' . $info->getSaveName();
- $filePath = str_replace('\\', '/', $img);
- $excelArray = ExcelUtil::read($filePath,
- ['val','val1','val2','val3','val4','val5','val6','val7','val8','val9','val10','val11','val13','val12']
- );
- // unset($excelArray[0]);
- if(empty($excelArray)){
- exit('文件内容为空');
- }
- $succ = [];
- foreach ($excelArray as $k => $v) {
- $name = $v['val'];
- $t = $v['val5'];
- $date = mb_substr($t,0,-11);
- $data = [
- 'name'=>$name,
- 'st'=>$date,
- 'day'=>date('Y-m-d',strtotime($date))
- ];
- $ret = Db::name('shuaka')->insert($data);
- if($ret){
- echo "<font color=\"green\" style='margin-left:20px;font-size: 17px'>第".($k+1)."行,导入成功</font><br />";
- }else{
- echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,导入失败</font><br />";
- }
- }
- }else{
- exit('请上传文件');
- }
- }
- public function sava(){
- $lists = Db::name('shuaka')
- ->group('name,day')
- ->order('id asc')
- ->select();
- foreach ($lists as $k=>$v){
- $count = Db::name('shuaka')
- ->where('name',$v['name'])
- ->where('day',$v['day'])
- ->count();
- $st = Db::name('shuaka')
- ->where('name',$v['name'])
- ->where('day',$v['day'])
- ->order('st asc')
- ->value('st');
- $et = Db::name('shuaka')
- ->where('name',$v['name'])
- ->where('day',$v['day'])
- ->order('st desc')
- ->value('st');
- $data = [
- 'name'=>$v['name'],
- 'st'=>$st,
- 'et'=>$count>1?$et:'',
- ];
- $res = Db::name('shuaka_log')->insertGetId($data);
- if($res){
- echo $res.'<pre/>';
- }
- }
- }
- }
|