| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- // +----------------------------------------------------------------------
- // | EasyAdmin
- // +----------------------------------------------------------------------
- // | PHP交流群: 763822524
- // +----------------------------------------------------------------------
- // | 开源协议 https://mit-license.org
- // +----------------------------------------------------------------------
- // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
- // +----------------------------------------------------------------------
- namespace app\common\service;
- use app\common\model\ExpressDeliveryModel;
- use utils\RedisCache;
- /**
- * 配送费模板服务 by wes
- * Class ExpressDeliveryService
- * @package app\common\service
- */
- class ExpressDeliveryService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new ExpressDeliveryModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 获取模板数据
- * @param $templateId 模板ID
- * @param bool $cache 是否缓存
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getDataByTemplate($templateId, $cache=true)
- {
- if($templateId<=0){
- return false;
- }
- $cacheKey = "caches:express:info_{$templateId}";
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $where = ['id'=> $templateId];
- $data = $this->model->where($where)->findOrEmpty();
- $data = $data? $data->toArray():[];
- if($data && $cache){
- RedisCache::set($cacheKey, $data, rand(10,20));
- }
- return $data;
- }
- }
|