|
...
|
...
|
@@ -2,6 +2,8 @@ |
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bside\Product;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Exceptions\BsideGlobalException;
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Http\Controllers\Bside\BaseController;
|
|
|
|
use App\Http\Logic\Bside\Product\ProductLogic;
|
|
...
|
...
|
@@ -13,7 +15,7 @@ use Illuminate\Http\Request; |
|
|
|
* Class ProductController
|
|
|
|
* @package App\Http\Controllers\Bside
|
|
|
|
* @author zbj
|
|
|
|
* @date 2023/4/12
|
|
|
|
* @date 2023/4/17
|
|
|
|
*/
|
|
|
|
class ProductController extends BaseController
|
|
|
|
{
|
|
...
|
...
|
@@ -24,9 +26,12 @@ class ProductController extends BaseController |
|
|
|
if(!empty($this->param['search'])){
|
|
|
|
$map[] = ['title', 'like', "%{$this->param['search']}%"];
|
|
|
|
}
|
|
|
|
if(!empty($this->param['created_at'])){
|
|
|
|
$map[] = ['created_at', 'between', $this->param['created_at']];
|
|
|
|
}
|
|
|
|
$sort = ['id' => 'desc'];
|
|
|
|
$data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
|
|
|
|
return $this->success(Arr::listToTree($data));
|
|
|
|
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function info(Request $request, ProductLogic $logic){
|
|
...
|
...
|
@@ -36,11 +41,47 @@ class ProductController extends BaseController |
|
|
|
'id.required' => 'ID不能为空'
|
|
|
|
]);
|
|
|
|
$data = $logic->getInfo($this->param['id']);
|
|
|
|
return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status']));
|
|
|
|
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',
|
|
|
|
'describe', 'seo_mate', 'related_product_id', 'status']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save(ProductRequest $request, ProductLogic $logic)
|
|
|
|
{
|
|
|
|
//验证图片集格式
|
|
|
|
foreach ($this->param['gallery'] as $v){
|
|
|
|
if(empty($v['url'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, '图片链接不能为空');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//验证产品参数
|
|
|
|
foreach ($this->param['attrs'] as $v){
|
|
|
|
if(empty($v['key'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性名不能为空');
|
|
|
|
}
|
|
|
|
if(empty($v['value'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, '产品属性值不能为空');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//验证seo_mate参数
|
|
|
|
if(empty($this->param['seo_mate']['title'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO标题不能为空');
|
|
|
|
}
|
|
|
|
if(empty($this->param['seo_mate']['description'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO描述不能为空');
|
|
|
|
}
|
|
|
|
if(empty($this->param['seo_mate']['keyword'])){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, 'SEO关键词不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
//关联产品 最多16个
|
|
|
|
$this->param['related_product_id'] = array_filter(Arr::splitFilterToArray($this->param['related_product_id']), 'intval');
|
|
|
|
if(count($this->param['related_product_id']) > 16){
|
|
|
|
throw new BsideGlobalException(Code::SYSTEM_ERROR, '关联产品不能超过16个');
|
|
|
|
}
|
|
|
|
|
|
|
|
//封面取第一个图片
|
|
|
|
$this->param['thumb'] = $this->param['gallery'][0] ?? '';
|
|
|
|
|
|
|
|
$data = $logic->save($this->param);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
...
|
...
|
@@ -57,5 +98,4 @@ class ProductController extends BaseController |
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//todo Ai生成 关键词和描述
|
|
|
|
} |
...
|
...
|
|