소스 검색

商品列表

shish 6 년 전
부모
커밋
0ddfb90cbc

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

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: admin
+ * Date: 2019/12/1
+ * Time: 13:55
+ */
+
+namespace business\controllers;
+
+use biz\goods\services\CategoryService;
+use Yii;
+use common\components\util;
+use biz\goods\services\GoodsService;
+
+class CategoryController extends BaseController
+{
+
+	//分类列表
+	public function actionList()
+	{
+		$list = CategoryService::getCategoryList();
+		util::success($list);
+	}
+
+}

+ 41 - 36
app/business/controllers/GoodsController.php

@@ -15,40 +15,45 @@ use biz\goods\services\GoodsService;
 
 class GoodsController extends BaseController
 {
-    //index,view,create,update,delete,options
-
-    public function actionList()
-    {
-        $where = null;
-        $list = GoodsService::getGoodsList($where);
-        util::success($list);
-    }
-
-    public function actionCreate()
-    {
-        $data = Yii::$app->request->get();
-        GoodsService::add($data);
-    }
-
-    public function actionView()
-    {
-        $id = Yii::$app->request->get('id');
-        $good = GoodsService::getById($id);
-        util::success($good);
-    }
-
-    public function actionUpdate()
-    {
-        $data = Yii::$app->request->get();
-        $id = $data['id'];
-        $re = GoodsService::updateById($id, $data);
-        util::success($re);
-    }
-
-    public function actionDelete()
-    {
-        $id = Yii::$app->request->get('id');
-        $good = GoodsService::deleteById($id);
-        //util::success($good);
-    }
+
+	//商品列表 shish 2019.12.7
+	public function actionList()
+	{
+		$where = ['merchantId' => $this->merchantId];
+		$list = GoodsService::getGoodsList($where);
+		util::success($list);
+	}
+
+	//新建商品 shish 2019.12.7
+	public function actionAdd()
+	{
+		$data = Yii::$app->request->get();
+		GoodsService::add($data);
+	}
+
+	//获取商品详情 shish 2019.12.7
+	public function actionDetail()
+	{
+		$id = Yii::$app->request->get('id');
+		$goods = GoodsService::getGoodsInfo($id);
+		util::success($goods);
+	}
+
+	//更新商品 shish 2019.12.7
+	public function actionUpdate()
+	{
+		$data = Yii::$app->request->get();
+		$id = $data['id'];
+		$re = GoodsService::updateById($id, $data);
+		util::success($re);
+	}
+
+	//删除商品 shish 2019.12.7
+	public function actionDelete()
+	{
+		$id = Yii::$app->request->get('id', 0);
+		GoodsService::deleteGoods($id, $this->admin);
+		util::success();
+	}
+
 }

+ 1 - 0
biz/goods/classes/GoodsClass.php

@@ -35,6 +35,7 @@ class GoodsClass extends BaseClass
 			$val['freeSendDist'] = 5;
 			//多款式
 			$val['goodsStyleList'] = isset($val['goodsStyle']) && $val['goodsStyle'] == 1 ? GoodsStyleService::getStyle($id) : [];
+			$val['createDate'] = date("Y-m-d", strtotime($val['createTime']));
 			$list[$key] = $val;
 			//涨价
 		}

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

@@ -12,11 +12,27 @@ class CategoryService extends BaseService
 	
 	public static $baseFile = '\biz\goods\classes\CategoryClass';
 	
+	//取所有的分类 shish 2019.12.7
+	public static function getCategoryList()
+	{
+		$merchantId = Yii::$app->params['merchantId'];
+		$cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId], 'inTurn DESC', '*');
+		if (empty($cat)) {
+			return [];
+		}
+		//处理图片
+		$prefix = Yii::$app->params['imgUrl'];
+		foreach ($cat as $key => $info) {
+			$cat[$key]['cover'] = $prefix . $info['cover'];
+		}
+		return $cat;
+	}
+	
 	//取出可用的分类 shish 2019.12.2
 	public static function getEnableList()
 	{
 		$merchantId = Yii::$app->params['merchantId'];
-		$cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId], 'inTurn DESC', '*');
+		$cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'status' => 1], 'inTurn DESC', '*');
 		if (empty($cat)) {
 			return [];
 		}

+ 25 - 1
biz/goods/services/GoodsService.php

@@ -2,19 +2,29 @@
 
 namespace biz\goods\services;
 
+use biz\admin\services\AdminService;
 use biz\base\services\BaseService;
 
 use biz\goods\classes\GoodsClass;
+use common\components\util;
 use Yii;
 use linslin\yii2\curl;
 
 class GoodsService extends BaseService
 {
+
 	public static $baseFile = '\biz\goods\classes\GoodsClass';
 
+	//后台列表 shish 2019.12.7
 	public static function getGoodsList($where)
 	{
-		return self::getList('*', $where, 'updateTime DESC');
+		$data = GoodsClass::getList('*', $where, 'inTurn DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$data['list'] = GoodsClass::groupGoodsBaseInfo($list);
+		return $data;
 	}
 
 	//获取商品完整详情 shish 2019.12.3
@@ -23,4 +33,18 @@ class GoodsService extends BaseService
 		return GoodsClass::getGoodsInfo($id);
 	}
 
+	//删除商品 shish 2019.12.7
+	public static function deleteGoods($id, $admin)
+	{
+		$goods = GoodsClass::getById($id);
+		if (empty($goods)) {
+			util::fail('商品不存在');
+		}
+		if ($goods['merchantId'] != $admin['merchantId']) {
+			util::fail('您没有权限删除');
+		}
+		GoodsClass::deleteById($id);
+		GoodsCategoryService::deleteByCondition(['gId' => $id]);
+	}
+	
 }

+ 2 - 0
sql.txt

@@ -5,6 +5,8 @@ RENAME TABLE xhUserIntegral TO xhUserGrowth;
 ALTER TABLE xhUserGrowth CHANGE `integral` `growth` INT NOT NULL DEFAULT 0 COMMENT '当前成长值';
 ALTER TABLE xhUserGrowth MODIFY `num` INT NOT NULL DEFAULT 0 COMMENT '增加或减少的成长值';
 ALTER TABLE xhOrder DROP COLUMN `payStyle`;
+ALTER TABLE xhGoods MODIFY `status` TINYINT NOT NULL DEFAULT 1 COMMENT '商品状态 0下架 1正常';
+ALTER TABLE xhGoods DROP COLUMN `delStatus`;
 
 2019.12.5 shish
 ALTER TABLE xhOrderGoods CHANGE `multipleTitle` `goodsStyleName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '款式名称';