success('请求成功'); } /** * 修改 */ public function getTab() { if (!$this->request->isPost()) { return json(['code' => 400, 'msg' => '请求方式错误'], 400); } $param = $this->request->post([ 'id', 'chinese_description', 'english_description', 'img_name' ]); if (empty($param['id'])) { return json(['code' => 422, 'msg' => '缺少必要参数'], 422); } $result = Db::name('text_to_image') ->where('id', $param['id']) ->update([ 'chinese_description' => $param['chinese_description'] ?? '', 'english_description' => $param['english_description'] ?? '', 'img_name' => $param['img_name'] ?? '' ]); if ($result !== false) { $this->success('修改成功'); } else { $this->success('修改失败'); } } /** * */ public function getList() { $params = Request::instance()->param(); // 分页参数(默认第1页,每页10条) $page = isset($params['page']) ? max((int)$params['page'], 1) : 1; $limit = isset($params['limit']) ? max((int)$params['limit'], 10) : 10; // 搜索关键词 $search = isset($params['search']) ? trim($params['search']) : ''; $folder = isset($params['folder']) ? trim($params['folder']) : ''; $where = []; $wheres = []; if (isset($search)) { $where['id|img_name|chinese_description|english_description'] = ['like', '%'. $search . '%']; } if (isset($folder)) { $wheres['old_image_url'] = ['like', '%'. $folder . '%']; } $count = Db::name('text_to_image') ->where('new_image_url', '<>', '') ->where($where) ->where($wheres) ->where('img_name', '<>', '') ->select(); $list = Db::name('text_to_image') ->where('new_image_url', '<>', '') ->where('img_name', '<>', '') ->where($where) ->where($wheres) ->order('update_time desc') ->page($page, $limit) ->select(); $folder = Db::name('text_to_image') ->field('old_image_url') ->where('new_image_url', '<>', '') ->where('img_name', '<>', '') ->order('update_time desc') ->select(); // 处理路径并去重 $processedFolders = []; foreach ($folder as $item) { $url = $item['old_image_url']; $lastSlashPos = strrpos($url, '/'); if ($lastSlashPos !== false) { $folderPath = substr($url, 0, $lastSlashPos); if (!in_array($folderPath, $processedFolders)) { $processedFolders[] = $folderPath; } } } $this->success('获取成功', [ 'total' => count($count), 'list' => $list, 'folder' => $processedFolders ]); } }