zhaoyang преди 2 години
родител
ревизия
25ddff0110

+ 40 - 0
modules/Manage/Enmus/MiniprogramType.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Modules\Manage\Enmus;
+
+use Catch\Enums\Enum;
+
+
+enum MiniprogramType: int implements Enum
+{
+    case WEIXIN = 1; // 全部数据
+    case BYTECODE = 2; // 自定义数据
+
+
+    public function value(): int
+    {
+        return match ($this) {
+            self::WEIXIN => 1,
+            self::BYTECODE => 2
+        };
+    }
+
+    public function name(): string
+    {
+        return match ($this) {
+            self::WEIXIN => '微信小程序',
+            self::BYTECODE => '字节小程序',
+        };
+    }
+
+    /**
+     * assert value
+     *
+     * @param int $value
+     * @return bool
+     */
+    public function assert(int $value): bool
+    {
+       return $this->value === $value;
+    }
+}

+ 63 - 0
modules/Manage/Http/Controllers/MiniprogramController.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace Modules\Manage\Http\Controllers;
+
+use Illuminate\Routing\Controller;
+use Illuminate\Http\Request;
+use Modules\Manage\Enmus\MiniprogramType;
+use Modules\Manage\Http\Requests\MiniprogramRequest;
+use Modules\Manage\Models\Miniprogram;
+use Log;
+
+class MiniprogramController extends Controller
+{
+
+    public function __construct(protected readonly Miniprogram $miniprogram)
+    {
+        
+    }
+
+    public function index(Request $request)
+    {
+        return $this->miniprogram->paginate(20)->map(function($item,$k){
+            $item->type_name = MiniprogramType::from($item->type)->name();
+            return $item;
+        });
+    }
+
+    public function store(MiniprogramRequest $request)
+    {
+        $validate_result = $request->validated();
+        $validate_result['remark'] = $request->post('remark','') ?? '';
+        return $this->miniprogram->create($validate_result)->toArray();
+
+    }
+
+    public function show($id)
+    {
+        return $this->miniprogram->find($id)->toArray();
+    }
+
+
+    public function update($id, MiniprogramRequest $request)
+    {
+        $validate_result = $request->validated();
+        if($request->post('remark','')){
+            $validate_result['remark'] = $request->post('remark','');
+        }
+        $this->miniprogram->where('id',$id)->update($validate_result);
+        return [];
+    }
+
+    public function destroy($id)
+    {
+
+    }
+
+
+    public function typeList(){
+        $type_list =  MiniprogramType::cases();
+        $data = array_map( fn($item)=>['name'=>$item->name(),'value'=>$item->value()],$type_list );
+        return $data;
+    }
+}

+ 41 - 0
modules/Manage/Http/Requests/MiniprogramRequest.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Modules\Manage\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+use Modules\Manage\Enmus\MiniprogramType;
+use Illuminate\Validation\Rule;
+
+class MiniprogramRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     */
+    public function authorize(): bool
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
+     */
+    public function rules(): array
+    {
+        return [
+            'name'=> 'required|max:50',
+            'play_name'=> 'required|max:100',
+            'company'=> 'required|max:255',
+            'type'=> [
+                'required',
+                Rule::in( array_map( fn($item)=>$item->value(),MiniprogramType::cases())),
+            ],
+            'appsecret'=>'required|min:30',
+            'appid'=>'required|unique:miniprogram|min:18',
+            'status'=>'in:0,1'
+        ];
+    }
+}
+
+

+ 30 - 0
modules/Manage/Models/BaseModel.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Modules\Manage\Models;
+
+use Catch\Base\CatchModel as Model;
+use Illuminate\Database\Eloquent\Builder;
+
+
+abstract class BaseModel extends Model
+{
+
+    protected array $defaultHidden = [];
+
+    protected array $defaultCasts = [
+        'created_at' => 'datetime:Y-m-d H:i:s',
+
+        'updated_at' => 'datetime:Y-m-d H:i:s',
+    ];
+    protected $dateFormat = '';
+
+    public static function bootSoftDeletes(): void{
+
+    }
+
+
+    public function scopeActive(Builder $query): void
+    {
+        $query->where($this->table.'.is_enabled', 1);
+    }
+}

+ 20 - 0
modules/Manage/Models/Miniprogram.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Modules\Manage\Models;
+
+
+class Miniprogram extends BaseModel
+{
+
+    protected string $sortField = 'id';
+
+    // 排序规则
+    protected bool $sortDesc = true;
+
+    protected $table = 'miniprogram';
+
+    protected $fillable = [
+        'id', 'name', 'company', 'type', 'appid', 'appsecret', 'status', 'remark', 'play_name','created_at', 'updated_at'
+    ];
+
+}

