EnterpriseApi.php 12 KB

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