Commit 44bbb7bf authored by 刘小敏's avatar 刘小敏

3D试戴次数和扣积分数逻辑按照客户最新要求调整

parent a4c2d32a
...@@ -119,23 +119,22 @@ class AiTryon extends Common ...@@ -119,23 +119,22 @@ 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(); $userService = new User();
$res = $userService->isTry($user->id); $res = $userService->deductPoints($user->id, 10);
if ($res === 0) { if ($res === 0) {
$this->success('今日试戴次数已用完', 0); $this->error('免费次数已用完,积分不足 无法试戴');
} else { }
}
// //开发时候先这样处理,AI图片生成次数有限
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// 合成AI图 // 合成AI图
$ai = new Ai(); $ai = new Ai();
...@@ -185,7 +184,7 @@ class AiTryon extends Common ...@@ -185,7 +184,7 @@ class AiTryon extends Common
$this->success('图片生成成功', config('shopro.api_host') . $attachment['data']??''); $this->success('图片生成成功', config('shopro.api_host') . $attachment['data']??'');
} }
}
} }
/** /**
...@@ -233,25 +232,23 @@ class AiTryon extends Common ...@@ -233,25 +232,23 @@ 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();
...@@ -295,6 +292,6 @@ class AiTryon extends Common ...@@ -295,6 +292,6 @@ class AiTryon extends Common
} }
} }
}
} }
...@@ -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() : [],
......
...@@ -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,9 +62,6 @@ class User ...@@ -62,9 +62,6 @@ 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]) {
return 0; // 不可以试戴
} else {
if($res->ai_time < Time::today()[0]) { if($res->ai_time < Time::today()[0]) {
$ai_count = 1; $ai_count = 1;
} else { } else {
...@@ -72,8 +69,6 @@ class User ...@@ -72,8 +69,6 @@ class User
} }
// 试戴次数+1 // 试戴次数+1
userModel::where('id', $user_id)->update(['ai_count' => $ai_count, 'ai_time' => time()]); userModel::where('id', $user_id)->update(['ai_count' => $ai_count, 'ai_time' => time()]);
return 1; // 可以试戴
}
} }
/** /**
...@@ -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) {
// 积分不足等异常情况 // 积分不足等异常情况
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment