Commit 12c63ffe authored by 孟维甫's avatar 孟维甫

Merge branch 'feature_jielong_native' into 'test'

add:kafka

See merge request bp/goods!28
parents 015e6811 b92efa6c
<?php
namespace App\Services\common;
use Api\PhpUtils\Kafka\KafkaUtil;
use Api\PhpUtils\Log\FileLog;
class KafkaService
{
/**
* marketing 广播
*/
public static function productMarketingUpdate(array $marketingInfo) : void
{
$msg = json_encode([
'marketingInfo' => $marketingInfo,
'time' => time(),
], JSON_FORCE_OBJECT);
$serverName = 'goods.publish';
$kafka = KafkaUtil::getInstance($serverName);
if ($kafka->produce($msg)) {
FileLog::info(sprintf('kafka produce success serverName %s msg = %s', $serverName, $msg));
}
else {
FileLog::error(sprintf('kafka produce failure serverName %s msg = %s', $serverName, $msg));
}
}
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ namespace App\Services\marketing; ...@@ -5,6 +5,7 @@ namespace App\Services\marketing;
use Api\PhpServices\Ksy\Ks3Api; use Api\PhpServices\Ksy\Ks3Api;
use Api\PhpUtils\Http\HttpUtil; use Api\PhpUtils\Http\HttpUtil;
use App\Exception\BaseException;
use App\Exception\custom\InterfaceException; use App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\Request; use Api\PhpUtils\Http\Request;
use App\Models\goods\mysql\Ota; use App\Models\goods\mysql\Ota;
...@@ -19,6 +20,7 @@ use App\Models\marketing\mysql\MarketingPindan; ...@@ -19,6 +20,7 @@ use App\Models\marketing\mysql\MarketingPindan;
use App\Models\marketing\mysql\MarketingTakePlace; use App\Models\marketing\mysql\MarketingTakePlace;
use App\Models\marketing\mysql\TakePlace; use App\Models\marketing\mysql\TakePlace;
use App\Services\common\CommonService; use App\Services\common\CommonService;
use App\Services\common\KafkaService;
use App\Services\goods\GoodsService; use App\Services\goods\GoodsService;
use Daemon\Goods; use Daemon\Goods;
use App\Exception\custom\GoodsException; use App\Exception\custom\GoodsException;
...@@ -748,6 +750,19 @@ class MarketingService ...@@ -748,6 +750,19 @@ class MarketingService
throw new MarketingException(["cus" => 5]); throw new MarketingException(["cus" => 5]);
} }
$picList = GoodsService::getUrlList($pindanPic);
KafkaService::productMarketingUpdate([
'activityId' => $marketingId,
'startDate' => $startTime,
'endDate' => $endTime,
'userId' => $lifeAccountId,
'activityName' => $marketingName,
'text' => $pindanDesc,
'imageId' => $picList[0] ?? '',
'createTime' => date('Y-m-d H:i:s'),
'onlineStatus' => Marketing::ONLINE_STATUS_QIDONG,
]);
return $pindanId; return $pindanId;
} }
...@@ -903,6 +918,20 @@ class MarketingService ...@@ -903,6 +918,20 @@ class MarketingService
throw new MarketingException(["cus" => 5]); throw new MarketingException(["cus" => 5]);
} }
$picList = GoodsService::getUrlList($marketingPindan['pindan_pic']);
KafkaService::productMarketingUpdate([
'activityId' => $marketingId,
'startDate' => $startTime,
'endDate' => $endTime,
'userId' => config('lifeaccount','life_account_id'),
'activityName' => $marketingName,
'text' => $pindanDesc,
'imageId' => $picList[0] ?? '',
'createTime' => $marketing['create_time'],
'onlineStatus' => Marketing::ONLINE_STATUS_QIDONG,
]);
return true; return true;
} }
...@@ -929,6 +958,26 @@ class MarketingService ...@@ -929,6 +958,26 @@ class MarketingService
'online_status' => $onlineStatus, 'online_status' => $onlineStatus,
'end_time' => $endTime, 'end_time' => $endTime,
]; ];
if ($marketingType == Marketing::MARKETING_TYPE_PINDAN) {
$marketing = Marketing::getRecord(["marketing_id" => $marketingId]);
$marketingPindan = MarketingPindan::getRecord(["marketing_id" => $marketingId]);
$picList = GoodsService::getUrlList($marketingPindan['pindan_pic']);
KafkaService::productMarketingUpdate([
'activityId' => $marketingId,
'startDate' => $marketing['start_time'],
'endDate' => $endTime,
'userId' => config('lifeaccount','life_account_id'),
'activityName' => $marketing['marketing_name'],
'text' => $marketingPindan['pindan_desc'],
'imageId' => $picList[0] ?? '',
'createTime' => $marketing['create_time'],
'onlineStatus' => $onlineStatus,
]);
}
Marketing::updateRecord($marketingParams, ["marketing_id" => $marketingId, "marketing_type" => $marketingType]); Marketing::updateRecord($marketingParams, ["marketing_id" => $marketingId, "marketing_type" => $marketingType]);
} }
......
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 to comment