CompanyApi.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\Company;
  4. /**
  5. * Description of CompanyApi
  6. *
  7. * @author sgq
  8. */
  9. class CompanyApi {
  10. public static function getOne($id) {
  11. return Company::findOrEmpty($id)->toArray();
  12. }
  13. public static function getList($params) {
  14. $order = $params["order"] ?: "desc";
  15. $offset = $params["offset"] ?: 0;
  16. $limit = $params["limit"] ?: 10;
  17. $where[] = ["delete", "=", 0];
  18. if ($params["name"]) {
  19. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  20. }
  21. if ($params["code"]) {
  22. $where[] = ["code", "=", $params["code"]];
  23. }
  24. $count = Company::where($where)->count();
  25. $list = Company::where($where)->limit($offset, $limit)->order("sn " . $order)->select()->toArray();
  26. return ["total" => $count, "rows" => $list];
  27. }
  28. public static function getAll() {
  29. $where[] = ["delete", "=", 0];
  30. $list = Company::where($where)->order("sn asc")->select()->toArray();
  31. return $list;
  32. }
  33. public static function edit($params) {
  34. $data["name"] = $params["name"];
  35. $data["shortName"] = $params["shortName"];
  36. $data["code"] = $params["code"];
  37. $data["sn"] = $params["sn"];
  38. $data["description"] = $params["description"];
  39. if ($params["id"]) {
  40. $data["id"] = $params["id"];
  41. $data["updateTime"] = date("Y-m-d H:i:s");
  42. $data["updateUser"] = session("user")["uid"];
  43. return Company::update($data);
  44. } else {
  45. $data["id"] = getStringId();
  46. $data["createTime"] = date("Y-m-d H:i:s");
  47. $data["createUser"] = session("user")["uid"];
  48. return Company::insert($data);
  49. }
  50. }
  51. public static function delete($id) {
  52. $data["id"] = $id;
  53. $data["delete"] = 1;
  54. $data["updateUser"] = session("user")["uid"];
  55. $data["updateTime"] = date("Y-m-d H:i:s");
  56. return Company::update($data);
  57. }
  58. }