| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace addons\Course\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_course_groups}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $gname 分组名称
- * @property int $sort 序号
- * @property string|null $cid 关联的课程id,多个课程 id 用逗号(英文)连接
- * @property string $logo 分组logo图片保存路径
- * @property int $status 状态 0禁用,1启用,-1是删除
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsCourseGroups extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_course_groups}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['cid'], 'string'],
- [['gname'], 'string', 'max' => 150],
- [['logo'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'gname' => '分组名称',
- 'sort' => '序号',
- 'cid' => '关联的课程id,多个课程 id 用逗号(英文)连接',
- 'logo' => '分组logo图片保存路径',
- 'status' => '状态 0禁用,1启用,-1是删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- 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 (!$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;
- }
- }
- }
|