Access.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\store;
  10. use app\common\model\BaseModel;
  11. /**
  12. * 商家用户权限模型
  13. * Class Access
  14. * @package app\common\model\admin
  15. */
  16. class Access extends BaseModel
  17. {
  18. protected $name = 'store_access';
  19. /**
  20. * 获取所有权限
  21. * @return array
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. protected static function getAll()
  27. {
  28. $data = static::useGlobalScope(false)->order(['sort' => 'asc', 'create_time' => 'asc'])->select();
  29. return $data ? $data->toArray() : [];
  30. }
  31. /**
  32. * 权限信息
  33. * @param int|array $where
  34. * @return array|false|\PDOStatement|string|\think\Model|static
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. */
  39. public static function detail($where)
  40. {
  41. $model = static::useGlobalScope(false);
  42. is_array($where) ? $model->where($where) : $model->where('access_id', '=', $where);
  43. return $model->find();
  44. }
  45. /**
  46. * 获取权限url集
  47. * @param $accessIds
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public static function getAccessUrls($accessIds)
  54. {
  55. $urls = [];
  56. foreach (static::getAll() as $item) {
  57. in_array($item['access_id'], $accessIds) && $urls[] = $item['url'];
  58. }
  59. return $urls;
  60. }
  61. }