qrdupload.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. class qrdupload extends Command
  12. {
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('qrdupload')
  17. ->setDescription('the qrdupload command');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $redis = Cache::store('redis');
  22. $isqrd = $redis->get("qrdupload");
  23. if($isqrd==0){
  24. $redis->set("qrdupload",1);
  25. }else{
  26. return;
  27. }
  28. $dirs = root_path() ."/public/storage/topic/QRD";
  29. if(!is_dir($dirs)){
  30. $redis->set("qrdupload",0);
  31. return ;
  32. }
  33. $ls =scandir($dirs);
  34. $files="";
  35. $extend="";
  36. foreach ($ls as $value){
  37. if($value=="." || $value==".."){
  38. continue;
  39. }
  40. if(is_file($dirs."/". $value)){
  41. $extend =pathinfo($dirs."/". $value)['extension'];
  42. if($extend=="xls"||$extend=="xlsx"){
  43. $files = $dirs."/". $value;
  44. break;
  45. }
  46. }
  47. }
  48. // $extend =pathinfo($files)['extension'];
  49. // $PHPEXCEL =new \PHPExcel()
  50. if ($extend == 'xlsx') {
  51. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  52. } else {
  53. $objReader = \PHPExcel_IOFactory::createReader('Excel5');
  54. }
  55. $spreadsheet = $objReader->load($files);
  56. $sheet = $spreadsheet->getActiveSheet();
  57. $sheetData = $sheet->toArray();
  58. if (empty($sheetData) || !is_array($sheetData)) {
  59. echo "数据不能为空";
  60. $redis->set("qrdupload",0);
  61. return ;
  62. }
  63. Db::startTrans();
  64. try{
  65. foreach ($sheetData as $key=>$value){
  66. if($key==0){
  67. continue;
  68. }
  69. $customer= Db::name("customer_info")->where("companyName","=",$value[11])->find();
  70. $companyNo = isset($customer['companyNo'])?$customer['companyNo']:$value['12'];
  71. $data=[
  72. 'name'=>$value[0],
  73. 'createdTime'=>$value[5],
  74. 'startTime'=>$value[7],
  75. 'finishTime'=>$value[7],
  76. 'ownerName'=>$value[3],
  77. 'departmentName'=>$value[2],
  78. 'sequenceNo'=>'QRDCP-'.date("YmdHis").$key,
  79. 'sequenceStatus'=>$value[9],
  80. 'Date1617081795606'=>$value[24],
  81. 'RelevanceForm1617022738190'=>$value[12],
  82. 'ShortText1617081712980'=>'',
  83. 'ShortText1617022967356'=>$value[19],
  84. 'ShortText1617023369580'=>$value[21],
  85. 'ShortText1617111725596'=>$value[25],
  86. 'ShortText1617365292699'=>$value[26],
  87. 'text1617499162303'=>$value[27],
  88. 'ShortText1617365495029'=>$value[28],
  89. 'ShortText1617499192065'=>$value[29],
  90. 'ShortText1617499210157'=>$value[30],
  91. 'text1617365578699'=>$value[31],
  92. 'text1617365594353'=>$value[32],
  93. 'text1617365597522'=>$value[33],
  94. 'text1617365646297'=>$value[34],
  95. 'text1617365950353'=>$value[35],
  96. 'ShortText1617366563255'=>$value[36],
  97. 'number1617366111666'=>$value[37],
  98. 'number1617366110639'=>$value[38],
  99. 'ShortText1617366186330'=>$value[39],
  100. 'ShortText1617367958909'=>$value[40],
  101. 'Number1617365688048'=>$value[41],
  102. 'Number1617366579767'=>$value[42],
  103. 'Number1617366626104'=>$value[43],
  104. 'ShortText1617650669915'=>$value[44],
  105. 'ShortText1617650701648'=>$value[45],
  106. 'ShortText1617670912205'=>$value[46],
  107. 'ShortText1617874567622'=>$value[47],
  108. 'Number1618248810624'=>$value[48],
  109. 'Number1618248813613'=>$value[49],
  110. 'Number1618249015661'=>$value[50],
  111. 'Number1618249019294'=>$value[51],
  112. 'Number1618249146997'=>$value[52],
  113. 'number1618249149738'=>$value[53],
  114. 'Number1618249202608'=>$value[54],
  115. 'Number1618249205231'=>$value[55],
  116. 'number1618249258956'=>$value[56],
  117. 'ShortText1618267589049'=>$value[57],
  118. 'StaffSelector1618445844046'=>$value[58],
  119. 'StaffSelector1618445850209'=>$value[59],
  120. 'ShortText1618446328311'=>$value[60],
  121. 'ShortText1618446949933'=>$value[61],
  122. 'ShortText1618446973813'=>$value[62],
  123. 'LongText1618446982973'=>$value[63],
  124. 'Date1618447068290'=>$value[64],
  125. 'ShortText1618447165317'=>$value[65],
  126. 'ShortText1618559007040'=>$value[66],
  127. 'ShortText1618559043560'=>$value[53]==0 ?3 :($value[52]==0 ? 1 :2),
  128. 'ShortText1618559274859'=>$value[68],
  129. 'ShortText1618887148862'=>$value[69],
  130. 'ShortText1619146965777'=>$value[70],
  131. 'ShortText1619164078168'=>$value[71],
  132. 'Date1619401771986'=>$value[72],
  133. 'Date1619402124793'=>$value[73],
  134. 'Number1619403905454'=>$value[74],
  135. 'Number1619403908740'=>$value[75],
  136. 'ShortText1619413388848'=>$value[15],
  137. 'ShortText1619413394855'=>$value[13],
  138. 'ShortText1619413401534'=>$value[14],
  139. 'ShortText1619487657199'=>$value[77],
  140. 'StaffSelector1619488013389'=>$value[79],
  141. 'ShortText1619523689586'=>$value[80],
  142. 'ShortText1619523693355'=>$value[85],
  143. 'ShortText1619523892833'=>$value[11],
  144. 'Date1619542686640'=>$value[82],
  145. 'RelevanceForm1619542896677'=>$value[83],
  146. 'ShortText1619542951283'=>$companyNo,
  147. 'ShortText1619543001392'=>$value[85],
  148. 'ShortText1619610909619'=>$value[86],
  149. 'Date1619626098213'=>$value[87],
  150. 'ShortText1619626536464'=>$value[88],
  151. 'Number1619626656082'=>$value[89],
  152. 'Number1619626666450'=>$value[90],
  153. 'Number1619632062547'=>$value[91],
  154. 'ShortText1619743751825'=>'',
  155. 'text1619743754479'=>"",
  156. 'text1619743755335'=>"",
  157. 'text1619743756377'=>"",
  158. 'Date1620370378620'=>$value[92],
  159. 'ShortText1620750298602'=>$value[93],
  160. 'ShortText1620750301301'=>$value[94],
  161. 'RelevanceForm1620750481892'=>$value[95],
  162. 'Number1620751537737'=>$value[96],
  163. 'Date1620751562219'=>$value[97],
  164. 'status'=>'',
  165. 'paying_fee'=>'',
  166. 'inving_fee'=>''
  167. ];
  168. $in= Db::name("qrd_info")->insert($data);
  169. if($in){
  170. $qrd = Db::name("qrd")->where([['sequenceNo',"=",$value[45]]])->find();
  171. if($qrd){
  172. $qrd['total_fee'] += round($value['49'],2);
  173. $qrd['apay_fee'] += round($value['52'],2);
  174. $qrd['wpay_fee'] += round($value['53'],2);
  175. $qrd['ainv_fee'] += round($value['54'],2);
  176. $qrd['winv_fee'] += round($value['55'],2);
  177. $qrd['inv_status'] = $value['68']==1 ? 1 : $qrd['inv_status'];
  178. $qrd['pay_status'] = $value['67']==1 ? 1 : $qrd['pay_status'];
  179. $up= Db::name("qrd")->save($qrd);
  180. if(!$up){
  181. unlink($files);
  182. Db::rollback();
  183. $redis->set("qrdupload",0);
  184. return;
  185. }
  186. }else{
  187. $qrd=[
  188. "name"=>'Excel'.$value[45],
  189. "createdTime"=>$value[5],
  190. "sequenceNo"=>$value[45],
  191. "sales_name"=>$value[58],
  192. "sales_depart"=>$value[2],
  193. "customer"=>$value[11],
  194. "total_fee"=> round($value['49'],2),
  195. "mobile"=>"",
  196. "contactor"=>"",
  197. "qrddate"=>$value[5],
  198. "companyNo"=>$companyNo,
  199. "supplerName"=>$value[10],
  200. "addr"=>"",
  201. "depart"=>$value[2],
  202. "type"=>1,
  203. "apay_fee"=>round($value['52'],2),
  204. "pay_fee"=>0,
  205. "wpay_fee"=>round($value['53'],2),
  206. "ainv_fee"=>round($value['54'],2),
  207. "inv_fee"=>0,
  208. "winv_fee"=>round($value['55'],2),
  209. "inv_status"=>$value['67'],
  210. "pay_status"=>$value['68'],
  211. "status"=>1,
  212. "addtime"=>$value[5],
  213. "updatetime"=>date("Y-m-d H:i:s")
  214. ];
  215. $link=Db::name("qrd")->insert($qrd);
  216. if(!$link){
  217. unlink($files);
  218. Db::rollback();
  219. $redis->set("qrdupload",0);
  220. return;
  221. }
  222. }
  223. }
  224. if(!$in){
  225. unlink($files);
  226. Db::rollback();
  227. $redis->set("qrdupload",0);
  228. echo $value[0];
  229. return;
  230. }
  231. }
  232. Db::commit();
  233. }catch (\Exception $e){
  234. Db::rollback();
  235. echo $e->getMessage();
  236. $redis->set("qrdupload",0);
  237. return ;
  238. }
  239. unlink($files);
  240. $redis->set("qrdupload",0);
  241. $output->writeln('qrdupload');
  242. }
  243. }