| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 | <?phpnamespace app\common\api;use app\admin\controller\EnterpriseChangeRecord;use app\common\api\CompanyApi;use app\enterprise\model\EnterpriseRecord;use think\facade\Db;use app\admin\model\Enterprise;class EnterpriseApi {    public static function getOne($id) {        return Enterprise::findOrEmpty($id);    }    public static function getSimpleList() {        $where[] = ["active", "=", 1];        return $list = Enterprise::where($where)->order("name", 'asc')->field("name,id")->select()->toArray();    }    public static function getList($request) {        $companyId = session('user')['companyId'];        $company_info = CompanyApi::getOne($companyId);        $where = [];        $whereRaw = "";        if ($company_info['code'] != 'super') {            $where[] = ['type', '=', session('user')['type']];            if (session('user')['type'] == 1) {                $whr[] = ["companyId", "=", $companyId];                $whr[] = ["delete", "=", 0];                $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();                $talentType = []; //查找单位对应标签                $org = [];                $ins = [];                $uniCodes = []; //查找单位对应例外                foreach ($list as $k => $v) {                    if(!empty($v['enterpriseTag'])){                        array_push($talentType, $v['enterpriseTag']);                    }                    if(!empty($v['organizationTag'])){                        array_push($org, $v['organizationTag']);                    }                    if(!empty($v['institutionTag'])){                        array_push($ins, $v['institutionTag']);                    }                    if(!empty($v["uniCode"])){                        $codes = explode(",", $v["uniCode"]);                        $uniCodes = array_merge($uniCodes, (array) $codes);                    }                }                $_whr[] = ["uniCode", "<>", ""];                $_whr[] = ["delete", "=", 0];                $_whr[] = ["companyId", "<>", $companyId];                $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();                $expUniCodes = []; //排除其它单位的例外                foreach ($_list as $_v) {                    $codes = explode(",", $_v["uniCode"]);                    $expUniCodes = array_merge($expUniCodes, (array) $codes);                }                if (($talentType || $org || $ins) && $uniCodes) {                    if ($expUniCodes) {                        $whereRaw = sprintf('(enterpriseTag in ("%s") and organizationTag in ("%s") and institutionTag in ("%s") and idCard not in ("%s")) or idCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $expUniCodes), implode('","', $uniCodes));                    } else {                        $whereRaw = sprintf('enterpriseTag in ("%s") and organizationTag in ("%s") and institutionTag in ("%s") or idCard in ("%s")', implode('","', $talentType), implode('","', $org), implode('","', $ins), implode('","', $uniCodes));                    }                }                if (($talentType || $org || $ins) && !$uniCodes) {                    if($talentType){                        $where[] = ["enterpriseTag", "in", $talentType];                    }                    if($org){                        $where[] = ["organizationTag", "in", $org];                    }                    if($ins){                        $where[] = ["institutionTag", "in", $ins];                    }                    if ($expUniCodes) {                        $where[] = ["idCard", "not in", $expUniCodes];                    }                }                if (!$talentType && !$org && !$ins && $uniCodes) {                    $where[] = ["idCard", "in", $uniCodes];                }            }        }        $offset = trim($request->param("offset")) ?: 0;        $limit = trim($request->param("limit")) ?: 10;        $name = trim($request->param("name"));        $idCard = trim($request->param("idCard"));        $legal = trim($request->param("legal"));        $ephone = trim($request->param("ephone"));        $agentName = trim($request->param("agentName"));        $agentPhone = trim($request->param("agentPhone"));        $checkState = trim($request->param("checkState"));        $active = trim($request->param("active"));        $street = trim($request->param("street"));        $enterpriseTag = trim($request->param("enterpriseTag"));        $industryFieldNew = trim($request->param("industryFieldNew"));        if ($name) {            $where[] = ["name", "like", "%{$name}%"];        }        if ($idCard) {            $where[] = ["idCard", "like", "%{$idCard}%"];        }        if ($legal) {            $where[] = ["legal", "like", "%{$legal}%"];        }        if ($ephone) {            $where[] = ["ephone", "like", "%{$ephone}%"];        }        if ($agentName) {            $where[] = ["agentName", "like", "%{$agentName}%"];        }        if ($agentPhone) {            $where[] = ["agentPhone", "like", "%{$agentPhone}%"];        }        if ($checkState) {            $where[] = ["checkState", "=", "{$checkState}"];        }        if ($active) {            $where[] = ["active", "=", "{$active}"];        }        if ($street) {            $where[] = ["street", "=", "{$street}"];        }        if ($enterpriseTag) {            $where[] = ["enterpriseTag", "=", "{$enterpriseTag}"];        }        if ($industryFieldNew) {            $where[] = ["industryFieldNew", "=", "{$industryFieldNew}"];        }        if ($whereRaw) {            $count = Enterprise::where($where)->whereRaw($whereRaw)->count();        } else {            $count = Enterprise::where($where)->count();        }        if ($count > 0) {            $talentTypeList = DictApi::selectByParentCode("enterprise_tag");            $orgList = DictApi::selectByParentCode("organization_tag");            $insList = DictApi::selectByParentCode("institution_tag");            $industryFieldNewList = DictApi::selectByParentCode("industry_field");            $streetList = DictApi::selectByParentCode("street");            //dd($talentTypeList);            if ($whereRaw) {                $list = Enterprise::where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();            } else {                $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();            }            foreach ($list as $k => &$v) {                unset($v['password']);                $v['enterpriseTagName'] = array_key_exists($v['enterpriseTag'],$talentTypeList) ? $talentTypeList[$v['enterpriseTag']] : ''; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写                $v['organizationTagName'] = array_key_exists($v['organizationTag'],$orgList) ? $orgList[$v['organizationTag']] : '';                $v['institutionTagName'] = array_key_exists($v['institutionTag'],$orgList) ? $orgList[$v['institutionTag']] : '';                $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];                $v['streetName'] = $streetList[$v['street']];            }        } else {            $list = [];        }        return ["total" => $count, "rows" => $list];    }    public static function getRecordList($request) {        $companyId = session('user')['companyId'];        $company_info = CompanyApi::getOne($companyId);        $where = [];        $whereRaw = "";        if ($company_info['code'] != 'super') {            $where[] = ['type', '=', session('user')['type']];            if (session('user')['type'] == 1) {                $whr[] = ["companyId", "=", $companyId];                $whr[] = ["delete", "=", 0];                $list = \app\common\model\EnterpriseVerifyMgr::where($whr)->select()->toArray();                $talentType = [];                $uniCodes = [];                foreach ($list as $k => $v) {                    array_push($talentType, $v['enterpriseTag']);                    $codes = explode(",", $v["uniCode"]);                    $uniCodes = array_merge($uniCodes, (array) $codes);                }                $_whr[] = ["uniCode", "<>", ""];                $_whr[] = ["delete", "=", 0];                $_whr[] = ["companyId", "<>", $companyId];                $_list = \app\common\model\EnterpriseVerifyMgr::where($_whr)->select()->toArray();                $expUniCodes = []; //排除其它单位的例外                foreach ($_list as $_v) {                    $codes = explode(",", $_v["uniCode"]);                    $expUniCodes = array_merge($expUniCodes, (array) $codes);                }                if ($talentType && $uniCodes) {                    if ($expUniCodes) {                        $whereRaw = sprintf('(newEnterpriseTag in ("%s") and newIdCard not in ("%s")) or newIdCard in ("%s")', implode('","', $talentType), implode('","', $expUniCodes), implode('","', $uniCodes));                    } else {                        $whereRaw = sprintf('newEnterpriseTag in ("%s") or newIdCard in ("%s")', implode('","', $talentType), implode('","', $uniCodes));                    }                }                if ($talentType && !$uniCodes) {                    $where[] = ["newEnterpriseTag", "in", $talentType];                    if ($expUniCodes) {                        $where[] = ["newIdCard", "not in", $expUniCodes];                    }                }                if (!$talentType && $uniCodes) {                    $where[] = ["newIdCard", "in", $uniCodes];                }            }        }        $offset = trim($request->param("offset")) ?: 0;        $limit = trim($request->param("limit")) ?: 10;        $oldName = trim($request->param("oldName"));        $oldIdCard = trim($request->param("oldIdCard"));        $oldLegal = trim($request->param("oldLegal"));        $oldStreet = trim($request->param("oldStreet"));        $oldEnterpriseTag = trim($request->param("oldEnterpriseTag"));        $oldIndustryFieldNew = trim($request->param("oldIndustryFieldNew"));        $newName = trim($request->param("newName"));        $newIdCard = trim($request->param("newIdCard"));        $newAgentName = trim($request->param("newAgentName"));        $newStreet = trim($request->param("newStreet"));        $newEnterpriseTag = trim($request->param("newEnterpriseTag"));        $newIndustryFieldNew = trim($request->param("newIndustryFieldNew"));        $checkState = trim($request->param("checkState"));        if ($oldName) {            $where[] = ["oldName", "like", "%{$oldName}%"];        }        if ($oldIdCard) {            $where[] = ["oldIdCard", "like", "%{$oldIdCard}%"];        }        if ($oldLegal) {            $where[] = ["oldLegal", "like", "%{$oldLegal}%"];        }        if ($oldStreet) {            $where[] = ["oldStreet", "=", "{$oldStreet}"];        }        if ($oldEnterpriseTag) {            $where[] = ["oldEnterpriseTag", "=", "{$oldEnterpriseTag}"];        }        if ($oldIndustryFieldNew) {            $where[] = ["oldIndustryFieldNew", "=", "{$oldIndustryFieldNew}"];        }        if ($newName) {            $where[] = ["newName", "like", "%{$newName}%"];        }        if ($newIdCard) {            $where[] = ["newIdCard", "like", "%{$newIdCard}%"];        }        if ($newAgentName) {            $where[] = ["newAgentName", "like", "%{$newAgentName}%"];        }        if ($checkState) {            $where[] = ["checkState", "=", "{$checkState}"];        } else {            $where[] = ['checkState', '>', 1];        }        if ($newStreet) {            $where[] = ["newStreet", "=", "{$newStreet}"];        }        if ($newEnterpriseTag) {            $where[] = ["newEnterpriseTag", "=", "{$newEnterpriseTag}"];        }        if ($newIndustryFieldNew) {            $where[] = ["newIndustryFieldNew", "=", "{$newIndustryFieldNew}"];        }        if ($whereRaw) {            $count = EnterpriseRecord::where($where)->whereRaw($whereRaw)->count();        } else {            $count = EnterpriseRecord::where($where)->count();        }        if ($count > 0) {            $talentTypeList = DictApi::selectByParentCode("enterprise_tag");            $industryFieldNewList = DictApi::selectByParentCode("industry_field");            $streetList = DictApi::selectByParentCode("street");            if ($whereRaw) {                $list = EnterpriseRecord::where($where)->whereRaw($whereRaw)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();            } else {                $list = EnterpriseRecord::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();            }            foreach ($list as $k => &$v) {                $v['oldStreetName'] = $streetList[$v['oldStreet']];                $v['newStreetName'] = $streetList[$v['newStreet']];                $v['oldEnterpriseTagName'] = $talentTypeList[$v['oldEnterpriseTag']];                $v['newEnterpriseTagName'] = $talentTypeList[$v['newEnterpriseTag']]; //此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写                $v['oldIndustryFieldNewName'] = $industryFieldNewList[$v['oldIndustryFieldNew']];                $v['newIndustryFieldNewName'] = $industryFieldNewList[$v['newIndustryFieldNew']];            }        } else {            $list = [];        }        return ["total" => $count, "rows" => $list];    }    public static function updateById($data) {        return Enterprise::update($data);    }    public static function getOneRecord($id) {        return EnterpriseRecord::findOrEmpty($id);    }}
 |