AddonsAlbumPage.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace addons\Album\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "qimall_addons_album_page".
  8. *
  9. * @property int $id
  10. * @property int $album_id 画册ID
  11. * @property string $image 画册单页图片
  12. * @property string $goods_ids 商品id,多个商品逗号隔开
  13. * @property int $created_at 添加时间戳
  14. * @property int $updated_at 更新时间戳
  15. * @property int $status -1是删除,0是禁用,1是启用
  16. * @property int $mall_id 商城ID
  17. * @property int $sort 排序
  18. */
  19. class AddonsAlbumPage extends \common\models\base\BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_album_page}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['album_id', 'created_at','mall_id', 'updated_at','sort', 'status'], 'integer'],
  35. [['goods_ids'], 'string'],
  36. [['image'], 'string', 'max' => 255],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'album_id' => '画册ID',
  47. 'image' => '画册单页图片',
  48. 'goods_ids' => '商品id,多个商品逗号隔开',
  49. 'created_at' => '添加时间戳',
  50. 'updated_at' => '更新时间戳',
  51. 'status' => '-1是删除,0是禁用,1是启用',
  52. 'mall_id' => '商城ID',
  53. 'sort' => '排序',
  54. ];
  55. }
  56. /**
  57. * @Author: ltm
  58. * @DateTime: 2022/2/15 0015 11:43
  59. * @Copyright: copyright (c) 2021 广东七件事集团
  60. * @param $data
  61. * @return string
  62. */
  63. public static function setData(array $params){
  64. try{
  65. if (!empty($params['id'])) {
  66. $model = self::findOne(['id'=>$params['id'],'mall_id'=>$params['mall_id']]);
  67. if($params['status'] == StatusEnum::DELETE){
  68. $album = AddonsAlbum::findOne(['id'=>$model->album_id]);
  69. $album->page_num = $album->page_num-1;
  70. $album->save();
  71. }
  72. $model->updated_at = time();
  73. if (empty($model)) throw new Exception('记录不存在或已删除');
  74. }else{
  75. $model = new self();
  76. $model->created_at = time();
  77. $model->loadDefaultValues();
  78. }
  79. $model->mall_id = $params['mall_id'];
  80. if(!$model->load($params,'') || !$model->save()){
  81. throw new Exception($model->getErrorMessage());
  82. }
  83. return $model;
  84. }catch(\Exception $e){
  85. self::$static_error = $e->getMessage();
  86. return false;
  87. }
  88. }
  89. }