liyaozhi
2025-10-28 1320688354fd168c51cf2e05f29a2253f4ed9c00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
 
namespace app\common\model\app;
 
use app\common\exception\BaseException;
use think\facade\Cache;
use app\common\model\BaseModel;
 
/**
 * 微信小程序模型
 */
class AppWx extends BaseModel
{
    protected $name = 'app_wx';
    protected $pk = 'app_id';
 
    /**
     * 获取小程序信息
     */
    public static function detail($app_id = null)
    {
        $self = new static();
        empty($app_id) && $app_id = $self::$app_id;
        return (new static())->find($app_id);
    }
 
    /**
     * 从缓存中获取小程序信息
     * @param null $app_id
     */
    public static function getAppWxCache($app_id = null)
    {
        if (is_null($app_id)) {
            $self = new static();
            $app_id = $self::$app_id;
        }
        if (!$data = Cache::get('app_wx_' . $app_id)) {
            $data = self::detail($app_id);
            if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
            Cache::set('app_wx_' . $app_id, $data);
        }
        return $data;
    }
 
}