Преглед изворни кода

Merge branch 'liuzj-pay-dev' into test

liuzejian пре 2 година
родитељ
комит
e732980ff4

+ 3 - 2
modules/Callback/Http/Controllers/CallbackLogController.php

@@ -42,15 +42,16 @@ class CallbackLogController extends CatchController
             })->when($userRanseStartAtBeginTime, function ($query, $userRanseStartAtBeginTime){
                 return $query->where('user_ranse_start_at', '>=', $userRanseStartAtBeginTime);
             })->when($userRanseStartAtEndTime, function ($query, $userRanseStartAtEndTime){
-                return $query->where('user_ranse_start_at', '<=', $userRanseStartAtEndTime);
+                return $query->where('user_ranse_start_at', '<=', $userRanseStartAtEndTime . ' 23:59:59');
             })->when($orderCreatedAtBeginTime, function ($query, $orderCreatedAtBeginTime){
                 return $query->where('order_created_at', '>=', $orderCreatedAtBeginTime);
             })->when($miniprogramId, function ($query, $miniprogramId){
                 return $query->where('miniprogram_id', $miniprogramId);
             })
             ->when($orderCreatedAtEndTime, function ($query, $orderCreatedAtEndTime) {
-                return $query->where('order_created_at', '<=', $orderCreatedAtEndTime);
+                return $query->where('order_created_at', '<=', $orderCreatedAtEndTime. ' 23:59:59');
             })->orderBy('created_at', 'desc');
+   
         if($isExport) {
             $result = $sql->get();
         } else {

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

@@ -18,15 +18,48 @@ 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')
+        $list =  DB::table('juliang_account_callback_config')
             ->where(['company_uid' => $this->getOptimizerUid()])
             ->when($advAccountId, function ($query, $advAccountId) {
                 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));
+        $ids = collect($list->items())->pluck('id');
+        $promotions = DB::table('promotions')
+            ->where([
+                'uid' => $this->getOptimizerUid(),
+                'callback_type' => 1,
+                'status' => 1,
+                'is_enabled' => 1,
+            ])->whereIn('callback_config_id', $ids)
+            ->select('name', 'id', 'callback_config_id')
+            ->get()->keyBy('callback_config_id');
+        foreach ($list as $item) {
+            $item->promotion_name = $promotions->get($item->id)->name ?? '';
+            $item->promotion_id = $promotions->get($item->id)->id ?? '';
+        }
+
+        return $list;
     }
 
     public function addAccount(Request $request) {
@@ -270,4 +303,65 @@ class JuliangAccountController extends CatchController
 
         return 'ok';
     }
+
+    /**
+     * 解绑推广
+     * @param Request $request
+     */
+    public function unbindPromotion(Request $request) {
+        $this->validate($request, [
+            'id' => 'required'
+        ]);
+
+        $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);
+        }
+        $now = date('Y-m-d H:i:s');
+        $affected = DB::table('promotions')
+            ->where([
+                'callback_type' => 1,
+                'callback_config_id' => $request->input('id'),
+                'is_enabled' => 1,
+                'status' => 1,
+            ])->update([
+                'status' => 0,
+                'updated_at' => $now,
+            ]);
+        if($affected) {
+            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

@@ -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']);
     });

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

@@ -21,7 +21,7 @@ class Errors
     public const  CALLBACK_RATE_TIME_RANGE_ERROR= [500102, '回传比例时间区间不合法'];
     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_PROMOTION_UNIQUE = [500105, '巨量广告账户只允许绑定一个推广,请先解绑'];
     public const  JULIANG_ACCOUNT_CONFIG_NOT_EXISTS = [500106, '回传配置不存在'];
     public const  TIXIAN_YUE_BUZU = [500201, '提现余额不足'];
     public const  BANK_CARD_STATUS_ERROR = [500202, '银行卡不存在或当前状态不可提现'];

+ 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);

+ 2 - 2
modules/Tuiguang/config/tuiguang.php

@@ -4,9 +4,9 @@ return [
     /**
      * 推广链接地址
      */
-    'url' => env('TUIGUAGN_URL', 'https://api.dududus.com'),
+    'url' => env('TUIGUAGN_URL', 'https://api.zhiyupa.com'),
     /**
      * 监测链接地址
      */
-    'trackUrl' => env('TUIGUAGN_TRACK_URL', 'https://track.dududus.com')
+    'trackUrl' => env('TUIGUAGN_TRACK_URL', 'https://track.zhiyupa.com')
 ];

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

@@ -54,6 +54,7 @@ class JuliangAccountControllerTest extends UsedTestCase
             'Authorization' => 'Bearer '. $this->token,
         ])->json('get','http://localhost/api/callback/juliangAccount/list');
 
+        $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'];
     }