| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace addons\Album\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_album_page".
- *
- * @property int $id
- * @property int $album_id 画册ID
- * @property string $image 画册单页图片
- * @property string $goods_ids 商品id,多个商品逗号隔开
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- * @property int $status -1是删除,0是禁用,1是启用
- * @property int $mall_id 商城ID
- * @property int $sort 排序
- */
- class AddonsAlbumPage extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_album_page}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['album_id', 'created_at','mall_id', 'updated_at','sort', 'status'], 'integer'],
- [['goods_ids'], 'string'],
- [['image'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'album_id' => '画册ID',
- 'image' => '画册单页图片',
- 'goods_ids' => '商品id,多个商品逗号隔开',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- 'status' => '-1是删除,0是禁用,1是启用',
- 'mall_id' => '商城ID',
- 'sort' => '排序',
- ];
- }
- /**
- * @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($params['status'] == StatusEnum::DELETE){
- $album = AddonsAlbum::findOne(['id'=>$model->album_id]);
- $album->page_num = $album->page_num-1;
- $album->save();
- }
- $model->updated_at = time();
- if (empty($model)) throw new Exception('记录不存在或已删除');
- }else{
- $model = new self();
- $model->created_at = time();
- $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;
- }
- }
- }
|