|
|
|
@ -20,6 +20,7 @@ use app\store\model\GoodsImage as GoodsImageModel; |
|
|
|
|
use app\store\model\GoodsSpecRel as GoodsSpecRelModel; |
|
|
|
|
use app\store\model\goods\ServiceRel as GoodsServiceRelModel; |
|
|
|
|
use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel; |
|
|
|
|
use app\store\model\Category as CategoryRelModel; |
|
|
|
|
use app\store\service\Goods as GoodsService; |
|
|
|
|
use app\common\enum\goods\SpecType as GoodsSpecTypeEnum; |
|
|
|
|
use app\common\enum\goods\Status as GoodsStatusEnum; |
|
|
|
@ -140,6 +141,9 @@ class Goods extends GoodsModel |
|
|
|
|
|
|
|
|
|
// 创建商品数据 |
|
|
|
|
$data = $this->createData($data); |
|
|
|
|
// echo "<pre>"; |
|
|
|
|
// print_r($data); |
|
|
|
|
// exit(); |
|
|
|
|
// 事务处理 |
|
|
|
|
$ret = $this->transaction(function () use ($data, $goodsModel) { |
|
|
|
|
|
|
|
|
@ -317,6 +321,81 @@ class Goods extends GoodsModel |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['alone_grade_equity'] = $aloneGradeEquity; |
|
|
|
|
|
|
|
|
|
$data['categoryIds'] = $this->dealCategory($data['categoryIds']); |
|
|
|
|
|
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function dealCategory($category){ |
|
|
|
|
$arr = []; |
|
|
|
|
// var_dump($category); |
|
|
|
|
foreach ($category as $key => $value) { |
|
|
|
|
//一级 |
|
|
|
|
$cate = CategoryRelModel::where('category_id', $value)->find(); |
|
|
|
|
if (!$cate) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate['category_id']; |
|
|
|
|
if ($cate['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//二级 |
|
|
|
|
$cate1 = CategoryRelModel::where('category_id', $cate['parent_id'])->find(); |
|
|
|
|
if (!$cate1) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate1['category_id']; |
|
|
|
|
if ($cate1['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//三级 |
|
|
|
|
$cate2 = CategoryRelModel::where('category_id', $cate1['parent_id'])->find(); |
|
|
|
|
if (!$cate2) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate2['category_id']; |
|
|
|
|
if ($cate2['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//四级 |
|
|
|
|
$cate3 = CategoryRelModel::where('category_id', $cate2['parent_id'])->find(); |
|
|
|
|
if (!$cate3) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate3['category_id']; |
|
|
|
|
if ($cate3['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//五级 |
|
|
|
|
$cate4 = CategoryRelModel::where('category_id', $cate3['parent_id'])->find(); |
|
|
|
|
if (!$cate4) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate4['category_id']; |
|
|
|
|
if ($cate4['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
//五级 |
|
|
|
|
$cate5 = CategoryRelModel::where('category_id', $cate4['parent_id'])->find(); |
|
|
|
|
if (!$cate5) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$arr[] = $cate5['category_id']; |
|
|
|
|
if ($cate5['parent_id'] == 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return array_unique($arr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|