Access.php 1.6 KB

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