Commit 97b3667b by 杨树贤

支持重新提交crm审核

parent 8408576a
...@@ -183,7 +183,32 @@ class SupplierSyncController extends BaseSyncController ...@@ -183,7 +183,32 @@ class SupplierSyncController extends BaseSyncController
// 幂等处理:供应商名称已存在 // 幂等处理:供应商名称已存在
$existingSupplier = SupplierChannelModel::where('supplier_name', $customerName)->first(); $existingSupplier = SupplierChannelModel::where('supplier_name', $customerName)->first();
if ($existingSupplier) { if ($existingSupplier) {
// CRM再次提交:仅当来源为CRM且状态为待确认(采购驳回后恢复待确认)时,更新数据 // 如果状态为待确认或CRM转移供应商不通过,说明CRM重新同步了,改回待确认状态并更新信息
if (!in_array($existingSupplier['status'], [SupplierChannelModel::STATUS_CONFIRM, SupplierChannelModel::STATUS_CRM_REJECTED])) {
Log::info('[CRM同步]供应商已存在且为正式供应商,跳过: ' . $customerName);
$this->syncResponse(-1, '供应商已存在,跳过');
}
// 如果状态为CRM转移供应商不通过,说明CRM重新同步了,改回待确认状态并更新信息
if (
$existingSupplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM
&& $existingSupplier['status'] == SupplierChannelModel::STATUS_CRM_REJECTED
) {
try {
// 先更新状态为待确认
SupplierChannelModel::where('supplier_id', $existingSupplier['supplier_id'])->update([
'status' => SupplierChannelModel::STATUS_CONFIRM,
'update_time' => time(),
]);
// 然后更新供应商信息
$this->updateCrmSupplier($existingSupplier, $data);
$this->syncResponse(0, 'CRM重新同步,状态已恢复为待确认并更新信息', ['supplier_id' => $existingSupplier['supplier_id']]);
} catch (\Exception $e) {
Log::error('[CRM同步]恢复待确认状态并更新失败: ' . $e->getMessage(), ['data' => $data]);
$this->syncResponse(-1, '恢复状态并更新失败: ' . $e->getMessage());
}
}
// CRM再次提交:当来源为CRM且状态为待确认时,更新数据
if ( if (
$existingSupplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM $existingSupplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM
&& $existingSupplier['status'] == SupplierChannelModel::STATUS_CONFIRM && $existingSupplier['status'] == SupplierChannelModel::STATUS_CONFIRM
...@@ -193,9 +218,10 @@ class SupplierSyncController extends BaseSyncController ...@@ -193,9 +218,10 @@ class SupplierSyncController extends BaseSyncController
$this->syncResponse(0, 'CRM再次提交更新成功', ['supplier_id' => $existingSupplier['supplier_id']]); $this->syncResponse(0, 'CRM再次提交更新成功', ['supplier_id' => $existingSupplier['supplier_id']]);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('[CRM同步]再次提交更新失败: ' . $e->getMessage(), ['data' => $data]); Log::error('[CRM同步]再次提交更新失败: ' . $e->getMessage(), ['data' => $data]);
$this->syncResponse(-1, '更新失败: ' . $e->getMessage()); $this->syncResponse(-1, '更新失败: ' . $e->getTraceAsString());
} }
} }
Log::info('[CRM同步]供应商已存在且不满足再次提交条件,跳过: ' . $customerName); Log::info('[CRM同步]供应商已存在且不满足再次提交条件,跳过: ' . $customerName);
$this->syncResponse(-1, '供应商已存在,跳过'); $this->syncResponse(-1, '供应商已存在,跳过');
} }
......
...@@ -13,8 +13,8 @@ class LogService ...@@ -13,8 +13,8 @@ class LogService
//添加日志 //添加日志
public function AddLog($supplierId, $type, $action, $content, $remark = '') public function AddLog($supplierId, $type, $action, $content, $remark = '')
{ {
$adminId = request()->user->userId; $adminId = isset(request()->user->userId) ? request()->user->userId : 0;
$adminName = request()->user->name; $adminName = isset(request()->user->name) ? request()->user->name : '';
$data = [ $data = [
'supplier_id' => $supplierId, 'supplier_id' => $supplierId,
'type' => $type, 'type' => $type,
......
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