255], ['pic_link', 'string', 'max' => 1000], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'sort' => '序号', 'title' => '图片标题', '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; } }