Răsfoiți Sursa

商品管理可以了

shish 6 ani în urmă
părinte
comite
e2098f2e52

+ 3 - 2
app/business/controllers/GoodsController.php

@@ -48,11 +48,12 @@ class GoodsController extends BaseController
 		$data = Yii::$app->request->post();
 		$id = isset($data['id']) ? $data['id'] : 0;
 		unset($data['id']);
-		GoodsService::valid($id,$this->merchantId);
+		GoodsService::valid($id, $this->merchantId);
+		$data['merchantId'] = $this->merchantId;
 		GoodsService::updateGoods($id, $data);
 		util::ok();
 	}
-
+	
 	//删除商品 shish 2019.12.7
 	public function actionDelete()
 	{

+ 11 - 4
biz/base/classes/BaseClass.php

@@ -16,7 +16,7 @@ class BaseClass
 		$return = $model->getAllList($select, $where, $order, $with);
 		return $return;
 	}
-
+	
 	//分页查询 shish 2019.9.21
 	public static function getList($select, $where, $order = '', $with = '')
 	{
@@ -25,14 +25,14 @@ class BaseClass
 		Yii::$app->params['page'] = $page;
 		//pageSize 已经在common/params.php定义
 		$pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
-
+		
 		$model = Yii::createObject(['class' => static::$baseFile]);
 		$return = $model->getList($select, $where, $page, $pageSize, $order, $with);
 		return $return;
 	}
-
+	
 	//查询指定条数 shish 2019.11.30
-	public static function getLimitList($select, $where, $limit=10, $order='', $with='')
+	public static function getLimitList($select, $where, $limit = 10, $order = '', $with = '')
 	{
 		$model = Yii::createObject(['class' => static::$baseFile]);
 		$return = $model->getLimitList($select, $where, $limit, $order, $with);
@@ -72,6 +72,13 @@ class BaseClass
 		$count = $model->deleteByCondition($condition);
 		return $count;
 	}
+
+	//根据id批量删 shish 2019.12.7
+	public static function deleteByIds($ids)
+	{
+		$model = Yii::createObject(['class' => static::$baseFile]);
+		return $model->deleteByIds($ids);
+	}
 	
 	/**
 	 * 根据主键ID更新一条记录

+ 17 - 19
biz/base/models/Base.php

@@ -66,21 +66,18 @@ class Base extends ActiveRecord
 	 */
 	public function deleteById($id)
 	{
-	    // shizhongqi 2019-12-07 注释掉
-		/*$return = $this->conditionQuery(['id' => $id])->delete();
-		return $return;*/
-        // shizhongqi 2019-12-07 更新为如下
-        try {
-            $model = $this->getModel();
-            $re = $model::findOne($id)->delete();
-            return $re;
-        }catch (\Exception $e){
-            Yii::error("delete error");
-        }catch (\Throwable $e) {
-            Yii::error("delete error");
-        }
+		//shizhongqi 2019-12-07
+		$model = $this->getModel();
+		return $model::findOne($id)->delete();
 	}
 	
+	//根据id批量删 shish 2019.12.7
+	public function deleteByIds($ids)
+	{
+		$model = $this->getModel();
+		$model::deleteAll(['id' => $ids]);
+	}
+
 	/**
 	 *根据条件删除一条或多条记录
 	 */
@@ -100,6 +97,7 @@ class Base extends ActiveRecord
 		return $count;
 	}
 	
+	
 	/**
 	 * 根据主键ID更新一条记录
 	 */
@@ -301,7 +299,7 @@ class Base extends ActiveRecord
 		$list = $query->asArray()->all();
 		return $list;
 	}
-
+	
 	//查询指定条数 shish 2019.11.30
 	public function getLimitList($field, $where, $limit, $order = '', $with = '')
 	{
@@ -316,9 +314,9 @@ class Base extends ActiveRecord
 		$list = $query->offset($offset)->limit($limit)->asArray()->all();
 		return $list;
 	}
-
-    public static function updateAllCounters($counters, $condition = '', $params = [])
-    {
-        return parent::updateAllCounters($counters, $condition, $params); // TODO: Change the autogenerated stub
-    }
+	
+	public static function updateAllCounters($counters, $condition = '', $params = [])
+	{
+		return parent::updateAllCounters($counters, $condition, $params); // TODO: Change the autogenerated stub
+	}
 }

+ 9 - 2
biz/base/services/BaseService.php

@@ -24,14 +24,14 @@ class BaseService
 		$class = static::$baseFile;
 		return $class::getList($select, $where, $order, $with);
 	}
