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; } }