MessageRecordApi.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\MessageRecord;
  4. class MessageRecordApi {
  5. public static function getList($params = []) {
  6. $where = [];
  7. $name = $params["name"];
  8. $phone = $params["phone"];
  9. $type = $params["type"];
  10. $state = $params["state"];
  11. $order = $params["order"] ?: "desc";
  12. $offset = $params["offset"] ?: 0;
  13. $limit = $params["limit"] ?: 10;
  14. if ($name) {
  15. $where[] = ["name", "like", "%{$name}%"];
  16. }
  17. if($phone){
  18. $where[] = ["phone", "like", "%{$phone}%"];
  19. }
  20. if($type){
  21. $where[] = ["type", "=", "{$type}"];
  22. }
  23. if($state){
  24. $where[] = ["type", "=", "{$state}"];
  25. }
  26. $count = MessageRecord::whereOr($where)->count();
  27. $list = MessageRecord::whereOr($where)
  28. ->order(["createTime" => $order])
  29. ->limit($offset, $limit)
  30. ->select()->toArray();
  31. return ["total" => $count, "rows" => $list];
  32. }
  33. }