<?php
namespace app\common\model;
use app\common\exception\BaseException;
use think\Cache;
use think\Db;
class Wxapp extends BaseModel
{
protected $name = 'wxapp';
public function navbar()
{
return $this->hasOne('WxappNavbar');
}
public function diyPage()
{
return $this->hasOne('WxappPage');
}
public static function detail($wxapp_id = null)
{
return self::get($wxapp_id ?: []);
}
public static function getWxappCache($wxapp_id = null)
{
if (is_null($wxapp_id)) {
$self = new static();
$wxapp_id = $self::$wxapp_id;
}
if (!$data = Cache::get('wxapp_' . $wxapp_id)) {
$data = self::detail($wxapp_id);
if (empty($data)) throw new BaseException(['msg' => '未找到当前小程序信息']);
Cache::tag('cache')->set('wxapp_' . $wxapp_id, $data);
}
return $data;
}
}