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

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

parent a4c2d32a
......@@ -119,73 +119,72 @@ class AiTryon extends Common
$this->error('商品所属分类不允许试戴');
}
//开发过程中临时代码,AI图片生成次数有限
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
$user = auth_user();
// 试戴一次扣5积分
// 校验试戴次数 && 扣除积分
$userService = new User();
$res = $userService->deductPoints($user->id, 5);
$res = $userService->isTry($user->id);
if ($res === 0) {
$this->error('积分不足 无法试戴');
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
$userService = new User();
$res = $userService->deductPoints($user->id, 10);
if ($res === 0) {
$this->error('免费次数已用完,积分不足 无法试戴');
}
}
$userService = new User();
$res = $userService->isTry($user->id);
if ($res === 0) {
$this->success('今日试戴次数已用完', 0);
// 合成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) {
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['msg'];
$tryonModel->save($tryonData);
$this->error($res['msg']);
} else {
// 保存图片到本地
$upload = new Upload();
$attachment = $upload->uploadBase64($res['data']);
// //开发时候先这样处理,AI图片生成次数有限
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// 合成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) {
// 记录入参日志
Log::info('用户ID:'. $user->id .' AI生成图片 保存到本地接口接口出参:'.json_encode($attachment));
if($attachment['code'] == 0){
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['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'];
$tryonData['ai_err_msg'] = '图片上传失败';
$tryonModel->save($tryonData);
$this->error('图片上传失败');
}
//试戴次数+1
$userService = new User();
$res = $userService->addTryTimes($user->id);
$tryonData['ai_status'] = 1;
$tryonData['ai_url'] = config('shopro.api_host') . $attachment['data'];
$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
$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');
// $this->success('推送队列成功');
// exit;
//开发过程中临时调试代码
\think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => 'cgt-20260518151431-zcrgp', 'user' => $user], 'shopro-high');
$this->success('推送队列成功');
exit;
// $this->success('视频生成中', 13);
// 校验试戴次数 && 扣除积分
$userService = new User();
$res = $userService->isTry($user->id);
if ($res === 0) {
$this->success('今日试戴次数已用完', 0);
} else {
// 开发过程中临时代码
// $this->success('视频生成中', 13);
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
$userService = new User();
$res = $userService->deductPoints($user->id, 10);
if ($res === 0) {
$this->error('免费次数已用完,积分不足 无法试戴');
}
}
// 合成AI视频
$ai = new Ai();
$res = $ai->generateVideo($params, $user->id);
// 合成AI视频
$ai = new Ai();
$res = $ai->generateVideo($params, $user->id);
// 我的试戴
$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_type' => 1,
];
// 我的试戴
$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_type' => 1,
];
if ($res['code'] === 0) {
if ($res['code'] === 0) {
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['msg'];
$tryonModel->insertGetId($tryonData);
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['msg'];
$tryonModel->insertGetId($tryonData);
$this->error($res['msg']);
$this->error($res['msg']);
} else {
} else {
// 保存一条 我的试戴
$tryonData['ai_status'] = 0;
$tryonData['ai_task_id'] = isset($res['data']) ? $res['data'] : '';
$id = $tryonModel->insertGetId($tryonData);
// 保存一条 我的试戴
$tryonData['ai_status'] = 0;
$tryonData['ai_task_id'] = isset($res['data']) ? $res['data'] : '';
$id = $tryonModel->insertGetId($tryonData);
//试戴次数+1
$userService = new User();
$userService->addTryTimes($user->id);
//试戴次数+1
$userService = new User();
$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);
}
}
}
}
......@@ -291,10 +291,6 @@ class AiVideoGen extends BaseJob
->find();
// 发送通知
// $user = User::where('id', $user_id)->find();
print_r($aiTryon->toArray());
print_r($user->toArray());
$user && $user->notify(
new AiVideoSuccess([
'ai_tryon' => $aiTryon ? $aiTryon->toArray() : [],
......
......@@ -45,7 +45,7 @@ class User
// 查询我的试戴列表
$res = userModel::where('id', $user_id)
->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; // 不可以试戴
} else {
return 1; // 可以试戴
......@@ -62,18 +62,13 @@ class User
// 查询我的试戴列表
$res = userModel::where('id', $user_id)
->find();
if ($res->ai_count > 4 && $res->ai_time > Time::today()[0]) {
return 0; // 不可以试戴
if($res->ai_time < Time::today()[0]) {
$ai_count = 1;
} else {
if($res->ai_time < Time::today()[0]) {
$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; // 可以试戴
$ai_count = intval($res->ai_count)+1;
}
// 试戴次数+1
userModel::where('id', $user_id)->update(['ai_count' => $ai_count, 'ai_time' => time()]);
}
/**
......@@ -86,7 +81,7 @@ class User
{
try {
// 使用 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;
} 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