Commit d13f1539 by mushishixian

fix

parent de503a64
......@@ -111,7 +111,7 @@ class SupplierContactApiController extends Controller
]);
$logService = new LogService();
$content = '删除联系人';
$remark = json_encode($contact);
$remark = json_encode(['old_contact' => $contact, 'new_contact' => []]);
$logService->AddLog($contact['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
$this->response(0, '删除成功');
}
......
......@@ -134,4 +134,67 @@ class LogService
return $result;
}
public function compareContactChange($oldContact, $newContact)
{
}
//获取修改联系人的变化内容
public function getContactDesc($contact)
{
$desc = '';
if (!empty($contact)) {
$contact = json_decode($contact, true);
//更新
if (!empty($contact['old_contact']) && !empty($contact['new_contact'])) {
// $diffCols = array_diff($contact['old_contact'], $contact['new_contact']);
$oldContent = $this->contactDesc($contact['old_contact']);
$newContent = $this->contactDesc($contact['new_contact']);
return $oldContent . ' 修改为=> ' . $newContent;
}
//新增
if (empty($contact['old_contact']) && !empty($contact['new_contact'])) {
$newContent = $this->contactDesc($contact['new_contact']);
return $newContent;
}
//删除
if (!empty($contact['old_contact']) && empty($contact['new_contact'])) {
$oldContent = $this->contactDesc($contact['old_contact']);
return $oldContent;
}
}
return $desc;
}
private function contactDesc($contact)
{
$cloNameMap = [
'supplier_consignee' => '联系名称',
'supplier_telephone' => '电话号码',
'supplier_fax' => '传真',
'supplier_qq' => 'QQ',
'supplier_mobile' => '联系方式',
'supplier_email' => '邮箱',
'supplier_position' => '职位',
'can_check_uids' => '采购',
];
$desc = '';
foreach ($contact as $key => $value) {
$colName = array_get($cloNameMap, $key);
if (empty($colName)) {
continue;
}
if ($key == 'can_check_uids') {
$service = new AdminUserService();
$user = $service->getAdminUserInfoByCodeId($value);
$value = array_get($user, 'name');
}
$desc .= $colName . ' : ' . $value . ' | ';
}
return $desc;
}
}
\ No newline at end of file
......@@ -53,11 +53,15 @@ class SupplierContactService
});
if (!empty($contact['contact_id'])) {
$contact['update_time'] = time();
$contactId = $contact['contact_id'];
$result = $model->where('contact_id', $contact['contact_id'])->update($contact);
$oldContact = $model->where('contact_id', $contact['contact_id'])->first()->toArray();
} else {
$oldContact = [];
$contact['add_time'] = time();
$contact['admin_id'] = request()->user->userId;
$result = $model->insert($contact);
$result = $model->insertGetId($contact);
$contactId = $result;
}
//不存在则写入
if (!in_array($contact['can_check_uids'], $channelUid)) {
......@@ -67,6 +71,7 @@ class SupplierContactService
'channel_uid'=>implode(',',$channelUid),
'update_time' => time(),
]);
$newContact = $model->where('contact_id', $contactId)->first()->toArray();
if ($result) {
//修改供应商为审核状态
$supplierModel = new SupplierChannelModel();
......@@ -76,7 +81,10 @@ class SupplierContactService
]);
$logService = new LogService();
$content = !empty($contact['contact_id'])?'修改联系人':'添加联系人';
$remark = json_encode($contact);
$remark = json_encode([
'old_contact'=>$oldContact,
'new_contact' => $newContact,
]);
$logService->AddLog($contact['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
}
......
......@@ -22,16 +22,20 @@ class LogTransformer
{
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
$item['type'] = array_get(config('fixed.LogType'), $item['type']);
$logService = new LogService();
//如果action是修改供应商,就要做对比处理
if ($item['action'] === '修改供应商基本资料') {
if ($item['content'] === '修改供应商') {
$logService = new LogService();
$remark = json_decode($item['remark'], true);
$oldSupplier = array_get($remark, 'old_supplier');
$newSupplier = array_get($remark, 'new_supplier');
$content = $logService->compareSupplierChange($newSupplier, $oldSupplier);
$item['content'] = $content;
}
if (!is_array($item['content'])&&strpos($item['content'], '联系') !== false) {
$item['content'] = $item['content'] .':'.$logService->getContactDesc($item['remark']);
}
}
return $item;
}
......
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