IntegralItemApi.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $model = new IntegralItem();
  38. $data["projectId"] = $params["projectId"];
  39. $data["name"] = $params["name"];
  40. $data["unit"] = $params["unit"];
  41. $data["fstNeedAmount"] = $params["fstNeedAmount"];
  42. $data["fstGainPoints"] = $params["fstGainPoints"];
  43. $data["fileTypeId"] = $params["fileTypeId"] ? implode(",", $params["fileTypeId"]) : null;
  44. $data["active"] = $params["active"];
  45. if ($params["plan"] == 2) {
  46. $data["stepNeedAmount"] = $params["stepNeedAmount"];
  47. $data["stepGainPoints"] = $params["stepGainPoints"];
  48. } else {
  49. $data["stepNeedAmount"] = 0;
  50. $data["stepGainPoints"] = 0;
  51. }
  52. if ($params["id"]) {
  53. $item = $model->find($params["id"]);
  54. $data["updateTime"] = date("Y-m-d H:i:s");
  55. $data["updateUser"] = session("user")["uid"];
  56. return $item->save($data);
  57. } else {
  58. $data["createTime"] = date("Y-m-d H:i:s");
  59. $data["createUser"] = session("user")["uid"];
  60. return $model->save($data);
  61. }
  62. }
  63. public static function delete($id) {
  64. $data["id"] = $id;
  65. $data["delete"] = 1;
  66. $data["updateUser"] = session("user")["uid"];
  67. $data["updateTime"] = date("Y-m-d H:i:s");
  68. return IntegralItem::update($data);
  69. }
  70. public static function chkExist($name, $projectId, $id = 0) {
  71. $where = [];
  72. $where[] = ["projectId", "=", $projectId];
  73. $where[] = ["name", "=", $name];
  74. $where[] = ["delete", "=", 0];
  75. if ($id) {
  76. $where[] = ["id", "<>", $id];
  77. }
  78. return IntegralItem::where($where)->find();
  79. }
  80. }