作者 lyh

gx

... ... @@ -101,6 +101,7 @@ class ProductController extends BaseController
*/
public function save(ProductRequest $request, ProductLogic $logic)
{
$request->validated();
$data = $logic->save($this->param);
return $this->success($data);
}
... ...
... ... @@ -27,28 +27,28 @@ class ProductLogic extends BaseLogic
$this->model = new Product();
}
public function save($param){
public function save(){
//封面取第一个图片
$param['thumb'] = $param['gallery'][0] ?? '';
// DB::beginTransaction();
// try {
$data = $param;
$data['created_uid'] = $this->user['id'];
$res = parent::save($data);
//关联分类
CategoryRelated::saveRelated($res['id'], $data['category_id']);
//关联关键词
if(isset($data['keyword_id']) && !empty($data['keyword_id'])){
KeywordRelated::saveRelated($res['id'], $data['keyword_id']);
$this->param['thumb'] = $this->param['gallery'][0] ?? '';
DB::beginTransaction();
try {
$this->param['created_uid'] = $this->user['id'];
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['updated_at'] = $this->param['created_at'];
$id = $this->model->insertGetId($this->param);
}
//路由映射
$route = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// errorLog('产品保存失败', $param, $e);
// $this->fail('保存失败');
// }
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('保存失败');
}
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
return $this->success();
... ... @@ -56,11 +56,9 @@ class ProductLogic extends BaseLogic
public function delete($ids, $map =[]){
$ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
DB::beginTransaction();
try {
foreach ($ids as $k => $id) {
$info = $this->getCacheInfo($id);
if(!$info){
unset($ids[$k]);
... ... @@ -69,10 +67,6 @@ class ProductLogic extends BaseLogic
if($info->status == Product::STATUS_RECYCLE){
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
//删除分类关联
CategoryRelated::where('product_id', $id)->delete();
//删除关键词关联
KeywordRelated::where('product_id', $id)->delete();
//删除当前产品模版
$this->delProductModule($id);
}else{
... ... @@ -125,10 +119,6 @@ class ProductLogic extends BaseLogic
$save_id = $this->model->insertGetId($param);
//同步路由信息
$this->copyRoute($save_id,$param['route'].'-'.$save_id);
//同步关联分类
CategoryRelated::saveRelated($save_id, explode(",", $param['category_id']));
//同步关联关键词
KeywordRelated::saveRelated($save_id,explode(",", $param['keyword_id']));
//同步可视化装修数据
$this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
return $this->success();
... ...