| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace common\models\link;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%link}}".
- *
- * @property int $id 主键
- * @property string|null $name 英文名
- * @property string $title 中文名
- * @property int $cat_id 分类id
- * @property string $open_type 打开类型:navigate,redirect,app,web,contact,call
- * @property string|null $route 路由
- * @property string|null $icon 图标
- * @property string|null $remark 备注
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class Link extends BaseActiveRecord
- {
- // 打开类型
- const OPEN_TYPE_PAGE = 'page';
- const OPEN_TYPE_CALL = 'call';
- const OPEN_TYPE_WEB = 'web';
- const OPEN_TYPE_APPLET = 'applet';
- const OPEN_TYPE = [
- self::OPEN_TYPE_PAGE => '页面',
- 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;
- }
- }
|