Commit 00b514ba authored by 刘小敏's avatar 刘小敏

增加AI试戴商品图;日志权限配置;AI试戴成图片优化;

parent 059352bf
......@@ -74,65 +74,72 @@ class AiTryon extends Common
if (!$this->request->isPost()) {
$this->error('');
}
$params = $this->request->only([
'person_image', 'jewelry_image','goods_id','goods_title','goods_subtitle'
]);
$this->svalidate($params, ".aiadd");
$user = auth_user();
//开发过程中临时调试代码
// \think\Queue::push('\addons\shopro\job\AiImgGen@exec', ['user' => $user->toArray(), 'id' => 245 ], 'shopro-high');
// $this->success('推送队列成功777');
// exit;
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// 校验商品分类是否在允许试戴分类中
$goodsService = new GoodsService();
$is_allowed = $goodsService->isCategoryAllowed('', $params['goods_id']);
if ($is_allowed === 0) {
custom_log('[AI生成图片接口] 商品所属分类不允许试戴 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
$this->error('商品所属分类不允许试戴');
}
try {
$params = $this->request->only([
'person_image', 'jewelry_image','goods_id','goods_title','goods_subtitle'
]);
$this->svalidate($params, ".aiadd");
$user = auth_user();
//开发过程中临时调试代码
// \think\Queue::push('\addons\shopro\job\AiImgGen@exec', ['user' => $user->toArray(), 'id' => 245 ], 'shopro-high');
// $this->success('推送队列成功777');
// exit;
// $this->success('图片生成成功', 'https://zhubaoshop.sydggxs.com/uploads/20260508/c92396f646bd41887329891647fcfcaf.png');
// 校验商品分类是否在允许试戴分类中
$goodsService = new GoodsService();
$is_allowed = $goodsService->isCategoryAllowed('', $params['goods_id']);
if ($is_allowed === 0) {
custom_log('[AI生成图片接口] 商品所属分类不允许试戴 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
$this->error('商品所属分类不允许试戴');
}
// 校验试戴次数 && 扣除积分
$userService = new User();
$res = $userService->isTry($user->id);
if ($res === 0) {
custom_log('[AI生成图片接口] 免费次数已用完 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
$res = $userService->deductPoints($user->id, 10);
// 校验试戴次数 && 扣除积分
$userService = new User();
$res = $userService->isTry($user->id);
if ($res === 0) {
custom_log('[AI生成图片接口] 积分不足 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
$this->error('免费次数已用完,积分不足,无法试戴');
custom_log('[AI生成图片接口] 免费次数已用完 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
// 免费试戴次数用完后,扣积分,试戴一次扣10积分
$res = $userService->deductPoints($user->id, 10);
if ($res === 0) {
custom_log('[AI生成图片接口] 积分不足 user_id:'.$user->id.' goods_id:'.$params['goods_id'], 'gen_ai');
$this->error('免费次数已用完,积分不足,无法试戴');
}
}
}
// 我的试戴
$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,
'ai_status' => 0,
'ai_url' => '',
'createtime' => time()
];
$id = $tryonModel->insertGetId($tryonData);
// 试戴次数+1
$userService->addTryTimes($user->id);
// 推送队列
\think\Queue::push('\addons\shopro\job\AiImgGen@exec', ['user' => $user->toArray(), 'id' => $id ], 'shopro-high');
$this->success('图片生成中', $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,
'ai_status' => 0,
'ai_url' => '',
'createtime' => time()
];
$id = $tryonModel->insertGetId($tryonData);
// 试戴次数+1
$userService->addTryTimes($user->id);
// 推送队列
\think\Queue::push('\addons\shopro\job\AiImgGen@exec', ['user' => $user->toArray(), 'id' => $id ], 'shopro-high');
$this->success('图片生成中', $id);
} catch (\Exception $e) {
format_log_error_custom_name($e, '[AI生成图片接口]', '', 'gen_ai');
$this->error('生成失败: ' . $e->getMessage());
}
}
/**
......@@ -146,7 +153,7 @@ class AiTryon extends Common
$res = AiTryOnModel::get($params['id']);
switch ($res->ai_status){
case 0:
$this->success('IA结果生成中');
$this->success('AI结果生成中');
break;
case 1:
$this->success('AI试戴详情', $res);
......@@ -227,4 +234,32 @@ class AiTryon extends Common
}
/**
* 删除AI试戴记录(逻辑删除)
*/
public function delete()
{
$params = $this->request->only(['id']);
$this->svalidate($params, ".aidetail");
$user = auth_user();
// 查询试戴记录
$tryon = AiTryOnModel::where('id', $params['id'])
->where('user_id', $user->id)
->where('deletetime', 'null')
->find();
if (!$tryon) {
$this->error('记录不存在或已删除');
}
// 执行逻辑删除
$tryon->deletetime = time();
$tryon->save();
$this->success('删除成功');
}
}
......@@ -209,6 +209,7 @@ class Ai
"response_format" => $response_format,
"size" => "2K",
"num" => 1,
"watermark" => false,
],
'timeout' => 300,
'verify' => false, // 关闭 SSL 证书验证
......
......@@ -116,7 +116,7 @@ class Goods extends Common
}
$params = $this->request->only([
'type', 'title', 'subtitle', 'category_ids', 'image', 'images', 'image_wh', 'params',
'type', 'title', 'subtitle', 'category_ids', 'image', 'images', 'image_wh', 'params', 'image_3d',
'original_price', 'price', 'is_sku', 'limit_type', 'limit_num', 'sales_show_type',
'stock_show_type', 'show_sales', 'service_ids', 'dispatch_type', 'dispatch_id', 'is_offline', 'status', 'weigh',
]); // likes, views, sales,
......@@ -184,7 +184,7 @@ class Goods extends Common
}
$params = $this->request->only([
'type', 'title', 'subtitle', 'image', 'images', 'image_wh', 'params',
'type', 'title', 'subtitle', 'image', 'images', 'image_wh', 'params', 'category_ids', 'image_3d',
'original_price', 'price', 'is_sku', 'limit_type', 'limit_num', 'sales_show_type',
'stock_show_type', 'show_sales', 'service_ids', 'dispatch_type', 'dispatch_id', 'is_offline', 'status', 'weigh','recommend'
]); // likes, views, sales,
......
......@@ -341,6 +341,12 @@
作用于商品详情顶部轮播显示,<br />轮播图可以拖拽调整顺序
</div>
</el-form-item>
<el-form-item label="3D试戴图" prop="image_3d">
<sa-uploader v-model="form.model.image_3d" type="image"></sa-uploader>
<div class="warning">
用于AI试戴功能的商品图片
</div>
</el-form-item>
<el-form-item label="商品分类">
<div class="sa-w-360">
<el-popover popper-class="category-tooltip sa-popper" effect="light"
......
......@@ -172,6 +172,8 @@ return [
'path' => LOG_PATH,
// 日志记录级别
'level' => [],
// 日志文件权限(设置为 777 让所有用户可写)
'file_permission' => 0777,
],
// +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效
......
......@@ -445,6 +445,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
type: 'normal', // 商品类型
image: '',
images: [],
image_3d: '',
title: '',
subtitle: '',
category_ids: '',
......
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