EnterpriseApi.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. namespace app\common\api;
  3. use app\admin\controller\EnterpriseChangeRecord;
  4. use app\common\api\CompanyApi;
  5. use app\enterprise\model\EnterpriseRecord;
  6. use think\facade\Db;
  7. use app\admin\model\Enterprise;
  8. use app\common\state\CommonConst;
  9. use app\common\api\Nhc;
  10. class EnterpriseApi {
  11. public static function getOne($id) {
  12. $ep = Enterprise::findOrEmpty($id);
  13. if ($ep->delete == 1) {
  14. return null;
  15. }
  16. $area = array_filter([$ep["provinceName"], $ep["cityName"], $ep["countyName"]]);
  17. $ep["fullLocationName"] = $area ? implode("", $area) : "";
  18. $ep["medicalCommunityName"] = $ep["medicalCommunityId"] ? Nhc::getMedicalCommunityMap()[$ep["medicalCommunityId"]] : "";
  19. return $ep;
  20. }
  21. public static function getSimpleList($extra = array()) {
  22. $where[] = ["active", "=", 1];
  23. $where[] = ["delete", "=", 0];
  24. $where[] = ['type', '=', session('user')['type']];
  25. if ($extra) {
  26. $where = array_merge($where, $extra);
  27. }
  28. return $list = Enterprise::where($where)->order("name", 'asc')->field("name,id")->select()->toArray();
  29. }
  30. public static function getMultipleList($typeList = array()) {
  31. $where[] = ["active", "=", 1];
  32. $where[] = ["delete", "=", 0];
  33. $where[] = ['type', 'in', $typeList];
  34. return $list = Enterprise::where($where)->order("name", 'asc')->field("name,id")->select()->toArray();
  35. }
  36. public static function getList($request, $isExport = false) {
  37. $companyId = session('user')['companyId'];
  38. $company_info = CompanyApi::getOne($companyId);
  39. $where = [];
  40. $whereRaw = "";
  41. $where[] = ['type', '=', session('user')['type']];
  42. if (session('user')['type'] == CommonConst::ENTERPRISE_WJ) {
  43. $where[] = ["step", "in", [1, 2]];
  44. }
  45. if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
  46. if (session('user')['type'] == 1) {
  47. $whr[] = ["companyId", "=", $companyId];
  48. $whr[] = ["delete", "=", 0];
  49. $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();
  50. $talentType = []; //查找单位对应标签
  51. $org = [];
  52. $ins = [];
  53. $uniCodes = []; //查找单位对应例外
  54. foreach ($list as $k => $v) {
  55. if (!empty($v['enterpriseTag'])) {
  56. array_push($talentType, $v['enterpriseTag']);
  57. }
  58. if (!empty($v['organizationTag'])) {
  59. array_push($org, $v['organizationTag']);
  60. }
  61. if (!empty($v['institutionTag'])) {
  62. array_push($ins, $v['institutionTag']);
  63. }
  64. if (!empty($v["uniCode"])) {
  65. $codes = explode(",", $v["uniCode"]);
  66. $uniCodes = array_merge($uniCodes, (array) $codes);
  67. }
  68. }
  69. $_whr[] = ["uniCode", "<>", ""];
  70. $_whr[] = ["delete", "=", 0];
  71. $_whr[] = ["companyId", "<>", $companyId];
  72. $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();
  73. $expUniCodes = []; //排除其它单位的例外
  74. foreach ($_list as $_v) {
  75. $codes = explode(",", $_v["uniCode"]);
  76. $expUniCodes = array_merge($expUniCodes, (array) $codes);
  77. }
  78. if (($talentType || $org || $ins) && $uniCodes) {
  79. if ($expUniCodes) {
  80. $whereRaw = sprintf('(enterpriseTag in ("%s") or organizationTag in ("%s") or institutionTag in ("%s") and idCard not in ("%s")) or idCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes), implode('","', $uniCodes));
  81. } else {
  82. $whereRaw = sprintf('enterpriseTag in ("%s") or organizationTag in ("%s") or institutionTag in ("%s") or idCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $uniCodes));
  83. }
  84. }
  85. if (($talentType || $org || $ins) && !$uniCodes) {
  86. if ($expUniCodes) {
  87. $whereRaw = sprintf('enterpriseTag in ("%s") or organizationTag in ("%s") or institutionTag in ("%s") and idCard not in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes));
  88. } else {
  89. $whereRaw = sprintf('enterpriseTag in ("%s") or organizationTag in ("%s") or institutionTag in ("%s") ', implode('","', $talentType), implode('","', $org), implode('","', $ins));
  90. }
  91. }
  92. if (!$talentType && !$org && !$ins && $uniCodes) {
  93. $where[] = ["idCard", "in", $uniCodes];
  94. }
  95. }
  96. }
  97. $offset = trim($request->param("offset")) ?: 0;
  98. $limit = trim($request->param("limit")) ?: 10;
  99. $name = urldecode(trim($request->param("name")));
  100. $idCard = urldecode(trim($request->param("idCard")));
  101. $legal = urldecode(trim($request->param("legal")));
  102. $medicalCommunityId = urldecode(trim($request->param("medicalCommunityId")));
  103. $isGeneral = urldecode(trim($request->param("isGeneral")));
  104. $ephone = urldecode(trim($request->param("ephone")));
  105. $agentName = urldecode(trim($request->param("agentName")));
  106. $agentPhone = urldecode(trim($request->param("agentPhone")));
  107. $checkState = urldecode(trim($request->param("checkState")));
  108. $active = urldecode(trim($request->param("active")));
  109. $street = urldecode(trim($request->param("street")));
  110. $special = urldecode(trim($request->param("special")));
  111. $agencyType = urldecode(trim($request->param("agencyType")));
  112. $industryFieldNew = urldecode(trim($request->param("industryFieldNew")));
  113. $industryFieldOld = urldecode(trim($request->param("industryFieldOld")));
  114. $enterpriseTag = urldecode(trim($request->param("enterpriseTag")));
  115. $enterpriseType = urldecode(trim($request->param("enterpriseType")));
  116. $where[] = ["delete", "=", 0];
  117. if ($name) {
  118. $where[] = ["name", "like", "%{$name}%"];
  119. }
  120. if ($idCard) {
  121. $where[] = ["idCard", "like", "%{$idCard}%"];
  122. }
  123. if ($legal) {
  124. $where[] = ["legal", "like", "%{$legal}%"];
  125. }
  126. if ($medicalCommunityId) {
  127. $where[] = ["medicalCommunityId", "=", $medicalCommunityId];
  128. }
  129. if ($isGeneral) {
  130. $where[] = ["isGeneral", "=", $isGeneral];
  131. }
  132. if ($ephone) {
  133. $where[] = ["ephone", "like", "%{$ephone}%"];
  134. }
  135. if ($agentName) {
  136. $where[] = ["agentName", "like", "%{$agentName}%"];
  137. }
  138. if ($agentPhone) {
  139. $where[] = ["agentPhone", "like", "%{$agentPhone}%"];
  140. }
  141. if ($checkState) {
  142. $where[] = ["checkState", "=", "{$checkState}"];
  143. }
  144. if ($active) {
  145. $where[] = ["active", "=", "{$active}"];
  146. }
  147. if ($street) {
  148. $where[] = ["street", "=", "{$street}"];
  149. }
  150. if ($special !== "") {
  151. $where[] = ["special", "=", "{$special}"];
  152. }
  153. if ($agencyType) {
  154. $where[] = ["agencyType", "=", "{$agencyType}"];
  155. }
  156. if ($industryFieldNew) {
  157. $where[] = ["industryFieldNew", "=", "{$industryFieldNew}"];
  158. }
  159. if ($industryFieldOld) {
  160. $where[] = ["industryFieldOld", "=", "{$industryFieldOld}"];
  161. }
  162. if ($enterpriseTag) {
  163. if ($special == 1) {
  164. $where[] = ["institutionTag", "=", "{$enterpriseTag}"];
  165. } else if ($special == 3) {
  166. $where[] = ["organizationTag", "=", "{$enterpriseTag}"];
  167. } else {
  168. $where[] = ["enterpriseTag", "=", "{$enterpriseTag}"];
  169. }
  170. }
  171. if ($enterpriseType) {
  172. $where[] = ["enterpriseType", "=", "{$enterpriseType}"];
  173. }
  174. if ($whereRaw) {
  175. $count = Enterprise::where($where)->whereRaw($whereRaw)->count();
  176. } else {
  177. $count = Enterprise::where($where)->count();
  178. }
  179. if ($count > 0) {
  180. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  181. $orgList = DictApi::selectByParentCode("organization_tag");
  182. $insList = DictApi::selectByParentCode("institution_tag");
  183. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  184. $streetList = DictApi::selectByParentCode("street");
  185. $medicalCommunityList = Nhc::getMedicalCommunityMap();
  186. //dd($talentTypeList);
  187. if ($whereRaw) {
  188. if ($isExport) {
  189. $list = Enterprise::where($where)->whereRaw($whereRaw)->order("createTime", 'desc')->select()->toArray();
  190. } else {
  191. $list = Enterprise::where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  192. }
  193. } else {
  194. if ($isExport) {
  195. $list = Enterprise::where($where)->order("createTime", 'desc')->select()->toArray();
  196. } else {
  197. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  198. }
  199. }
  200. foreach ($list as $k => &$v) {
  201. unset($v['password']);
  202. $v['enterpriseTagName'] = array_key_exists($v['enterpriseTag'], $talentTypeList) ? $talentTypeList[$v['enterpriseTag']] : ''; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  203. $v['organizationTagName'] = array_key_exists($v['organizationTag'], $orgList) ? $orgList[$v['organizationTag']] : '';
  204. $v['institutionTagName'] = array_key_exists($v['institutionTag'], $orgList) ? $orgList[$v['institutionTag']] : '';
  205. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  206. $v['streetName'] = $streetList[$v['street']];
  207. $v['medicalCommunityName'] = $v['medicalCommunityId'] ? $medicalCommunityList[$v['medicalCommunityId']] : "";
  208. }
  209. } else {
  210. $list = [];
  211. }
  212. return ["total" => $count, "rows" => $list];
  213. }
  214. public static function getRecordList($request) {
  215. $companyId = session('user')['companyId'];
  216. $company_info = CompanyApi::getOne($companyId);
  217. $where = [];
  218. $whereRaw = "";
  219. $where[] = ['r.type', '=', session('user')['type']];
  220. if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
  221. if (session('user')['type'] == 1) {
  222. $whr[] = ["companyId", "=", $companyId];
  223. $whr[] = ["delete", "=", 0];
  224. $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();
  225. $talentType = []; //查找单位对应标签
  226. $org = [];
  227. $ins = [];
  228. $uniCodes = [];
  229. foreach ($list as $k => $v) {
  230. if (!empty($v['enterpriseTag'])) {
  231. array_push($talentType, $v['enterpriseTag']);
  232. }
  233. if (!empty($v['organizationTag'])) {
  234. array_push($org, $v['organizationTag']);
  235. }
  236. if (!empty($v['institutionTag'])) {
  237. array_push($ins, $v['institutionTag']);
  238. }
  239. if (!empty($v["uniCode"])) {
  240. $codes = explode(",", $v["uniCode"]);
  241. $uniCodes = array_merge($uniCodes, (array) $codes);
  242. }
  243. }
  244. $_whr[] = ["uniCode", "<>", ""];
  245. $_whr[] = ["delete", "=", 0];
  246. $_whr[] = ["companyId", "<>", $companyId];
  247. $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();
  248. $expUniCodes = []; //排除其它单位的例外
  249. foreach ($_list as $_v) {
  250. $codes = explode(",", $_v["uniCode"]);
  251. $expUniCodes = array_merge($expUniCodes, (array) $codes);
  252. }
  253. if (($talentType || $org || $ins) && $uniCodes) {
  254. if ($expUniCodes) {
  255. $whereRaw = sprintf('(newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") and newIdCard not in ("%s")) or newIdCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes), implode('","', $uniCodes));
  256. } else {
  257. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") or newIdCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $uniCodes));
  258. }
  259. }
  260. if (($talentType || $org || $ins) && !$uniCodes) {
  261. if ($expUniCodes) {
  262. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") and newIdCard not in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes));
  263. } else {
  264. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") ', implode('","', $talentType), implode('","', $org), implode('","', $ins));
  265. }
  266. }
  267. }
  268. }
  269. $offset = trim($request->param("offset")) ?: 0;
  270. $limit = trim($request->param("limit")) ?: 10;
  271. $oldName = trim($request->param("oldName"));
  272. $oldIdCard = trim($request->param("oldIdCard"));
  273. $oldLegal = trim($request->param("oldLegal"));
  274. $oldMedicalCommunityId = trim($request->param("oldMedicalCommunityId"));
  275. $oldIsGeneral = trim($request->param("oldIsGeneral"));
  276. $oldStreet = trim($request->param("oldStreet"));
  277. $oldEnterpriseTag = trim($request->param("oldEnterpriseTag"));
  278. $oldIndustryFieldNew = trim($request->param("oldIndustryFieldNew"));
  279. $newName = trim($request->param("newName"));
  280. $newIdCard = trim($request->param("newIdCard"));
  281. $newMedicalCommunityId = trim($request->param("newMedicalCommunityId"));
  282. $newIsGeneral = trim($request->param("newIsGeneral"));
  283. $newAgentName = trim($request->param("newAgentName"));
  284. $newStreet = trim($request->param("newStreet"));
  285. $newEnterpriseTag = trim($request->param("newEnterpriseTag"));
  286. $newIndustryFieldNew = trim($request->param("newIndustryFieldNew"));
  287. $checkState = trim($request->param("checkState"));
  288. if ($oldName) {
  289. $where[] = ["r.oldName", "like", "%{$oldName}%"];
  290. }
  291. if ($oldIdCard) {
  292. $where[] = ["r.oldIdCard", "like", "%{$oldIdCard}%"];
  293. }
  294. if ($oldLegal) {
  295. $where[] = ["r.oldLegal", "like", "%{$oldLegal}%"];
  296. }
  297. if ($oldMedicalCommunityId) {
  298. $where[] = ["r.oldMedicalCommunityId", "=", $oldMedicalCommunityId];
  299. }
  300. if ($oldIsGeneral) {
  301. $where[] = ["r.oldIsGeneral", "=", $oldIsGeneral];
  302. }
  303. if ($oldStreet) {
  304. $where[] = ["r.oldStreet", "=", "{$oldStreet}"];
  305. }
  306. if ($oldEnterpriseTag) {
  307. $where[] = ["r.oldEnterpriseTag", "=", "{$oldEnterpriseTag}"];
  308. }
  309. if ($oldIndustryFieldNew) {
  310. $where[] = ["r.oldIndustryFieldNew", "=", "{$oldIndustryFieldNew}"];
  311. }
  312. if ($newName) {
  313. $where[] = ["r.newName", "like", "%{$newName}%"];
  314. }
  315. if ($newIdCard) {
  316. $where[] = ["r.newIdCard", "like", "%{$newIdCard}%"];
  317. }
  318. if ($newMedicalCommunityId) {
  319. $where[] = ["r.newMedicalCommunityId", "=", $newMedicalCommunityId];
  320. }
  321. if ($newIsGeneral) {
  322. $where[] = ["r.newIsGeneral", "=", $newIsGeneral];
  323. }
  324. if ($newAgentName) {
  325. $where[] = ["r.newAgentName", "like", "%{$newAgentName}%"];
  326. }
  327. if ($checkState) {
  328. $where[] = ["r.checkState", "=", "{$checkState}"];
  329. } else {
  330. $where[] = ['r.checkState', '>', 1];
  331. }
  332. if ($newStreet) {
  333. $where[] = ["r.newStreet", "=", "{$newStreet}"];
  334. }
  335. if ($newEnterpriseTag) {
  336. $where[] = ["r.newEnterpriseTag", "=", "{$newEnterpriseTag}"];
  337. }
  338. if ($newIndustryFieldNew) {
  339. $where[] = ["r.newIndustryFieldNew", "=", "{$newIndustryFieldNew}"];
  340. }
  341. $where[] = ["e.delete", "=", 0];
  342. if ($whereRaw) {
  343. $count = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->where($where)->whereRaw($whereRaw)->count();
  344. } else {
  345. $count = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->where($where)->count();
  346. }
  347. if ($count > 0) {
  348. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  349. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  350. $streetList = DictApi::selectByParentCode("street");
  351. $medicalCommunityList = Nhc::getMedicalCommunityMap();
  352. if ($whereRaw) {
  353. $list = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->field("r.*")->where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("r.createTime", 'desc')->select()->toArray();
  354. } else {
  355. $list = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->field("r.*")->where($where)->limit($offset, $limit)->order("r.createTime", 'desc')->select()->toArray();
  356. }
  357. foreach ($list as $k => &$v) {
  358. $v['oldStreetName'] = $streetList[$v['oldStreet']];
  359. $v['newStreetName'] = $streetList[$v['newStreet']];
  360. $v['oldEnterpriseTagName'] = $talentTypeList[$v['oldEnterpriseTag']];
  361. $v['newEnterpriseTagName'] = $talentTypeList[$v['newEnterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  362. $v['oldIndustryFieldNewName'] = $industryFieldNewList[$v['oldIndustryFieldNew']];
  363. $v['newIndustryFieldNewName'] = $industryFieldNewList[$v['newIndustryFieldNew']];
  364. $v['oldMedicalCommunityName'] = $medicalCommunityList[$v['oldMedicalCommunityId']];
  365. $v['newMedicalCommunityName'] = $medicalCommunityList[$v['newMedicalCommunityId']];
  366. }
  367. } else {
  368. $list = [];
  369. }
  370. return ["total" => $count, "rows" => $list];
  371. }
  372. public static function getExportList($request) {
  373. $companyId = session('user')['companyId'];
  374. $company_info = CompanyApi::getOne($companyId);
  375. $where = [];
  376. $whereRaw = "";
  377. $where[] = ['r.type', '=', session('user')['type']];
  378. if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
  379. if (session('user')['type'] == 1) {
  380. $whr[] = ["companyId", "=", $companyId];
  381. $whr[] = ["delete", "=", 0];
  382. $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();
  383. $talentType = []; //查找单位对应标签
  384. $org = [];
  385. $ins = [];
  386. $uniCodes = [];
  387. foreach ($list as $k => $v) {
  388. if (!empty($v['enterpriseTag'])) {
  389. array_push($talentType, $v['enterpriseTag']);
  390. }
  391. if (!empty($v['organizationTag'])) {
  392. array_push($org, $v['organizationTag']);
  393. }
  394. if (!empty($v['institutionTag'])) {
  395. array_push($ins, $v['institutionTag']);
  396. }
  397. if (!empty($v["uniCode"])) {
  398. $codes = explode(",", $v["uniCode"]);
  399. $uniCodes = array_merge($uniCodes, (array) $codes);
  400. }
  401. }
  402. $_whr[] = ["uniCode", "<>", ""];
  403. $_whr[] = ["delete", "=", 0];
  404. $_whr[] = ["companyId", "<>", $companyId];
  405. $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();
  406. $expUniCodes = []; //排除其它单位的例外
  407. foreach ($_list as $_v) {
  408. $codes = explode(",", $_v["uniCode"]);
  409. $expUniCodes = array_merge($expUniCodes, (array) $codes);
  410. }
  411. if (($talentType || $org || $ins) && $uniCodes) {
  412. if ($expUniCodes) {
  413. $whereRaw = sprintf('(newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") and newIdCard not in ("%s")) or newIdCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes), implode('","', $uniCodes));
  414. } else {
  415. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") or newIdCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $uniCodes));
  416. }
  417. }
  418. if (($talentType || $org || $ins) && !$uniCodes) {
  419. if ($expUniCodes) {
  420. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") and newIdCard not in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes));
  421. } else {
  422. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") ', implode('","', $talentType), implode('","', $org), implode('","', $ins));
  423. }
  424. }
  425. }
  426. }
  427. $offset = trim($request->param("offset")) ?: 0;
  428. $limit = trim($request->param("limit")) ?: 10;
  429. $oldName = urldecode(trim($request->param("oldName")));
  430. $oldIdCard = urldecode(trim($request->param("oldIdCard")));
  431. $oldLegal = urldecode(trim($request->param("oldLegal")));
  432. $oldMedicalCommunityId = trim($request->param("oldMedicalCommunityId"));
  433. $oldIsGeneral = trim($request->param("oldIsGeneral"));
  434. $oldStreet = urldecode(trim($request->param("oldStreet")));
  435. $oldEnterpriseTag = urldecode(trim($request->param("oldEnterpriseTag")));
  436. $oldIndustryFieldNew = urldecode(trim($request->param("oldIndustryFieldNew")));
  437. $newName = urldecode(trim($request->param("newName")));
  438. $newIdCard = urldecode(trim($request->param("newIdCard")));
  439. $newMedicalCommunityId = trim($request->param("newMedicalCommunityId"));
  440. $newIsGeneral = trim($request->param("newIsGeneral"));
  441. $newAgentName = urldecode(trim($request->param("newAgentName")));
  442. $newStreet = urldecode(trim($request->param("newStreet")));
  443. $newEnterpriseTag = urldecode(trim($request->param("newEnterpriseTag")));
  444. $newIndustryFieldNew = urldecode(trim($request->param("newIndustryFieldNew")));
  445. $checkState = urldecode(trim($request->param("checkState")));
  446. if ($oldName) {
  447. $where[] = ["oldName", "like", "%{$oldName}%"];
  448. }
  449. if ($oldIdCard) {
  450. $where[] = ["oldIdCard", "like", "%{$oldIdCard}%"];
  451. }
  452. if ($oldLegal) {
  453. $where[] = ["oldLegal", "like", "%{$oldLegal}%"];
  454. }
  455. if ($oldMedicalCommunityId) {
  456. $where[] = ["oldMedicalCommunityId", "=", $oldMedicalCommunityId];
  457. }
  458. if ($oldIsGeneral) {
  459. $where[] = ["oldIsGeneral", "=", $oldIsGeneral];
  460. }
  461. if ($oldStreet) {
  462. $where[] = ["oldStreet", "=", "{$oldStreet}"];
  463. }
  464. if ($oldEnterpriseTag) {
  465. $where[] = ["oldEnterpriseTag", "=", "{$oldEnterpriseTag}"];
  466. }
  467. if ($oldIndustryFieldNew) {
  468. $where[] = ["oldIndustryFieldNew", "=", "{$oldIndustryFieldNew}"];
  469. }
  470. if ($newName) {
  471. $where[] = ["newName", "like", "%{$newName}%"];
  472. }
  473. if ($newIdCard) {
  474. $where[] = ["newIdCard", "like", "%{$newIdCard}%"];
  475. }
  476. if ($newMedicalCommunityId) {
  477. $where[] = ["newMedicalCommunityId", "=", $newMedicalCommunityId];
  478. }
  479. if ($newIsGeneral) {
  480. $where[] = ["newIsGeneral", "=", $newIsGeneral];
  481. }
  482. if ($newAgentName) {
  483. $where[] = ["newAgentName", "like", "%{$newAgentName}%"];
  484. }
  485. if ($checkState) {
  486. $where[] = ["r.checkState", "=", "{$checkState}"];
  487. } else {
  488. $where[] = ['r.checkState', '>', 1];
  489. }
  490. if ($newStreet) {
  491. $where[] = ["newStreet", "=", "{$newStreet}"];
  492. }
  493. if ($newEnterpriseTag) {
  494. $where[] = ["newEnterpriseTag", "=", "{$newEnterpriseTag}"];
  495. }
  496. if ($newIndustryFieldNew) {
  497. $where[] = ["newIndustryFieldNew", "=", "{$newIndustryFieldNew}"];
  498. }
  499. $where[] = ["e.delete", "=", 0];
  500. if ($whereRaw) {
  501. $count = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->where($where)->whereRaw($whereRaw)->count();
  502. } else {
  503. $count = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->where($where)->count();
  504. }
  505. if ($count > 0) {
  506. $organizationTagList = DictApi::selectByParentCode("organization_tag");
  507. $institutionTag = DictApi::selectByParentCode("institution_tag");
  508. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  509. $enterpriseTypeList = DictApi::selectByParentCode("enterprise_type");
  510. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  511. $streetList = DictApi::selectByParentCode("street");
  512. $agencyTypeList = DictApi::selectByParentCode("agency_type");
  513. $medicalCommunityList = Nhc::getMedicalCommunityMap();
  514. if ($whereRaw) {
  515. $list = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->field("r.*")->where($where)->whereRaw($whereRaw)->order("createTime", 'desc')->select()->toArray();
  516. } else {
  517. $list = EnterpriseRecord::alias("r")->leftJoin("un_enterprise e", "e.id=r.mainId")->field("r.*")->where($where)->order("createTime", 'desc')->select()->toArray();
  518. }
  519. foreach ($list as $k => &$v) {
  520. if ($v["special"] == 1) {
  521. $v["typeName"] = "事业单位";
  522. $v["oldAgencyTagName"] = $institutionTag[$v["oldInstitutionTag"]];
  523. $v["newAgencyTagName"] = $institutionTag[$v["newInstitutionTag"]];
  524. } else if ($v["special"] == 2) {
  525. $v["typeName"] = "民办非企业";
  526. $v["oldAgencyTagName"] = $organizationTagList[$v["oldOrganizationTag"]];
  527. $v["newAgencyTagName"] = $organizationTagList[$v["newOrganizationTag"]];
  528. } else {
  529. $v["typeName"] = "企业用户";
  530. if ($v["type"] == CommonConst::ENTERPRISE_NORMAL) {
  531. $v["typeName"] .= "(晋江市现代产业体系人才)";
  532. } else if ($v["type"] == CommonConst::ENTERPRISE_JC) {
  533. $v["typeName"] .= "(集成电路优秀人才)";
  534. } else if ($v["type"] == CommonConst::ENTERPRISE_WJ) {
  535. $v["typeName"] .= "(卫健医院)";
  536. } else if ($v["type"] == CommonConst::ENTERPRISE_GJ) {
  537. $v["typeName"] .= "(高教学校)";
  538. }
  539. }
  540. $v['oldStreetName'] = $streetList[$v['oldStreet']];
  541. $v['newStreetName'] = $streetList[$v['newStreet']];
  542. $v['oldEnterpriseTagName'] = $talentTypeList[$v['oldEnterpriseTag']];
  543. $v['newEnterpriseTagName'] = $talentTypeList[$v['newEnterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  544. $v['oldIndustryFieldNewName'] = $industryFieldNewList[$v['oldIndustryFieldNew']];
  545. $v['newIndustryFieldNewName'] = $industryFieldNewList[$v['newIndustryFieldNew']];
  546. $v["oldIndustryFieldOldName"] = DictApi::findDictByCode($v['oldIndustryFieldOld'])["name"];
  547. $v["newIndustryFieldOldName"] = DictApi::findDictByCode($v['newIndustryFieldOld'])["name"];
  548. $v["oldEnterpriseTypeName"] = $enterpriseTypeList[$v["oldEnterpriseType"]];
  549. $v["newEnterpriseTypeName"] = $enterpriseTypeList[$v["newEnterpriseType"]];
  550. $v["oldAgencyTypeName"] = $agencyTypeList[$v["oldAgencyType"]];
  551. $v["newAgencyTypeName"] = $agencyTypeList[$v["newAgencyType"]];
  552. $v['oldMedicalCommunityName'] = $medicalCommunityList[$v['oldMedicalCommunityId']];
  553. $v['newMedicalCommunityName'] = $medicalCommunityList[$v['newMedicalCommunityId']];
  554. switch ($v["checkState"]) {
  555. case 1:
  556. $v['checkStateName'] = '保存未提交审核';
  557. break;
  558. case 2:
  559. $v['checkStateName'] = '待审核';
  560. break;
  561. case 3:
  562. $v['checkStateName'] = "审核驳回";
  563. break;
  564. case 4:
  565. $v['checkStateName'] = "审核通过";
  566. break;
  567. case 5:
  568. $v['checkStateName'] = '重新提交';
  569. break;
  570. case 6:
  571. $v['checkStateName'] = '初审驳回';
  572. break;
  573. case 7:
  574. $v['checkStateName'] = '初审通过';
  575. break;
  576. }
  577. }
  578. } else {
  579. $list = [];
  580. }
  581. return $list;
  582. }
  583. public static function updateById($data) {
  584. return Enterprise::update($data);
  585. }
  586. public static function getOneRecord($id) {
  587. return EnterpriseRecord::findOrEmpty($id);
  588. }
  589. private static function getSuperusersForEnterprise() {
  590. $superusers = getJsonConfig("../sys_config.json", "super_users_for_enterprise");
  591. return $superusers;
  592. }
  593. public static function chkUserInSuperusers() {
  594. $superusers = self::getSuperusersForEnterprise();
  595. $account = session("user")["account"];
  596. return in_array($account, $superusers);
  597. }
  598. }