thinkphp thinkcmf 惰加载 with hasOne hasMany

$info=$xModel->select()
$info=$xModel->with(“bxx”)->select()
区别在于在$info在返回后是否使用bxx,如果不使用的化 不用with的将不会关联 即惰加载,减少数据库的IO

TAG:关联可以采用非主键关联


hasOne 关联单数组

默认hasOne关联的是第一条数据,即最老的数据

hasMany关联数组-数组

A: return $this->hasOne(HistroyModel::class,”code”,’code’)->order(‘create_time’,’desc’);
B: return $this->hasMany(HistroyModel::class,”code”,’code’)->order(‘create_time’,’desc’)->limit(1);

上面两个都可以返回关联的最新一条但是结构不同

A[xxxx]

B[[xxxx]]

发表在 None | 留下评论

php curl

1.先初始化 curl_init() 变量

2.设置变量的 URL header 超时 DNS curl_setopt()

3.执行 curl_exec()

4.检查执行结果

5.关闭curl curl_close()

    $ch = curl_init();
    
    // 设置 CURL 核心参数
    curl_setopt($ch, CURLOPT_URL, $url);
    // 将结果返回而不是直接输出
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // 模拟浏览器 User-Agent(和原代码一致)
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36');
    
    // ========== 针对你纽约VPS的关键优化 ==========
    // 连接超时(重点!比原代码的10秒短,避免卡死)
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    // 总请求超时(建议3秒内,比原10秒更合理)
    curl_setopt($ch, CURLOPT_TIMEOUT, 3);
    // 启用DNS缓存,避免重复解析域名拖慢速度
    curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
    // 关闭TCP延迟,提升传输速度
    curl_setopt($ch, CURLOPT_TCP_NODELAY, true);
    // 禁用SSL验证(因为你用的是http,这行只是兜底,防止后续改https出问题)
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec($ch);
    if ($response === false) {
            $errorMsg = curl_error($ch);
            $errorCode = curl_errno($ch);
            throw new Exception("CURL请求失败 [{$errorCode}]:{$errorMsg}");
        }
            // 保留原有的编码转换逻辑(GBK转UTF-8)
        $utf8Str = mb_convert_encoding($response, 'UTF-8', 'GBK');
        
        // 关闭CURL资源
        curl_close($ch);

发表在 None | 留下评论

python代码块 获取腾讯的股票信息

import requests
import json



def get_url(code="sz002142"):
    url="https://qt.gtimg.cn/q="
    return requests.get(url+code)

q=get_url()

#不分割

def parse_data(code_str):
    rex={}
    code_str = code_str.replace("~~~", "~").replace("~~", "~")
    vsx=code_str.split("~")
    if len(vsx)>10:
        rex['name']=vsx[1]
        rex['code']=vsx[2]
        rex['now']=vsx[3]
        rex['yestday']=vsx[4]
        rex['today_start']=vsx[5]
        rex['done_num']=vsx[6]
        rex['done_money']=vsx[36]
        rex['done_pre']=vsx[37]
        rex['today_max']=vsx[32]
        rex['today_min']=vsx[33]
        rex['time']=vsx[29]
        rex['preg']=vsx[37]
        rex['syl']=vsx[38]
        rex['money']=vsx[68]
        rex['year_max']=vsx[45]
        rex['year_min']=vsx[46]
    return rex

def c_code(num):
    #传入必须为之str 因为 sz为0开头
    str_num=str(num)
    if len(str_num)!=6:
        return False
    if str_num[0:1] in ['0','2','3']:
        return "sz"+str_num
    elif str_num[0:1] in ['6','9']:
        return "sh"+str_num
    elif str_num[0:1] in ['4','8']:
        return "bj"+str_num
    else:
        return False

def c_search_str(num_list):
    str_code=''
    for i in num_list:
        code=c_code(i)
        if code:
            str_code=code+","+str_code
    return str_code
发表在 None | 留下评论

Kindle里面浏览器刷新

使用meta标签可以实现定时刷新无需AJAX和JS

<meta http-equiv=”refresh” content=”3″>

content=3 为3秒刷新一次

发表在 None | 留下评论

E-Paper平台

平台端

当且仅当只有一个对服务端的拉取功能,提供一个key 来实现,获取信息。

服务端

每个用户独立账号 可以添加10个股票信息

每个账户根据设备绑定key来实现轮询

平台内所有的账号将股票信息汇总,使用腾讯的API 获取 差不多2秒查询一个 ,如果有100个账户那么就要查询最多1000个股票 需要2000次 显然不可能 ,但是如果只有10人那么就只有200秒 可以实现3分钟一次轮询查询,查询好的数据更新到数据库,更具不同的key来拉取对应的信息

查询数据:

股票名称代码开盘价当前价成交量换手率最低最高市值市盈率

发表在 None | 留下评论