cgdupload.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. include (__DIR__ . '/../../vendor/phpoffice/phpexcel/Classes/PHPExcel.php');
  12. include (__DIR__ . '/../../vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php');
  13. class cgdupload extends Command
  14. {
  15. protected function configure()
  16. {
  17. // 指令配置
  18. $this->setName('cgdupload')
  19. ->setDescription('the cgdupload command');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. // 指令输出
  24. $redis = Cache::store('redis');
  25. $iscgd = $redis->get("cgdupload");
  26. if($iscgd==0){
  27. $redis->set("cgdupload",1);
  28. }else{
  29. return;
  30. }
  31. $dirs = root_path() ."/public/storage/topic/CGD";
  32. if(!is_dir($dirs)){
  33. $redis->set("cgdupload",0);
  34. return ;
  35. }
  36. $ls =scandir($dirs);
  37. $files="";
  38. $extend="";
  39. foreach ($ls as $value){
  40. if($value=="." || $value==".."){
  41. continue;
  42. }
  43. if(is_file($dirs."/". $value)){
  44. $extend =pathinfo($dirs."/". $value)['extension'];
  45. if($extend=="xls"||$extend=="xlsx"){
  46. $files = $dirs."/". $value;
  47. break;
  48. }
  49. }
  50. }
  51. if ($extend == 'xlsx') {
  52. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  53. } else {
  54. $objReader = \PHPExcel_IOFactory::createReader('Excel5');
  55. }
  56. $spreadsheet = $objReader->load($files);
  57. $sheet = $spreadsheet->getActiveSheet();
  58. $sheetData = $sheet->toArray();
  59. if (empty($sheetData) || !is_array($sheetData)) {
  60. echo "数据不能为空";
  61. $redis->set("cgdupload",0);
  62. return ;
  63. }
  64. Db::startTrans();
  65. try{
  66. foreach ($sheetData as $key=>$value){
  67. if($key==0){
  68. continue;
  69. }
  70. $customer= Db::name("supplier_info")->where("name","=",$value[53])->find();
  71. $companyNo = isset($customer['code'])?$customer['code']:$value[54];
  72. $data=[
  73. 'name'=>$value[0],
  74. 'createdTime'=>$value[5],
  75. 'startTime'=>$value[5],
  76. 'ownerName'=>$value[1],
  77. 'department'=>$value[2],
  78. 'finishTime'=>$value[5],
  79. 'sequenceNo'=>$value[14],
  80. 'sequenceStatus'=>$value[9],
  81. 'ShortText1618270412964'=>$value[10],
  82. 'ShortText1618270466672'=>$value[11],
  83. 'number1618272663951'=>$value[12],
  84. 'ShortText1618308753677'=>$value[13],
  85. 'ShortText1618315935182'=>$value[14],
  86. 'Date1618315953443'=>$value[15],
  87. 'Number1618316157066'=>$value[16],
  88. 'Number1618316171848'=>$value[17],
  89. 'ShortText1617866362204'=>$value[18],
  90. 'ShortText1617866360004'=>$value[19],
  91. 'ShortText1618239976714'=>$value[20],
  92. 'ShortText1617866364821'=>$value[21],
  93. 'ShortText1618239993162'=>$value[22],
  94. 'RelevanceForm1617860945268'=>$value[23],
  95. 'ShortText1617861001482'=>$value[24],
  96. 'ShortText1617861966146'=>$value[25],
  97. 'ShortText1617865626160'=>$value[26],
  98. 'ShortText1617865633070'=>$value[27],
  99. 'ShortText1617865675342'=>$value[28],
  100. 'ShortText1617865678025'=>$value[29],
  101. 'ShortText1617865680605'=>$value[30],
  102. 'ShortText1617865683042'=>$value[31],
  103. 'text1618268357055'=>$value[32],
  104. 'ShortText1617865685744'=>$value[33],
  105. 'ShortText1618240134229'=>$value[34],
  106. 'Number1618240480148'=>$value[35],
  107. 'Number1618240458074'=>$value[36],
  108. 'ShortText1617866158120'=>$value[37],
  109. 'Number1618240350696'=>$value[38],
  110. 'number1618240356104'=>$value[39],
  111. 'ShortText1617865688485'=>$value[40],
  112. 'Number1617865804813'=>$value[41],
  113. 'Number1617865807879'=>$value[42],
  114. 'Number1617865810822'=>$value[43],
  115. 'Number1617865813284'=>$value[44],
  116. 'Number1617865816181'=>$value[45],
  117. 'number1618240204358'=>$value[46],
  118. 'number1618240287778'=>$value[47],
  119. 'Number1617865818517'=>$value[48],
  120. 'Number1617865824797'=>$value[49],
  121. 'ShortText1617866144054'=>$value[50],
  122. 'Number1618240600907'=>$value[51],
  123. 'Number1618240685904'=>$value[52],
  124. 'RelevanceForm1617861284547'=>$value[53],
  125. 'ShortText1617861287265'=>$companyNo,
  126. 'ShortText1617861449444'=>$value[55],
  127. 'ShortText1617861455145'=>$value[56],
  128. 'Date1617866234869'=> $value[57],
  129. 'Date1618324547052'=>$value[58],
  130. 'Number1618330470625'=>$value[59],
  131. 'Number1618330472961'=>$value[60],
  132. 'Number1618330541286'=>$value[61],
  133. 'Number1618330543270'=>$value[62],
  134. 'ShortText1618465932373'=>$value[63],
  135. 'number1618467257146'=>$value[64],
  136. 'ShortText1618859161646'=>$value[65],
  137. 'Date1618859180209'=>$value[66],
  138. 'StaffSelector1618859194105'=>$value[67],
  139. 'ShortText1618859321070'=>$value[68],
  140. 'StaffSelector1618885082387'=>$value[69],
  141. 'ShortText1618900704399'=>$value[70],
  142. 'Date1619009560712'=>$value[71],
  143. 'ShortText1619147112929'=>$value[72],
  144. 'ShortText1619164207953'=>$value[73],
  145. 'ShortText1619463188366'=>$value[74],
  146. 'ShortText1619463208482'=>$value[75],
  147. 'Date1619624209148'=>$value[76],
  148. 'ShortText1619624490635'=>$value[77],
  149. 'Number1619625470651'=>$value[78],
  150. 'Number1619625483510'=>$value[79],
  151. 'ShortText1619625566608'=>$value[80],
  152. 'Number1619632826654'=>$value[81],
  153. 'Number1619632830397'=>$value[82],
  154. 'RelevanceForm1620373842422'=>"",
  155. 'ShortText1620399144946'=>$value[83],
  156. 'ShortText1620753234895'=>$value[84],
  157. 'ShortText1620753237335'=>$value[85],
  158. 'StaffSelector1620899427104'=>$value[86],
  159. 'status'=>0,
  160. 'check_rate'=>0,
  161. ];
  162. $in= Db::name("cgd_info")->insert($data);
  163. if(!$in){
  164. unlink($files);
  165. Db::rollback();
  166. $redis->set("cgdupload",0);
  167. echo $value[0];
  168. return;
  169. }
  170. }
  171. Db::commit();
  172. $redis->set("cgdupload",0);
  173. }catch (\Exception $e){
  174. Db::rollback();
  175. echo $e->getMessage();
  176. $redis->set("cgdupload",0);
  177. return ;
  178. }
  179. $redis->set("cgdupload",0);
  180. unlink($files);
  181. $output->writeln('cgdupload');
  182. }
  183. }