瀏覽代碼

Merge branch 'stable' into liuzj-wechat-check-dev

liuzejian 1 年之前
父節點
當前提交
8e75e5da17

+ 0 - 249
app/Jobs/Callback/RechargeReport.php

@@ -1,249 +0,0 @@
-<?php
-
-namespace App\Jobs\OrangeSite;
-
-use App\Modules\Callback\Models\ChannelCallbackConfig;
-use App\Modules\Callback\Services\CallbackBaseService;
-use App\Modules\OrangeSite\Services\CheckReport\EnableReportCheck;
-use App\Modules\OrangeSite\Services\CheckReport\OrderAlreadyReportCheck;
-use App\Modules\OrangeSite\Services\CheckReport\PromotionProtectCheck;
-use App\Modules\OrangeSite\Services\CheckReport\RechargeAmountCheck;
-use App\Modules\OrangeSite\Services\CheckReport\ReportRateCheck;
-use App\Modules\OrangeSite\Services\CheckReport\ReportRechargeTypeCheck;
-use App\Modules\OrangeSite\Services\OrangeSitePromotionService;
-use App\Modules\OrangeSite\Services\OrangeSiteRechargeReportCheckContext;
-use App\Modules\OrangeSite\Services\OrangeSiteReportRateService;
-use App\Modules\Order\Models\ReportUserChargeRecord;
-use App\Modules\Trace\TraceContext;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Foundation\Bus\Dispatchable;
-use Illuminate\Pipeline\Pipeline;
-use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\SerializesModels;
-use Illuminate\Support\Facades\DB;
-
-class RechargeReport implements ShouldQueue
-{
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
-    public const QUEUE = '{orangeSite}.report.recharge';
-    public const CONNECTION = 'redis_queue';
-
-    public const PLATFORM = 'orange';
-    /**
-     * @var array
-     * <pre>
-     * [
-     *      'channelId' => 'xxx, // 站点id
-     *      'orderId' => 'xxx', // 订单id
-     *      'uid' => 'xxx', // 充值用户uid
-     * ]
-     * </pre>
-     */
-    private $reportInfo;
-
-    /**
-     * Create a new job instance.
-     *
-     * @return void
-     */
-    public function __construct(array $reportInfo)
-    {
-        $this->reportInfo = $reportInfo;
-    }
-
-    /**
-     * Execute the job.
-     *
-     * @return void
-     */
-    public function handle()
-    {
-        $traceContext = new TraceContext();
-        \Log::info('[orangeSiteRechargeReport]开始回传', [
-            'reportInfo' => $this->reportInfo,
-            'traceInfo' => $traceContext->getTraceInfo()
-        ]);
-        $user = DB::table('users')->find(($this->reportInfo['uid'] ?? -1));
-        $order = DB::table('orders')->where([
-            ['id', '=', ($this->reportInfo['orderId'] ?? -1)],
-            ['status', '=', 'PAID']
-        ])->first();
-        $channelCallbackConfig = ChannelCallbackConfig::where('channel_id', ($this->reportInfo['channelId'] ?? -1))
-            ->where('platform', self::PLATFORM)->first();
-
-        $channelSettingRate = OrangeSiteReportRateService::getChannelSettingReportRate($user->distribution_channel_id);
-        $reportCheckContext = new OrangeSiteRechargeReportCheckContext($user, $order, $channelCallbackConfig,
-            $traceContext, $channelSettingRate);
-
-        try {
-            $reportCheckContext->checkNecessaryInfo();
-        } catch (\Exception $exception) {
-            \Log::error('[orangeSiteRechargeReport]回传基础信息有误', [
-                'message' => $exception->getMessage(),
-                'traceInfo' => $traceContext->getTraceInfo()
-            ]);
-            dingTalkAlert(config('common.orangeSite.dingTalkUrl'), "[orangeSite]订单回传基础信息有误报警:\r\n" .
-                \json_encode([
-                    'reportInfo' => $this->reportInfo,
-                    'message' => $exception->getMessage(),
-                    'traceInfo' => $traceContext->getTraceInfo()
-                ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
-            return;
-        }
-
-
-        $pipes = [
-            EnableReportCheck::class,
-            OrderAlreadyReportCheck::class,
-            ReportRechargeTypeCheck::class,
-            RechargeAmountCheck::class,
-            PromotionProtectCheck::class,
-            ReportRateCheck::class
-        ];
-
-        $content = app(Pipeline::class)
-            ->send($reportCheckContext)
-            ->through($pipes)
-            ->then(function ($content) {
-                return $content;
-            });
-        $result = $content->result;
-        \Log::info('[orangeSiteRechargeReport]回传判定结果', [
-            'result' => $result,
-            'traceInfo' => $traceContext->getTraceInfo()]);
-        if ($result['needRecord'] ?? true) {
-            $this->saveReportUserChargeReportInfo($reportCheckContext, $result);
-        }
-        if ($result['result']) {
-            $this->reportRecharge($reportCheckContext, $result);
-        }
-    }
-
-    private function reportRecharge(OrangeSiteRechargeReportCheckContext $reportCheckContext, array $checkResult)
-    {
-        $params = [
-            'uid' => $reportCheckContext->user->id,
-            'source' => 'zsy',
-            'amount' => $reportCheckContext->order->price ?? 0,
-            'link_source' => 'tiktok_event',
-        ];
-
-
-        $result = $this->reprotResultDeal(CallbackBaseService::directlyCharge($params));
-
-        $resultContent = \json_decode(($result['content'] ?? '[]'), true);
-
-        $updateInfo = [
-            'status' => $result['status'] ?? 0,
-            'request_param' => $result['request_param'] ?? '',
-            'updated_at' => date('Y-m-d H:i:s'),
-            'content' => \json_encode(array_merge($resultContent,
-                ['log_content' => ($reportCheckContext->result['content'] ?? '')]))
-        ];
-
-        \Log::info('[orangeSiteRechargeReport]请求回传接口结果:' . ($updateInfo['status'] ? '成功' : '失败'), [
-            'status' => $updateInfo['status'],
-            'traceInfo' => $reportCheckContext->traceContext->getTraceInfo()]);
-
-        DB::transaction(function () use ($reportCheckContext, $updateInfo, $checkResult, $result) {
-            DB::table('report_user_charge_records')->where([
-                'order_no' => $reportCheckContext->order->trade_no,
-                'uid' => $reportCheckContext->order->uid,
-                'link_source' => $reportCheckContext->platform,
-            ])->update($updateInfo);
-
-            if (1 == $result['status']) {
-                /**
-                 * 如果是计划保护回传成功的,只增加 orange_site_recharge_report_protect_records.current_protect_num,
-                 * 而不增加 orange_site_recharge_report_records.rate_total_num 和 orange_site_recharge_report_records.rate_success_num
-                 */
-                if ('promotionProtect' == ($checkResult['result_ok_reason'] ?? '')) {
-                    \Log::debug('[orangeSiteRechargeReport]回传成功,增加对应计划的成功数', [
-                        'traceInfo' => $reportCheckContext->traceContext->getTraceInfo(),
-                        'promotionId' => $reportCheckContext->reportInfo['promotionId']]);
-
-                    OrangeSitePromotionService::setCurrentPromotionProtectNum($reportCheckContext->user->distribution_channel_id,
-                        $reportCheckContext->reportInfo['promotionId'],
-                        $reportCheckContext->channelCallbackConfig->eligible_count ?: 0);
-                } else {
-                    OrangeSiteReportRateService::increaseSuccessNum($reportCheckContext->user->distribution_channel_id,
-                        $reportCheckContext->reportInfo['configRate']);
-                }
-
-            } else {
-                if ('promotionProtect' != ($checkResult['result_ok_reason'] ?? '')) {
-                    \Log::error('[orangeSiteRechargeReport]订单回传失败', [
-                        'traceInfo' => $reportCheckContext->traceContext->getTraceInfo()]);
-                    OrangeSiteReportRateService::increaseFailNum($reportCheckContext->user->distribution_channel_id,
-                        $reportCheckContext->reportInfo['configRate']);
-                } else {
-                    \Log::error('[orangeSiteRechargeReport]计划保护订单回传失败', [
-                        'traceInfo' => $reportCheckContext->traceContext->getTraceInfo()]);
-                }
-            }
-        });
-    }
-
-
-    /**
-     * [调用tiktok 接口回传后,数据处理逻辑]
-     * @return [type]          [description]
-     */
-    public function reprotResultDeal($result)
-    {
-        $status = 0;
-        $content = '';
-        $result_data = isset($result['data']) ? $result['data'] : [];
-        if (!empty($result_data['content'])) {
-            $content = $result_data['content'];
-            $con_arr = json_decode($content, true);
-            $content = json_encode($con_arr);
-            if (isset($con_arr['code']) && 0 == $con_arr['code']) {
-                //tiktok_event
-                $status = 1;
-            }
-        }
-        //处理请求参数
-        $request_param = '';
-        if (isset($result_data['query_params'])) {
-            if (is_string($result_data['query_params'])) {
-                $request_param = $result_data['query_params'];
-            }
-            if (is_array($result_data['query_params'])) {
-                $request_param = json_encode($result_data['query_params']);
-            }
-        }
-        $data = [
-            'status' => $status,
-            'request_param' => $request_param,
-        ];
-        if ($content) {
-            $data['content'] = $content;
-        }
-        return $data;
-    }
-
-    private function saveReportUserChargeReportInfo(OrangeSiteRechargeReportCheckContext $reportCheckContext, array $result)
-    {
-        $data = [
-            'uid' => $this->reportInfo['uid'],
-            'config_percent' => round($reportCheckContext->reportInfo['configRate'] / 100, 4),
-            'report_percent' => round($reportCheckContext->reportInfo['reportRate'] / 100, 4),
-            'order_no' => $reportCheckContext->order->trade_no,
-            'timestamp' => time(),
-            'status' => 0,
-            'type' => $result['type'] ?? '',
-            'content' => $result['content'] ?? '',
-            'channel_id' => $reportCheckContext->user->distribution_channel_id,
-            'request_param' => '',
-            'link_source' => $reportCheckContext->platform,
-        ];
-        ReportUserChargeRecord::updateOrCreate([
-            'order_no' => $data['order_no'],
-            'uid' => $data['uid'],
-            'link_source' => $data['link_source'],
-        ], $data);
-    }
-}

+ 4 - 1
app/Jobs/Callback/ReportCharge.php

@@ -48,7 +48,10 @@ class ReportCharge implements ShouldQueue
 
         $order = DB::table('orders')->where('id', $this->info['orderId'])->first();
         if($order && $order->promotion_id) {
-            $promotion = DB::table('promotions')->where('id', $order->promotion_id)->first();
+            $promotion = DB::table('promotions')->where([
+                'id'=> $order->promotion_id,
+                'is_enabled' => 1
+            ])->first();
             switch ($promotion->callback_type ?? 0) {
                 case 0:
                     myLog('reportCharge')->error('end:订单染色配置有问题', [

+ 7 - 1
app/Service/Callback/JuliangAccountReportChargeService.php

@@ -289,11 +289,17 @@ class JuliangAccountReportChargeService
     }
 
     /**
-     * 获取订单的染色信息,回传配置信息
+     * 获取订单的染色信息,回传配置信息, 推广被禁用,就按照没有回传配置处理
      */
     private function fillRanseInfo() {
         $ranseId = $this->order->promotion_id;
         $this->promotion = DB::table('promotions')->where('id', $ranseId)->first();
+        if(0 == $this->promotion->status) {
+            $this->result['need_report'] = false;
+            $this->result['info_type'] = 'no_callback_config';
+            $this->result['info_str'] = '没有回传配置';
+            return;
+        }
         $this->callbackConfig = DB::table('juliang_account_callback_config')
             ->where(['id' => $this->promotion->callback_config_id])
             ->first();

+ 1 - 1
config/logging.php

@@ -54,7 +54,7 @@ return [
     'channels' => [
         'stack' => [
             'driver' => 'stack',
-            'channels' => ['single'],
+            'channels' => ['daily'],
             'ignore_exceptions' => false,
         ],