ソースを参照

查看分类详情

shish 6 年 前
コミット
e0c952903f

+ 10 - 1
app/business/controllers/CategoryController.php

@@ -15,12 +15,21 @@ use biz\goods\services\GoodsService;
 
 class CategoryController extends BaseController
 {
-
+	
 	//分类列表
 	public function actionList()
 	{
 		$list = CategoryService::getCategoryList();
 		util::success($list);
 	}
+	
+	//查看详情 shish 2019.12.8
+	public function actionDetail()
+	{
+		$id = Yii::$app->request->get('categoryId', 0);
+		CategoryService::valid($id, $this->merchantId);
+		$info = CategoryService::getInfo($id);
+		util::success($info);
+	}
 
 }

+ 21 - 5
biz/goods/classes/CategoryClass.php

@@ -2,22 +2,38 @@
 
 namespace biz\goods\classes;
 
+use common\components\business;
 use Yii;
 use biz\base\classes\BaseClass;
 
 class CategoryClass extends BaseClass
 {
-
+	
 	public static $baseFile = '\biz\goods\models\Category';
-
+	
 	//取出商家所有的分类 shish 2019.12.7
 	public static function getCategoryIdList($merchantId)
 	{
 		$category = self::getAllByCondition(['merchantId' => $merchantId], null, '*', 'id');
-		if (empty($category)) {
-			return [];
+		return empty($category) ? [] : array_keys($category);
+	}
+	
+	//获取详情 shish 2019.12.8
+	public static function getInfo($id)
+	{
+		$info = self::getById($id);
+		$list = self::groupBaseInfo([$info]);
+		return current($list);
+	}
+	
+	//组合信息 shish 2019.12.8
+	public static function groupBaseInfo($list)
+	{
+		foreach ($list as $key => $val) {
+			$val = business::formatCategoryImg($val);
+			$list[$key] = $val;
 		}
-		return array_keys($category);
+		return $list;
 	}
 	
 }

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

@@ -4,6 +4,7 @@ namespace biz\goods\services;
 
 use biz\base\services\BaseService;
 use biz\goods\classes\CategoryClass;
+use common\components\util;
 use Yii;
 use linslin\yii2\curl;
 
@@ -27,7 +28,7 @@ class CategoryService extends BaseService
 		}
 		return $cat;
 	}
-
+	
 	//取出商家所有的分类 shish 2019.12.7
 	public static function getCategoryIdList($merchantId)
 	{
@@ -70,4 +71,19 @@ class CategoryService extends BaseService
 		return $cat;
 	}
 	
+	//验证操作权限 shish 2019.12.8
+	public static function valid($id, $merchantId)
+	{
+		$category = CategoryClass::getById($id);
+		if ($category['merchantId'] != $merchantId) {
+			util::fail('您没有权限操作');
+		}
+	}
+	
+	//获取详情 shish 2019.12.8
+	public static function getInfo($id)
+	{
+		return CategoryClass::getInfo($id);
+	}
+	
 }

+ 13 - 0
common/components/business.php

@@ -91,6 +91,19 @@ class business
 		$info['imgUrl'] = $middle;
 		return $info;
 	}
+	
+	public static function formatCategoryImg($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)

+ 3 - 0
sql.txt

@@ -19,6 +19,9 @@ 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';
 ALTER TABLE xhGoodsCategory ADD `status` TINYINT NOT NULL DEFAULT 1 COMMENT '上下架状态 0下架 1正常' AFTER `merchantId`;
+ALTER TABLE xhCategory ADD goodsNum INT NOT NULL DEFAULT 0 COMMENT '商品数' AFTER `cover`;
+ALTER TABLE xhCategory ADD sold INT NOT NULL DEFAULT 0 COMMENT '销量' AFTER `goodsNum`;
+ALTER TABLE xhCategory CHANGE cover `img` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '分类图片';
 
 shizhongqi 2019.12.7
 ALTER TABLE xhAd ADD `status` TINYINT NOT NULL DEFAULT 0 COMMENT '启用状态 0 未启用 1 启用' AFTER `adName`;