+ 20 - 0
modules/Manage/Providers/ManageServiceProvider.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Modules\Manage\Providers;
+
+use Catch\CatchAdmin;
+use Catch\Providers\CatchModuleServiceProvider;
+
+class ManageServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * route path
+     *
+     * @return string
+     */
+    public function moduleName(): string
+    {
+        // TODO: Implement path() method.
+        return 'manage';
+    }
+}

+ 12 - 0
modules/Manage/config/miniprogram.php

@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * 小程序配置
+ */
+return [
+    
+    'typelist'=>[
+        'WEIXIN','BYTECODE'
+    ],
+    
+];

+ 30 - 0
modules/Manage/routes/route.php

@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+use Modules\Manage\Http\Controllers\MiniprogramController;
+
+Route::prefix('manage')->group(function(){
+    Route::prefix('miniprogram')->group(function () {
+        //类型列表
+        Route::get('typelist',[MiniprogramController::class,'typeList'])
+        ->withoutMiddleware(config('catch.route.middlewares'));
+
+        //添加
+        Route::post('store',[MiniprogramController::class,'store'])
+        ->withoutMiddleware(config('catch.route.middlewares'));
+
+        //小程序列表
+        Route::get('index',[MiniprogramController::class,'index'])
+        ->withoutMiddleware(config('catch.route.middlewares'));
+
+        //小程序详情
+        Route::get('show/{id}',[MiniprogramController::class,'show'])
+        ->withoutMiddleware(config('catch.route.middlewares'));
+
+         //小程序详情
+         Route::post('update/{id}',[MiniprogramController::class,'update'])
+         ->withoutMiddleware(config('catch.route.middlewares'));
+
+    });
+});

+ 0 - 9
phpunit.xml

@@ -11,15 +11,6 @@
         <testsuite name="Feature">
             <directory suffix="Test.php">./tests/Feature</directory>
         </testsuite>
-
-        <testsuite name="ContentOutput">
-            <directory suffix="Test.php">./tests/ContentManage/Output</directory>
-        </testsuite>
-
-        <testsuite name="ContentOutputBook">
-            <directory suffix="Test.php">./tests/ContentManage/Http/Controllers</directory>
-        </testsuite>
-
     </testsuites>
     <coverage processUncoveredFiles="true">
         <include>

+ 0 - 27
tests/Common/Http/Controllers/OptionControllerTest.php

@@ -1,27 +0,0 @@
-<?php
-
-namespace Tests\Common\Http\Controllers;
-
-use Modules\Common\Http\Controllers\OptionController;
-use Modules\Common\Support\Trace\TraceContext;
-use PHPUnit\Framework\TestCase;
-
-class OptionControllerTest extends \Tests\TestCase
-{
-
-    public function testIndex()
-    {
-        $res = $this->get('http://localhost/api/options/xiaoming');
-//        $res->dump();
-        dump(app(TraceContext::class)->getTraceInfo());
-        dump(app(TraceContext::class)->getTraceInfo());
-        dump($info1 = app(TraceContext::class)->getTraceInfo());
-        $channel = \Log::build([
-            'driver' => 'daily',
-            'path' => storage_path('logs/aa.log'),
-            'level' => 'debug'
-        ]);
-        \Log::stack([$channel])->info('hellow', ['traceInfo' => $info1]);
-        \Log::stack([$channel])->debug('hellow', ['traceInfo' => $info1]);
-    }
-}

+ 0 - 17
tests/Common/Support/Trace/CustomizeLoggerTest.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Tests\Common\Support\Trace;
-
-use Modules\Common\Support\Trace\CustomizeLogger;
-use PHPUnit\Framework\TestCase;
-
-class CustomizeLoggerTest extends \Tests\TestCase
-{
-
-    public function testGetSubscribeLogger()
-    {
-        $logger = CustomizeLogger::getSubscribeLogger();
-        $logger->debug('dddd', ['kk' => 1]);
-        $logger->info('dddd', ['kk' => 1]);
-    }
-}

+ 0 - 97
tests/ContentManage/Http/Controllers/BookControllerTest.php

