MachineList.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. namespace app\api\controller;
  3. use think\Request;
  4. use app\common\controller\Api;
  5. use think\response\Json;
  6. use function fast\e;
  7. /**
  8. * 设备维修保养记录
  9. */
  10. class MachineList extends Api
  11. {
  12. protected $noNeedLogin = ['*'];
  13. protected $noNeedRight = ['*'];
  14. //设备维修保养记录左侧菜单
  15. public function getTab()
  16. {
  17. if ($this->request->isGet() === false){
  18. $this->error('请求错误');
  19. }
  20. $year = date('Y',time());
  21. $lastYear = date('Y', strtotime('-1 year'));
  22. //年度维修统计
  23. $yearResult1 = $this->getYearSite($year);
  24. $yearResult2 = $this->getYearSite($lastYear);
  25. $data['1、年度维修统计'] = [
  26. $year => $yearResult1,
  27. $lastYear => $yearResult2
  28. ];
  29. //月度维修记录
  30. $lastMouth = date('Y-m', strtotime('-1 year'));
  31. $mouthReault = $this->getMouthSite($lastMouth);
  32. $data['2、月度维修记录'] = $mouthReault;
  33. //年度保养记录
  34. $YearMaintenanceSist1 = $this->getYearMaintenanceSist($year);
  35. $YearMaintenanceSist2 = $this->getYearMaintenanceSist($lastYear);
  36. if (!empty($YearMaintenanceSist1)){
  37. $data['3、年度保养统计'][$year] = $YearMaintenanceSist1;
  38. }
  39. if (!empty($YearMaintenanceSist2)){
  40. $data['3、年度保养统计'][$lastYear] = $YearMaintenanceSist2;
  41. }
  42. //月度保养记录
  43. $mouthMaintenanceSist = $this->getMouthMaintenanceSist($lastMouth);
  44. $data['4、月度保养记录'] = $mouthMaintenanceSist;
  45. $this->success('成功',$data);
  46. }
  47. private function getYearSite($year)
  48. {
  49. $sist = db('设备_维修记录')
  50. ->where('报障时间','like',$year.'%')
  51. ->group('使用部门')
  52. ->column('rtrim(使用部门)');
  53. $data = [];
  54. if (!empty($sist)){
  55. foreach ($sist as $item){
  56. $count = db('设备_维修记录')
  57. ->where('使用部门',$item)
  58. ->where('报障时间','like',$year.'%')
  59. ->count();
  60. if ($count !== 0){
  61. $data[] = $item.'('.$count.'台次)';
  62. }
  63. }
  64. }
  65. return $data;
  66. }
  67. private function getMouthSite($mouth)
  68. {
  69. $mouth = db('设备_维修记录')
  70. ->where('报障时间','>',$mouth.'-01 00:00:00')
  71. ->where('报障时间','<',date('Y-m-d H:i:s',time()))
  72. ->group('date')
  73. ->order('date desc')
  74. ->column('DATE_FORMAT(报障时间, "%Y-%m") AS date');
  75. $data = [];
  76. foreach ($mouth as $item){
  77. $sist = db('设备_维修记录')
  78. ->where('报障时间','like',$item.'%')
  79. ->group('使用部门')
  80. ->column('rtrim(使用部门)');
  81. foreach ($sist as $value){
  82. $count = db('设备_维修记录')
  83. ->where('使用部门',$value)
  84. ->where('报障时间','like',$item.'%')
  85. ->count();
  86. $data[$item][] = $value.'('.$count.'台次)';
  87. }
  88. }
  89. return $data;
  90. }
  91. private function getYearMaintenanceSist($year)
  92. {
  93. $sist = db('设备_保养记录')
  94. ->where('保养开始时间','like',$year.'%')
  95. ->group('使用部门')
  96. ->column('rtrim(使用部门)');
  97. $data = [];
  98. if (!empty($sist)){
  99. foreach ($sist as $item){
  100. $count = db('设备_保养记录')
  101. ->where('使用部门',$item)
  102. ->where('保养开始时间','like',$year.'%')
  103. ->count();
  104. if ($count !== 0){
  105. $data[] = $item.'('.$count.'台次)';
  106. }
  107. }
  108. }
  109. return $data;
  110. }
  111. private function getMouthMaintenanceSist($mouth)
  112. {
  113. $mouth = db('设备_保养记录')
  114. ->where('保养开始时间','>',$mouth.'-01 00:00:00')
  115. ->where('保养开始时间','<',date('Y-m-d H:i:s',time()))
  116. ->group('date')
  117. ->order('date desc')
  118. ->column('DATE_FORMAT(保养开始时间, "%Y-%m") AS date');
  119. $data = [];
  120. foreach ($mouth as $item){
  121. $sist = db('设备_保养记录')
  122. ->where('保养开始时间','like',$item.'%')
  123. ->group('使用部门')
  124. ->column('rtrim(使用部门)');
  125. foreach ($sist as $value){
  126. $count = db('设备_保养记录')
  127. ->where('使用部门',$value)
  128. ->where('保养开始时间','like',$item.'%')
  129. ->count();
  130. $data[$item][] = $value.'('.$count.'台次)';
  131. }
  132. }
  133. return $data;
  134. }
  135. /**
  136. * 年度维修记录上方列表
  137. * @return Json|void
  138. */
  139. public function YearMaintenanceList()
  140. {
  141. // 验证请求方法
  142. if (!$this->request->isGet()) {
  143. $this->error('请求错误');
  144. }
  145. // 获取并验证参数
  146. $param = $this->request->param();
  147. if (empty($param) || !isset($param['sist']) || !isset($param['year'])) {
  148. $this->error('参数错误');
  149. }
  150. $department = $param['sist'];
  151. $year = $param['year'];
  152. try {
  153. // 获取该部门该年份的所有维修设备编号
  154. $machineQuery = db('设备_维修记录')
  155. ->where('使用部门', $department)
  156. ->where('报障时间', 'like', $year . '%')
  157. ->order('设备编号');
  158. $machines = $machineQuery->column('distinct(设备编号) as 设备编号');
  159. if (empty($machines)) {
  160. $this->success('成功', []);
  161. }
  162. // 预加载设备名称
  163. $machineNames = db('设备_基本资料')
  164. ->whereIn('设备编号', $machines)
  165. ->column('rtrim(设备名称) as 设备名称', '设备编号');
  166. $result = [];
  167. // 一次性获取所有维修记录
  168. $allRecords = db('设备_维修记录')
  169. ->where('使用部门', $department)
  170. ->where('报障时间', 'like', $year . '%')
  171. ->field([
  172. '设备编号',
  173. 'DATE_FORMAT(报障时间, "%m") AS month', // 直接提取月份数字
  174. 'COUNT(*) AS count'
  175. ])
  176. ->group('设备编号, DATE_FORMAT(报障时间, "%m")')
  177. ->select();
  178. // 按设备编号组织数据
  179. $recordsByMachine = [];
  180. foreach ($allRecords as $record) {
  181. $monthKey = $record['month']; // 直接使用月份数字作为键
  182. $recordsByMachine[$record['设备编号']][$monthKey] = $record['count'];
  183. }
  184. // 构建结果数组
  185. foreach ($machines as $machineId) {
  186. $monthData = [];
  187. $total = 0;
  188. if (isset($recordsByMachine[$machineId])) {
  189. foreach ($recordsByMachine[$machineId] as $month => $count) {
  190. $monthData[$month] = $count; // 保持月份键为字符串
  191. $total += $count;
  192. }
  193. }
  194. // 确保月份键是两位数格式
  195. $formattedMonthData = [];
  196. foreach ($monthData as $month => $count) {
  197. $formattedMonth = str_pad($month, 2, '0', STR_PAD_LEFT);
  198. $formattedMonthData[$formattedMonth] = $count;
  199. }
  200. $result[] = [
  201. '使用部门' => $department,
  202. '设备编号' => $machineId,
  203. '设备名称' => $machineNames[$machineId] ?? '未知设备',
  204. 'total' => $total
  205. ] + $formattedMonthData;
  206. }
  207. return json([
  208. 'code' => 0,
  209. 'msg' => '成功',
  210. 'time' =>time(),
  211. 'data' => $result
  212. ]);
  213. } catch (\Exception $e) {
  214. $this->error('查询失败: ' . $e->getMessage());
  215. }
  216. }
  217. /**
  218. * 设备维修记录配件详情
  219. * @return void
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\ModelNotFoundException
  222. * @throws \think\exception\DbException
  223. */
  224. public function YearAccessoriesList()
  225. {
  226. if ($this->request->isGet() === false) {
  227. $this->error('请求错误');
  228. }
  229. $param = $this->request->param();
  230. if (empty($param) || !isset($param['machine']) || !isset($param['year']) || !isset($param['sist'])) {
  231. $this->error('参数错误');
  232. }
  233. $where = [];
  234. if (isset($param['type']) && $param['type'] == '修理') {
  235. $where['st_jylb'] =['like','修理领用%'];
  236. }
  237. $list = db('物料_收发记录')
  238. ->alias('a')
  239. ->join('物料_仓库信息 b', 'a.仓库编号 = b.编号','left')
  240. ->join('设备_基本资料 c', 'a.st_jtbh = c.设备编号','left')
  241. ->join('物料_存货编码 d', 'a.st_wlbh = d.物料代码')
  242. ->where('a.st_jtbh',$param['machine'])
  243. ->where('a.st_rq','like',$param['year'].'%')
  244. ->where(function ($query) {
  245. $query->where('a.仓库编号', '107')
  246. ->whereOr('a.仓库编号', 'Y107');
  247. })
  248. ->where($where)
  249. ->field(['DATE_FORMAT(a.st_rq, "%y-%m-%d") AS 日期','rtrim(a.st_jylb) as 交易类别','a.st_jtbh AS 机台编号','rtrim(a.仓库编号) as 仓库编号',
  250. 'rtrim(b.名称) as 仓库名称','rtrim(c.使用部门) as 领用部门','a.st_wlbh as 物料编号','rtrim(d.物料名称) as 物料名称','a.st_sl as 领用数量',
  251. 'rtrim(a.st_dw) as 领用单位','a.领用单价','a.st_sl*a.领用单价 as 金额','a.st_desc as 备注'])
  252. ->order('日期 DESC')
  253. ->select();
  254. if (empty($list)) {
  255. $this->error('未找到数据');
  256. }else{
  257. $this->success('成功', $list);
  258. }
  259. }
  260. /**
  261. * 年度保养统计上方几台列表
  262. * @return Json|void
  263. */
  264. public function YearMaintainList()
  265. {
  266. // 验证请求方法
  267. if (!$this->request->isGet()) {
  268. $this->error('请求错误');
  269. }
  270. // 获取并验证参数
  271. $param = $this->request->param();
  272. if (empty($param) || !isset($param['sist']) || !isset($param['year'])) {
  273. $this->error('参数错误');
  274. }
  275. $department = $param['sist'];
  276. $year = $param['year'];
  277. try {
  278. // 获取该部门该年份的所有维修设备编号
  279. $machineQuery = db('设备_保养记录')
  280. ->where('使用部门', $department)
  281. ->where('保养开始时间', 'like', $year . '%')
  282. ->order('设备编号');
  283. $machines = $machineQuery->column('distinct(设备编号) as 设备编号');
  284. if (empty($machines)) {
  285. $this->success('成功', []);
  286. }
  287. // 预加载设备名称
  288. $machineNames = db('设备_基本资料')
  289. ->whereIn('设备编号', $machines)
  290. ->column('rtrim(设备名称) as 设备名称', '设备编号');
  291. $result = [];
  292. // 一次性获取所有维修记录
  293. $allRecords = db('设备_保养记录')
  294. ->where('使用部门', $department)
  295. ->where('保养开始时间', 'like', $year . '%')
  296. ->field([
  297. '设备编号',
  298. 'DATE_FORMAT(保养开始时间, "%m") AS month', // 直接提取月份数字
  299. 'COUNT(*) AS count'
  300. ])
  301. ->group('设备编号, DATE_FORMAT(保养开始时间, "%m")')
  302. ->select();
  303. // 按设备编号组织数据
  304. $recordsByMachine = [];
  305. foreach ($allRecords as $record) {
  306. $monthKey = $record['month']; // 直接使用月份数字作为键
  307. $recordsByMachine[$record['设备编号']][$monthKey] = $record['count'];
  308. }
  309. // 构建结果数组
  310. foreach ($machines as $machineId) {
  311. $monthData = [];
  312. $total = 0;
  313. if (isset($recordsByMachine[$machineId])) {
  314. foreach ($recordsByMachine[$machineId] as $month => $count) {
  315. $monthData[$month] = $count; // 保持月份键为字符串
  316. $total += $count;
  317. }
  318. }
  319. // 确保月份键是两位数格式
  320. $formattedMonthData = [];
  321. foreach ($monthData as $month => $count) {
  322. $formattedMonth = str_pad($month, 2, '0', STR_PAD_LEFT);
  323. $formattedMonthData[$formattedMonth] = $count;
  324. }
  325. $result[] = [
  326. '使用部门' => $department,
  327. '设备编号' => $machineId,
  328. '设备名称' => $machineNames[$machineId] ?? '未知设备',
  329. 'total' => $total
  330. ] + $formattedMonthData;
  331. }
  332. return json([
  333. 'code' => 0,
  334. 'msg' => '成功',
  335. 'time' =>time(),
  336. 'data' => $result
  337. ]);
  338. } catch (\Exception $e) {
  339. $this->error('查询失败: ' . $e->getMessage());
  340. }
  341. }
  342. /**
  343. * 月度设备维修记录上方机台列表
  344. * @return void
  345. * @throws \think\db\exception\DataNotFoundException
  346. * @throws \think\db\exception\ModelNotFoundException
  347. * @throws \think\exception\DbException
  348. */
  349. public function MonthAccessoriesList()
  350. {
  351. if ($this->request->isGet() === false) {
  352. $this->error('请求错误');
  353. }
  354. $param = $this->request->param();
  355. if (empty($param)) {
  356. $this->error('参数错误');
  357. }
  358. $where = [];
  359. if (isset($param['mouth'])) {
  360. $where['a.报障时间'] = ['like', $param['mouth'] . '%'];
  361. }
  362. if (isset($param['sist'])) {
  363. $where['a.使用部门'] = $param['sist'];
  364. }
  365. if (isset($param['search'])) {
  366. $where['a.故障现象'] = ['like','%'.$param['search'].'%'];
  367. }
  368. $query = db('设备_维修记录')
  369. ->alias('a')
  370. ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
  371. ->field('rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,a.报障时间,a.维修受理时间,a.修复时间,a.实际维修工时 as 故障维修工时,rtrim(a.验收情况) as 验收情况,
  372. rtrim(b.员工姓名) as 机长,rtrim(c1.员工姓名) as 维修姓名1,rtrim(c2.员工姓名) as 维修姓名2,rtrim(c3.员工姓名) as 维修姓名3,rtrim(c4.员工姓名) as 维修姓名4,
  373. rtrim(a.故障现象) as 故障现象,rtrim(a.处理方法) as 处理方法,rtrim(a.使用部门) as 使用部门,a.sys_id as 创建用户,a.sys_rq as 创建时间,a.mod_rq as 修改时间,a.UniqId');
  374. for($i=1;$i<=4;$i++){
  375. $tableNumber = 'c'.$i;
  376. $field = 'a.维修人员'.$i;
  377. $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
  378. }
  379. $list = $query->where($where)->order('设备编号')->select();
  380. if (empty($list)) {
  381. $this->error('未找到数据');
  382. }else{
  383. $this->success('成功', $list);
  384. }
  385. }
  386. /**
  387. * 月度设备保养记录上方机台列表
  388. * @return void
  389. * @throws \think\db\exception\DataNotFoundException
  390. * @throws \think\db\exception\ModelNotFoundException
  391. * @throws \think\exception\DbException
  392. */
  393. public function MouthMaintainList()
  394. {
  395. if ($this->request->isGet() === false) {
  396. $this->error('请求错误');
  397. }
  398. $param = $this->request->param();
  399. if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
  400. $this->error('参数错误');
  401. }
  402. $fields = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
  403. a.保养工时,rtrim(b.员工姓名) as 执行机修,rtrim(c.员工姓名) as 执行机长,rtrim(a.保养备注) as 保养备注,d.员工姓名 as 验收人员,rtrim(a.验收情况) as 验收情况,
  404. rtrim(a.sys_id) as 创建用户,a.sys_rq as 创建时间,a.UniqId';
  405. $query = db('设备_保养记录')
  406. ->alias('a')
  407. ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
  408. ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
  409. ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
  410. ->field($fields)
  411. ->where('a.使用部门', $param['sist'])
  412. ->where('a.保养开始时间', 'like', $param['mouth'] . '%')
  413. ->order('a.设备编号');
  414. $list = $query->select();
  415. if (empty($list)) {
  416. $this->error('未找到数据');
  417. }else{
  418. $this->success('成功', $list);
  419. }
  420. }
  421. /**
  422. * 设备维修记录修改-》维修信息获取
  423. * @return void
  424. * @throws \think\db\exception\DataNotFoundException
  425. * @throws \think\db\exception\ModelNotFoundException
  426. * @throws \think\exception\DbException
  427. */
  428. public function MachineMaintenanceDetail()
  429. {
  430. if ($this->request->isGet() === false) {
  431. $this->error('请求错误');
  432. }
  433. $param = $this->request->param();
  434. if (empty($param) || !isset($param['UniqId'])) {
  435. $this->error('参数错误');
  436. }
  437. $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,a.报障时间,a.等配件时间,a.修复时间,rtrim(a.故障现象) as 故障现象,
  438. rtrim(a.报障人) as 机长,b.员工编号 as 机长姓名,rtrim(a.维修性质) as 维修性质,a.维修受理时间,a.修复时间,a.等配件时间,
  439. a.修复时间,a.维修人员1,a.维修人员2,a.维修人员3,a.维修人员4,c1.员工姓名 as 维修人员姓名1,c2.员工姓名 as 维修人员姓名2,c3.员工姓名 as 维修人员姓名3,c4.员工姓名 as 维修人员姓名4,
  440. rtrim(a.处理方法) as 原因分析及措施,a.实际维修工时,a.故障工时,rtrim(a.验收人) as 验收人,rtrim(a.验收情况) as 验收情况,a.UniqId';
  441. $query = db('设备_维修记录')
  442. ->alias('a')
  443. ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
  444. ->field($field)
  445. ->where('a.UniqId', $param['UniqId']);
  446. for($i=1;$i<=4;$i++){
  447. $tableNumber = 'c'.$i;
  448. $field = 'a.维修人员'.$i;
  449. $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
  450. }
  451. $list = $query->find();
  452. if (empty($list)) {
  453. $this->error('未找到数据');
  454. }else{
  455. $this->success('成功', $list);
  456. }
  457. }
  458. /**
  459. * 设备维修修改
  460. * @return void
  461. * @throws \think\Exception
  462. * @throws \think\db\exception\BindParamException
  463. * @throws \think\exception\PDOException
  464. */
  465. public function MachineMaintenanceUpdate()
  466. {
  467. if ($this->request->isPost() === false) {
  468. $this->error('请求错误');
  469. }
  470. $param = Request::instance()->post();
  471. if (empty($param) || !isset($param['UniqId'])) {
  472. $this->error('参数错误');
  473. }
  474. $data = $param;
  475. unset($data['UniqId']);
  476. $data['mod_rq'] = date('Y-m-d H:i:s');
  477. $sql = db('设备_维修记录')
  478. ->where('UniqId', $param['UniqId'])
  479. ->fetchSql(true)
  480. ->update($data);
  481. $res = db()->query($sql);
  482. if ($res !== false) {
  483. $this->success('修改成功');
  484. }else{
  485. $this->error('修改失败');
  486. }
  487. }
  488. /**
  489. * 设备维修记录添加
  490. * @return void
  491. * @throws \think\db\exception\BindParamException
  492. * @throws \think\exception\PDOException
  493. */
  494. public function MachineMaintenanceAdd()
  495. {
  496. if ($this->request->isPost() === false) {
  497. $this->error('请求错误');
  498. }
  499. $param = Request::instance()->post();
  500. if (empty($param)) {
  501. $this->error('参数错误');
  502. }
  503. $param['sys_rq'] = date('Y-m-d H:i:s');
  504. $param['mod_rq'] = '1900-01-01 00:00:00';
  505. $sql = db('设备_维修记录')
  506. ->fetchSql(true)
  507. ->insert($param);
  508. $res = db()->query($sql);
  509. if ($res !== false) {
  510. $this->success('添加成功');
  511. }else{
  512. $this->error('添加失败');
  513. }
  514. }
  515. /**
  516. * 设备保养记录修改信息获取
  517. * @return void
  518. * @throws \think\db\exception\DataNotFoundException
  519. * @throws \think\db\exception\ModelNotFoundException
  520. * @throws \think\exception\DbException
  521. */
  522. public function MachineMaintainDetail()
  523. {
  524. if ($this->request->isGet() === false) {
  525. $this->error('请求错误');
  526. }
  527. $param = $this->request->param();
  528. if (empty($param) || !isset($param['UniqId'])) {
  529. $this->error('参数错误');
  530. }
  531. $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
  532. a.保养工时,rtrim(a.执行机修) as 执行机修,b.员工编号 as 执行机修姓名,a.执行机长,c.员工姓名 as 执行机长姓名,rtrim(a.保养备注) as 保养备注,rtrim(a.验收人员) as 验收人员,
  533. d.员工姓名 as 验收人员姓名,rtrim(a.验收备注) as 验收备注,rtrim(a.验收情况) as 验收情况,a.UniqId';
  534. $query = db('设备_保养记录')
  535. ->alias('a')
  536. ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
  537. ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
  538. ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
  539. ->field($field)
  540. ->where('a.UniqId', $param['UniqId']);
  541. $list = $query->find();
  542. if (empty($list)) {
  543. $this->error('未找到数据');
  544. }else{
  545. $this->success('成功', $list);
  546. }
  547. }
  548. /**
  549. * 设备保养记录修改
  550. * @return void
  551. * @throws \think\Exception
  552. * @throws \think\db\exception\BindParamException
  553. * @throws \think\exception\PDOException
  554. */
  555. public function MachineMaintainUpdate()
  556. {
  557. if ($this->request->isPost() === false) {
  558. $this->error('请求错误');
  559. }
  560. $param = Request::instance()->post();
  561. if (empty($param) || !isset($param['UniqId'])) {
  562. $this->error('参数错误');
  563. }
  564. $data = $param;
  565. unset($data['UniqId']);
  566. $data['mod_rq'] = date('Y-m-d H:i:s');
  567. $sql = db('设备_保养记录')
  568. ->where('UniqId', $param['UniqId'])
  569. ->fetchSql(true)
  570. ->update($data);
  571. $res = db()->query($sql);
  572. if ($res !== false) {
  573. $this->success('修改成功');
  574. }else{
  575. $this->error('修改失败');
  576. }
  577. }
  578. /**
  579. * 设备保养记录新增
  580. * @return void
  581. * @throws \think\db\exception\BindParamException
  582. * @throws \think\exception\PDOException
  583. */
  584. public function MachineMaintainAdd()
  585. {
  586. if ($this->request->isPost() === false) {
  587. $this->error('请求错误');
  588. }
  589. $param = Request::instance()->post();
  590. if (empty($param)) {
  591. $this->error('参数错误');
  592. }
  593. $param['sys_rq'] = date('Y-m-d H:i:s');
  594. $param['mod_rq'] = '1900-01-01 00:00:00';
  595. $sql = db('设备_保养记录')
  596. ->fetchSql(true)
  597. ->insert($param);
  598. $res = db()->query($sql);
  599. if ($res !== false) {
  600. $this->success('添加成功');
  601. }else{
  602. $this->error('添加失败');
  603. }
  604. }
  605. /**
  606. * 设备保养维修记录删除
  607. * @return void
  608. * @throws \think\Exception
  609. * @throws \think\exception\PDOException
  610. */
  611. public function MachineMaintainDelete()
  612. {
  613. if ($this->request->isGet() === false) {
  614. $this->error('请求错误');
  615. }
  616. $param = $this->request->param();
  617. if (empty($param) || !isset($param['UniqId']) || !isset($param['type'])) {
  618. $this->error('参数错误');
  619. }
  620. if ($param['type'] == 0) {
  621. $table = '设备_维修记录';
  622. }else{
  623. $table = '设备_保养记录';
  624. }
  625. $res = db($table)->where('UniqId', $param['UniqId'])->delete();
  626. if ($res !== false) {
  627. $this->success('删除成功');
  628. }else{
  629. $this->error('删除失败');
  630. }
  631. }
  632. }