AddonsAlbum.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace addons\Album\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "qimall_addons_album".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property string $title 画册标题
  12. * @property string $bg_image 画册背景图
  13. * @property string $bg_video 背景音乐
  14. * @property string $bg_color 画册背景颜色
  15. * @property int $size_type 预设尺寸
  16. * @property string $file 附件下载地址
  17. * @property string $share_title 自定义分享标题
  18. * @property string $share_desc 自定义分享描述
  19. * @property string $share_image 自定义分享图片
  20. * @property int $author_id 发布者,会员id
  21. * @property string $author_nick 发布者,会员昵称
  22. * @property string $author_mobile 发布者,手机号
  23. * @property int $created_at 添加时间戳
  24. * @property int $updated_at 更新时间戳
  25. * @property int $status -1是删除,0是禁用,1是启用
  26. * @property string $album_image 封面图片
  27. * @property int $goods_count 画册商品数量
  28. * @property int $page_num 页面数量
  29. * @property int $bg_type 背景方式
  30. * @property string $goods_ids 商品ID集合
  31. */
  32. class AddonsAlbum extends \common\models\base\BaseActiveRecord
  33. {
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public static function tableName()
  38. {
  39. return '{{%addons_album}}';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['mall_id','bg_type', 'size_type','page_num', 'author_id', 'created_at', 'updated_at', 'status', 'goods_count'], 'integer'],
  48. [['title'], 'required'],
  49. [['title', 'bg_color', 'author_nick', 'author_mobile'], 'string', 'max' => 32],
  50. [['bg_image', 'share_title', 'share_desc', 'goods_ids','share_image', 'album_image'], 'string', 'max' => 255],
  51. [['bg_video'], 'string', 'max' => 5000],
  52. [['file',], 'string', 'max' => 500],
  53. ];
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function attributeLabels()
  59. {
  60. return [
  61. 'id' => 'ID',
  62. 'mall_id' => '商城ID',
  63. 'title' => '画册标题',
  64. 'bg_image' => '画册背景图',
  65. 'bg_video' => '背景音乐',
  66. 'bg_color' => '画册背景颜色',
  67. 'size_type' => '预设尺寸',
  68. 'file' => '附件下载地址',
  69. 'share_title' => '自定义分享标题',
  70. 'share_desc' => '自定义分享描述',
  71. 'share_image' => '自定义分享图片',
  72. 'author_id' => '发布者,会员id',
  73. 'author_nick' => '发布者,会员昵称',
  74. 'author_mobile' => '发布者,手机号',
  75. 'created_at' => '添加时间戳',
  76. 'updated_at' => '更新时间戳',
  77. 'status' => '-1是删除,0是禁用,1是启用',
  78. 'album_image' => '封面图片',
  79. 'goods_count' => '画册商品数量',
  80. 'page_num' => '页面数量',
  81. 'bg_type' => '背景类型',
  82. 'goods_ids' => '商品集合',
  83. ];
  84. }
  85. public function getUser()
  86. {
  87. return $this->hasOne(User::class, ['id' => 'author_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  88. }
  89. public function getStatistics()
  90. {
  91. return $this->hasOne(AddonsAlbumStatistics::class, ['album_id' => 'id']);
  92. }
  93. /**
  94. * @Author: ltm
  95. * @DateTime: 2022/2/15 0015 11:43
  96. * @Copyright: copyright (c) 2021 广东七件事集团
  97. * @param $data
  98. * @return string
  99. */
  100. public static function setData(array $params){
  101. try{
  102. if (!empty($params['id'])) {
  103. $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
  104. if (empty($model)) throw new Exception('记录不存在或已删除');
  105. }else{
  106. $model = new self();
  107. $model->loadDefaultValues();
  108. }
  109. $model->mall_id = $params['mall_id'];
  110. if(!$model->load($params,'') || !$model->save()){
  111. throw new Exception($model->getErrorMessage());
  112. }
  113. return $model;
  114. }catch(\Exception $e){
  115. self::$static_error = $e->getMessage();
  116. return false;
  117. }
  118. }
  119. }