WorkOrder.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\job\ImageJob;
  5. use app\service\ImageService;
  6. use think\App;
  7. use think\Db;
  8. use think\Log;
  9. use think\Queue;
  10. use think\queue\job\Redis;
  11. class WorkOrder extends Api
  12. {
  13. protected $noNeedLogin = ['*'];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 出图接口
  17. * 此方法处理图像转换为文本的请求,将图像信息存入队列以供后续处理。
  18. */
  19. public function imageToText()
  20. {
  21. $params = $this->request->param();
  22. $service = new ImageService();
  23. $service->handleImage($params);
  24. $this->success('任务成功提交至队列');
  25. }
  26. public function imgtowimg()
  27. {
  28. $prompt = $this->request->param('prompt', '将图片纵向扩展至1248像素');
  29. $imgRelPath = 'uploads/operate/ai/Preview/arr/一朵盛开的白色牡丹花为主体采用厚涂技法花心和背景点缀金箔灰银.png';
  30. $imgPath = ROOT_PATH . 'public/' . $imgRelPath;
  31. if (!file_exists($imgPath)) {
  32. return json(['code' => 1, 'msg' => '原图不存在:' . $imgRelPath]);
  33. }
  34. $imgData = file_get_contents($imgPath);
  35. $base64Img = base64_encode($imgData);
  36. $initImage = 'data:image/png;base64,' . $base64Img;
  37. $postData = json_encode([
  38. 'prompt' => "1girl",
  39. 'negative_prompt' => '(nsfw),sketches,tattoo,(beard:1.3,(EasyNegative:1.3),badhandv,(Teeth:1.3),(worst quality:2),(low quality:2),(normal quality:2),lowers,normal quality,facing away,looking away,text,error,extra digit,fewer digits,cropped,jpeg artifacts,signature,watermark,username,blurry,skin spots,acnes,skin blemishes,bad anatomy,fat,bad feet,poorly drawn hands,poorly drawn face,mutation,deformed,tilted hands,extra fingers,extra limbs,extra arms,extra legs,malformed proportions,gross proportions,missing fingers,missing toes)',
  40. 'steps' => 20,
  41. 'cfg_scale' => 7,
  42. 'seed' => -1,
  43. 'clip_skip' => 7,
  44. 'denoising_strength' => 0.2,
  45. 'width' => 1024,
  46. 'height' => 1248,
  47. 'resize_mode' => 2, // 缩放后填充空白
  48. 'inpainting_fill' => 0, // 保留原图内容
  49. 'mask_blur' => 0,
  50. 'sampler_name' => 'Euler a',
  51. 'init_images' => [$initImage],
  52. 'override_settings' => [
  53. 'sd_model_checkpoint' => 'Realistic_Vision_V5.0-inpainting',
  54. 'sd_vae' => 'vae-ft-mse-840000-ema-pruned',
  55. 'CLIP_stop_at_last_layers' => 7
  56. ],
  57. 'override_settings_restore_afterwards' => true,
  58. 'alwayson_scripts' => [
  59. 'ControlNet' => [
  60. 'args' => [[
  61. 'input_image' => null,
  62. 'module' => 'inpaint_only+lama',
  63. 'model' => 'control_v11p_sd15_openpose [cab727d4]',
  64. 'weight' => 1.0,
  65. 'resize_mode' => 'Resize and Fill',
  66. 'lowvram' => false,
  67. 'processor_res' => 512,
  68. 'threshold_a' => 64,
  69. 'threshold_b' => 64,
  70. 'guidance_start' => 0.0,
  71. 'guidance_end' => 1.0,
  72. 'pixel_perfect' => true,
  73. 'control_mode' => 2 // 更偏向ControlNet
  74. ]]
  75. ]
  76. ]
  77. ]);
  78. $apiUrl = "http://20.0.17.188:45001/sdapi/v1/img2img";
  79. $headers = ['Content-Type: application/json'];
  80. $ch = curl_init();
  81. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  82. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  83. curl_setopt($ch, CURLOPT_POST, true);
  84. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  85. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  86. curl_setopt($ch, CURLOPT_TIMEOUT, 90);
  87. $response = curl_exec($ch);
  88. $error = curl_error($ch);
  89. curl_close($ch);
  90. if ($error) {
  91. return json(['code' => 1, 'msg' => '请求失败:' . $error]);
  92. }
  93. $data = json_decode($response, true);
  94. if (!isset($data['images'][0])) {
  95. return json(['code' => 1, 'msg' => '接口未返回图像数据']);
  96. }
  97. $resultImg = base64_decode($data['images'][0]);
  98. $saveDir = ROOT_PATH . 'public/uploads/img2img/';
  99. if (!is_dir($saveDir)) {
  100. mkdir($saveDir, 0755, true);
  101. }
  102. $originalBaseName = pathinfo($imgRelPath, PATHINFO_FILENAME);
  103. $fileName = $originalBaseName . '-' . time() . '-1024x1248.png';
  104. $savePath = $saveDir . $fileName;
  105. file_put_contents($savePath, $resultImg);
  106. return json([
  107. 'code' => 0,
  108. 'msg' => '图像生成成功',
  109. 'data' => [
  110. 'origin_url' => '/uploads/img2img/' . $fileName
  111. ]
  112. ]);
  113. }
  114. // /**
  115. // * 图生图功能-单张图片本地测试使用
  116. // * 接口地址: /sdapi/v1/img2img
  117. // */
  118. // public function imgtowimg()
  119. // {
  120. // $prompt = $this->request->param('prompt', '将图片不完整部分补充完整');
  121. // $imgRelPath = 'uploads/operate/ai/Preview/arr/一朵盛开的白色牡丹花为主体采用厚涂技法花心和背景点缀金箔灰银.png';
  122. // $imgPath = ROOT_PATH . 'public/' . $imgRelPath;
  123. // //原图是否存在
  124. // if (!file_exists($imgPath)) {
  125. // return json(['code' => 1, 'msg' => '原图不存在:' . $imgRelPath]);
  126. // }
  127. //
  128. // // -------- 图像编码 -------- //
  129. // $imgData = file_get_contents($imgPath);
  130. // $base64Img = base64_encode($imgData);
  131. // $initImage = 'data:image/png;base64,' . $base64Img;
  132. //
  133. // // -------- 请求体构建 -------- //
  134. // $postData = json_encode([
  135. // 'prompt' => $prompt,
  136. // 'steps' => 30, // 步数
  137. // 'cfg_scale' => 7, // CFG 强度
  138. // 'denoising_strength' => 0.2, // 重绘强度
  139. // 'width' => 679, // 图像宽度
  140. // 'height' => 862, // 图像高度
  141. // 'resize_mode' => 1, // 保留原图比例并裁剪
  142. // 'inpaint_full_res' => true, // 使用原图分辨率
  143. // 'inpaint_full_res_padding' => 64, // 边缘补全像素
  144. // 'mask_blur' => 4, // 蒙版柔化
  145. // 'inpainting_fill' => 3, // 自动填充内容(不是黑色)
  146. // 'sampler_name' => 'DPM++ 2M SDE', // 采样器
  147. // 'scheduler' => 'Exponential', // ✅ 调度类型(补充字段)
  148. // 'seed' => 3689437019, // 固定种子(确保结果可复现)
  149. // 'init_images' => [$initImage], // 原图 base64
  150. // 'override_settings' => [
  151. // 'sd_model_checkpoint' => 'AbyssOrangeMix2_sfw', // 模型名
  152. // 'sd_vae' => "Automatic",
  153. // 'CLIP_stop_at_last_layers' => 2
  154. // ],
  155. // 'override_settings_restore_afterwards' => true
  156. // ]);
  157. //
  158. // // -------- 发送请求到 SD API -------- //
  159. // $apiUrl = "http://20.0.17.188:45001/sdapi/v1/img2img";
  160. // $headers = ['Content-Type: application/json'];
  161. //
  162. // $ch = curl_init();
  163. // curl_setopt($ch, CURLOPT_URL, $apiUrl);
  164. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  165. // curl_setopt($ch, CURLOPT_POST, true);
  166. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  167. // curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  168. // curl_setopt($ch, CURLOPT_TIMEOUT, 90);
  169. // $response = curl_exec($ch);
  170. // $error = curl_error($ch);
  171. // curl_close($ch);
  172. //
  173. // if ($error) {return json(['code' => 1, 'msg' => '请求失败:' . $error]);}
  174. // $data = json_decode($response, true);
  175. // if (!isset($data['images'][0])) {
  176. // return json(['code' => 1, 'msg' => '接口未返回图像数据']);
  177. // }
  178. //
  179. // // -------- 保存生成图像 -------- //
  180. // $resultImg = base64_decode($data['images'][0]);
  181. // $saveDir = ROOT_PATH . 'public/uploads/img2img/';
  182. // if (!is_dir($saveDir)) {
  183. // mkdir($saveDir, 0755, true);
  184. // }
  185. //
  186. // $originalBaseName = pathinfo($imgRelPath, PATHINFO_FILENAME);
  187. // $fileName = $originalBaseName . '-' . time() . '-1.png';
  188. // $savePath = $saveDir . $fileName;
  189. // file_put_contents($savePath, $resultImg);
  190. //
  191. // return json([
  192. // 'code' => 0,
  193. // 'msg' => '图像生成成功',
  194. // 'data' => [
  195. // 'origin_url' => '/uploads/img2img/' . $fileName
  196. // ]
  197. // ]);
  198. // }
  199. /**
  200. * 后期图像处理-单张图片高清放大处理
  201. * 接口地址: /sdapi/v1/extra-single-image
  202. */
  203. public function extra_image()
  204. {
  205. // 配置参数
  206. $config = [
  207. 'input_dir' => 'uploads/operate/ai/Preview/arr/',
  208. 'output_dir' => 'uploads/extra_image/',
  209. 'api_url' => 'http://20.0.17.188:45001/sdapi/v1/extra-single-image',
  210. 'timeout' => 120, // 增加超时时间,高清处理可能耗时较长
  211. 'upscale_params' => [
  212. 'resize_mode' => 0,
  213. 'show_extras_results' => true,
  214. 'gfpgan_visibility' => 0, // 人脸修复关闭
  215. 'codeformer_visibility' => 0, // 人脸修复关闭
  216. 'codeformer_weight' => 0,
  217. 'upscaling_resize' => 2.45, // 放大倍数
  218. 'upscaling_crop' => true,
  219. 'upscaler_1' => 'R-ESRGAN 4x+ Anime6B', // 主放大模型
  220. 'upscaler_2' => 'None', // 不使用第二放大器
  221. 'extras_upscaler_2_visibility' => 0,
  222. 'upscale_first' => false,
  223. ]
  224. ];
  225. // 输入文件处理
  226. $imgRelPath = '图案的整体色调是柔和的蓝色和灰色形成温馨而宁静的视觉效果花卉.png';
  227. $imgPath = ROOT_PATH . 'public/' . $config['input_dir'] . $imgRelPath;
  228. if (!file_exists($imgPath)) {
  229. return json(['code' => 1, 'msg' => '原图不存在:' . $imgRelPath]);
  230. }
  231. // 读取并编码图片
  232. try {
  233. $imgData = file_get_contents($imgPath);
  234. if ($imgData === false) {
  235. throw new Exception('无法读取图片文件');
  236. }
  237. $base64Img = base64_encode($imgData);
  238. } catch (Exception $e) {
  239. return json(['code' => 1, 'msg' => '图片处理失败:' . $e->getMessage()]);
  240. }
  241. // 准备API请求数据
  242. $postData = array_merge($config['upscale_params'], ['image' => $base64Img]);
  243. $jsonData = json_encode($postData);
  244. if ($jsonData === false) {
  245. return json(['code' => 1, 'msg' => 'JSON编码失败']);
  246. }
  247. // 调用API进行高清放大
  248. $ch = curl_init();
  249. curl_setopt_array($ch, [
  250. CURLOPT_URL => $config['api_url'],
  251. CURLOPT_RETURNTRANSFER => true,
  252. CURLOPT_POST => true,
  253. CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
  254. CURLOPT_POSTFIELDS => $jsonData,
  255. CURLOPT_TIMEOUT => $config['timeout'],
  256. CURLOPT_CONNECTTIMEOUT => 30,
  257. ]);
  258. $response = curl_exec($ch);
  259. $error = curl_error($ch);
  260. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  261. curl_close($ch);
  262. if ($error) {
  263. return json(['code' => 1, 'msg' => 'API请求失败:' . $error]);
  264. }
  265. if ($httpCode !== 200) {
  266. return json(['code' => 1, 'msg' => 'API返回错误状态码:' . $httpCode]);
  267. }
  268. $data = json_decode($response, true);
  269. if (json_last_error() !== JSON_ERROR_NONE) {
  270. return json(['code' => 1, 'msg' => 'API返回数据解析失败']);
  271. }
  272. if (!isset($data['image']) || empty($data['image'])) {
  273. return json(['code' => 1, 'msg' => '接口未返回有效的图像数据']);
  274. }
  275. // 保存处理后的图片
  276. try {
  277. $resultImg = base64_decode($data['image']);
  278. if ($resultImg === false) {
  279. throw new Exception('Base64解码失败');
  280. }
  281. $saveDir = ROOT_PATH . 'public/' . $config['output_dir'];
  282. if (!is_dir($saveDir) && !mkdir($saveDir, 0755, true)) {
  283. throw new Exception('无法创建输出目录');
  284. }
  285. $originalBaseName = pathinfo($imgRelPath, PATHINFO_FILENAME);
  286. $fileName = $originalBaseName . '-hd.png'; // 使用-hd后缀更明确
  287. $savePath = $saveDir . $fileName;
  288. if (file_put_contents($savePath, $resultImg) === false) {
  289. throw new Exception('无法保存处理后的图片');
  290. }
  291. // 返回成功响应
  292. return json([
  293. 'code' => 0,
  294. 'msg' => '图像高清放大处理成功',
  295. 'data' => [
  296. 'url' => '/' . $config['output_dir'] . $fileName,
  297. 'original_size' => filesize($imgPath),
  298. 'processed_size' => filesize($savePath),
  299. 'resolution' => getimagesize($savePath), // 返回新图片的分辨率
  300. ]
  301. ]);
  302. } catch (Exception $e) {
  303. return json(['code' => 1, 'msg' => '保存结果失败:' . $e->getMessage()]);
  304. }
  305. }
  306. /**
  307. * 获取 SD 模型列表
  308. * 接口地址: /sdapi/v1/sd-models
  309. */
  310. public function sd_models() {
  311. // $url = "http://20.0.17.188:45001/sdapi/v1/sd-models";
  312. // // 初始化 cURL
  313. // $ch = curl_init();
  314. // // 设置请求参数
  315. // curl_setopt($ch, CURLOPT_URL, $url);
  316. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  317. // curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  318. // curl_setopt($ch, CURLOPT_HTTPHEADER, [
  319. // 'Content-Type: application/json',
  320. // 'Accept: application/json',
  321. // ]);
  322. // // 发送请求
  323. // $response = curl_exec($ch);
  324. // // 错误处理
  325. // if (curl_errno($ch)) {
  326. // curl_close($ch);
  327. // return json([
  328. // 'code' => 1,
  329. // 'msg' => '请求失败: ' . curl_error($ch),
  330. // 'data' => [],
  331. // 'count' => 0
  332. // ]);
  333. // }
  334. // curl_close($ch);
  335. // // 解析 JSON 响应
  336. // $result = json_decode($response, true);
  337. // // 判断返回数据是否有效
  338. // if (!is_array($result)) {
  339. // return json([
  340. // 'code' => 1,
  341. // 'msg' => '数据解析失败',
  342. // 'data' => [],
  343. // 'count' => 0
  344. // ]);
  345. // }
  346. // 正常返回
  347. return json([
  348. 'code' => 0,
  349. 'msg' => '查询成功',
  350. 'data' => '',
  351. 'count' => 2,
  352. ]);
  353. }
  354. /**
  355. * 查询队列列表
  356. * 统计文件对应的队列情况
  357. */
  358. public function get_queue_logs()
  359. {
  360. $params = $this->request->param('old_image_file', '');
  361. $queue_logs = Db::name('queue_logs')
  362. ->where('old_image_file', $params)
  363. ->order('id desc')
  364. ->select();
  365. $result = []; //初始化变量,避免未定义错误
  366. foreach ($queue_logs as &$log) {
  367. $taskId = $log['id'];
  368. $statusCount = Db::name('image_task_log')
  369. ->field('status, COUNT(*) as count')
  370. ->where('task_id', $taskId)
  371. ->where('mod_rq', null)
  372. ->group('status')
  373. ->select();
  374. $log['已完成数量'] = 0;
  375. $log['处理中数量'] = 0;
  376. $log['排队中的数量'] = 0;
  377. $log['失败数量'] = 0;
  378. foreach ($statusCount as $item) {
  379. switch ($item['status']) {
  380. case 0:
  381. $log['排队中的数量'] = $item['count'];
  382. break;
  383. case 1:
  384. $log['处理中数量'] = $item['count'];
  385. break;
  386. case 2:
  387. $log['已完成数量'] = $item['count'];
  388. break;
  389. case -1:
  390. $log['失败数量'] = $item['count'];
  391. break;
  392. }
  393. }
  394. // if ($log['排队中的数量'] >$log['已完成数量']) {
  395. // $result[] = $log;
  396. // }
  397. if ($log['排队中的数量']) {
  398. $result[] = $log;
  399. }
  400. // if ($log['处理中数量'] >= 0) {
  401. // $result[] = $log;
  402. // }
  403. }
  404. return json([
  405. 'code' => 0,
  406. 'msg' => '查询成功',
  407. 'data' => $result,
  408. 'count' => count($result)
  409. ]);
  410. }
  411. /**
  412. * 查询总队列状态(统计当前处理的数据量)
  413. */
  414. public function queueStats()
  415. {
  416. $statusList = Db::name('image_task_log')
  417. ->field('status, COUNT(*) as total')
  418. ->where('mod_rq', null)
  419. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  420. ->group('status')
  421. ->select();
  422. $statusCount = [];
  423. foreach ($statusList as $item) {
  424. $statusCount[$item['status']] = $item['total'];
  425. }
  426. // 总数为所有状态和
  427. $total = array_sum($statusCount);
  428. //获取队列当前状态
  429. $statusText = Db::name('queue_logs')->order('id desc')->value('status');
  430. return json([
  431. 'code' => 0,
  432. 'msg' => '获取成功',
  433. 'data' => [
  434. '总任务数' => $total,
  435. '待处理' => $statusCount[0] ?? 0,
  436. '处理中' => $statusCount[1] ?? 0,
  437. '成功' => $statusCount[2] ?? 0,
  438. '失败' => $statusCount[-1] ?? 0,
  439. '当前状态' => $statusText
  440. ]
  441. ]);
  442. }
  443. /**
  444. * 显示当前运行中的队列监听进程
  445. */
  446. public function viewQueueStatus()
  447. {
  448. $redis = new \Redis();
  449. $redis->connect('127.0.0.1', 6379);
  450. $redis->auth('123456');
  451. $redis->select(15);
  452. $key = 'queues:imgtotxt';
  453. // 判断 key 是否存在,避免报错
  454. if (!$redis->exists($key)) {
  455. return json([
  456. 'code' => 0,
  457. 'msg' => '查询成功,队列为空',
  458. 'count' => 0,
  459. 'tasks_preview' => []
  460. ]);
  461. }
  462. $count = $redis->lLen($key);
  463. $list = $redis->lRange($key, 0, 9);
  464. // 解码 JSON 内容,确保每一项都有效
  465. $parsed = array_filter(array_map(function ($item) {
  466. return json_decode($item, true);
  467. }, $list), function ($item) {
  468. return !is_null($item);
  469. });
  470. return json([
  471. 'code' => 0,
  472. 'msg' => '查询成功',
  473. 'count' => $count,
  474. 'tasks_preview' => $parsed
  475. ]);
  476. }
  477. /**
  478. * 清空队列并删除队列日志记录
  479. */
  480. public function stopQueueProcesses()
  481. {
  482. Db::name('image_task_log')
  483. ->where('log', '队列中')
  484. ->whereOr('status', 1)
  485. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  486. ->update([
  487. 'status' => "-1",
  488. 'log' => '清空取消队列',
  489. 'mod_rq' => date('Y-m-d H:i:s')
  490. ]);
  491. Db::name('image_task_log')
  492. ->whereLike('log', '%处理中%')
  493. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  494. ->update([
  495. 'status' => "-1",
  496. 'log' => '清空取消队列',
  497. 'mod_rq' => date('Y-m-d H:i:s')
  498. ]);
  499. $redis = new \Redis();
  500. $redis->connect('127.0.0.1', 6379);
  501. $redis->auth('123456');
  502. $redis->select(15);
  503. $key_txttoimg = 'queues:txttoimg:reserved';
  504. $key_txttotxt = 'queues:txttotxt:reserved';
  505. $key_imgtotxt = 'queues:imgtotxt:reserved';
  506. $key_imgtoimg = 'queues:imgtoimg:reserved';
  507. // 清空 Redis 队列
  508. $redis->del($key_txttoimg);
  509. $redis->del($key_txttotxt);
  510. $redis->del($key_imgtotxt);
  511. $redis->del($key_imgtoimg);
  512. $count = $redis->lLen($key_txttoimg) + $redis->lLen($key_txttotxt) + $redis->lLen($key_imgtotxt) + $redis->lLen($key_imgtoimg);
  513. // if ($count === 0) {
  514. // return json([
  515. // 'code' => 1,
  516. // 'msg' => '暂无队列需要停止'
  517. // ]);
  518. // }
  519. return json([
  520. 'code' => 0,
  521. 'msg' => '成功停止队列任务'
  522. ]);
  523. }
  524. /**
  525. * 开启队列任务
  526. * 暂时用不到、服务器已开启自动开启队列模式
  527. */
  528. // public function kaiStats()
  529. // {
  530. // // 判断是否已有监听进程在运行
  531. // $check = shell_exec("ps aux | grep 'queue:listen' | grep -v grep");
  532. // if ($check) {
  533. // return json([
  534. // 'code' => 1,
  535. // 'msg' => '监听进程已存在,请勿重复启动'
  536. // ]);
  537. // }
  538. // // 启动监听
  539. // $command = 'nohup php think queue:listen --queue --timeout=300 --sleep=3 --memory=256 > /var/log/job_queue.log 2>&1 &';
  540. // exec($command, $output, $status);
  541. // if ($status === 0) {
  542. // return json([
  543. // 'code' => 0,
  544. // 'msg' => '队列监听已启动'
  545. // ]);
  546. // } else {
  547. // return json([
  548. // 'code' => 1,
  549. // 'msg' => '队列启动失败',
  550. // 'output' => $output
  551. // ]);
  552. // }
  553. // }
  554. /**
  555. * 通过店铺ID-查询对应店铺表数据
  556. *
  557. */
  558. public function PatternApi()
  559. {
  560. $params = $this->request->param('pattern_id', '');
  561. $tableName = 'pattern-' . $params;
  562. // 连接 MongoDB
  563. $mongo = Db::connect('mongodb');
  564. // 查询指定 skc 的数据
  565. $data = $mongo->table($tableName)
  566. ->field('
  567. name,
  568. skc,
  569. file
  570. ')
  571. ->where("skc", '0853004152036')
  572. ->select();
  573. $data = json_decode(json_encode($data), true); // 数组
  574. return json([
  575. 'code' => 0,
  576. 'msg' => '获取成功',
  577. 'data' => $data
  578. ]);
  579. }
  580. }