'页面', self::OPEN_TYPE_WEB => '网页', self::OPEN_TYPE_CALL => '电话联系', self::OPEN_TYPE_APPLET => '小程序', ]; /** * {@inheritdoc} */ public static function tableName() { return '{{%link}}'; } /** * {@inheritdoc} */ public function rules() { return [ [['cat_id', 'status', 'created_at', 'updated_at'], 'integer'], [['remark'], 'string'], [['name', 'title', 'open_type'], 'string', 'max' => 20], [['route'], 'string', 'max' => 200], [['icon'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '主键', 'name' => '英文名', 'title' => '中文名', 'cat_id' => '分类id', 'open_type' => '打开类型:navigate,redirect,app,web,contact,call', 'route' => '路由', 'icon' => 'Icon', 'remark' => '备注', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '修改时间', ]; } public function getCategory() { return $this->hasMany(LinkCategory::class, ['id' => 'cat_id'])->select("id,title,is_link"); } /** * 根据cat_id获取链接列表 * @param $mall_id * @param $cat_id * @return array|\yii\db\ActiveRecord[] */ public static function getLinkByCatId($mall_id, $cat_id) { $field = "id,title as name,cat_id,open_type,route as value,remark"; return self::find()->select($field)->where(['mall_id' => $mall_id, 'cat_id' => $cat_id, 'status' => StatusEnum::ENABLED])->asArray()->all(); } /** * 获取所有链接,将cat_id作为键 * @Author: lun * @DateTime: 2021/10/13 0013 12:20 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $cond * @param bool $is_array * @param string $select * @param string $indexBy * @return array|\yii\db\ActiveRecord[] */ public static function getLink(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; } }