LinkService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\LinkModel;
  13. /**
  14. * 友链管理-服务类
  15. * @author wesmiler
  16. * @since 2020/11/11
  17. * Class LinkService
  18. * @package App\Services
  19. */
  20. class LinkService extends BaseService
  21. {
  22. /**
  23. * 构造函数
  24. * @author wesmiler
  25. * @since 2020/11/11
  26. * LinkService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new LinkModel();
  31. }
  32. /**
  33. * 获取友链列表
  34. * @return array
  35. * @since 2020/11/11
  36. * @author wesmiler
  37. */
  38. public function getList()
  39. {
  40. $param = request()->all();
  41. // 查询条件
  42. $map = [];
  43. // 友链平台
  44. $platform = getter($param, "platform");
  45. if ($platform) {
  46. $map[] = ["platform", '=', $platform];
  47. }
  48. return parent::getList($map); // TODO: Change the autogenerated stub
  49. }
  50. /**
  51. * 添加或编辑
  52. * @return array
  53. * @since 2020/11/11
  54. * @author wesmiler
  55. */
  56. public function edit()
  57. {
  58. $data = request()->all();
  59. // 图片处理
  60. $image = trim($data['image']);
  61. if (!$data['id'] && !$image) {
  62. return message('请上传友链图片', false);
  63. }
  64. if (strpos($image, "temp")) {
  65. $data['image'] = save_image($image, 'item');
  66. } else {
  67. $data['image'] = str_replace(IMG_URL, "", $data['image']);
  68. }
  69. return parent::edit($data); // TODO: Change the autogenerated stub
  70. }
  71. }