'ID', 'mall_id' => '商城id', 'store_id' => '商品id', 'user_id' => '会员id', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData(array $params) { try { if ($params['type'] == 1) { if (!empty($params['store_id'])) { $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } else { if ($model->status) throw new \Exception('已收藏'); } if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } } if ($params['type'] == 0) { if (!empty($params['store_id'])) { $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED]]); if (empty($model)) throw new \Exception('不存在'); if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } } } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } }