OrderSuperLoss.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\service\AIGatewayService;
  5. use app\service\ImageService;
  6. use think\Cache;
  7. use \think\Request;
  8. use \think\Db;
  9. /**
  10. * 工单超节损核算接口
  11. */
  12. class OrderSuperLoss extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. /**
  21. * 修改
  22. */
  23. public function getTab()
  24. {
  25. if (!$this->request->isPost()) {
  26. return json(['code' => 400, 'msg' => '请求方式错误'], 400);
  27. }
  28. $param = $this->request->post([
  29. 'id',
  30. 'chinese_description',
  31. 'english_description',
  32. 'img_name'
  33. ]);
  34. if (empty($param['id'])) {
  35. return json(['code' => 422, 'msg' => '缺少必要参数'], 422);
  36. }
  37. $result = Db::name('text_to_image')
  38. ->where('id', $param['id'])
  39. ->update([
  40. 'chinese_description' => $param['chinese_description'] ?? '',
  41. 'english_description' => $param['english_description'] ?? '',
  42. 'img_name' => $param['img_name'] ?? ''
  43. ]);
  44. if ($result !== false) {
  45. $this->success('修改成功');
  46. } else {
  47. $this->success('修改失败');
  48. }
  49. }
  50. /**
  51. *
  52. */
  53. public function getList()
  54. {
  55. $params = Request::instance()->param();
  56. // 分页参数(默认第1页,每页10条)
  57. $page = isset($params['page']) ? max((int)$params['page'], 1) : 1;
  58. $limit = isset($params['limit']) ? max((int)$params['limit'], 10) : 10;
  59. // 搜索关键词
  60. $search = isset($params['search']) ? trim($params['search']) : '';
  61. $folder = isset($params['folder']) ? trim($params['folder']) : '';
  62. $where = [];
  63. $wheres = [];
  64. if (isset($search)) {
  65. $where['id|img_name|chinese_description|english_description'] = ['like', '%'. $search . '%'];
  66. }
  67. if (isset($folder)) {
  68. $wheres['old_image_url'] = ['like', '%'. $folder . '%'];
  69. }
  70. $count = Db::name('text_to_image')
  71. ->where('new_image_url', '<>', '')
  72. ->where($where)
  73. ->where($wheres)
  74. ->where('img_name', '<>', '')
  75. ->select();
  76. $list = Db::name('text_to_image')
  77. ->where('new_image_url', '<>', '')
  78. ->where('img_name', '<>', '')
  79. ->where($where)
  80. ->where($wheres)
  81. ->order('update_time desc')
  82. ->page($page, $limit)
  83. ->select();
  84. $folder = Db::name('text_to_image')
  85. ->field('old_image_url')
  86. ->where('new_image_url', '<>', '')
  87. ->where('img_name', '<>', '')
  88. ->order('update_time desc')
  89. ->select();
  90. // 处理路径并去重
  91. $processedFolders = [];
  92. foreach ($folder as $item) {
  93. $url = $item['old_image_url'];
  94. $lastSlashPos = strrpos($url, '/');
  95. if ($lastSlashPos !== false) {
  96. $folderPath = substr($url, 0, $lastSlashPos);
  97. if (!in_array($folderPath, $processedFolders)) {
  98. $processedFolders[] = $folderPath;
  99. }
  100. }
  101. }
  102. $this->success('获取成功', [
  103. 'total' => count($count),
  104. 'list' => $list,
  105. 'folder' => $processedFolders
  106. ]);
  107. }
  108. }