merchantId); $categoryClassifyName = configDict::getConfig('categoryClassifyName');//商品、文章、图片等分类 $categoryClassify = configDict::getConfig('categoryClassify'); return $this->render('list',['list' => $list,'categoryClassifyName' => $categoryClassifyName,'categoryClassify'=>$categoryClassify]); } public function actionGoodsList() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $category = xhCategoryService::getList($this->merchantId); if(!in_array($id,array_keys($category))){ util::stop('访问出错了'); } $categoryName = $category[$id]; $list = xhGoodsCategoryService::getGoodsListByCId($id); return $this->render('goodsList',['list' => $list,'categoryName' => $categoryName]); } /** * 添加分类 */ public function actionAdd() { $post = Yii::$app->request->post(); $parentId = isset($post['parentId']) ? $post['parentId'] : 0; xhCategoryService::addCategory($post,$parentId,$this->merchantId); echo Json::encode(['code' => 'A0001','msg' => '添加成功','data' =>[]]); } /** * 修改分类 */ public function actionModify() { $post = Yii::$app->request->post(); $id = $post['id']; $list = xhCategoryService::getList($this->merchantId); if(!in_array($id,array_keys($list))){ util::failInfo('出错了,请联系网站管理员'); } unset($post['_csrf']); unset($post['id']); xhCategoryService::updateById($id,$post,$this->merchantId); echo Json::encode(['code' => 'A0001','msg' => '修改成功','data' =>[]]); } /** * 删除分类 */ public function actionDel() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $category = xhCategoryService::getList($this->merchantId); if(!in_array($id,array_keys($category))){ util::failInfo('访问出错了'); } xhCategoryService::getByCateogryId($id, $this->merchantId); $parent = xhCategory::getByCondition(['parentId' => $id]); if(!empty($parent)){ util::failInfo('还有子分类,不能删除'); } $goods = xhGoodsCategory::getAllByCondition(['cId' => $id]); if(!empty($goods)){ util::failInfo("此分类下还有商品
确认删除请10秒内再次提交"); } xhCategoryService::deleteById($id,$this->merchantId); util::successInfo('删除成功'); } /** * 分类上移 */ public function actionMoveUp() { $get = Yii::$app->request->get(); $id = $get['id']; $merchantId = $this->merchantId; $c = xhCategory::getById($id,$merchantId); $parentId = $c['parentId']; $currentInTurn = $c['inTurn']; $list = xhCategory::getAllByCondition(['parentId' => $parentId,'merchantId' => $merchantId],'inTurn asc'); if(count($list) <= 1){ $this->redirect(Yii::$app->request->getReferrer()); Yii::$app->end(); } $modify = []; foreach($list as $val){ $modify[] = $val['id']; $inTurn[] = $val['inTurn'];//新排序 } $pos = array_search($currentInTurn,$inTurn);//根据值返回键,新排序中位置 if($pos <= 0){//已经是第一位了 $this->redirect(Yii::$app->request->getReferrer()); Yii::$app->end(); } $toUpCategoryId = $modify[$pos]; $modify[$pos] = $modify[$pos - 1]; $modify[$pos - 1] = $toUpCategoryId; foreach($modify as $key => $val){ xhCategoryService::updateById($val, ['inTurn' => $key],$this->merchantId); } $this->redirect(Yii::$app->request->getReferrer()); } /** * 分类下移 */ public function actionMoveDown() { $get = Yii::$app->request->get(); $id = $get['id']; $merchantId = $this->merchantId; $c = xhCategory::getById($id,$merchantId); $parentId = $c['parentId']; $currentInTurn = $c['inTurn']; $list = xhCategory::getAllByCondition(['parentId' => $parentId,'merchantId' => $merchantId],'inTurn asc'); $count = count($list); if($count <= 1){ $this->redirect(Yii::$app->request->getReferrer()); Yii::$app->end(); } $modify = []; foreach($list as $val){ $modify[] = $val['id']; $inTurn[] = $val['inTurn'];//新排序 } $pos = array_search($currentInTurn,$inTurn);//根据值返回键,新排序中位置 if($pos >= ($count - 1)){//已经是最后位了 $this->redirect(Yii::$app->request->getReferrer()); Yii::$app->end(); } $toDownCategoryId = $modify[$pos]; $modify[$pos] = $modify[$pos + 1]; $modify[$pos + 1] = $toDownCategoryId; foreach($modify as $key => $val){ xhCategoryService::updateById($val, ['inTurn' => $key],$this->merchantId); } $this->redirect(Yii::$app->request->getReferrer()); } }