WorkOrder.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\job\ImageJob;
  5. use app\service\AIGatewayService;
  6. use app\service\ImageService;
  7. use think\App;
  8. use think\Db;
  9. use think\Exception;
  10. use think\Log;
  11. use think\Queue;
  12. use think\queue\job\Redis;
  13. use think\Request;
  14. class WorkOrder extends Api{
  15. protected $noNeedLogin = ['*'];
  16. protected $noNeedRight = ['*'];
  17. public function index(){echo '访问成功';}
  18. /**
  19. * AI队列入口处理 出图接口
  20. * 此方法处理图像转换为文本的请求,将图像信息存入队列以供后续处理。
  21. */
  22. public function imageToText()
  23. {
  24. $params = $this->request->param();
  25. $service = new ImageService();
  26. $service->handleImage($params);
  27. $this->success('任务成功提交至队列');
  28. }
  29. /**
  30. * product 产品专用统一api调用接口
  31. * AI模型调用接口
  32. */
  33. public function GetTxtToTxt(){
  34. $params = $this->request->param();
  35. $prompt = $params['prompt'];//提示词
  36. $old_path = $params['path'] ?? '';//原图路径
  37. $model = $params['model'];//模型
  38. if(empty($model)) {
  39. return json(['code' => 1, 'msg' => '模型请求失败']);
  40. }
  41. $aiGateway = new AIGatewayService();
  42. $service = new ImageService();
  43. if($params['status_val'] == '图生文'){
  44. $service->handleImgToText($params);
  45. $res = [
  46. 'code' => 0,
  47. 'msg' => '正在优化提示词,请稍等.....'
  48. ];
  49. return json($res);
  50. }else if($params['status_val'] == '文生文'){
  51. $fullPrompt = $prompt;
  52. $fullPrompt .= "
  53. 请根据上述内容生成一段完整的话术,要求:
  54. 1. 内容必须是连贯的一段话,不要使用列表、分隔线或其他结构化格式
  55. 2. 不要包含非文本元素的描述
  56. 3. 不要添加任何额外的引导语、解释或开场白
  57. 4. 语言流畅自然";
  58. $result = $service->handleTextToText($fullPrompt, $model);
  59. if(!empty($params['id'])){
  60. Db::name('product')->where('id', $params['id'])->update(['content' => $result['data']]);
  61. }
  62. $res = [
  63. 'code' => 0,
  64. 'msg' => '优化成功',
  65. 'content' => $result['data']
  66. ];
  67. return json($res);
  68. }elseif($params['status_val'] == '文生图'){
  69. $service->handleTextToImg($params);
  70. $res = [
  71. 'code' => 0,
  72. 'msg' => '正在生成图片中,请稍等.....'
  73. ];
  74. return json($res);
  75. }else{
  76. $this->error('请求失败');
  77. }
  78. }
  79. public function GetTxtToImg(){
  80. $params = $this->request->param();
  81. $prompt = $params['prompt'];//提示词
  82. $model = $params['model'];//模型
  83. $size = $params['size'];//尺寸
  84. // 调用AI生成图片
  85. $aiGateway = new AIGatewayService();
  86. $res = $aiGateway->callDalleApi($prompt, $model, $size);
  87. // 提取base64图片数据
  88. $imageData = '';
  89. $imageType = 'png'; // 默认图片类型
  90. if (isset($res['candidates'][0]['content']['parts'][0]['text'])) {
  91. $text_content = $res['candidates'][0]['content']['parts'][0]['text'];
  92. // 匹配base64图片数据和类型
  93. if (preg_match('/data:image\/([a-zA-Z0-9]+);base64,([^\s]+)/', $text_content, $matches)) {
  94. $imageType = strtolower($matches[1]);
  95. $base64Data = $matches[2];
  96. // 解码base64数据
  97. $imageData = base64_decode($base64Data);
  98. }
  99. }
  100. if (!$imageData) {
  101. return json(['code' => 1, 'msg' => '图片生成失败,未找到有效图片数据']);
  102. }
  103. // 创建保存目录(public/uploads/log/YYYY-MM/)
  104. $yearMonth = date('Ym');
  105. $saveDir = ROOT_PATH . 'public/uploads/log/' . $yearMonth . '/';
  106. if (!is_dir($saveDir)) {
  107. mkdir($saveDir, 0755, true);
  108. }
  109. // 生成唯一文件名
  110. $fileName = uniqid() . '.' . $imageType;
  111. $filePath = $saveDir . $fileName;
  112. // 保存图片到本地文件
  113. if (file_put_contents($filePath, $imageData) === false) {
  114. return json(['code' => 1, 'msg' => '图片保存失败']);
  115. }
  116. // 生成前端可访问的URL
  117. $imageUrl = '/uploads/log/' . $yearMonth . '/' . $fileName;
  118. // 返回标准JSON响应
  119. return json([
  120. 'code' => 0,
  121. 'msg' => '图片生成成功',
  122. 'data' => [
  123. 'url' => $imageUrl
  124. // 'url' => '/uploads/log/202601/695b141099d1e.jpeg'
  125. ]
  126. ]);
  127. }
  128. /**
  129. * 学生端文生视频接口 - 用于生成视频
  130. */
  131. public function GetTxtToVideo(){
  132. // 获取并验证参数
  133. $params = $this->request->param();
  134. // echo "<pre>";
  135. // print_r($params);
  136. // echo "<pre>";die;
  137. // 正常的视频生成请求处理
  138. $apiUrl = 'https://chatapi.onechats.ai/v1/videos';
  139. $apiKey = 'sk-sWW1GFlnjbrDRb1DkMEzePIxgdvLK6cZt0Qg93yDMVP2z1yN';
  140. $postData = [
  141. 'prompt' => $params['prompt'],
  142. 'model' => $params['model'],
  143. 'seconds' => $params['duration'],
  144. 'size' => $params['size'],
  145. ];
  146. // 初始化CURL
  147. $ch = curl_init();
  148. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  149. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  150. curl_setopt($ch, CURLOPT_POST, true);
  151. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  152. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  153. 'Authorization: Bearer ' . $apiKey
  154. ]);
  155. curl_setopt($ch, CURLOPT_TIMEOUT, 300);
  156. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  157. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  158. curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
  159. curl_setopt($ch, CURLOPT_VERBOSE, true); // 启用详细输出以进行调试
  160. // 创建临时文件来捕获详细的cURL输出
  161. $verbose = fopen('php://temp', 'w+');
  162. curl_setopt($ch, CURLOPT_STDERR, $verbose);
  163. // 执行请求
  164. $response = curl_exec($ch);
  165. //HTTP状态码
  166. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  167. // 获取详细的cURL调试信息
  168. rewind($verbose);
  169. //CURL调试信息
  170. $verboseLog = stream_get_contents($verbose);
  171. fclose($verbose);
  172. // 分离头部和主体
  173. $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  174. //响应头部
  175. $header = substr($response, 0, $header_size);
  176. //响应主体
  177. $body = substr($response, $header_size);
  178. // 检查CURL错误
  179. $curlError = curl_error($ch);
  180. curl_close($ch);
  181. $responseData = json_decode($body, true);
  182. // 检查API是否返回了错误信息
  183. if (isset($responseData['error'])) {
  184. $errorMessage = isset($responseData['error']['message']) ? $responseData['error']['message'] : 'API请求失败';
  185. return json([
  186. 'code' => 1,
  187. 'msg' => '视频生成请求失败',
  188. 'data' => [
  189. 'error_type' => isset($responseData['error']['type']) ? $responseData['error']['type'] : 'unknown',
  190. 'error_code' => isset($responseData['error']['code']) ? $responseData['error']['code'] : 'unknown',
  191. 'error_message' => $errorMessage
  192. ]
  193. ]);
  194. }
  195. // 检查是否有自定义错误格式
  196. if (isset($responseData['code']) && $responseData['code'] === 'fail_to_fetch_task' && isset($responseData['message'])) {
  197. return json([
  198. 'code' => 1,
  199. 'msg' => '视频生成请求失败',
  200. 'data' => [
  201. 'error_code' => $responseData['code'],
  202. 'error_message' => $responseData['message']
  203. ]
  204. ]);
  205. }
  206. // 检查是否存在id字段
  207. if (!isset($responseData['id'])) {
  208. return json([
  209. 'code' => 1,
  210. 'msg' => '无法获取视频ID',
  211. 'data' => [
  212. 'response_data' => $responseData,
  213. 'http_code' => $httpCode
  214. ]
  215. ]);
  216. }
  217. // 1. 先检查视频状态
  218. $statusUrl = 'https://chatapi.onechats.ai/v1/videos/' . $responseData['id'];
  219. $statusData = $this->fetchVideoStatus($statusUrl, $apiKey);
  220. // 检查视频状态
  221. if ($statusData['status'] !== 'completed') {
  222. return json([
  223. 'code' => 202,
  224. 'msg' => '视频尚未生成完成',
  225. 'data' => [
  226. 'video_id' => $responseData['id'],
  227. 'status' => $statusData['status'],
  228. 'progress' => $statusData['progress'],
  229. 'created_at' => $statusData['created_at'],
  230. 'message' => '请稍后再试,视频仍在' . ($statusData['status'] === 'queued' ? '排队中' : '处理中')
  231. ]
  232. ]);
  233. }
  234. // 2. 视频生成完成,准备下载
  235. $apiUrl = 'https://chatapi.onechats.ai/v1/videos/' . $responseData['id'] . '/content';
  236. // 获取可选的variant参数
  237. $variant = $this->request->get('variant', '');
  238. if (!empty($variant)) {
  239. $apiUrl .= '?variant=' . urlencode($variant);
  240. }
  241. // 创建保存目录
  242. $saveDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'videos' . DS . date('Ymd');
  243. if (!is_dir($saveDir)) {
  244. mkdir($saveDir, 0755, true);
  245. }
  246. // 生成唯一文件名
  247. $filename = $responseData['id'] . '.mp4';
  248. $localPath = DS . 'uploads' . DS . 'videos' . DS . date('Ymd') . DS . $filename;
  249. $fullPath = $saveDir . DS . $filename;
  250. // 3. 下载视频
  251. $videoData = $this->downloadVideo($apiUrl, $apiKey);
  252. // 4. 保存视频文件
  253. if (file_put_contents($fullPath, $videoData) === false) {
  254. throw new Exception('视频保存失败');
  255. }
  256. // 确保路径使用正斜杠,并只保存相对路径部分
  257. $localPath = str_replace('\\', '/', $localPath);
  258. // 移除开头的斜杠,确保路径格式为uploads/videos/...
  259. $savePath = ltrim($localPath, '/');
  260. // 返回成功响应
  261. return json([
  262. 'code' => 0,
  263. 'msg' => '视频下载成功',
  264. 'data' => [
  265. 'video_id' => $responseData['id'],
  266. 'web_url' => $savePath
  267. ]
  268. ]);
  269. }
  270. /**
  271. * 学生端视频状态查询接口 - 用于通过video_id查询视频状态
  272. */
  273. public function Getvideo_id(){
  274. // 获取并验证参数
  275. $params = $this->request->param();
  276. $videoId = $params['video_id'] ?? '';
  277. // 验证video_id参数
  278. if (empty($videoId)) {
  279. return json([
  280. 'code' => 1,
  281. 'msg' => '缺少必要参数:video_id',
  282. 'data' => []
  283. ]);
  284. }
  285. $apiUrl = 'https://chatapi.onechats.ai/v1/videos/' . $videoId;
  286. $apiKey = 'sk-sWW1GFlnjbrDRb1DkMEzePIxgdvLK6cZt0Qg93yDMVP2z1yN';
  287. // 先检查本地是否已经有该视频
  288. $localVideoPath = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'videos' . DS . date('Ymd') . DS . $videoId . '.mp4';
  289. if (file_exists($localVideoPath)) {
  290. // 视频已存在本地,直接返回
  291. $webPath = '/uploads/videos/' . date('Ymd') . '/' . $videoId . '.mp4';
  292. return json([
  293. 'code' => 0,
  294. 'msg' => '视频下载成功',
  295. 'data' => [
  296. 'video_id' => $videoId,
  297. 'web_url' => substr($webPath, 1) // 移除开头的斜杠
  298. ]
  299. ]);
  300. }
  301. // 检查视频状态
  302. $statusData = $this->fetchVideoStatus($apiUrl, $apiKey);
  303. // 检查视频状态
  304. if ($statusData['status'] !== 'completed') {
  305. return json([
  306. 'code' => 202,
  307. 'msg' => '视频尚未生成完成',
  308. 'data' => [
  309. 'video_id' => $videoId,
  310. 'status' => $statusData['status'],
  311. 'progress' => isset($statusData['progress']) ? $statusData['progress'] : 0,
  312. 'created_at' => $statusData['created_at'],
  313. 'message' => '请稍后再试,视频仍在' . ($statusData['status'] === 'queued' ? '排队中' : '处理中')
  314. ]
  315. ]);
  316. }
  317. // 视频生成完成,下载视频
  318. $downloadUrl = 'https://chatapi.onechats.ai/v1/videos/' . $videoId . '/content';
  319. // 获取可选的variant参数
  320. $variant = $this->request->get('variant', '');
  321. if (!empty($variant)) {
  322. $downloadUrl .= '?variant=' . urlencode($variant);
  323. }
  324. // 创建保存目录
  325. $saveDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'videos' . DS . date('Ymd');
  326. if (!is_dir($saveDir)) {
  327. mkdir($saveDir, 0755, true);
  328. }
  329. // 生成唯一文件名
  330. $filename = $videoId . '.mp4';
  331. $localPath = DS . 'uploads' . DS . 'videos' . DS . date('Ymd') . DS . $filename;
  332. $fullPath = $saveDir . DS . $filename;
  333. // 下载视频
  334. $videoData = $this->downloadVideo($downloadUrl, $apiKey);
  335. // 保存视频文件
  336. if (file_put_contents($fullPath, $videoData) === false) {
  337. throw new Exception('视频保存失败');
  338. }
  339. // 确保路径使用正斜杠,并只保存相对路径部分
  340. $localPath = str_replace(DIRECTORY_SEPARATOR, '/', $localPath);
  341. // 移除开头的斜杠,确保路径格式为uploads/videos/...
  342. $savePath = ltrim($localPath, '/');
  343. // 返回成功响应
  344. return json([
  345. 'code' => 0,
  346. 'msg' => '视频下载成功',
  347. 'data' => [
  348. 'video_id' => $videoId,
  349. 'web_url' => $savePath
  350. ]
  351. ]);
  352. }
  353. //获取服务器URL IP地址:端口
  354. public function GetHttpUrl(){
  355. $data = Db::name('http_url')->find();
  356. $fullUrl = "http://" . $data['baseUrl'] . ":" . $data['port'];
  357. $res = [
  358. 'code' => 0,
  359. 'msg' => '成功',
  360. 'data' => [
  361. 'full_url' => $fullUrl,
  362. 'id' => $data['id'],
  363. 'baseUrl' => $data['baseUrl'],
  364. 'port' => $data['port']
  365. ]
  366. ];
  367. return json($res);
  368. }
  369. //获取视频列表
  370. public function Getvideolist(){
  371. if (!$this->request->isGet()) {
  372. $this->error('请求方式错误');
  373. }
  374. $params = $this->request->param();
  375. $search = input('search', '');
  376. $page = isset($params['page']) ? (int)$params['page'] : 1;
  377. $limit = isset($params['limit']) ? (int)$params['limit'] : 50;
  378. $where = [];
  379. if (!empty($search)) {
  380. $where['prompt'] = ['like', '%' . $search . '%'];
  381. }
  382. $list = Db::name('video')->where('mod_rq', null)
  383. ->where($where)
  384. ->order('id desc')
  385. ->limit(($page - 1) * $limit, $limit)
  386. ->select();
  387. $total = Db::name('video')->where('mod_rq', null)
  388. ->where($where)
  389. ->count();
  390. $res['code'] = 0;
  391. $res['msg'] = '成功';
  392. $res['count'] = $total;
  393. $res['data'] = $list;
  394. return json($res);
  395. }
  396. /**
  397. * 文生视频/图生视频接口
  398. * @return \think\response\Json
  399. * @throws \Exception
  400. */
  401. //文生视频
  402. public function video(){
  403. $params = $this->request->param();
  404. $apiUrl = 'https://chatapi.onechats.ai/v1/videos';
  405. $apiKey = 'sk-sWW1GFlnjbrDRb1DkMEzePIxgdvLK6cZt0Qg93yDMVP2z1yN';
  406. $postData = [
  407. 'prompt' => $params['prompt'],
  408. 'model' => $params['model'],
  409. 'seconds' => $params['seconds'],
  410. 'size' => $params['size'],
  411. ];
  412. // 初始化CURL
  413. $ch = curl_init();
  414. curl_setopt($ch, CURLOPT_URL, $apiUrl);
  415. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  416. curl_setopt($ch, CURLOPT_POST, true);
  417. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  418. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  419. 'Authorization: Bearer ' . $apiKey
  420. ]);
  421. curl_setopt($ch, CURLOPT_TIMEOUT, 300);
  422. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  423. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  424. curl_setopt($ch, CURLOPT_HEADER, true); // 获取响应头
  425. curl_setopt($ch, CURLOPT_VERBOSE, true); // 启用详细输出以进行调试
  426. // 创建临时文件来捕获详细的cURL输出
  427. $verbose = fopen('php://temp', 'w+');
  428. curl_setopt($ch, CURLOPT_STDERR, $verbose);
  429. // 执行请求
  430. $response = curl_exec($ch);
  431. //HTTP状态码
  432. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  433. // 获取详细的cURL调试信息
  434. rewind($verbose);
  435. //CURL调试信息
  436. $verboseLog = stream_get_contents($verbose);
  437. fclose($verbose);
  438. // 分离头部和主体
  439. $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  440. //响应头部
  441. $header = substr($response, 0, $header_size);
  442. //响应主体
  443. $body = substr($response, $header_size);
  444. // 检查CURL错误
  445. $curlError = curl_error($ch);
  446. curl_close($ch);
  447. $responseData = json_decode($body, true);
  448. // 检查API是否返回了错误信息
  449. if (isset($responseData['error'])) {
  450. $errorMessage = isset($responseData['error']['message']) ? $responseData['error']['message'] : 'API请求失败';
  451. return json([
  452. 'code' => 1,
  453. 'msg' => '视频生成请求失败',
  454. 'data' => [
  455. 'error_type' => isset($responseData['error']['type']) ? $responseData['error']['type'] : 'unknown',
  456. 'error_code' => isset($responseData['error']['code']) ? $responseData['error']['code'] : 'unknown',
  457. 'error_message' => $errorMessage
  458. ]
  459. ]);
  460. }
  461. // 检查是否有自定义错误格式
  462. if (isset($responseData['code']) && $responseData['code'] === 'fail_to_fetch_task' && isset($responseData['message'])) {
  463. return json([
  464. 'code' => 1,
  465. 'msg' => '视频生成请求失败',
  466. 'data' => [
  467. 'error_code' => $responseData['code'],
  468. 'error_message' => $responseData['message']
  469. ]
  470. ]);
  471. }
  472. // 检查是否存在id字段
  473. if (!isset($responseData['id'])) {
  474. return json([
  475. 'code' => 1,
  476. 'msg' => '无法获取视频ID',
  477. 'data' => [
  478. 'response_data' => $responseData,
  479. 'http_code' => $httpCode
  480. ]
  481. ]);
  482. }
  483. $videoData = [
  484. 'video_id' => $responseData['id'],
  485. 'prompt' => $postData['prompt'],
  486. 'model' => $postData['model'],
  487. 'seconds' => $postData['seconds'],
  488. 'size' => $postData['size'],
  489. 'sys_rq' => date("Y-m-d H:i:s")
  490. ];
  491. // 尝试插入数据
  492. try {
  493. $res = Db::name('video')->insert($videoData);
  494. return json([
  495. 'code' => 0,
  496. 'msg' => '视频正在生成中',
  497. 'data ' => [
  498. 'video_id' => $responseData['id'],
  499. 'insert_result' => $res
  500. ]
  501. ]);
  502. } catch (Exception $e) {
  503. return json([
  504. 'code' => 1,
  505. 'msg' => '数据库操作失败',
  506. 'data' => [
  507. 'error_message' => $e->getMessage()
  508. ]
  509. ]);
  510. }
  511. }
  512. /**
  513. * 获取视频内容
  514. * 下载已完成的视频内容
  515. */
  516. public function videoContent(){
  517. // 从请求参数获取video_id,如果没有则使用默认值
  518. $video_id = input('get.video_id');
  519. $apiKey = 'sk-sWW1GFlnjbrDRb1DkMEzePIxgdvLK6cZt0Qg93yDMVP2z1yN';
  520. // 1. 先检查视频状态
  521. $statusUrl = 'https://chatapi.onechats.ai/v1/videos/' . $video_id;
  522. $statusData = $this->fetchVideoStatus($statusUrl, $apiKey);
  523. // 检查视频状态
  524. if ($statusData['status'] !== 'completed') {
  525. return json([
  526. 'code' => 202,
  527. 'msg' => '视频尚未生成完成',
  528. 'data' => [
  529. 'video_id' => $video_id,
  530. 'status' => $statusData['status'],
  531. 'progress' => $statusData['progress'],
  532. 'created_at' => $statusData['created_at'],
  533. 'message' => '请稍后再试,视频仍在' . ($statusData['status'] === 'queued' ? '排队中' : '处理中')
  534. ]
  535. ]);
  536. }
  537. // 2. 视频生成完成,准备下载
  538. $apiUrl = 'https://chatapi.onechats.ai/v1/videos/' . $video_id . '/content';
  539. // 获取可选的variant参数
  540. $variant = $this->request->get('variant', '');
  541. if (!empty($variant)) {
  542. $apiUrl .= '?variant=' . urlencode($variant);
  543. }
  544. // 创建保存目录
  545. $saveDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'videos' . DS . date('Ymd');
  546. if (!is_dir($saveDir)) {
  547. mkdir($saveDir, 0755, true);
  548. }
  549. // 生成唯一文件名
  550. $filename = $video_id . '.mp4';
  551. $localPath = DS . 'uploads' . DS . 'videos' . DS . date('Ymd') . DS . $filename;
  552. $fullPath = $saveDir . DS . $filename;
  553. // 3. 下载视频
  554. $videoData = $this->downloadVideo($apiUrl, $apiKey);
  555. // 4. 保存视频文件
  556. if (file_put_contents($fullPath, $videoData) === false) {
  557. throw new Exception('视频保存失败');
  558. }
  559. // 确保路径使用正斜杠,并只保存相对路径部分
  560. $localPath = str_replace('\\', '/', $localPath);
  561. // 移除开头的斜杠,确保路径格式为uploads/videos/...
  562. $savePath = ltrim($localPath, '/');
  563. // 将正确格式的文件路径存入数据库
  564. Db::name('video')->where('video_id', $video_id)->update([
  565. 'web_url' => $savePath
  566. ]);
  567. // 返回成功响应
  568. return json([
  569. 'code' => 0,
  570. 'msg' => '视频下载成功',
  571. 'data' => [
  572. 'video_id' => $video_id,
  573. 'local_path' => $localPath,
  574. 'web_url' => $savePath,
  575. 'file_size' => filesize($fullPath)
  576. ]
  577. ]);
  578. }
  579. /**
  580. * 获取视频状态
  581. */
  582. private function fetchVideoStatus($url, $apiKey) {
  583. $ch = curl_init();
  584. curl_setopt($ch, CURLOPT_URL, $url);
  585. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  586. curl_setopt($ch, CURLOPT_HTTPGET, true);
  587. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  588. 'Authorization: Bearer ' . $apiKey,
  589. 'Accept: application/json'
  590. ]);
  591. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  592. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  593. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  594. $response = curl_exec($ch);
  595. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  596. $error = curl_error($ch);
  597. curl_close($ch);
  598. if ($error) {
  599. throw new Exception('获取视频状态失败: ' . $error);
  600. }
  601. if ($httpCode < 200 || $httpCode >= 300) {
  602. throw new Exception('获取视频状态失败,HTTP状态码: ' . $httpCode);
  603. }
  604. $data = json_decode($response, true);
  605. if (!is_array($data)) {
  606. throw new Exception('视频状态数据格式错误');
  607. }
  608. return $data;
  609. }
  610. /**
  611. * 下载视频文件
  612. */
  613. private function downloadVideo($url, $apiKey) {
  614. $ch = curl_init();
  615. curl_setopt($ch, CURLOPT_URL, $url);
  616. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  617. curl_setopt($ch, CURLOPT_HTTPGET, true);
  618. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  619. 'Authorization: Bearer ' . $apiKey
  620. ]);
  621. curl_setopt($ch, CURLOPT_TIMEOUT, 300);
  622. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  623. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  624. $response = curl_exec($ch);
  625. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  626. $error = curl_error($ch);
  627. curl_close($ch);
  628. if ($error) {
  629. throw new Exception('视频下载失败: ' . $error);
  630. }
  631. if ($httpCode < 200 || $httpCode >= 300) {
  632. throw new Exception('视频下载失败,HTTP状态码: ' . $httpCode);
  633. }
  634. return $response;
  635. }
  636. private function sendPostRequest($url, $data, $apiKey)
  637. {
  638. $ch = curl_init();
  639. curl_setopt($ch, CURLOPT_URL, $url);
  640. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  641. curl_setopt($ch, CURLOPT_POST, true);
  642. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  643. 'Authorization: Bearer ' . $apiKey,
  644. 'Accept: application/json',
  645. 'Content-Type: application/json'
  646. ]);
  647. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  648. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  649. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  650. curl_setopt($ch, CURLOPT_TIMEOUT, 60); // 延长超时时间
  651. $response = curl_exec($ch);
  652. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  653. $error = curl_error($ch);
  654. curl_close($ch);
  655. return [
  656. 'response' => $response,
  657. 'http_code' => $httpCode,
  658. 'error' => $error
  659. ];
  660. }
  661. /**
  662. * 文本生成图片并保存第一张结果
  663. * @param array $params 请求参数
  664. * @return array 返回结果
  665. */
  666. public function txttowimg()
  667. {
  668. // API配置
  669. $config = [
  670. 'api_url' => 'https://chatapi.onechats.ai/mj/submit/imagine',
  671. 'fetch_url' => 'https://chatapi.onechats.ai/mj/task/',
  672. 'api_key' => 'sk-iURfrAgzAjhZ4PpPLwzmWIAhM7zKfrkwDvyxk4RVBQ4ouJNK',
  673. 'default_prompt' => '一个猫',
  674. 'wait_time' => 3 // 等待生成完成的秒数
  675. ];
  676. try {
  677. // 1. 准备请求数据
  678. $prompt = $config['default_prompt'];
  679. $postData = [
  680. 'botType' => 'MID_JOURNEY',
  681. 'prompt' => $prompt,
  682. 'base64Array' => [],
  683. 'accountFilter' => [
  684. 'channelId' => "",
  685. 'instanceId' => "",
  686. 'modes' => [],
  687. 'remark' => "",
  688. 'remix' => true,
  689. 'remixAutoConsidered' => true
  690. ],
  691. 'notifyHook' => "",
  692. 'state' => ""
  693. ];
  694. // 2. 提交生成请求
  695. $generateResponse = $this->sendApiRequest($config['api_url'], $postData, $config['api_key']);
  696. $generateData = json_decode($generateResponse, true);
  697. if (empty($generateData['result'])) {
  698. throw new Exception('生成失败: '.($generateData['message'] ?? '未知错误'));
  699. }
  700. $taskId = $generateData['result'];
  701. // 3. 等待图片生成完成
  702. sleep($config['wait_time']);
  703. // 4. 获取生成结果
  704. $fetchUrl = $config['fetch_url'].$taskId.'/fetch';
  705. $fetchResponse = $this->sendApiRequest($fetchUrl, [], $config['api_key'], 'GET');
  706. $fetchData = json_decode($fetchResponse, true);
  707. if (empty($fetchData['imageUrl'])) {
  708. throw new Exception('获取图片失败: '.($fetchData['message'] ?? '未知错误'));
  709. }
  710. // 5. 处理返回的图片数组(取第一张)
  711. $imageUrls = is_array($fetchData['imageUrl']) ? $fetchData['imageUrl'] : [$fetchData['imageUrl']];
  712. $firstImageUrl = $imageUrls[0];
  713. // 6. 保存图片到本地
  714. $savePath = $this->saveImage($firstImageUrl);
  715. // 7. 返回结果
  716. return [
  717. 'code' => 200,
  718. 'msg' => '图片生成并保存成功',
  719. 'data' => [
  720. 'local_path' => $savePath,
  721. 'web_url' => request()->domain().$savePath,
  722. 'task_id' => $taskId
  723. ]
  724. ];
  725. } catch (Exception $e) {
  726. // 错误处理
  727. return [
  728. 'code' => 500,
  729. 'msg' => '处理失败: '.$e->getMessage(),
  730. 'data' => null
  731. ];
  732. }
  733. }
  734. /**
  735. * 发送API请求
  736. * @param string $url 请求地址
  737. * @param array $data 请求数据
  738. * @param string $apiKey API密钥
  739. * @param string $method 请求方法
  740. * @return string 响应内容
  741. * @throws Exception
  742. */
  743. private function sendApiRequest($url, $data, $apiKey, $method = 'POST')
  744. {
  745. $ch = curl_init();
  746. curl_setopt_array($ch, [
  747. CURLOPT_URL => $url,
  748. CURLOPT_RETURNTRANSFER => true,
  749. CURLOPT_CUSTOMREQUEST => $method,
  750. CURLOPT_HTTPHEADER => [
  751. 'Authorization: Bearer '.$apiKey,
  752. 'Accept: application/json',
  753. 'Content-Type: application/json'
  754. ],
  755. CURLOPT_POSTFIELDS => $method === 'POST' ? json_encode($data) : null,
  756. CURLOPT_SSL_VERIFYPEER => false,
  757. CURLOPT_SSL_VERIFYHOST => false,
  758. CURLOPT_TIMEOUT => 60,
  759. CURLOPT_FAILONERROR => true
  760. ]);
  761. $response = curl_exec($ch);
  762. $error = curl_error($ch);
  763. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  764. curl_close($ch);
  765. if ($error) {
  766. throw new Exception('API请求失败: '.$error);
  767. }
  768. if ($httpCode < 200 || $httpCode >= 300) {
  769. throw new Exception('API返回错误状态码: '.$httpCode);
  770. }
  771. return $response;
  772. }
  773. /**
  774. * 保存图片到本地
  775. * @param string $imageUrl 图片URL
  776. * @return string 本地保存路径
  777. * @throws Exception
  778. */
  779. private function saveImage($imageUrl)
  780. {
  781. // 1. 创建存储目录
  782. $saveDir = ROOT_PATH.'public'.DS.'uploads'.DS.'midjourney'.DS.date('Ymd');
  783. if (!is_dir($saveDir)) {
  784. mkdir($saveDir, 0755, true);
  785. }
  786. // 2. 生成唯一文件名
  787. $filename = uniqid().'.png';
  788. $localPath = DS.'uploads'.DS.'midjourney'.DS.date('Ymd').DS.$filename;
  789. $fullPath = $saveDir.DS.$filename;
  790. // 3. 下载图片
  791. $ch = curl_init($imageUrl);
  792. curl_setopt_array($ch, [
  793. CURLOPT_RETURNTRANSFER => true,
  794. CURLOPT_FOLLOWLOCATION => true,
  795. CURLOPT_SSL_VERIFYPEER => false,
  796. CURLOPT_CONNECTTIMEOUT => 15
  797. ]);
  798. $imageData = curl_exec($ch);
  799. $error = curl_error($ch);
  800. curl_close($ch);
  801. if (!$imageData) {
  802. throw new Exception('图片下载失败: '.$error);
  803. }
  804. // 4. 验证图片类型
  805. $imageInfo = getimagesizefromstring($imageData);
  806. if (!in_array($imageInfo['mime'] ?? '', ['image/png', 'image/jpeg'])) {
  807. throw new Exception('下载内容不是有效图片');
  808. }
  809. // 5. 保存文件
  810. if (!file_put_contents($fullPath, $imageData)) {
  811. throw new Exception('图片保存失败');
  812. }
  813. return $localPath;
  814. }
  815. /**
  816. * 查询队列列表
  817. * 统计文件对应的队列情况
  818. */
  819. public function get_queue_logs()
  820. {
  821. $params = $this->request->param('old_image_file', '');
  822. $queue_logs = Db::name('queue_logs')
  823. ->where('old_image_file', $params)
  824. ->order('id desc')
  825. ->select();
  826. $result = []; //初始化变量,避免未定义错误
  827. foreach ($queue_logs as &$log) {
  828. $taskId = $log['id'];
  829. $statusCount = Db::name('image_task_log')
  830. ->field('status, COUNT(*) as count')
  831. ->where('task_id', $taskId)
  832. ->where('mod_rq', null)
  833. ->group('status')
  834. ->select();
  835. $log['已完成数量'] = 0;
  836. $log['处理中数量'] = 0;
  837. $log['排队中的数量'] = 0;
  838. $log['失败数量'] = 0;
  839. foreach ($statusCount as $item) {
  840. switch ($item['status']) {
  841. case 0:
  842. $log['排队中的数量'] = $item['count'];
  843. break;
  844. case 1:
  845. $log['处理中数量'] = $item['count'];
  846. break;
  847. case 2:
  848. $log['已完成数量'] = $item['count'];
  849. break;
  850. case -1:
  851. $log['失败数量'] = $item['count'];
  852. break;
  853. }
  854. }
  855. // if ($log['排队中的数量'] >$log['已完成数量']) {
  856. // $result[] = $log;
  857. // }
  858. if ($log['排队中的数量']) {
  859. $result[] = $log;
  860. }
  861. // if ($log['处理中数量'] >= 0) {
  862. // $result[] = $log;
  863. // }
  864. }
  865. return json([
  866. 'code' => 0,
  867. 'msg' => '查询成功',
  868. 'data' => $result,
  869. 'count' => count($result)
  870. ]);
  871. }
  872. /**
  873. * 查询总队列状态(统计当前处理的数据量)
  874. */
  875. public function queueStats()
  876. {
  877. $statusList = Db::name('image_task_log')
  878. ->field('status, COUNT(*) as total')
  879. ->where('mod_rq', null)
  880. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  881. ->group('status')
  882. ->select();
  883. $statusCount = [];
  884. foreach ($statusList as $item) {
  885. $statusCount[$item['status']] = $item['total'];
  886. }
  887. // 总数为所有状态和
  888. $total = array_sum($statusCount);
  889. //获取队列当前状态
  890. $statusText = Db::name('queue_logs')->order('id desc')->value('status');
  891. return json([
  892. 'code' => 0,
  893. 'msg' => '获取成功',
  894. 'data' => [
  895. '总任务数' => $total,
  896. '待处理' => $statusCount[0] ?? 0,
  897. '处理中' => $statusCount[1] ?? 0,
  898. '成功' => $statusCount[2] ?? 0,
  899. '失败' => $statusCount[-1] ?? 0,
  900. '当前状态' => $statusText
  901. ]
  902. ]);
  903. }
  904. /**
  905. * 显示当前运行中的队列监听进程
  906. */
  907. public function viewQueueStatus()
  908. {
  909. $redis = new \Redis();
  910. $redis->connect('127.0.0.1', 6379);
  911. $redis->auth('123456');
  912. $redis->select(15);
  913. $key = 'queues:imgtotxt';
  914. // 判断 key 是否存在,避免报错
  915. if (!$redis->exists($key)) {
  916. return json([
  917. 'code' => 0,
  918. 'msg' => '查询成功,队列为空',
  919. 'count' => 0,
  920. 'tasks_preview' => []
  921. ]);
  922. }
  923. $count = $redis->lLen($key);
  924. $list = $redis->lRange($key, 0, 9);
  925. // 解码 JSON 内容,确保每一项都有效
  926. $parsed = array_filter(array_map(function ($item) {
  927. return json_decode($item, true);
  928. }, $list), function ($item) {
  929. return !is_null($item);
  930. });
  931. return json([
  932. 'code' => 0,
  933. 'msg' => '查询成功',
  934. 'count' => $count,
  935. 'tasks_preview' => $parsed
  936. ]);
  937. }
  938. /**
  939. * 清空队列并删除队列日志记录
  940. */
  941. public function stopQueueProcesses()
  942. {
  943. Db::name('image_task_log')
  944. ->where('log', '队列中')
  945. ->whereOr('status', 1)
  946. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  947. ->update([
  948. 'status' => "-1",
  949. 'log' => '清空取消队列',
  950. 'mod_rq' => date('Y-m-d H:i:s')
  951. ]);
  952. Db::name('image_task_log')
  953. ->whereLike('log', '%处理中%')
  954. ->where('create_time', '>=', date('Y-m-d 00:00:00'))
  955. ->update([
  956. 'status' => "-1",
  957. 'log' => '清空取消队列',
  958. 'mod_rq' => date('Y-m-d H:i:s')
  959. ]);
  960. $redis = new \Redis();
  961. $redis->connect('127.0.0.1', 6379);
  962. $redis->auth('123456');
  963. $redis->select(15);
  964. $key_txttoimg = 'queues:txttoimg:reserved';
  965. $key_txttotxt = 'queues:txttotxt:reserved';
  966. $key_imgtotxt = 'queues:imgtotxt:reserved';
  967. $key_imgtoimg = 'queues:imgtoimg:reserved';
  968. // 清空 Redis 队列
  969. $redis->del($key_txttoimg);
  970. $redis->del($key_txttotxt);
  971. $redis->del($key_imgtotxt);
  972. $redis->del($key_imgtoimg);
  973. $count = $redis->lLen($key_txttoimg) + $redis->lLen($key_txttotxt) + $redis->lLen($key_imgtotxt) + $redis->lLen($key_imgtoimg);
  974. // if ($count === 0) {
  975. // return json([
  976. // 'code' => 1,
  977. // 'msg' => '暂无队列需要停止'
  978. // ]);
  979. // }
  980. return json([
  981. 'code' => 0,
  982. 'msg' => '成功停止队列任务'
  983. ]);
  984. }
  985. /**
  986. * 开启队列任务
  987. * 暂时用不到、服务器已开启自动开启队列模式
  988. */
  989. // public function kaiStats()
  990. // {
  991. // // 判断是否已有监听进程在运行
  992. // $check = shell_exec("ps aux | grep 'queue:listen' | grep -v grep");
  993. // if ($check) {
  994. // return json([
  995. // 'code' => 1,
  996. // 'msg' => '监听进程已存在,请勿重复启动'
  997. // ]);
  998. // }
  999. // // 启动监听
  1000. // $command = 'nohup php think queue:listen --queue --timeout=300 --sleep=3 --memory=256 > /var/log/job_queue.log 2>&1 &';
  1001. // exec($command, $output, $status);
  1002. // if ($status === 0) {
  1003. // return json([
  1004. // 'code' => 0,
  1005. // 'msg' => '队列监听已启动'
  1006. // ]);
  1007. // } else {
  1008. // return json([
  1009. // 'code' => 1,
  1010. // 'msg' => '队列启动失败',
  1011. // 'output' => $output
  1012. // ]);
  1013. // }
  1014. // }
  1015. /**
  1016. * 通过店铺ID-查询对应店铺表数据
  1017. *
  1018. */
  1019. public function PatternApi()
  1020. {
  1021. $params = $this->request->param('pattern_id', '');
  1022. $tableName = 'pattern-' . $params;
  1023. // 连接 MongoDB
  1024. $mongo = Db::connect('mongodb');
  1025. // 查询指定 skc 的数据
  1026. $data = $mongo->table($tableName)
  1027. ->field('
  1028. name,
  1029. skc,
  1030. file
  1031. ')
  1032. ->where("skc", '0853004152036')
  1033. ->select();
  1034. $data = json_decode(json_encode($data), true); // 数组
  1035. return json([
  1036. 'code' => 0,
  1037. 'msg' => '获取成功',
  1038. 'data' => $data
  1039. ]);
  1040. }
  1041. /**
  1042. * 新增产品模版
  1043. */
  1044. public function Add_Product_Template(){
  1045. try {
  1046. // 获取请求参数
  1047. $params = $this->request->param();
  1048. $chinese_description = $params['chinese_description'] ?? '';
  1049. $template_image_url = $params['template_image_url'] ?? '';
  1050. $template_name = $params['template_name'] ?? '';
  1051. $size = $params['size'] ?? '';
  1052. $style = $params['style'] ?? '';
  1053. $type = $params['type'] ?? '';
  1054. $user_id = $params['user_id'] ?? '';
  1055. $seconds = $params['seconds'] ?? '';
  1056. $video_id = $params['video_id'] ?? '';
  1057. if (empty($template_name)) {
  1058. return json(['code' => 1, 'msg' => '模板名称不能为空']);
  1059. }
  1060. $data = [
  1061. 'toexamine' => "未审核",
  1062. 'chinese_description' => $chinese_description,
  1063. 'template_image_url' => $template_image_url,
  1064. 'template_name' => $template_name,
  1065. 'type' => $type,
  1066. 'style' => $style,
  1067. 'seconds' => $seconds,
  1068. 'size' => $size,
  1069. 'video_id' => $video_id,
  1070. 'user_id' => $user_id,
  1071. 'sys_rq' => date('Y-m-d'),
  1072. 'create_time' => date('Y-m-d H:i:s')
  1073. ];
  1074. // echo "<pre>";
  1075. // print_r($data);
  1076. // echo "<pre>";die;
  1077. // 记录插入的数据用于调试
  1078. // Log::record('准备插入模板数据: ' . json_encode($data), 'info');
  1079. $result = Db::name('product_template')->insert($data);
  1080. if ($result) {
  1081. // Log::record('模板保存成功,插入数据: ' . json_encode($data), 'info');
  1082. return json(['code' => 0, 'msg' => '模板保存成功']);
  1083. } else {
  1084. // Log::record('模板保存失败,插入数据: ' . json_encode($data) . ',受影响行数: ' . $result, 'error');
  1085. return json(['code' => 1, 'msg' => '模板保存失败: 数据库操作未影响任何行']);
  1086. }
  1087. } catch (\Exception $e) {
  1088. // 捕获并记录异常信息
  1089. Log::record('模板保存异常: ' . $e->getMessage(), 'error');
  1090. Log::record('异常堆栈: ' . $e->getTraceAsString(), 'error');
  1091. return json(['code' => 1, 'msg' => '模板保存失败: ' . $e->getMessage()]);
  1092. }
  1093. }
  1094. /**
  1095. * 新查询产品模版
  1096. */
  1097. public function product_template()
  1098. {
  1099. $params = $this->request->param();
  1100. // 构建查询条件
  1101. $where = [];
  1102. if (!empty($params['search'])) {
  1103. $where['chinese_description'] = ['like', '%' . $params['search'] . '%'];
  1104. }
  1105. // 查询模版表
  1106. $products = Db::name('product_template')->order('id desc')->where($where)->select();
  1107. $http_url = Db::name('http_url')->field('baseUrl,port')->find();
  1108. if ($products && $http_url) {
  1109. $base_url = !empty($http_url['baseUrl']) && !empty($http_url['port'])
  1110. ? 'http://' . $http_url['baseUrl'] . ':' . $http_url['port'] : '';
  1111. if ($base_url) {
  1112. foreach ($products as &$val) {
  1113. $val['template_image_url'] = $base_url . $val['template_image_url'];
  1114. }
  1115. }
  1116. }
  1117. return json([
  1118. 'code' => 0,
  1119. 'msg' => '请求成功',
  1120. 'data' => $products
  1121. ]);
  1122. }
  1123. }