-
+	
 	//查询指定条数 shish 2019.11.30
 	public static function getLimitList($select, $where, $limit, $order = '', $with = '')
 	{
 		$class = static::$baseFile;
 		return $class::getLimitList($select, $where, $limit, $order, $with);
 	}
-
+	
 	public static function add($data, $returnObject = false)
 	{
 		$class = static::$baseFile;
@@ -66,6 +66,13 @@ class BaseService
 		return $count;
 	}
 	
+	//根据id批量删除 shish 2019.12.7
+	public static function deleteByIds($ids)
+	{
+		$class = static::$baseFile;
+		return $class::deleteByIds($ids);
+	}
+	
 	/**
 	 * 根据主键ID更新一条记录
 	 */

+ 31 - 11
biz/goods/classes/GoodsClass.php

@@ -59,13 +59,14 @@ class GoodsClass extends BaseClass
 		unset($data['goodsStyleList']);
 		
 		//用商户id生成商品的编号
+		$merchantId = $data['merchantId'];
 		$data['itemNumber'] = stringUtil::buildRandNo($merchantId);
 		$data['createTime'] = date("Y-m-d H:i:s");
+		$data['shopImg'] = json_encode($data['shopImg']);
 		$goodsInfo = self::add($data);
 		$id = $goodsInfo['id'];
 		
 		//处理分类
-		$merchantId = $data['merchantId'];
 		$hasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
 		$diff = array_diff($categoryIdList, $hasCategoryIdList);
 		if (!empty($diff)) {
@@ -78,9 +79,10 @@ class GoodsClass extends BaseClass
 		GoodsCategoryClass::batchAdd($addCategory);
 		//处理款式
 		if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
-			$goodsStyleList = [['styleName' => '红色', 'price' => 0.1, 'picture' => '']];
+			$goodsStyleList = ['add' => [['styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '']]];
+			$addGoodsStyle = $goodsStyleList['add'];
 			$addStyle = [];
-			foreach ($goodsStyleList as $style) {
+			foreach ($addGoodsStyle as $style) {
 				$addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
 			}
 			GoodsStyleClass::batchAdd($addStyle);
@@ -106,7 +108,6 @@ class GoodsClass extends BaseClass
 		if (!empty($diff)) {
 			util::fail('您使用了别人的分类');
 		}
-
 		//先删除分类
 		GoodsCategoryClass::delGoodsCategory($id);
 		$addCategory = [];
@@ -115,17 +116,36 @@ class GoodsClass extends BaseClass
 		}
 		//再添加分类
 		GoodsCategoryClass::batchAdd($addCategory);
-
+		
 		//处理款式
 		if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
-			$goodsStyleList = [['id' => 0, 'styleName' => '红色', 'price' => 0.1, 'picture' => '','act'=>'']];
-			$addStyle = [];
-			foreach ($goodsStyleList as $style) {
-				$addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
+			$goodsStyleList = [
+				'add' => [['styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '']],
+				'delete' => [1, 2, 3],
+				'update' => [['id' => 4, 'styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['id' => 5, 'styleName' => '蓝色', 'price' => 0.1, 'picture' => '']],
+			];
+			if (isset($goodsStyleList['add']) && !empty($goodsStyleList['add'])) {
+				$addStyleList = $goodsStyleList['add'];
+				$addStyle = [];
+				foreach ($addStyleList as $style) {
+					$addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
+				}
+				GoodsStyleClass::batchAdd($addStyle);
+			}
+			if (isset($goodsStyleList['delete']) && !empty($goodsStyleList['delete'])) {
+				GoodsStyleClass::deleteByIds($goodsStyleList['delete']);
+			}
+			if (isset($goodsStyleList['update']) && !empty($goodsStyleList['update'])) {
+				$update = $goodsStyleList['update'];
+				foreach ($update as $up) {
+					$currentId = $up['id'];
+					unset($up['id']);
+					GoodsStyleClass::updateById($currentId, $up);
+				}
 			}
-			GoodsStyleClass::batchAdd($addStyle);
 		}
-
+		
+		$data['shopImg'] = json_encode($data['shopImg']);
 		self::updateById($id, $data);
 	}
 	

+ 2 - 2
相关文档/开发规范.md

@@ -35,8 +35,8 @@ condition支持查询条件包括
 'name'=>'john'
 'id>'=>3
 'id<'=>10
-'id'=>['in',[10,11,12]
-'age'=>['between',[20,30]
+'id'=>['in',[10,11,12]]
+'age'=>['between',[20,30]]
 'name'=>['like','Jack']
 ````