| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace common\models\diy;
- use common\enums\DiyEnum;
- use common\enums\StatusEnum;
- use common\models\link\Link;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%diy_page}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $title 名称
- * @property string $mall_template_id 商城模板ID,对应qimall_diy_mall_template.id
- * @property string $template_id 商城模板ID,对应qimall_diy_template.id
- * @property int $type 页面类型 1:普通页面 2:首页 3:特殊页面(不可设为首页)
- * @property int $is_home_page 是否首页 0:否 1:是
- * @property string $template 页面模板
- * @property string $content 内容
- * @property int $expire_time 过期时间
- * @property int $is_show_bottom_nav 过期时间
- * @property string|null $cover 预览图片
- * @property int|null $sort 排序,越小排越前
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 添加时间
- * @property int $updated_at
- */
- class DiyPage extends \common\models\base\BaseActiveRecord
- {
- const PAGE_PATH_DIY = '/pages/index/index';
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%diy_page}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'title'], 'required'],
- [['mall_id', 'mall_template_id', 'template_id', 'type', 'is_home_page', 'sort', 'expire_time', 'status', 'created_at', 'updated_at', 'is_show_bottom_nav'], 'integer'],
- [['content'], 'string'],
- [['title'], 'string', 'max' => 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',
- ],
- ];
- }
- }
|