json([ 'status' => false, 'message' => '请选择要操作的记录' ]); } $successCount = 0; foreach ($ids as $id) { if ($this->repository()->toggleStatus($id)) { $successCount++; } } return response()->json([ 'status' => true, 'message' => "成功切换 {$successCount} 条记录的状态" ]); } /** * 获取商品的限购配置 * * @param int $shopItemId * @return \Illuminate\Http\JsonResponse */ public function getByShopItem($shopItemId) { $limits = $this->repository()->getByShopItem($shopItemId); return response()->json([ 'status' => true, 'data' => $limits->map(function ($limit) { return [ 'id' => $limit->id, 'name' => $limit->name, 'limit_type_text' => $limit->limit_type_text, 'limit_period_text' => $limit->limit_period_text, 'max_quantity' => $limit->max_quantity, 'is_active' => $limit->is_active, ]; }) ]); } /** * 复制限购配置 * * @param int $id * @return \Illuminate\Http\JsonResponse */ public function copy($id) { $limit = $this->repository()->newQuery()->find($id); if (!$limit) { return response()->json([ 'status' => false, 'message' => '限购配置不存在' ]); } $newData = $limit->toArray(); unset($newData['id'], $newData['created_at'], $newData['updated_at']); $newData['name'] = $newData['name'] . ' (副本)'; $newData['is_active'] = false; // 副本默认为禁用状态 $repository = $this->repository(); $newLimit = $repository->createLimit($newData); return response()->json([ 'status' => true, 'message' => '限购配置复制成功', 'data' => [ 'id' => $newLimit->id, 'name' => $newLimit->name ] ]); } }