| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace addons\OperatingNote\common\models;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_operating_note_ad}}".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $sort 排序
- * @property string $title 广告标题
- * @property string $img 广告图
- * @property string $jump_href 跳转链接
- * @property int $status -1是删除,0是禁用,1是启用
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsOperatingNoteAd extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operating_note_ad}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'sort'], 'required'],
- [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title'], 'string', 'max' => 50],
- [['img'], 'string', 'max' => 255],
- [[ 'jump_href'], 'string', 'max' => 5000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'sort' => '排序',
- 'title' => '广告标题',
- 'img' => '广告图',
- 'jump_href' => '跳转链接',
- 'status' => '-1是删除,0是禁用,1是启用',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @throws \yii\db\Exception
- */
- public static function setData(array $params, string $scenarios = 'create')
- {
- $transaction = \Yii::$app->db->beginTransaction();
- try {
- if ($scenarios == 'update') {
- $model = self::findOne(['id' => $params['id']]);
- } else {
- $model = new self();
- }
- if (!$model->load($params, '') || false === $model->validate()) {
- $errors = $model->errors;
- $error_str = '';
- foreach ($errors as $error) {
- $error_str .= implode(',', $error) . ',';
- }
- $error_str = trim($error_str, ',');
- throw new \Exception($error_str);
- }
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- $transaction->commit();
- return true;
- } catch (Exception $e) {
- $transaction->rollBack();
- throw new Exception($e->getErrorMessage());
- }
- }
- }
|