Ver Fonte

Merge branch 'liuzj-permission-dev' into test

liuzejian há 1 ano atrás
pai
commit
20d1925f39

+ 121 - 0
modules/Tuiguang/Http/Controllers/PromotionController.php

@@ -0,0 +1,121 @@
+<?php
+
+namespace Modules\Tuiguang\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Modules\Common\Errors\Errors;
+use Modules\Common\Exceptions\CommonBusinessException;
+use Modules\User\Http\Controllers\UserTrait;
+
+class PromotionController extends CatchController
+{
+    use UserTrait;
+    use ValidatesRequests;
+
+    public function list(Request $request) {
+        $callbackTypeMap = [
+            '0' => '无',
+            '1' => '巨量账户级回传',
+        ];
+        $name = $request->input('name');
+        $isConfig = $request->input('is_config', 1);
+        $id = $request->input('id');
+        $videoName = $request->input('video_name');
+        $starTime = $request->input('start_time');
+        $endTime = $request->input('endTime');
+        $miniprogramId = $request->input('miniprogram_id');
+        $result = DB::table('promotions')
+            ->leftJoin('videos', 'videos.id', '=', 'promotions.video_id')
+            ->where(['promotions.is_enabled' => 1, 'promotions.uid' => $this->getLoginUserId()])
+            ->when($miniprogramId, function ($query, $miniprogramId) {
+                return $query->where('promotions.miniprogram_id', $miniprogramId);
+            })
+            ->when($isConfig, function ($query) {
+                return $query->where('promotions.callback_config_id', '<>', 0);
+            }, function ($query) {
+                return $query->where('promotions.callback_config_id', 0);
+            })->when($name, function ($query, $name){
+                return $query->where('promotions.name', 'like', '%'. $name . '%');
+            })->when($id, function ($query, $id) {
+                return $query->where('promotions.id', $id);
+            })->when($videoName, function ($query, $videoName) {
+                return $query->where('videos.name', 'like', '%'. $videoName . '%');
+            })->when($starTime, function ($query, $startTime) {
+                return $query->where('promotions.created_at', '>=', $startTime);
+            })->when($endTime, function ($query, $endTime){
+                return $query->where('promotions.created_at', '<=', $endTime);
+            })->select('promotions.id', 'promotions.name', 'promotions.created_at',
+            'videos.name as video_name', 'promotions.series_sequence', 'promotions.callback_type', 'promotions.callback_config_id')
+            ->paginate($request->input('limit', 15));
+        foreach ($result as $item) {
+            $item->callback_type_str = $callbackTypeMap[$item->callback_type] ?? '';
+            // todo: 待完善
+            $item->promotion_path = '';
+            $item->track_url = '';
+        }
+
+        return $result;
+
+    }
+
+    public function delete(Request $request) {
+        $this->validate($request, ['id' => 'required']);
+
+        DB::table('promotions')
+            ->where(['id' => $request->input('id'), 'uid' => $this->getLoginUserId(), 'is_enabled' => 1])
+            ->update(['is_enabled' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
+
+        return 'ok';
+    }
+
+    public function updateSeriesSequence(Request $request) {
+        $this->validate($request, ['id' => 'required', 'series_sequence' => 'required']);
+
+        DB::table('promotions')
+            ->where(['id' => $request->input('id'), 'uid' => $this->getLoginUserId(), 'is_enabled' => 1])
+            ->update(['series_sequence' => $request->input('series_sequence')
+                , 'updated_at' => date('Y-m-d H:i:s')]);
+
+        return 'ok';
+    }
+
+    public function add(Request $request) {
+        $this->validate($request, [
+            'video_id' => 'required',
+            'series_sequence' => 'required',
+            'name' => 'required',
+            'miniprogram_id' => 'required',
+        ]);
+        $now = date('Y-m-d H:i:s');
+        DB::table('promotions')
+            ->insert([
+                'uid' => $this->getLoginUserId(),
+                'miniprogram_id' => $request->input('miniprogram_id'),
+                'name' => $request->input('name'),
+                'video_id' => $request->input('video_id'),
+                'series_sequence' =>  $request->input('series_sequence'),
+                'created_at' => $now,
+                'updated_at' => $now,
+            ]);
+        return 'ok';
+    }
+
+    public function updateCallbackConfig(Request $request) {
+        $this->validate($request, [
+            'id' => 'required',
+            'callback_type' => 'required|in:1',
+            'callback_config_id' => 'required'
+        ]);
+        DB::table('promotions')
+            ->where(['id' => $request->input('id'), 'uid' => $this->getLoginUserId(), 'is_enabled' => 1])
+            ->update([
+                'callback_type' => $request->input('callback_type'),
+                'callback_config_id' => $request->input('callback_config_id'),
+                'updated_at' => date('Y-m-d')
+            ]);
+        return 'ok';
+    }
+}

+ 32 - 0
modules/Tuiguang/Installer.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Modules\ContentManage;
+
+use Catch\Support\Module\Installer as ModuleInstaller;
+use Modules\ContentManage\Providers\ContentManageServiceProvider;
+
+class Installer extends ModuleInstaller
+{
+    protected function info(): array
+    {
+        // TODO: Implement info() method.
+        return [
+            'title' => '内容中台',
+            'name' => 'contentManage',
+            'path' => 'contentManage',
+            'keywords' => '内容中台',
+            'description' => '内容中台管理模块',
+            'provider' => ContentManageServiceProvider::class
+        ];
+    }
+
+    protected function requirePackages(): void
+    {
+        // TODO: Implement requirePackages() method.
+    }
+
+    protected function removePackages(): void
+    {
+        // TODO: Implement removePackages() method.
+    }
+}

+ 29 - 0
modules/Tuiguang/Providers/TuiguangServiceProvider.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace Modules\Tuiguang\Providers;
+
+use Catch\Providers\CatchModuleServiceProvider;
+
+class TuiguangServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+       return [];
+    }
+
+    /**
+     * route path
+     *
+     * @return string|array
+     */
+    public function moduleName(): string|array
+    {
+        // TODO: Implement path() method.
+        return 'tuiguang';
+    }
+}

