Index.php 24 KB

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