| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\Course\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_course_activity}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $course_id 活动关联的课程id,多个用逗号连接
- * @property int $good_id 活动关联的商品id,只能是一个商品
- * @property int $course_number 活动关联的课程个数
- * @property int $select_number 活动关联的课程中任选课程的个数
- * @property string $name 活动名称
- * @property string|null $banners 活动轮播图,多个图片地址用逗号隔开
- * @property int $status 活动状态,1:启用,0:禁用,-1删除
- * @property int $created_at
- * @property int $updated_at
- * @property string $logo 活动封面logo图片
- */
- class AddonsCourseActivity extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_course_activity}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'goods_id', 'course_number', 'select_number', 'status', 'created_at', 'updated_at'], 'integer'],
- [['course_id', 'banners', 'logo'], 'string'],
- [['name'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'course_id' => '活动关联的课程id,多个用逗号连接',
- 'goods_id' => '活动关联的商品id,只能是一个商品',
- 'course_number' => '活动关联的课程个数',
- 'select_number' => '活动关联的课程中任选课程的个数',
- 'name' => '活动名称',
- 'banners' => '活动轮播图,多个图片地址用逗号隔开',
- 'status' => '活动状态,1:启用,0:禁用,-1删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'logo' => '活动封面logo图片保存地址',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- if(!empty($params['banners'])) $params['banners'] = json_encode($params['banners']);
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|