Commit e87e12f3 by 杨树贤

优化黑名单

parent 5fbcd9a6
......@@ -300,7 +300,9 @@ class SupplierApiController extends Controller
$supplierId = $request->get('supplier_id');
$region = $request->get('region');
$model = new SupplierChannelModel();
$regionType = $region == SupplierChannelModel::REGION_CN ? 1 : 2;
$unitedCompanyInfo = (new CompanyService())->getUnitedCompanyInfo($supplierName, $taxNumber, $regionType);
//如果是编辑操作,则要忽略非当前
if ($supplierId) {
$originSupplierName = $model->where('supplier_id', $supplierId)->value('supplier_name');
......@@ -318,13 +320,26 @@ class SupplierApiController extends Controller
if ($existedSupplierName) {
$this->response(-1, '供应商已存在,请重新输入或者咨询审批人');
}
//还要去检测是否是一体化黑名单
//新增的时候要先去检验下一体化的数据,如果是实体黑名单用户,那么就不允许新增
//还要校验提交上来的公司是否有合法信息
$unitedInfo = $unitedCompanyInfo['united_company_info'];
if ($unitedInfo) {
if ($unitedInfo['is_entity'] == 1) {
$this->response(-3, '该供应商已经被一体化系统加入黑名单,不能新增');
}
if ($unitedInfo['company_category'] != '') {
if ($unitedInfo['company_category'] != '普通供应商') {
$this->response(-3, '该供应商已经被一体化系统加入黑名单,不能新增');
}
}
}
}
$company = [];
//判断用户选的地区是不是需要校验的,不需要直接返回即可
if (in_array($region, config('field.NeedCheckCompanyRegion'))) {
$regionType = $region == SupplierChannelModel::REGION_CN ? 1 : 2;
//还要去请求天眼查获取资料
$company = (new CompanyService())->getCompanyInfo($supplierName, $taxNumber, $regionType);
$company = $unitedCompanyInfo['company'];
if (!$company) {
$this->response(-2, '公司未进行工商注册,请修改后重新提交');
}
......
......@@ -20,6 +20,7 @@ class SupplierSyncController extends BaseSyncController
'company_name',
'init_nature',
'company_nature',
'company_category',
]);
$rules = [
......@@ -28,6 +29,7 @@ class SupplierSyncController extends BaseSyncController
"company_name" => "required",
"init_nature" => 'required',
"company_nature" => "required",
"company_category" => "required",
];
$validator = Validator::make($rules, $rules);
......
......@@ -12,12 +12,44 @@ use Illuminate\Support\Facades\DB;
class CompanyService
{
//获取一体化的所有信息
public function getUnitedCompanyInfo($supplierName, $taxNumber, $regionType = 1)
{
$params = [
'company_name' => $supplierName,
'region' => $regionType,
'company_type' => 2,
'company_tax_no' => $taxNumber,
];
$url = config('website.UnitedDataDomain') . '/sync/Company/getCompanyInfoByName';
$result = curl($url, $params);
$result = json_decode($result, true);
$unitedCompanyInfo = [];
if (array_get($result, 'code') === 0) {
$unitedCompanyInfo['united_company_info'] = !empty($result['data']['companyInfo']) ? $result['data']['companyInfo'] : [];
$company = [];
$companyInfoList = array_get(array_get($result['data'], 'tycList'), 'company_info_list');
if (!empty($companyInfoList)) {
$companyInfo = $companyInfoList[0];
$company = [
'supplier_name' => $companyInfo['com_name'] == $supplierName ? $companyInfo['com_name'] : $companyInfo['en_com_name'],
'registered_capital' => (int)$companyInfo['registered_capital'],
'supplier_address' => $companyInfo['com_address'],
'tax_number' => $companyInfo['tyc_info']['tax_number'],
'phone' => $companyInfo['tyc_info']['phone_number'],
];
}
$unitedCompanyInfo['company'] = $company;
}
return $unitedCompanyInfo;
}
public function getCompanyInfo($supplierName, $taxNumber, $regionType = 1)
{
$params = [
'company_name' => $supplierName,
'region' => $regionType,
'company_type' => 1,
'company_type' => 2,
'company_tax_no' => $taxNumber,
];
$url = config('website.UnitedDataDomain') . '/sync/Company/getCompanyInfoByName';
......
......@@ -145,6 +145,7 @@ class SyncSupplierService
* "company_name":"\u6d4b\u8bd5\u516c\u53f8",//公司名
* "init_nature":"1234567",//初鉴性质
* "company_nature":"1234567"//公司真实性质
* "company_category":"普通供应商"//公司类别,只要不是普"通供应商",就是要拉黑的
* }
**/
//接收一体化系统处理好的供应商数据,可能是第一次新增返回的数据,也可能是一体化那边修改的数据需要同步到供应商
......@@ -152,26 +153,34 @@ class SyncSupplierService
{
$groupCode = array_get($syncResult, 'group_code');
$sourceSn = array_get($syncResult, 'source_sn');
$supplierId = $sourceSn;
if ($supplierId) {
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first();
$companyCategory = array_get($syncResult, 'company_category', '');
$isEntity = array_get($syncResult, 'is_entity', 0);
$supplier = SupplierChannelModel::where('supplier_id', $sourceSn)->orWhere('group_code', $groupCode)->first();
$supplier = !empty($supplier) ? $supplier->toArray() : [];
$redis = new RedisModel();
$redis->hset('supplier_sync_backup', $supplierId, json_encode($supplier));
$supplierId = $supplier['supplier_id'];
if ($companyCategory != '') {
//实体名单和黑名单都要拉黑,如果不属于黑名单,那么就要将状态改成审核中
if ($companyCategory != '普通供应商') {
$data['status'] = SupplierChannelModel::STATUS_BLOCK;
} elseif ($isEntity) {
$data['status'] = SupplierChannelModel::STATUS_BLOCK;
} else {
$data['status'] = SupplierChannelModel::STATUS_IN_REVIEW;
}
}
$data['sync_united_status'] = SupplierChannelModel::SYNC_UNITED_STATUS_OK;
$data['group_code'] = $groupCode;
$data['company_nature'] = $syncResult['company_nature'];
$data['company_category'] = $companyCategory;
//$sourceSn不为空的话,就是代表这是第一次新增的供应商,所以会回传供应商id过来
if ($sourceSn) {
$data['supplier_name'] = $syncResult['company_name'];
return SupplierChannelModel::where('supplier_id', $supplierId)
->update([
'supplier_name' => $syncResult['company_name'],
'sync_united_status' => SupplierChannelModel::SYNC_UNITED_STATUS_OK,
'group_code' => $groupCode,
'company_nature' => $syncResult['company_nature'],
]);
->update($data);
} else {
return SupplierChannelModel::where('group_code', $groupCode)
->update([
'sync_united_status' => SupplierChannelModel::SYNC_UNITED_STATUS_OK,
'group_code' => $groupCode,
'company_nature' => $syncResult['company_nature'],
]);
->update($data);
}
}
......
......@@ -25,16 +25,37 @@ class SupplierValidator
return null;
}
$isAdd = empty($supplier['supplier_id']) ? true : false;
//新增的时候要先去检验下一体化的数据,如果是实体黑名单用户,那么就不允许新增
$regionType = $validateData['region'] == SupplierChannelModel::REGION_CN ? 1 : 2;
//还要校验提交上来的公司是否有合法信息
$unitedCompanyInfo = (new CompanyService())->getUnitedCompanyInfo($validateData['supplier_name'],
$validateData['tax_number'],
$regionType);
$unitedInfo = $unitedCompanyInfo['united_company_info'];
if ($unitedInfo && $isAdd) {
if ($unitedInfo['is_entity'] == 1) {
return '该供应商已经被一体化系统加入黑名单,不能新增';
}
if ($unitedInfo['company_category'] != '') {
if ($unitedInfo['company_category'] != '普通供应商') {
return '该供应商已经被一体化系统加入黑名单,不能新增';
}
}
}
//没有忽略校验的权限并且供应商地区属于内地和港台才会去校验天眼查
if (!checkPerm('IgnoreCompanyCheck') && in_array($validateData['region'],
config('field.NeedCheckCompanyRegion'))) {
$needCheckFlag = false;
//新增的校验,然后修改的话,如果没有集团编码,并且是标准添加(非标准添加,即是特殊权限添加,不需要校验),也要去校验
if (empty($validateData['supplier_id'])) {
if ($isAdd) {
$needCheckFlag = true;
}
if (!empty($validateData['supplier_id'])) {
if (!$isAdd) {
$supplier = SupplierChannelModel::where('supplier_id', $validateData['supplier_id'])
->first()->toArray();
if (empty($supplier['group_code']) && $supplier['is_standard_add'] == 1) {
......@@ -42,11 +63,7 @@ class SupplierValidator
}
}
if ($needCheckFlag) {
$regionType = $validateData['region'] == SupplierChannelModel::REGION_CN ? 1 : 2;
//还要校验提交上来的公司是否有合法信息
$companyInfo = (new CompanyService())->getCompanyInfo($validateData['supplier_name'],
$validateData['tax_number'],
$regionType);
$companyInfo = $unitedCompanyInfo['company'];
if (empty($companyInfo)) {
return '公司未进行工商注册,请修改后重新提交';
}
......@@ -97,7 +114,6 @@ class SupplierValidator
'cn_delivery_time' => 'regex:/^\d+\-\d$/',
'us_delivery_time' => 'regex:/^\d+\-\d$/',
'shipping_address' => 'max:100',
//'billing_period_detail' => 'required|max:100',
'return_address' => 'max:100',
'return_consignee' => 'max:50',
'return_phone' => 'max:50',
......@@ -126,7 +142,7 @@ class SupplierValidator
//只有在提交供应商是正式的时候,才会去校验附件
//校验附件这块,新增和修改判断的逻辑不一样
if (empty($supplierId)) {
if ($isAdd) {
$attachmentFields = array_unique(array_get($validateData, 'field_name', []));
} else {
$attachmentFields = SupplierAttachmentsModel::where('supplier_id',
......@@ -149,10 +165,6 @@ class SupplierValidator
}
}
// if (!in_array('billing_information', $attachmentFields) && $validateData['currency'] == 1) {
// $errorMessageList[] = '如果选择币种为人民币,开票资料必须上传';
// }
if ($validateData['supplier_type'] == SupplierChannelModel::SUPPLIER_TYPE_OFFICIAL && !in_array($validateData['supplier_group'],
[SupplierChannelModel::SUPPLIER_TYPE_OFFICIAL, SupplierChannelModel::SUPPLIER_GROUP_PROXY])) {
if (!in_array('quality_assurance_agreement', $attachmentFields)) {
......@@ -173,7 +185,7 @@ class SupplierValidator
}
}
if (!$supplierId) {
if ($isAdd) {
//附件信息校验
foreach ($validateData['validity_type'] as $key => $type) {
//最后一个跳过,因为是模板里的数据
......@@ -224,7 +236,7 @@ class SupplierValidator
//联系人校验
if (empty($supplierId)) {
if ($isAdd) {
$rules = array_merge($rules, $contactRuler);
} else {
//修改的时候,还要去判断联系人是否有
......@@ -275,7 +287,7 @@ class SupplierValidator
}
}
if (!empty($supplierId)) {
if (!$isAdd) {
//还要去判断当前提交人是否存在与其关联的联系人没有完善
$codeId = request()->user->codeId;
$notCompleteContacts = (new SupplierContactModel())->getNotCompletedContacts($supplierId, $codeId);
......
......@@ -60,6 +60,10 @@
self.next().find('p').text(res.err_msg);
$('#supplier_name').prop('disabled', false);
}
} else if (res.err_code === -3) {
layer.msg(res.err_msg, {icon: 5});
self.next().find('p').text(res.err_msg);
$('#supplier_name').prop('disabled', false);
} else {
//这个code代表供应商名称已经存在,自然要检测
layer.msg(res.err_msg, {icon: 5});
......
......@@ -89,9 +89,9 @@
</button>
@endif
@if($supplier['status']==\App\Model\SupplierChannelModel::STATUS_BLOCK && checkPerm('CancelBlockSupplier'))
<button type="button" style="margin-bottom: 25px;margin-top: 5px" id="cancel_block_supplier"
class="layui-btn layui-btn">取消拉黑
</button>
{{-- <button type="button" style="margin-bottom: 25px;margin-top: 5px" id="cancel_block_supplier"--}}
{{-- class="layui-btn layui-btn">取消拉黑--}}
{{-- </button>--}}
@endif
@endif
@if (checkPerm('PrintSupplier'))
......
......@@ -30,9 +30,9 @@
{{-- 申请审核--}}
{{-- </button>--}}
@if(checkPerm('BlockSupplier'))
<button type="button" class="layui-btn layui-btn-sm" id="block_supplier">
拉黑
</button>
{{-- <button type="button" class="layui-btn layui-btn-sm" id="block_supplier">--}}
{{-- 拉黑--}}
{{-- </button>--}}
@endif
@if(request()->user->userId==1000)
<button type="button" class="layui-btn layui-btn-sm" title="该操作可以将供应商同步到供应商" id="sync_supplier_to_erp">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment