shish 6 лет назад
Родитель
Сommit
e701a390e3
2 измененных файлов с 31 добавлено и 4 удалено
  1. 29 2
      app/business/controllers/PicController.php
  2. 2 2
      biz/goods/services/CategoryService.php

+ 29 - 2
app/business/controllers/PicController.php

@@ -2,6 +2,7 @@
 
 namespace business\controllers;
 
+use biz\goods\services\CategoryService;
 use biz\goods\services\PicCategoryService;
 use biz\goods\services\PicService;
 use Yii;
@@ -37,12 +38,38 @@ class PicController extends BaseController
 		$pic = PicService::add($data);
 		util::success(['id' => $pic['id'], 'url' => $url, 'shortUrl' => $img]);
 	}
-
+	
 	//备注图片 shish 2019.12.8
 	public function actionRemark()
 	{
 		$post = Yii::$app->request->post();
-		dd($post);
+		$picIdList = isset($post['picIdList']) && !empty($post['picIdList']) ? $post['picIdList'] : [];
+		unset($post['picIdList']);
+		if (empty($picIdList)) {
+			util::fail('没有图片需要备注');
+		}
+		$categoryIdList = isset($post['categoryIdList']) && !empty($post['categoryIdList']) ? $post['categoryIdList'] : [];
+		unset($post['categoryIdList']);
+		$merchantHas = CategoryService::getCategoryIdList($this->merchantId);
+		$diff = array_diff($categoryIdList, $merchantHas);
+		if (!empty($diff)) {
+			util::fail('只能设置自己的分类');
+		}
+		$picList = PicService::getByIds($picIdList);
+		$add = [];
+		foreach ($picList as $picKey => $picVal) {
+			if ($picVal['merchantId'] != $this->merchantId) {
+				util::fail('只能设置自己的图片');
+			}
+			$currentId = $picVal['id'];
+			PicService::updateById($currentId, $post);
+			foreach ($categoryIdList as $categoryId) {
+				$add[] = ['categoryId' => $categoryId, 'picId' => $currentId, 'merchantId' => $this->merchantId];
+			}
+			PicCategoryService::deleteByCondition(['picId' => $currentId]);
+		}
+		PicCategoryService::batchAdd($add);
+		util::ok('备注成功');
 	}
 
 }

+ 2 - 2
biz/goods/services/CategoryService.php

@@ -23,7 +23,7 @@ class CategoryService extends BaseService
 		//处理图片
 		$prefix = Yii::$app->params['imgUrl'];
 		foreach ($cat as $key => $info) {
-			$cat[$key]['cover'] = $prefix . $info['cover'];
+			$cat[$key]['img'] = $prefix . $info['img'];
 		}
 		return $cat;
 	}
@@ -38,7 +38,7 @@ class CategoryService extends BaseService
 		//处理图片
 		$prefix = Yii::$app->params['imgUrl'];
 		foreach ($cat as $key => $info) {
-			$cat[$key]['cover'] = $prefix . $info['cover'];
+			$cat[$key]['img'] = $prefix . $info['img'];
 		}
 		return $cat;
 	}