NoticeApi.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\common\api;
  3. use app\admin\model\Notice;
  4. /**
  5. * Description of NoticeApi
  6. *
  7. * @author sgq
  8. */
  9. class NoticeApi {
  10. public static function getList($params = []) {
  11. $where = [];
  12. $condition = $params["condition"];
  13. $order = $params["order"] ?: "desc";
  14. $offset = $params["offset"] ?: 0;
  15. $limit = $params["limit"] ?: 10;
  16. if ($condition) {
  17. $where[] = ["n.title", "like", "%{$condition}%"];
  18. $where[] = ["n.content", "like", "%{$condition}%"];
  19. }
  20. $count = Notice::alias("n")->whereOr($where)->count();
  21. $list = Notice::alias("n")->whereOr($where)
  22. ->leftJoin("sys_user u", "u.id=n.creater")
  23. ->leftJoin("sys_company c", "c.id=u.companyId")
  24. ->order(["n.isTop" => $order, "n.topTime" => $order, "n.createTime" => $order])
  25. ->limit($offset, $limit)
  26. ->field("n.*,concat(u.name,'(',c.name,')') as createrName")
  27. ->select()->toArray();
  28. return ["total" => $count, "rows" => $list];
  29. }
  30. }