TalentAllowanceApi.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\TalentAllowance as TaModel;
  4. use app\common\state\MainState;
  5. use think\facade\Db;
  6. use app\common\state\CommonConst;
  7. /**
  8. * Description of TalentAllowanceApi
  9. *
  10. * @author sgq
  11. */
  12. class TalentAllowanceApi {
  13. public static function getList($params) {
  14. $user = session("user");
  15. $order = trim($params["order"]) ?: "desc";
  16. $offset = trim($params["offset"]) ?: 0;
  17. $limit = trim($params["limit"]) ?: 10;
  18. $where = [];
  19. $where[] = ["enterpriseId", "=", $user["uid"]];
  20. if ($_where = self::setTalentAllowanceInfo($params)) {
  21. $where = array_merge($where, $_where);
  22. }
  23. $count = TaModel::where($where)->count();
  24. $list = TaModel::where($where)->limit($offset, $limit)->order("year " . $order)->select()->toArray();
  25. $levelList = DictApi::selectByParentCode("talent_arrange");
  26. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  27. $streetList = DictApi::selectByParentCode("street");
  28. $identifyConditionIds = array_filter(array_unique(array_column($list, "identifyCondition")));
  29. $whr[] = ["id", "in", $identifyConditionIds];
  30. $whr[] = ["type", "=", $user["type"]];
  31. $identifyConditionKvList = TalentConditionApi::getKvList($whr);
  32. foreach ($list as $key => $item) {
  33. $list[$key]["talentArrangeName"] = $levelList[$item["talentArrange"]];
  34. $list[$key]["talentTypeName"] = $talentTypeList[$item["talentType"]];
  35. $list[$key]["addressName"] = $streetList[$item["address"]];
  36. $list[$key]["identifyConditionText"] = $identifyConditionKvList[$item["identifyCondition"]];
  37. }
  38. return ["total" => $count, "rows" => $list];
  39. }
  40. public static function setTalentAllowanceInfo($params) {
  41. $where = [];
  42. if (\StrUtil::isNotEmpAndNull($params["year"])) {
  43. $where[] = ["year", "=", $params["year"]];
  44. }
  45. if (\StrUtil::isNotEmpAndNull($params["enterpriseName"])) {
  46. $where[] = ["enterpriseName", "like", "%" . $params["enterpriseName"] . "%"];
  47. }
  48. if (\StrUtil::isNotEmpAndNull($params["name"])) {
  49. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  50. }
  51. if (\StrUtil::isNotEmpAndNull($params["talentType"])) {
  52. $where[] = ["talentType", "=", $params["talentType"]];
  53. }
  54. if (\StrUtil::isNotEmpAndNull($params["talentArrange"])) {
  55. $where[] = ["talentArrange", "=", $params["talentArrange"]];
  56. }
  57. if (\StrUtil::isNotEmpAndNull($params["identiryCondition"])) {
  58. $where[] = ["identifyCondition", "=", $params["identifyCondition"]];
  59. }
  60. if (\StrUtil::isNotEmpAndNull($params["address"])) {
  61. $where[] = ["address", "=", $params["address"]];
  62. }
  63. return $where;
  64. }
  65. public static function getInfoById($id) {
  66. return TaModel::findOrEmpty($id)->toArray();
  67. }
  68. public static function getApplyCountByIdCard($idCard) {
  69. $where = [];
  70. $where[] = ["idCard", "=", $idCard];
  71. $where[] = ["checkState", "<>", MainState::NOTPASS];
  72. $list = TaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  73. $years = array_column($list, "year");
  74. return $years;
  75. }
  76. public static function getPassYearsByIdCard($idCard) {
  77. $where = [];
  78. $where[] = ["idCard", "=", $idCard];
  79. $where[] = ["checkState", "=", MainState::PASS];
  80. $list = TaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  81. $passYears = array_column($list, "year");
  82. return $passYears;
  83. }
  84. }