作者 lyh

gx

@@ -101,6 +101,7 @@ class ProductController extends BaseController @@ -101,6 +101,7 @@ class ProductController extends BaseController
101 */ 101 */
102 public function save(ProductRequest $request, ProductLogic $logic) 102 public function save(ProductRequest $request, ProductLogic $logic)
103 { 103 {
  104 + $request->validated();
104 $data = $logic->save($this->param); 105 $data = $logic->save($this->param);
105 return $this->success($data); 106 return $this->success($data);
106 } 107 }
@@ -27,28 +27,28 @@ class ProductLogic extends BaseLogic @@ -27,28 +27,28 @@ class ProductLogic extends BaseLogic
27 $this->model = new Product(); 27 $this->model = new Product();
28 } 28 }
29 29
30 - public function save($param){ 30 + public function save(){
31 //封面取第一个图片 31 //封面取第一个图片
32 - $param['thumb'] = $param['gallery'][0] ?? '';  
33 -// DB::beginTransaction();  
34 -// try {  
35 - $data = $param;  
36 - $data['created_uid'] = $this->user['id'];  
37 - $res = parent::save($data);  
38 - //关联分类  
39 - CategoryRelated::saveRelated($res['id'], $data['category_id']);  
40 - //关联关键词  
41 - if(isset($data['keyword_id']) && !empty($data['keyword_id'])){  
42 - KeywordRelated::saveRelated($res['id'], $data['keyword_id']); 32 + $this->param['thumb'] = $this->param['gallery'][0] ?? '';
  33 + DB::beginTransaction();
  34 + try {
  35 + $this->param['created_uid'] = $this->user['id'];
  36 + if(isset($this->param['id']) && !empty($this->param['id'])){
  37 + $id = $this->param['id'];
  38 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  39 + }else{
  40 + $this->param['project_id'] = $this->user['project_id'];
  41 + $this->param['created_at'] = date('Y-m-d H:i:s');
  42 + $this->param['updated_at'] = $this->param['created_at'];
  43 + $id = $this->model->insertGetId($this->param);
43 } 44 }
44 //路由映射 45 //路由映射
45 - $route = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);  
46 -// DB::commit();  
47 -// }catch (\Exception $e){  
48 -// DB::rollBack();  
49 -// errorLog('产品保存失败', $param, $e);  
50 -// $this->fail('保存失败');  
51 -// } 46 + $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
  47 + DB::commit();
  48 + }catch (\Exception $e){
  49 + DB::rollBack();
  50 + $this->fail('保存失败');
  51 + }
52 //通知更新 52 //通知更新
53 $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]); 53 $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
54 return $this->success(); 54 return $this->success();
@@ -56,11 +56,9 @@ class ProductLogic extends BaseLogic @@ -56,11 +56,9 @@ class ProductLogic extends BaseLogic
56 56
57 public function delete($ids, $map =[]){ 57 public function delete($ids, $map =[]){
58 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); 58 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
59 -  
60 DB::beginTransaction(); 59 DB::beginTransaction();
61 try { 60 try {
62 foreach ($ids as $k => $id) { 61 foreach ($ids as $k => $id) {
63 -  
64 $info = $this->getCacheInfo($id); 62 $info = $this->getCacheInfo($id);
65 if(!$info){ 63 if(!$info){
66 unset($ids[$k]); 64 unset($ids[$k]);
@@ -69,10 +67,6 @@ class ProductLogic extends BaseLogic @@ -69,10 +67,6 @@ class ProductLogic extends BaseLogic
69 if($info->status == Product::STATUS_RECYCLE){ 67 if($info->status == Product::STATUS_RECYCLE){
70 //删除路由映射 68 //删除路由映射
71 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); 69 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
72 - //删除分类关联  
73 - CategoryRelated::where('product_id', $id)->delete();  
74 - //删除关键词关联  
75 - KeywordRelated::where('product_id', $id)->delete();  
76 //删除当前产品模版 70 //删除当前产品模版
77 $this->delProductModule($id); 71 $this->delProductModule($id);
78 }else{ 72 }else{
@@ -125,10 +119,6 @@ class ProductLogic extends BaseLogic @@ -125,10 +119,6 @@ class ProductLogic extends BaseLogic
125 $save_id = $this->model->insertGetId($param); 119 $save_id = $this->model->insertGetId($param);
126 //同步路由信息 120 //同步路由信息
127 $this->copyRoute($save_id,$param['route'].'-'.$save_id); 121 $this->copyRoute($save_id,$param['route'].'-'.$save_id);
128 - //同步关联分类  
129 - CategoryRelated::saveRelated($save_id, explode(",", $param['category_id']));  
130 - //同步关联关键词  
131 - KeywordRelated::saveRelated($save_id,explode(",", $param['keyword_id']));  
132 //同步可视化装修数据 122 //同步可视化装修数据
133 $this->copyTemplate($this->param['id'],$info['project_id'],$save_id); 123 $this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
134 return $this->success(); 124 return $this->success();