@@ -1,97 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Http\Controllers;
-
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Illuminate\Support\Facades\Storage;
-use Illuminate\Http\UploadedFile;
-use Tests\TestCase;
-
-class BookControllerTest extends TestCase
-{
-    /**
-     * A basic feature test example.
-     */
-    public function test_book_import(): void
-    {
-    $content = <<<EOT
-###第一章 前女友居然会逆袭
-大学毕业之后在武汉呆了半年,楚飞终于还是决定去深圳。
-之所以会做出这个决定,倒不是因为什么其它什么乱七八糟的理由,简单四个字,人穷志短!
-同样是刚刚毕业半年,楚飞现在每个月拿着不到两千块的工资勉强活着,但他的女朋友李冉却每个月可以拿四千的固定工资,而且刚刚发放的年底奖金,她竟然拿了十五万!这样折合起来她一个月接近一万七八千的薪水了,是楚飞的十倍!
-这就是差距
-###第二章 发光的残破青铜壶
-所以兜兜转转一圈之后,终于还是回到了原点么?
-
-现在承受着楚飞凶猛冲刺的不是他以为这辈子最爱的女人李冉,而是前女友张倩,一个对性爱无比热情无比投入的女人,偏偏也只有她这样的女人才能让楚飞玩的尽兴,玩的爽快,这还真是一件很搞笑的事情。因为在张倩身上楚飞可以不用压抑自己,更不用委屈自己,他想用什么姿势玩都行,想用多大的力道都行,甚至……想射在她身体上的任何位置都没问题!
-
-而在李冉身上,这一切永远只是奢望。
-
-###第三章 吃不饱的恐怖怪物
-楚飞先回宿舍去洗了个澡,然后收拾了一下自己的东西,准备踏踏实实的定下心干活。
-###第四章 妹是用来调教的
-楚飞真的愕住了,是真的。
-他从没有想过,那个自小时候就喜欢粘着他不停问问题的丫头,每次被他逗几句就会脸红心跳的诗诗丫头,来了深圳四年之后,却已经变成了这样……时间果然是一把残忍的杀猪刀,而现实也最是无情的恶魔,多少的美好都已经随风彻底的逝去。
-轻轻的走上去,楚飞在何诗诗的屁股上轻轻拍了拍,然后帮她拉起了内裤,“诗诗,我不是要跟你……”
-###第五章 男人应该胸有成竹
-发泄过后的男人总会有一阵空虚感,不过看着表妹把自己爆发出的东西一点不剩的全都吞了下去,楚飞突然却又觉得很有一种成就感。
-她……是我表妹呀!!
-EOT;
-        $file = UploadedFile::fake()->createWithContent("美女养成师.txt",$content);
-        $response = $this->postJson("api/contentManage/book/import",[
-            'cp_id'=>1,
-            'cp_name'=>'Testcp01111',
-            'book_name'=>'美女养成师师',
-            'author'=>'小林',
-            'channel'=>1,
-            'category_id'=>21,
-            'category_name'=>'武侠仙侠',
-            'vip_start'=>4,
-            'file'=>$file
-        ]);
-        print_r(json_decode($response->getContent(),1));   
-        $response->assertStatus(200);
-    }
-
-
-    public function test_create_book(): void
-    {
-        $path = 'book/NqpYgFL6yddDPSOnAwhIihk0DRjO7hEbOY3geJ6s.txt';
-        $response = $this->postJson("api/contentManage/book/createBook",[
-            'cp_id'=>1,
-            'cp_name'=>'Testcp01111',
-            'book_name'=>'美女养成的师师',
-            'author'=>'小林',
-            'channel'=>1,
-            'category_id'=>21,
-            'category_name'=>'武侠仙侠',
-            'vip_start'=>4,
-            'path'=>$path
-        ]);
-        print_r(json_decode($response->getContent(),1));   
-        $response->assertStatus(200);
-    }
-
-    
-    private $token;
-    protected function setUp(): void
-    {
-        parent::setUp(); // TODO: Change the autogenerated stub
-        $tokenInfo = $this->post('http://localhost/api/login', [
-            'email' => 'catch@admin.com',
-            'password' => 'catchadmin',
-            'remember' => false
-        ])->json();
-        $this->token = $tokenInfo['data']['token'];
-    }
-
-
-    public function testList()
-    {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('get', 'http://localhost/api/contentManage/book/list?is_export=1');
-        $res->dump();
-    }
-}

+ 0 - 22
tests/ContentManage/Http/Controllers/CpListControllerTest.php

