Bladeren bron

Merge branch 'liuzj-permission-dev' into test

liuzejian 1 jaar geleden
bovenliggende
commit
f3484d4363

+ 2 - 1
app/Console/Commands/Callback/JuliangAccountRateConfigRefresh.php

@@ -36,6 +36,7 @@ class JuliangAccountRateConfigRefresh extends Command
     public function start(){
         $list = DB::table('juliang_account_promotion_config_time')
             ->where('is_enable',1)->orderBy('id')->get();
+
         foreach ($list as  $item) {
             $is_exec = $this->timeThan($item->config_time);
             if (!$is_exec || $item->next_exec_time != date("Y-m-d")) {
@@ -72,7 +73,7 @@ class JuliangAccountRateConfigRefresh extends Command
                 ->update(['is_enabled' => 0, 'updated_at' => $now]);
             DB::table('juliang_account_promotion_protect_record')
                 ->where('optimizer_uid', $item->company_uid)
-                ->whereIn('advertiser_id', $item->account_id)
+                ->where('advertiser_id', $item->account_id)
                 ->where('is_enabled', 1)
                 ->update(['is_enabled' => 0, 'updated_at' => $now]);
             DB::table('juliang_account_rate_config_log')

+ 0 - 108
app/Console/Commands/ContentManage/BookCopyrightAlert.php

@@ -1,108 +0,0 @@
-<?php
-
-namespace App\Console\Commands\ContentManage;
-
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-use Modules\ContentManage\Services\Notice\NoticesService;
-
-class BookCopyrightAlert extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'ContentManage:BookCopyrightAlert';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '书籍版权快到期预警';
-    private $alertDate;
-    /**
-     * Execute the console command.
-     */
-    public function handle(): void
-    {
-        $todayStr = date('Y-m-d');
-        $alertDate = date_add(date_create($todayStr), date_interval_create_from_date_string('30 day'))->format('Y-m-d');
-        $roleIds = DB::table('roles')
-            ->whereIn('identify', ['admin', 'businessmaster', 'business'])
-            ->where('deleted_at', '=', 0)
-            ->select('id')
-            ->get()->pluck('id')->unique();
-        $users = DB::table('users')->join('user_has_roles', 'users.id', 'user_has_roles.user_id')
-            ->whereIn('user_has_roles.role_id', $roleIds)
-            ->where('users.deleted_at', '=', 0)
-            ->where('users.status', '=', 1)
-            ->select('id', 'username', 'email')
-            ->get()->keyBy('id');
-        DB::table('books')
-            ->where('end_date', '<>', '')
-            ->where('end_date', '<=', $alertDate)
-            ->orderBy('id', 'desc')
-            ->select('id','name', 'start_date', 'end_date', 'cp_name', 'cp_id')
-            ->chunk(300, function ($books) use ($users, $todayStr){
-                    foreach ($books->chunk(30) as $iBooks) {
-                        $this->copyrightAlert($iBooks, $users, $todayStr);
-                    }
-            });
-    }
-
-
-    /**
-     * 快到期书籍,邮件通知,内容管理后台消息通知
-     * @param $iBooks
-     * @param $userCollect
-     */
-    private function copyrightAlert($iBooks, $userCollect, $todayStr) {
-        $emailStr = '';
-        $noticeStr = '';
-        foreach ($iBooks as $book) {
-            $leftDay = intval(date_diff(date_create($todayStr), date_create($book->end_date))->format("%r%a"));
-            if($leftDay > 0) {
-                $emailStr .= 'bid='.$book->id. "<br>";
-                $emailStr .= '书名='.$book->name. "<br>";
-                $emailStr .= '版权开始日期='.$book->start_date. "<br>";
-                $emailStr .= '版权结束日期='.$book->end_date. "<br>";
-                $emailStr .= '版权剩余天数='. $leftDay . "天<br>";
-                $emailStr .= 'cp_name='.$book->cp_name. "<br>";
-                $emailStr .= 'cp_id='.$book->cp_id. "<br>";
-                $emailStr .= "==========================================<br>";
-            } else {
-                $noticeStr .= 'bid='.$book->id. "<br>";
-                $noticeStr .= '书名='.$book->name. "<br>";
-                $noticeStr .= '版权开始日期='.$book->start_date. "<br>";
-                $noticeStr .= '版权结束日期='.$book->end_date. "<br>";
-                $noticeStr .= 'cp_name='.$book->cp_name. "<br>";
-                $noticeStr .= 'cp_id='.$book->cp_id. "<br>";
-                $noticeStr .= "==========================================<br>";
-            }
-
-        }
-
-
-        $users = [];
-        foreach ($userCollect as $user) {
-            $users[] = ['address' => $user->email, 'name' => $user->username];
-        }
-
-
-        $params = [
-            'subject' => sprintf('版权快到期预警[%s]', date('Y-m-d H:i:s')),
-            'body' => $emailStr
-        ];
-        sendEmail($users,$params);
-
-        NoticesService::addNotice([
-            'title' => '书籍版权到期提醒',
-            'notice_type_id' => 2,
-            'type' => 1,
-            'is_popup' => 1,
-            'content' => $noticeStr
-        ]);
-    }
-}

+ 0 - 105
app/Console/Commands/ContentManage/BookImport.php

@@ -1,105 +0,0 @@
-<?php
-
-namespace App\Console\Commands\ContentManage;
-
-use Illuminate\Console\Command;
-use Modules\ContentManage\Models\BookCategories;
-use Modules\ContentManage\Models\Cp\Cps;
-use Modules\ContentManage\Services\Books\BooksService;
-use Modules\ContentManage\Services\Books\ChapterService;
-
-class BookImport extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'ContentManage:bookimport {--name=: 书名}
-                                                     {--cp_id=:cp_id}
-                                                     {--category_id=:分类id}
-                                                     {--author=:作者}
-                                                     {--vip=:vip起始章节默认:8}
-                                                     {--filename=:文件名,放在storage/app/目录下}';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '导入书籍文本';
-
-    /**
-     * Execute the console command.
-     */
-    public function handle(): void
-    {
-        $create_info = $this->createBook();
-        if($create_info['error']){
-            return ;
-        }
-        $filname = $this->option('filename');
-        if(!$filname){
-            $this->error('filename empty');
-            return ;
-        }
-        $result = $create_info['book'];
-        $chapter_result = $this->createChapter( $result->id,$filname);
-        $result->size = $chapter_result['size'];
-        $result->chapter_count = $chapter_result['chapter_count'];
-        $result->first_cid = $chapter_result['first_cid'];
-        $result->last_cid = $chapter_result['last_cid'];
-        $result->last_chapter = $chapter_result['last_chapter'];
-        $result->save();
-    }
-
-
-    private function createBook(){
-        $cp_id = $this->option('cp_id');
-        $book_name = $this->option('name');
-        $author  = $this->option('author');
-        $category_id = $this->option('category_id');
-        $cp_name = $this->getCpName($cp_id);
-        if(!$cp_name){
-            $this->error('cp_id不存在');
-            return ['error'=>1];
-        }
-
-        $category_info = $this->getCategoryInfo($category_id);
-        if(!$category_info){
-            $this->error('分类id不存在');
-            return ['error'=>2];
-        }
-
-        $result = BooksService::createBook([
-            'cp_name'=>$cp_name,'cp_id'=>$cp_id,'name'=>$book_name,'author'=>$author ?? '','intro'=>'','cover'=>'','category_id'=>$category_id,
-            'category_name'=>$category_info->category_name,'status'=>1,'channel'=>$category_info->channel_id
-        ]);
-        if(!$result){
-            $this->error('已经存在了');
-            return ['error'=>3];
-        }
-        return ['error'=>0,'book'=>$result];
-    }
-
-    private function createChapter($bid,$filname){
-        $vip_start = $this->option('vip');
-        $path = storage_path('app/'.$filname);
-        return  ChapterService::createChapterFromFile($bid,1,$vip_start ?? 8,$path);
-    }
-
-
-    private function getCpName($cp_id){
-        $cp_info = Cps::where('cp_id',$cp_id)->select('cp_nick')->first();
-        if($cp_info){
-            return $cp_info->cp_nick;
-        }
-        return '';
-    }
-
-
-    private function getCategoryInfo($category_id){
-        return BookCategories::where('id',$category_id)->first();
-    }
-
-}

+ 0 - 59
app/Console/Commands/ContentManage/NewCpBookComeIn.php

@@ -1,59 +0,0 @@
-<?php
-
-namespace App\Console\Commands\ContentManage;
-
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Redis;
-use Modules\ContentManage\Services\Notice\NoticesService;
-
-class NewCpBookComeIn extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'ContentManage:NewCpBookComeIn';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '如果发现当天有cp方新的书籍接入进来后,自动生成公告通知';
-
-    /**
-     * Execute the console command.
-     */
-    public function handle(): void
-    {
-        $datetime = date_sub(date_create(), date_interval_create_from_date_string('28 hour'))->format('Y-m-d H:i:s');
-        $books = DB::table('books')
-            ->where('created_at', '>=', $datetime)
-            ->select('id', 'cp_name', 'name')
-            ->get();
-        $redisKey = 'contentManage.cp.newBook.alreadyAlert';
-        $str = '';
-        foreach ($books as $book) {
-            if(Redis::sismember($redisKey, $book->id)) {
-                continue;
-            }
-            $str .= sprintf('%s cp方的新书:%s <br>', $book->cp_name, $book->name);
-            Redis::sadd($redisKey, $book->id);
-        }
-        if(!$str) {
-            return ;
-        }
-
-        $str .= '已经进入植宇内容中台,请尽快查看';
-
-        NoticesService::addNotice([
-            'title' => '有cp方新的书籍接入',
-            'notice_type_id' => 2,
-            'type' => 1,
-            'is_popup' => 1,
-            'content' => $str
-        ]);
-    }
-}

