64], [['app_ext'], 'string', 'max' => 1024], [['img_url', 'page_url', 'video_url','other_img_url'], 'string', 'max' => 2048], [['title'], 'string', 'max' => 512], [['text'], 'string'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'user_id' => '用户ID', 'zone_id' => '位置ID', 'url_type' => '链接类型,0=小程序页面,1=外部链接,2=小程序', 'app_id' => 'APP_ID', 'app_ext' => 'APP_EXT', 'img_url' => '图片', 'title' => '标题', 'page_url' => '链接', 'sort' => '排序', 'is_delete' => '是否删除', 'status' => '状态,0=隐藏,1=显示', 'created_at' => '添加时间', 'updated_at' => '更新时间', 'deleted_at' => '删除时间', 'media' => '媒体类型:0=图片,1=视频', 'video_url' => '视频', ]; } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->isNewRecord) { $this->created_at = time(); } $this->updated_at = time(); if ($this->is_delete == 1) $this->deleted_at = time(); $this->htmlTagFilter(); return true; } else { return false; } } public function htmlTagFilter() { $this->img_url = Model::htmlTagFilter($this->img_url); $this->title = Model::htmlTagFilter($this->title); // $this->page_url = Model::htmlTagFilter($this->page_url); $this->video_url = Model::htmlTagFilter($this->video_url); } public static function urlTypeLabels() { return [ '0' => '小程序页面', '1' => '外部链接', '2' => '小程序', '3' => '公众号图片', '4' => '视频号图片', '5' => '抖音号图片', '6' => '文章', '7' => '不弹窗', ]; } public static function getUrlType($type) { $labels = self::urlTypeLabels(); return isset($labels[$type]) ? $labels[$type] : "未知"; } public static function statusLabels() { return [ '0' => '隐藏', '1' => '显示' ]; } public static function getStatus($status) { $labels = self::statusLabels(); return isset($labels[$status]) ? $labels[$status] : "未知"; } public static function mediaLabels() { return [ '0' => '图片', // '1' => '视频', ]; } public static function type() { return [ // '1' => 'banner', '2' => '轮播', ]; } public static function getMedia($media) { $labels = self::statusLabels(); return isset($labels[$media]) ? $labels[$media] : "未知"; } public static function getBannerList($zone_id, $cx_mch_id = 0) { $list = Banner::find() ->where([ 'zone_id' => $zone_id, 'is_delete' => 0, 'cx_mch_id' => $cx_mch_id, 'status' => 1, ]) ->select('id,url_type,app_id,app_ext,img_url,title,page_url,media,video_url,type,other_img_url,text') ->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item) { if ($item['media'] == self::MEDIA_IMG) { $item['img_url'] = SiteHelper::getFullUrl($item['img_url']); } if ($item['media'] == self::MEDIA_VIDEO) { //获取视频时长 $item['duration'] = 0; $video_url = trim($item['video_url'], "."); $video_url = trim($item['video_url'], "/"); if (file_exists($video_url)) { $video_info = Utils::getVideoInfo($video_url); $item['duration'] = ceil($video_info['seconds']); } $item['video_url'] = SiteHelper::getFullUrl($item['video_url']); } $list[$index] = $item; } return $list; } /** * 轮播图查询 */ public function search() { $data = Banner::find()->where(['status' => 1, 'is_delete' => 0, 'media' => 0])->select('title,page_url,sort,status,')->orderBy(['sort' => SORT_DESC])->all(); return $data; } }