Commit f40b76ad authored by 刘小敏's avatar 刘小敏

AI试戴 开发代码移除,换成正式代码

parent 85eceb29
......@@ -27,27 +27,28 @@ class AiTryon extends Common
/**
* 保存至我的试戴
* 已废弃
*/
public function saveMyTryon()
{
if (!$this->request->isPost()) {
$this->error('');
}
$user = auth_user();
$params = $this->request->only([
'url', 'goods_id', 'goods_title', 'goods_sku_id', 'goods_sku_name', 'goods_sku_image'
]);
$params['user_id'] = $user->id;
$this->svalidate($params, ".add");
Db::transaction(function () use ($params) {
$userAddress = new AiTryOnModel();
$userAddress->save($params);
});
$this->success('保存成功' );
// if (!$this->request->isPost()) {
// $this->error('');
// }
// $user = auth_user();
//
// $params = $this->request->only([
// 'url', 'goods_id', 'goods_title', 'goods_sku_id', 'goods_sku_name', 'goods_sku_image'
// ]);
// $params['user_id'] = $user->id;
//
// $this->svalidate($params, ".add");
//
// Db::transaction(function () use ($params) {
// $userAddress = new AiTryOnModel();
// $userAddress->save($params);
// });
//
// $this->success('保存成功' );
}
/**
......@@ -120,55 +121,55 @@ class AiTryon extends Common
$this->success('今日免费试戴次数已用完', 0);
} else {
//开发时候先这样处理,AI图片生成次数有限
$this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// //开发时候先这样处理,AI图片生成次数有限
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// 合成AI图
// $ai = new Ai();
// $res = $ai->generateImage($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_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']);
//
// 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);
// //试戴次数+1
// $userService = new User();
// $res = $userService->addTryTimes($user->id);
//
// $this->success($res['msg'], config('shopro.api_host') . $attachment['data']);
// }
$ai = new Ai();
$res = $ai->generateImage($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_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']);
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);
//试戴次数+1
$userService = new User();
$res = $userService->addTryTimes($user->id);
$this->success($res['msg'], config('shopro.api_host') . $attachment['data']);
}
}
}
......@@ -177,10 +178,6 @@ class AiTryon extends Common
*/
public function getAiDetail()
{
if (!$this->request->isGet()) {
$this->error('请用get方式请求');
}
$params = $this->request->only(['id']);
$this->svalidate($params, ".aidetail");
......@@ -220,48 +217,48 @@ class AiTryon extends Common
// 开发过程中临时代码
$this->success('视频生成中', 13);
// // 合成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,
// ];
//
// if ($res['code'] === 0) {
//
// $tryonData['ai_status'] = 2;
// $tryonData['ai_err_msg'] = $res['msg'];
// $tryonModel->save($tryonData);
//
// $this->error($res['msg']);
//
// } else {
//
// // 保存一条 我的试戴
// $tryonData['ai_status'] = 0;
// $tryonData['ai_task_id'] = isset($res['data']) ? $res['data'] : '';
// $tryonModel->save($tryonData);
// $id = $tryonModel->id;
// //试戴次数+1
// $userService = new User();
// $res = $userService->addTryTimes($user->id);
//
// // 推送队列
// \think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => $res['data'], 'user' => $user], 'shopro-high');
//
// $this->success($res['msg'], $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,
];
if ($res['code'] === 0) {
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['msg'];
$tryonModel->save($tryonData);
$this->error($res['msg']);
} else {
// 保存一条 我的试戴
$tryonData['ai_status'] = 0;
$tryonData['ai_task_id'] = isset($res['data']) ? $res['data'] : '';
$tryonModel->save($tryonData);
$id = $tryonModel->id;
//试戴次数+1
$userService = new User();
$res = $userService->addTryTimes($user->id);
// 推送队列
\think\Queue::push('\addons\shopro\job\AiVideoGen@save', ['taskid' => $res['data'], 'user' => $user], 'shopro-high');
$this->success($res['msg'], $id);
}
}
}
......
......@@ -45,15 +45,9 @@ class User
// 查询我的试戴列表
$res = userModel::where('id', $user_id)
->find();
// if ($res->ai_count > 4 && $res->ai_time > Time::today()[0]) {
if ($res->ai_count > 999999 && $res->ai_time > Time::today()[0]) {
if ($res->ai_count > 4 && $res->ai_time > Time::today()[0]) {
return 0; // 不可以试戴
} else {
if($res->ai_time < Time::today()[0]) {
$ai_count = 1;
} else {
$ai_count = intval($res->ai_count)+1;
}
return 1; // 可以试戴
}
}
......
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