| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace addons\Store\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_store_menu}}".
- *
- * @property int $id
- * @property string $title 标题
- * @property string $app_id 应用id
- * @property int|null $pid 上级id
- * @property int|null $is_addon 是否插件[0=否,1=是]
- * @property string|null $addons_name 插件标识
- * @property string|null $url 路由
- * @property string|null $icon 样式
- * @property int|null $level 级别
- * @property int|null $dev 开发者[0:都可见;开发模式可见]
- * @property int|null $sort 排序
- * @property string|null $params 参数
- * @property string $tree 树
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 添加时间
- * @property int|null $updated_at 修改时间
- */
- class StoreMenu extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_menu}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['pid', 'is_addon', 'level', 'dev', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['params'], 'safe'],
- [['title', 'icon', 'addons_name'], 'string', 'max' => 50],
- [['app_id'], 'string', 'max' => 20],
- [['url'], 'string', 'max' => 100],
- [['tree'], 'string', 'max' => 300],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'title' => '标题',
- 'app_id' => '应用id',
- 'pid' => '上级id',
- 'is_addon' => '是否插件[0=否,1=是]',
- 'addons_name' => '插件标识',
- 'url' => '路由',
- 'icon' => '样式',
- 'level' => '级别',
- 'dev' => '开发者[0:都可见;开发模式可见]',
- 'sort' => '排序',
- 'params' => '参数',
- 'tree' => '树',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '添加时间',
- 'updated_at' => '修改时间',
- ];
- }
- //关联模型
- public function getChild()
- {
- return $this->hasMany(self::class, ['pid' => 'id'])->where(['<>', 'status', StatusEnum::DELETE])->orderBy('sort asc,id asc');
- }
- /**
- *
- * @Author bing
- * @DateTime 2021-08-26 10:56:02
- * @param integer $cate_id
- * @param integer $pid
- * @param string $app_id
- * @return array|null
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- public static function getMenus(array $cond, array $with = [], bool $is_array = true, string $select = '*')
- {
- $query = self::find()->select($select);
- self::paramPack(['where' => $cond, 'with' => $with, 'order' => 'sort asc, id asc'], $query);
- $menu = $query->asArray($is_array)->all();
- return $menu;
- }
- /**
- * 获取树状菜单
- * @Author bing
- * @DateTime 2021-08-10 18:22:16
- * @param array $menu 菜单
- * @param integer $parentId
- * @param string $app_id APP_ID
- * @return array
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- public static function getTreeMenu(array $menu, int $pid = 0, string $route = '',string $mall_sign = '')
- {
- $tree = [];
- foreach ($menu as $k => $v) {
- $v['value'] = $v['id'];
- $v['label'] = $v['title'];
- $v['mall_sign'] = $mall_sign;
- if ($v['pid'] == $pid) {
- $tmp = $v;
- // 当前路由的菜单被选中
- if ($route == $v['url']) $tmp['is_active'] = true;
- $children = self::getTreeMenu($menu, $v['id'], $route,$mall_sign);
- $children && $tmp['children'] = $children;
- //判断父级菜单是否被选中
- if (isset($tmp['children']) && !empty($tmp['children'])) {
- foreach ($tmp['children'] as $child) {
- if (isset($child['is_active']) && $child['is_active'] == true) {
- $tmp['is_active'] = true;
- }
- }
- }
- $tree[] = $tmp;
- }
- }
- return $tree;
- }
- /**
- * 冻结账户权限
- * @Author bing
- * @DateTime 2021-08-10 18:22:16
- * @param array $menu 菜单
- * @param integer $parentId
- * @param string $app_id APP_ID
- * @return array
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- public static function getFreezeMenu(array $menus,int $store_id)
- {
- $freeze_url_arr = [
- 'store/client/index/index',
- 'store/client/cash/index',
- 'store/client/finance/index',
- ];
- $store = Store::findOne(['id'=>$store_id]);
- if(!empty($store['is_freeze'])){
- $newMenus = [];
- foreach($menus as $item){
- if(in_array($item['url'],$freeze_url_arr)){
- $newMenus[] = $item;
- }
- }
- }else{
- $newMenus = $menus;
- }
- return $newMenus;
- }
- }
|