123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\facade\Cache;
- use think\facade\Db;
- include (__DIR__ . '/../../vendor/phpoffice/phpexcel/Classes/PHPExcel.php');
- include (__DIR__ . '/../../vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php');
- class cgdupload extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('cgdupload')
- ->setDescription('the cgdupload command');
- }
- protected function execute(Input $input, Output $output)
- {
- // 指令输出
- $redis = Cache::store('redis');
- $iscgd = $redis->get("cgdupload");
- if($iscgd==0){
- $redis->set("cgdupload",1);
- }else{
- return;
- }
- $dirs = root_path() ."/public/storage/topic/CGD";
- if(!is_dir($dirs)){
- $redis->set("cgdupload",0);
- return ;
- }
- $ls =scandir($dirs);
- $files="";
- $extend="";
- foreach ($ls as $value){
- if($value=="." || $value==".."){
- continue;
- }
- if(is_file($dirs."/". $value)){
- $extend =pathinfo($dirs."/". $value)['extension'];
- if($extend=="xls"||$extend=="xlsx"){
- $files = $dirs."/". $value;
- break;
- }
- }
- }
- if ($extend == 'xlsx') {
- $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
- } else {
- $objReader = \PHPExcel_IOFactory::createReader('Excel5');
- }
- $spreadsheet = $objReader->load($files);
- $sheet = $spreadsheet->getActiveSheet();
- $sheetData = $sheet->toArray();
- if (empty($sheetData) || !is_array($sheetData)) {
- echo "数据不能为空";
- $redis->set("cgdupload",0);
- return ;
- }
- Db::startTrans();
- try{
- foreach ($sheetData as $key=>$value){
- if($key==0){
- continue;
- }
- $customer= Db::name("supplier_info")->where("name","=",$value[53])->find();
- $companyNo = isset($customer['code'])?$customer['code']:$value[54];
- $data=[
- 'name'=>$value[0],
- 'createdTime'=>$value[5],
- 'startTime'=>$value[5],
- 'ownerName'=>$value[1],
- 'department'=>$value[2],
- 'finishTime'=>$value[5],
- 'sequenceNo'=>$value[14],
- 'sequenceStatus'=>$value[9],
- 'ShortText1618270412964'=>$value[10],
- 'ShortText1618270466672'=>$value[11],
- 'number1618272663951'=>$value[12],
- 'ShortText1618308753677'=>$value[13],
- 'ShortText1618315935182'=>$value[14],
- 'Date1618315953443'=>$value[15],
- 'Number1618316157066'=>$value[16],
- 'Number1618316171848'=>$value[17],
- 'ShortText1617866362204'=>$value[18],
- 'ShortText1617866360004'=>$value[19],
- 'ShortText1618239976714'=>$value[20],
- 'ShortText1617866364821'=>$value[21],
- 'ShortText1618239993162'=>$value[22],
- 'RelevanceForm1617860945268'=>$value[23],
- 'ShortText1617861001482'=>$value[24],
- 'ShortText1617861966146'=>$value[25],
- 'ShortText1617865626160'=>$value[26],
- 'ShortText1617865633070'=>$value[27],
- 'ShortText1617865675342'=>$value[28],
- 'ShortText1617865678025'=>$value[29],
- 'ShortText1617865680605'=>$value[30],
- 'ShortText1617865683042'=>$value[31],
- 'text1618268357055'=>$value[32],
- 'ShortText1617865685744'=>$value[33],
- 'ShortText1618240134229'=>$value[34],
- 'Number1618240480148'=>$value[35],
- 'Number1618240458074'=>$value[36],
- 'ShortText1617866158120'=>$value[37],
- 'Number1618240350696'=>$value[38],
- 'number1618240356104'=>$value[39],
- 'ShortText1617865688485'=>$value[40],
- 'Number1617865804813'=>$value[41],
- 'Number1617865807879'=>$value[42],
- 'Number1617865810822'=>$value[43],
- 'Number1617865813284'=>$value[44],
- 'Number1617865816181'=>$value[45],
- 'number1618240204358'=>$value[46],
- 'number1618240287778'=>$value[47],
- 'Number1617865818517'=>$value[48],
- 'Number1617865824797'=>$value[49],
- 'ShortText1617866144054'=>$value[50],
- 'Number1618240600907'=>$value[51],
- 'Number1618240685904'=>$value[52],
- 'RelevanceForm1617861284547'=>$value[53],
- 'ShortText1617861287265'=>$companyNo,
- 'ShortText1617861449444'=>$value[55],
- 'ShortText1617861455145'=>$value[56],
- 'Date1617866234869'=> $value[57],
- 'Date1618324547052'=>$value[58],
- 'Number1618330470625'=>$value[59],
- 'Number1618330472961'=>$value[60],
- 'Number1618330541286'=>$value[61],
- 'Number1618330543270'=>$value[62],
- 'ShortText1618465932373'=>$value[63],
- 'number1618467257146'=>$value[64],
- 'ShortText1618859161646'=>$value[65],
- 'Date1618859180209'=>$value[66],
- 'StaffSelector1618859194105'=>$value[67],
- 'ShortText1618859321070'=>$value[68],
- 'StaffSelector1618885082387'=>$value[69],
- 'ShortText1618900704399'=>$value[70],
- 'Date1619009560712'=>$value[71],
- 'ShortText1619147112929'=>$value[72],
- 'ShortText1619164207953'=>$value[73],
- 'ShortText1619463188366'=>$value[74],
- 'ShortText1619463208482'=>$value[75],
- 'Date1619624209148'=>$value[76],
- 'ShortText1619624490635'=>$value[77],
- 'Number1619625470651'=>$value[78],
- 'Number1619625483510'=>$value[79],
- 'ShortText1619625566608'=>$value[80],
- 'Number1619632826654'=>$value[81],
- 'Number1619632830397'=>$value[82],
- 'RelevanceForm1620373842422'=>"",
- 'ShortText1620399144946'=>$value[83],
- 'ShortText1620753234895'=>$value[84],
- 'ShortText1620753237335'=>$value[85],
- 'StaffSelector1620899427104'=>$value[86],
- 'status'=>0,
- 'check_rate'=>0,
- ];
- $in= Db::name("cgd_info")->insert($data);
- if(!$in){
- unlink($files);
- Db::rollback();
- $redis->set("cgdupload",0);
- echo $value[0];
- return;
- }
- }
- Db::commit();
- $redis->set("cgdupload",0);
- }catch (\Exception $e){
- Db::rollback();
- echo $e->getMessage();
- $redis->set("cgdupload",0);
- return ;
- }
- $redis->set("cgdupload",0);
- unlink($files);
- $output->writeln('cgdupload');
- }
- }
|