FaultCodeLists.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\fault_code;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\lists\ListsSearchInterface;
  17. use app\common\model\fault_code\FaultCode;
  18. use app\common\model\fault_type\FaultType;
  19. /**
  20. * FaultCode列表
  21. * Class FaultCodeLists
  22. * @package app\adminapi\lists
  23. */
  24. class FaultCodeLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2024/10/18 09:58
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '=' => ['status'],
  36. '%like%' => ['codes', 'name', 'detail'],
  37. ];
  38. }
  39. public function queryWhere()
  40. {
  41. $where = [];
  42. if (isset($this->params['type_id']) && $this->params['type_id'] !== '') {
  43. $pid = FaultType::where('id', $this->params['type_id'])->value('pid');
  44. if ($pid == 0) {
  45. $where[] = ['type_id', 'in', FaultType::where('pid', $this->params['type_id'])->column('id')];
  46. } else {
  47. $where[] = ['type_id', '=', $this->params['type_id']];
  48. }
  49. }
  50. return $where;
  51. }
  52. /**
  53. * @notes 获取列表
  54. * @return array
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @author likeadmin
  59. * @date 2024/10/18 09:58
  60. */
  61. public function lists(): array
  62. {
  63. return FaultCode::with(['faultType'])->where($this->searchWhere)
  64. ->where($this->queryWhere())
  65. ->field(['*'])
  66. ->limit($this->limitOffset, $this->limitLength)
  67. ->order(['id' => 'asc'])
  68. ->select()
  69. ->toArray();
  70. }
  71. /**
  72. * @notes 获取数量
  73. * @return int
  74. * @author likeadmin
  75. * @date 2024/10/18 09:58
  76. */
  77. public function count(): int
  78. {
  79. return FaultCode::where($this->searchWhere)->where($this->queryWhere())->count();
  80. }
  81. }