Region.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: thinkphp <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\model;
  13. use app\common\model\Region as RegionModel;
  14. use think\facade\Cache;
  15. /**
  16. * 地区模型
  17. * Class Region
  18. * @package app\api\model
  19. */
  20. class Region extends RegionModel
  21. {
  22. protected $globalScope = [''];
  23. /**
  24. * @param int $pid
  25. * @return Region[]|array|mixed|\think\Collection|null
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public static function getCacheOptions(int $pid = 2069)
  31. {
  32. $datas = Cache::get("caches:region:options_{$pid}");
  33. if($datas){
  34. return $datas;
  35. }
  36. $datas = self::where(['pid'=> $pid])
  37. ->field('id,name,code')
  38. ->select();
  39. if($datas){
  40. Cache::set("caches:region:options_{$pid}", $datas, rand(120, 300));
  41. }
  42. return $datas;
  43. }
  44. }