+ 10 - 0
modules/Tuiguang/README.md

@@ -0,0 +1,10 @@
+#内容中台管理模块
+关于内容中台 相关的后台接口,对外api接口,都写在这里
+配置文件放在: config目录下,读取配置文件示例:config('contentManage.zhushuyunpublicapi.public_domain');
+config("模块名.配置文件名.配置项");
+
+数据库模型文件放在:Models 目录下面
+服务层文件放在:Services 目录下面
+控制器放在:modules/ContentManage/Http/Controllers 目录下面
+中间件放在:modules/ContentManage/Middlewares 目录下面
+路由只能现在 modules/ContentManage/rout/route.php 文件里

+ 16 - 0
modules/Tuiguang/routes/route.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use Modules\Callback\Http\Controllers\JuliangAccountController;
+use Modules\Tuiguang\Http\Controllers\PromotionController;
+
+Route::prefix('tuiguang')->group(function () {
+    Route::prefix('promotion')->group(function(){
+        Route::get('list', [PromotionController::class, 'list']);
+        Route::post('updateSeriesSequence', [PromotionController::class, 'updateSeriesSequence']);
+        Route::post('delete', [PromotionController::class, 'delete']);
+        Route::post('add', [PromotionController::class, 'add']);
+        Route::post('updateCallbackConfig', [PromotionController::class, 'updateCallbackConfig']);
+    });
+});
+

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

@@ -47,4 +47,11 @@ class JuliangAccountControllerTest extends UsedTestCase
         ]);
         $res->dump();
     }
+    public function testList() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/callback/juliangAccount/list');
+
+        $this->dumpJson($res);
+    }
 }

+ 75 - 0
tests/Tuiguang/Http/Controllers/PromotionControllerTest.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace Tests\Tuiguang\Http\Controllers;
+
+use Modules\Tuiguang\Http\Controllers\PromotionController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class PromotionControllerTest extends UsedTestCase
+{
+
+    public function testAdd()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/tuiguang/promotion/add', [
+            'video_id' => 6,
+            'series_sequence'  => 4,
+            'name' => 'kkkkddd',
+            'miniprogram_id' => 2,
+        ]);
+
+        $res->dump();
+    }
+
+    public function testDelete()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/tuiguang/promotion/delete', [
+            'id' => 1
+        ]);
+
+        $res->dump();
+    }
+
+
+    public function testupdateSeriesSequence()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/tuiguang/promotion/updateSeriesSequence', [
+            'id' => 2,
+            'series_sequence' => 5
+        ]);
+
+        $res->dump();
+    }
+
+    public function testList()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/tuiguang/promotion/list', [
+//            'is_config' => 0,
+//            'name' => 'kkk'
+        ]);
+
+//        $res->dump();
+        $this->dumpJson($res);
+    }
+
+    public function testupdateCallbackConfig() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/tuiguang/promotion/updateCallbackConfig', [
+            'id' => 2,
+            'callback_type' => 1,
+            'callback_config_id' => 4
+        ]);
+
+        $res->dump();
+
+    }
+}

+ 2 - 2
tests/UsedTestCase.php

@@ -15,9 +15,9 @@ abstract class UsedTestCase extends BaseTestCase
         $tokenInfo = $this->post('http://localhost/api/login', [
 //            'email' => 'catch@admin.com',
             'remember' => false,
-            'email' => 'xiaoli@qq.com',
+//            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
-//        'email' => 'aa@test.com',
+            'email' => 'aa@test.com',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }