ItemService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\ItemModel;
  13. /**
  14. * 站点管理-服务类
  15. * @author wesmiler
  16. * @since 2020/11/11
  17. * Class ItemService
  18. * @package App\Services
  19. */
  20. class ItemService extends BaseService
  21. {
  22. /**
  23. * 构造函数
  24. * @author wesmiler
  25. * @since 2020/11/11
  26. * ItemService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new ItemModel();
  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. $type = getter($param, "type", 0);
  45. if ($type) {
  46. $map[] = ["type", '=', $type];
  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. /**
  72. * 获取站点列表
  73. * @return array
  74. * @since 2020/11/11
  75. * @author wesmiler
  76. */
  77. public function getItemList()
  78. {
  79. $list = $this->model->where("status", "=", 1)
  80. ->where("mark", "=", 1)
  81. ->orderBy("sort", "asc")
  82. ->get()
  83. ->toArray();
  84. return message("操作成功", true, $list);
  85. }
  86. }