| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\CityModel;
- use App\Models\ActionLogModel;
- use App\Services\BaseService;
- /**
- * 城市管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class CityService
- * @package App\Services\Common
- */
- class CityService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * CityService constructor.
- */
- public function __construct()
- {
- $this->model = new CityModel();
- }
- /**
- * 获取城市列表
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function getList()
- {
- $param = request()->all();
- // 查询条件
- $map = [];
- // 上级ID
- $pid = intval(getter($param, 'pid', 0));
- if (!$pid) {
- $map[] = ['pid', '=', 0];
- } else {
- $map[] = ['pid', '=', $pid];
- }
- // 城市名称
- $name = getter($param, "name");
- if ($name) {
- $map[] = ['name', 'like', "%{$name}%"];
- }
- $list = $this->model->getList($map, [['sort', 'asc']]);
- if (!empty($list)) {
- foreach ($list as &$val) {
- if ($val['level'] <= 2) {
- $val['hasChildren'] = true;
- }
- }
- }
- return message("操作成功", true, $list);
- }
- /**
- * 删除七天之前标记软删除的数据
- */
- public function delete()
- {
- // 设置日志标题
- ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除城市信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
- ActionLogModel::record();
- $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
- return parent::delete();
- }
- }
|