mineadmin mapper用法

[该文章已加密,请点击标题输入密码访问]


xiang 发布于  2024-7-26 16:36 

laravel hyeprf whereHas 分析

[该文章已加密,请点击标题输入密码访问]


xiang 发布于  2024-7-25 22:04 

mineadmin mapper使用

SystemMenuMapper

  /**
     * 获取子孙menus.
     */
    public function getDescendantsMenus(int $id): array
    {
        $params = ['level' => $id];
        return $this->handleSearch($this->model::query(), $params)->get()->toArray();
    }

    /**
     * 搜索处理器.
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', $params['status']);
        }

        if (isset($params['level']) && filled($params['level'])) {
            $query->where('level', 'like', '%' . $params['level'] . '%');
        }

        if (isset($params['name']) && filled($params['name'])) {
            $query->where('name', 'like', '%' . $params['name'] . '%');
        }

        if (isset($params['created_at']) && filled($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
            $query->whereBetween(
                'created_at',
                [$params['created_at'][0] . ' 00:00:00', $params['created_at'][1] . ' 23:59:59']
            );
        }

        if (isset($params['noButton']) && filled($params['noButton']) && $params['noButton'] === true) {
            $query->where('type', '<>', SystemMenu::BUTTON);
        }
        return $query;
    }

xiang 发布于  2024-7-25 20:46 

git filemode false

安全目录

git config --global --add safe.directory /var/www/html

忽略文件属性

git config --global core.filemode false

xiang 发布于  2024-7-24 16:54 

yt-dlp 下载youtube视频

yt-dlp 下载youtube视频


xiang 发布于  2024-7-20 10:27 

ffmepg命令

ffmpeg -i 2KNg9BKbVJE.mp4 -vf "pad=iw:2*trunc(iw*16/18):(ow-iw)/2:(oh-ih)/2,setsar=1" output.mp4

9比16比例

ffmpeg -i output2.mp4 -vf "subtitles=2KNg9BKbVJE.vtt:force_style='FontSize=20,Alignment=2,FontName=Arial,MarginV=50'" -c:a copy output3.mp4

xiang 发布于  2024-7-18 22:18 

swoole hyperf 指定最多创建100个协程。

应用场景

异步队列消费,大量创建协程序会导致mysql连接数用完,mysql压力大增,所以控制协程数跟mysql连接池数量相约。可以有效控制mysql的写入压力。

 public function handle()
    {
        $num=100;
        Co::set(['max_coroutine'=>$num]);
        for ($i=0;$i<1000;$i++) {
           $status=Co::stats();
           if($status['coroutine_num']<$num){
               go(function () {
                   Coroutine::sleep(1);
                   print_r($coroutineId = Coroutine::getuid()."\n");
               });
           }else{
                $this->main();
           }
        }
    }

    public function main()
    {
        print_r("no coroutine"."\n");
    }

  Co::set(['max_coroutine'=>$num]); 

设置最大协程数


 $status=Co::stats(); 
    $status['coroutine_num']

获取协程状态。
coroutine_num 当前运行的协程数量


xiang 发布于  2024-7-13 12:16 

php swoole.当前代码是否在协程内。怎么判断

use Swoole\Coroutine;

try {
    // 尝试获取协程ID
    $coroutineId = Coroutine::getuid();
    if ($coroutineId != -1) {
        echo "当前代码正在协程内执行,协程ID为:" . $coroutineId . "\n";
    } else {
        echo "当前代码不在协程内执行。\n";
    }
} catch (\Throwable $e) {
    // 如果在非协程环境中调用getuid(),会抛出异常
    echo "当前代码不在协程内执行,因为抛出了异常:" . $e->getMessage() . "\n";
}

xiang 发布于  2024-7-13 12:14 

unixtime时间戳,不同时区

date_default_timezone_set("America/New_York");
        $vl=time();
        print_r($vl."\n");
        date_default_timezone_set("Asia/Shanghai");
        $v2=time();
        print_r($v2."\n");

结果

1720780223
1720780223

是一样的


xiang 发布于  2024-7-12 18:29