MaterialArticle.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace common\models\wechat;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%wechat_material_article}}".
  7. *
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property string $content
  12. * @property string $thumb_media_id
  13. * @property string $title
  14. * @property string $cover_pic
  15. * @property int $show_cover 是否在文章内容显示封面图片
  16. * @property string $media_id
  17. * @property string|null $source_url 原文链接
  18. * @property string|null $article_desc
  19. * @property string|null $url
  20. * @property string|null $thumb_url 缩略图
  21. * @property string|null $author
  22. * @property int $status 状态【1启用 0禁用 -1删除】
  23. * @property int $created_at
  24. * @property int $updated_at
  25. * @property string $article_id 图文id
  26. */
  27. class MaterialArticle extends \common\models\base\BaseActiveRecord
  28. {
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%wechat_material_article}}';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['mall_id', 'content', 'thumb_media_id', 'title', 'cover_pic', 'media_id'], 'required'],
  43. [['mall_id', 'show_cover', 'status', 'created_at', 'updated_at','publish_id'], 'integer'],
  44. [['content'], 'string'],
  45. [['thumb_media_id', 'title', 'media_id', 'author'], 'string', 'max' => 64],
  46. [['cover_pic', 'source_url', 'article_desc', 'url', 'thumb_url','article_id'], 'string', 'max' => 255],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'mall_id' => 'Mall ID',
  57. 'content' => 'Content',
  58. 'thumb_media_id' => 'Thumb Media ID',
  59. 'title' => 'Title',
  60. 'cover_pic' => 'Cover Pic',
  61. 'show_cover' => '是否在文章内容显示封面图片',
  62. 'media_id' => 'Media ID',
  63. 'source_url' => '原文链接',
  64. 'article_desc' => 'Article Desc',
  65. 'url' => 'Url',
  66. 'thumb_url' => '缩略图',
  67. 'author' => 'Author',
  68. 'status' => '状态【1启用 0禁用 -1删除】',
  69. 'created_at' => 'Created At',
  70. 'updated_at' => 'Updated At',
  71. 'publish_id' => 'Publish Id',
  72. 'article_id' => '图文id'
  73. ];
  74. }
  75. /**
  76. * 保存数据
  77. * @Author lun
  78. * @DateTime 2021-09-17 14:16:24
  79. * @copyright: Copyright (c) 2020 广东七件事集团
  80. * @param array $params
  81. * @return object|boolean
  82. */
  83. public static function setData(int $mall_id, array $params){
  84. try{
  85. if(!empty($params['id'])){
  86. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status',StatusEnum::DELETE]]);
  87. if(empty($model)) throw new \Exception('图文素材不存在或已删除');
  88. }else{
  89. $model = new self();
  90. $model->loadDefaultValues();
  91. $model->mall_id = $mall_id;
  92. }
  93. if(!$model->load($params,'') || !$model->save()){
  94. throw new \Exception($model->getErrorMessage());
  95. }
  96. return $model;
  97. }catch(\Exception $e){
  98. self::$static_error = $e->getMessage();
  99. return false;
  100. }
  101. }
  102. }