Commit 2cf74328 by 杨树贤

多个供应商实体化广播问题

parent 0b3de077
......@@ -279,115 +279,114 @@ class SyncSupplierService
(new ChainService())->changeChainIsEntity($supplierName, $isEntityResult);
//先找到对应的供应商(草稿的跳过),如果没有那跳过
$supplier = SupplierChannelModel::where('supplier_name', $supplierName)->first();
if (empty($supplier)) {
$suppliers = SupplierChannelModel::where('supplier_name', $supplierName)->get()->toArray();
if (empty($suppliers)) {
Log::error('供应商不存在');
return true;
}
$supplier = $supplier->toArray();
$supplierId = $supplier['supplier_id'];
//先把修改之前的状态给记录下来
$status = $supplier['status'];
$preStatus = null;
$redis = new RedisModel();
if ($isEntity) {
$cachedExists = $redis->hexists('supplier_status_before_disable', $supplierId);
if (!$cachedExists) {
$redis->hset('supplier_status_before_disable', $supplierId, $status);
}
} else {
$preStatus = $redis->hget('supplier_status_before_disable', $supplierId);
if ($preStatus === null) {
$preStatus = $status;
}
$redis->hdel('supplier_status_before_disable', $supplierId);
}
//如果是移除实体名单,但是得到之前的状态还是禁止交易,那么强行改成审核中
if (!$isEntity && $preStatus == SupplierChannelModel::STATUS_DISABLE) {
$preStatus = SupplierChannelModel::STATUS_IN_REVIEW;
}
//修改供应商的状态
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'is_entity' => $isEntityResult,
'update_time' => time(),
//这里的逻辑是,因为取消实体名单以后,如果之前的状态是黑名单的话,直接变成待提审
'status' => $isEntity ? SupplierChannelModel::STATUS_DISABLE : ($preStatus == SupplierChannelModel::STATUS_BLOCK ? SupplierChannelModel::STATUS_IN_REVIEW : $preStatus),
'disable_reason' => $reason,
'united_tags' => !empty($tagList) ? implode(',', $tagList) : '',
]);
$isYunxinSupplier = false;
//还要去修改对应的供应商账号,也是要记录禁用前的状态
$supplierAccount = SupplierAccountModel::where('supplier_id', $supplierId)->first();
//如果是待确认,那么不需要去操作供应商账号
if (!empty($supplierAccount) && $result != 0) {
$isYunxinSupplier = true;
$supplierAccount = $supplierAccount->toArray();
$accountPreStatus = $supplierAccount['a_status'];
foreach ($suppliers as $supplier) {
//$supplier = $supplier->toArray();
$supplierId = $supplier['supplier_id'];
//先把修改之前的状态给记录下来
$status = $supplier['status'];
$preStatus = null;
$redis = new RedisModel();
if ($isEntity) {
$redis->hset('supplier_account_status_before_disable', $supplierId, $accountPreStatus);
$cachedExists = $redis->hexists('supplier_status_before_disable', $supplierId);
if (!$cachedExists) {
$redis->hset('supplier_status_before_disable', $supplierId, $status);
}
} else {
$accountPreStatus = $redis->hget('supplier_account_status_before_disable', $supplierId);
$redis->hdel('supplier_account_status_before_disable', $supplierId);
$preStatus = $redis->hget('supplier_status_before_disable', $supplierId);
if ($preStatus === null) {
$preStatus = $status;
}
$redis->hdel('supplier_status_before_disable', $supplierId);
}
SupplierAccountModel::where('supplier_id', $supplierId)->update([
//如果是移除实体名单,但是得到之前的状态还是禁止交易,那么强行改成审核中
if (!$isEntity && $preStatus == SupplierChannelModel::STATUS_DISABLE) {
$preStatus = SupplierChannelModel::STATUS_IN_REVIEW;
}
//修改供应商的状态
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'is_entity' => $isEntityResult,
'update_time' => time(),
'a_status' => $isEntity ? SupplierAccountModel::STATUS_DISABLE : $accountPreStatus,
//这里的逻辑是,因为取消实体名单以后,如果之前的状态是黑名单的话,直接变成待提审
'status' => $isEntity ? SupplierChannelModel::STATUS_DISABLE : ($preStatus == SupplierChannelModel::STATUS_BLOCK ? SupplierChannelModel::STATUS_IN_REVIEW : $preStatus),
'disable_reason' => $reason,
'united_tags' => !empty($tagList) ? implode(',', $tagList) : '',
]);
}
$isYunxinSupplier = false;
//还要去修改对应的供应商账号,也是要记录禁用前的状态
$supplierAccount = SupplierAccountModel::where('supplier_id', $supplierId)->first();
//如果是待确认,那么不需要去操作供应商账号
if (!empty($supplierAccount) && $result != 0) {
$isYunxinSupplier = true;
$supplierAccount = $supplierAccount->toArray();
$accountPreStatus = $supplierAccount['a_status'];
if ($isEntity) {
$redis->hset('supplier_account_status_before_disable', $supplierId, $accountPreStatus);
} else {
$accountPreStatus = $redis->hget('supplier_account_status_before_disable', $supplierId);
$redis->hdel('supplier_account_status_before_disable', $supplierId);
}
SupplierAccountModel::where('supplier_id', $supplierId)->update([
'update_time' => time(),
'a_status' => $isEntity ? SupplierAccountModel::STATUS_DISABLE : $accountPreStatus,
]);
}
//还要去打日志
$logService = new LogService();
$logService->AddAdminLog($supplierId, LogModel::UPDATE_OPERATE, '实体名单设置', $logContent);
//还要去打日志
$logService = new LogService();
$logService->AddAdminLog($supplierId, LogModel::UPDATE_OPERATE, '实体名单设置', $logContent);
//不属于加入实体名单和移除实体名单不去发邮件
if (!in_array($result, [1, -1])) {
return true;
}
//不属于加入实体名单和移除实体名单不去发邮件
if (!in_array($result, [1, -1])) {
return true;
}
//return true;
//return true;
//还要去发送邮箱给采购员,线上采购员,采购总
$data['data']['supplier_code'] = $supplier['supplier_code'];
$data['data']['supplier_name'] = $supplier['supplier_name'];
$data['data']['supplier_group_name'] = array_get(config('fixed.SupplierGroup'), $supplier['supplier_group']);
$data['data']['operation'] = $isEntity ? '确认' : '移除';
$data['data']['content'] = $isEntity ? ' 注意:实体名单的供应商已自动拉入禁止交易,无法使用!' : '注意:已移除实体名单的供应商,状态自动返回到前一个状态!';
$data['data']['ps_content'] = $isEntity ? 'PS:如果该供应商为芯链商家,该供应商的芯链账号无法登录芯链系统!' : 'PS:如果该供应商为芯链商家,该供应商的芯链账号可正常登录芯链系统!';
if ($isYunxinSupplier) {
$data['data']['supplier_name'] .= ' (芯链商家) ';
}
if (!empty($supplier['yunxin_channel_uid'])) {
$yunxinChannelUser = (new AdminUserService())->getAdminUserInfoByCodeId($supplier['yunxin_channel_uid']);
if (!empty($yunxinChannelUser['email'])) {
//先发送邮件给线上采购员
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $yunxinChannelUser['email'], true);
//还要去发送邮箱给采购员,线上采购员,采购总
$data['data']['supplier_code'] = $supplier['supplier_code'];
$data['data']['supplier_name'] = $supplier['supplier_name'];
$data['data']['supplier_group_name'] = array_get(config('fixed.SupplierGroup'), $supplier['supplier_group']);
$data['data']['operation'] = $isEntity ? '确认' : '移除';
$data['data']['content'] = $isEntity ? ' 注意:实体名单的供应商已自动拉入禁止交易,无法使用!' : '注意:已移除实体名单的供应商,状态自动返回到前一个状态!';
$data['data']['ps_content'] = $isEntity ? 'PS:如果该供应商为芯链商家,该供应商的芯链账号无法登录芯链系统!' : 'PS:如果该供应商为芯链商家,该供应商的芯链账号可正常登录芯链系统!';
if ($isYunxinSupplier) {
$data['data']['supplier_name'] .= ' (芯链商家) ';
}
//再找出线上采购员对应的采购总监
$supervisorDepartmentId = $yunxinChannelUser['department_id'];
$positionId = \DB::table('user_position')->where('department_id', $supervisorDepartmentId)
->where('position_name', '采购总监')->value('position_id');
if (!empty($positionId)) {
$supervisor = UserInfoModel::where('position_id', $positionId)->first()->toArray();
if (!empty($supervisor['email'])) {
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $supervisor['email'], true);
if (!empty($supplier['yunxin_channel_uid'])) {
$yunxinChannelUser = (new AdminUserService())->getAdminUserInfoByCodeId($supplier['yunxin_channel_uid']);
if (!empty($yunxinChannelUser['email'])) {
//先发送邮件给线上采购员
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $yunxinChannelUser['email'], true);
}
//再找出线上采购员对应的采购总监
$supervisorDepartmentId = $yunxinChannelUser['department_id'];
$positionId = \DB::table('user_position')->where('department_id', $supervisorDepartmentId)
->where('position_name', '采购总监')->value('position_id');
if (!empty($positionId)) {
$supervisor = UserInfoModel::where('position_id', $positionId)->first()->toArray();
if (!empty($supervisor['email'])) {
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $supervisor['email'], true);
}
}
}
}
if (!empty($supplier['channel_uid'])) {
$supplier['channel_uid'] = explode(',', $supplier['channel_uid']);
$channelUserList = (new AdminUserService())->getAdminUserListByCodeIds($supplier['channel_uid']);
foreach ($channelUserList as $channelUser) {
if (!empty($channelUser['email'])) {
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $channelUser['email'], true);
if (!empty($supplier['channel_uid'])) {
$supplier['channel_uid'] = explode(',', $supplier['channel_uid']);
$channelUserList = (new AdminUserService())->getAdminUserListByCodeIds($supplier['channel_uid']);
foreach ($channelUserList as $channelUser) {
if (!empty($channelUser['email'])) {
(new MessageService())->sendMessage('supplier_entity_notice_purchase', $data, $channelUser['email'], true);
}
}
}
}
}
}
......@@ -15,6 +15,7 @@
use App\Http\Services\CompanyService;
use App\Http\Services\DepartmentService;
use App\Http\Services\SkuService;
use App\Model\RedisModel;
Route::group(['middleware' => ['web', 'menu']], function () {
Route::get('/', 'WebController@Entrance');
......@@ -89,5 +90,7 @@ Route::match(['get', 'post'], '/test', function () {
//\App\Model\SupplierChannelModel::where('supplier_id', 11042)->update([
// 'supplier_address' => 'xx测试猎芯123xx'
//]);
\App\Http\Services\DataService::repairAccount();
//$redis = new RedisModel();
//dd($redis->hget('api_coupon',476));
//\App\Http\Services\DataService::repairAccount();
});
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