liuzejian 1 рік тому
батько
коміт
f07f2d6225

+ 21 - 2
modules/Callback/Http/Controllers/JuliangAccountController.php

@@ -18,6 +18,20 @@ class JuliangAccountController extends CatchController
     public function list(Request $request) {
         $advAccountId = $request->input('account_id');
         $advAccountName = $request->input('account_name');
+        $unBind = $request->input('unbind', 0);
+        $alreadyBindConfigIds = null;
+        if($unBind) {
+            $alreadyBindConfigIds = DB::table('promotions')
+                ->where([
+                    'uid' => $this->getOptimizerUid(),
+                    'callback_type' => 1,
+                    'status' => 1,
+                    'is_enabled' => 1,
+                ])->where('callback_config_id' , '<>', 0)
+                ->distinct()
+                ->select('callback_config_id')
+                ->get()->pluck('callback_config_id')->toArray();
+        }
 
         return DB::table('juliang_account_callback_config')
             ->where(['company_uid' => $this->getOptimizerUid()])
@@ -25,7 +39,10 @@ class JuliangAccountController extends CatchController
                 return $query->where('adv_account_id' , $advAccountId);
             })->when($advAccountName, function ($query, $advAccountName) {
                 return $query->where('adv_account_name', 'like', '%'. $advAccountName. '%');
-            })->orderBy('id', 'desc')
+            })->when($alreadyBindConfigIds, function ($query, $alreadyBindConfigIds) {
+                return $query->whereNotIn('id', $alreadyBindConfigIds);
+            })
+            ->orderBy('id', 'desc')
             ->paginate($request->input('limit', 30));
     }
 
@@ -295,8 +312,9 @@ class JuliangAccountController extends CatchController
                 'callback_type' => 1,
                 'callback_config_id' => $request->input('id'),
                 'is_enabled' => 1,
+                'status' => 1,
             ])->update([
-                'callback_config_id' => 0,
+                'status' => 0,
                 'updated_at' => $now,
             ]);
         DB::table('juliang_account_rate_config_log')
@@ -326,4 +344,5 @@ class JuliangAccountController extends CatchController
 
         return 'ok';
     }
+
 }

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

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

+ 4 - 2
modules/Tuiguang/Http/Controllers/PromotionController.php

@@ -54,9 +54,10 @@ class PromotionController extends CatchController
             })->orderBy('created_at', 'desc')
             ->select('promotions.id', 'promotions.name', 'promotions.created_at',
             'videos.name as video_name', 'promotions.series_sequence', 'promotions.callback_type',
-                'promotions.callback_config_id', 'promotions.video_id', 'promotions.remark')
+                'promotions.callback_config_id', 'promotions.video_id', 'promotions.remark', 'promotions.status')
             ->paginate($request->input('limit', 15));
         foreach ($result as $item) {
+            $item->status_str = $item->status ? '启用':'禁用';
             $item->series_sequence_name = '第'. $item->series_sequence . '集';
             $item->callback_type_str = $callbackTypeMap[$item->callback_type] ?? '';
             $item->promotion_path = config('tuiguang.tuiguang.url') . DIRECTORY_SEPARATOR . 'api/promotion/index?ranse_id='. $item->id;
@@ -131,7 +132,8 @@ class PromotionController extends CatchController
         if(1 == $request->input('callback_type')) {
             $exist = DB::table('promotions')
                 ->where(['is_enabled' => 1, 'callback_type' => $request->input('callback_type'),
-                    'callback_config_id' => $request->input('callback_config_id')])
+                    'callback_config_id' => $request->input('callback_config_id'),
+                    'status' => 1])
                 ->first();
             if($exist && $exist->id != $request->input('id')) {
                 CommonBusinessException::throwError(Errors::JULIANG_ACCOUNT_PROMOTION_UNIQUE);

+ 11 - 1
tests/Callback/Http/Controllers/JuliangAccountControllerTest.php

@@ -52,8 +52,9 @@ class JuliangAccountControllerTest extends UsedTestCase
     public function testList() {
         $res = $this->withHeaders([
             'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/callback/juliangAccount/list');
+        ])->json('get','http://localhost/api/callback/juliangAccount/list?unbind=1');
 
+        $res->dump();
         $this->dumpJson($res);
     }
 
@@ -66,4 +67,13 @@ class JuliangAccountControllerTest extends UsedTestCase
         ]);
         $res->dump();
     }
+
+    public function testunbindPromotion() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/callback/juliangAccount/unbindPromotion', [
+            'id' => 5,
+        ]);
+        $res->dump();
+    }
 }

+ 2 - 2
tests/UsedTestCase.php

@@ -13,11 +13,11 @@ abstract class UsedTestCase extends BaseTestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $tokenInfo = $this->post('http://localhost/api/login', [
-            'email' => 'catch@admin.com',
+//            'email' => 'catch@admin.com',
             'remember' => false,
 //            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
-//            'email' => 'aa4@test.com',
+            'email' => 'aa4@test.com',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }