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
86180074
Commit
86180074
authored
May 15, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3D试戴接口日志记录优化;试戴增加扣积分逻辑;生成视频异步消息通知代码初始化;
parent
4cd73cd9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
148 additions
and
14 deletions
+148
-14
AiTryon.php
addons/shopro/controller/user/AiTryon.php
+16
-4
AiVideoGen.php
addons/shopro/job/AiVideoGen.php
+3
-6
AiVideoSuccess.php
addons/shopro/notification/AiVideoSuccess.php
+106
-0
Ai.php
addons/shopro/service/user/Ai.php
+4
-4
User.php
addons/shopro/service/user/User.php
+19
-0
No files found.
addons/shopro/controller/user/AiTryon.php
View file @
86180074
...
@@ -120,11 +120,18 @@ class AiTryon extends Common
...
@@ -120,11 +120,18 @@ class AiTryon extends Common
}
}
$user
=
auth_user
();
$user
=
auth_user
();
// 试戴一次扣5积分
$userService
=
new
User
();
$userService
=
new
User
();
$res
=
$userService
->
isTry
(
$user
->
id
);
$res
=
$userService
->
deductPoints
(
$user
->
id
,
5
);
if
(
$res
===
0
)
{
$this
->
error
(
'积分不足 无法试戴'
);
}
$userService
=
new
User
();
$res
=
$userService
->
isTry
(
$user
->
id
);
if
(
$res
===
0
)
{
if
(
$res
===
0
)
{
$this
->
success
(
'今日
免费
试戴次数已用完'
,
0
);
$this
->
success
(
'今日试戴次数已用完'
,
0
);
}
else
{
}
else
{
// //开发时候先这样处理,AI图片生成次数有限
// //开发时候先这样处理,AI图片生成次数有限
...
@@ -226,6 +233,12 @@ class AiTryon extends Common
...
@@ -226,6 +233,12 @@ class AiTryon extends Common
$user
=
auth_user
();
$user
=
auth_user
();
// 试戴一次扣5积分
$userService
=
new
User
();
$res
=
$userService
->
deductPoints
(
$user
->
id
,
5
);
if
(
$res
===
0
)
{
$this
->
error
(
'积分不足 无法试戴'
);
}
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260506113558-x6wtq', 'user' => $user], 'shopro-high');
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260506113558-x6wtq', 'user' => $user], 'shopro-high');
// $this->success('推送队列成功');
// $this->success('推送队列成功');
...
@@ -233,9 +246,8 @@ class AiTryon extends Common
...
@@ -233,9 +246,8 @@ class AiTryon extends Common
$userService
=
new
User
();
$userService
=
new
User
();
$res
=
$userService
->
isTry
(
$user
->
id
);
$res
=
$userService
->
isTry
(
$user
->
id
);
if
(
$res
===
0
)
{
if
(
$res
===
0
)
{
$this
->
success
(
'今日
免费
试戴次数已用完'
,
0
);
$this
->
success
(
'今日试戴次数已用完'
,
0
);
}
else
{
}
else
{
// 开发过程中临时代码
// 开发过程中临时代码
...
...
addons/shopro/job/AiVideoGen.php
View file @
86180074
...
@@ -273,8 +273,7 @@ class AiVideoGen extends BaseJob
...
@@ -273,8 +273,7 @@ class AiVideoGen extends BaseJob
// 获取用户信息
// 获取用户信息
$user
=
User
::
find
(
$user_id
);
$user
=
User
::
find
(
$user_id
);
if
(
!
$user
)
{
if
(
!
$user
)
{
// Log::error('[AI视频通知]用户不存在: ' . $user_id);
$this
->
debug_log
(
'[AI视频通知]用户不存在: '
.
$user_id
);
$this
->
debug_log
(
'[AI视频通知]用户不存在: '
.
$user_id
,
'gen_ai'
);
return
false
;
return
false
;
}
}
...
@@ -289,12 +288,10 @@ class AiVideoGen extends BaseJob
...
@@ -289,12 +288,10 @@ class AiVideoGen extends BaseJob
'user'
=>
$user
->
toArray
()
'user'
=>
$user
->
toArray
()
]));
]));
// Log::info('[AI视频通知]通知发送成功: user_id=' . $user_id);
$this
->
debug_log
(
'[AI视频通知]通知发送成功: user_id='
.
$user_id
);
$this
->
debug_log
(
'[AI视频通知]通知发送成功: user_id='
.
$user_id
,
'gen_ai'
);
return
true
;
return
true
;
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
// Log::error('[AI视频通知]发送失败: ' . $e->getMessage());
$this
->
debug_log
(
'[AI视频通知]发送失败: user_id='
.
$user_id
.
' '
.
$e
->
getMessage
());
$this
->
debug_log
(
'[AI视频通知]发送失败: user_id='
.
$user_id
.
' '
.
$e
->
getMessage
(),
'gen_ai'
);
return
false
;
return
false
;
}
}
}
}
...
...
addons/shopro/notification/AiVideoSuccess.php
0 → 100644
View file @
86180074
<?php
namespace
addons\shopro\notification\ai
;
use
addons\shopro\notification\Notification
;
use
addons\shopro\notification\traits\Notification
as
NotificationTrait
;
/**
* AI视频生成成功通知
*/
class
AiVideoSuccess
extends
Notification
{
use
NotificationTrait
;
// 队列延迟时间
public
$delay
=
0
;
public
$receiver_type
=
'user'
;
// 接收人: user=用户
// 消息类型
public
$notification_type
=
'shop'
;
// 发送类型(对应后台配置的事件名)
public
$event
=
'ai_video_success'
;
// 额外数据
public
$data
=
[];
// 模板配置
public
$template
=
[
'MessageDefaultContent'
=>
'您的AI试戴视频已生成完成,点击查看效果!'
,
'WechatOfficialAccount'
=>
[
'temp_no'
=>
''
,
// 需要在后台配置模板ID
'keywords'
=>
[
'视频状态'
,
'生成时间'
],
'fields'
=>
[
[
"name"
=>
"视频状态"
,
"field"
=>
"status"
,
"template_field"
=>
"character_string1"
,
],
[
"name"
=>
"生成时间"
,
"field"
=>
"create_time"
,
"template_field"
=>
"time2"
,
]
],
],
'WechatMiniProgram'
=>
[
'category_id'
=>
670
,
'tid'
=>
''
,
// 需要在后台配置模板ID
'kid'
=>
[
1
,
2
],
'scene_desc'
=>
'AI视频生成成功通知用户'
,
'fields'
=>
[
[
"name"
=>
"视频状态"
,
"field"
=>
"status"
,
"template_field"
=>
"character_string1"
,
],
[
"name"
=>
"生成时间"
,
"field"
=>
"create_time"
,
"template_field"
=>
"time2"
,
]
],
]
];
// 返回的字段列表
public
$returnField
=
[
'name'
=>
'AI视频生成成功通知'
,
'channels'
=>
[
'Sms'
,
'Email'
,
'WechatOfficialAccount'
,
'WechatMiniProgram'
],
'fields'
=>
[
[
'name'
=>
'消息名称'
,
'field'
=>
'template'
],
[
'name'
=>
'视频状态'
,
'field'
=>
'status'
],
[
'name'
=>
'生成时间'
,
'field'
=>
'create_time'
],
[
'name'
=>
'视频链接'
,
'field'
=>
'video_url'
],
[
'name'
=>
'用户昵称'
,
'field'
=>
'nickname'
],
[
'name'
=>
'用户手机'
,
'field'
=>
'mobile'
],
]
];
/**
* 组合数据参数
*
* @param \think\Model $notifiable
* @return array
*/
protected
function
getData
(
$notifiable
)
{
$aiTryon
=
$this
->
data
[
'ai_tryon'
];
$user
=
$this
->
data
[
'user'
];
$data
[
'template'
]
=
$this
->
returnField
[
'name'
];
$data
[
'status'
]
=
'生成成功'
;
$data
[
'create_time'
]
=
date
(
'Y-m-d H:i:s'
);
$data
[
'video_url'
]
=
$aiTryon
[
'ai_url'
]
??
''
;
$data
[
'nickname'
]
=
$user
[
'nickname'
]
??
''
;
$data
[
'mobile'
]
=
$user
[
'mobile'
]
??
''
;
// 小程序跳转地址
$data
[
'jump_url'
]
=
"/pages/user/tryOnRecord"
;
return
$data
;
}
}
\ No newline at end of file
addons/shopro/service/user/Ai.php
View file @
86180074
...
@@ -49,7 +49,7 @@ class Ai
...
@@ -49,7 +49,7 @@ class Ai
'allow_redirects'
=>
true
'allow_redirects'
=>
true
];
];
// 记录入参日志
// 记录入参日志
Log
::
info
(
'用户ID:'
.
$userId
.
' response_format'
.
$response_format
.
' AI生成图片接口入参:'
.
json_encode
(
$params
)
);
custom_log
(
'[AI生成图片接口]用户ID:'
.
$userId
.
' response_format'
.
$response_format
.
' AI生成图片接口入参:'
.
json_encode
(
$params
),
'gen_ai_img_api'
);
// 发送请求
// 发送请求
$client
=
new
Http
();
$client
=
new
Http
();
...
@@ -61,7 +61,7 @@ class Ai
...
@@ -61,7 +61,7 @@ class Ai
$result
=
json_decode
(
$content
,
true
);
$result
=
json_decode
(
$content
,
true
);
// 记录出参日志
// 记录出参日志
Log
::
info
(
'用户ID:'
.
$userId
.
' response_format'
.
$response_format
.
' AI生成图片接口返回:'
.
json_encode
(
$result
)
);
custom_log
(
'[AI生成图片接口]用户ID:'
.
$userId
.
' response_format'
.
$response_format
.
' AI生成图片接口出参:'
.
json_encode
(
$result
),
'gen_ai_img_api'
);
if
(
$response_format
==
'b64_json'
){
if
(
$response_format
==
'b64_json'
){
if
(
!
$result
||
!
isset
(
$result
[
'data'
][
0
][
'b64_json'
]))
{
if
(
!
$result
||
!
isset
(
$result
[
'data'
][
0
][
'b64_json'
]))
{
...
@@ -151,7 +151,7 @@ class Ai
...
@@ -151,7 +151,7 @@ class Ai
];
];
// 记录入参日志
// 记录入参日志
Log
::
info
(
'用户ID:'
.
$userId
.
' AI生成视频接口入参:'
.
json_encode
(
$params
)
);
custom_log
(
'用户ID:'
.
$userId
.
' AI生成视频接口入参:'
.
json_encode
(
$params
),
'gen_ai_video_api'
);
// 发送请求
// 发送请求
$client
=
new
Http
();
$client
=
new
Http
();
...
@@ -163,7 +163,7 @@ class Ai
...
@@ -163,7 +163,7 @@ class Ai
$result
=
json_decode
(
$content
,
true
);
$result
=
json_decode
(
$content
,
true
);
// 记录出参日志
// 记录出参日志
Log
::
info
(
'用户ID:'
.
$userId
.
' AI生成视频接口返回:'
.
json_encode
(
$result
)
);
custom_log
(
'用户ID:'
.
$userId
.
' AI生成视频接口返回:'
.
json_encode
(
$result
),
'gen_ai_video_api'
);
return
[
return
[
'code'
=>
1
,
'code'
=>
1
,
...
...
addons/shopro/service/user/User.php
View file @
86180074
...
@@ -75,4 +75,23 @@ class User
...
@@ -75,4 +75,23 @@ class User
return
1
;
// 可以试戴
return
1
;
// 可以试戴
}
}
}
}
/**
* @name 扣积分
* @param int $user_id 用户ID
* @param int $points 扣除积分数量
* @return int 0=失败(积分不足), 1=成功
*/
public
function
deductPoints
(
$user_id
,
$points
)
{
try
{
// 使用 Wallet::change() 扣减积分,负数表示扣除
$result
=
\addons\shopro\service\Wallet
::
change
(
$user_id
,
'score'
,
-
$points
,
'ai_tryon_video'
,
[],
'AI试戴扣积分'
);
return
$result
?
1
:
0
;
}
catch
(
\Exception
$e
)
{
// 积分不足等异常情况
return
0
;
}
}
}
}
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