LivingAllowanceApi.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\LivingAllowance as LaModel;
  4. use app\common\state\LivingAllowanceState as LaState;
  5. use think\facade\Db;
  6. use app\common\state\CommonConst;
  7. /**
  8. * Description of LivingAllowanceApi
  9. *
  10. * @author sgq
  11. */
  12. class LivingAllowanceApi {
  13. public static function getList($params) {
  14. $order = trim($params["order"]) ?: "desc";
  15. $offset = trim($params["offset"]) ?: 0;
  16. $limit = trim($params["limit"]) ?: 10;
  17. $where = [];
  18. if ($_where = self::setLivingAllowanceCheckStateCondition($params)) {
  19. $where = array_merge($where, $_where);
  20. }
  21. if ($_where = self::getWhereByParams($params)) {
  22. $where = array_merge($where, $_where);
  23. }
  24. $type = session("user")["type"];
  25. if ($type == CommonConst::ENTERPRISE_NORMAL) {
  26. $where[] = ["type", "in", [CommonConst::ENTERPRISE_NORMAL, CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]];
  27. } else if ($type == CommonConst::ENTERPRISE_JC) {
  28. $where[] = ["type", "=", $type];
  29. } else {
  30. $where[] = ["type", "=", "you have no power"];
  31. }
  32. $count = laModel::where($where)->count();
  33. $list = laModel::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  34. $masterTypes = DictApi::selectByParentCode("un_master_education"); //申报对象类型
  35. $degrees = DictApi::selectByParentCode("highest_degree"); //最高学历
  36. foreach ($list as $key => $item) {
  37. $list[$key]["declareTypeName"] = $masterTypes[$item["declareType"]];
  38. $list[$key]["highEducation"] = $degrees[$item["highEducation"]];
  39. }
  40. return ["total" => $count, "rows" => $list];
  41. }
  42. public static function setLivingAllowanceCheckStateCondition($params) {
  43. $where = [];
  44. $checkState = $params["checkState"];
  45. $process = $params["process"];
  46. if ($checkState) {
  47. switch ($process) {
  48. case -1:
  49. if ($checkState == 7) {
  50. $where[] = ["checkState", ">=", $checkState];
  51. } else {
  52. $where[] = ["checkState", "=", $checkState];
  53. }
  54. break;
  55. case 1:
  56. if ($checkState == LaState::LA_NEED_DEP_CHECK) {
  57. $where[] = ["checkState", "in", [15, 25, 30, 35]];
  58. } else if ($checkState == 5) {
  59. $where[] = ["checkState", "=", LaState::LA_NEED_FIRST_CHECK];
  60. $where[] = ["highProcess", ">=", 1];
  61. } else if ($checkState == LaState::LA_NEED_FIRST_CHECK) {
  62. $where[] = ["checkState", "=", LaState::LA_NEED_FIRST_CHECK];
  63. $where[] = ["highProcess", "<", 1];
  64. } else {
  65. $where[] = ["checkState", "=", $checkState];
  66. }
  67. break;
  68. case 2:
  69. if ($checkState == LaState::LA_BEFORE_REJECT) {
  70. $where[] = ["checkState", "=", 15];
  71. $where[] = ["highProcess", ">=", 2];
  72. } else if ($checkState == LaState::LA_NEED_FIRST_CHECK) {
  73. $where[] = ["checkState", "=", 15];
  74. $where[] = ["highProcess", "<", 2];
  75. } else if ($checkState == LaState::LA_FIRST_REJECT) { //待复核
  76. $where[] = ["checkState", "in", [1, 3, 5, 7, 10, 20]];
  77. } else if ($checkState == LaState::LA_NEED_DEP_CHECK) {
  78. $where[] = ["checkState", ">=", 25];
  79. } else {
  80. $where[] = ["checkState", "=", $checkState];
  81. }
  82. break;
  83. case 3:
  84. if ($checkState == LaState::LA_THIRD_REJECT) {
  85. $where [] = ["checkState", "in", [7, 10, 15, 20, 30]];
  86. } else if ($checkState == LaState::LA_BEFORE_REJECT) { //重新提交
  87. $where[] = ["checkState", "=", LaState::LA_NEED_THIRD];
  88. $where[] = ["highProcess", ">=", 3];
  89. } else if ($checkState == LaState::LA_NEED_THIRD) { //待复核
  90. $where[] = ["checkState", "=", $checkState];
  91. $where[] = ["highProcess", "<", 3];
  92. } else {
  93. $where[] = ["checkState", "=", $checkState];
  94. }
  95. break;
  96. case 4:
  97. $where[] = ["checkState", "=", $checkState];
  98. break;
  99. case 5:
  100. break;
  101. }
  102. }
  103. return $where;
  104. }
  105. public static function getWhereByParams($params) {
  106. foreach ($params as &$param) {
  107. $param = trim($param);
  108. }unset($param);
  109. $where = [];
  110. if ($params["name"]) {
  111. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  112. }
  113. if ($params["idCard"]) {
  114. $where[] = ["idCard", "like", "%" . $params["idCard"] . "%"];
  115. }
  116. if ($params["introductionMethod"]) {
  117. $where[] = ["introductionMethod", "=", $params["introductionMethod"]];
  118. }
  119. if ($params["sex"]) {
  120. $where[] = ["sex", "=", $params["sex"]];
  121. }
  122. if ($params["declareType"]) {
  123. $where[] = ["declareType", "=", $params["declareType"]];
  124. }
  125. if ($params["nation"]) {
  126. $where[] = ["nation", "=", $params["nation"]];
  127. }
  128. if ($params["nationality"]) {
  129. $where[] = ["nationality", "=", $params["nationality"]];
  130. }
  131. if ($params["provinceCode"]) {
  132. $where[] = ["provinceCode", "=", $params["provinceCode"]];
  133. }
  134. if ($params["politics"]) {
  135. $where[] = ["politics", "=", $params["politics"]];
  136. }
  137. if (session("user")["usertype"] == 2) {
  138. $where[] = ["enterpriseId", "=", session("user")["uid"]];
  139. } else {
  140. if ($params["enterpriseId"]) {
  141. $where[] = ["enterpriseId", "=", $params["enterpriseId"]];
  142. }
  143. }
  144. if ($params["industryFieldNew"]) {
  145. $where[] = ["industryFieldNew", "=", $params["industryFieldNew"]];
  146. }
  147. if ($params["industryField"]) {
  148. $where[] = ["industryField", "=", $params["industryField"]];
  149. }
  150. if ($params["introductionMode"]) {
  151. $where[] = ["introductionMode", "=", $params["introductionMode"]];
  152. }
  153. if ($params["highEducation"]) {
  154. $where[] = ["highEducation", "=", $params["highEducation"]];
  155. }
  156. if ($params["major"]) {
  157. $where[] = ["major", "like", "%" . $params["major"] . "%"];
  158. }
  159. if ($params["title"]) {
  160. $where[] = ["title", "like", "%" . $params["title"] . "%"];
  161. }
  162. if ($params["studyAbroad"]) {
  163. $where[] = ["studyAbroad", "=", $params["studyAbroad"]];
  164. }
  165. if ($params["phone"]) {
  166. $where[] = ["phone", "like", "%" . $params["phone"] . "%"];
  167. }
  168. if ($params["email"]) {
  169. $where[] = ["email", "like", "%" . $params["email"] . "%"];
  170. }
  171. if ($params["address"]) {
  172. $where[] = ["address", "=", $params["address"]];
  173. }
  174. if ($params["isPublic"]) {
  175. $where[] = ["isPublic", "=", $params["isPublic"]];
  176. }
  177. if ($params["year"]) {
  178. $where[] = ["year", "=", $params["year"]];
  179. }
  180. switch ($params["process"]) {
  181. case 1:
  182. $where[] = ["checkState", "not in", [3, 5]];
  183. break;
  184. case 2:
  185. $where[] = ["firstPassTime", "EXP", Db::raw("is not null")];
  186. break;
  187. case 3:
  188. $where[] = ["firstDepPassTime", "EXP", Db::raw("is not null")];
  189. break;
  190. case 4:
  191. $where[] = ["checkState", "in", [-1, 35]];
  192. break;
  193. }
  194. return $where;
  195. }
  196. public static function getInfoById($id) {
  197. return LaModel::findOrEmpty($id)->toArray();
  198. }
  199. public static function getApplyCountByIdCard($idCard) {
  200. $where = [];
  201. $where[] = ["idCard", "=", $idCard];
  202. $where[] = ["checkState", "<>", LaState::LA_NOTPASS];
  203. $list = LaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  204. $years = array_column($list, "year");
  205. return $years;
  206. }
  207. public static function getPassYearsByIdCard($idCard) {
  208. $where = [];
  209. $where[] = ["idCard", "=", $idCard];
  210. $where[] = ["checkState", "=", LaState::LA_PASS];
  211. $list = LaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  212. $passYears = array_column($list, "year");
  213. return $passYears;
  214. }
  215. }