zhaoyang 1 vuosi sitten
vanhempi
commit
ef9f5da4cb

+ 165 - 0
modules/Callback/Http/Controllers/TencentAdqController.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace Modules\Callback\Http\Controllers;
+
+use Carbon\Carbon;
+use Illuminate\Http\Request;
+use Catch\Base\CatchController;
+use Modules\Callback\Services\CallbackConst;
+use Modules\Callback\Models\TencentAdqRateConfigLogModel;
+use Modules\Callback\Models\TencentAdqCallbackConfigModel;
+use Modules\Callback\Services\JLEventService;
+use Modules\Common\Errors\Errors;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Modules\Common\Exceptions\CommonBusinessException;
+
+class TencentAdqController extends CatchController
+{
+    use ValidatesRequests;
+
+    public function __construct(protected readonly TencentAdqCallbackConfigModel $tencentAdqCallbackConfigModel,
+    protected readonly TencentAdqRateConfigLogModel $tencentAdqRateConfigLogModel )
+    {
+        
+    }
+
+    /**
+     * 回传配置列表
+     * @param Request $request
+     */
+    public function index(Request $request)
+    {
+        $id = $request->get('id');
+        $name = $request->get('name');
+        $promotionId = $request->get('promotion_id');
+        $unbind = $request->get('unbind', 0);
+
+        $result = $this->tencentAdqCallbackConfigModel
+            ->leftJoin('promotions', function($join){
+                $join->on('promotions.callback_config_id', '=', 'config.id')
+                    ->where('promotions.callback_type' , CallbackConst::TYPE_TENCENT_ADQ_DIRECT);
+            })
+            ->where([
+                'user_id' => $this->getLoginUserId(),
+            ])->when($id, function ($query, $id){
+                return $query->where('config.id', $id);
+            })->when($name, function ($query, $name){
+                return $query->where('config.name', 'like', '%' .$name. '%');
+            })->when($promotionId, function ($query, $promotionId){
+                return $query->where('promotions.id', $promotionId)
+                    ->where('promotions.callback_type' , CallbackConst::TYPE_TENCENT_ADQ_DIRECT);
+            })->when(1 == $unbind, function ($query){
+                return $query->whereNull('promotions.id');
+            })
+            ->select('config.id', 'config.name', 'config.charge_type', 'config.updated_at',
+                'promotions.name as promotion_name', 'promotions.id as promotion_id',
+            'config.charge_money_map', 'config.is_roi')
+            ->orderBy('id', 'desc')
+            ->paginate($request->get('limit', 15));
+        foreach ($result as $item){
+            $item->charge_type_str = CallbackConst::CHARGE_TYPE_MAP[$item->charge_type] ?? '-';
+            $item->charge_money_map = json_decode($item->charge_money_map) ?? [];
+        }
+        return $result;
+
+    }
+
+    /**
+     * 新增回传配置
+     * @param Request $request
+     */
+    public function store(Request $request)
+    {
+        $this->validate($request, [
+            'name' => 'required|string|max:64',
+            // roi 全量上报:1-全量上报,2-不全量上报
+            'is_roi' => 'required|integer|in:1,2',
+            // 充值行为:1-首充,2-所有充值
+            'charge_type' => 'required_if:is_roi,2|integer|in:1,2',
+            // 金额项
+            'charge_money_map'  => 'required_if:is_roi,2|array',
+            'charge_money_map.*.min_money' => 'integer|min:0',
+        ]);
+        if(2 == $request->input('is_roi') &&
+            (!JLEventService::judgeChargeMoneyOk($request->input('charge_money_map')))) {
+            CommonBusinessException::throwError(Errors::CALLBACK_CHARGE_MONEY_MAP_ERROR);
+        }
+        $userId = $this->getLoginUserId();
+
+
+        $model = $this->tencentAdqCallbackConfigModel->create(array_merge($request->only('name', 'is_roi', 'charge_type'), [
+            'charge_money_map' => json_encode($request->input('charge_money_map')),
+            'user_id' => $userId,
+        ]));
+
+        $this->saveRateConfigLog($userId, $model->id, $request->input('charge_money_map', []));
+
+        return 'ok';
+    }
+
+
+    public function update(Request $request)
+    {
+        $this->validate($request, [
+            'ids' => 'required|array',
+            'ids.*' => 'integer',
+            // roi 全量上报:1-全量上报,2-不全量上报
+            'is_roi' => 'required|integer|in:1,2',
+            // 充值行为:1-首充,2-所有充值
+            'charge_type' => 'required_if:is_roi,2|integer|in:1,2',
+            // 金额项
+            'charge_money_map'  => 'required_if:is_roi,2|array',
+            'charge_money_map.*.min_money' => 'integer|min:0',
+        ]);
+
+        if(1 == count($request->post('ids'))) {
+            $updateData = $request->only('is_roi', 'charge_type', 'name');
+        } else {
+            $updateData = $request->only('is_roi', 'charge_type');
+        }
+        $now = Carbon::now();
+        $userId = $this->getLoginUserId();
+        $configIds = $this->tencentAdqCallbackConfigModel->whereIn('id', $request->post('ids'))
+            ->where('user_id', $userId)->select('id')->get()->pluck('id');
+        $this->tencentAdqCallbackConfigModel->whereIn('id', $configIds)
+            ->update(array_merge($updateData, [
+                'charge_money_map' => json_encode($request->post('charge_money_map', [])),
+                'updated_at' => $now,
+            ]));
+        foreach ($configIds as $configId) {
+            $this->saveRateConfigLog($userId, $configId, $request->post('charge_money_map', []));
+        }
+        return 'ok';
+    }
+
+
+
+    private  function saveRateConfigLog($userId, $configId, $chargeMoneyMap){
+        $now = Carbon::now();
+        $this->tencentAdqRateConfigLogModel
+            ->where([
+                'user_id' => $userId, 'config_id' => $configId,
+                'is_enabled' => 1,
+            ])->update([
+                'is_enabled' => 0, 'updated_at' => $now,
+            ]);
+
+        $insertData = [];
+        foreach ($chargeMoneyMap as $item) {
+            if(3 == $item['callback_type']) {
+                $insertData[] = [
+                    'user_id' => $userId,
+                    'config_id' => $configId,
+                    'rate_str' => $item['callback_param'],
+                    'created_at' => $now, 'updated_at' => $now,
+                    'min_money' => $item['min_money'],
+                    'max_money' => $item['max_money']
+                ];
+            }
+        }
+        if(count($insertData)) {
+            $this->tencentAdqRateConfigLogModel->insert($insertData);
+        }
+    }
+
+}

