| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\common\service;
- use app\common\model\ExpressShippingMethodModel;
- use utils\RedisCache;
- /**
- * 配送费模板列表服务 by wes
- * Class ExpressShippingMethodService
- * @package app\common\service
- */
- class ExpressShippingMethodService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new ExpressShippingMethodModel();
- }
- /**
- * 静态化入口
- * @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 getListByTemplate($templateId, $cache=true)
- {
- if($templateId<=0){
- return false;
- }
- $cacheKey = "caches:shippingList:template_{$templateId}";
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $where = ['template_id'=> $templateId];
- $data = $this->model->where($where)->select();
- $data = $data? $data->toArray():[];
- if($data && $cache){
- RedisCache::set($cacheKey, $data, rand(10,20));
- }
- return $data;
- }
- }
|