Browse Source

fix:修改商品sku错误字段

antshop
linyaostalker 5 years ago
parent
commit
e296e64bfc
  1. 94
      backend/modules/goods/logic/goods/GoodsManager.php

94
backend/modules/goods/logic/goods/GoodsManager.php

@ -2,6 +2,8 @@
namespace backend\modules\goods\logic\goods;
use backend\modules\file\models\ars\File;
use backend\modules\goods\models\ars\Category;
use backend\modules\goods\models\ars\ShopCategory;
use Throwable;
use Yii;
use yii\db\Exception;
@ -264,11 +266,11 @@ class GoodsManager
$data['data'] = [];
if ($data['type'] == Goods::SKU_MODE_ATTR) {
$sku = GoodsSku::find()
->where(['goods_id' => $id, 'is_manaul' => 0])
->where(['goods_id' => $id, 'is_manual' => 0])
->all();
} else {
$sku = GoodsSku::find()
->where(['goods_id' => $id, 'is_manaul' => 1])
->where(['goods_id' => $id, 'is_manual' => 1])
->all();
}
foreach ($sku as $value) {
@ -341,10 +343,10 @@ class GoodsManager
$ids = [];
if ($type == Goods::SKU_MODE_MANUAL) {
$query = GoodsSku::find()
->where(['is_manaul' => 1]);
->where(['is_manual' => 1]);
} else {
$query = GoodsSku::find()
->where(['is_manaul' => 0]);
->where(['is_manual' => 0]);
}
$sku = $query
->andWhere(['goods_id' => $goodsId])
@ -384,7 +386,7 @@ class GoodsManager
throw new \Exception('手动属性修改失败');
}
$goodsSku->goods_attr = (string)$attr->id;
$goodsSku->is_manaul = 1;
$goodsSku->is_manual = 1;
} else {
$goodsSku->goods_attr = implode(',', array_filter($sku['value']));
}
@ -424,10 +426,10 @@ class GoodsManager
}
if ($type == Goods::SKU_MODE_MANUAL) {
$query = GoodsSku::find()
->where(['is_manaul' => 1]);
->where(['is_manual' => 1]);
} else {
$query = GoodsSku::find()
->where(['is_manaul' => 0]);
->where(['is_manual' => 0]);
}
$sku = $query
->andWhere(['goods_id' => $goodsId])
@ -568,4 +570,82 @@ class GoodsManager
}
return true;
}
/**
* 根据pid的父级关系,给字段|___做层级标记
* @param $data
* @param int $pid
* @param int $lev
* @return array
*/
public static function btree($data, $pid = 0, $lev = 0)
{
$tree = [];
foreach ($data as $k => $value) {
if ($value['pid'] == $pid) {
$value['name'] = str_repeat('|___', $lev) . $value['name'];
$tree[] = $value;
$tree = array_merge($tree, self::btree($data, $value['id'], $lev + 1));
}
}
return $tree;
}
/**
* 构建下拉数组
* @param $dataArr
* @param int $needDefault
* @return array
*/
public static function constructDropList($dataArr, $needDefault = 1)
{
$data = [];
if ($needDefault) {
$data[0] = '一级分类';
}
foreach ($dataArr as $k => $v) {
$data[$v['id']] = $v['name'];
}
return $data;
}
/**
* 获取分类中所有下级id
* @param int $ownId
* @param array $idArr
* @return array
*/
public static function subCategoryId($ownId = 0, $idArr = [])
{
$idArr[] = $ownId;
if ($ownId) {
$subCategoryModel = Category::find()->where(['pid' => $ownId])->all();
if ($subCategoryModel) {
foreach ($subCategoryModel as $subCategory) {
$idArr = self::subCategoryId($subCategory->id, $idArr);
}
}
}
return $idArr;
}
/**
* 获取分类中所有下级id
* @param int $ownId
* @param array $idArr
* @return array
*/
public static function subShopCategoryId($ownId = 0, $idArr = [])
{
$idArr[] = $ownId;
if ($ownId) {
$subShopCategoryModel = ShopCategory::find()->where(['pid' => $ownId])->all();
if ($subShopCategoryModel) {
foreach ($subShopCategoryModel as $subShopCategory) {
$idArr = self::subShopCategoryId($subShopCategory->id, $idArr);
}
}
}
return $idArr;
}
}
Loading…
Cancel
Save