DiyRouteService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\api\diy;
  12. use app\model\diy\DiyRoute;
  13. use core\base\BaseApiService;
  14. /**
  15. * 自定义路由表服务层
  16. * Class DiyRouteService
  17. * @package app\service\api\diy
  18. */
  19. class DiyRouteService extends BaseApiService
  20. {
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->model = new DiyRoute();
  25. }
  26. /**
  27. * 获取页面分享信息
  28. * @param array $data
  29. * @return array|void
  30. */
  31. public function getShare(array $data = [])
  32. {
  33. $field = 'id,title,name,page,share,is_share';
  34. $info = $this->model->field($field)->where([ [ 'page', '=', $data[ 'route' ] ] ])->findOrEmpty()->toArray();
  35. $share = [];
  36. if (!empty($info[ 'share' ])) {
  37. $share = json_decode($info[ 'share' ], true);
  38. $share[ 'route' ] = $info[ 'page' ];
  39. $share[ 'query' ] = '';
  40. $query = [];
  41. if (!empty($data[ 'params' ])) {
  42. $query = json_decode($data[ 'params' ], true);
  43. }
  44. if ($this->member_id > 0) {
  45. $query[ 'mid' ] = $this->member_id;
  46. }
  47. if (!empty($query)) {
  48. $str = [];
  49. foreach ($query as $k => $v) {
  50. $str[] = $k . '=' . $v;
  51. }
  52. $share[ 'query' ] = implode('&', $str);
  53. }
  54. $share[ 'url' ] = $share[ 'route' ] . ( $share[ 'query' ] ? '?' . $share[ 'query' ] : '' );
  55. }
  56. return $share;
  57. }
  58. }