| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace addons\Course\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_course_category".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $sort 序号
- * @property string $cname 分类名称
- * @property string $logo 分类logo图片保存地址
- * @property int $is_navicat 是否展示导航,1:是,0:不是
- * @property int $status 状态 0禁用,1启用,-1是删除
- * @property int $created_at
- * @property int $updated_at
- */
- class CourseCategory extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_course_category}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'is_navicat', 'status', 'created_at', 'updated_at'], 'integer'],
- [['cname'], 'string', 'max' => 150],
- [['logo'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'sort' => '序号',
- 'cname' => '分类名称',
- 'logo' => '分类logo图片保存地址',
- 'is_navicat' => '是否展示导航,1:是,0:不是',
- 'status' => '状态 0禁用,1启用,-1是删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- 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;
- if (empty($data['sort'])) {
- $model->sort = 999;
- unset($data['sort']);
- }
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|