作者 lyh

gx

... ... @@ -60,7 +60,8 @@ class KeywordController extends BaseController
public function save(KeywordRequest $request, KeywordLogic $logic)
{
$data = $logic->save($this->param);
$request->validated();
$data = $logic->keywordSave();
return $this->success($data);
}
... ...
... ... @@ -21,7 +21,7 @@ class KeywordLogic extends BaseLogic
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Keyword();
}
... ... @@ -43,16 +43,23 @@ class KeywordLogic extends BaseLogic
return $this->success($info);
}
public function save($param){
public function keywordSave(){
DB::beginTransaction();
try {
$res = parent::save($param);
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['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $this->user['project_id']);
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
errorLog('产品关键词保存失败', $param, $e);
$this->fail('保存失败');
}
//通知更新
... ...