IntegralRecordApi.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\common\api;
  3. use app\common\api\DictApi;
  4. use app\admin\model\Enterprise;
  5. use think\facade\Db;
  6. use app\common\model\IntegralRecord;
  7. use app\common\state\IntegralState;
  8. /**
  9. * Description of IntegralRecordApi
  10. *
  11. * @author sgq
  12. */
  13. class IntegralRecordApi {
  14. public static function getOne($id) {
  15. $result = IntegralRecord::where("id", "=", $id)->find();
  16. if ($result) {
  17. $result["items"] = $result->detail;
  18. }
  19. return $result;
  20. }
  21. public static function getList($params) {
  22. $where = [];
  23. $order = $params["order"] ?: "desc";
  24. $offset = $params["offset"] ?: 0;
  25. $limit = $params["limit"] ?: 10;
  26. if (session("user")["usertype"] == 2) {
  27. $where[] = ["enterprise_id", "=", session("user")["uid"]];
  28. }
  29. $where[] = ["delete", "=", 0];
  30. $count = IntegralRecord::where($where)->count();
  31. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  32. foreach ($list as $key => $item) {
  33. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  34. $tmp_items = [];
  35. foreach ($item["detail"] as $_item) {
  36. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  37. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  38. }
  39. $list[$key]["details"] = implode(",", $tmp_items);
  40. $list[$key]["type"] = session("user")["type"];
  41. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  42. $list[$key]["real_state"] = $last_log["state"];
  43. $list[$key]["last_state"] = $last_log["last_state"];
  44. }
  45. return ["total" => $count, "rows" => $list];
  46. }
  47. public static function getListByProcess($params) {
  48. $process = $params["process"] ?: 1;
  49. $where = [];
  50. switch ($process) {
  51. case 1://初审阶段
  52. $where[] = ["checkState", "in", [IntegralState::SUBMIT]];
  53. break;
  54. case 2://复审阶段
  55. $where[] = ["checkState", "in", [IntegralState::VERIFY_PASS]];
  56. break;
  57. case 3://复审后征信公示等状态
  58. $where[] = ["checkState", "in", [IntegralState::REVERIFY_PASS, IntegralState::ZX_PASS, IntegralState::ZX_FAIL, IntegralState::ANNOUNCED, IntegralState::ANNOUNCED_REVERIFY_PASS, IntegralState::ANNOUNCED_REVERIFY_FAIL, IntegralState::PUBLISH_PASS, IntegralState::PUBLISH_FAIL, IntegralState::SUCCESS]];
  59. break;
  60. }
  61. $order = $params["order"] ?: "desc";
  62. $offset = $params["offset"] ?: 0;
  63. $limit = $params["limit"] ?: 10;
  64. $where[] = ["delete", "=", 0];
  65. $count = IntegralRecord::where($where)->count();
  66. $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
  67. foreach ($list as $key => $item) {
  68. $list[$key]["apply_year"] = BatchApi::getOne($item["batch_id"])["batch"];
  69. $tmp_items = [];
  70. foreach ($item["detail"] as $_item) {
  71. $integral_item_info = getCacheById("IntegralItem", $_item["item_id"]);
  72. $tmp_items[] = sprintf("%s(%s%s)", $integral_item_info["name"], $_item["amount"], $integral_item_info["unit"]);
  73. }
  74. $list[$key]["details"] = implode(",", $tmp_items);
  75. $list[$key]["type"] = session("user")["type"];
  76. $last_log = TalentLogApi::getLastLog($item["id"], \app\common\state\ProjectState::INTEGRAL);
  77. $list[$key]["real_state"] = $last_log["state"];
  78. $list[$key]["last_state"] = $last_log["last_state"];
  79. }
  80. return ["total" => $count, "rows" => $list];
  81. }
  82. public static function checkIsEditable($id) {
  83. $info = self::getOne($id);
  84. if (!$info || !in_array($info["checkState"], [0, IntegralState::SAVE]))
  85. return false;
  86. return true;
  87. }
  88. static public function chkIsOwner($id, $uid) {
  89. $info = self::getOne($id);
  90. if ($info["enterprise_id"] != $uid)
  91. return null;
  92. return $info;
  93. }
  94. }