Prechádzať zdrojové kódy

图库管理的优化

shish 6 rokov pred
rodič
commit
dba3ba909f

+ 13 - 3
app/shop/controllers/PicController.php

@@ -21,11 +21,13 @@ class PicController extends BaseController
 		$categoryId = isset($get['categoryId']) && is_numeric($get['categoryId']) ? $get['categoryId'] : -1;
 		if ($categoryId != -1) {
 			$where['categoryId'] = $get['categoryId'];
+			$list = PicCategoryService::getPicList($where);
+		} else {
+			$list = PicService::getPicList($where);
 		}
-		$list = PicCategoryService::getPicList($where);
 		util::success($list);
 	}
-	
+
 	//上传图片 shish 2019.12.7
 	public function actionAdd()
 	{
@@ -51,19 +53,27 @@ class PicController extends BaseController
 		}
 		$categoryIdList = isset($post['categoryIdList']) && !empty($post['categoryIdList']) ? $post['categoryIdList'] : [];
 		unset($post['categoryIdList']);
+		if (empty($categoryIdList)) {
+			util::fail('最少选择一个分类');
+		}
 		$merchantHas = CategoryService::getCategoryIdList($this->merchantId);
 		$diff = array_diff($categoryIdList, $merchantHas);
 		if (!empty($diff)) {
-			util::fail('只能设置自己的分类');
+			util::fail('只能选择自己的分类');
 		}
 		$picList = PicService::getByIds($picIdList);
 		$add = [];
+		print_r($picIdList);
+		print_r($picList);
 		foreach ($picList as $picKey => $picVal) {
 			if ($picVal['merchantId'] != $this->merchantId) {
 				util::fail('只能设置自己的图片');
 			}
 			$currentId = $picVal['id'];
 			PicService::updateById($currentId, $post);
+			echo $currentId;
+			print_r($post);
+			die;
 			foreach ($categoryIdList as $categoryId) {
 				$add[] = ['categoryId' => $categoryId, 'picId' => $currentId, 'merchantId' => $this->merchantId];
 			}

+ 15 - 5
biz/goods/services/PicService.php

@@ -9,10 +9,20 @@ use common\components\util;
 
 class PicService extends BaseService
 {
-	
+
 	public static $baseFile = '\biz\goods\classes\PicClass';
-	
-	
+
+	public static function getPicList($where)
+	{
+		$data = PicClass::getList('*', $where, 'inTurn DESC,addTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$data['list'] = PicClass::groupPicBaseInfo($list);
+		return $data;
+	}
+
 	public static function addPic($data)
 	{
 		PicClass::addPic();
@@ -41,7 +51,7 @@ class PicService extends BaseService
 		PicService::deleteById($id);
 		PicCategoryService::deleteByCondition(['picId' => $id]);
 	}
-
+	
 	//置顶 shish 2019.12.8
 	public static function top($info)
 	{
@@ -50,5 +60,5 @@ class PicService extends BaseService
 		$num = PicClass::getTopNum($merchantId);
 		PicClass::updateById($id, ['inTurn' => ++$num]);
 	}
-
+	
 }