PageLinkServices.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\diy;
  13. use app\services\BaseServices;
  14. use app\dao\diy\PageLinkDao;
  15. use crmeb\exceptions\AdminException;
  16. use crmeb\services\FormBuilder as Form;
  17. use think\facade\Route as Url;
  18. /**
  19. *
  20. * Class DiyServices
  21. * @package app\services\diy
  22. */
  23. class PageLinkServices extends BaseServices
  24. {
  25. /**
  26. * PageLinkServices constructor.
  27. * @param PageLinkDao $dao
  28. */
  29. public function __construct(PageLinkDao $dao)
  30. {
  31. $this->dao = $dao;
  32. }
  33. /**
  34. * 获取页面链接
  35. * @param array $where
  36. * @return array
  37. */
  38. public function getLinkList(array $where)
  39. {
  40. [$page, $limit] = $this->getPageValue();
  41. $list = $this->dao->getList($where, '*', $page, $limit);
  42. $count = $this->dao->count($where);
  43. foreach ($list as &$item) {
  44. $item['h5_url'] = sys_config('site_url') . $item['url'];
  45. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  46. }
  47. return compact('list', 'count');
  48. }
  49. /**
  50. * 删除
  51. * @param int $id
  52. */
  53. public function del(int $id)
  54. {
  55. $res = $this->dao->delete($id);
  56. if (!$res) throw new AdminException(100008);
  57. }
  58. public function getLinkSave($id, $data)
  59. {
  60. unset($data['id']);
  61. if ($id) {
  62. $res = $this->dao->update($id, $data);
  63. } else {
  64. $data['add_time'] = time();
  65. $data['status'] = 1;
  66. $res = $this->dao->save($data);
  67. }
  68. if (!$res) {
  69. throw new AdminException('保存失败');
  70. } else {
  71. return true;
  72. }
  73. }
  74. }