IntegralRecordApi.php 4.5 KB

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