+ 16 - 0
modules/Callback/Models/TencentAdqCallbackConfigModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace Modules\Callback\Models;
+
+use Catch\Base\CatchModel as Model;
+
+
+class TencentAdqCallbackConfigModel extends Model
+{
+    protected $table = 'tencent_adq_callback_config';
+
+    protected $fillable = [
+        'id', 'name', 'user_id', 'is_roi', 'charge_type', 'charge_money_map', 'created_at', 'updated_at', 
+    ];
+
+}

+ 16 - 0
modules/Callback/Models/TencentAdqRateConfigLogModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace Modules\Callback\Models;
+
+use Catch\Base\CatchModel as Model;
+
+
+class TencentAdqRateConfigLogModel extends Model
+{
+    protected $table = 'tencent_adq_rate_config_log';
+
+    protected $fillable = [
+        'id', 'user_id', 'config_id', 'rate_str', 'is_enabled', 'report_count', 'unreport_count', 'min_money', 'max_money', 'callback_type', 'callback_param', 'flag', 'flag_report', 'flag_unreport', 'created_at', 'updated_at', 
+    ];
+
+}

+ 3 - 0
modules/Callback/Services/CallbackConst.php

@@ -12,6 +12,9 @@ class CallbackConst
      * 回传类型:巨量2.0事件
      */
     const TYPE_JL_EVENT_20 = 2;
+
+    const TYPE_TENCENT_ADQ_DIRECT = 3;
+
     /**
      * 充值行为类型
      */

+ 8 - 0
modules/Callback/routes/route.php

@@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route;
 use Modules\Callback\Http\Controllers\CallbackLogController;
 use Modules\Callback\Http\Controllers\JLEvent\JLEventController;
 use Modules\Callback\Http\Controllers\JuliangAccountController;
+use Modules\Callback\Http\Controllers\TencentAdqController;
 
 Route::prefix('callback')->group(function () {
     Route::prefix('juliangAccount')->group(function(){
@@ -21,5 +22,12 @@ Route::prefix('callback')->group(function () {
         Route::post('update', [JLEventController::class, 'update']);
         Route::get('list', [JLEventController::class, 'list']);
     });
+
+    Route::prefix('tencentadq')->group(function(){
+        Route::post('add', [TencentAdqController::class, 'index']);
+        Route::post('update', [TencentAdqController::class, 'update']);
+        Route::get('index', [TencentAdqController::class, 'index']);
+    });
+
 });