HappinessStoreMenu.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use addons\happiness\common\models\happinessStore;
  4. use common\enums\StatusEnum;
  5. use common\models\base\BaseActiveRecord;
  6. /**
  7. * This is the model class for table "qimall_addons_happiness_store_menu".
  8. *
  9. * @property int $id
  10. * @property string $title 标题
  11. * @property string $app_id 应用id
  12. * @property int|null $pid 上级id
  13. * @property string|null $addons_name 插件标识
  14. * @property int|null $is_addon 是否插件[0=否,1=是]
  15. * @property string|null $url 路由
  16. * @property string|null $icon 样式
  17. * @property int|null $level 级别
  18. * @property int|null $dev 开发者[0:都可见;开发模式可见]
  19. * @property int|null $sort 排序
  20. * @property string|null $params 参数
  21. * @property string $tree 树
  22. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  23. * @property int|null $created_at 添加时间
  24. * @property int|null $updated_at 修改时间
  25. */
  26. class HappinessStoreMenu extends BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_happiness_store_menu}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['pid', 'is_addon', 'level', 'dev', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
  42. [['params'], 'safe'],
  43. [['title', 'addons_name', 'icon'], 'string', 'max' => 50],
  44. [['app_id'], 'string', 'max' => 20],
  45. [['url'], 'string', 'max' => 100],
  46. [['tree'], 'string', 'max' => 300],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'title' => '标题',
  57. 'app_id' => '应用id',
  58. 'pid' => '上级id',
  59. 'addons_name' => '插件标识',
  60. 'is_addon' => '是否插件[0=否,1=是]',
  61. 'url' => '路由',
  62. 'icon' => '样式',
  63. 'level' => '级别',
  64. 'dev' => '开发者[0:都可见;开发模式可见]',
  65. 'sort' => '排序',
  66. 'params' => '参数',
  67. 'tree' => '树',
  68. 'status' => '状态[-1:删除;0:禁用;1启用]',
  69. 'created_at' => '添加时间',
  70. 'updated_at' => '修改时间',
  71. ];
  72. }
  73. //关联模型
  74. public function getChild()
  75. {
  76. return $this->hasMany(self::class, ['pid' => 'id'])->where(['<>', 'status', StatusEnum::DELETE])->orderBy('sort asc,id asc');
  77. }
  78. /**
  79. *
  80. * @Author bing
  81. * @DateTime 2021-08-26 10:56:02
  82. * @param integer $cate_id
  83. * @param integer $pid
  84. * @param string $app_id
  85. * @return array|null
  86. * @copyright: Copyright (c) 2020 广东七件事集团
  87. */
  88. public static function getMenus(array $cond, array $with = [], bool $is_array = true, string $select = '*')
  89. {
  90. $query = self::find()->select($select);
  91. self::paramPack(['where' => $cond, 'with' => $with, 'order' => 'sort asc, id asc'], $query);
  92. $menu = $query->asArray($is_array)->all();
  93. return $menu;
  94. }
  95. /**
  96. * 获取树状菜单
  97. * @Author bing
  98. * @DateTime 2021-08-10 18:22:16
  99. * @param array $menu 菜单
  100. * @param integer $parentId
  101. * @param string $app_id APP_ID
  102. * @return array
  103. * @copyright: Copyright (c) 2020 广东七件事集团
  104. */
  105. public static function getTreeMenu(array $menu, int $pid = 0, string $route = '',string $mall_sign = '')
  106. {
  107. $tree = [];
  108. foreach ($menu as $k => $v) {
  109. $v['value'] = $v['id'];
  110. $v['label'] = $v['title'];
  111. $v['mall_sign'] = $mall_sign;
  112. if ($v['pid'] == $pid) {
  113. $tmp = $v;
  114. // 当前路由的菜单被选中
  115. if ($route == $v['url']) $tmp['is_active'] = true;
  116. $children = self::getTreeMenu($menu, $v['id'], $route,$mall_sign);
  117. $children && $tmp['children'] = $children;
  118. //判断父级菜单是否被选中
  119. if (isset($tmp['children']) && !empty($tmp['children'])) {
  120. foreach ($tmp['children'] as $child) {
  121. if (isset($child['is_active']) && $child['is_active'] == true) {
  122. $tmp['is_active'] = true;
  123. }
  124. }
  125. }
  126. $tree[] = $tmp;
  127. }
  128. }
  129. return $tree;
  130. }
  131. /**
  132. * 冻结账户权限
  133. * @Author bing
  134. * @DateTime 2021-08-10 18:22:16
  135. * @param array $menu 菜单
  136. * @param integer $parentId
  137. * @param string $app_id APP_ID
  138. * @return array
  139. * @copyright: Copyright (c) 2020 广东七件事集团
  140. */
  141. public static function getFreezeMenu(array $menus,int $store_id)
  142. {
  143. $freeze_url_arr = [
  144. 'happiness/client/index/index',
  145. 'happiness/client/cash/index',
  146. 'happiness/client/finance/index',
  147. ];
  148. $store = happinessStore::findOne(['id'=>$store_id]);
  149. if(!empty($store['is_freeze'])){
  150. $newMenus = [];
  151. foreach($menus as $item){
  152. if(in_array($item['url'],$freeze_url_arr)){
  153. $newMenus[] = $item;
  154. }
  155. }
  156. }else{
  157. $newMenus = $menus;
  158. }
  159. return $newMenus;
  160. }
  161. }