EnterpriseApi.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. class EnterpriseApi {
  9. public static function getOne($id) {
  10. return Enterprise::findOrEmpty($id);
  11. }
  12. public static function getSimpleList() {
  13. $where[] = ["active", "=", 1];
  14. return $list = Enterprise::where($where)->order("name", 'asc')->field("name,id")->select()->toArray();
  15. }
  16. public static function getList($request) {
  17. $companyId = session('user')['companyId'];
  18. $company_info = CompanyApi::getOne($companyId);
  19. $where = [];
  20. $whereRaw = "";
  21. if ($company_info['code'] != 'super') {
  22. $where[] = ['type', '=', session('user')['type']];
  23. if (session('user')['type'] == 1) {
  24. $whr[] = ["companyId", "=", $companyId];
  25. $whr[] = ["delete", "=", 0];
  26. $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();
  27. $talentType = []; //查找单位对应标签
  28. $org = [];
  29. $ins = [];
  30. $uniCodes = []; //查找单位对应例外
  31. foreach ($list as $k => $v) {
  32. if(!empty($v['enterpriseTag'])){
  33. array_push($talentType, $v['enterpriseTag']);
  34. }
  35. if(!empty($v['organizationTag'])){
  36. array_push($org, $v['organizationTag']);
  37. }
  38. if(!empty($v['institutionTag'])){
  39. array_push($ins, $v['institutionTag']);
  40. }
  41. if(!empty($v["uniCode"])){
  42. $codes = explode(",", $v["uniCode"]);
  43. $uniCodes = array_merge($uniCodes, (array) $codes);
  44. }
  45. }
  46. $_whr[] = ["uniCode", "<>", ""];
  47. $_whr[] = ["delete", "=", 0];
  48. $_whr[] = ["companyId", "<>", $companyId];
  49. $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();
  50. $expUniCodes = []; //排除其它单位的例外
  51. foreach ($_list as $_v) {
  52. $codes = explode(",", $_v["uniCode"]);
  53. $expUniCodes = array_merge($expUniCodes, (array) $codes);
  54. }
  55. if (($talentType || $org || $ins) && $uniCodes) {
  56. if ($expUniCodes) {
  57. $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));
  58. } else {
  59. $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));
  60. }
  61. }
  62. if (($talentType || $org || $ins) && !$uniCodes) {
  63. if ($expUniCodes) {
  64. $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));
  65. } else {
  66. $whereRaw = sprintf('enterpriseTag in ("%s") or organizationTag in ("%s") or institutionTag in ("%s") ', implode('","', $talentType), implode('","', $org), implode('","', $ins));
  67. }
  68. }
  69. if (!$talentType && !$org && !$ins && $uniCodes) {
  70. $where[] = ["idCard", "in", $uniCodes];
  71. }
  72. }
  73. }
  74. $offset = trim($request->param("offset")) ?: 0;
  75. $limit = trim($request->param("limit")) ?: 10;
  76. $name = trim($request->param("name"));
  77. $idCard = trim($request->param("idCard"));
  78. $legal = trim($request->param("legal"));
  79. $ephone = trim($request->param("ephone"));
  80. $agentName = trim($request->param("agentName"));
  81. $agentPhone = trim($request->param("agentPhone"));
  82. $checkState = trim($request->param("checkState"));
  83. $active = trim($request->param("active"));
  84. $street = trim($request->param("street"));
  85. $enterpriseTag = trim($request->param("enterpriseTag"));
  86. $industryFieldNew = trim($request->param("industryFieldNew"));
  87. if ($name) {
  88. $where[] = ["name", "like", "%{$name}%"];
  89. }
  90. if ($idCard) {
  91. $where[] = ["idCard", "like", "%{$idCard}%"];
  92. }
  93. if ($legal) {
  94. $where[] = ["legal", "like", "%{$legal}%"];
  95. }
  96. if ($ephone) {
  97. $where[] = ["ephone", "like", "%{$ephone}%"];
  98. }
  99. if ($agentName) {
  100. $where[] = ["agentName", "like", "%{$agentName}%"];
  101. }
  102. if ($agentPhone) {
  103. $where[] = ["agentPhone", "like", "%{$agentPhone}%"];
  104. }
  105. if ($checkState) {
  106. $where[] = ["checkState", "=", "{$checkState}"];
  107. }
  108. if ($active) {
  109. $where[] = ["active", "=", "{$active}"];
  110. }
  111. if ($street) {
  112. $where[] = ["street", "=", "{$street}"];
  113. }
  114. if ($enterpriseTag) {
  115. $where[] = ["enterpriseTag", "=", "{$enterpriseTag}"];
  116. }
  117. if ($industryFieldNew) {
  118. $where[] = ["industryFieldNew", "=", "{$industryFieldNew}"];
  119. }
  120. if ($whereRaw) {
  121. $count = Enterprise::where($where)->whereRaw($whereRaw)->count();
  122. } else {
  123. $count = Enterprise::where($where)->count();
  124. }
  125. if ($count > 0) {
  126. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  127. $orgList = DictApi::selectByParentCode("organization_tag");
  128. $insList = DictApi::selectByParentCode("institution_tag");
  129. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  130. $streetList = DictApi::selectByParentCode("street");
  131. //dd($talentTypeList);
  132. if ($whereRaw) {
  133. $list = Enterprise::where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  134. } else {
  135. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  136. }
  137. foreach ($list as $k => &$v) {
  138. unset($v['password']);
  139. $v['enterpriseTagName'] = array_key_exists($v['enterpriseTag'],$talentTypeList) ? $talentTypeList[$v['enterpriseTag']] : ''; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  140. $v['organizationTagName'] = array_key_exists($v['organizationTag'],$orgList) ? $orgList[$v['organizationTag']] : '';
  141. $v['institutionTagName'] = array_key_exists($v['institutionTag'],$orgList) ? $orgList[$v['institutionTag']] : '';
  142. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  143. $v['streetName'] = $streetList[$v['street']];
  144. }
  145. } else {
  146. $list = [];
  147. }
  148. return ["total" => $count, "rows" => $list];
  149. }
  150. public static function getRecordList($request) {
  151. $companyId = session('user')['companyId'];
  152. $company_info = CompanyApi::getOne($companyId);
  153. $where = [];
  154. $whereRaw = "";
  155. if ($company_info['code'] != 'super') {
  156. $where[] = ['type', '=', session('user')['type']];
  157. if (session('user')['type'] == 1) {
  158. $whr[] = ["companyId", "=", $companyId];
  159. $whr[] = ["delete", "=", 0];
  160. $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();
  161. $talentType = []; //查找单位对应标签
  162. $org = [];
  163. $ins = [];
  164. $uniCodes = [];
  165. foreach ($list as $k => $v) {
  166. if(!empty($v['enterpriseTag'])){
  167. array_push($talentType, $v['enterpriseTag']);
  168. }
  169. if(!empty($v['organizationTag'])){
  170. array_push($org, $v['organizationTag']);
  171. }
  172. if(!empty($v['institutionTag'])){
  173. array_push($ins, $v['institutionTag']);
  174. }
  175. if(!empty($v["uniCode"])){
  176. $codes = explode(",", $v["uniCode"]);
  177. $uniCodes = array_merge($uniCodes, (array) $codes);
  178. }
  179. }
  180. $_whr[] = ["uniCode", "<>", ""];
  181. $_whr[] = ["delete", "=", 0];
  182. $_whr[] = ["companyId", "<>", $companyId];
  183. $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();
  184. $expUniCodes = []; //排除其它单位的例外
  185. foreach ($_list as $_v) {
  186. $codes = explode(",", $_v["uniCode"]);
  187. $expUniCodes = array_merge($expUniCodes, (array) $codes);
  188. }
  189. if (($talentType || $org || $ins) && $uniCodes) {
  190. if ($expUniCodes) {
  191. $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));
  192. } else {
  193. $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));
  194. }
  195. }
  196. if (($talentType || $org || $ins) && !$uniCodes) {
  197. if ($expUniCodes) {
  198. $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));
  199. } else {
  200. $whereRaw = sprintf('newEnterpriseTag in ("%s") or newOrganizationTag in ("%s") or newInstitutionTag in ("%s") ', implode('","', $talentType), implode('","', $org), implode('","', $ins));
  201. }
  202. }
  203. }
  204. }
  205. $offset = trim($request->param("offset")) ?: 0;
  206. $limit = trim($request->param("limit")) ?: 10;
  207. $oldName = trim($request->param("oldName"));
  208. $oldIdCard = trim($request->param("oldIdCard"));
  209. $oldLegal = trim($request->param("oldLegal"));
  210. $oldStreet = trim($request->param("oldStreet"));
  211. $oldEnterpriseTag = trim($request->param("oldEnterpriseTag"));
  212. $oldIndustryFieldNew = trim($request->param("oldIndustryFieldNew"));
  213. $newName = trim($request->param("newName"));
  214. $newIdCard = trim($request->param("newIdCard"));
  215. $newAgentName = trim($request->param("newAgentName"));
  216. $newStreet = trim($request->param("newStreet"));
  217. $newEnterpriseTag = trim($request->param("newEnterpriseTag"));
  218. $newIndustryFieldNew = trim($request->param("newIndustryFieldNew"));
  219. $checkState = trim($request->param("checkState"));
  220. if ($oldName) {
  221. $where[] = ["oldName", "like", "%{$oldName}%"];
  222. }
  223. if ($oldIdCard) {
  224. $where[] = ["oldIdCard", "like", "%{$oldIdCard}%"];
  225. }
  226. if ($oldLegal) {
  227. $where[] = ["oldLegal", "like", "%{$oldLegal}%"];
  228. }
  229. if ($oldStreet) {
  230. $where[] = ["oldStreet", "=", "{$oldStreet}"];
  231. }
  232. if ($oldEnterpriseTag) {
  233. $where[] = ["oldEnterpriseTag", "=", "{$oldEnterpriseTag}"];
  234. }
  235. if ($oldIndustryFieldNew) {
  236. $where[] = ["oldIndustryFieldNew", "=", "{$oldIndustryFieldNew}"];
  237. }
  238. if ($newName) {
  239. $where[] = ["newName", "like", "%{$newName}%"];
  240. }
  241. if ($newIdCard) {
  242. $where[] = ["newIdCard", "like", "%{$newIdCard}%"];
  243. }
  244. if ($newAgentName) {
  245. $where[] = ["newAgentName", "like", "%{$newAgentName}%"];
  246. }
  247. if ($checkState) {
  248. $where[] = ["checkState", "=", "{$checkState}"];
  249. } else {
  250. $where[] = ['checkState', '>', 1];
  251. }
  252. if ($newStreet) {
  253. $where[] = ["newStreet", "=", "{$newStreet}"];
  254. }
  255. if ($newEnterpriseTag) {
  256. $where[] = ["newEnterpriseTag", "=", "{$newEnterpriseTag}"];
  257. }
  258. if ($newIndustryFieldNew) {
  259. $where[] = ["newIndustryFieldNew", "=", "{$newIndustryFieldNew}"];
  260. }
  261. if ($whereRaw) {
  262. $count = EnterpriseRecord::where($where)->whereRaw($whereRaw)->count();
  263. } else {
  264. $count = EnterpriseRecord::where($where)->count();
  265. }
  266. if ($count > 0) {
  267. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  268. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  269. $streetList = DictApi::selectByParentCode("street");
  270. if ($whereRaw) {
  271. $list = EnterpriseRecord::where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  272. } else {
  273. $list = EnterpriseRecord::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  274. }
  275. foreach ($list as $k => &$v) {
  276. $v['oldStreetName'] = $streetList[$v['oldStreet']];
  277. $v['newStreetName'] = $streetList[$v['newStreet']];
  278. $v['oldEnterpriseTagName'] = $talentTypeList[$v['oldEnterpriseTag']];
  279. $v['newEnterpriseTagName'] = $talentTypeList[$v['newEnterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  280. $v['oldIndustryFieldNewName'] = $industryFieldNewList[$v['oldIndustryFieldNew']];
  281. $v['newIndustryFieldNewName'] = $industryFieldNewList[$v['newIndustryFieldNew']];
  282. }
  283. } else {
  284. $list = [];
  285. }
  286. return ["total" => $count, "rows" => $list];
  287. }
  288. public static function updateById($data) {
  289. return Enterprise::update($data);
  290. }
  291. public static function getOneRecord($id) {
  292. return EnterpriseRecord::findOrEmpty($id);
  293. }
  294. }