IntegralItemApi.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\IntegralItem;
  4. class IntegralItemApi {
  5. public static function getOne($id) {
  6. return IntegralItem::findOrEmpty($id);
  7. }
  8. public static function getList($params) {
  9. $order = $params["order"] ?: "desc";
  10. $offset = $params["offset"] ?: 0;
  11. $limit = $params["limit"] ?: 10;
  12. $where[] = ["delete", "=", 0];
  13. if ($params["type"]) {
  14. $where[] = ["type", "=", $params["type"]];
  15. }
  16. if ($params["name"]) {
  17. $where[] = ["name", "like", "%{$params["name"]}%"];
  18. }
  19. if ($params["projectType"]) {
  20. $where[] = ["projectType", "=", $params["projectType"]];
  21. }
  22. if ($params["active"]) {
  23. $where[] = ["active", "=", $params["active"]];
  24. }
  25. $count = IntegralItem::where($where)->count();
  26. $list = IntegralItem::where($where)->limit($offset, $limit)->order("updateTime desc,createTime desc")->select()->toArray();
  27. return ["total" => $count, "rows" => $list];
  28. }
  29. public static function getAll() {
  30. $where[] = ["delete", "=", 0];
  31. $list = IntegralItem::where($where)->order("updateTime desc,createTime desc")->select()->toArray();
  32. return $list;
  33. }
  34. public static function edit($params) {
  35. $data["type"] = $params["type"];
  36. $data["name"] = $params["name"];
  37. $data["projectType"] = $params["projectType"];
  38. $data["active"] = $params["active"];
  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 IntegralItem::update($data);
  44. } else {
  45. $data["createTime"] = date("Y-m-d H:i:s");
  46. $data["createUser"] = session("user")["uid"];
  47. return IntegralItem::insert($data);
  48. }
  49. }
  50. public static function delete($id) {
  51. $data["id"] = $id;
  52. $data["delete"] = 1;
  53. $data["updateUser"] = session("user")["uid"];
  54. $data["updateTime"] = date("Y-m-d H:i:s");
  55. //同时删除子项
  56. $upd["delete"] = 1;
  57. $upd["updateTime"] = date("Y-m-d H:i:s");
  58. $upd["updateTime"] = session("user")["uid"];
  59. $where[] = ["projectId", "=", $id];
  60. \app\common\model\IntegralItem::where($where)->save($upd);
  61. return IntegralItem::update($data);
  62. }
  63. public static function chkExist($name, $type, $projectType, $id = 0) {
  64. $where = [];
  65. $where[] = ["type", "=", $params["type"]];
  66. $where[] = ["projectType", "=", $params["projectType"]];
  67. $where[] = ["name", "=", $params["name"]];
  68. $where[] = ["delete", "=", 0];
  69. if ($id) {
  70. $where[] = ["id", "<>", $id];
  71. }
  72. return IntegralItem::where($where)->find();
  73. }
  74. }