Commit 2cf74328 by 杨树贤

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

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