SysExport.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\model\sys;
  12. use app\dict\sys\ExportDict;
  13. use core\base\BaseModel;
  14. use think\db\Query;
  15. /**
  16. * 导出报表模型
  17. * Class SysExport
  18. * @package app\model\sys
  19. */
  20. class SysExport extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'sys_export';
  32. /**
  33. * 状态字段转化
  34. * @param $value
  35. * @param $data
  36. * @return mixed
  37. */
  38. public function getExportStatusNameAttr($value, $data)
  39. {
  40. if (empty($data['export_status']))
  41. return '';
  42. return ExportDict::getStatus()[$data['export_status']] ?? '';
  43. }
  44. /**
  45. * 关键字字段转化
  46. * @param $value
  47. * @param $data
  48. * @return mixed
  49. */
  50. public function getExportKeyNameAttr($value, $data)
  51. {
  52. if (empty($data['export_key']))
  53. return '';
  54. return ExportDict::getExportType()[$data['export_key']]['name'] ?? '';
  55. }
  56. /**
  57. * 主题关键字搜索器
  58. * @param Query $query
  59. * @param $value
  60. * @param $data
  61. */
  62. public function searchExportKeyAttr(Query $query, $value, $data)
  63. {
  64. if ($value) {
  65. $query->where('export_key', $value);
  66. }
  67. }
  68. /**
  69. * 导出状态搜索器
  70. * @param Query $query
  71. * @param $value
  72. * @param $data
  73. */
  74. public function searchExportStatusAttr(Query $query, $value, $data)
  75. {
  76. if ($value) {
  77. $query->where('export_status', $value);
  78. }
  79. }
  80. /**
  81. * 导出时间搜索器
  82. * @param $query
  83. * @param $value
  84. * @param $data
  85. */
  86. public function searchCreateTimeAttr($query, $value, $data)
  87. {
  88. $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
  89. $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
  90. if ($start_time > 0 && $end_time > 0) {
  91. $query->whereBetweenTime('create_time', $start_time, $end_time);
  92. } else if ($start_time > 0 && $end_time == 0) {
  93. $query->where([['create_time', '>=', $start_time]]);
  94. } else if ($start_time == 0 && $end_time > 0) {
  95. $query->where([['create_time', '<=', $end_time]]);
  96. }
  97. }
  98. }