Api.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model\store;
  13. use cores\BaseModel;
  14. /**
  15. * 商家后台API权限模型
  16. * Class Api
  17. * @package app\common\model\admin
  18. */
  19. class Api extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'store_api';
  23. // 定义表主键
  24. protected $pk = 'api_id';
  25. /**
  26. * 获取所有权限
  27. * @return array
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. protected static function getAll(): array
  33. {
  34. $data = static::withoutGlobalScope()
  35. ->order(['sort', 'create_time'])
  36. ->select();
  37. return !$data->isEmpty() ? $data->toArray() : [];
  38. }
  39. /**
  40. * 权限信息
  41. * @param int|array $where
  42. * @return static|array|null
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public static function detail($where)
  48. {
  49. $model = static::withoutGlobalScope();
  50. is_array($where) ? $model->where($where) : $model->where('api_id', '=', $where);
  51. return $model->find();
  52. }
  53. /**
  54. * 获取指定ID集的url
  55. * @param array $apiIds
  56. * @return array
  57. */
  58. public static function getApiUrls(array $apiIds): array
  59. {
  60. return static::withoutGlobalScope()
  61. ->where('api_id', 'in', $apiIds)
  62. ->order(['sort', 'create_time'])
  63. ->column('url');
  64. }
  65. }