Commit bc054980 by 杨树贤

部分审核代码

parent f8fffe03
...@@ -295,6 +295,13 @@ class SupplierApiController extends Controller ...@@ -295,6 +295,13 @@ class SupplierApiController extends Controller
//写日志 //写日志
$logService = new LogService(); $logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '禁用', '禁用供应商,理由是 : ' . $disableReason); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '禁用', '禁用供应商,理由是 : ' . $disableReason);
// CRM来源供应商同步状态到CRM
if ($supplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$crmStatus = CrmService::mapSupplierStatusToCrm(SupplierChannelModel::STATUS_DISABLE);
CrmService::syncSupplierStatus($supplier['supplier_name'], $crmStatus, '禁止交易: ' . $disableReason);
}
$this->response(0, '禁用成功'); $this->response(0, '禁用成功');
} else { } else {
$this->response(-1, '禁用失败'); $this->response(-1, '禁用失败');
...@@ -722,6 +729,14 @@ class SupplierApiController extends Controller ...@@ -722,6 +729,14 @@ class SupplierApiController extends Controller
if ($result) { if ($result) {
$logService = new LogService(); $logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '拉黑', '拉黑供应商'); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '拉黑', '拉黑供应商');
// CRM来源供应商同步状态到CRM
$supplier = $channelModel->where('supplier_id', $supplierId)->first();
if ($supplier && $supplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$crmStatus = CrmService::mapSupplierStatusToCrm(SupplierChannelModel::STATUS_BLOCK);
CrmService::syncSupplierStatus($supplier['supplier_name'], $crmStatus, '拉入黑名单');
}
$this->response(0, '拉黑成功'); $this->response(0, '拉黑成功');
} else { } else {
$this->response(-1, '拉黑操作失败'); $this->response(-1, '拉黑操作失败');
......
...@@ -9,6 +9,8 @@ use App\Http\Services\CrmService; ...@@ -9,6 +9,8 @@ use App\Http\Services\CrmService;
use App\Http\Services\LogService; use App\Http\Services\LogService;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Services\AuditCenterService;
use App\Http\Services\SupplierAuditService;
//CRM转移供应商相关接口 //CRM转移供应商相关接口
class SupplierCrmApiController extends Controller class SupplierCrmApiController extends Controller
...@@ -18,19 +20,10 @@ class SupplierCrmApiController extends Controller ...@@ -18,19 +20,10 @@ class SupplierCrmApiController extends Controller
$this->$id($request, $id); $this->$id($request, $id);
} }
//转化供应商确认 //转化供应商确认 - 提交审批到审核中心
public function ConfirmCrmSupplier($request) public function ConfirmCrmSupplier($request)
{ {
$supplierId = $request->get('supplier_id'); $supplierId = $request->get('supplier_id');
$auditOpinion = $request->get('audit_opinion'); // agree / disagree
$remark = trim($request->get('remark', ''));
if (empty($auditOpinion)) {
$this->response(-1, '必须选择一个审核意见');
}
if ($auditOpinion == 'disagree' && empty($remark)) {
$this->response(-1, '请填写原因说明');
}
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $model->where('supplier_id', $supplierId)->first();
...@@ -45,34 +38,59 @@ class SupplierCrmApiController extends Controller ...@@ -45,34 +38,59 @@ class SupplierCrmApiController extends Controller
$this->response(-1, '该供应商不满足转化条件(须为待确认状态且来源为CRM客户转化)'); $this->response(-1, '该供应商不满足转化条件(须为待确认状态且来源为CRM客户转化)');
} }
$approverName = $request->user->name;
try { try {
if ($auditOpinion == 'agree') { // 提交审批到审核中心
// 同意:状态改为待提审(0) $auditService = new SupplierAuditService();
$result = $auditService->addApproveForCustomerConvert($supplierId, '客户转化供应商审核');
// 更新状态为审核中
$model->where('supplier_id', $supplierId)->update([ $model->where('supplier_id', $supplierId)->update([
'status' => SupplierChannelModel::STATUS_PENDING, 'status' => SupplierChannelModel::STATUS_IN_REVIEW,
'update_time' => time(), 'update_time' => time(),
]); ]);
$approveResult = 'agree';
} else {
// 不同意:状态保持待确认(4)
$approveResult = 'disagree';
}
// 记录日志 // 记录提交审批日志
$logService = new LogService(); $logService = new LogService();
$logContent = '转化供应商确认 - 审核意见: ' . ($auditOpinion == 'agree' ? '同意' : '不同意') $logContent = "确认客户转化供应商:提交审核\n"
. ($remark ? ', 原因说明: ' . $remark : ''); . date('Y-m-d H:i:s') . " " . $request->user->name;
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '转化供应商确认', $logContent); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
// 回传CRM系统:审批人、审批结果、附加说明 $this->response(0, '提交审核成功', $result);
$supplierName = $supplier['supplier_name']; } catch (Exception $e) {
CrmService::confirmCrmSupplier($supplierName, $approverName, $approveResult, $remark); $this->response(-1, '提交审核失败: ' . $e->getMessage());
}
}
$this->response(0, '操作成功'); //客户转化供应商 - 审核操作
public function AuditCustomerConvertSupplier($request)
{
$supplierId = $request->get('supplier_id');
$auditOpinion = $request->get('audit_opinion'); // agree / disagree
$remark = trim($request->get('remark', ''));
if (empty($auditOpinion)) {
$this->response(-1, '必须选择一个审核意见');
}
if ($auditOpinion == 'disagree' && empty($remark)) {
$this->response(-1, '请填写原因说明');
}
$approvalStatus = $auditOpinion == 'agree' ? 1 : 2;
try {
$auditService = new SupplierAuditService();
$result = $auditService->auditCustomerConvertSupplier($supplierId, $approvalStatus, $remark);
$this->response(0, '审核成功');
} catch (Exception $e) { } catch (Exception $e) {
$this->response(-1, '操作失败: ' . $e->getMessage()); $this->response(-1, '审核失败: ' . $e->getMessage());
} }
} }
//获取客户转化供应商审核流程
public function GetCustomerConvertAuditFlow($request)
{
$supplierId = $request->get('supplier_id');
$result = AuditCenterService::getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT);
$this->response(0, 'ok', $result);
}
} }
...@@ -9,6 +9,8 @@ use App\Http\Services\AdminUserService; ...@@ -9,6 +9,8 @@ use App\Http\Services\AdminUserService;
use App\Http\Services\CompanyService; use App\Http\Services\CompanyService;
use App\Http\Services\SupplierService; use App\Http\Services\SupplierService;
use App\Http\Services\SyncSupplierService; use App\Http\Services\SyncSupplierService;
use App\Http\Services\LogService;
use App\Model\LogModel;
use App\Model\SupplierAttachmentsModel; use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
...@@ -178,10 +180,21 @@ class SupplierSyncController extends BaseSyncController ...@@ -178,10 +180,21 @@ class SupplierSyncController extends BaseSyncController
$customerName = trim($data['customer_name']); $customerName = trim($data['customer_name']);
// 幂等处理:供应商名称已存在则直接返回成功 // 幂等处理:供应商名称已存在
$exists = SupplierChannelModel::where('supplier_name', $customerName)->exists(); $existingSupplier = SupplierChannelModel::where('supplier_name', $customerName)->first();
if ($exists) { if ($existingSupplier) {
Log::info('[CRM同步]供应商已存在,跳过: ' . $customerName); // CRM再次提交:仅当来源为CRM且状态为待确认(采购驳回后恢复待确认)时,更新数据
if ($existingSupplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM
&& $existingSupplier['status'] == SupplierChannelModel::STATUS_CONFIRM) {
try {
$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());
}
}
Log::info('[CRM同步]供应商已存在且不满足再次提交条件,跳过: ' . $customerName);
$this->syncResponse(0, '供应商已存在,跳过'); $this->syncResponse(0, '供应商已存在,跳过');
} }
...@@ -324,4 +337,161 @@ class SupplierSyncController extends BaseSyncController ...@@ -324,4 +337,161 @@ class SupplierSyncController extends BaseSyncController
$this->syncResponse(-1, '创建供应商失败: ' . $e->getMessage()); $this->syncResponse(-1, '创建供应商失败: ' . $e->getMessage());
} }
} }
/**
* CRM再次提交 - 更新待确认状态的供应商数据
* 采购驳回后CRM可再次提交,更新原待确认数据,记录日志
*/
private function updateCrmSupplier($existingSupplier, $data)
{
$supplierId = $existingSupplier['supplier_id'];
$changeDetails = [];
DB::connection('web')->transaction(function () use ($existingSupplier, $data, $supplierId, &$changeDetails) {
$model = new SupplierChannelModel();
// 比较并更新主表字段
$updateFields = [
'sign_com_id' => array_get($data, 'sign_com_id'),
'channel_uid' => array_get($data, 'purchaser_uid', ''),
];
foreach ($updateFields as $field => $newValue) {
if ($newValue !== null && $existingSupplier[$field] != $newValue) {
$changeDetails[] = "{$field}: {$existingSupplier[$field]}{$newValue}";
}
}
$updateFields['update_time'] = time();
$model->where('supplier_id', $supplierId)->update($updateFields);
// 更新扩展表
$extendData = [];
$existingExtend = SupplierExtendModel::where('supplier_id', $supplierId)->first();
if ($existingExtend) {
$newCreatorName = array_get($data, 'creator_name', '');
if ($newCreatorName && $existingExtend['reverse_purchaser'] != $newCreatorName) {
$changeDetails[] = "reverse_purchaser: {$existingExtend['reverse_purchaser']}{$newCreatorName}";
$extendData['reverse_purchaser'] = $newCreatorName;
}
$newCustomerNature = array_get($data, 'customer_nature', '');
if ($newCustomerNature && $existingExtend['customer_nature'] != $newCustomerNature) {
$changeDetails[] = "customer_nature: {$existingExtend['customer_nature']}{$newCustomerNature}";
$extendData['customer_nature'] = $newCustomerNature;
}
$newCrmRemark = array_get($data, 'crm_remark', '');
if ($existingExtend['crm_remark'] != $newCrmRemark) {
$changeDetails[] = "crm_remark: {$existingExtend['crm_remark']}{$newCrmRemark}";
$extendData['crm_remark'] = $newCrmRemark;
}
if (!empty($extendData)) {
$extendData['update_time'] = time();
SupplierExtendModel::where('supplier_id', $supplierId)->update($extendData);
}
}
// 更新联系人
$contactData = [];
$existingContact = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->first();
if ($existingContact) {
$newContactName = array_get($data, 'contact_name', '');
$newContactEmail = array_get($data, 'contact_email', '');
$newContactMobile = array_get($data, 'contact_mobile', '');
if ($newContactName && $existingContact['supplier_consignee'] != $newContactName) {
$changeDetails[] = "contact_name: {$existingContact['supplier_consignee']}{$newContactName}";
$contactData['supplier_consignee'] = $newContactName;
}
if ($newContactEmail && $existingContact['supplier_email'] != $newContactEmail) {
$changeDetails[] = "contact_email: {$existingContact['supplier_email']}{$newContactEmail}";
$contactData['supplier_email'] = $newContactEmail;
}
if ($newContactMobile && $existingContact['supplier_mobile'] != $newContactMobile) {
$changeDetails[] = "contact_mobile: {$existingContact['supplier_mobile']}{$newContactMobile}";
$contactData['supplier_mobile'] = $newContactMobile;
}
if (!empty($contactData)) {
SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->update($contactData);
}
}
});
// 记录日志
$logService = new LogService();
$crmSubmitter = array_get($data, 'creator_name', 'CRM');
$logContent = "CRM修改:" . (empty($changeDetails) ? "修改内容无变化" : implode(", ", $changeDetails)) . "\n"
. date('Y-m-d H:i:s') . " CRM提交人" . $crmSubmitter;
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, 'CRM再次提交', $logContent);
Log::info('[CRM同步]再次提交更新成功', ['supplier_id' => $supplierId, 'changes' => $changeDetails]);
}
/**
* CRM客户公司转让同步接口
* 客户公司发生转让时,CRM将客户公司名称+原始销售员+转让后销售员信息同步
* 供应商系统自动更改逆向采购员为转让后销售员,记录日志
*/
public function syncCrmCustomerTransfer(Request $request)
{
$data = $request->only([
'customer_name',
'original_saler',
'transfer_saler',
]);
$rules = [
'customer_name' => 'required',
'original_saler' => 'required',
'transfer_saler' => 'required',
];
$validator = Validator::make($data, $rules);
if ($validator->fails()) {
$error = $validator->errors()->first();
Log::warning('[CRM转让同步]参数校验失败: ' . $error, $data);
$this->syncResponse(-1, $error);
}
$customerName = trim($data['customer_name']);
$supplier = SupplierChannelModel::where('supplier_name', $customerName)
->where('supplier_source', SupplierChannelModel::SUPPLIER_SOURCE_CRM)
->first();
if (empty($supplier)) {
Log::warning('[CRM转让同步]供应商不存在或非CRM来源: ' . $customerName);
$this->syncResponse(-1, '供应商不存在或非CRM来源');
}
$supplierId = $supplier['supplier_id'];
try {
// 更新逆向采购员
$extend = SupplierExtendModel::where('supplier_id', $supplierId)->first();
if ($extend) {
SupplierExtendModel::where('supplier_id', $supplierId)->update([
'reverse_purchaser' => $data['transfer_saler'],
'update_time' => time(),
]);
}
// 记录日志
$logService = new LogService();
$logContent = "CRM修改:原逆向采购员{$data['original_saler']}修改为{$data['transfer_saler']}\n"
. date('Y-m-d H:i:s') . " CRM";
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, 'CRM客户转让', $logContent);
Log::info('[CRM转让同步]逆向采购员更新成功', [
'supplier_id' => $supplierId,
'original_saler' => $data['original_saler'],
'transfer_saler' => $data['transfer_saler'],
]);
$this->syncResponse(0, '同步成功');
} catch (\Exception $e) {
Log::error('[CRM转让同步]更新失败: ' . $e->getMessage(), ['data' => $data]);
$this->syncResponse(-1, '更新失败: ' . $e->getMessage());
}
}
} }
...@@ -19,6 +19,7 @@ class AuditCenterService ...@@ -19,6 +19,7 @@ class AuditCenterService
const TYPE_SUPPLIER_AUDIT = 'supplier_audit'; const TYPE_SUPPLIER_AUDIT = 'supplier_audit';
const TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT = 'customer_convert_supplier_audit';
public static function getAuditInfoByIdAndType($id, $type) public static function getAuditInfoByIdAndType($id, $type)
{ {
......
...@@ -32,6 +32,14 @@ class BlacklistService ...@@ -32,6 +32,14 @@ class BlacklistService
} else { } else {
$res = $model->insert($data); $res = $model->insert($data);
} }
// CRM来源供应商同步状态到CRM
$supplier = $supplierModel->where('supplier_id', $supplierId)->first();
if ($supplier && $supplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$crmStatus = CrmService::mapSupplierStatusToCrm(SupplierChannelModel::STATUS_BLOCK);
CrmService::syncSupplierStatus($supplier['supplier_name'], $crmStatus, '拉入黑名单: ' . $reason);
}
return $res; return $res;
} }
return false; return false;
......
...@@ -4,6 +4,7 @@ namespace App\Http\Services; ...@@ -4,6 +4,7 @@ namespace App\Http\Services;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use App\Model\RedisModel; use App\Model\RedisModel;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class CrmService class CrmService
...@@ -48,7 +49,7 @@ class CrmService ...@@ -48,7 +49,7 @@ class CrmService
* 回传CRM供应商转化确认结果 * 回传CRM供应商转化确认结果
* @param string $supplierName 供应商名称 * @param string $supplierName 供应商名称
* @param string $approverName 审批人姓名 * @param string $approverName 审批人姓名
* @param string $approveResult 审批结果:agree/disagree * @param string $approveResult 审批结果:completed(通过)/purchase_rejected(采购驳回)
* @param string $remark 附加说明 * @param string $remark 附加说明
* @return bool * @return bool
*/ */
...@@ -61,7 +62,7 @@ class CrmService ...@@ -61,7 +62,7 @@ class CrmService
'form_params' => [ 'form_params' => [
'customer_name' => $supplierName, 'customer_name' => $supplierName,
'approver' => $approverName, 'approver' => $approverName,
'approve_result' => $approveResult, // agree / disagree 'approve_result' => $approveResult,
'remark' => $remark, 'remark' => $remark,
] ]
]); ]);
...@@ -76,4 +77,51 @@ class CrmService ...@@ -76,4 +77,51 @@ class CrmService
return false; return false;
} }
} }
/**
* 同步供应商状态变更到CRM系统
* @param string $supplierName 供应商名称
* @param string $supplierStatus CRM供应商状态:rejected/passed/blacklist/disable_trade
* @param string $remark 备注
* @return bool
*/
public static function syncSupplierStatus($supplierName, $supplierStatus, $remark = '')
{
try {
$url = env('CRM_URL') . '/open/customer/syncSupplierStatus';
$client = new Client();
$response = $client->post($url, [
'form_params' => [
'customer_name' => $supplierName,
'supplier_status' => $supplierStatus,
'remark' => $remark,
]
]);
$result = json_decode($response->getBody()->getContents(), true);
if (isset($result['code']) && $result['code'] == 0) {
return true;
}
\Illuminate\Support\Facades\Log::warning('[CRM回传]同步供应商状态失败', ['response' => $result, 'supplier_name' => $supplierName]);
return false;
} catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error('[CRM回传]同步供应商状态异常: ' . $e->getMessage(), ['supplier_name' => $supplierName]);
return false;
}
}
/**
* 供应商状态映射到CRM状态
* @param int $supplierStatus 供应商系统状态常量
* @return string|null CRM状态值,不需要同步的返回null
*/
public static function mapSupplierStatusToCrm($supplierStatus)
{
$map = [
SupplierChannelModel::STATUS_REJECT => 'rejected', // 未通过
SupplierChannelModel::STATUS_PASSED => 'passed', // 已通过
SupplierChannelModel::STATUS_BLOCK => 'blacklist', // 黑名单
SupplierChannelModel::STATUS_DISABLE => 'disable_trade', // 禁止交易
];
return isset($map[$supplierStatus]) ? $map[$supplierStatus] : null;
}
} }
...@@ -7,6 +7,7 @@ use App\Http\Validators\SupplierValidator; ...@@ -7,6 +7,7 @@ use App\Http\Validators\SupplierValidator;
use App\Model\LogModel; use App\Model\LogModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel; use App\Model\SupplierContactModel;
use App\Http\Services\CrmService;
class SupplierAuditService class SupplierAuditService
{ {
...@@ -99,6 +100,12 @@ class SupplierAuditService ...@@ -99,6 +100,12 @@ class SupplierAuditService
$logService = new LogService(); $logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', '审核通过'); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', '审核通过');
// CRM来源供应商同步状态到CRM
if ($supplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$crmStatus = CrmService::mapSupplierStatusToCrm(SupplierChannelModel::STATUS_PASSED);
CrmService::syncSupplierStatus($supplier['supplier_name'], $crmStatus, '审核通过');
}
// 同步到金蝶 // 同步到金蝶
$service = new SyncSupplierService(); $service = new SyncSupplierService();
$service->syncSupplierToErp($supplierId); $service->syncSupplierToErp($supplierId);
...@@ -153,6 +160,13 @@ class SupplierAuditService ...@@ -153,6 +160,13 @@ class SupplierAuditService
$logService = new LogService(); $logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', '审核不通过,原因是 : ' . $rejectReason); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', '审核不通过,原因是 : ' . $rejectReason);
// CRM来源供应商同步状态到CRM
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if ($supplier && $supplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$crmStatus = CrmService::mapSupplierStatusToCrm(SupplierChannelModel::STATUS_REJECT);
CrmService::syncSupplierStatus($supplier['supplier_name'], $crmStatus, '审核未通过: ' . $rejectReason);
}
return true; return true;
} }
...@@ -540,6 +554,137 @@ class SupplierAuditService ...@@ -540,6 +554,137 @@ class SupplierAuditService
} }
} }
/**
* 客户转化供应商 - 提交审批到审核中心
*/
public function addApproveForCustomerConvert($supplierId, $triggerReason)
{
if (\isAdmin()) {
return true;
}
$supplierInfo = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if (!$supplierInfo) {
throw new \Exception("供应商不存在");
}
$auditInfo = AuditCenterService::getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT);
// 如果存在审核信息,并且状态不是 已完成,已拒绝,已撤销时直接跳过
if (!empty($auditInfo) && !in_array($auditInfo['approval_status'], [
AuditCenterService::APPROVAL_STATUS_REFUSE,
AuditCenterService::APPROVAL_STATUS_CANCEL,
AuditCenterService::APPROVAL_STATUS_FINISH
])) {
return $auditInfo;
}
// 先获取审核流节点数据
$flowInfo = AuditCenterService::getAuditFlowInfo(
AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT,
request()->user->userId,
null
);
// 创建审批单据
$billInfo = AuditCenterService::addAudit([
"flow_id" => $flowInfo['flow_info']['id'],
"source_id" => $supplierId,
"source_sn" => $supplierInfo['supplier_code'],
"org_id" => 1,
"trigger_reason" => $triggerReason,
"current_node" => null,
"apply_node_ids" => implode(",", array_column($flowInfo['node_list'], 'id'))
], request()->user->userId, request()->user->userId);
return $billInfo;
}
/**
* 客户转化供应商 - 审核操作
*/
public function auditCustomerConvertSupplier($supplierId, $approvalStatus, $remark)
{
$auditBillInfo = AuditCenterService::getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT);
if (empty($auditBillInfo)) {
throw new \Exception("客户转化供应商审核单据不存在");
}
$approvalUid = request()->user->userId;
// 调用审核中心审核接口
if (in_array($auditBillInfo['approval_status'], [
AuditCenterService::APPROVAL_STATUS_WAIT,
AuditCenterService::APPROVAL_STATUS_ING
])) {
$auditBillInfo = AuditCenterService::audit($auditBillInfo['id'], $approvalUid, $approvalStatus, $remark);
}
// 处理审核结果
$this->handleCustomerConvertAuditResult($supplierId, $auditBillInfo, $approvalStatus, $remark);
return true;
}
/**
* 客户转化供应商 - 处理审核结果
*/
private function handleCustomerConvertAuditResult($supplierId, $billInfo, $approvalStatus, $remark)
{
$approverName = request()->user->name;
$currentTime = date('Y-m-d H:i:s');
if ($approvalStatus == 1) { // 通过
if ($billInfo['approval_status'] == AuditCenterService::APPROVAL_STATUS_FINISH) {
// 最终审核完成,状态改为待提审
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'status' => SupplierChannelModel::STATUS_PENDING,
'update_time' => time(),
]);
// 回传CRM系统:转化供应商状态更新为完成
$supplierName = SupplierChannelModel::where('supplier_id', $supplierId)->value('supplier_name');
CrmService::confirmCrmSupplier($supplierName, $approverName, 'completed', $remark);
// 记录审批日志
$logContent = "确认客户转化供应商:审核通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
} else {
// 中间节点审核通过,记录日志
$logContent = "确认客户转化供应商:审核通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
}
} else { // 拒绝
if ($billInfo['approval_status'] == AuditCenterService::APPROVAL_STATUS_REFUSE) {
// 最终审核拒绝,状态恢复为待确认
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'status' => SupplierChannelModel::STATUS_CONFIRM,
'update_time' => time(),
]);
// 回传CRM系统:转化供应商状态更新为采购驳回
$supplierName = SupplierChannelModel::where('supplier_id', $supplierId)->value('supplier_name');
CrmService::confirmCrmSupplier($supplierName, $approverName, 'purchase_rejected', $remark);
// 记录审批日志
$logContent = "确认客户转化供应商:审核未通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
} else {
// 中间节点拒绝
$logContent = "确认客户转化供应商:审核未通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
}
}
}
//获取审核流程 //获取审核流程
public function getAuditFlow($supplierId) public function getAuditFlow($supplierId)
{ {
......
...@@ -97,6 +97,8 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -97,6 +97,8 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
Route::get('/sync/audit/GetNeedAuditSupplierCount', 'SupplierSyncController@GetNeedAuditSupplierCount'); Route::get('/sync/audit/GetNeedAuditSupplierCount', 'SupplierSyncController@GetNeedAuditSupplierCount');
//CRM推送供应商同步接口 //CRM推送供应商同步接口
Route::post('/sync/crm/syncSupplier', 'SupplierSyncController@syncCrmSupplier'); Route::post('/sync/crm/syncSupplier', 'SupplierSyncController@syncCrmSupplier');
//CRM客户公司转让同步接口
Route::post('/sync/crm/syncCustomerTransfer', 'SupplierSyncController@syncCrmCustomerTransfer');
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
......
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