IntegralItemApi.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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::alias("i")->leftJoin("new_integral_project p", "p.id=i.projectId")->field("i.*,p.type,if(stepNeedAmount > 0,2,1) as plan")->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[] = ["i.delete", "=", 0];
  13. if ($params["type"]) {
  14. $where[] = ["p.type", "=", $params["type"]];
  15. }
  16. if ($params["name"]) {
  17. $where[] = ["i.name", "like", "%{$params["name"]}%"];
  18. }
  19. if ($params["projectType"]) {
  20. $where[] = ["p.projectType", "=", $params["projectType"]];
  21. }
  22. if ($params["active"]) {
  23. $where[] = ["i.active", "=", $params["active"]];
  24. }
  25. $count = IntegralItem::alias("i")->leftJoin("new_integral_project p", "p.id=i.projectId")->where($where)->count();
  26. $list = IntegralItem::alias("i")->leftJoin("new_integral_project p", "p.id=i.projectId")->where($where)
  27. ->field("i.*,p.type,p.name as projectName,p.projectType")
  28. ->limit($offset, $limit)->order("i.updateTime desc,i.createTime desc")->select()->toArray();
  29. return ["total" => $count, "rows" => $list];
  30. }
  31. public static function getAll($where = []) {
  32. $where[] = ["delete", "=", 0];
  33. $list = IntegralItem::where($where)->order("updateTime desc,createTime desc")->select()->toArray();
  34. return $list;
  35. }
  36. public static function edit($params) {
  37. $data["projectId"] = $params["projectId"];
  38. $data["name"] = $params["name"];
  39. $data["unit"] = $params["unit"];
  40. $data["fstNeedAmount"] = $params["fstNeedAmount"];
  41. $data["fstGainPoints"] = $params["fstGainPoints"];
  42. $data["fileTypeId"] = $params["fileTypeId"] ? implode(",", $params["fileTypeId"]) : null;
  43. $data["active"] = $params["active"];
  44. if ($params["plan"] == 2) {
  45. $data["stepNeedAmount"] = $params["stepNeedAmount"];
  46. $data["stepGainPoints"] = $params["stepGainPoints"];
  47. } else {
  48. $data["stepNeedAmount"] = 0;
  49. $data["stepGainPoints"] = 0;
  50. }
  51. if ($params["id"]) {
  52. $data["id"] = $params["id"];
  53. $data["updateTime"] = date("Y-m-d H:i:s");
  54. $data["updateUser"] = session("user")["uid"];
  55. return IntegralItem::update($data);
  56. } else {
  57. $data["createTime"] = date("Y-m-d H:i:s");
  58. $data["createUser"] = session("user")["uid"];
  59. return IntegralItem::insert($data);
  60. }
  61. }
  62. public static function delete($id) {
  63. $data["id"] = $id;
  64. $data["delete"] = 1;
  65. $data["updateUser"] = session("user")["uid"];
  66. $data["updateTime"] = date("Y-m-d H:i:s");
  67. return IntegralItem::update($data);
  68. }
  69. public static function chkExist($name, $projectId, $id = 0) {
  70. $where = [];
  71. $where[] = ["projectId", "=", $projectId];
  72. $where[] = ["name", "=", $name];
  73. $where[] = ["delete", "=", 0];
  74. if ($id) {
  75. $where[] = ["id", "<>", $id];
  76. }
  77. return IntegralItem::where($where)->find();
  78. }
  79. }