Commit bfeef9fc by 杨树贤

完善审核流

parent bc054980
......@@ -902,7 +902,13 @@ class SupplierApiController extends Controller
{
$supplierId = $request->get('supplier_id');
$supplierAuditService = new AuditCenterService();
$result = $supplierAuditService->getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_SUPPLIER_AUDIT);
//判断是否是待确认,是的话去请求crm转供应商的审核
$status = SupplierChannelModel::where('supplier_id', $supplierId)->value('status');
if ($status == SupplierChannelModel::STATUS_CONFIRM) {
$result = $supplierAuditService->getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT);
} else {
$result = $supplierAuditService->getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_SUPPLIER_AUDIT);
}
$this->response(0, 'ok', $result);
}
}
......@@ -20,47 +20,6 @@ class SupplierCrmApiController extends Controller
$this->$id($request, $id);
}
//转化供应商确认 - 提交审批到审核中心
public function ConfirmCrmSupplier($request)
{
$supplierId = $request->get('supplier_id');
$model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first();
if (empty($supplier)) {
$this->response(-1, '供应商不存在');
}
$supplier = $supplier->toArray();
// 前置条件校验:状态必须为待确认(4)且来源为CRM客户转化(2)
if ($supplier['status'] != SupplierChannelModel::STATUS_CONFIRM
|| $supplier['supplier_source'] != SupplierChannelModel::SUPPLIER_SOURCE_CRM) {
$this->response(-1, '该供应商不满足转化条件(须为待确认状态且来源为CRM客户转化)');
}
try {
// 提交审批到审核中心
$auditService = new SupplierAuditService();
$result = $auditService->addApproveForCustomerConvert($supplierId, '客户转化供应商审核');
// 更新状态为审核中
$model->where('supplier_id', $supplierId)->update([
'status' => SupplierChannelModel::STATUS_IN_REVIEW,
'update_time' => time(),
]);
// 记录提交审批日志
$logService = new LogService();
$logContent = "确认客户转化供应商:提交审核\n"
. date('Y-m-d H:i:s') . " " . $request->user->name;
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
$this->response(0, '提交审核成功', $result);
} catch (Exception $e) {
$this->response(-1, '提交审核失败: ' . $e->getMessage());
}
}
//客户转化供应商 - 审核操作
public function AuditCustomerConvertSupplier($request)
{
......
......@@ -10,11 +10,13 @@ use App\Http\Services\CompanyService;
use App\Http\Services\SupplierService;
use App\Http\Services\SyncSupplierService;
use App\Http\Services\LogService;
use App\Http\Services\SupplierAuditService;
use App\Model\LogModel;
use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierExtendModel;
use App\Model\UserInfoModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
......@@ -55,7 +57,6 @@ class SupplierSyncController extends BaseSyncController
$result = (new SyncSupplierService())->syncSupplierToUnitedResult($resultData);
$this->syncResponse(0, '同步一体化信息成功');
}
public function receiveEntityResult(Request $request)
......@@ -99,7 +100,6 @@ class SupplierSyncController extends BaseSyncController
}
(new SyncSupplierService())->receiveEntityResult($resultData);
$this->syncResponse(0, '获取审核结果广播成功');
}
//获取供应商需要审核的数量
......@@ -140,7 +140,6 @@ class SupplierSyncController extends BaseSyncController
* - contact_email: 联系人邮箱
* - contact_mobile: 联系人手机号
* - creator_name (必填): 创建人姓名 → 逆向采购员
* - purchaser_uid: 采购员codeId(第一个审批人)
* - platform_agreement_url: 平台合作协议附件URL
* - platform_agreement_name: 平台合作协议附件文件名
* - quality_agreement_url: 品质保证协议附件URL
......@@ -155,13 +154,13 @@ class SupplierSyncController extends BaseSyncController
'contact_email',
'contact_mobile',
'creator_name',
'purchaser_uid',
'platform_agreement_url',
'platform_agreement_name',
'quality_agreement_url',
'quality_agreement_name',
'customer_nature',
'crm_remark',
'apply_uid'
]);
//参数校验
......@@ -169,6 +168,7 @@ class SupplierSyncController extends BaseSyncController
'customer_name' => 'required',
'sign_com_id' => 'required',
'creator_name' => 'required',
'apply_uid' => 'required',
];
$validator = Validator::make($data, $rules);
......@@ -184,8 +184,10 @@ class SupplierSyncController extends BaseSyncController
$existingSupplier = SupplierChannelModel::where('supplier_name', $customerName)->first();
if ($existingSupplier) {
// CRM再次提交:仅当来源为CRM且状态为待确认(采购驳回后恢复待确认)时,更新数据
if ($existingSupplier['supplier_source'] == SupplierChannelModel::SUPPLIER_SOURCE_CRM
&& $existingSupplier['status'] == SupplierChannelModel::STATUS_CONFIRM) {
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']]);
......@@ -195,7 +197,7 @@ class SupplierSyncController extends BaseSyncController
}
}
Log::info('[CRM同步]供应商已存在且不满足再次提交条件,跳过: ' . $customerName);
$this->syncResponse(0, '供应商已存在,跳过');
$this->syncResponse(-1, '供应商已存在,跳过');
}
try {
......@@ -208,7 +210,8 @@ class SupplierSyncController extends BaseSyncController
$establishedTime = array_get($companyInfo, 'establishment_time', '');
// legal_representative 从天眼查数据获取(如果有)
$legalRepresentative = '';
$applyUid = !empty($data['apply_uid']) ? $data['apply_uid'] : 1000;
$applyName = (new AdminUserService())->getAdminUserNameByUserId($applyUid);
// 2. 构建供应商数据
$channel = [
'supplier_name' => $customerName,
......@@ -237,7 +240,7 @@ class SupplierSyncController extends BaseSyncController
'supplier_type' => SupplierChannelModel::SUPPLIER_TYPE_OFFICIAL, // 正式供应商
'is_business_abnormal' => -1, // 默认无异常
'has_legal_ID_card' => -1, // 默认无法人身份证
'apply_uid' => $applyUid,
// 状态设为待确认
'status' => SupplierChannelModel::STATUS_CONFIRM,
//CRM同步供应商不需要初审
......@@ -253,11 +256,12 @@ class SupplierSyncController extends BaseSyncController
]
]);
// 4. 使用事务创建供应商
$supplierId = DB::connection('web')->transaction(function () use ($channel, $data) {
// 4. 使用事务创建供应商和审核流
$supplierId = DB::connection('web')->transaction(function () use ($applyUid, $applyName, $channel, $data) {
unset($channel['apply_uid']);
$model = new SupplierChannelModel();
$channel['create_uid'] = 0;
$channel['create_name'] = 'CRM同步';
$channel['create_uid'] = $applyUid;
$channel['create_name'] = $applyName;
$channel['create_time'] = time();
$channel['update_time'] = time();
......@@ -271,6 +275,10 @@ class SupplierSyncController extends BaseSyncController
'supplier_sn' => 'FOO' . ltrim($supplierCode, 'L'),
]);
// 提交审批到审核中心(在事务中,失败则回滚)
$auditService = new SupplierAuditService();
$auditService->addApproveForCustomerConvert($supplierId, $applyUid, '客户转化供应商审核');
// 写入逆向采购员到扩展表
$extendData = [
'supplier_id' => $supplierId,
......@@ -291,7 +299,7 @@ class SupplierSyncController extends BaseSyncController
'can_check_uids' => array_get($data, 'purchaser_uid', ''),
'channel_user_type' => SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN,
'add_time' => time(),
'admin_id' => 0,
'admin_id' => $applyUid,
];
SupplierContactModel::insert($contactData);
......@@ -301,11 +309,13 @@ class SupplierSyncController extends BaseSyncController
$platformAgreementName = array_get($data, 'platform_agreement_name', '平台合作协议');
SupplierAttachmentsModel::insert([
'supplier_id' => $supplierId,
'type_name' => '平台合作协议',
'field_name' => 'cooperation_agreement',
'file_url' => $platformAgreementUrl,
'file_name' => $platformAgreementName,
'create_name' => $applyName,
'create_time' => time(),
'create_uid' => 0,
'create_uid' => $applyUid,
]);
}
......@@ -315,11 +325,13 @@ class SupplierSyncController extends BaseSyncController
$qualityAgreementName = array_get($data, 'quality_agreement_name', '品质保证协议');
SupplierAttachmentsModel::insert([
'supplier_id' => $supplierId,
'type_name' => '品质保证协议',
'field_name' => 'quality_assurance_agreement',
'file_url' => $qualityAgreementUrl,
'file_name' => $qualityAgreementName,
'create_name' => $applyName,
'create_time' => time(),
'create_uid' => 0,
'create_uid' => $applyUid,
]);
}
......@@ -329,6 +341,11 @@ class SupplierSyncController extends BaseSyncController
return $supplierId;
});
// 记录提交审批日志
$logService = new LogService();
$logContent = "CRM同步:自动提交客户转化供应商审核";
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
Log::info('[CRM同步]供应商创建成功', ['supplier_id' => $supplierId, 'supplier_name' => $customerName]);
$this->syncResponse(0, '同步成功', ['supplier_id' => $supplierId]);
......
......@@ -62,6 +62,11 @@ class AdminUserService
return UserInfoModel::where('name', $userName)->value('userId');
}
public function getAdminUserNameByUserId($userId)
{
return UserInfoModel::where('userId', $userId)->value('name');
}
public function getAdminIdByEmail($email)
{
return UserInfoModel::where('email', $email)->value('userId');
......
......@@ -126,7 +126,6 @@ class AuditCenterService
'apply_node_ids' => array_get($params, 'apply_node_ids', ''),
];
$response = self::requestAudit("/sync/bill/addBill", $requestData);
if ($response['code'] != 0) {
throw new Exception($response['msg']);
}
......
......@@ -468,7 +468,7 @@ class SupplierAuditService
{
// 如果是admin用户,直接跳过审核
if (isAdmin()) {
return false;
// return false;
}
//只要不是已通过状态,修改任何字段都需要审核
......@@ -557,11 +557,11 @@ class SupplierAuditService
/**
* 客户转化供应商 - 提交审批到审核中心
*/
public function addApproveForCustomerConvert($supplierId, $triggerReason)
public function addApproveForCustomerConvert($supplierId, $applyUid, $triggerReason)
{
if (\isAdmin()) {
return true;
}
// if (\isAdmin()) {
// return true;
// }
$supplierInfo = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if (!$supplierInfo) {
......@@ -569,7 +569,6 @@ class SupplierAuditService
}
$auditInfo = AuditCenterService::getAuditInfoByIdAndType($supplierId, AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT);
// 如果存在审核信息,并且状态不是 已完成,已拒绝,已撤销时直接跳过
if (!empty($auditInfo) && !in_array($auditInfo['approval_status'], [
AuditCenterService::APPROVAL_STATUS_REFUSE,
......@@ -579,13 +578,13 @@ class SupplierAuditService
return $auditInfo;
}
// 先获取审核流节点数据
$flowInfo = AuditCenterService::getAuditFlowInfo(
AuditCenterService::TYPE_CUSTOMER_CONVERT_SUPPLIER_AUDIT,
request()->user->userId,
null
array_get(request()->user, 'userId', 1000),
1
);
// 创建审批单据
$billInfo = AuditCenterService::addAudit([
"flow_id" => $flowInfo['flow_info']['id'],
......@@ -595,8 +594,7 @@ class SupplierAuditService
"trigger_reason" => $triggerReason,
"current_node" => null,
"apply_node_ids" => implode(",", array_column($flowInfo['node_list'], 'id'))
], request()->user->userId, request()->user->userId);
], $applyUid, $applyUid);
return $billInfo;
}
......@@ -647,14 +645,12 @@ class SupplierAuditService
CrmService::confirmCrmSupplier($supplierName, $approverName, 'completed', $remark);
// 记录审批日志
$logContent = "确认客户转化供应商:审核通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logContent = "确认客户转化供应商:审核通过";
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
} else {
// 中间节点审核通过,记录日志
$logContent = "确认客户转化供应商:审核通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logContent = "确认客户转化供应商:审核通过";
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
}
......@@ -671,14 +667,12 @@ class SupplierAuditService
CrmService::confirmCrmSupplier($supplierName, $approverName, 'purchase_rejected', $remark);
// 记录审批日志
$logContent = "确认客户转化供应商:审核未通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logContent = "确认客户转化供应商:审核未通过";
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
} else {
// 中间节点拒绝
$logContent = "确认客户转化供应商:审核未通过" . ($remark ? " " . $remark : "") . "\n"
. $currentTime . " " . $approverName;
$logContent = "确认客户转化供应商:审核未通过";
$logService = new LogService();
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '客户转化供应商审核', $logContent);
}
......
curl -X POST http://supplier.liexin.net/sync/crm/syncSupplier \
# 同步CRM客户到供应商
curl -X POST http://supplier.liexin.net/sync/crm/syncSupplier \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "customer_name=测试科技有限公司" \
-d "sign_com_id=1" \
-d "contact_name=张三" \
-d "contact_email=zhangsan@test.com" \
-d "contact_mobile=13800138000" \
-d "creator_name=李四" \
-d "purchaser_uid=P20240001" \
-d "customer_nature=工厂" \
-d "crm_remark=CRM客户转化供应商测试" \
-d "platform_agreement_url=https://example.com/agreements/platform_2024.pdf" \
-d "platform_agreement_name=平台合作协议_2024" \
-d "quality_agreement_url=https://example.com/agreements/quality_2024.pdf" \
# 同步CRM客户到供应商
curl -X POST http://supplier.liexin.net/sync/crm/syncSupplier
-H "Content-Type: application/x-www-form-urlencoded"
-d "customer_name=测试科技有限公司"
-d "sign_com_id=1"
-d "contact_name=张三"
-d "contact_email=zhangsan@test.com"
-d "contact_mobile=13800138000"
-d "creator_name=李四"
-d "customer_nature=工厂"
-d "crm_remark=CRM客户转化供应商测试"
-d "platform_agreement_url=https://example.com/agreements/platform_2024.pdf"
-d "platform_agreement_name=平台合作协议_2024"
-d "quality_agreement_url=https://example.com/agreements/quality_2024.pdf"
-d "quality_agreement_name=品质保证协议_2024"
......@@ -3,14 +3,14 @@
let admin = layui.admin;
let form = layui.form;
let layer = layui.layer;
form.on('submit(confirmCrmSupplier)', function (data) {
let supplierId = getQueryVariable('supplier_id');
let auditOpinion = data.field.audit_opinion;
let remark = data.field.remark || '';
let url = '/api/supplier_crm/ConfirmCrmSupplier?supplier_id=' + supplierId;
let url = '/api/supplier_crm/AuditCustomerConvertSupplier';
let res = ajax(url, {
supplier_id: supplierId,
audit_opinion: auditOpinion,
remark: remark,
});
......
......@@ -467,6 +467,10 @@
let supplierId = data[0].supplier_id;
let status = data[0].status;
let canReviewSupplier = {{checkPerm("ReviewSupplier")?1:0}};
if (status === 4){
layer.msg('该供应商状态为待确认,需要先确认客户转化供应商', {icon: 5});
return;
}
if (canReviewSupplier === 0 && status === -1) {
layer.msg('你没有复审供应商的权限', {icon: 5})
return
......
......@@ -70,4 +70,3 @@
</form>
</div>
</div>
@include('script.ConfirmCrmSupplierScript')
......@@ -54,9 +54,7 @@
lay-submit
lay-filter="saveSupplierMemo">确认
</button>
<button type="button" id="cancel" class="layui-btn layui-btn-primary"
lay-submit
lay-filter="cancelSupplierMemo">取消
<button type="button" id="cancel" class="layui-btn layui-btn-primary" lay-submit lay-filter="cancelSupplierMemo">取消
</button>
</div>
</div>
......
......@@ -53,7 +53,7 @@
<label class="layui-form-label">供应商来源 : </label>
<div class="layui-input-block">
<input type="text" class="layui-input" disabled
value="{{array_get(config('fixed.SupplierSource'), $supplier['supplier_source'] ?? '1', '供应商系统新增')}}">
value="{{array_get(config('fixed.SupplierSource'), !empty($supplier['supplier_source']) ? $supplier['supplier_source'] : '1', '供应商系统新增')}}">
</div>
</div>
</div>
......@@ -122,7 +122,7 @@
<label class="layui-form-label">逆向采购员 : </label>
<div class="layui-input-block" style="width: 150px">
<input type="text" class="layui-input layui-disabled" disabled
value="{{$supplier['reverse_purchaser'] ?? ''}}">
value="{{$supplier['reverse_purchaser'] or ''}}">
</div>
</div>
<div class="layui-col-md3">
......
......@@ -467,6 +467,10 @@
let supplierId = data[0].supplier_id;
let status = data[0].status;
let canReviewSupplier = <?php echo e(checkPerm("ReviewSupplier")?1:0); ?>;
if (status === 4){
layer.msg('该供应商状态为待确认,需要先确认客户转化供应商', {icon: 5});
return;
}
if (canReviewSupplier === 0 && status === -1) {
layer.msg('你没有复审供应商的权限', {icon: 5})
return
......
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