@@ -1,22 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Http\Controllers;
-
-use Illuminate\Foundation\Testing\RefreshDatabase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Illuminate\Support\Facades\Storage;
-use Illuminate\Http\UploadedFile;
-use Tests\TestCase;
-
-// php artisan test --testsuite=ContentOutputBook
-
-class CpListControllerTest extends TestCase{
-
-    public function test_cpP_collection(){
-
-        $response = $this->getJson("api/contentManage/cp/cpCollection?cp_id=1&cp_name=Testcp01111");
-        print_r(json_decode($response->getContent(),1));   
-        $response->assertStatus(200);
-
-    }
-}

+ 0 - 62
tests/ContentManage/Http/Controllers/CpSubscribeStatisticDataControllerTest.php

@@ -1,62 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Http\Controllers;
-
-use Modules\ContentManage\Http\Controllers\CpSubscribeStatisticDataController;
-use PHPUnit\Framework\TestCase;
-
-class CpSubscribeStatisticDataControllerTest extends \Tests\UsedTestCase
-{
-    public function testList()
-    {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/contentManage/cp/subscribeStatisticData/list?'.http_build_query([
-                'limit' => 15, 'page' => 1, 'book_name' => '小溪村的诱惑',
-                'cp_name' => 'quyuewang'
-            ]));
-        dump(\json_encode($res->json()));
-        $res->dump();
-    }
-
-    public function testlistStatistic()
-    {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/contentManage/cp/subscribeStatisticData/listStatistic?');
-        dump(\json_encode($res->json()));
-        $res->dump();
-    }
-
-    public function testMonthList()
-    {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/contentManage/cp/subscribeStatisticData/monthList?'.http_build_query([
-                'limit' => 15, 'page' => 1 , 'month' => '2022-07', 'cp_name' => 'Testcp01111'
-            ]));
-        dump(\json_encode($res->json()));
-        $res->dump();
-    }
-
-    public function testSaveFinalState() {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('post','http://localhost/api/contentManage/cp/subscribeStatisticData/saveFinalState', [
-            'id' => 1, 'final_state' => 'done'
-        ]);
-        dump(\json_encode($res->json()));
-        $res->dump();
-    }
-
-    public function testlistCpBooksMonthFinalAmount() {
-        $res = $this->withHeaders([
-            'Authorization' => 'Bearer '. $this->token,
-        ])->json('get','http://localhost/api/contentManage/cp/subscribeStatisticData/listCpMonthFinalAmount?'.http_build_query([
-                'cp_name' => '1221', 'month' => '2023-03'
-            ]));
-
-        $this->dumpJson($res);
-    }
-
-}

+ 0 - 57
tests/ContentManage/Output/OutputTest.php

@@ -1,57 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Output;
-
-// use Illuminate\Foundation\Testing\RefreshDatabase;
-use Tests\TestCase;
-
-/**
- * 输出测试
- */
-class OutputTest extends TestCase
-{
-    private string $query = 'channel_name=zhuishuyun&channel_key=123456';
-    private string $prefix = '/api/output/';
-    /**
-     * 
-     *书籍列表
-     * @return void
-     */
-    public function test_book_list()
-    {
-        $response = $this->getJson($this->prefix.'booklist?'.$this->query);
-        print_r(json_decode($response->getContent(),1));    
-        $response->assertStatus(200);
-    }
-
-    public function test_book_detail()
-    {
-        $response = $this->getJson($this->prefix.'bookdetail/1?'.$this->query);
-        print_r(json_decode($response->getContent(),1));   
-        $response->assertStatus(200);
-    }
-
-    public function test_chapter_list()
-    {
-        $response = $this->getJson($this->prefix.'chapterlist/1?'.$this->query);
-        //print_r(json_decode($response->getContent(),1));   
-        $response->assertStatus(200);
-    }
-
-
-
-    public function test_chapter_content()
-    {
-        $response = $this->getJson($this->prefix.'chaptercontent/1/chapterid/1?'.$this->query);
-        print_r(json_decode($response->getContent(),1));
-        $response->assertStatus(200)->assertJsonPath('code', 10000);
-    }
-
-
-    public function test_categories()
-    {
-        $response = $this->getJson($this->prefix.'listCategories?'.$this->query);
-        print_r(json_decode($response->getContent(),1));
-        $response->assertStatus(200)->assertJsonPath('code', 10000);
-    }
-}

+ 0 - 18
tests/ContentManage/Services/CP/SyncSubscribeTest.php

