EnterpriseApi.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. if ($company_info['code'] != 'super') {
  21. $where[] = ['type', '=', session('user')['type']];
  22. if (session('user')['type'] == 1) {
  23. $list = Db::table('sys_enterprisetype_properties')->where('companyIds', 'like', "%{$companyId}%")->select()->toArray();
  24. $talentType = [];
  25. foreach ($list as $k => $v) {
  26. array_push($talentType, $v['talentType']);
  27. }
  28. $where[] = ['enterpriseTag', 'in', $talentType];
  29. }
  30. }
  31. $offset = trim($request->param("offset")) ?: 0;
  32. $limit = trim($request->param("limit")) ?: 10;
  33. $name = trim($request->param("name"));
  34. $idCard = trim($request->param("idCard"));
  35. $legal = trim($request->param("legal"));
  36. $ephone = trim($request->param("ephone"));
  37. $agentName = trim($request->param("agentName"));
  38. $agentPhone = trim($request->param("agentPhone"));
  39. $checkState = trim($request->param("checkState"));
  40. $active = trim($request->param("active"));
  41. $street = trim($request->param("street"));
  42. $enterpriseTag = trim($request->param("enterpriseTag"));
  43. $industryFieldNew = trim($request->param("industryFieldNew"));
  44. if ($name) {
  45. $where[] = ["name", "like", "%{$name}%"];
  46. }
  47. if ($idCard) {
  48. $where[] = ["idCard", "like", "%{$idCard}%"];
  49. }
  50. if ($legal) {
  51. $where[] = ["legal", "like", "%{$legal}%"];
  52. }
  53. if ($ephone) {
  54. $where[] = ["ephone", "like", "%{$ephone}%"];
  55. }
  56. if ($agentName) {
  57. $where[] = ["agentName", "like", "%{$agentName}%"];
  58. }
  59. if ($agentPhone) {
  60. $where[] = ["agentPhone", "like", "%{$agentPhone}%"];
  61. }
  62. if ($checkState) {
  63. $where[] = ["checkState", "=", "{$checkState}"];
  64. }
  65. if ($active) {
  66. $where[] = ["active", "=", "{$active}"];
  67. }
  68. if ($street) {
  69. $where[] = ["street", "=", "{$street}"];
  70. }
  71. if ($enterpriseTag) {
  72. $where[] = ["enterpriseTag", "=", "{$enterpriseTag}"];
  73. }
  74. if ($industryFieldNew) {
  75. $where[] = ["industryFieldNew", "=", "{$industryFieldNew}"];
  76. }
  77. $count = Enterprise::where($where)->count();
  78. if ($count > 0) {
  79. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  80. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  81. $streetList = DictApi::selectByParentCode("street");
  82. //dd($talentTypeList);
  83. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  84. foreach ($list as $k => &$v) {
  85. unset($v['password']);
  86. $v['enterpriseTagName'] = $talentTypeList[$v['enterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  87. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  88. $v['streetName'] = $streetList[$v['street']];
  89. }
  90. } else {
  91. $list = [];
  92. }
  93. return ["total" => $count, "rows" => $list];
  94. }
  95. public static function getRecordList($request) {
  96. $companyId = session('user')['companyId'];
  97. $company_info = CompanyApi::getOne($companyId);
  98. $where = [];
  99. if ($company_info['code'] != 'super') {
  100. $where[] = ['type', '=', session('user')['type']];
  101. if (session('user')['type'] == 1) {
  102. $list = Db::table('sys_enterprisetype_properties')->where('companyIds', 'like', $companyId)->select()->toArray();
  103. $talentType = [];
  104. foreach ($list as $k => $v) {
  105. array_push($talentType, $v['talentType']);
  106. }
  107. $where[] = ['newEnterpriseTag', 'in', $talentType];
  108. }
  109. }
  110. $offset = trim($request->param("offset")) ?: 0;
  111. $limit = trim($request->param("limit")) ?: 10;
  112. $oldName = trim($request->param("oldName"));
  113. $oldIdCard = trim($request->param("oldIdCard"));
  114. $oldLegal = trim($request->param("oldLegal"));
  115. $oldStreet = trim($request->param("oldStreet"));
  116. $oldEnterpriseTag = trim($request->param("oldEnterpriseTag"));
  117. $oldIndustryFieldNew = trim($request->param("oldIndustryFieldNew"));
  118. $newName = trim($request->param("newName"));
  119. $newIdCard = trim($request->param("newIdCard"));
  120. $newAgentName = trim($request->param("newAgentName"));
  121. $newStreet = trim($request->param("newStreet"));
  122. $newEnterpriseTag = trim($request->param("newEnterpriseTag"));
  123. $newIndustryFieldNew = trim($request->param("newIndustryFieldNew"));
  124. $checkState = trim($request->param("checkState"));
  125. if ($oldName) {
  126. $where[] = ["oldName", "like", "%{$oldName}%"];
  127. }
  128. if ($oldIdCard) {
  129. $where[] = ["oldIdCard", "like", "%{$oldIdCard}%"];
  130. }
  131. if ($oldLegal) {
  132. $where[] = ["oldLegal", "like", "%{$oldLegal}%"];
  133. }
  134. if ($oldStreet) {
  135. $where[] = ["oldStreet", "=", "{$oldStreet}"];
  136. }
  137. if ($oldEnterpriseTag) {
  138. $where[] = ["oldEnterpriseTag", "=", "{$oldEnterpriseTag}"];
  139. }
  140. if ($oldIndustryFieldNew) {
  141. $where[] = ["oldIndustryFieldNew", "=", "{$oldIndustryFieldNew}"];
  142. }
  143. if ($newName) {
  144. $where[] = ["newName", "like", "%{$newName}%"];
  145. }
  146. if ($newIdCard) {
  147. $where[] = ["newIdCard", "like", "%{$newIdCard}%"];
  148. }
  149. if ($newAgentName) {
  150. $where[] = ["newAgentName", "like", "%{$newAgentName}%"];
  151. }
  152. if ($checkState) {
  153. $where[] = ["checkState", "=", "{$checkState}"];
  154. }
  155. if ($newStreet) {
  156. $where[] = ["newStreet", "=", "{$newStreet}"];
  157. }
  158. if ($newEnterpriseTag) {
  159. $where[] = ["newEnterpriseTag", "=", "{$newEnterpriseTag}"];
  160. }
  161. if ($newIndustryFieldNew) {
  162. $where[] = ["newIndustryFieldNew", "=", "{$newIndustryFieldNew}"];
  163. }
  164. $count = EnterpriseRecord::where($where)->count();
  165. if ($count > 0) {
  166. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  167. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  168. $streetList = DictApi::selectByParentCode("street");
  169. $list = EnterpriseRecord::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  170. foreach ($list as $k => &$v) {
  171. $v['oldStreetName'] = $streetList[$v['oldStreet']];
  172. $v['newStreetName'] = $streetList[$v['newStreet']];
  173. $v['oldEnterpriseTagName'] = $talentTypeList[$v['oldEnterpriseTag']];
  174. $v['newEnterpriseTagName'] = $talentTypeList[$v['newEnterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  175. $v['oldIndustryFieldNewName'] = $industryFieldNewList[$v['oldIndustryFieldNew']];
  176. $v['newIndustryFieldNewName'] = $industryFieldNewList[$v['newIndustryFieldNew']];
  177. }
  178. } else {
  179. $list = [];
  180. }
  181. return ["total" => $count, "rows" => $list];
  182. }
  183. public static function updateById($data) {
  184. return Enterprise::update($data);
  185. }
  186. public static function getOneRecord($id) {
  187. return EnterpriseRecord::findOrEmpty($id);
  188. }
  189. }