user; if (empty($user)) { util::success([]); } $get = Yii::$app->request->get(); $flower = $get['flower'] ?? -1; //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open $mainId = $this->mainId; if (getenv('YII_ENV') == 'production') { if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) { util::fail('暂无商品哦,编号25395'); } } else { if (in_array($mainId, [0, 1])) { util::fail('暂无商品哦!编号639942'); } } //建立客户关系 CustomClass::buildRelation($this->shop, $this->user); $mainId = $this->mainId ?? 0; $where = ['mainId' => $mainId, 'delStatus' => 0, 'status' => 1]; if ($flower > -1) { $where['flower'] = $flower; } //默认列出正常分类,美团等第三方分类不列表 $where['style'] = 0; $return = CategoryService::getAllCategory($where); util::success($return); } //取分类下商品 ssh 2019.12.2 public function actionGoodsList() { $user = $this->user; if (empty($user)) { util::success(['list' => []]); } $get = Yii::$app->request->get(); $shop = $this->shop; $custom = $this->custom; $params = []; //调用花店端的方法,后面再分离 (为了代码维护可以不分离,免得一处改了,另一处没修改到。--- 所以分离好后,又还原了) $data = \bizHd\goods\classes\GoodsCategoryClass::getGoodsList($get, $shop, $custom, $params); $data['list'] = $this->appendUseCaseInfo($data['list'] ?? []); util::success($data); } /** * 场景列表(商城筛选弹窗用) * 游客可访问,未登录返回空数组 */ public function actionUseCaseList() { $user = $this->user; if (empty($user)) { util::success([]); } $mainId = intval($this->mainId ?? 0); if ($mainId <= 0) { util::success([]); } $list = UseCaseClass::getAllByCondition( ['mainId' => $mainId, 'status' => 1, 'delStatus' => 0], 'inTurn DESC', 'id,useCaseName' ); util::success($list ?: []); } /** * 批量为商品列表补充场景 ID 与名称,供列表页标签展示 * * @param array $list * @return array */ private function appendUseCaseInfo($list) { if (empty($list)) { return []; } $goodsIds = array_column($list, 'id'); if (empty($goodsIds)) { return $list; } $relations = GoodsUseCaseClass::getAllByCondition( ['goodsId' => ['in', $goodsIds]], null, 'goodsId,useCaseId' ); $useCaseIds = array_unique(array_column($relations ?: [], 'useCaseId')); $nameMap = []; if (!empty($useCaseIds)) { $useCases = UseCaseClass::getAllByCondition( [ 'id' => ['in', $useCaseIds], 'mainId' => intval($this->mainId ?? 0), 'delStatus' => 0, ], null, 'id,useCaseName' ); foreach ($useCases ?: [] as $uc) { $nameMap[intval($uc['id'])] = $uc['useCaseName'] ?? ''; } } $goodsUseCaseMap = []; foreach ($relations ?: [] as $rel) { $gid = intval($rel['goodsId']); $uid = intval($rel['useCaseId']); if (!isset($goodsUseCaseMap[$gid])) { $goodsUseCaseMap[$gid] = []; } if (!isset($nameMap[$uid])) { continue; } $goodsUseCaseMap[$gid][] = [ 'id' => $uid, 'name' => $nameMap[$uid], ]; } foreach ($list as &$item) { $gid = intval($item['id'] ?? 0); $cases = $goodsUseCaseMap[$gid] ?? []; $item['useCaseIdList'] = array_column($cases, 'id'); $item['useCaseNames'] = array_values(array_filter(array_column($cases, 'name'))); } unset($item); return $list; } }