| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace common\models\wechat;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%wechat_material_article}}".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property string $content
- * @property string $thumb_media_id
- * @property string $title
- * @property string $cover_pic
- * @property int $show_cover 是否在文章内容显示封面图片
- * @property string $media_id
- * @property string|null $source_url 原文链接
- * @property string|null $article_desc
- * @property string|null $url
- * @property string|null $thumb_url 缩略图
- * @property string|null $author
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at
- * @property int $updated_at
- * @property string $article_id 图文id
- */
- class MaterialArticle extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%wechat_material_article}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'content', 'thumb_media_id', 'title', 'cover_pic', 'media_id'], 'required'],
- [['mall_id', 'show_cover', 'status', 'created_at', 'updated_at','publish_id'], 'integer'],
- [['content'], 'string'],
- [['thumb_media_id', 'title', 'media_id', 'author'], 'string', 'max' => 64],
- [['cover_pic', 'source_url', 'article_desc', 'url', 'thumb_url','article_id'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'content' => 'Content',
- 'thumb_media_id' => 'Thumb Media ID',
- 'title' => 'Title',
- 'cover_pic' => 'Cover Pic',
- 'show_cover' => '是否在文章内容显示封面图片',
- 'media_id' => 'Media ID',
- 'source_url' => '原文链接',
- 'article_desc' => 'Article Desc',
- 'url' => 'Url',
- 'thumb_url' => '缩略图',
- 'author' => 'Author',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'publish_id' => 'Publish Id',
- 'article_id' => '图文id'
- ];
- }
- /**
- * 保存数据
- * @Author lun
- * @DateTime 2021-09-17 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return object|boolean
- */
- public static function setData(int $mall_id, array $params){
- try{
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status',StatusEnum::DELETE]]);
- if(empty($model)) throw new \Exception('图文素材不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $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;
- }
- }
- }
|