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
44bbb7bf
Commit
44bbb7bf
authored
May 19, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3D试戴次数和扣积分数逻辑按照客户最新要求调整
parent
a4c2d32a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
115 deletions
+103
-115
AiTryon.php
addons/shopro/controller/user/AiTryon.php
+96
-99
AiVideoGen.php
addons/shopro/job/AiVideoGen.php
+0
-4
User.php
addons/shopro/service/user/User.php
+7
-12
No files found.
addons/shopro/controller/user/AiTryon.php
View file @
44bbb7bf
...
@@ -119,73 +119,72 @@ class AiTryon extends Common
...
@@ -119,73 +119,72 @@ class AiTryon extends Common
$this
->
error
(
'商品所属分类不允许试戴'
);
$this
->
error
(
'商品所属分类不允许试戴'
);
}
}
//开发过程中临时代码,AI图片生成次数有限
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
$user
=
auth_user
();
$user
=
auth_user
();
//
试戴一次扣5
积分
//
校验试戴次数 && 扣除
积分
$userService
=
new
User
();
$userService
=
new
User
();
$res
=
$userService
->
deductPoints
(
$user
->
id
,
5
);
$res
=
$userService
->
isTry
(
$user
->
id
);
if
(
$res
===
0
)
{
if
(
$res
===
0
)
{
$this
->
error
(
'积分不足 无法试戴'
);
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
$userService
=
new
User
();
$res
=
$userService
->
deductPoints
(
$user
->
id
,
10
);
if
(
$res
===
0
)
{
$this
->
error
(
'免费次数已用完,积分不足 无法试戴'
);
}
}
}
$userService
=
new
User
();
// 合成AI图
$res
=
$userService
->
isTry
(
$user
->
id
);
$ai
=
new
Ai
();
if
(
$res
===
0
)
{
$res
=
$ai
->
generateImage
(
$params
,
$user
->
id
,
'b64_json'
);
$this
->
success
(
'今日试戴次数已用完'
,
0
);
// 我的试戴
$tryonModel
=
new
AiTryOnModel
();
$tryonData
=
[
'user_id'
=>
$user
->
id
,
'goods_id'
=>
$params
[
'goods_id'
],
'goods_title'
=>
$params
[
'goods_title'
],
'goods_subtitle'
=>
$params
[
'goods_subtitle'
],
'goods_image'
=>
$params
[
'jewelry_image'
],
'person_image'
=>
$params
[
'person_image'
],
'ai_task_id'
=>
''
,
'ai_type'
=>
0
,
];
if
(
$res
[
'code'
]
===
0
)
{
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_err_msg'
]
=
$res
[
'msg'
];
$tryonModel
->
save
(
$tryonData
);
$this
->
error
(
$res
[
'msg'
]);
}
else
{
}
else
{
// 保存图片到本地
$upload
=
new
Upload
();
$attachment
=
$upload
->
uploadBase64
(
$res
[
'data'
]);
// //开发时候先这样处理,AI图片生成次数有限
// 记录入参日志
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
Log
::
info
(
'用户ID:'
.
$user
->
id
.
' AI生成图片 保存到本地接口接口出参:'
.
json_encode
(
$attachment
));
// 合成AI图
$ai
=
new
Ai
();
$res
=
$ai
->
generateImage
(
$params
,
$user
->
id
,
'b64_json'
);
// 我的试戴
$tryonModel
=
new
AiTryOnModel
();
$tryonData
=
[
'user_id'
=>
$user
->
id
,
'goods_id'
=>
$params
[
'goods_id'
],
'goods_title'
=>
$params
[
'goods_title'
],
'goods_subtitle'
=>
$params
[
'goods_subtitle'
],
'goods_image'
=>
$params
[
'jewelry_image'
],
'person_image'
=>
$params
[
'person_image'
],
'ai_task_id'
=>
''
,
'ai_type'
=>
0
,
];
if
(
$res
[
'code'
]
===
0
)
{
if
(
$attachment
[
'code'
]
==
0
){
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_err_msg'
]
=
$res
[
'msg'
];
$tryonData
[
'ai_err_msg'
]
=
'图片上传失败'
;
$tryonModel
->
save
(
$tryonData
);
$this
->
error
(
$res
[
'msg'
]);
}
else
{
// 保存图片到本地
$upload
=
new
Upload
();
$attachment
=
$upload
->
uploadBase64
(
$res
[
'data'
]);
// 记录入参日志
Log
::
info
(
'用户ID:'
.
$user
->
id
.
' AI生成图片 保存到本地接口接口出参:'
.
json_encode
(
$attachment
));
if
(
$attachment
[
'code'
]
==
0
){
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_err_msg'
]
=
'图片上传失败'
;
$tryonModel
->
save
(
$tryonData
);
$this
->
error
(
'图片上传失败'
);
}
$tryonData
[
'ai_status'
]
=
1
;
$tryonData
[
'ai_url'
]
=
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
];
$tryonModel
->
save
(
$tryonData
);
$tryonModel
->
save
(
$tryonData
);
$this
->
error
(
'图片上传失败'
);
}
//试戴次数+1
$tryonData
[
'ai_status'
]
=
1
;
$userService
=
new
User
()
;
$tryonData
[
'ai_url'
]
=
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
]
;
$res
=
$userService
->
addTryTimes
(
$user
->
id
);
$tryonModel
->
save
(
$tryonData
);
$this
->
success
(
'图片生成成功'
,
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
]
??
''
);
//试戴次数+1
}
$userService
=
new
User
();
$res
=
$userService
->
addTryTimes
(
$user
->
id
);
$this
->
success
(
'图片生成成功'
,
config
(
'shopro.api_host'
)
.
$attachment
[
'data'
]
??
''
);
}
}
}
}
/**
/**
...
@@ -233,68 +232,66 @@ class AiTryon extends Common
...
@@ -233,68 +232,66 @@ class AiTryon extends Common
$user
=
auth_user
();
$user
=
auth_user
();
// 试戴一次扣5积分
//开发过程中临时调试代码
$userService
=
new
User
();
\think\Queue
::
push
(
'\addons\shopro\job\AiVideoGen@save'
,
[
'taskid'
=>
'cgt-20260518151431-zcrgp'
,
'user'
=>
$user
],
'shopro-high'
);
$res
=
$userService
->
deductPoints
(
$user
->
id
,
5
);
$this
->
success
(
'推送队列成功'
);
if
(
$res
===
0
)
{
exit
;
$this
->
error
(
'积分不足 无法试戴'
);
// $this->success('视频生成中', 13);
}
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260506113558-x6wtq', 'user' => $user], 'shopro-high');
// $this->success('推送队列成功');
// exit;
// 校验试戴次数 && 扣除积分
$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
);
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
}
else
{
$userService
=
new
User
();
$res
=
$userService
->
deductPoints
(
$user
->
id
,
10
);
// 开发过程中临时代码
if
(
$res
===
0
)
{
// $this->success('视频生成中', 13);
$this
->
error
(
'免费次数已用完,积分不足 无法试戴'
);
}
}
// 合成AI视频
// 合成AI视频
$ai
=
new
Ai
();
$ai
=
new
Ai
();
$res
=
$ai
->
generateVideo
(
$params
,
$user
->
id
);
$res
=
$ai
->
generateVideo
(
$params
,
$user
->
id
);
// 我的试戴
// 我的试戴
$tryonModel
=
new
AiTryOnModel
();
$tryonModel
=
new
AiTryOnModel
();
$tryonData
=
[
$tryonData
=
[
'user_id'
=>
$user
->
id
,
'user_id'
=>
$user
->
id
,
'goods_id'
=>
$params
[
'goods_id'
],
'goods_id'
=>
$params
[
'goods_id'
],
'goods_title'
=>
$params
[
'goods_title'
],
'goods_title'
=>
$params
[
'goods_title'
],
'goods_subtitle'
=>
$params
[
'goods_subtitle'
],
'goods_subtitle'
=>
$params
[
'goods_subtitle'
],
'goods_image'
=>
$params
[
'jewelry_image'
],
'goods_image'
=>
$params
[
'jewelry_image'
],
'person_image'
=>
$params
[
'person_image'
],
'person_image'
=>
$params
[
'person_image'
],
'ai_type'
=>
1
,
'ai_type'
=>
1
,
];
];
if
(
$res
[
'code'
]
===
0
)
{
if
(
$res
[
'code'
]
===
0
)
{
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_status'
]
=
2
;
$tryonData
[
'ai_err_msg'
]
=
$res
[
'msg'
];
$tryonData
[
'ai_err_msg'
]
=
$res
[
'msg'
];
$tryonModel
->
insertGetId
(
$tryonData
);
$tryonModel
->
insertGetId
(
$tryonData
);
$this
->
error
(
$res
[
'msg'
]);
$this
->
error
(
$res
[
'msg'
]);
}
else
{
}
else
{
// 保存一条 我的试戴
// 保存一条 我的试戴
$tryonData
[
'ai_status'
]
=
0
;
$tryonData
[
'ai_status'
]
=
0
;
$tryonData
[
'ai_task_id'
]
=
isset
(
$res
[
'data'
])
?
$res
[
'data'
]
:
''
;
$tryonData
[
'ai_task_id'
]
=
isset
(
$res
[
'data'
])
?
$res
[
'data'
]
:
''
;
$id
=
$tryonModel
->
insertGetId
(
$tryonData
);
$id
=
$tryonModel
->
insertGetId
(
$tryonData
);
//试戴次数+1
//试戴次数+1
$userService
=
new
User
();
$userService
=
new
User
();
$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
],
'shopro-high'
);
$this
->
success
(
$res
[
'msg'
],
$id
);
$this
->
success
(
$res
[
'msg'
],
$id
);
}
}
}
}
}
}
}
addons/shopro/job/AiVideoGen.php
View file @
44bbb7bf
...
@@ -291,10 +291,6 @@ class AiVideoGen extends BaseJob
...
@@ -291,10 +291,6 @@ class AiVideoGen extends BaseJob
->
find
();
->
find
();
// 发送通知
// 发送通知
// $user = User::where('id', $user_id)->find();
print_r
(
$aiTryon
->
toArray
());
print_r
(
$user
->
toArray
());
$user
&&
$user
->
notify
(
$user
&&
$user
->
notify
(
new
AiVideoSuccess
([
new
AiVideoSuccess
([
'ai_tryon'
=>
$aiTryon
?
$aiTryon
->
toArray
()
:
[],
'ai_tryon'
=>
$aiTryon
?
$aiTryon
->
toArray
()
:
[],
...
...
addons/shopro/service/user/User.php
View file @
44bbb7bf
...
@@ -45,7 +45,7 @@ class User
...
@@ -45,7 +45,7 @@ class User
// 查询我的试戴列表
// 查询我的试戴列表
$res
=
userModel
::
where
(
'id'
,
$user_id
)
$res
=
userModel
::
where
(
'id'
,
$user_id
)
->
find
();
->
find
();
if
(
$res
->
ai_count
>
4
&&
$res
->
ai_time
>
Time
::
today
()[
0
])
{
if
(
$res
->
ai_count
>
2
&&
$res
->
ai_time
>
Time
::
today
()[
0
])
{
return
0
;
// 不可以试戴
return
0
;
// 不可以试戴
}
else
{
}
else
{
return
1
;
// 可以试戴
return
1
;
// 可以试戴
...
@@ -62,18 +62,13 @@ class User
...
@@ -62,18 +62,13 @@ class User
// 查询我的试戴列表
// 查询我的试戴列表
$res
=
userModel
::
where
(
'id'
,
$user_id
)
$res
=
userModel
::
where
(
'id'
,
$user_id
)
->
find
();
->
find
();
if
(
$res
->
ai_count
>
4
&&
$res
->
ai_time
>
Time
::
today
()[
0
])
{
if
(
$res
->
ai_time
<
Time
::
today
()[
0
])
{
return
0
;
// 不可以试戴
$ai_count
=
1
;
}
else
{
}
else
{
if
(
$res
->
ai_time
<
Time
::
today
()[
0
])
{
$ai_count
=
intval
(
$res
->
ai_count
)
+
1
;
$ai_count
=
1
;
}
else
{
$ai_count
=
intval
(
$res
->
ai_count
)
+
1
;
}
// 试戴次数+1
userModel
::
where
(
'id'
,
$user_id
)
->
update
([
'ai_count'
=>
$ai_count
,
'ai_time'
=>
time
()]);
return
1
;
// 可以试戴
}
}
// 试戴次数+1
userModel
::
where
(
'id'
,
$user_id
)
->
update
([
'ai_count'
=>
$ai_count
,
'ai_time'
=>
time
()]);
}
}
/**
/**
...
@@ -86,7 +81,7 @@ class User
...
@@ -86,7 +81,7 @@ class User
{
{
try
{
try
{
// 使用 Wallet::change() 扣减积分,负数表示扣除
// 使用 Wallet::change() 扣减积分,负数表示扣除
$result
=
\addons\shopro\service\Wallet
::
change
(
$user_id
,
'score'
,
-
$points
,
'ai_tryon_video'
,
[],
'
AI
试戴扣积分'
);
$result
=
\addons\shopro\service\Wallet
::
change
(
$user_id
,
'score'
,
-
$points
,
'ai_tryon_video'
,
[],
'
3D
试戴扣积分'
);
return
$result
?
1
:
0
;
return
$result
?
1
:
0
;
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
// 积分不足等异常情况
// 积分不足等异常情况
...
...
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