CommonFileApi.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\CommonFile;
  4. /**
  5. * Description of CommonFileApi
  6. *
  7. * @author sgq
  8. */
  9. class CommonFileApi {
  10. public static function getOne($id) {
  11. return CommonFile::findOrEmpty($id);
  12. }
  13. public static function getList($params) {
  14. $order = $params["order"] ?: "desc";
  15. $offset = $params["offset"] ?: 0;
  16. $limit = $params["limit"] ?: 10;
  17. $count = CommonFile::where($where)->count();
  18. $list = CommonFile::alias("c")->leftJoin("sys_user u", "c.createUser=u.id")->field("c.*,u.name as createUser")->where($where)->limit($offset, $limit)->order("updateTime desc,createTime desc")->select()->toArray();
  19. foreach ($list as $key => $item) {
  20. $list[$key]["url"] = getStoragePath($item["url"], true);
  21. }
  22. return ["total" => $count, "rows" => $list];
  23. }
  24. public static function getAll($where = []) {
  25. $list = CommonFile::where($where)->order("updateTime desc,createTime desc")->select()->toArray();
  26. return $list;
  27. }
  28. public static function edit($params) {
  29. $data["originalName"] = $params["originalName"];
  30. $data["url"] = $params["url"];
  31. $data["description"] = $params["description"];
  32. if ($params["id"]) {
  33. $data["id"] = $params["id"];
  34. $data["updateTime"] = date("Y-m-d H:i:s");
  35. $data["updateUser"] = session("user")["uid"];
  36. return CommonFile::update($data);
  37. } else {
  38. $data["id"] = getStringId();
  39. $data["createTime"] = date("Y-m-d H:i:s");
  40. $data["createUser"] = session("user")["uid"];
  41. return CommonFile::insert($data);
  42. }
  43. }
  44. public static function delete($id) {
  45. return CommonFile::where(["id" => $id])->delete();
  46. }
  47. }