|
@@ -6,10 +6,12 @@ use App\Service\Callback\Tiktok\TiktokEventReportService;
|
|
use App\Service\Util\Support\Trace\TraceContext;
|
|
use App\Service\Util\Support\Trace\TraceContext;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 巨量账户级订单回传业务
|
|
|
|
+ */
|
|
class JuliangAccountReportChargeService
|
|
class JuliangAccountReportChargeService
|
|
{
|
|
{
|
|
private $uid;
|
|
private $uid;
|
|
- private $orderId;
|
|
|
|
/**
|
|
/**
|
|
* @var TraceContext
|
|
* @var TraceContext
|
|
*/
|
|
*/
|
|
@@ -17,24 +19,24 @@ class JuliangAccountReportChargeService
|
|
private $order;
|
|
private $order;
|
|
private $result;
|
|
private $result;
|
|
private $trackRecord;
|
|
private $trackRecord;
|
|
- private $ranseInfo;
|
|
|
|
private $callbackConfig;
|
|
private $callbackConfig;
|
|
private $promotion;
|
|
private $promotion;
|
|
private $rateConfig;
|
|
private $rateConfig;
|
|
- public function __construct($uid, $orderId, $traceInfo)
|
|
|
|
|
|
+ public function __construct($uid, $order, $traceInfo)
|
|
{
|
|
{
|
|
|
|
+ $this->order = $order;
|
|
$this->uid = $uid;
|
|
$this->uid = $uid;
|
|
- $this->orderId = $orderId;
|
|
|
|
$this->traceContext = TraceContext::newFromParent($traceInfo);
|
|
$this->traceContext = TraceContext::newFromParent($traceInfo);
|
|
$this->result = [
|
|
$this->result = [
|
|
'need_report' => true,
|
|
'need_report' => true,
|
|
'config_rate' => 0,
|
|
'config_rate' => 0,
|
|
'current_rate' => 0,
|
|
'current_rate' => 0,
|
|
|
|
+ 'report_success' => false,
|
|
|
|
+ 'info_type' => 'ok',
|
|
];
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
public function report() {
|
|
public function report() {
|
|
- $this->order = DB::table('orders')->where('id', $this->orderId)->first();
|
|
|
|
$this->fillRanseInfo();
|
|
$this->fillRanseInfo();
|
|
$this->fillTrackInfo();
|
|
$this->fillTrackInfo();
|
|
$this->judgeOrderAlreadyDeal();
|
|
$this->judgeOrderAlreadyDeal();
|
|
@@ -42,21 +44,21 @@ class JuliangAccountReportChargeService
|
|
$this->judgeChargeMoney();
|
|
$this->judgeChargeMoney();
|
|
$this->judgePromotionProtect();
|
|
$this->judgePromotionProtect();
|
|
$this->judgeCallbackRate();
|
|
$this->judgeCallbackRate();
|
|
-
|
|
|
|
- dump($this->result);
|
|
|
|
$this->reportJuliang();
|
|
$this->reportJuliang();
|
|
-
|
|
|
|
$this->saveRecord();
|
|
$this->saveRecord();
|
|
}
|
|
}
|
|
|
|
|
|
private function saveRecord() {
|
|
private function saveRecord() {
|
|
|
|
+ dump($this->result);
|
|
|
|
+
|
|
if($this->result['save_record'] ?? true) {
|
|
if($this->result['save_record'] ?? true) {
|
|
$now = date('Y-m-d H:i:s');
|
|
$now = date('Y-m-d H:i:s');
|
|
- if($this->result['info_type'] == 'promotion_protect') {
|
|
|
|
|
|
+ if(($this->result['info_type'] ?? '') == 'promotion_protect') {
|
|
if($this->result['report_success']) {
|
|
if($this->result['report_success']) {
|
|
$protectedRecord = DB::table('juliang_account_promotion_protect_record')
|
|
$protectedRecord = DB::table('juliang_account_promotion_protect_record')
|
|
->where(['adv_promotion_id' => $this->trackRecord->adv_promotion_id,
|
|
->where(['adv_promotion_id' => $this->trackRecord->adv_promotion_id,
|
|
- 'optimizer_uid' => $this->promotion->uid, 'is_enabeld' => 1])
|
|
|
|
|
|
+ 'optimizer_uid' => $this->promotion->uid, 'is_enabled' => 1])
|
|
|
|
+ ->orderBy('id','desc')
|
|
->first();
|
|
->first();
|
|
if($protectedRecord) {
|
|
if($protectedRecord) {
|
|
DB::table('juliang_account_promotion_protect_record')
|
|
DB::table('juliang_account_promotion_protect_record')
|
|
@@ -66,7 +68,7 @@ class JuliangAccountReportChargeService
|
|
} else {
|
|
} else {
|
|
DB::table('juliang_account_promotion_protect_record')
|
|
DB::table('juliang_account_promotion_protect_record')
|
|
->insert([
|
|
->insert([
|
|
- 'adv_promotion_id' => $this->trackRecord->adv_promotion_id,
|
|
|
|
|
|
+ 'adv_promotion_id' => $this->trackRecord->adv_promotion_id ?? '',
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'advertiser_id' => $this->callbackConfig->adv_account_id,
|
|
'advertiser_id' => $this->callbackConfig->adv_account_id,
|
|
'protected_num' => 1,
|
|
'protected_num' => 1,
|
|
@@ -85,7 +87,7 @@ class JuliangAccountReportChargeService
|
|
DB::table('callback_report_charge_record')
|
|
DB::table('callback_report_charge_record')
|
|
->insert([
|
|
->insert([
|
|
'uid' => $this->uid,
|
|
'uid' => $this->uid,
|
|
- 'order_id' => $this->orderId,
|
|
|
|
|
|
+ 'order_id' => $this->order->id,
|
|
'order_no' => $this->order->trade_no,
|
|
'order_no' => $this->order->trade_no,
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'filter_type' => $this->result['info_type'] ?? 'ok',
|
|
'filter_type' => $this->result['info_type'] ?? 'ok',
|
|
@@ -94,8 +96,8 @@ class JuliangAccountReportChargeService
|
|
'report_result' => \json_encode($this->result['report_result'] ?? []),
|
|
'report_result' => \json_encode($this->result['report_result'] ?? []),
|
|
'created_at' => $now,
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
'updated_at' => $now,
|
|
- 'advertiser_id' => $this->trackRecord->advertiser_id,
|
|
|
|
- 'adv_promotion_id' => $this->trackRecord->adv_promotion_id,
|
|
|
|
|
|
+ 'advertiser_id' => $this->trackRecord->advertiser_id ?? '',
|
|
|
|
+ 'adv_promotion_id' => $this->trackRecord->adv_promotion_id ?? '',
|
|
'config_rate' => $this->result['config_rate'],
|
|
'config_rate' => $this->result['config_rate'],
|
|
'current_rate' => $this->result['current_rate'],
|
|
'current_rate' => $this->result['current_rate'],
|
|
]);
|
|
]);
|
|
@@ -104,7 +106,7 @@ class JuliangAccountReportChargeService
|
|
->where(['id' => $chargeRecord->id])
|
|
->where(['id' => $chargeRecord->id])
|
|
->update([
|
|
->update([
|
|
'uid' => $this->uid,
|
|
'uid' => $this->uid,
|
|
- 'order_id' => $this->orderId,
|
|
|
|
|
|
+ 'order_id' => $this->order->id,
|
|
'order_no' => $this->order->trade_no,
|
|
'order_no' => $this->order->trade_no,
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'optimizer_uid' => $this->promotion->uid,
|
|
'filter_type' => $this->result['info_type'] ?? 'ok',
|
|
'filter_type' => $this->result['info_type'] ?? 'ok',
|
|
@@ -112,21 +114,32 @@ class JuliangAccountReportChargeService
|
|
'report_success' => intval($this->result['report_success'] ?? false),
|
|
'report_success' => intval($this->result['report_success'] ?? false),
|
|
'report_result' => \json_encode($this->result['report_result'] ?? []),
|
|
'report_result' => \json_encode($this->result['report_result'] ?? []),
|
|
'updated_at' => $now,
|
|
'updated_at' => $now,
|
|
- 'advertiser_id' => $this->trackRecord->advertiser_id,
|
|
|
|
- 'adv_promotion_id' => $this->trackRecord->adv_promotion_id,
|
|
|
|
|
|
+ 'advertiser_id' => $this->trackRecord->advertiser_id ?? '',
|
|
|
|
+ 'adv_promotion_id' => $this->trackRecord->adv_promotion_id ?? '',
|
|
'config_rate' => $this->result['config_rate'],
|
|
'config_rate' => $this->result['config_rate'],
|
|
'current_rate' => $this->result['current_rate'],
|
|
'current_rate' => $this->result['current_rate'],
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
- DB::table('juliang_account_rate_config_log')
|
|
|
|
- ->where(['id' => $this->rateConfig->id])
|
|
|
|
- ->update([
|
|
|
|
- 'report_count' => $this->rateConfig->report_count + intval($this->result['report_success']),
|
|
|
|
- 'unreport_count' => $this->rateConfig->report_count + intval(!$this->result['report_success']),
|
|
|
|
- 'total_count' => $this->rateConfig->total_count + 1,
|
|
|
|
- 'updated_at' => $now,
|
|
|
|
- ]);
|
|
|
|
|
|
+ if($this->rateConfig) {
|
|
|
|
+ if('ok' == $this->result['info_type'] && $this->result['report_success']) {
|
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
|
+ ->where(['id' => $this->rateConfig->id])
|
|
|
|
+ ->update([
|
|
|
|
+ 'report_count' => $this->rateConfig->report_count + 1,
|
|
|
|
+ 'total_count' => $this->rateConfig->total_count + 1,
|
|
|
|
+ 'updated_at' => $now,
|
|
|
|
+ ]);
|
|
|
|
+ } elseif ('rate_filter' == $this->result['info_type']) {
|
|
|
|
+ DB::table('juliang_account_rate_config_log')
|
|
|
|
+ ->where(['id' => $this->rateConfig->id])
|
|
|
|
+ ->update([
|
|
|
|
+ 'unreport_count' => $this->rateConfig->unreport_count + 1,
|
|
|
|
+ 'total_count' => $this->rateConfig->total_count + 1,
|
|
|
|
+ 'updated_at' => $now,
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -166,7 +179,7 @@ class JuliangAccountReportChargeService
|
|
} else {
|
|
} else {
|
|
$this->result['need_report'] = false;
|
|
$this->result['need_report'] = false;
|
|
$this->result['info_type'] = 'rate_filter';
|
|
$this->result['info_type'] = 'rate_filter';
|
|
- $this->result['info_type'] = '比率过滤';
|
|
|
|
|
|
+ $this->result['info_str'] = '比率过滤';
|
|
$this->result['config_rate'] = $configRate;
|
|
$this->result['config_rate'] = $configRate;
|
|
$this->result['current_rate'] = $currentRate;
|
|
$this->result['current_rate'] = $currentRate;
|
|
}
|
|
}
|
|
@@ -235,7 +248,7 @@ class JuliangAccountReportChargeService
|
|
'promotion_id' => $this->trackRecord->ranse_id,
|
|
'promotion_id' => $this->trackRecord->ranse_id,
|
|
])->where('created_at', '>=', $this->trackRecord->ranse_start_at)
|
|
])->where('created_at', '>=', $this->trackRecord->ranse_start_at)
|
|
->where('created_at', '<=', $this->trackRecord->ranse_end_at)
|
|
->where('created_at', '<=', $this->trackRecord->ranse_end_at)
|
|
- ->where('id', '<', $this->orderId)
|
|
|
|
|
|
+ ->where('id', '<', $this->order->id)
|
|
->count() == 0;
|
|
->count() == 0;
|
|
if($isFirstCharge) {
|
|
if($isFirstCharge) {
|
|
$this->result['need_report'] = true;
|
|
$this->result['need_report'] = true;
|
|
@@ -286,12 +299,17 @@ class JuliangAccountReportChargeService
|
|
$reportResult = $service->reportCharge((object)[
|
|
$reportResult = $service->reportCharge((object)[
|
|
'callback' => $this->trackRecord->callback
|
|
'callback' => $this->trackRecord->callback
|
|
]);
|
|
]);
|
|
- $reportContent = \json_decode($reportResult->content, true);
|
|
|
|
|
|
+ $reportContent = \json_decode($reportResult['content'], true);
|
|
if($reportResult['result'] && 0 == $reportContent['code']) {
|
|
if($reportResult['result'] && 0 == $reportContent['code']) {
|
|
$this->result['report_success'] = true;
|
|
$this->result['report_success'] = true;
|
|
} else {
|
|
} else {
|
|
$this->result['report_success'] = false;
|
|
$this->result['report_success'] = false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 要删除
|
|
|
|
+ */
|
|
|
|
+ $this->result['report_success'] = (bool)rand(0,1);
|
|
$this->result['report_result'] = $reportResult;
|
|
$this->result['report_result'] = $reportResult;
|
|
$this->result['need_report'] = false;
|
|
$this->result['need_report'] = false;
|
|
}
|
|
}
|