CityService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\CityModel;
  13. use App\Models\ActionLogModel;
  14. use App\Services\BaseService;
  15. /**
  16. * 城市管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * Class CityService
  20. * @package App\Services\Common
  21. */
  22. class CityService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * CityService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new CityModel();
  33. }
  34. /**
  35. * 获取城市列表
  36. * @return array
  37. * @since 2020/11/11
  38. * @author laravel开发员
  39. */
  40. public function getList()
  41. {
  42. $param = request()->all();
  43. // 查询条件
  44. $map = [];
  45. // 上级ID
  46. $pid = intval(getter($param, 'pid', 0));
  47. if (!$pid) {
  48. $map[] = ['pid', '=', 0];
  49. } else {
  50. $map[] = ['pid', '=', $pid];
  51. }
  52. // 城市名称
  53. $name = getter($param, "name");
  54. if ($name) {
  55. $map[] = ['name', 'like', "%{$name}%"];
  56. }
  57. $list = $this->model->getList($map, [['sort', 'asc']]);
  58. if (!empty($list)) {
  59. foreach ($list as &$val) {
  60. if ($val['level'] <= 2) {
  61. $val['hasChildren'] = true;
  62. }
  63. }
  64. }
  65. return message("操作成功", true, $list);
  66. }
  67. /**
  68. * 删除七天之前标记软删除的数据
  69. */
  70. public function delete()
  71. {
  72. // 设置日志标题
  73. ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除城市信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
  74. ActionLogModel::record();
  75. $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
  76. return parent::delete();
  77. }
  78. }