MachineList.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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) || !isset($param['sist']) || !isset($param['mouth'])) {
  356. $this->error('参数错误');
  357. }
  358. $query = db('设备_维修记录')
  359. ->alias('a')
  360. ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
  361. ->where('a.使用部门', $param['sist'])
  362. ->where('a.报障时间', 'like', $param['mouth'] . '%')
  363. ->field('rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,a.报障时间,a.维修受理时间,a.修复时间,a.实际维修工时 as 故障维修工时,rtrim(a.验收情况) as 验收情况,
  364. rtrim(b.员工姓名) as 机长,rtrim(c1.员工姓名) as 维修姓名1,rtrim(c2.员工姓名) as 维修姓名2,rtrim(c3.员工姓名) as 维修姓名3,rtrim(c4.员工姓名) as 维修姓名4,
  365. rtrim(a.故障现象) as 故障现象,rtrim(a.处理方法) as 处理方法,rtrim(a.使用部门) as 使用部门,a.sys_id as 创建用户,a.sys_rq as 创建时间,a.mod_rq as 修改时间,a.UniqId');
  366. for($i=1;$i<=4;$i++){
  367. $tableNumber = 'c'.$i;
  368. $field = 'a.维修人员'.$i;
  369. $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
  370. }
  371. $list = $query->order('设备编号')->select();
  372. if (empty($list)) {
  373. $this->error('未找到数据');
  374. }else{
  375. $this->success('成功', $list);
  376. }
  377. }
  378. /**
  379. * 月度设备保养记录上方机台列表
  380. * @return void
  381. * @throws \think\db\exception\DataNotFoundException
  382. * @throws \think\db\exception\ModelNotFoundException
  383. * @throws \think\exception\DbException
  384. */
  385. public function MouthMaintainList()
  386. {
  387. if ($this->request->isGet() === false) {
  388. $this->error('请求错误');
  389. }
  390. $param = $this->request->param();
  391. if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
  392. $this->error('参数错误');
  393. }
  394. $fields = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
  395. a.保养工时,rtrim(b.员工姓名) as 执行机修,rtrim(c.员工姓名) as 执行机长,rtrim(a.保养备注) as 保养备注,d.员工姓名 as 验收人员,rtrim(a.验收情况) as 验收情况,
  396. rtrim(a.sys_id) as 创建用户,a.sys_rq as 创建时间,a.UniqId';
  397. $query = db('设备_保养记录')
  398. ->alias('a')
  399. ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
  400. ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
  401. ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
  402. ->field($fields)
  403. ->where('a.使用部门', $param['sist'])
  404. ->where('a.保养开始时间', 'like', $param['mouth'] . '%')
  405. ->order('a.设备编号');
  406. $list = $query->select();
  407. if (empty($list)) {
  408. $this->error('未找到数据');
  409. }else{
  410. $this->success('成功', $list);
  411. }
  412. }
  413. /**
  414. * 设备维修记录修改-》维修信息获取
  415. * @return void
  416. * @throws \think\db\exception\DataNotFoundException
  417. * @throws \think\db\exception\ModelNotFoundException
  418. * @throws \think\exception\DbException
  419. */
  420. public function MachineMaintenanceDetail()
  421. {
  422. if ($this->request->isGet() === false) {
  423. $this->error('请求错误');
  424. }
  425. $param = $this->request->param();
  426. if (empty($param) || !isset($param['UniqId'])) {
  427. $this->error('参数错误');
  428. }
  429. $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,a.报障时间,a.等配件时间,a.修复时间,rtrim(a.故障现象) as 故障现象,
  430. rtrim(a.报障人) as 机长,b.员工编号 as 机长姓名,rtrim(a.维修性质) as 维修性质,a.维修受理时间,a.修复时间,a.等配件时间,
  431. a.修复时间,a.维修人员1,a.维修人员2,a.维修人员3,a.维修人员4,c1.员工姓名 as 维修人员姓名1,c2.员工姓名 as 维修人员姓名2,c3.员工姓名 as 维修人员姓名3,c4.员工姓名 as 维修人员姓名4,
  432. rtrim(a.处理方法) as 原因分析及措施,a.实际维修工时,a.故障工时,rtrim(a.验收人) as 验收人,rtrim(a.验收情况) as 验收情况,a.UniqId';
  433. $query = db('设备_维修记录')
  434. ->alias('a')
  435. ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
  436. ->field($field)
  437. ->where('a.UniqId', $param['UniqId']);
  438. for($i=1;$i<=4;$i++){
  439. $tableNumber = 'c'.$i;
  440. $field = 'a.维修人员'.$i;
  441. $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
  442. }
  443. $list = $query->find();
  444. if (empty($list)) {
  445. $this->error('未找到数据');
  446. }else{
  447. $this->success('成功', $list);
  448. }
  449. }
  450. /**
  451. * 设备维修修改
  452. * @return void
  453. * @throws \think\Exception
  454. * @throws \think\db\exception\BindParamException
  455. * @throws \think\exception\PDOException
  456. */
  457. public function MachineMaintenanceUpdate()
  458. {
  459. if ($this->request->isPost() === false) {
  460. $this->error('请求错误');
  461. }
  462. $param = Request::instance()->post();
  463. if (empty($param) || !isset($param['UniqId'])) {
  464. $this->error('参数错误');
  465. }
  466. $data = $param;
  467. unset($data['UniqId']);
  468. $data['mod_rq'] = date('Y-m-d H:i:s');
  469. $sql = db('设备_维修记录')
  470. ->where('UniqId', $param['UniqId'])
  471. ->fetchSql(true)
  472. ->update($data);
  473. $res = db()->query($sql);
  474. if ($res !== false) {
  475. $this->success('修改成功');
  476. }else{
  477. $this->error('修改失败');
  478. }
  479. }
  480. /**
  481. * 设备维修记录添加
  482. * @return void
  483. * @throws \think\db\exception\BindParamException
  484. * @throws \think\exception\PDOException
  485. */
  486. public function MachineMaintenanceAdd()
  487. {
  488. if ($this->request->isPost() === false) {
  489. $this->error('请求错误');
  490. }
  491. $param = Request::instance()->post();
  492. if (empty($param)) {
  493. $this->error('参数错误');
  494. }
  495. $param['sys_rq'] = date('Y-m-d H:i:s');
  496. $param['mod_rq'] = '1900-01-01 00:00:00';
  497. $sql = db('设备_维修记录')
  498. ->fetchSql(true)
  499. ->insert($param);
  500. $res = db()->query($sql);
  501. if ($res !== false) {
  502. $this->success('添加成功');
  503. }else{
  504. $this->error('添加失败');
  505. }
  506. }
  507. /**
  508. * 设备保养记录修改信息获取
  509. * @return void
  510. * @throws \think\db\exception\DataNotFoundException
  511. * @throws \think\db\exception\ModelNotFoundException
  512. * @throws \think\exception\DbException
  513. */
  514. public function MachineMaintainDetail()
  515. {
  516. if ($this->request->isGet() === false) {
  517. $this->error('请求错误');
  518. }
  519. $param = $this->request->param();
  520. if (empty($param) || !isset($param['UniqId'])) {
  521. $this->error('参数错误');
  522. }
  523. $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
  524. a.保养工时,rtrim(a.执行机修) as 执行机修,b.员工编号 as 执行机修姓名,a.执行机长,c.员工姓名 as 执行机长姓名,rtrim(a.保养备注) as 保养备注,rtrim(a.验收人员) as 验收人员,
  525. d.员工姓名 as 验收人员姓名,rtrim(a.验收备注) as 验收备注,rtrim(a.验收情况) as 验收情况,a.UniqId';
  526. $query = db('设备_保养记录')
  527. ->alias('a')
  528. ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
  529. ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
  530. ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
  531. ->field($field)
  532. ->where('a.UniqId', $param['UniqId']);
  533. $list = $query->find();
  534. if (empty($list)) {
  535. $this->error('未找到数据');
  536. }else{
  537. $this->success('成功', $list);
  538. }
  539. }
  540. /**
  541. * 设备保养记录修改
  542. * @return void
  543. * @throws \think\Exception
  544. * @throws \think\db\exception\BindParamException
  545. * @throws \think\exception\PDOException
  546. */
  547. public function MachineMaintainUpdate()
  548. {
  549. if ($this->request->isPost() === false) {
  550. $this->error('请求错误');
  551. }
  552. $param = Request::instance()->post();
  553. if (empty($param) || !isset($param['UniqId'])) {
  554. $this->error('参数错误');
  555. }
  556. $data = $param;
  557. unset($data['UniqId']);
  558. $data['mod_rq'] = date('Y-m-d H:i:s');
  559. $sql = db('设备_保养记录')
  560. ->where('UniqId', $param['UniqId'])
  561. ->fetchSql(true)
  562. ->update($data);
  563. $res = db()->query($sql);
  564. if ($res !== false) {
  565. $this->success('修改成功');
  566. }else{
  567. $this->error('修改失败');
  568. }
  569. }
  570. /**
  571. * 设备保养记录新增
  572. * @return void
  573. * @throws \think\db\exception\BindParamException
  574. * @throws \think\exception\PDOException
  575. */
  576. public function MachineMaintainAdd()
  577. {
  578. if ($this->request->isPost() === false) {
  579. $this->error('请求错误');
  580. }
  581. $param = Request::instance()->post();
  582. if (empty($param)) {
  583. $this->error('参数错误');
  584. }
  585. $param['sys_rq'] = date('Y-m-d H:i:s');
  586. $param['mod_rq'] = '1900-01-01 00:00:00';
  587. $sql = db('设备_保养记录')
  588. ->fetchSql(true)
  589. ->insert($param);
  590. $res = db()->query($sql);
  591. if ($res !== false) {
  592. $this->success('添加成功');
  593. }else{
  594. $this->error('添加失败');
  595. }
  596. }
  597. /**
  598. * 设备保养维修记录删除
  599. * @return void
  600. * @throws \think\Exception
  601. * @throws \think\exception\PDOException
  602. */
  603. public function MachineMaintainDelete()
  604. {
  605. if ($this->request->isGet() === false) {
  606. $this->error('请求错误');
  607. }
  608. $param = $this->request->param();
  609. if (empty($param) || !isset($param['UniqId']) || !isset($param['type'])) {
  610. $this->error('参数错误');
  611. }
  612. if ($param['type'] == 0) {
  613. $table = '设备_维修记录';
  614. }else{
  615. $table = '设备_保养记录';
  616. }
  617. $res = db($table)->where('UniqId', $param['UniqId'])->delete();
  618. if ($res !== false) {
  619. $this->success('删除成功');
  620. }else{
  621. $this->error('删除失败');
  622. }
  623. }
  624. }