| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\service\AIGatewayService;
- use app\service\ImageService;
- use think\Cache;
- use \think\Request;
- use \think\Db;
- /**
- * 工单超节损核算接口
- */
- class OrderSuperLoss extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function index()
- {
- $this->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
- ]);
- }
- }
|