30], [['title'], 'string', 'max' => 50], [['icon'], 'string', 'max' => 300], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '主键', 'code' => '标识', 'title' => '标题', 'group' => '组件分组', 'icon' => '图标', 'sort' => '排序,越小排越前', 'source' => '来源', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '添加时间', 'updated_at' => '修改时间', ]; } /** * 根据分组获取组件 * @Author: lun * @DateTime: 2021/9/27 0027 16:55 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $group 需要查询的分组 * @param array $showComponents 显示需要查询的分组中选中的组件,格式 ['goods' => ['pic','price'], 'img_text' => ['ad','banner']] * @param array $validAddons 商城已安装的有效插件 * @return array|\yii\db\ActiveRecord[] */ public static function getComponent(array $groups, $showComponents = [], $validAddons = [], int $mallId = 0) { $where = [['in', 'group', $groups]]; $select = "id,code type,title,group,icon img,count,is_top,permission,source"; $components = self::getDiyComponents($where, [], true, $select); if (!$components) return []; $new_components = $temp_component = []; $group_arr = DiyEnum::groupName();// 获取分组名称 if(!in_array('Store', $validAddons)) unset($group_arr['store']); $checkIsInstallAddons = [AddonsEnum::STAR_CAR_CARE, AddonsEnum::ADDONS_NAME_XUN_AI]; foreach ($components as $key => $component) { // 商城未安装的插件不显示对应组件 if ($component['group'] == 'marketing' || in_array($component['source'], $checkIsInstallAddons)) { if (empty($validAddons)) continue;// 没有安装插件直接跳过 if (!in_array($component['source'], $validAddons)) continue;// 对应组件不在已安装的插件中跳过循环 } if ($mallId) { $event = new IsShowDiyComponentsEvent($mallId); $data = ['component' => $component, 'mall_id' => $mallId]; \Yii::$app->services->events->dispatch($event, $data, $event->listeners); if (!$event->getIsShow()) { continue; } } // 需要显示的组件进行重新组合 if (!empty($showComponents[$component['group']])) { if (in_array($component['code'], $showComponents[$component['group']])) { $temp_component[] = $component; } } else { $temp_component[] = $component; } } // 重新组合分组 $group_index = 0; foreach ($group_arr as $group => $title) { $new_components[$group_index]['title'] = $title; foreach ($temp_component as $item) { if ($item['group'] == $group) { $new_components[$group_index]['list'][] = $item; } } if (empty($new_components[$group_index]['list'])) unset($new_components[$group_index]); $group_index++; } return array_values($new_components); } /** * 重新组合数组,返回组件内容 * @Author: lun * @DateTime: 2021/9/27 0027 17:22 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $components * @param array $showComponents * @return array */ private static function makeUpGroup(array $components, array $makeUpArr) { } /** * * @Author: lun * @DateTime: 2021/9/27 0027 16:55 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $cond * @param array $with * @param bool $is_array * @param string $select * @return array|\yii\db\ActiveRecord[] */ public static function getDiyComponents(array $cond=[],array $with=[],bool $is_array=true,string $select='*'){ $default_cond = [['<>','status',StatusEnum::DELETE]]; $cond = array_merge($default_cond,$cond); $query = self::find()->select($select); self::paramPack(['where'=>$cond,'with'=>$with],$query); $data = $query->asArray($is_array)->all(); return $data; } /** * 递归获取文件夹里面的文件名 * @Author: lun * @DateTime: 2021/9/27 0027 18:23 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $path * @param array $fileArr * @return array */ public static function getDir($path, $initialPath, &$fileArr = []) { if(is_dir($path)){ $dir = scandir($path); foreach ($dir as $value){ $sub_path = $path . '/' . $value; if($value == '.' || $value == '..'){ continue; }else if(is_dir($sub_path)){ self::getDir($sub_path, $initialPath, $fileArr); }else{ $file = str_replace('.php' ,'' ,$sub_path); $fileArr[] = str_replace($initialPath . '/', '', $file); } } } return $fileArr; } }