Index.php 18 KB

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