Quellcode durchsuchen

删除商品的逻辑

shish vor 6 Jahren
Ursprung
Commit
efbdeaeece
2 geänderte Dateien mit 224 neuen und 225 gelöschten Zeilen
  1. 157 155
      app/shop/controllers/GoodsController.php
  2. 67 70
      biz/goods/services/GoodsService.php

+ 157 - 155
app/shop/controllers/GoodsController.php

@@ -19,159 +19,161 @@ use biz\goods\services\GoodsService;
 
 class GoodsController extends BaseController
 {
-	
-	//商品列表 shish 2019.12.7
-	public function actionList()
-	{
-		$get = Yii::$app->request->get();
-		$status = isset($get['status']) ? $get['status'] : -1;
-		$goodsName = isset($get['goodsName']) && !empty($get['goodsName']) ? $get['goodsName'] : '';
-		$where = [];
-		if ($status != -1) {
-			$where['status'] = $status;
-		}
-		if (!empty($goodsName)) {
-			$where['goodsName'] = ['like', $goodsName];
-		}
-		if (isset($get['cId']) && $get['cId'] != -1) {
-			$where['cId'] = $get['cId'];
-		}
-		$where['merchantId'] = $this->merchantId;
-		$where['delStatus'] = 0;
-		$data = GoodsService::getGoodsList($where);
-		$asset = MerchantAssetService::getByMerchantId($this->merchantId);
-		$data['MerchantAsset'] = $asset;
-		util::success($data);
-	}
-	
-	//添加商品 shish 2019.12.7
-	public function actionAdd()
-	{
-		$data = Yii::$app->request->post();
-		$data['merchantId'] = $this->merchantId;
-		$return = GoodsService::addGoods($data);
-		$id = $return['id'];
-		$info = GoodsService::getById($id);
-		util::success($info);
-	}
-	
-	//获取商品详情 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->post();
-		$id = isset($data['id']) ? $data['id'] : 0;
-		$info = GoodsService::getById($id);
-		GoodsService::valid($info, $this->merchantId);
-		$data['merchantId'] = $this->merchantId;
-		GoodsService::updateGoods($id, $data);
-		util::complete();
-	}
-
-	//商品排序 shish 2020.3.11
-	public function actionSort()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		$cId = Yii::$app->request->get('cId', -1);
-		$inTurn = Yii::$app->request->get('inTurn', 0);
-		//验证商品
-		$info = GoodsService::getById($id);
-		GoodsService::valid($info, $this->merchantId);
-		if ($cId != -1) {
-			//验证分类
-			$category = CategoryService::getById($cId);
-			CategoryService::valid($category, $this->merchantId);
-			GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
-		} else {
-			GoodsService::updateById($id, ['inTurn' => $inTurn]);
-		}
-		util::complete('操作成功');
-	}
-	
-	//删除商品 shish 2019.12.7
-	public function actionDelete()
-	{
-		$id = Yii::$app->request->get('id', 0);
-		GoodsService::deleteGoods($id, $this->admin);
-		util::complete();
-	}
-	
-	//上下架 shish 2019.12.8
-	public function actionChangeStatus()
-	{
-		$post = Yii::$app->request->post();
-		$id = isset($post['id']) ? $post['id'] : 0;
-		$status = isset($post['status']) ? $post['status'] : 1;
-		$info = GoodsService::getById($id);
-		GoodsService::valid($info, $this->merchantId);
-		GoodsService::changeStatus($id, $status);
-		util::complete();
-	}
-	
-	//发送短链接到手机上 shish 2019.12.8
-	public function actionSendShortUrl()
-	{
-		$id = Yii::$app->request->get('id');
-		util::complete();
-	}
-	
-	//查看商品短链接 shish 2019.12.8
-	public function actionShortUrl()
-	{
-		$id = Yii::$app->request->get('id');
-		util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
-	}
-	
-	//商品说明 shish 2019.12.8
-	public function actionIntroduce()
-	{
-		$set = GoodsSettingService::getByCondition(['merchantId' => $this->merchantId]);
-		$introduce = $set['goodsIntroduce'];
-		util::success(['introduce' => $introduce]);
-	}
-	
-	//修改商品说明 shish 2019.12.8
-	public function actionUpdateIntroduce()
-	{
-		$introduce = Yii::$app->request->post('introduce', '');
-		GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], ['goodsIntroduce' => $introduce]);
-		util::complete('提交成功');
-	}
-	
-	//设置 shish 2019.12.8
-	public function actionSetting()
-	{
-		$return = GoodsSettingService::getSetting($this->merchantId);
-		util::success($return);
-	}
-	
-	//更新涨价 shish 2019.12.9
-	public function actionUpdateRise()
-	{
-		$post = Yii::$app->request->post();
-		$festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
-		unset($post['festIdList']);
-		$riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
-		if ($riseSwitch == 1) {
-			if (empty($festIdList)) {
-				util::fail('请选择节日');
-			}
-			FestRiseService::deleteByCondition(['merchantId' => $this->merchantId]);
-			$add = [];
-			foreach ($festIdList as $festId) {
-				$add[] = ['merchantId' => $this->merchantId, 'festId' => $festId];
-			}
-			FestRiseService::batchAdd($add);
-		}
-		GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], $post);
-		util::complete('提交成功');
-	}
-	
+
+    //商品列表 shish 2019.12.7
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $status = isset($get['status']) ? $get['status'] : -1;
+        $goodsName = isset($get['goodsName']) && !empty($get['goodsName']) ? $get['goodsName'] : '';
+        $where = [];
+        if ($status != -1) {
+            $where['status'] = $status;
+        }
+        if (!empty($goodsName)) {
+            $where['goodsName'] = ['like', $goodsName];
+        }
+        if (isset($get['cId']) && $get['cId'] != -1) {
+            $where['cId'] = $get['cId'];
+        }
+        $where['merchantId'] = $this->merchantId;
+        $where['delStatus'] = 0;
+        $data = GoodsService::getGoodsList($where);
+        $asset = MerchantAssetService::getByMerchantId($this->merchantId);
+        $data['MerchantAsset'] = $asset;
+        util::success($data);
+    }
+
+    //添加商品 shish 2019.12.7
+    public function actionAdd()
+    {
+        $data = Yii::$app->request->post();
+        $data['merchantId'] = $this->merchantId;
+        $return = GoodsService::addGoods($data);
+        $id = $return['id'];
+        $info = GoodsService::getById($id);
+        util::success($info);
+    }
+
+    //获取商品详情 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->post();
+        $id = isset($data['id']) ? $data['id'] : 0;
+        $info = GoodsService::getById($id);
+        GoodsService::valid($info, $this->merchantId);
+        $data['merchantId'] = $this->merchantId;
+        GoodsService::updateGoods($id, $data);
+        util::complete();
+    }
+
+    //商品排序 shish 2020.3.11
+    public function actionSort()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $cId = Yii::$app->request->get('cId', -1);
+        $inTurn = Yii::$app->request->get('inTurn', 0);
+        //验证商品
+        $info = GoodsService::getById($id);
+        GoodsService::valid($info, $this->merchantId);
+        if ($cId != -1) {
+            //验证分类
+            $category = CategoryService::getById($cId);
+            CategoryService::valid($category, $this->merchantId);
+            GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
+        } else {
+            GoodsService::updateById($id, ['inTurn' => $inTurn]);
+        }
+        util::complete('操作成功');
+    }
+
+    //删除商品 shish 2019.12.7
+    public function actionDelete()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $goods = GoodsService::getById($id);
+        GoodsService::valid($goods, $this->merchantId);
+        GoodsService::deleteGoods($goods);
+        util::complete();
+    }
+
+    //上下架 shish 2019.12.8
+    public function actionChangeStatus()
+    {
+        $post = Yii::$app->request->post();
+        $id = isset($post['id']) ? $post['id'] : 0;
+        $status = isset($post['status']) ? $post['status'] : 1;
+        $info = GoodsService::getById($id);
+        GoodsService::valid($info, $this->merchantId);
+        GoodsService::changeStatus($id, $status);
+        util::complete();
+    }
+
+    //发送短链接到手机上 shish 2019.12.8
+    public function actionSendShortUrl()
+    {
+        $id = Yii::$app->request->get('id');
+        util::complete();
+    }
+
+    //查看商品短链接 shish 2019.12.8
+    public function actionShortUrl()
+    {
+        $id = Yii::$app->request->get('id');
+        util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
+    }
+
+    //商品说明 shish 2019.12.8
+    public function actionIntroduce()
+    {
+        $set = GoodsSettingService::getByCondition(['merchantId' => $this->merchantId]);
+        $introduce = $set['goodsIntroduce'];
+        util::success(['introduce' => $introduce]);
+    }
+
+    //修改商品说明 shish 2019.12.8
+    public function actionUpdateIntroduce()
+    {
+        $introduce = Yii::$app->request->post('introduce', '');
+        GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], ['goodsIntroduce' => $introduce]);
+        util::complete('提交成功');
+    }
+
+    //设置 shish 2019.12.8
+    public function actionSetting()
+    {
+        $return = GoodsSettingService::getSetting($this->merchantId);
+        util::success($return);
+    }
+
+    //更新涨价 shish 2019.12.9
+    public function actionUpdateRise()
+    {
+        $post = Yii::$app->request->post();
+        $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
+        unset($post['festIdList']);
+        $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
+        if ($riseSwitch == 1) {
+            if (empty($festIdList)) {
+                util::fail('请选择节日');
+            }
+            FestRiseService::deleteByCondition(['merchantId' => $this->merchantId]);
+            $add = [];
+            foreach ($festIdList as $festId) {
+                $add[] = ['merchantId' => $this->merchantId, 'festId' => $festId];
+            }
+            FestRiseService::batchAdd($add);
+        }
+        GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], $post);
+        util::complete('提交成功');
+    }
+
 }

