IntegralItemApi.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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,if(i.updateTime is null,i.createTime,i.updateTime) as orderTime")
  28. ->limit($offset, $limit)->order("orderTime 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)->field("*,if(updateTime is null,createTime,updateTime) as orderTime")->order("orderTime 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. $data["limit"] = $params["limit"];
  53. if ($data["limit"] == 1) {
  54. $data["yearly"] = $params["yearly"];
  55. $data["max"] = $params["max"];
  56. } else {
  57. $data["yearly"] = 0;
  58. $data["max"] = 0;
  59. }
  60. if ($params["id"]) {
  61. $item = $model->find($params["id"]);
  62. $data["updateTime"] = date("Y-m-d H:i:s");
  63. $data["updateUser"] = session("user")["uid"];
  64. return $item->save($data);
  65. } else {
  66. $data["createTime"] = date("Y-m-d H:i:s");
  67. $data["createUser"] = session("user")["uid"];
  68. return $model->save($data);
  69. }
  70. }
  71. public static function delete($id) {
  72. $data["id"] = $id;
  73. $data["delete"] = 1;
  74. $data["updateUser"] = session("user")["uid"];
  75. $data["updateTime"] = date("Y-m-d H:i:s");
  76. return IntegralItem::update($data);
  77. }
  78. public static function chkExist($name, $projectId, $id = 0) {
  79. $where = [];
  80. $where[] = ["projectId", "=", $projectId];
  81. $where[] = ["name", "=", $name];
  82. $where[] = ["delete", "=", 0];
  83. if ($id) {
  84. $where[] = ["id", "<>", $id];
  85. }
  86. return IntegralItem::where($where)->find();
  87. }
  88. }