@@ -1,18 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Services\CP;
-
-use Modules\ContentManage\Services\CpManage\SyncSubscribe;
-use PHPUnit\Framework\TestCase;
-
-class SyncSubscribeTest extends \Tests\TestCase
-{
-    public function testsync() {
-        $syncSubscribe = new SyncSubscribe();
-        $syncSubscribe->syncUrl = 'http://pubapi.pre.aizhuishu.com/outapi/zhiyu/getSubsByZhiyu';
-        $syncSubscribe->syncStartDate = '2022-07-25';
-        $syncSubscribe->syncEndDate = '2022-07-26';
-
-        $syncSubscribe->sync();
-    }
-}

+ 0 - 52
tests/ContentManage/Services/CpManage/BookSettlementTest.php

@@ -1,52 +0,0 @@
-<?php
-
-namespace Tests\ContentManage\Services\CpManage;
-
-use Illuminate\Support\Facades\DB;
-use Modules\Common\Support\Trace\TraceContext;
-use Modules\ContentManage\Services\CpManage\BookSettlement;
-use PHPUnit\Framework\TestCase;
-
-class BookSettlementTest extends \Tests\TestCase
-{
-    private $bid = 10002;
-    protected function setUp11(): void
-    {
-        parent::setUp(); // TODO: Change the autogenerated stub
-
-        $startDate = '2023-01-23';
-        $endDate = '2023-05-13';
-
-        $date = $startDate;
-        DB::table('cp_subscribe_statistic_data')
-            ->where(['bid' => $this->bid])
-            ->delete();
-        while ($date <= $endDate) {
-            $nextDate = date_add(date_create($date), date_interval_create_from_date_string('1 day'))->format('Y-m-d');
-            DB::table('cp_subscribe_statistic_data')
-                ->insert([
-                    'bid' => $this->bid,
-                    'calculate_date' => $nextDate,
-                    'settlement_date' => $date,
-                    'month' => date_create($date)->format('Y-m'),
-                    'cp_name' => 'kanshu',
-                    'yesterday_available_amount' => rand(1000 , 5000),
-                    'yesterday_final_amount' => rand(100, 500),
-                    'yesterday_total_coins' => rand(10000, 50000),
-                    'book_settlement_type' => array_rand(['share', 'bottomline', 'buyout'])
-                ]);
-            $date = $nextDate;
-        }
-
-    }
-
-    public function testRun()
-    {
-        $bid = 10002;
-        $month = '2023-03';
-        dump($pInfo = app(TraceContext::class)->getTraceInfo());
-        $service = new BookSettlement($bid, $month);
-        $service->traceContext = TraceContext::newFromParent($pInfo);
-        dump($service->detail());
-    }
-}

+ 45 - 0
tests/Feature/MiniprogramTest.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace Tests\Feature;
+
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class MiniprogramTest extends TestCase
+{
+    /**
+     * A basic feature test example.
+     */
+    public function ttest_example(): void
+    {
+        $response = $this->getJson('/api/manage/miniprogram/typelist');
+
+        $response->dd();
+    }
+
+
+    public function test_store(): void
+    {
+        $response = $this->postJson('/api/manage/miniprogram/update/13',[
+            'name'=>'三个十千短剧',
+            'company'=>'三个三集团',
+            'play_name'=>'三个十千短剧',
+            'type'=>1,
+            'appid'=>'wxts5415641fgtjhuswsae13',
+            'appsecret'=>'2f659djhsjsfa256b5523ta1shqa3d313',
+            'status'=>1,
+            'remark'=>''
+        ]);
+
+        $response->dd();
+    }
+
+
+    public function ttest_index(): void
+    {
+        $response = $this->getJson('/api/manage/miniprogram/index');
+
+        $response->dd();
+    }
+}

+ 0 - 18
tests/Unit/ExampleTest.php

@@ -16,22 +16,4 @@ class ExampleTest extends TestCase
     {
         $this->assertTrue(true);
     }
-
-    public function testmyLog() {
-        myLog('test1111')->info('kkkkk');
-    }
-
-    public function testDate() {
-        $str = 'php artisan ContentManage:SyncCpSubscribeStatisticDataFromZW --startDate=%s --endDate=%s';
-
-        $startDate = '2023-04-01';
-        $newStr = '';
-        foreach (range(1, 32) as $i) {
-            $endDate = date_add(date_create($startDate), date_interval_create_from_date_string('1 day'))->format('Y-m-d');
-//            dump(sprintf($str, $startDate, $endDate));
-            $newStr .= sprintf($str, $startDate, $endDate) . "\r\n";
-            $startDate = $endDate;
-        }
-        dump($newStr);
-    }
 }