AddonsAlbumPageShare.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\Album\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "qimall_addons_album_page_share".
  7. *
  8. * @property int $id
  9. * @property int $album_id 画册ID
  10. * @property int $album_page_id 画册页ID
  11. * @property int $mall_id
  12. * @property int $user_id
  13. * @property int $created_at 分享时间
  14. * @property int $updated_at 更新时间
  15. * @property string $date 日期
  16. */
  17. class AddonsAlbumPageShare extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_album_page_share}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['album_id', 'album_page_id', 'mall_id', 'user_id', 'created_at','updated_at'], 'integer'],
  33. [['date'], 'required'],
  34. [['date'], 'safe'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'album_id' => '画册ID',
  45. 'album_page_id' => '画册页ID',
  46. 'mall_id' => 'Mall ID',
  47. 'user_id' => 'User ID',
  48. 'created_at' => '分享时间',
  49. 'date' => '日期',
  50. 'updated_at' => '更新时间',
  51. ];
  52. }
  53. /**
  54. * @Author: ltm
  55. * @DateTime: 2022/2/15 0015 11:43
  56. * @Copyright: copyright (c) 2021 广东七件事集团
  57. * @param $data
  58. * @return string
  59. */
  60. public static function setData(array $params){
  61. try{
  62. $params['created_at'] = time();
  63. $params['updated_at'] = time();
  64. $params['date'] = date("Y-m-d");
  65. if (!empty($params['id'])) {
  66. $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
  67. if (empty($model)) throw new Exception('记录不存在或已删除');
  68. }else{
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. $model->mall_id = $params['mall_id'];
  73. if(!$model->load($params,'') || !$model->save()){
  74. throw new Exception($model->getErrorMessage());
  75. }
  76. return $model;
  77. }catch(\Exception $e){
  78. self::$static_error = $e->getMessage();
  79. return false;
  80. }
  81. }
  82. public function getAlbum()
  83. {
  84. return $this->hasOne(AddonsAlbum::class, ['id' => 'album_id'])->select('id,title,goods_count');
  85. }
  86. }