Index.php 24 KB

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