| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace addons\Album\common\models;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_album".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string $title 画册标题
- * @property string $bg_image 画册背景图
- * @property string $bg_video 背景音乐
- * @property string $bg_color 画册背景颜色
- * @property int $size_type 预设尺寸
- * @property string $file 附件下载地址
- * @property string $share_title 自定义分享标题
- * @property string $share_desc 自定义分享描述
- * @property string $share_image 自定义分享图片
- * @property int $author_id 发布者,会员id
- * @property string $author_nick 发布者,会员昵称
- * @property string $author_mobile 发布者,手机号
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- * @property int $status -1是删除,0是禁用,1是启用
- * @property string $album_image 封面图片
- * @property int $goods_count 画册商品数量
- * @property int $page_num 页面数量
- * @property int $bg_type 背景方式
- * @property string $goods_ids 商品ID集合
- */
- class AddonsAlbum extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_album}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id','bg_type', 'size_type','page_num', 'author_id', 'created_at', 'updated_at', 'status', 'goods_count'], 'integer'],
- [['title'], 'required'],
- [['title', 'bg_color', 'author_nick', 'author_mobile'], 'string', 'max' => 32],
- [['bg_image', 'share_title', 'share_desc', 'goods_ids','share_image', 'album_image'], 'string', 'max' => 255],
- [['bg_video'], 'string', 'max' => 5000],
- [['file',], 'string', 'max' => 500],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'title' => '画册标题',
- 'bg_image' => '画册背景图',
- 'bg_video' => '背景音乐',
- 'bg_color' => '画册背景颜色',
- 'size_type' => '预设尺寸',
- 'file' => '附件下载地址',
- 'share_title' => '自定义分享标题',
- 'share_desc' => '自定义分享描述',
- 'share_image' => '自定义分享图片',
- 'author_id' => '发布者,会员id',
- 'author_nick' => '发布者,会员昵称',
- 'author_mobile' => '发布者,手机号',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- 'status' => '-1是删除,0是禁用,1是启用',
- 'album_image' => '封面图片',
- 'goods_count' => '画册商品数量',
- 'page_num' => '页面数量',
- 'bg_type' => '背景类型',
- 'goods_ids' => '商品集合',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'author_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- public function getStatistics()
- {
- return $this->hasOne(AddonsAlbumStatistics::class, ['album_id' => 'id']);
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/2/15 0015 11:43
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function setData(array $params){
- try{
- if (!empty($params['id'])) {
- $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- $model->mall_id = $params['mall_id'];
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|