+ 67 - 70
biz/goods/services/GoodsService.php

@@ -13,75 +13,72 @@ use linslin\yii2\curl;
 
 class GoodsService extends BaseService
 {
-	
-	public static $baseFile = '\biz\goods\classes\GoodsClass';
 
-	//后台列表 shish 2019.12.7
-	public static function getGoodsList($where)
-	{
-		if (isset($where['cId'])) {
-			$data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC', 'goods');
-			$list = [];
-			if (isset($data['list']) && !empty($data['list'])) {
-				foreach ($data['list'] as $val) {
-					$list[] = $val['goods'];
-				}
-			}
-		} else {
-			$data = GoodsClass::getList('*', $where, 'inTurn DESC,updateTime 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
-	public static function getGoodsInfo($id)
-	{
-		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::updateById($id, ['delStatus' => 1]);
-		GoodsCategoryClass::updateByCondition(['gId' => $id], ['delStatus' => 1]);
-	}
-	
-	//添加商品 shish 2019.12.7
-	public static function addGoods($data)
-	{
-		return GoodsClass::addGoods($data);
-	}
-	
-	//更新商品 shish 2019.12.7
-	public static function updateGoods($id, $data)
-	{
-		return GoodsClass::updateGoods($id, $data);
-	}
-	
-	//验证对此商品的操作权限 shish 2019.12.7
-	public static function valid($info, $merchantId)
-	{
-		if ($info['merchantId'] != $merchantId) {
-			util::fail('您没有权限操作');
-		}
-	}
-	
-	//上下架 shish 2019.12.8
-	public static function changeStatus($id, $status)
-	{
-		GoodsClass::changeStatus($id, $status);
-	}
-	
+    public static $baseFile = '\biz\goods\classes\GoodsClass';
+
+    //后台列表 shish 2019.12.7
+    public static function getGoodsList($where)
+    {
+        if (isset($where['cId'])) {
+            $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC', 'goods');
+            $list = [];
+            if (isset($data['list']) && !empty($data['list'])) {
+                foreach ($data['list'] as $val) {
+                    $list[] = $val['goods'];
+                }
+            }
+        } else {
+            $data = GoodsClass::getList('*', $where, 'inTurn DESC,updateTime 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
+    public static function getGoodsInfo($id)
+    {
+        return GoodsClass::getGoodsInfo($id);
+    }
+
+    //删除商品 shish 2019.12.7
+    public static function deleteGoods($goods)
+    {
+        $id = $goods['id'];
+        GoodsClass::updateById($id, ['delStatus' => 1]);
+        GoodsCategoryClass::updateByCondition(['gId' => $id], ['delStatus' => 1]);
+    }
+
+    //添加商品 shish 2019.12.7
+    public static function addGoods($data)
+    {
+        return GoodsClass::addGoods($data);
+    }
+
+    //更新商品 shish 2019.12.7
+    public static function updateGoods($id, $data)
+    {
+        return GoodsClass::updateGoods($id, $data);
+    }
+
+    //验证对此商品的操作权限 shish 2019.12.7
+    public static function valid($info, $merchantId)
+    {
+        if (empty($info)) {
+            util::fail('没有找到商品');
+        }
+        if ($info['merchantId'] != $merchantId) {
+            util::fail('您没有权限操作');
+        }
+    }
+
+    //上下架 shish 2019.12.8
+    public static function changeStatus($id, $status)
+    {
+        GoodsClass::changeStatus($id, $status);
+    }
+
 }