Index.php 18 KB

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