Browse Source

Merge branch 'liuzj-permission-dev' into test

liuzejian 1 year ago
parent
commit
bcfc7b9964

+ 53 - 0
modules/Callback/Http/Controllers/JuliangAccountController.php

@@ -217,4 +217,57 @@ class JuliangAccountController extends CatchController
         //插入设置最新的时间段百分比
         DB::table('juliang_account_promotion_config_time')->insert($data);
     }
+
+    /**
+     * 回传开关
+     * @param Request $request
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function turnCallbackState(Request $request) {
+        $this->validate($request, ['state' => 'required|integer|in:0,1',
+            'id' => 'required']);
+        $now = date('Y-m-d H:i:s');
+        $config = DB::table('juliang_account_callback_config')
+            ->where([
+                'id' => $request->input('id'),
+                'company_uid' => $this->getOptimizerUid(),
+            ])->first();
+        if(!$config) {
+            CommonBusinessException::throwError(Errors::JULIANG_ACCOUNT_CONFIG_NOT_EXISTS);
+        }
+        DB::table('juliang_account_callback_config')
+            ->where('id', $request->input('id'))
+            ->update([
+                'state' => $request->input('state'),
+                'updated_at' => $now
+            ]);
+        if(1 == $request->input('state')) {
+            DB::table('juliang_account_rate_config_log')
+                ->where('company_uid', $this->getOptimizerUid())
+                ->where('account_id', $config->adv_account_id)
+                ->where('is_enabled', 1)
+                ->update(['is_enabled' => 0, 'updated_at' => $now]);
+            DB::table('juliang_account_promotion_protect_record')
+                ->where('optimizer_uid', $this->getOptimizerUid())
+                ->where('advertiser_id', $config->adv_account_id)
+                ->where('is_enabled', 1)
+                ->update(['is_enabled' => 0, 'updated_at' => $now]);
+            DB::table('juliang_account_rate_config_log')
+                ->insert([
+                    'company_uid' => $this->getOptimizerUid(),
+                    'account_id' => $config->adv_account_id,
+                    'config_per' => $config->default_rate,
+                    'created_at' => $now,
+                    'updated_at' => $now,
+                ]);
+            // 让所有的时间区间比例配置,在定时任务中,重新执行一遍
+            DB::table('juliang_account_promotion_config_time')
+                ->where('is_enable',1)
+                ->where('company_uid',$this->getOptimizerUid())
+                ->where('account_id',$config->adv_account_id)
+                ->update(['next_exec_time' => date('Y-m-d'), 'updated_at' => $now]);
+        }
+
+        return 'ok';
+    }
 }

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

@@ -9,6 +9,7 @@ Route::prefix('callback')->group(function () {
         Route::get('list', [JuliangAccountController::class, 'list']);
         Route::post('addAccount', [JuliangAccountController::class, 'addAccount']);
         Route::post('updateCallbackConfig', [JuliangAccountController::class, 'updateCallbackConfig']);
+        Route::post('turnCallbackState', [JuliangAccountController::class, 'turnCallbackState']);
         Route::get('log/list', [CallbackLogController::class, 'list']);
         Route::post('log/callbackAgain', [CallbackLogController::class, 'callbackAgain']);
     });

+ 1 - 0
modules/Common/Errors/Errors.php

@@ -22,4 +22,5 @@ class Errors
     public const  CALLBACK_RECORD_NOT_EXISTS= [500103, '回传日志不存在'];
     public const  CALLBACK_RECORD_LOG_ERROR= [500104, '回传日志补传信息缺失'];
     public const  JULIANG_ACCOUNT_PROMOTION_UNIQUE = [500105, '巨量广告账户只允许绑定一个推广'];
+    public const  JULIANG_ACCOUNT_CONFIG_NOT_EXISTS = [500106, '回传配置不存在'];
 }

+ 10 - 0
tests/Callback/Http/Controllers/JuliangAccountControllerTest.php

@@ -56,4 +56,14 @@ class JuliangAccountControllerTest extends UsedTestCase
 
         $this->dumpJson($res);
     }
+
+    public function testturnCallbackState() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/callback/juliangAccount/turnCallbackState', [
+            'id' => 5,
+            'state' => 1
+        ]);
+        $res->dump();
+    }
 }