|
|
@@ -12,6 +12,20 @@ use common\components\util;
|
|
|
class CategoryController extends BaseController
|
|
|
{
|
|
|
|
|
|
+ public function actionGetMenu()
|
|
|
+ {
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $classInfo = CategoryClass::getMenuList($mainId);
|
|
|
+ $index = [];
|
|
|
+ if (!empty($classInfo)) {
|
|
|
+ foreach ($classInfo as $class) {
|
|
|
+ $id = $class['id'] ?? 0;
|
|
|
+ $index[$id] = $class;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ util::success(['class' => $classInfo, 'classIndex' => $index]);
|
|
|
+ }
|
|
|
+
|
|
|
public function actionGetAllCategory()
|
|
|
{
|
|
|
$where = ['mainId' => $this->mainId, 'delStatus' => 0];
|
|
|
@@ -23,7 +37,6 @@ class CategoryController extends BaseController
|
|
|
public function actionList()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
- //$flower = $get['flower'] ?? '';
|
|
|
$list = CategoryService::getCategoryList($this->mainId);
|
|
|
util::success($list);
|
|
|
}
|
|
|
@@ -80,11 +93,11 @@ class CategoryController extends BaseController
|
|
|
CategoryService::valid($category, $this->mainId);
|
|
|
|
|
|
if ($category['goodsNum'] > 0) {
|
|
|
- $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId'=>$this->mainId, 'cId'=>$categoryId]);
|
|
|
+ $goodsCateObjs = GoodsCategoryClass::getAllByCondition(['mainId' => $this->mainId, 'cId' => $categoryId]);
|
|
|
|
|
|
//检查是否有默认分类,没有默认分类创建一个
|
|
|
- $defaultCategory = CategoryClass::getByCondition(['mainId'=>$this->mainId, 'default'=>1]);
|
|
|
- if ($defaultCategory == null){
|
|
|
+ $defaultCategory = CategoryClass::getByCondition(['mainId' => $this->mainId, 'default' => 1]);
|
|
|
+ if ($defaultCategory == null) {
|
|
|
$data = [
|
|
|
'mainId' => $this->mainId,
|
|
|
'sjId' => $this->sjId,
|
|
|
@@ -96,7 +109,7 @@ class CategoryController extends BaseController
|
|
|
$defaultCategoryId = $defaultCategory['id'];
|
|
|
foreach ($goodsCateObjs as $gcObj) {
|
|
|
// 先判断商品是否也在其它分类下
|
|
|
- $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId'=>$this->mainId, 'gId'=>$gcObj['gId'], 'delStatus'=>0]);
|
|
|
+ $goodsOtherCateCount = GoodsCategoryClass::getCount(['mainId' => $this->mainId, 'gId' => $gcObj['gId'], 'delStatus' => 0]);
|
|
|
if ($goodsOtherCateCount == 1) {
|
|
|
// 如果商品仅在此分类下,则归到默认分类
|
|
|
GoodsCategoryClass::updateById($gcObj['id'], ['cId' => $defaultCategoryId, 'delStatus' => 0]);
|
|
|
@@ -134,21 +147,21 @@ class CategoryController extends BaseController
|
|
|
if ($flowerNum > 0) {
|
|
|
$goodsCond['flowerNum'] = $flowerNum;
|
|
|
}
|
|
|
- if (isset($get['lookPrice'])) { // 1:有价格 2:无价格 -- 根据前端的传值
|
|
|
- $lookPrice = intval($get['lookPrice']);
|
|
|
- if ($lookPrice == 1) {
|
|
|
+ if (isset($get['priceStatus'])) { // 1:有价格 2:无价格 -- 根据前端的传值
|
|
|
+ $priceStatus = intval($get['priceStatus']);
|
|
|
+ if ($priceStatus == 1) {
|
|
|
$goodsCond['priceType'] = 1;
|
|
|
}
|
|
|
- if ($lookPrice == 2) {
|
|
|
+ if ($priceStatus == 2) {
|
|
|
$goodsCond['priceType'] = 0;
|
|
|
}
|
|
|
}
|
|
|
- if (isset($get['lookStock'])) { // 1:有库存 2:无库存 -- 根据前端的传值
|
|
|
- $lookStock = intval($get['lookStock']);
|
|
|
- if ($lookStock == 1) {
|
|
|
+ if (isset($get['stockStatus'])) { // 1:有库存 2:无库存 -- 根据前端的传值
|
|
|
+ $stockStatus = intval($get['stockStatus']);
|
|
|
+ if ($stockStatus == 1) {
|
|
|
$goodsCond['stock>'] = 0;
|
|
|
}
|
|
|
- if ($lookStock == 2) {
|
|
|
+ if ($stockStatus == 2) {
|
|
|
$goodsCond['stock'] = 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -169,7 +182,7 @@ class CategoryController extends BaseController
|
|
|
|
|
|
//验证商品
|
|
|
// 提取所有商品ID
|
|
|
- $categoryIds = array_map(function($item) {
|
|
|
+ $categoryIds = array_map(function ($item) {
|
|
|
return intval($item['id']);
|
|
|
}, $items);
|
|
|
|
|
|
@@ -177,12 +190,12 @@ class CategoryController extends BaseController
|
|
|
$goodsInfos = CategoryClass::getByIds($categoryIds);
|
|
|
|
|
|
// 批量验证商品
|
|
|
- foreach($goodsInfos as $info) {
|
|
|
+ foreach ($goodsInfos as $info) {
|
|
|
CategoryService::valid($info, $this->mainId);
|
|
|
}
|
|
|
|
|
|
// 更新商品排序
|
|
|
- foreach($items as $item) {
|
|
|
+ foreach ($items as $item) {
|
|
|
$id = intval($item['id']);
|
|
|
$inTurn = intval($item['inTurn']);
|
|
|
CategoryClass::updateById($id, ['inTurn' => $inTurn]);
|