作者 赵彬吉

update

@@ -116,6 +116,6 @@ class CategoryLogic extends BaseLogic @@ -116,6 +116,6 @@ class CategoryLogic extends BaseLogic
116 */ 116 */
117 public function getProductNum($cate_id){ 117 public function getProductNum($cate_id){
118 $cate_ids = $this->model->getChildIdsArr($cate_id); 118 $cate_ids = $this->model->getChildIdsArr($cate_id);
119 - return CategoryRelated::whereIn('cate_id', $cate_ids)->count(); 119 + return CategoryRelated::whereIn('cate_id', $cate_ids)->distinct()->count('product_id');
120 } 120 }
121 } 121 }
@@ -92,6 +92,6 @@ class KeywordLogic extends BaseLogic @@ -92,6 +92,6 @@ class KeywordLogic extends BaseLogic
92 } 92 }
93 93
94 public function getProductNum($keyword_id){ 94 public function getProductNum($keyword_id){
95 - return KeywordRelated::where('keyword_id', $keyword_id)->count(); 95 + return KeywordRelated::where('keyword_id', $keyword_id)->distinct()->count('product_id');
96 } 96 }
97 } 97 }
@@ -86,15 +86,29 @@ class ProductLogic extends BaseLogic @@ -86,15 +86,29 @@ class ProductLogic extends BaseLogic
86 86
87 DB::beginTransaction(); 87 DB::beginTransaction();
88 try { 88 try {
89 - foreach ($ids as $id){  
90 - //删除路由映射  
91 - RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); 89 + foreach ($ids as $k => $id) {
92 90
93 - //删除分类关联  
94 - CategoryRelated::where('product_id', $id)->delete(); 91 + $info = $this->getCacheInfo($id);
  92 + if(!$info){
  93 + unset($ids[$k]);
  94 + continue;
  95 + }
95 96
96 - //删除关键词关联  
97 - KeywordRelated::where('product_id', $id)->delete(); 97 + if($info->status == Product::STATUS_RECYCLE){
  98 + //删除路由映射
  99 + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
  100 +
  101 + //删除分类关联
  102 + CategoryRelated::where('product_id', $id)->delete();
  103 +
  104 + //删除关键词关联
  105 + KeywordRelated::where('product_id', $id)->delete();
  106 + }else{
  107 + //回收站
  108 + $info->status = Product::STATUS_RECYCLE;
  109 + $info->save();
  110 + unset($ids[$k]);
  111 + }
98 } 112 }
99 parent::delete($ids); 113 parent::delete($ids);
100 114