Index.php 25 KB

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