WasteRecord.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\User;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. use think\Exception;
  8. class WasteRecord extends Auth {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model = new \app\common\model\WasteRecord();
  12. $this->table = $this->model->table;
  13. }
  14. public function index() {
  15. if (request()->isAjax()) {
  16. //分页参数
  17. $length = input('rows', 10, 'intval'); //每页条数
  18. $page = input('page', 1, 'intval'); //第几页
  19. $start = ($page - 1) * $length; //分页开始位置
  20. //排序
  21. $sortRow = input('sidx', 'id', 'trim'); //排序列
  22. $sort = input('sord', 'desc', 'trim'); //排序方式
  23. $order = $sortRow . ' ' . $sort;
  24. $cateid = input('cateid', '', 'trim');
  25. if ($cateid) {
  26. $map[] = ['cateid', 'like', '%' . $cateid . '%'];
  27. }
  28. $start_time = input('start', '', 'trim');
  29. $end_time = input('end', '', 'trim');
  30. if ($start_time !== '' && $end_time !== '') {
  31. if ($start_time <= $end_time) {
  32. $start_time = date('Ymd', strtotime($start_time));
  33. $end_time = date('Ymd', strtotime($end_time));
  34. $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
  35. }
  36. }
  37. if ($start_time !== '' && $end_time == '') {
  38. $start_time = date('Ymd', strtotime($start_time));
  39. $map[] = ['create_yyyymmdd', '>=', $start_time];
  40. }
  41. if ($start_time == '' && $end_time !== '') {
  42. $end_time = date('Ymd', strtotime($end_time));
  43. $map[] = ['create_yyyymmdd', '<=', $end_time];
  44. }
  45. $status = input('status', '', 'trim');
  46. if ($status != '') {
  47. if ($status == 4) {
  48. $map[] = ['status', 'in', [0, 1]];
  49. }
  50. else {
  51. if (in_array($status, array(0, 1, 2, 3))) {
  52. $map[] = ['status', '=', $status];
  53. }
  54. }
  55. }
  56. $post = request()->post();
  57. if (!isset($post['status'])) {
  58. $map[] = ['status', 'in', [0, 1]];
  59. }
  60. $map[] = ['del', '=', 0];
  61. $map[] = ['org_id', '=', $this->orgId];
  62. $map = empty($map) ? true : $map;
  63. //数据查询
  64. $lists = db($this->table)
  65. ->where($map)
  66. ->limit($start, $length)
  67. ->order($order)
  68. ->select();
  69. foreach ($lists as $k => $v) {
  70. $lists[$k]['waste_device'] = db('address')
  71. ->where('id', $v['waste_device_id'])
  72. ->value('title');
  73. $lists[$k]['real_name'] = db('user')
  74. ->where('id', $v['user_id'])
  75. ->value('real_name');
  76. $lists[$k]['cate'] = db('waste_type')
  77. ->where('id', $v['cateid'])
  78. ->value('title');
  79. // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
  80. $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
  81. $lists[$k]['status'] = $this->model->status[$v['status']];
  82. $type = Db::name('waste_type')
  83. ->where('id', $v['cateid'])
  84. ->find();
  85. $num = '';
  86. if($type['type'] == 1 && $v['num'] > 0){
  87. $num = ' ('.$v['num'].$type['unit'].')';
  88. }
  89. $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
  90. }
  91. //数据返回
  92. $totalCount = db($this->table)->where($map)->count();
  93. $totalPage = ceil($totalCount / $length);
  94. $result['page'] = $page;
  95. $result['total'] = $totalPage;
  96. $result['records'] = $totalCount;
  97. $result['rows'] = $lists;
  98. return json($result);
  99. }
  100. else {
  101. $type = (new \app\common\model\WasteType())->getList($this->orgId);
  102. $this->assign('m_name', '医废类型');
  103. $this->assign('type', $type);
  104. $this->assign('status', $this->model->status);
  105. return $this->fetch();
  106. }
  107. }
  108. // 科室医废
  109. public function index2() {
  110. if (request()->isAjax()) {
  111. $depId = Db::name('user_dep')->where("user_id",$this->userId)->value('dep_id');
  112. $addrs = [];
  113. $alists = model("Address")->getListByType(7,$this->orgId);
  114. foreach ($alists as $k=>$v){
  115. if($v['dep_id'] == $depId){
  116. $addrs[] = $v['id'];
  117. }
  118. }
  119. //分页参数
  120. $length = input('rows', 10, 'intval'); //每页条数
  121. $page = input('page', 1, 'intval'); //第几页
  122. $start = ($page - 1) * $length; //分页开始位置
  123. //排序
  124. $sortRow = input('sidx', 'id', 'trim'); //排序列
  125. $sort = input('sord', 'desc', 'trim'); //排序方式
  126. $order = $sortRow . ' ' . $sort;
  127. $cateid = input('cateid', '', 'trim');
  128. if ($cateid) {
  129. $map[] = ['cateid', 'like', '%' . $cateid . '%'];
  130. }
  131. $start_time = input('start', '', 'trim');
  132. $end_time = input('end', '', 'trim');
  133. if ($start_time !== '' && $end_time !== '') {
  134. if ($start_time <= $end_time) {
  135. $start_time = date('Ymd', strtotime($start_time));
  136. $end_time = date('Ymd', strtotime($end_time));
  137. $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
  138. }
  139. }
  140. if ($start_time !== '' && $end_time == '') {
  141. $start_time = date('Ymd', strtotime($start_time));
  142. $map[] = ['create_yyyymmdd', '>=', $start_time];
  143. }
  144. if ($start_time == '' && $end_time !== '') {
  145. $end_time = date('Ymd', strtotime($end_time));
  146. $map[] = ['create_yyyymmdd', '<=', $end_time];
  147. }
  148. $status = input('status', '', 'trim');
  149. if ($status != '') {
  150. if ($status == 4) {
  151. $map[] = ['status', 'in', [0, 1]];
  152. }
  153. else {
  154. if (in_array($status, array(0, 1, 2, 3))) {
  155. $map[] = ['status', '=', $status];
  156. }
  157. }
  158. }
  159. $post = request()->post();
  160. if (!isset($post['status'])) {
  161. $map[] = ['status', 'in', [0, 1]];
  162. }
  163. $map[] = ['waste_device_id', 'in', $addrs];
  164. $map[] = ['del', '=', 0];
  165. $map[] = ['org_id', '=', $this->orgId];
  166. $map = empty($map) ? true : $map;
  167. //数据查询
  168. $lists = db($this->table)->where($map)
  169. ->limit($start, $length)
  170. ->order($order)->select();
  171. foreach ($lists as $k => $v) {
  172. $lists[$k]['waste_device'] = db('address')
  173. ->where('id', $v['waste_device_id'])
  174. ->value('title');
  175. $lists[$k]['real_name'] = db('user')
  176. ->where('id', $v['user_id'])
  177. ->value('real_name');
  178. $lists[$k]['cate'] = db('waste_type')
  179. ->where('id', $v['cateid'])
  180. ->value('title');
  181. // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
  182. $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
  183. $lists[$k]['status'] = $this->model->status[$v['status']];
  184. $type = Db::name('waste_type')
  185. ->where('id', $v['cateid'])
  186. ->find();
  187. $num = '';
  188. if($type['type'] == 1 && $v['num'] > 0){
  189. $num = ' ('.$v['num'].$type['unit'].')';
  190. }
  191. $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
  192. }
  193. //数据返回
  194. $totalCount = db($this->table)->where($map)->count();
  195. $totalPage = ceil($totalCount / $length);
  196. $result['page'] = $page;
  197. $result['total'] = $totalPage;
  198. $result['records'] = $totalCount;
  199. $result['rows'] = $lists;
  200. $types = (new \app\common\model\WasteType())->getList($this->orgId);
  201. $tname = '';
  202. foreach ($types as $k=>$v){
  203. $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
  204. $tname .= $v['title'].':'.round($weight/1000,2).'kg'.' ';
  205. if($v['type'] == 1){
  206. $num = db($this->table)->where($map)->where('cateid',$v['id'])->sum('num');
  207. $tname .= $v['title'].':'.round($weight/1000,2).'kg'.'('.$num.$v['unit'].' ) ';
  208. }
  209. // $types[$k]['weight'] = round($weight/1000,2);
  210. }
  211. $result['tnames'] = $tname;
  212. return json($result);
  213. }
  214. else {
  215. $type = (new \app\common\model\WasteType())->getList($this->orgId);
  216. $this->assign('m_name', '医废类型');
  217. $this->assign('type', $type);
  218. $this->assign('status', $this->model->status);
  219. return $this->fetch();
  220. }
  221. }
  222. // 所有科室医废
  223. public function index3() {
  224. if (request()->isAjax()) {
  225. //分页参数
  226. $length = input('rows', 10, 'intval'); //每页条数
  227. $page = input('page', 1, 'intval'); //第几页
  228. $start = ($page - 1) * $length; //分页开始位置
  229. //排序
  230. $sortRow = input('sidx', 'id', 'trim'); //排序列
  231. $sort = input('sord', 'desc', 'trim'); //排序方式
  232. $order = $sortRow . ' ' . $sort;
  233. $cateid = input('cateid', '', 'trim');
  234. if ($cateid) {
  235. $map[] = ['cateid', 'like', '%' . $cateid . '%'];
  236. }
  237. $start_time = input('start', '', 'trim');
  238. $end_time = input('end', '', 'trim');
  239. if ($start_time !== '' && $end_time !== '') {
  240. if ($start_time <= $end_time) {
  241. $start_time = date('Ymd', strtotime($start_time));
  242. $end_time = date('Ymd', strtotime($end_time));
  243. $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
  244. }
  245. }
  246. if ($start_time !== '' && $end_time == '') {
  247. $start_time = date('Ymd', strtotime($start_time));
  248. $map[] = ['create_yyyymmdd', '>=', $start_time];
  249. }
  250. if ($start_time == '' && $end_time !== '') {
  251. $end_time = date('Ymd', strtotime($end_time));
  252. $map[] = ['create_yyyymmdd', '<=', $end_time];
  253. }
  254. $status = input('status', '', 'trim');
  255. if ($status != '') {
  256. if ($status == 4) {
  257. $map[] = ['status', 'in', [0, 1]];
  258. }
  259. else {
  260. if (in_array($status, array(0, 1, 2, 3))) {
  261. $map[] = ['status', '=', $status];
  262. }
  263. }
  264. }
  265. $post = request()->post();
  266. if (!isset($post['status'])) {
  267. $map[] = ['status', 'in', [0, 1]];
  268. }
  269. $map[] = ['del', '=', 0];
  270. $map[] = ['org_id', '=', $this->orgId];
  271. $map = empty($map) ? true : $map;
  272. //数据查询
  273. $lists = db($this->table)->where($map)
  274. ->limit($start, $length)
  275. ->order($order)->select();
  276. foreach ($lists as $k => $v) {
  277. $lists[$k]['waste_device'] = db('address')
  278. ->where('id', $v['waste_device_id'])
  279. ->value('title');
  280. $lists[$k]['real_name'] = db('user')
  281. ->where('id', $v['user_id'])
  282. ->value('real_name');
  283. $lists[$k]['cate'] = db('waste_type')
  284. ->where('id', $v['cateid'])
  285. ->value('title');
  286. $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
  287. $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
  288. $lists[$k]['status'] = $this->model->status[$v['status']];
  289. $type = Db::name('waste_type')
  290. ->where('id', $v['cateid'])
  291. ->find();
  292. $num = '';
  293. if($type['type'] == 1 && $v['num'] > 0){
  294. $num = ' ('.$v['num'].$type['unit'].')';
  295. }
  296. $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
  297. }
  298. //数据返回
  299. $totalCount = db($this->table)->where($map)->count();
  300. $totalPage = ceil($totalCount / $length);
  301. $result['page'] = $page;
  302. $result['total'] = $totalPage;
  303. $result['records'] = $totalCount;
  304. $result['rows'] = $lists;
  305. // $weight = db($this->table)->where($map)->sum('weight');
  306. // $result['weight'] = round($weight/1000,2);
  307. $types = (new \app\common\model\WasteType())->getList($this->orgId);
  308. // foreach ($types as $k=>$v){
  309. // $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
  310. // $types[$k]['weight'] = round($weight/1000,2);
  311. // }
  312. $tname = '';
  313. foreach ($types as $k=>$v){
  314. $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
  315. $tname .= $v['title'].':'.round($weight/1000,2).'kg'.' ';
  316. if($v['type'] == 1){
  317. $num = db($this->table)->where($map)->where('cateid',$v['id'])->sum('num');
  318. $tname .= $v['title'].':'.round($weight/1000,2).'kg'.'('.$num.$v['unit'].' ) ';
  319. }
  320. // $types[$k]['weight'] = round($weight/1000,2);
  321. }
  322. $result['tnames'] = $tname;
  323. $result['types'] = $types;
  324. return json($result);
  325. }
  326. else {
  327. $type = (new \app\common\model\WasteType())->getList($this->orgId);
  328. $this->assign('m_name', '医废类型');
  329. $this->assign('type', $type);
  330. $this->assign('status', $this->model->status);
  331. return $this->fetch();
  332. }
  333. }
  334. public function add($id=0){
  335. if(request()->isPost()){
  336. $data = [
  337. 'org_id' => $this->orgId,
  338. 'user_id' => input('user_id/d',0),
  339. 'waste_device_id' => input('waste_device_id/d',0),
  340. 'cateid' =>input('cateid/d',0),
  341. 'weight' => input('weight',0),
  342. 'create_time' => input('create_time'),
  343. 'status' => 0,
  344. 'is_print' => 0,
  345. 'num'=>input('num',0)
  346. ];
  347. if(!$data['waste_device_id']){
  348. $this->error('未选择收取科室');
  349. }
  350. if(!$data['cateid']){
  351. $this->error('类型不能为空');
  352. }
  353. $type = Db::name('waste_type')->where('id',$data['cateid'])->find();
  354. if(!$type){
  355. $this->error('类型不存在');
  356. }
  357. if($type['type'] == 0 && $data['weight'] <= 0){
  358. $this->error('重量不能为空');
  359. }
  360. if($type['type'] == 1 && $data['num'] <= 0){
  361. HelpHander::error('数量不能为空');
  362. }
  363. if(!$data['create_time']){
  364. $this->error('未选择收取时间');
  365. }
  366. $waste_record_id = $this->model->saverecord($data);
  367. if(!$waste_record_id){
  368. HelpHander::error($this->model->getError());
  369. }
  370. $this->success('操作成功',url('index'));
  371. }else{
  372. $addrs = model("Address")->getListByType(7,$this->orgId);
  373. $this->assign('addrs', $addrs);
  374. $type = (new \app\common\model\WasteType())->getList($this->orgId);
  375. $this->assign('type', $type);
  376. $this->assign('user',(new User())->getWasteWorker());
  377. return $this->fetch();
  378. }
  379. }
  380. /**
  381. * 详情
  382. *
  383. * @author wst
  384. * @date 2021/9/8 17:29
  385. * @return array
  386. */
  387. public function info($id = 0) {
  388. $info = $this->model->info($id,cur_org_id());
  389. if (!$info) {
  390. $this->error('记录不存在');
  391. }
  392. $this->assign('info', $info);
  393. return $this->fetch();
  394. }
  395. /**
  396. * 转运
  397. *
  398. * @author wst
  399. * @date 2021/9/8 17:48
  400. * @param int $id
  401. * @return bool
  402. */
  403. public function finish($id) {
  404. $info = $this->model->getOne($id,cur_org_id());
  405. if (!$info) {
  406. $this->error('记录不存在');
  407. }
  408. if ($info['status'] != 1) {
  409. $this->error('处于已交接状态的才可转运');
  410. }
  411. $ret = $this->model->finish($id, is_login());
  412. $ret ? $this->success('转运成功') : $this->error($this->model->getError());
  413. }
  414. /**
  415. * 批量转运
  416. *
  417. * @author wst
  418. * @date 2021/9/8 17:48
  419. * @param array $ids
  420. * @return bool
  421. */
  422. public function batchFinish() {
  423. $ids = input('ids', [], 'trim');
  424. if (empty($ids)) {
  425. $this->error('未选择记录');
  426. }
  427. $success = 0;
  428. $error = '';
  429. foreach ($ids as $k => $v) {
  430. $info = $this->model->getOne($v,cur_org_id());
  431. if (!$info) {
  432. $error .= 'id='.$v . ':记录不存在';
  433. continue;
  434. }
  435. if ($info['status'] != 1) {
  436. $error .= '当前状态不可转运';
  437. continue;
  438. }
  439. $ret = $this->model->finish($v, is_login());
  440. if ($ret) {
  441. $success++;
  442. }
  443. else {
  444. $error .= 'id='.$v.':' . $this->model->getError();
  445. }
  446. }
  447. $success ? $this->success('成功转运' . $success . '条记录') : $this->error($error);
  448. }
  449. /**
  450. * 删除记录
  451. * @param int $id
  452. */
  453. public function del($id = 0) {
  454. if (!$id) {
  455. $this->error('参数错误');
  456. }
  457. $res = db($this->table)->where('id', $id)->update([
  458. 'del' => 1,
  459. 'del_user_id' => is_login(),
  460. 'del_datetime' => getTime(),
  461. ]);
  462. if ($res) {
  463. $this->success('删除成功');
  464. }
  465. else {
  466. $this->error('删除失败');
  467. }
  468. }
  469. //excel导出
  470. public function export() {
  471. $meta_title = '医废记录';
  472. if (request()->isGet()) {
  473. $cateid = input('cateid', '', 'trim');
  474. if ($cateid) {
  475. $map[] = ['cateid', 'like', '%' . $cateid . '%'];
  476. }
  477. $start_time = input('start', '', 'trim');
  478. $end_time = input('end', '', 'trim');
  479. if ($start_time !== '' && $end_time !== '') {
  480. if ($start_time <= $end_time) {
  481. $start_time = date('Ymd', strtotime($start_time));
  482. $end_time = date('Ymd', strtotime($end_time));
  483. $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
  484. }
  485. }
  486. if ($start_time !== '' && $end_time == '') {
  487. $start_time = date('Ymd', strtotime($start_time));
  488. $map[] = ['create_yyyymmdd', '>=', $start_time];
  489. }
  490. if ($start_time == '' && $end_time !== '') {
  491. $end_time = date('Ymd', strtotime($end_time));
  492. $map[] = ['create_yyyymmdd', '<=', $end_time];
  493. }
  494. $status = input('status', '', 'trim');
  495. if ($status != '') {
  496. if ($status == 4) {
  497. $map[] = ['status', 'in', [0, 1]];
  498. }
  499. else {
  500. if (in_array($status, array(0, 1, 2, 3))) {
  501. $map[] = ['status', '=', $status];
  502. }
  503. }
  504. }
  505. $map[] = ['del', '=', 0];
  506. $map[] = ['org_id', '=', $this->orgId];
  507. $map = empty($map) ? true : $map;
  508. //数据查询
  509. $lists = db($this->table)->where($map)->select();
  510. foreach ($lists as $k => $v) {
  511. $lists[$k]['waste_device'] = db('address')
  512. ->where('id', $v['waste_device_id'])
  513. ->value('title');
  514. $lists[$k]['real_name'] = db('user')
  515. ->where('id', $v['user_id'])
  516. ->value('real_name');
  517. $lists[$k]['cate'] = db('waste_type')
  518. ->where('id', $v['cateid'])
  519. ->value('title');
  520. // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
  521. $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
  522. $lists[$k]['status'] = $this->model->status[$v['status']];
  523. $type = Db::name('waste_type')
  524. ->where('id', $v['cateid'])
  525. ->find();
  526. $num = '';
  527. if($type['type'] == 1 && $v['num'] > 0){
  528. $num = ' ('.$v['num'].$type['unit'].')';
  529. }
  530. $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
  531. }
  532. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  533. //实例化PHPExcel类
  534. $objPHPExcel = new \PHPExcel();
  535. //激活当前的sheet表
  536. $objActSheet = $objPHPExcel->setActiveSheetIndex(0);
  537. //设置表格头(即excel表格的第一行)
  538. $objPHPExcel->setActiveSheetIndex(0)
  539. ->setCellValue('A1', '编号')
  540. ->setCellValue('B1', '收取地点')
  541. ->setCellValue('C1', '收取人')
  542. ->setCellValue('D1', '类别')
  543. ->setCellValue('E1', '重量(kg)')
  544. ->setCellValue('F1', '收取时间')
  545. ->setCellValue('G1', '状态')
  546. ->setCellValue('H1', '医废异常信息')
  547. ->setCellValue('I1', '是否签字')
  548. ->setCellValue('J1', '签名图');
  549. // 设置表格头水平居中
  550. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  551. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  552. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  553. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  554. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  555. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  556. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  557. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  558. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  559. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  560. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  561. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  562. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  563. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  564. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  565. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  566. //设置列水平居中
  567. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  568. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  569. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  570. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  571. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  572. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  573. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  574. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  575. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  576. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  577. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  578. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  579. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  580. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  581. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  582. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  583. //设置单元格宽度
  584. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  585. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  586. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  587. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  588. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  589. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  590. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  591. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  592. //循环刚取出来的数组,将数据逐一添加到excel表格。
  593. for ($i = 0; $i < count($lists); $i++) {
  594. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
  595. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['waste_device']);
  596. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
  597. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['cate']);
  598. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['weight']);
  599. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
  600. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['status']);
  601. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['reason']);
  602. $sign_text = '否';
  603. if($lists[$i]['sign'] == 1){
  604. $sign_text = '是';
  605. }
  606. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $sign_text);
  607. $signList = explode(".",$lists[$i]['sign_path']);
  608. if($signList){
  609. $ext = end($signList);
  610. $img ='';
  611. if ($ext == 'jpg' || $ext == 'jpeg'){
  612. $img = @imagecreatefromjpeg($lists[$i]['sign_path']);
  613. }
  614. if ($ext == 'png'){
  615. $img = @imagecreatefrompng($lists[$i]['sign_path']);
  616. }
  617. if($img){
  618. //实例化图片操作类
  619. $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
  620. $objDrawing->setImageResource($img);
  621. $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
  622. $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
  623. $objDrawing->setHeight(40);//照片高度
  624. $objDrawing->setWidth(40); //照片宽度
  625. $objDrawing->setCoordinates('J'.($i+2));//图片要插入的单元格
  626. $objDrawing->setOffsetX(8);//图片X轴偏移
  627. $objDrawing->setOffsetY(8);//图片Y轴偏移
  628. $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  629. //设置每一行高度
  630. }else{
  631. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), '');
  632. }
  633. }else{
  634. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), '');
  635. }
  636. $objActSheet->getRowDimension($i + 2)->setRowHeight(40); // 行高
  637. }
  638. //设置保存的Excel表格名称
  639. $filename = $meta_title.'_' . date('YmdHis', time()) . '.xls';
  640. //设置当前激活的sheet表格名称
  641. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  642. //设置浏览器窗口下载表格
  643. ob_end_clean();
  644. header("Content-Type: application/force-download");
  645. header("Content-Type: application/octet-stream");
  646. header("Content-Type: application/download");
  647. header('Content-Disposition:inline;filename="' . $filename);
  648. //生成excel文件
  649. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  650. //下载文件在浏览器窗口
  651. return $objWriter->save('php://output');
  652. }
  653. }
  654. public function allZy(){
  655. $ids = Db::name('waste_record')
  656. ->where('org_id',$this->orgId)
  657. ->where('del',0)
  658. ->where('status',1)
  659. ->column('id');
  660. if($ids){
  661. // 启动事务
  662. Db::startTrans();
  663. try {
  664. $ret = Db::name('waste_record')
  665. ->whereIn('id', $ids)
  666. ->update(['status'=>2]);
  667. if(!$ret){
  668. throw new Exception('更新状态失败');
  669. }
  670. foreach ($ids as $k=>$v){
  671. $ret2 = Db::name('waste_record_user')->insert(array(
  672. 'waste_record_id' => $v,
  673. 'user_id' => $this->userId,
  674. 'status' => 2,
  675. 'create_time' => getTime()
  676. ));
  677. if(!$ret2){
  678. throw new exception('保存操作记录失败');
  679. }
  680. }
  681. // 提交事务
  682. Db::commit();
  683. } catch (\Exception $e) {
  684. // 回滚事务
  685. Db::rollback();
  686. }
  687. $this->success('成功转运' . count($ids) . '条记录');
  688. }else{
  689. $this->success('成功转运');
  690. }
  691. }
  692. public function apply() {
  693. $id= input('id', '');
  694. if (empty($id)) {
  695. $this->error('未选择记录');
  696. }
  697. $info = $this->model->getOne($id,cur_org_id());
  698. $info['type'] = Db::name('waste_type')->where('id',$info['cateid'])->value('type');
  699. if (!$info) {
  700. $this->error('医废记录不存在');
  701. }
  702. if (request()->isPost()) {
  703. $data = request()->post();
  704. $check = Db::name('waste_apply')
  705. ->where('record_id',$id)
  706. ->where('del',0)
  707. ->where('status',0)
  708. ->find();
  709. if ($check) {
  710. $this->error('当前记录正在申请中');
  711. }
  712. $old = Db::name('waste_record')
  713. ->where('id',$info['id'])
  714. ->find();
  715. $key = ['user_id','cateid','weight','waste_device_id','num'];
  716. $su = 0;
  717. foreach ($key as $kk=>$vv){
  718. if($data[$vv]!=$old[$vv]){
  719. $su++;
  720. }
  721. }
  722. if($su==0){
  723. $this->error('当前数据未做修改');
  724. }
  725. $data['record_id'] = $data['id'];
  726. $data['org_id'] =$this->orgId;
  727. $data['create_time'] = getTime();
  728. unset($data['id']);
  729. $result = validate('WasteApply')->check($data,[],'');
  730. if(true !== $result){
  731. $this->error(validate('WasteApply')->getError());
  732. }
  733. $data['old_data'] = json_encode($old);
  734. $res = Db::name('waste_apply')->insertGetId($data);
  735. $res?$this->success('操作成功'):$this->error('操作失败');
  736. }else{
  737. $scan = Db::name('waste_scale')
  738. ->where('enable',1)
  739. ->where('del',0)
  740. ->where('org_id',cur_org_id())
  741. ->select();
  742. $uList = [];
  743. if(!empty($scan)){
  744. $uList = Db::name('user')
  745. ->where('del',0)
  746. ->where('id','in',array_column($scan,'user_id'))
  747. ->field('id,real_name as title')
  748. ->select();
  749. }
  750. $type = model('WasteType')->getList($this->orgId);
  751. $addr = model('Address')->getListByType(7,$this->orgId);
  752. $this->assign('addr', $addr);
  753. $this->assign('type', $type);
  754. $this->assign('uList',$uList);
  755. $this->assign('info',$info);
  756. $uInfo = Db::name('user')
  757. ->where('id',$this->userId)
  758. ->find();
  759. $this->assign('uInfo',$uInfo);
  760. return $this->fetch();
  761. }
  762. }
  763. public function wasteType(){
  764. $id = input('id');
  765. $info = Db::name('waste_type')->where('id',$id)->find();
  766. $this->success('操作成功','',$info);
  767. }
  768. }