ApiService.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\AdModel;
  13. use App\Models\ApiModel;
  14. use App\Services\BaseService;
  15. /**
  16. * 接口管理-服务类
  17. * Class ApiService
  18. * @package App\Services\Common
  19. */
  20. class ApiService extends BaseService
  21. {
  22. // 静态对象
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * ApiService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new ApiModel();
  31. }
  32. /**
  33. * 静态入口
  34. * @return static|null
  35. */
  36. public static function make()
  37. {
  38. if (!self::$instance) {
  39. self::$instance = (new static());
  40. }
  41. return self::$instance;
  42. }
  43. /**
  44. * 添加或编辑
  45. * @return array
  46. */
  47. public function saveData($adminId, $data)
  48. {
  49. $data['admin_id'] = $adminId;
  50. // 权限
  51. if ($data['user_limits']) {
  52. $data['user_limits'] = array_filter($data['user_limits']);
  53. $data['user_limits'] = $data['user_limits']? implode(',', $data['user_limits']) : '';
  54. }
  55. // 结束时间
  56. $id = isset($data['id'])? $data['id'] : 0;
  57. if (!$id) {
  58. $data['api_key'] = getCode('Ti', 12);
  59. }
  60. return parent::edit($data); // TODO: Change the autogenerated stub
  61. }
  62. }