Commit a90e6cff by mushishixian

联系人检验并且覆盖

parent f0f57d34
......@@ -53,13 +53,13 @@ class SupplierContactApiController extends Controller
$inUserIdSql = "(" . $inUserIdSql . ")";
if ($inCodeIdSql) {
$query->whereRaw(DB::raw("(admin_id in $inUserIdSql or can_check_uids in $inCodeIdSql)"));
}else{
} else {
$query->whereRaw(DB::raw("(admin_id in $inUserIdSql)"));
}
}else{
} else {
if ($codeId) {
$query->whereRaw("(can_check_uids = $codeId or admin_id = $adminId)");
}else{
} else {
$query->whereRaw("(admin_id = $adminId)");
}
}
......@@ -91,12 +91,19 @@ class SupplierContactApiController extends Controller
$this->response(-1, $validateResult);
}
$service = new SupplierContactService();
$hasNeedReplaceContact = $service->getNeedReplaceContact($data['supplier_id'], $data['can_check_uids']);
$result = $service->saveContact($data);
if (!$result) {
$this->response(-1, '操作失败');
}
//有需要自动替换补全数据操作后的提示
if ($hasNeedReplaceContact) {
$this->response(0, '系统检测到当前采购有默认的空联系人,直接更新对应数据');
}else{
$this->response(0, '保存成功');
}
}
public function DeleteSupplierContact($request)
{
......
......@@ -46,18 +46,32 @@ class SupplierContactService
//还要将采购的数据整理重新写入
$supplierId = $contact['supplier_id'];
$supplierModel = new SupplierChannelModel();
//去判断该供应商是否已经有相同的can_check_uids并且是空联系人
$needReplaceContact = $this->getNeedReplaceContact($supplierId, $contact['can_check_uids']);
if (!empty($contact['contact_id'])) {
$contact['update_time'] = time();
$contactId = $contact['contact_id'];
$oldContact = $model->where('contact_id', $contact['contact_id'])->first()->toArray();
$result = $model->where('contact_id', $contact['contact_id'])->update($contact);
} else {
//进行新增操作的时候,还要去判断是否这次新增的采购员ID在库里面是否有空白联系人的记录
//有的话直接替换就可以
if ($needReplaceContact) {
$oldContact = $model->where('contact_id', $needReplaceContact['contact_id'])->first()->toArray();
$contactId = $needReplaceContact['contact_id'];
$contact['contact_id'] = $contactId;
$contact['update_time'] = time();
$contact['admin_id'] = request()->user->userId;
$result = $model->where('contact_id', $contactId)->update($contact);
}else{
$oldContact = [];
$contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId;
$result = $model->insertGetId($contact);
$contactId = $result;
}
}
//找出所有的联系人对应的采购id,更新主表
$canCheckUids = $model->where('supplier_id', $supplierId)->pluck('can_check_uids');
if (!empty($canCheckUids)) {
......@@ -96,6 +110,20 @@ class SupplierContactService
return $result;
}
//判断是否需要替换掉空的联系方式而不是新增,因为新增的时候,可能添加的采购已经在数据库有了(之前从金蝶导过来的)
//有的话,就把这次新增的联系方式更新到这个采购里面去
public function getNeedReplaceContact($supplierId, $canCheckUids)
{
$contactModel = new SupplierContactModel();
$contact = $contactModel->where('supplier_id', $supplierId)->where('can_check_uids', $canCheckUids)
->where('supplier_consignee', '')
->where('supplier_position', '')
->where('supplier_email', '')
->where('supplier_mobile', '')
->where('supplier_telephone', '')->first();
return !empty($contact) ? $contact->toArray() : [];
}
//判断是否要进入待审核状态,因为部分字段修改是不需要走审核的
private function checkNeedAudit($oldContact, $newContact)
{
......
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