MLoginLog.Class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 日志模型
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/10/30
  7. * Time: 14:26
  8. */
  9. namespace JinDouYun\Model\Log;
  10. use Mall\Framework\Core\StatusCode;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Dao\Log\DLoginLog;
  14. class MLoginLog
  15. {
  16. private $objDLoginLog;
  17. private $enterpriseId;
  18. public function __construct($enterpriseId)
  19. {
  20. $this->enterpriseId = $enterpriseId;
  21. $this->objDLoginLog = new DLoginLog('log');
  22. //$this->objDLoginLog->setSearchIndex('login_log')->setType('login');
  23. }
  24. /**
  25. * 搜索条件 ES
  26. * @param $selectParams
  27. * @return array
  28. */
  29. public function setSearchWhere($selectParams = [])
  30. {
  31. $defaultDSL = [];
  32. if (isset($selectParams['offset'])) {
  33. $defaultDSL['from'] = $selectParams['offset'];
  34. }
  35. if (isset($selectParams['limit'])) {
  36. $defaultDSL['size'] = $selectParams['limit'];
  37. }
  38. $defaultDSL['sort'] =[
  39. 'createTime' => [
  40. 'order' => 'desc',
  41. 'unmapped_type' => 'long',
  42. ]
  43. ];
  44. $dsl = [];
  45. $dsl['query']['bool']['must'][] = [
  46. 'term' => ['enterpriseId' => $this->enterpriseId],
  47. ];
  48. $dsl = array_merge($defaultDSL, $dsl);
  49. return $dsl;
  50. }
  51. /**
  52. * @param array $selectParams 过滤条件
  53. * @return ResultWrapper
  54. * @throws Exception
  55. * @throws \Exception
  56. */
  57. public function getAllLoginLog($selectParams)
  58. {
  59. return ResultWrapper::success(['data'=>[],'total'=>0]);
  60. /*
  61. $dsl = $this->setSearchWhere($selectParams);
  62. $result = $this->objDLoginLog->getSearchQueryDsl($dsl);
  63. if (isset($result['status']) && $result['status'] == 400) {
  64. return ResultWrapper::success([
  65. 'data' => [],
  66. 'total' => 0
  67. ]);
  68. }
  69. if (!isset($result['hits']) || $result['hits']['total'] == 0) {
  70. return ResultWrapper::success([
  71. 'data' => [],
  72. 'total' => 0
  73. ]);
  74. }
  75. $total = $result['hits']['total'];
  76. $dbResult = $result['hits']['hits'];
  77. $list = [];
  78. foreach ($dbResult as $key => &$value) {
  79. $data = [];
  80. $data = $value['_source'];
  81. $data['id'] = $value['_id'];
  82. $list[] = $data;
  83. }
  84. $return = [
  85. 'data' => $list,
  86. 'total' => ($total) ? intval($total) : 0,
  87. ];
  88. return ResultWrapper::success($return);*/
  89. }
  90. }