EnterpriseApi.php 8.0 KB

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