Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
ffddce78
Commit
ffddce78
authored
May 19, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3D试戴优化
parent
7e2d1ee4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
40 deletions
+52
-40
AiTryon.php
addons/shopro/controller/user/AiTryon.php
+8
-4
AiVideoGen.php
addons/shopro/job/AiVideoGen.php
+8
-36
Ai.php
addons/shopro/service/user/Ai.php
+36
-0
No files found.
addons/shopro/controller/user/AiTryon.php
View file @
ffddce78
...
@@ -170,7 +170,7 @@ class AiTryon extends Common
...
@@ -170,7 +170,7 @@ class AiTryon extends Common
// $attachment = $upload->uploadBase64($res['data']);
// $attachment = $upload->uploadBase64($res['data']);
// 记录入参日志
// 记录入参日志
custom_log
(
'
用户ID:'
.
$user
->
id
.
' AI生成图片
保存到本地接口接口出参:'
.
json_encode
(
$attachment
),
'gen_ai'
);
custom_log
(
'
[AI生成图片接口] user_id:'
.
$user
->
id
.
'
保存到本地接口接口出参:'
.
json_encode
(
$attachment
),
'gen_ai'
);
if
(
$attachment
==
0
){
if
(
$attachment
==
0
){
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_status'
]
=
2
;
...
@@ -181,12 +181,16 @@ class AiTryon extends Common
...
@@ -181,12 +181,16 @@ class AiTryon extends Common
$tryonData
[
'ai_status'
]
=
1
;
$tryonData
[
'ai_status'
]
=
1
;
$tryonData
[
'ai_url'
]
=
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
];
$tryonData
[
'ai_url'
]
=
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
];
$
tryonModel
->
save
(
$tryonData
);
$
id
=
$tryonModel
->
insertGetId
(
$tryonData
);
// 试戴次数+1
// 试戴次数+1
$userService
=
new
User
();
$userService
=
new
User
();
$userService
->
addTryTimes
(
$user
->
id
);
$userService
->
addTryTimes
(
$user
->
id
);
// 发送消息通知
$aiService
=
new
Ai
();
$aiService
->
sendNotification
(
$user
->
id
,
$id
);
$this
->
success
(
'图片生成成功'
,
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
]
??
''
);
$this
->
success
(
'图片生成成功'
,
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
]
??
''
);
}
}
...
@@ -239,7 +243,7 @@ class AiTryon extends Common
...
@@ -239,7 +243,7 @@ class AiTryon extends Common
}
}
//开发过程中临时调试代码
//开发过程中临时调试代码
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260518151431-zcrgp', 'user' => $user], 'shopro-high');
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260518151431-zcrgp', 'user' => $user
, 'id'=> 214
], 'shopro-high');
// $this->success('推送队列成功');
// $this->success('推送队列成功');
// exit;
// exit;
// $this->success('视频生成中', 13);
// $this->success('视频生成中', 13);
...
@@ -294,7 +298,7 @@ class AiTryon extends Common
...
@@ -294,7 +298,7 @@ class AiTryon extends Common
$userService
->
addTryTimes
(
$user
->
id
);
$userService
->
addTryTimes
(
$user
->
id
);
// 推送队列
// 推送队列
\think\Queue
::
push
(
'\addons\shopro\job\AiVideoGen@save'
,
[
'taskid'
=>
$res
[
'data'
],
'user'
=>
$user
],
'shopro-high'
);
\think\Queue
::
push
(
'\addons\shopro\job\AiVideoGen@save'
,
[
'taskid'
=>
$res
[
'data'
],
'user'
=>
$user
,
'id'
=>
$id
],
'shopro-high'
);
$this
->
success
(
$res
[
'msg'
],
$id
);
$this
->
success
(
$res
[
'msg'
],
$id
);
...
...
addons/shopro/job/AiVideoGen.php
View file @
ffddce78
...
@@ -130,6 +130,7 @@ class AiVideoGen extends BaseJob
...
@@ -130,6 +130,7 @@ class AiVideoGen extends BaseJob
try
{
try
{
$taskid
=
$data
[
'taskid'
];
$taskid
=
$data
[
'taskid'
];
$id
=
$data
[
'id'
];
$user
=
$data
[
'user'
];
$user
=
$data
[
'user'
];
$user_id
=
isset
(
$user
[
'id'
])
?
$user
[
'id'
]
:
0
;
$user_id
=
isset
(
$user
[
'id'
])
?
$user
[
'id'
]
:
0
;
$this
->
debug_log
(
'***************************** '
.
date
(
'Y-m-d H:i:s'
)
.
'保存AI视频脚本开始 userid '
.
$user_id
.
' taskid:'
.
$taskid
.
' ***********************************'
.
PHP_EOL
);
$this
->
debug_log
(
'***************************** '
.
date
(
'Y-m-d H:i:s'
)
.
'保存AI视频脚本开始 userid '
.
$user_id
.
' taskid:'
.
$taskid
.
' ***********************************'
.
PHP_EOL
);
...
@@ -177,7 +178,10 @@ class AiVideoGen extends BaseJob
...
@@ -177,7 +178,10 @@ class AiVideoGen extends BaseJob
// AI接口 返回失败
// AI接口 返回失败
if
(
isset
(
$result
[
'error'
])){
if
(
isset
(
$result
[
'error'
])){
$message
=
$result
[
'error'
][
'message'
]
??
'未知错误'
;
$message
=
$result
[
'error'
][
'message'
]
??
'未知错误'
;
AiTryOnModel
::
where
(
'user_id'
,
$user_id
)
->
where
(
'ai_task_id'
,
$taskid
)
->
update
([
'ai_status'
=>
2
,
'ai_err_msg'
=>
$message
]);
AiTryOnModel
::
where
(
'user_id'
,
$user_id
)
->
where
(
'ai_task_id'
,
$taskid
)
->
where
(
'id'
,
$id
)
->
update
([
'ai_status'
=>
2
,
'ai_err_msg'
=>
$message
]);
// 删除队列job
// 删除队列job
$this
->
debug_log
(
'[AI视频异步队列]删除Job'
);
$this
->
debug_log
(
'[AI视频异步队列]删除Job'
);
...
@@ -195,6 +199,7 @@ class AiVideoGen extends BaseJob
...
@@ -195,6 +199,7 @@ class AiVideoGen extends BaseJob
$video_url
=
$aiService
->
saveFileLoc
(
isset
(
$result
[
'content'
][
'video_url'
])
?
$result
[
'content'
][
'video_url'
]
:
''
,
'gen_ai'
);
$video_url
=
$aiService
->
saveFileLoc
(
isset
(
$result
[
'content'
][
'video_url'
])
?
$result
[
'content'
][
'video_url'
]
:
''
,
'gen_ai'
);
// $video_url = $this->saveVideoLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : '');
// $video_url = $this->saveVideoLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : '');
$this
->
debug_log
(
'[AI视频异步队列]保存本地接口返回值 video_url:'
.
$video_url
);
$this
->
debug_log
(
'[AI视频异步队列]保存本地接口返回值 video_url:'
.
$video_url
);
if
(
$video_url
===
0
){
if
(
$video_url
===
0
){
...
@@ -207,7 +212,8 @@ class AiVideoGen extends BaseJob
...
@@ -207,7 +212,8 @@ class AiVideoGen extends BaseJob
$this
->
debug_log
(
'[AI视频异步队列]保存本地视频成功 sql: '
.
db
()
->
getLastSql
());
$this
->
debug_log
(
'[AI视频异步队列]保存本地视频成功 sql: '
.
db
()
->
getLastSql
());
// 发送消息通知
// 发送消息通知
$this
->
sendNotification
(
$user_id
,
$taskid
);
$aiService
=
new
Ai
();
$aiService
->
sendNotification
(
$user_id
,
$id
);
// 删除队列job
// 删除队列job
$this
->
debug_log
(
'[AI视频异步队列]删除Job'
);
$this
->
debug_log
(
'[AI视频异步队列]删除Job'
);
...
@@ -278,37 +284,4 @@ class AiVideoGen extends BaseJob
...
@@ -278,37 +284,4 @@ class AiVideoGen extends BaseJob
}
}
}
}
/**
* 发送AI视频生成成功通知
*/
private
function
sendNotification
(
$user_id
,
$taskid
)
{
try
{
// 获取用户信息
$user
=
User
::
find
(
$user_id
);
if
(
!
$user
)
{
$this
->
debug_log
(
'[AI视频异步队列][通知]用户不存在: '
.
$user_id
);
return
false
;
}
// 获取AI试戴记录
$aiTryon
=
AiTryOnModel
::
where
(
'user_id'
,
$user_id
)
->
where
(
'ai_task_id'
,
$taskid
)
->
find
();
// 发送通知
$user
&&
$user
->
notify
(
new
AiVideoSuccess
([
'ai_tryon'
=>
$aiTryon
?
$aiTryon
->
toArray
()
:
[],
'user'
=>
$aiTryon
?
$user
->
toArray
()
:
[]
])
);
$this
->
debug_log
(
'[AI视频异步队列][通知]通知发送成功: user_id='
.
$user_id
.
' taskid='
.
$taskid
);
return
true
;
}
catch
(
\Exception
$e
)
{
format_log_error_custom_name
(
$e
,
'[AI视频异步队列][通知]通知发送失败: user_id='
.
$user_id
.
' taskid='
.
$taskid
,
''
,
'gen_ai'
);
}
}
}
}
\ No newline at end of file
addons/shopro/service/user/Ai.php
View file @
ffddce78
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
namespace
addons\shopro\service\user
;
namespace
addons\shopro\service\user
;
use
addons\shopro\library\HttpClient
as
Http
;
use
addons\shopro\library\HttpClient
as
Http
;
use
addons\shopro\notification\ai\AiVideoSuccess
;
use
app\admin\model\shopro\AiTryon
as
AiTryOnModel
;
use
app\admin\model\shopro\user\User
;
use
think\Config
;
use
think\Config
;
use
think\Log
;
use
think\Log
;
...
@@ -18,6 +21,39 @@ class Ai
...
@@ -18,6 +21,39 @@ class Ai
}
}
/**
/**
* 发送AI生成成功通知
*/
public
function
sendNotification
(
$user_id
,
$id
)
{
try
{
// 获取用户信息
$user
=
User
::
find
(
$user_id
);
if
(
!
$user
)
{
custom_log
(
'[AI][通知]用户不存在: '
.
$user_id
,
'gen_ai'
);
return
false
;
}
// 获取AI试戴记录
$aiTryon
=
AiTryOnModel
::
where
(
'user_id'
,
$user_id
)
->
where
(
'id'
,
$id
)
->
find
();
// 发送通知
$user
&&
$user
->
notify
(
new
AiVideoSuccess
([
'ai_tryon'
=>
$aiTryon
?
$aiTryon
->
toArray
()
:
[],
'user'
=>
$aiTryon
?
$user
->
toArray
()
:
[]
])
);
custom_log
(
'[AI][通知]通知发送成功: user_id='
.
$user_id
.
' id='
.
$id
,
'gen_ai'
);
return
true
;
}
catch
(
\Exception
$e
)
{
format_log_error_custom_name
(
$e
,
'[AI][通知]通知发送失败: user_id='
.
$user_id
.
' id='
.
$id
,
''
,
'gen_ai'
);
}
}
/**
* 保存远端文件到本地
* 保存远端文件到本地
* 主要用于3D试戴 2026.05.19
* 主要用于3D试戴 2026.05.19
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment