Commit 8a5f2486 by mushishixian

优化

parent 41245090
<?php
namespace App\Http\Services;
use App\Model\RedisModel;
use App\Model\SupplierChannelModel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
//这个服务是专门给搜索那边处理数据用的,供应商这边修改了标签以后,如果有变化,会影响对应的所有sku的标签
class SupplierSearchTagService
{
//保存标签情况(搜索相关,不是系统标签和自定义标签)
//供应商性质为原厂(4)的话,写入标签2;已认证的话,写入标签3
public function saveSupplierSearchTags($supplierId)
{
$supplierModel = new SupplierChannelModel();
$supplier = $supplierModel->where('supplier_id', $supplierId)->first()->toArray();
$tagFlags = [];
//先去判断供应商性质是否为原厂,如果是的话,写入标签2
if ($supplier['supplier_group'] == 4) {
$tagFlags[] = 2;
}
if ($supplier['has_certification'] == 1) {
$tagFlags[] = 3;
}
$redis = new RedisModel();
$originTags = $redis->hget('supplier_search_tags', $supplier['supplier_code']);
$tagFlags = json_encode([
'supplier_code' => $supplier['supplier_code'],
'tags' => $tagFlags,
]);
$redis->hset('supplier_search_tags', $supplier['supplier_code'], $tagFlags);
//判断是否发生变化,有变化才推送
if ($originTags != $tagFlags) {
//{"supplier_code":"L00055"}
$message = json_encode([
'supplier_code' => $supplier['supplier_code'],
]);
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
$channel = $conn->channel();
$channel->queue_declare('supplier_zhuanmai_update', false, true, false, false);
$msg = new AMQPMessage(json_encode($message),
array('content_type' => 'text/plain'));
$result = $channel->basic_publish($msg, '', 'supplier_zhuanmai_update');
}
}
}
\ No newline at end of file
......@@ -159,7 +159,8 @@ class SupplierService
//重新生成外部显示的编码
$this->generateSupplierSn($supplierId, $channel['supplier_group']);
//保存和搜索相关的标签情况
$this->saveSupplierSearchTags($supplierId);
$supplierSearchTagService = new SupplierSearchTagService();
$supplierSearchTagService->saveSupplierSearchTags($supplierId);
return true;
});
......@@ -432,25 +433,4 @@ class SupplierService
}
}
//保存标签情况(搜索相关,不是系统标签和自定义标签)
//供应商性质为原厂(4)的话,写入标签2;已认证的话,写入标签3
public function saveSupplierSearchTags($supplierId)
{
$supplierModel = new SupplierChannelModel();
$supplier = $supplierModel->where('supplier_id', $supplierId)->first()->toArray();
$tagFlags = [];
//先去判断供应商性质是否为原厂,如果是的话,写入标签2
if ($supplier['supplier_group'] == 4) {
$tagFlags[] = 2;
}
if ($supplier['has_certification'] == 1) {
$tagFlags[] = 3;
}
$redis = new RedisModel();
$redis->hset('supplier_search_tags', $supplier['supplier_code'], json_encode([
'supplier_code' => $supplier['supplier_code'],
'tags' => $tagFlags,
]));
}
}
\ No newline at end of file
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