| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace addons\Bargain\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_course_banners}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $sort 序号
- * @property string $pic_link 图片跳转链接
- * @property string $pic_path 图片保存路径
- * @property int $is_show 是否展示,1:是,0:不是
- * @property int $status 活动状态,1:启用,0:禁用,-1删除
- * @property int $created_at
- * @property int $updated_at
- */
- class BargainBanners extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_bargain_banners}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'is_show', 'status', 'created_at', 'updated_at'], 'integer'],
- [['pic_path'], 'string', 'max' => 255],
- ['pic_link', 'string', 'max' => 1000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'sort' => '序号',
- 'pic_link' => '图片跳转链接',
- 'pic_path' => '图片保存路径',
- 'is_show' => '是否展示,1:是,0:不是',
- 'status' => '活动状态,1:启用,0:禁用,-1删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- if (!empty($data['pic_link']) && is_array($data['pic_link'])) {
- $data['pic_link'] = json_encode($data['pic_link']);
- }
- if (!empty($data['id'])) {
- $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
- if (empty($model)) {
- self::$static_error = '数据异常';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->status = StatusEnum::ENABLED;
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|