Commit 7a7c3c20 authored by 刘小敏's avatar 刘小敏

AI试戴生成图片接口优化

parent a6360472
...@@ -107,7 +107,7 @@ class AiTryon extends Common ...@@ -107,7 +107,7 @@ class AiTryon extends Common
} }
$params = $this->request->only([ $params = $this->request->only([
'person_image', 'jewelry_image','goods_id','goods_title','goods_subtitle','goods_image' 'person_image', 'jewelry_image','goods_id','goods_title','goods_subtitle'
]); ]);
$this->svalidate($params, ".aiadd"); $this->svalidate($params, ".aiadd");
...@@ -122,29 +122,40 @@ class AiTryon extends Common ...@@ -122,29 +122,40 @@ class AiTryon extends Common
$ai = new Ai(); $ai = new Ai();
$res = $ai->generateImage($params, $user->id); $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'],
'ai_task_id' => 0,
'ai_type' => 0,
];
if ($res['code'] === 0) { if ($res['code'] === 0) {
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = $res['msg'];
$tryonModel->save($tryonData);
$this->error($res['msg']); $this->error($res['msg']);
} else { } else {
// 保存图片到本服务器 // 保存图片到本
$upload = new Upload(); $upload = new Upload();
$attachment = $upload->uploadBase64($res['data']); $attachment = $upload->uploadBase64($res['data']);
if($attachment['code'] == 0){ if($attachment['code'] == 0){
$tryonData['ai_status'] = 2;
$tryonData['ai_err_msg'] = '图片上传失败';
$tryonModel->save($tryonData);
$this->error('图片上传失败'); $this->error('图片上传失败');
} }
$userAddress = new AiTryOnModel(); $tryonData['ai_status'] = 1;
$userAddress->save([ $tryonData['ai_url'] = config('shopro.api_host') . $attachment['data'];
'ai_url' => config('shopro.api_host') . $attachment['data'], $tryonModel->save($tryonData);
'user_id' => $user->id,
'goods_id' => $params['goods_id'],
'goods_title' => $params['goods_title'],
'goods_subtitle' => $params['goods_subtitle'],
'goods_image' => $params['goods_image'],
'ai_status' => 1,
'ai_task_id' => 0,
'ai_type' => 0,
]);
$this->success($res['msg'], config('shopro.api_host') . $attachment['data']); $this->success($res['msg'], config('shopro.api_host') . $attachment['data']);
} }
......
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