shish 6 anni fa
parent
commit
966995007d

+ 26 - 0
app/business/controllers/PicController.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace business\controllers;
+
+use biz\goods\services\PicCategoryService;
+use Yii;
+use common\components\util;
+
+class PicController extends BaseController
+{
+	
+	//图库列表 shish 2019.12.7
+	public function actionList()
+	{
+		$get = Yii::$app->request->get();
+		$where = [];
+		$where['merchantId'] = $this->merchantId;
+		$categoryId = isset($get['categoryId']) && is_numeric($get['categoryId']) ? $get['categoryId'] : -1;
+		if ($categoryId != -1) {
+			$where['categoryId'] = $get['categoryId'];
+		}
+		$list = PicCategoryService::getPicList($where);
+		util::success($list);
+	}
+
+}

+ 10 - 0
biz/goods/classes/PicClass.php

@@ -14,4 +14,14 @@ class PicClass extends BaseClass
 	
 	public static $baseFile = '\biz\goods\models\Pic';
 	
+
+	public static function groupPicBaseInfo($list)
+	{
+		foreach ($list as $key => $val) {
+			$val = business::formatPic($val);
+			$list[$key] = $val;
+		}
+		return $list;
+	}
+	
 }

+ 17 - 1
biz/goods/services/PicCategoryService.php

@@ -3,10 +3,26 @@
 namespace biz\goods\services;
 
 use biz\base\services\BaseService;
+use biz\goods\classes\PicCategoryClass;
+use biz\goods\classes\PicClass;
 
 class PicCategoryService extends BaseService
 {
-	
+
 	public static $baseFile = '\biz\goods\classes\PicCategoryClass';
+
+	//图库列表 shish 2019.12.7
+	public static function getPicList($where)
+	{
+		$data = PicCategoryClass::getList('*', $where, 'inTurn DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$picIdList = array_column($list, 'picId');
+		$picInfoList = PicClass::getByIds($picIdList);
+		$data['list'] = PicClass::groupPicBaseInfo($picInfoList);
+		return $data;
+	}
 	
 }

+ 3 - 1
biz/goods/services/PicService.php

@@ -3,10 +3,12 @@
 namespace biz\goods\services;
 
 use biz\base\services\BaseService;
+use biz\goods\classes\PicClass;
 
 class PicService extends BaseService
 {
-
+	
 	public static $baseFile = '\biz\goods\classes\PicClass';
 
+
 }

+ 16 - 2
common/components/business.php

@@ -69,7 +69,7 @@ class business
 	{
 		$imgUrl = isset($info['picture']) ? $info['picture'] : '';
 		if (empty($imgUrl)) {
-			$info['imgList'] = ['normal' => '', 'middle' => ''];
+			$info['img'] = '';
 		}
 		$prefixImgUrl = Yii::$app->params['imgUrl'];
 		$middleImg = self::getMiddleImg($imgUrl);
@@ -78,6 +78,20 @@ class business
 		return $info;
 	}
 	
+	//对图库图片的转化
+	public static function formatPic($info)
+	{
+		$imgUrl = isset($info['img']) ? $info['img'] : '';
+		if (empty($imgUrl)) {
+			$info['imgUrl'] = '';
+		}
+		$prefixImgUrl = Yii::$app->params['imgUrl'];
+		$middleImg = self::getMiddleImg($imgUrl);
+		$middle = $prefixImgUrl . $middleImg;
+		$info['imgUrl'] = $middle;
+		return $info;
+	}
+
 	//取中图 shish 2019.12.4
 	public static function getMiddleImg($imgUrl)
 	{
@@ -87,5 +101,5 @@ class business
 		$middleImg = $pre . '_200.' . $ext;
 		return $middleImg;
 	}
-
+	
 }

+ 3 - 0
sql.txt

@@ -15,6 +15,9 @@ merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
 pictureId INT NOT NULL DEFAULT 0 COMMENT '图片id',
 categoryId INT NOT NULL DEFAULT 0 COMMENT '分类id'
 )COMMENT='商品图与分类关系';
+ALTER TABLE xhPic ADD inTurn INT NOT NULL DEFAULT 0 COMMENT '排序' AFTER `name`;
+ALTER TABLE xhPicCategory ADD inTurn INT NOT NULL DEFAULT 0 COMMENT '排序' AFTER categoryId;
+ALTER TABLE xhPicCategory CHANGE pictureId picId INT NOT NULL DEFAULT 0 COMMENT '图片id';
 
 shizhongqi 2019.12.7
 ALTER TABLE xhAd ADD `status` TINYINT NOT NULL DEFAULT 0 COMMENT '启用状态 0 未启用 1 启用' AFTER `adName`;