Index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\util\AppMsg;
  4. use app\common\util\ExcelUtil;
  5. use app\hander\HelpHander;
  6. use EasyWeChat\Factory;
  7. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  8. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  9. use think\App;
  10. use think\Controller;
  11. use think\Db;
  12. class Index extends Controller
  13. {
  14. public function __construct(App $app = null) {
  15. parent::__construct($app);
  16. // $this->model = new \app\common\model\Daily();
  17. }
  18. public function device(){
  19. set_time_limit(0);
  20. ini_set("memory_limit","512M");
  21. $file = "./1.xls";
  22. $orgId = 100;
  23. $cate1 = 22; //灭火器
  24. $cate2 = 23; // 消火栓
  25. $form1 = "20,21,22,23";
  26. $form2 = "24,25,26,27";
  27. $userId = 3139;
  28. $data = ExcelUtil::read($file,['title','sn','area','cate_id','content']);
  29. $i = 0;
  30. foreach ($data as $k=>$v){
  31. if($i >= 906){
  32. $data[$k]['org_id'] = $orgId;
  33. $data[$k]['enable'] = 1;
  34. if($v['cate_id'] == "灭火器"){
  35. $data[$k]['cate_id'] = $cate1;
  36. $data[$k]['device_form'] = $form1;
  37. }else{
  38. $data[$k]['cate_id'] = $cate2;
  39. $data[$k]['device_form'] = $form2;
  40. }
  41. $deivceId = Db::name('device')->insertGetId($data[$k]);
  42. if($deivceId){
  43. Db::name('device_user')->insert([
  44. "device_id" => $deivceId,
  45. "user_id" => $userId,
  46. ]);
  47. }
  48. }
  49. $i++;
  50. }
  51. halt($data);
  52. }
  53. public function tt(){
  54. $orgId = 28;
  55. $mode = 3;
  56. // $res = send_jpush(['8'],AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>1]);
  57. // echo "<pre/>";
  58. // print_r($res);
  59. // die;
  60. }
  61. public function index(){
  62. halt(get_unique_sn());
  63. $cc = config('database.database');
  64. halt($cc);
  65. // $json = [
  66. // 'users' => [9],
  67. // 'msg' => 'ssssssssssssssss',
  68. // 'extra' => [],
  69. // 'type' => AppMsg::PUSH_WORKER_ORDER_SEND
  70. // ];
  71. // queue_push(json_encode($json),0);
  72. $client = new \GuzzleHttp\Client();
  73. $url = "https://www.baidu.com";
  74. $response = $client->request('GET', $url);
  75. $result = $response->getBody();
  76. halt($result);
  77. }
  78. public function setSn(){
  79. $orders = Db::name('orders')->where('sn','')->limit(300)->field('id,create_time')->select();
  80. $orders = $orders?$orders:[];
  81. $nums = 100001;
  82. foreach ($orders as $k=>$v){
  83. Db::name('orders')->where('id',$v['id'])->update(['sn' => date('YmdHis').$nums]);
  84. $nums++;
  85. }
  86. dump(count($orders));
  87. }
  88. public function setSn2(){
  89. $orders = Db::name('todo')->where('sn','')->limit(300)->field('id,create_time')->select();
  90. $orders = $orders?$orders:[];
  91. $nums = 100001;
  92. foreach ($orders as $k=>$v){
  93. Db::name('todo')->where('id',$v['id'])->update(['sn' => date('YmdHis').$nums]);
  94. $nums++;
  95. }
  96. dump(count($orders));
  97. }
  98. public function sqldic(){
  99. $db = config('database.database');
  100. $sql = <<<sql
  101. select
  102. TABLE_NAME as name,
  103. COLUMN_NAME as col,
  104. COLUMN_TYPE as type,
  105. COLLATION_NAME as collation,
  106. COLUMN_COMMENT as comment
  107. from information_schema.columns
  108. where TABLE_SCHEMA='{$db}'
  109. sql;
  110. $sql2 = <<<sql
  111. select
  112. ENGINE as engine,
  113. TABLE_COLLATION as collation,
  114. TABLE_COMMENT as comment,
  115. TABLE_TYPE as type
  116. from information_schema.tables
  117. where TABLE_SCHEMA='{$db}' and TABLE_NAME=
  118. sql;
  119. $lists = Db::query($sql);
  120. if(!$lists){
  121. halt('无数据');
  122. }
  123. $dic = [];
  124. $tables = [];
  125. foreach ($lists as $k=>$v){
  126. if(!in_array($v['name'],$tables)){
  127. $mdata = Db::query($sql2."'{$v['name']}'");
  128. if(!$mdata){
  129. halt('查询表错误');
  130. }
  131. $table = $mdata[0];
  132. if($table['type'] != 'VIEW'){
  133. $tables[] = $v['name'];
  134. $cols = [];
  135. foreach ($lists as $kk=>$vv){
  136. if($vv['name'] == $v['name']){
  137. $cols[] = [
  138. 'name' => $vv['col'],
  139. 'type' => $vv['type'],
  140. 'comment' => $vv['comment']
  141. ];
  142. }
  143. }
  144. $dic[] = [
  145. 'name' => $v['name'],
  146. 'engine' => $table['engine'],
  147. 'type' => $table['type'],
  148. 'collation' => $table['collation'],
  149. 'comment' => $table['comment'],
  150. 'cols' => $cols
  151. ];
  152. }
  153. }
  154. }
  155. $spreadsheet = new Spreadsheet();
  156. $worksheet = $spreadsheet->getActiveSheet();
  157. $worksheet->setTitle('数据库字典');
  158. $titles = ['表名','引擎','排序规则','注释'];
  159. foreach ($titles as $key => $value) {
  160. $worksheet->setCellValueByColumnAndRow($key+1, 1, $value);
  161. }
  162. $arr = array('A','B','C','D');
  163. $styleArray = [
  164. 'font' => [
  165. 'bold' => true
  166. ],
  167. 'alignment' => [
  168. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  169. ],
  170. ];
  171. $styleArray2 = [
  172. 'alignment' => [
  173. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  174. ],
  175. ];
  176. foreach($arr as $k=>$v){
  177. $worksheet->getStyle($v.'1')->applyFromArray($styleArray)->getFont()->setSize(12);
  178. $worksheet->getStyle($v)->applyFromArray($styleArray2)->getAlignment()->setWrapText(true);//换行
  179. $worksheet->getColumnDimension($v)->setWidth(25);
  180. }
  181. $lists = $dic;
  182. foreach ($lists as $k=>$v){
  183. $worksheet->setCellValueByColumnAndRow(1, $k + 2, $v['name']);
  184. $worksheet->setCellValueByColumnAndRow(2, $k + 2, $v['engine']);
  185. $worksheet->setCellValueByColumnAndRow(3, $k + 2, $v['collation']);
  186. $worksheet->setCellValueByColumnAndRow(4, $k + 2, $v['comment']);
  187. $cols = $v['cols'];
  188. $sheet = $spreadsheet->createSheet($k+10)->setTitle($v['name']);
  189. $worksheet->getCellByColumnAndRow(1, $k + 2)->getHyperlink()->setUrl("sheet://{$v['name']}!A1");
  190. foreach ($cols as $kk=>$vv){
  191. $this->writeSheet($sheet,$cols,$k + 2);
  192. }
  193. }
  194. $worksheet->setCellValueByColumnAndRow(1, $k + 3, '共'.count($lists).'张表');
  195. $fileName = '数据库字典.xlsx';
  196. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  197. header('Content-Disposition: attachment;filename="'.$fileName.'"');
  198. header('Cache-Control: max-age=0');
  199. $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
  200. $writer->save('php://output');
  201. }
  202. private function writeSheet($sheet,$data,$row){
  203. $arr = array('A','B','C','D');
  204. $styleArray = [
  205. 'font' => [
  206. 'bold' => true
  207. ],
  208. 'alignment' => [
  209. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  210. ],
  211. ];
  212. $styleArray2 = [
  213. 'alignment' => [
  214. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  215. ],
  216. ];
  217. foreach($arr as $k=>$v){
  218. $sheet->getStyle($v.'2')->applyFromArray($styleArray)->getFont()->setSize(12);
  219. $sheet->getStyle($v)->applyFromArray($styleArray2)->getAlignment()->setWrapText(true);//换行
  220. $sheet->getColumnDimension($v)->setWidth(20);
  221. }
  222. $sheet->setCellValueByColumnAndRow(1, 1, '返回目录页');
  223. $sheet->getCellByColumnAndRow(1, 1)->getHyperlink()->setUrl("sheet://数据库字典!A".$row);
  224. $titles = ['字段名','类型','注释'];
  225. foreach ($titles as $key => $value) {
  226. $sheet->setCellValueByColumnAndRow($key+1, 2, $value);
  227. }
  228. foreach ($data as $k=>$v){
  229. $sheet->setCellValueByColumnAndRow(1, $k + 3, $v['name']);
  230. $sheet->setCellValueByColumnAndRow(2, $k + 3, $v['type']);
  231. $sheet->setCellValueByColumnAndRow(3, $k + 3, $v['comment']);
  232. }
  233. }
  234. public function host(){
  235. exit();
  236. $host1 = "http://lf.jya-tech.com";
  237. $host2 = "http://wy.gzbjwy.net";
  238. $host = "http://logistics.hetaigl.com";
  239. // $lists = Db::name('screen_module')->select();
  240. // foreach ($lists as $k=>$v){
  241. // if($v['img']){
  242. // $img = str_ireplace($host1,$host,$v['img']);
  243. // $img = str_ireplace($host2,$host,$img);
  244. // Db::name('screen_module')->where('id',$v['id'])->setField('img',$img);
  245. // }
  246. // }
  247. $lists = Db::name('screen')->select();
  248. foreach ($lists as $k=>$v){
  249. if($v['img']){
  250. $img = str_ireplace($host1,$host,$v['img']);
  251. $img = str_ireplace($host2,$host,$img);
  252. Db::name('screen')->where('id',$v['id'])->setField('img',$img);
  253. }
  254. }
  255. $lists = Db::name('screen_template')->select();
  256. foreach ($lists as $k=>$v){
  257. if($v['img']){
  258. $img = str_ireplace($host1,$host,$v['img']);
  259. $img = str_ireplace($host2,$host,$img);
  260. Db::name('screen_template')->where('id',$v['id'])->setField('img',$img);
  261. }
  262. }
  263. // $lists = Db::name('app_icon')->select();
  264. // foreach ($lists as $k=>$v){
  265. // if($v['path']){
  266. // $img = str_ireplace($host1,$host,$v['path']);
  267. // $img = str_ireplace($host2,$host,$img);
  268. // Db::name('app_icon')->where('id',$v['id'])->setField('path',$img);
  269. // }
  270. // if($v['url']){
  271. // $img = str_ireplace($host1,$host,$v['url']);
  272. // $img = str_ireplace($host2,$host,$img);
  273. // Db::name('app_icon')->where('id',$v['id'])->setField('url',$img);
  274. // }
  275. // }
  276. }
  277. private function getSize($text,$size,$weight,$height,$i=1,$angle=0){
  278. //获取文字信息
  279. $font = env('root_path').'public/static/hylht.ttf';
  280. // $size = 100;
  281. $info = imagettfbbox($size, $angle, $font, $text);
  282. $minx = min($info[0], $info[2], $info[4], $info[6]);
  283. $maxx = max($info[0], $info[2], $info[4], $info[6]);
  284. $miny = min($info[1], $info[3], $info[5], $info[7]);
  285. $maxy = max($info[1], $info[3], $info[5], $info[7]);
  286. /* 计算文字初始坐标和尺寸 */
  287. $x = $minx;
  288. $y = abs($miny);
  289. $w = $maxx - $minx;
  290. $h = $maxy - $miny;
  291. $xx = ($weight - $w) / 2;
  292. $yy = $height - ($h+10)*$i;
  293. return [$xx,$yy];
  294. }
  295. public function excel2(){
  296. set_time_limit(0);
  297. ini_set("memory_limit","2048M");
  298. exit();
  299. $page = 9;
  300. $size = 10000;
  301. $lists = Db::name('oa_lis')->page($page,$size)->order('start asc')->select();
  302. if(!$lists){
  303. halt('无数据');
  304. }
  305. foreach ($lists as $k=>$v){
  306. $btime = date('Y-m-d',strtotime($v['start'])).' 03:00:00';
  307. if($btime > $v['start']){ // 算昨天的
  308. $v['day'] = date('Ymd',strtotime($btime) - 24*60*60);
  309. }
  310. $ret = Db::name('oa')->where('name',$v['name'])->where('day',$v['day'])->find();
  311. if($ret){
  312. if(!$ret['end'] || $ret['end'] < $v['start']){
  313. Db::name('oa')->where('id',$ret['id'])->update([
  314. 'end' => $v['start']
  315. ]);
  316. }
  317. }else{
  318. if($btime <= $v['start']){
  319. Db::name('oa')->insert([
  320. 'name' => $v['name'],
  321. 'start' => $v['start'],
  322. 'day' => $v['day'],
  323. ]);
  324. }
  325. }
  326. }
  327. halt('结束2');
  328. }
  329. public function excel3(){
  330. $names = [
  331. '冯主任','张棉旺','吴晓刚','王先生','肖先生','王君','杨林源','王杰','董春艳','吴新刚','胡添滢','荣海燕',
  332. '丁文佳','王国玲','杨和融','赵雷','杨劲','石少亮','许倩鸿','杨璐','王玉玲','秦健','汪涵','郑琳','蔡涛',
  333. '贾永利','陈婧','周钊伟','雷春光','孙晨','谢正辉','吕雯','张宁','杨耀强','李本新','李月辉','陈晨','林进军',
  334. '寇建娣','王晓博','齐学东','隗永芝','牛全起','李鑫','闫勇哲','郭风军','张光利','文辉','王晨','王敏','范泉',
  335. '刘学政','王昱','马跃征','董杰','刘卉丛','梁艳','董军红','刘晓伟','赵雪','赵南','伍力','王宇','张京环',
  336. '李永尖','陈鹏','贾自强','杨云','黄志军','张天舒','张云','王新先','沈涛','吴德安','王帅','龙朝辉','王瑞',
  337. '刘爱枝','耿波','薛晓辉','徐新建','魏京菊','周云隆','孙立民','刁文矛','王鹏飞','冯峰-华馨泰','刘建宁-华馨泰'
  338. ];
  339. // $days = [1,2,3,4,5,6,7,10,16,17,23,24,30,31];
  340. // $mdays = 31;
  341. // $m = '10';
  342. // $month = '202110';
  343. $days = [6,7,13,14,20,21,27,28];
  344. $mdays = 30;
  345. $m = '11';
  346. $month = '202111';
  347. // $days = [4,5,11,12,18,19,25,26];
  348. // $mdays = 31;
  349. // $m = '12';
  350. // $month = '202112';
  351. $char = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  352. $lins = [];
  353. for( $i=0;$i<$mdays*3 + 4;$i++ ){
  354. $r1 = $i%26;
  355. $r2 = floor($i/26);
  356. if($r2 == 0){
  357. $lins[] = $char[$r1];
  358. }else if($r2 == 1){
  359. $lins[] = 'A'.$char[$r1];
  360. }else if($r2 == 2){
  361. $lins[] = 'B'.$char[$r1];
  362. }else if($r2 == 3){
  363. $lins[] = 'C'.$char[$r1];
  364. }
  365. }
  366. $lists = [];
  367. foreach ($names as $k=>$v){
  368. $d = [
  369. 'name' => $v,
  370. 'tday' => $mdays - count($days),
  371. ];
  372. $thour = 0;
  373. for( $i=1;$i<=$mdays;$i++ ){
  374. if($i < 10){
  375. $day = $month.'0'.$i;
  376. }else{
  377. $day = $month.$i;
  378. }
  379. $d['s'.$i] = '';
  380. $d['e'.$i] = '';
  381. $d['h'.$i] = 0;
  382. $info = Db::name('oa')->where('name',$v)->where('day',$day)->find();
  383. if($info){
  384. $d['s'.$i] = date('H:i:s',strtotime($info['start']));
  385. $d['e'.$i] = $info['end']?date('H:i:s',strtotime($info['end'])):'';
  386. $hour = 0;
  387. if($info['end']){
  388. $hour = round((strtotime($info['end']) - strtotime($info['start']))/3600,2);
  389. }
  390. $d['h'.$i] = $hour;
  391. $thour = $thour + $hour;
  392. }
  393. }
  394. $d['thour'] = $thour;
  395. $d['avghour'] = round($thour/$d['tday'],2);
  396. $lists[] = $d;
  397. }
  398. // halt($lists);
  399. $spreadsheet = new Spreadsheet();
  400. $worksheet = $spreadsheet->getActiveSheet();
  401. //设置工作表标题名称
  402. $worksheet->setTitle('考勤'.$m.'月');
  403. foreach ($lins as $k=>$v){
  404. $spreadsheet->setActiveSheetIndex(0)->getStyle($v)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
  405. $spreadsheet->setActiveSheetIndex(0)->getColumnDimension($v)->setAutoSize(true);
  406. }
  407. //表头
  408. //设置单元格内容
  409. $worksheet->setCellValueByColumnAndRow(1, 1, '姓名');
  410. $spreadsheet->getActiveSheet()->mergeCells('A1:A2');
  411. $j = 1;
  412. for( $i=1;$i<=$mdays*3;$i=$i+3 ){
  413. $spreadsheet->getActiveSheet()->mergeCells($lins[$i].'1:'.$lins[$i+2].'1');
  414. $worksheet->setCellValueByColumnAndRow($i+1, 1, $j.'日');
  415. $worksheet->setCellValueByColumnAndRow($i+2, 1, '');
  416. $worksheet->setCellValueByColumnAndRow($i+3, 1, '');
  417. $j++;
  418. }
  419. $worksheet->setCellValueByColumnAndRow($mdays*3+2, 1, '应出勤天数');
  420. $spreadsheet->getActiveSheet()->mergeCells($lins[$mdays*3+1].'1:'.$lins[$mdays*3+1].'2');
  421. $worksheet->setCellValueByColumnAndRow($mdays*3+3, 1, '总时长(h)');
  422. $spreadsheet->getActiveSheet()->mergeCells($lins[$mdays*3+2].'1:'.$lins[$mdays*3+2].'2');
  423. $worksheet->setCellValueByColumnAndRow($mdays*3+4, 1, '平均时长(h)');
  424. $spreadsheet->getActiveSheet()->mergeCells($lins[$mdays*3+3].'1:'.$lins[$mdays*3+3].'2');
  425. $worksheet->setCellValueByColumnAndRow(1, 2, '');
  426. for( $i=1;$i<=$mdays*3;$i=$i+3 ){
  427. $worksheet->setCellValueByColumnAndRow($i+1, 2, '上班');
  428. $worksheet->setCellValueByColumnAndRow($i+2, 2, '下班');
  429. $worksheet->setCellValueByColumnAndRow($i+3, 2, '时长(h)');
  430. }
  431. foreach ($lists as $k=>$v){
  432. $n = $v['name'];
  433. if($n == '冯主任'){
  434. $n = '冯磊';
  435. }else if($n == '王先生'){
  436. $n = '王汝江';
  437. }else if($n == '肖先生'){
  438. $n = '肖洪钦';
  439. }else if($n == '冯峰-华馨泰'){
  440. $n = '冯峰';
  441. }else if($n == '刘建宁-华馨泰'){
  442. $n = '刘建宁';
  443. }
  444. $worksheet->setCellValueByColumnAndRow(1, $k+3, $n);
  445. $j = 1;
  446. for( $i=1;$i<=$mdays*3;$i=$i+3 ){
  447. $worksheet->setCellValueByColumnAndRow($i+1, $k+3, $v['s'.$j]);
  448. $worksheet->setCellValueByColumnAndRow($i+2, $k+3, $v['e'.$j]);
  449. $worksheet->setCellValueByColumnAndRow($i+3, $k+3, $v['h'.$j]);
  450. $j++;
  451. }
  452. $worksheet->setCellValueByColumnAndRow($mdays*3+2, $k+3, $v['tday']);
  453. $worksheet->setCellValueByColumnAndRow($mdays*3+3, $k+3, $v['thour']);
  454. $worksheet->setCellValueByColumnAndRow($mdays*3+4, $k+3, $v['avghour']);
  455. }
  456. $filename = '考勤'.$m.'月.xlsx';
  457. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  458. header('Content-Disposition: attachment;filename="'.$filename.'"');
  459. header('Cache-Control: max-age=0');
  460. $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
  461. $writer->save('php://output');
  462. }
  463. public function ll(){
  464. $list = Db::name('mate_goods')
  465. ->alias('a')
  466. ->join('mate_cate b','a.cate_id=b.id')
  467. ->where('a.org_id',27)
  468. ->field('a.*,b.title as cateName')
  469. ->select();
  470. $succ = 0;
  471. foreach ($list as $k=>$v){
  472. if($v['cateName']=='电工类'){
  473. $a = 9;
  474. }elseif ($v['cateName']=='木工类'){
  475. $a = 93;
  476. }elseif ($v['cateName']=='水工类'){
  477. $a = 128;
  478. }
  479. $r = Db::name('mate_goods')
  480. ->where('id',$v['id'])
  481. ->update([
  482. 'update_time'=>getTime(),
  483. 'cate_id'=>$a
  484. ]);
  485. if($r){
  486. $succ++;
  487. }
  488. }
  489. echo $succ;
  490. }
  491. }