EnterpriseApi.php 10 KB

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