15], [['template'], 'string', 'max' => 20], [['cover'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'title' => '名称', 'mall_template_id' => '我的模板ID,对应qimall_diy_mall_template.id', 'template_id' => '商城模板ID,对应qimall_diy_template.id', 'type' => '页面类型 1:普通页面 2:首页 3:特殊页面(不可设为首页)', 'is_home_page' => '是否首页 0:否 1:是', 'template' => '页面模板', 'content' => '内容', 'cover' => '预览图片', 'expire_time' => '过期时间', 'sort' => '排序,越小排越前', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '添加时间', 'updated_at' => 'Updated At', ]; } /** * 保存数据 * @param array $params * @return bool|array */ public static function setData(array $params){ try{ if(!empty($params['id'])){ $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'],'status'=>[StatusEnum::ENABLED]]); if(empty($model)) throw new Exception('页面不存在或已删除'); // 判断是否已过期,过期不允许修改 if ($model->expire_time != -1 && $model->expire_time <= time()) throw new Exception('模板已过期请续费'); }else{ $model = new self(); $model->loadDefaultValues(); $model->template = $params['template'] ?? DiyEnum::CUSTOM_PAGE; } if(!$model->load($params,'') || !$model->save()){ throw new Exception($model->getErrorMessage()); } // 存入缓存 return $model->toArray(); }catch(Exception $e){ self::setStaticError($e->getMessage()); return false; } } /** * 获取装修 * @Author: lun * @DateTime: 2021/10/13 0013 16:32 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $cond * @param array $with * @param bool $is_array * @param string $select * @return array|\yii\db\ActiveRecord[] */ public static function getDiyPage(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; } /** * 获取装修首页 * @Author: lun * @DateTime: 2021/10/22 0022 14:16 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @return array */ public static function getHomePage($mall_id, &$navs = []) { $page = self::findOne(['mall_id' => $mall_id, 'is_home_page' => StatusEnum::ENABLED, 'status' => StatusEnum::ENABLED]); if (empty($page)) return []; $navs = [ 'is_show'=>$navs['is_show'], 'selectedIconPath' => $navs['selectedIconPath'] ?? '', 'iconPath' => $navs['iconPath'] ?? '', 'text' => $navs['text'] ?? $page->title, 'url' => self::PAGE_PATH_DIY . '?id=' . $page->id, 'open_type' => Link::OPEN_TYPE_PAGE, 'params' => [ 'title' => $page->title, 'route' => self::PAGE_PATH_DIY . '?id=' . $page->id, 'open_type' => Link::OPEN_TYPE_PAGE, 'navigate' => 'navigateTo', ], ]; } }