+ 0 - 144
app/Console/Commands/ContentManage/cpCollection.php

@@ -1,144 +0,0 @@
-<?php
-
-namespace App\Console\Commands\ContentManage;
-
-use Illuminate\Console\Command;
-use Modules\ContentManage\Models\Cp\CpCollection as CpCollectionModel;
-use Modules\ContentManage\Models\Book;
-use Illuminate\Support\Facades\Process;
-use Modules\ContentManage\Services\Notice\NoticesService;
-use Modules\Permissions\Models\Roles;
-use Log;
-
-
-class cpCollection extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'ContentManage:cpcollection';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    private $cp_name = '';
-    private $spider_name = '';
-    private $cp_id = 0;
-    private $commad_status = -1;
-    private $start_time;
-
-    private $record = null;
-
-
-
-    public function __construct(protected readonly CpCollectionModel $CpCollectionModel,protected readonly Book $book)
-    {
-        parent::__construct();
-    }
-
-    /**
-     * Execute the console command.
-     */
-    public function handle(): void
-    {
-        $this->getTask();
-        if(!$this->cp_id){
-            return ;
-        }
-        $this->start_time = date('Y-m-d H:i:s');
-        $this->runSpider();
-        if($this->commad_status){
-            $this->record->spider_status = 3;
-        }else{
-            $this->record->spider_status = 2;
-        }
-        $spider_result = $this->getResult();
-        $this->record->spider_result = $spider_result->pluck('id')->implode(',');
-        $this->record->save();
-        $this->notice($spider_result);
-    }
-
-    /**
-     * 获取同步任务,一次只获取一个
-     * @return void
-     */
-    private function getTask(){
-        $record = $this->CpCollectionModel->where('created_at','>',date('Y-m-d H:i:s',time()-86400))->where('spider_status',0)->first();
-        if($record){
-            $record->spider_status = 1;
-            $record->save();
-            $this->cp_name = $record->cp_name; 
-            $this->cp_id = $record->cp_id;
-            $this->spider_name = str_replace('zy_','',$this->cp_name);
-            $this->record = $record;
-        }
-    }
-
-
-    /**
-     * 执行脚本,并获取状态
-     * @return void
-     */
-    private function runSpider(){
-        $command = ' bash /project/www/zhiyu_content_spider/content_spider/bash/command.sh '.$this->spider_name;
-        Log::info('cpCollection',['command'=>$command]);
-        $result = Process::forever()->run($command);
-        if($result->successful()){
-            $this->commad_status = 0;
-        }else{
-            $this->commad_status = 1;
-        }
-    }
-
-    /**
-     * 获取同步结果
-     */
-    private function getResult(){
-       return  $this->book->where('cp_id',$this->cp_id)
-        ->where('created_at','>=',$this->start_time)
-        ->where('created_at','<=',date('Y-m-d H:i:s'))
-        ->select('id','name')->get();
-    }
-
-
-    /**
-     * 通知同步结果
-     * @param [type] $collection_result
-     * @return void
-     */
-    private function notice($collection_result){
-        $role = Roles::where('identify','contentadmin')->select('id','role_name')->first();
-        $notice_obj = [];
-        if($role){
-            $notice_obj[] = ['id'=>$role->id,'name'=>$role->role_name];
-        }
-
-        $admin_role = Roles::where('identify','admin')->select('id','role_name')->first();
-        if($admin_role){
-            $notice_obj[] = ['id'=>$admin_role->id,'name'=>$admin_role->role_name];
-        }
-        if(!$notice_obj){
-            $notice_obj = [['id'=>6,'name'=>'内容管理员']];
-        }
-
-        $end_time = date('Y-m-d H:i:s');
-        $count = $collection_result->count();
-        $books = $collection_result->pluck('name')->implode(',');
-        $content =  $this->start_time.' 同步'.$this->cp_name."任务执行完成\r\n此次执行任务在 {$end_time}执行完成,增量同步{$count}本书如下:\r\n".$books;
-
-        NoticesService::addNotice([
-            'title' => $this->cp_name.'书籍同步完成',
-            'notice_type_id' => 2,
-            'type' => 3,
-            'notice_obj'=>$notice_obj,
-            'is_popup' => 1,
-            'content' => $content
-        ]);
-    }
-}

+ 6 - 5
tests/Callback/Http/Controllers/JuliangAccountControllerTest.php

@@ -35,15 +35,16 @@ class JuliangAccountControllerTest extends UsedTestCase
             'Authorization' => 'Bearer '. $this->token,
         ])->json('post','http://localhost/api/callback/juliangAccount/updateCallbackConfig', [
             'ids' => [4],
-            'state' => 0,
-            'protect_num' => 2,
+            'state' => 1,
+            'protect_num' => 3,
             'default_rate' => 30,
             'rate_time_config' => [
                 ['start_time' => '15:00', 'end_time' => '16:10', 'config_per' => 20],
-                ['start_time' => '16:20', 'end_time' => '19:30', 'config_per' => 50],
+                ['start_time' => '16:20', 'end_time' => '17:30', 'config_per' => 50],
+                ['start_time' => '17:55', 'end_time' => '18:30', 'config_per' => 20],
             ],
-            'min_money' => 40,
-            'max_money' => 60,
+            'min_money' => 30,
+            'max_money' => 80,
         ]);
         $res->dump();
     }